!3556 feat(#I62RUU): set the parameter default value for DialogCloseButton/DialogSaveButton

* feat: ModalDialog 增加对 DialogClose/SaveButton 支持
* feat: DialogSaveButton 增加默认属性
* feat: DialogCloseButton 增加默认属性
This commit is contained in:
Argo 2022-11-23 15:30:04 +00:00
parent 0bc43b2635
commit 79e3a752d8
3 changed files with 49 additions and 4 deletions

View File

@ -3,6 +3,7 @@
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace BootstrapBlazor.Components;
@ -11,9 +12,19 @@ namespace BootstrapBlazor.Components;
/// </summary>
public partial class DialogCloseButton : Button
{
/// <summary>
/// 获得/设置 按钮颜色
/// </summary>
[Parameter]
public override Color Color { get; set; } = Color.Secondary;
[CascadingParameter]
private Func<Task>? OnCloseAsync { get; set; }
[Inject]
[NotNull]
private IStringLocalizer<ModalDialog>? Localizer { get; set; }
/// <summary>
/// <inheritdoc/>
/// </summary>
@ -26,4 +37,15 @@ public partial class DialogCloseButton : Button
OnClickWithoutRender = OnCloseAsync;
}
}
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnParametersSet()
{
base.OnParametersSet();
ButtonIcon ??= "fa-solid fa-fw fa-xmark";
Text ??= Localizer[nameof(ModalDialog.CloseButtonText)];
}
}

View File

@ -3,6 +3,7 @@
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace BootstrapBlazor.Components;
@ -11,6 +12,10 @@ namespace BootstrapBlazor.Components;
/// </summary>
public partial class DialogSaveButton : Button
{
[Inject]
[NotNull]
private IStringLocalizer<ModalDialog>? Localizer { get; set; }
/// <summary>
/// <inheritdoc/>
/// </summary>
@ -20,4 +25,15 @@ public partial class DialogSaveButton : Button
ButtonType = ButtonType.Submit;
}
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnParametersSet()
{
base.OnParametersSet();
ButtonIcon ??= "fa-solid fa-floppy-disk";
Text ??= Localizer[nameof(ModalDialog.SaveButtonText)];
}
}

View File

@ -35,9 +35,11 @@
</div>
}
<CascadingValue Name="BodyContext" Value="@BodyContext" IsFixed="true">
<div class="modal-body">
@RenderBodyTemplate()
</div>
<CascadingValue Value="OnClickClose" IsFixed="true">
<div class="modal-body">
@RenderBodyTemplate()
</div>
</CascadingValue>
@if (ShowFooter)
{
<div class="modal-footer">
@ -53,7 +55,12 @@
{
<Button Color="Color.Primary" Text="@SaveButtonText" Icon="fa-solid fa-fw fa-floppy-disk" OnClickWithoutRender="OnClickSave" />
}
@FooterTemplate
@if (FooterTemplate != null)
{
<CascadingValue Value="OnClickClose" IsFixed>
@FooterTemplate
</CascadingValue>
}
</div>
}
</CascadingValue>