Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

on:
push:
branches: [main]
branches: [prod]
tags: ['v*']
pull_request:
branches: [main]
branches: [prod]
workflow_dispatch:

env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
Size="@Size"
Outline="@Outline"
Disabled="@IsDisabled"
Click="@OpenDialogAsync" />
Click="@OpenDialogAsync"
@attributes="AdditionalAttributes" />

@code {
protected override SuperDataGridExportFormat Format => SuperDataGridExportFormat.Csv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
Size="@Size"
Outline="@Outline"
Disabled="@IsDisabled"
Click="@OpenDialogAsync" />
Click="@OpenDialogAsync"
@attributes="AdditionalAttributes" />

@code {
protected override SuperDataGridExportFormat Format => SuperDataGridExportFormat.Excel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public abstract class SuperDataGridExportButtonBase<TItem> : ComponentBase
[Parameter]
public bool IconOnly { get; set; }

/// <summary>
/// Additional attributes applied to the underlying <see cref="SuperButton"/>,
/// such as <c>class</c> or <c>style</c>.
/// </summary>
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> AdditionalAttributes { get; set; } = new();

protected abstract SuperDataGridExportFormat Format { get; }
protected abstract string DefaultText { get; }
protected abstract string DialogTitle { get; }
Expand All @@ -52,6 +59,36 @@ public abstract class SuperDataGridExportButtonBase<TItem> : ComponentBase
private SuperDataGrid<TItem>? EffectiveGrid => Grid ?? CascadedGrid;
protected bool IsDisabled => Disabled || EffectiveGrid is null;

public override async Task SetParametersAsync(ParameterView parameters)
{
var normalized = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
string? htmlStyle = null;
var hasHtmlStyle = false;

foreach (var parameter in parameters)
{
if (string.Equals(parameter.Name, "style", StringComparison.OrdinalIgnoreCase)
&& (parameter.Value is string || parameter.Value is null))
{
hasHtmlStyle = true;
htmlStyle = parameter.Value as string;
continue;
}

normalized[parameter.Name] = parameter.Value;
}

if (!hasHtmlStyle)
{
await base.SetParametersAsync(parameters);
return;
}

await base.SetParametersAsync(ParameterView.FromDictionary(normalized));
if (htmlStyle is not null)
AdditionalAttributes["style"] = htmlStyle;
}

protected async Task OpenDialogAsync(MouseEventArgs _)
{
var grid = EffectiveGrid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ private string CssClass

protected override void OnParametersSet()
{
if (CapturedHtmlStyleAttribute is not null)
{
CapturedAttributes["style"] = CapturedHtmlStyleAttribute;
}
else
{
CapturedAttributes.Remove("style");
}

CapturedAttributes.TryGetValue("class", out var cls);
_additionalCssClass = cls?.ToString();

Expand Down
30 changes: 30 additions & 0 deletions src/SuperBlazorComponents/Components/Buttons/SuperButtonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace SuperBlazorComponents.Components.Buttons;

public abstract class SuperButtonBase : ComponentBase
{
protected string? CapturedHtmlStyleAttribute { get; private set; }

[Parameter]
public EventCallback<MouseEventArgs> Click { get; set; }

Expand All @@ -20,6 +22,34 @@ public abstract class SuperButtonBase : ComponentBase
[Parameter]
public bool IsBusy { get; set; } = false;

public override async Task SetParametersAsync(ParameterView parameters)
{
var normalized = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
var hasHtmlStyle = false;
CapturedHtmlStyleAttribute = null;

foreach (var parameter in parameters)
{
if (string.Equals(parameter.Name, "style", StringComparison.OrdinalIgnoreCase)
&& (parameter.Value is string || parameter.Value is null))
{
hasHtmlStyle = true;
CapturedHtmlStyleAttribute = parameter.Value as string;
continue;
}

normalized[parameter.Name] = parameter.Value;
}

if (!hasHtmlStyle)
{
await base.SetParametersAsync(parameters);
return;
}

await base.SetParametersAsync(ParameterView.FromDictionary(normalized));
}

private bool _isBusy;

protected bool IsDisabled => _isBusy || IsBusy || Disabled || CapturedAttributes.ContainsKey("disabled");
Expand Down
16 changes: 16 additions & 0 deletions tests/SuperBlazorComponents.Tests/SuperDataGridExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ public void ExportButtons_IconOnlyHidesTextAndKeepsAccessibleLabel()
Assert.HasCount(1, button.QuerySelectorAll(".fa-file-csv"));
}

[TestMethod]
public void ExportButtons_ForwardClassAndStyleToUnderlyingButton()
{
using var context = new BunitContext();
context.JSInterop.Mode = JSRuntimeMode.Loose;
context.Services.AddSuperComponents();

var button = context.Render<SuperDataGridCsvExportButton<TestRow>>(parameters => parameters
.AddUnmatched("class", "me-2")
.AddUnmatched("style", "margin-inline-end: 0.5rem"))
.Find("button");

StringAssert.Contains(button.GetAttribute("class")!, "me-2");
Assert.AreEqual("margin-inline-end: 0.5rem", button.GetAttribute("style"));
}

[TestMethod]
public void ExportDialog_AfterGenerationDisplaysDownloadLink()
{
Expand Down
Loading