Dialog و Popup
نمونه کد
کپی
@using BzCore.Components.Dialog
@inject IBzDialogService Dialog
@* تایید *@
var ok = await Dialog.ConfirmAsync("حذف رکورد", "مطمئنید؟", "حذف", "انصراف");
if (ok) { /* حذف */ }
@* هشدار *@
await Dialog.AlertAsync("اطلاع", "انجام شد.");
@* نکته: یکبار <BzDialogHost /> را در لِیاوت ریشه قرار بده تا سرویس مرکزی کار کند. *@
دیالوگ اعلانی (با reference)
باز کردن دیالوگ
کد کامل
کپی
@using BzCore.Components.Dialog
@using BzCore.Components.Input
@using BzCore.Enums
<BzButton Text="باز کردن دیالوگ" OnClick="@(() => dlg.Show())" />
<BzDialog @ref="dlg" Title="ویرایش کاربر" Icon="fa-solid fa-user-pen"
Size="BzDialogSize.Medium" Buttons="buttons" OnClose="@(r => result = r)">
<ChildContent>
<BzInput TValue="string" @bind-Value="editName" Label="نام کاربر" Clearable />
</ChildContent>
</BzDialog>
@code {
BzDialog dlg = default!;
string? editName = "کاربر نمونه";
BzDialogResult? result;
List<BzDialogButton> buttons = new()
{
BzDialogButton.Cancel(),
new BzDialogButton
{
Text = "ذخیره", Color = BzColor.Success, Icon = "fa-solid fa-check",
OnClick = async () => await Task.Delay(900) // ذخیرهٔ واقعی
}
};
}
سرویس مرکزی
Confirm
Alert
BzPopup
کد کامل
کپی
@using BzCore.Components.Dialog
@using BzCore.Components.Button
@using BzCore.Enums
<BzPopup Placement="BzPopupPlacement.Bottom" Width="220px">
<Trigger>
<BzButton Text="منوی کاربر" EndIcon="fa-solid fa-chevron-down"
Variant="BzButtonVariant.Soft" />
</Trigger>
<ChildContent>
<BzButton Variant="BzButtonVariant.Text" FullWidth StartIcon="fa-solid fa-user" Text="پروفایل" />
<BzButton Variant="BzButtonVariant.Text" FullWidth StartIcon="fa-solid fa-gear" Text="تنظیمات" />
<BzButton Variant="BzButtonVariant.Text" FullWidth Color="BzColor.Danger"
StartIcon="fa-solid fa-right-from-bracket" Text="خروج" />
</ChildContent>
</BzPopup>