Files
decePubClient/Components/Daisy/Actions/DFab.razor
T

53 lines
2.3 KiB
Plaintext
Raw Normal View History

@inherits DComponentBase
@* daisyUI FAB: https://daisyui.com/components/fab/ . Opening is daisyUI's own :focus-within rule (there is no
open-state class): the trigger is the focusable first child, and focus moving out of the FAB closes it. The order
of the children matters to daisyUI: trigger, then Close or MainAction, then the speed-dial items (ChildContent,
e.g. DButton Size="DSize.Lg" Shape="DButtonShape.Circle", optionally inside a <div> with a text label). *@
<div @attributes="AdditionalAttributes" class="@CssClass">
<div tabindex="0" role="button" aria-label="@LabelText" class="@Cx("btn btn-lg btn-circle", ColorClass, TriggerClass)">
@Trigger
</div>
@if (Close is not null)
{
<div class="fab-close">@Close</div>
}
@if (MainAction is not null)
{
<div class="fab-main-action">@MainAction</div>
}
@ChildContent
</div>
@code {
/// <summary>Content of the button shown while closed, usually an icon.</summary>
[Parameter] public RenderFragment Trigger { get; set; }
/// <summary>Accessible name of the trigger (aria-label), since it usually holds only an icon.</summary>
[Parameter] public string LabelText { get; set; }
[Parameter] public DColor Color { get; set; } = DColor.Primary;
[Parameter] public string TriggerClass { get; set; }
/// <summary>Replaces the trigger while open; clicking it closes the FAB. Not focusable, e.g. a text label and a
/// &lt;span class="btn btn-circle btn-lg"&gt;.</summary>
[Parameter] public RenderFragment Close { get; set; }
/// <summary>Replaces the trigger while open with a main action, e.g. a label and a button.</summary>
[Parameter] public RenderFragment MainAction { get; set; }
/// <summary>The speed-dial items.</summary>
[Parameter] public RenderFragment ChildContent { get; set; }
/// <summary>Arrange the items in a quarter circle (fab-flower) instead of a column.</summary>
[Parameter] public bool Flower { get; set; }
string CssClass => Cx("fab", Flower ? "fab-flower" : null, Class);
string ColorClass => Color switch
{
DColor.Neutral => "btn-neutral",
DColor.Primary => "btn-primary",
DColor.Secondary => "btn-secondary",
DColor.Accent => "btn-accent",
DColor.Info => "btn-info",
DColor.Success => "btn-success",
DColor.Warning => "btn-warning",
DColor.Error => "btn-error",
_ => null
};
}