Files
decePubClient/Components/Daisy/Layout/DDrawer.razor
T
thepraandClaude Opus 5.5 90e4b9200c Add D-prefixed Blazor wrappers for every daisyUI 5 component
Components/Daisy/ wraps all 69 components in daisyUI's llms.txt, grouped by
daisyUI's categories (Actions, DataDisplay, Navigation, Feedback, DataInput,
Layout, Mockup), with part components where daisyUI has repeating parts (DTab,
DMenuItem, DTimelineItem, ...).
- Each enum maps to whole literal class names in a switch, so Tailwind's scanner
  generates them. Nothing is concatenated.
- Value-holding fields derive from DInputBase<TValue>, Blazor's InputBase, so
  @bind-Value and EditForm validation work. Invalid fields get the component's
  *-error class.
- Open and active state lives in C# (@bind-IsOpen, @bind-Active) and is rendered
  with daisyUI's *-open modifiers. DDropdown adds an outside-click layer and
  Escape. No component uses JS interop.
- The one exception is DCalendar, which wraps the Cally web component, vendored
  as wwwroot/vendor/cally.js (0.9.2, MIT).

/styleguide (not linked) renders every component in all its colours, sizes and
states, with a theme and hue picker that previews without saving.

neo.css follows what the styleguide showed:
- select keeps daisyUI's arrow;
- skeleton-text isn't sunk;
- the phone mockup and dock are raised;
- active menu items and OTP digits are inset;
- a joined accordion is raised as one block.
The primary, secondary and accent colours are deeper, so they still read as
text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
2026-10-03 12:01:42 +02:00

61 lines
2.4 KiB
Plaintext

@inherits DComponentBase
@* daisyUI Drawer: https://daisyui.com/components/drawer/ . daisyUI's hidden drawer-toggle checkbox is bound to IsOpen
(@bind-IsOpen); the overlay label toggles it natively, Escape closes it, and any
<label for="{ToggleId}" class="btn drawer-button"> in the content toggles it too. Put the navbar and footer in
ChildContent. *@
<div @attributes="AdditionalAttributes" class="@CssClass" @onkeydown="OnKeyDown">
<input id="@toggleId" type="checkbox" class="drawer-toggle" checked="@IsOpen" @onchange="OnChange" />
<div class="@Cx("drawer-content", ContentClass)">
@ChildContent
</div>
<div class="@Cx("drawer-side", SideClass)">
<label for="@toggleId" aria-label="@CloseText" class="drawer-overlay"></label>
@Side
</div>
</div>
@code {
/// <summary>The page content, beside the side.</summary>
[Parameter] public RenderFragment ChildContent { get; set; }
/// <summary>The sidebar, e.g. &lt;ul class="menu bg-base-200 min-h-full w-80 p-4"&gt;.</summary>
[Parameter] public RenderFragment Side { get; set; }
[Parameter] public bool IsOpen { get; set; }
[Parameter] public EventCallback<bool> IsOpenChanged { get; set; }
/// <summary>Put the side on the right (drawer-end).</summary>
[Parameter] public bool End { get; set; }
[Parameter] public DDrawerOpenFrom OpenFrom { get; set; }
/// <summary>The checkbox id, for drawer-button labels; defaults to a per-instance id.</summary>
[Parameter] public string ToggleId { get; set; }
/// <summary>Accessible name of the overlay, which closes the side.</summary>
[Parameter] public string CloseText { get; set; } = "close sidebar";
[Parameter] public string ContentClass { get; set; }
[Parameter] public string SideClass { get; set; }
readonly string uid = "d" + Guid.NewGuid().ToString("N")[..8];
string toggleId => ToggleId ?? uid;
string CssClass => Cx("drawer", End ? "drawer-end" : null, OpenFromClass, Class);
string OpenFromClass => OpenFrom switch
{
DDrawerOpenFrom.Sm => "sm:drawer-open",
DDrawerOpenFrom.Md => "md:drawer-open",
DDrawerOpenFrom.Lg => "lg:drawer-open",
DDrawerOpenFrom.Xl => "xl:drawer-open",
DDrawerOpenFrom.Always => "drawer-open",
_ => null
};
Task OnChange(ChangeEventArgs e) => SetOpen(e.Value is true);
Task OnKeyDown(KeyboardEventArgs e) => e.Key == "Escape" && IsOpen ? SetOpen(false) : Task.CompletedTask;
async Task SetOpen(bool isOpen)
{
IsOpen = isOpen;
await IsOpenChanged.InvokeAsync(isOpen);
}
}