Adds the building blocks every later screen uses, so modules are built from one set of components instead of ad hoc markup: - Form components (KhForm, KhTextBox, KhNumberBox, KhDateBox, KhSelect, KhCheck, KhSwitch, KhHotlink) with Italian number and date input, inline calculation (=10*3), field messages plus a summary that focuses the field, and service errors added by field name. - Display and window components (panels, tiles, badges, chips, money, tabs with Alt+1..9, steps, dialog, side drawer and DrawerService). - KhIconToolbar that keeps one line and moves less used commands into the "..." menu, KhDocHead, and the RecordPage/DocumentPage/MasterDataPage bases with standard commands, shortcuts and save/cancel/delete flow (#27, #29). - Development-only component catalog and sample document page. - Profile: personal data, password change that ends other sessions, TOTP enable/disable and recovery codes through ProfileService (#31). Refs #27 #29 #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.5 KiB
Plaintext
83 lines
2.5 KiB
Plaintext
@inject IJSRuntime JS
|
|
|
|
@* A modal dialog (SPEC §10.7): title with icon, content, buttons at the bottom right. Escape and the close button
|
|
call OnClose; the focus moves into the dialog when it opens. *@
|
|
@if (Open)
|
|
{
|
|
<div class="overlay" @onkeydown="OnKeyDownAsync">
|
|
<div class="dialog kh-dialog @SizeClass" role="dialog" aria-modal="true" aria-labelledby="@(_id + "-t")" @ref="_dialog">
|
|
<div class="dh">
|
|
@if (Icon is not null)
|
|
{
|
|
<KhIcon Name="@Icon" />
|
|
}
|
|
<span class="grow" id="@(_id + "-t")">@Title</span>
|
|
<button type="button" class="ib kh-close" aria-label="@T["Common.Close"]" @onclick="CloseAsync"><KhIcon Name="x" /></button>
|
|
</div>
|
|
<div class="db">@ChildContent</div>
|
|
@if (Footer is not null)
|
|
{
|
|
<div class="df">@Footer</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private static int _next;
|
|
private readonly string _id = "kh-dlg" + Interlocked.Increment(ref _next).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
private ElementReference _dialog;
|
|
private bool _wasOpen;
|
|
|
|
/// <summary>Whether the dialog is shown.</summary>
|
|
[Parameter]
|
|
public bool Open { get; set; }
|
|
|
|
/// <summary>The title.</summary>
|
|
[Parameter]
|
|
public string? Title { get; set; }
|
|
|
|
/// <summary>The icon before the title.</summary>
|
|
[Parameter]
|
|
public string? Icon { get; set; }
|
|
|
|
/// <summary>The width: <c>sm</c> (420 px), <c>md</c> (640 px), <c>lg</c> (860 px).</summary>
|
|
[Parameter]
|
|
public string Size { get; set; } = "md";
|
|
|
|
/// <summary>Called by Escape and the close button.</summary>
|
|
[Parameter]
|
|
public EventCallback OnClose { get; set; }
|
|
|
|
/// <summary>The content.</summary>
|
|
[Parameter]
|
|
public RenderFragment? ChildContent { get; set; }
|
|
|
|
/// <summary>The buttons.</summary>
|
|
[Parameter]
|
|
public RenderFragment? Footer { get; set; }
|
|
|
|
private string SizeClass => "kh-" + Size;
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (Open && !_wasOpen)
|
|
{
|
|
await JS.InvokeVoidAsync("khaemhat.focusFirst", _dialog);
|
|
}
|
|
|
|
_wasOpen = Open;
|
|
}
|
|
|
|
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
|
{
|
|
if (e.Key == "Escape")
|
|
{
|
|
await CloseAsync();
|
|
}
|
|
}
|
|
|
|
private Task CloseAsync() => OnClose.InvokeAsync();
|
|
}
|