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
This commit is contained in:
1 parent
8e03d12a3e
commit
90e4b9200c
127 files changed
+6962
-17
No files matched your search
@@ -0,0 +1,74 @@
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Button: https://daisyui.com/components/button/ . Renders an <a> when Href is set. *@
|
||||
@if (Href is null)
|
||||
{
|
||||
<button @attributes="AdditionalAttributes" type="@Type" class="@CssClass" disabled="@Disabled" @onclick="OnClick">
|
||||
@ChildContent
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a @attributes="AdditionalAttributes" href="@(Disabled ? null : Href)" class="@CssClass" role="button"
|
||||
aria-disabled="@(Disabled ? "true" : null)" tabindex="@(Disabled ? "-1" : null)" @onclick="OnClick">
|
||||
@ChildContent
|
||||
</a>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
[Parameter] public DColor Color { get; set; }
|
||||
[Parameter] public DButtonVariant Variant { get; set; }
|
||||
[Parameter] public DSize Size { get; set; }
|
||||
[Parameter] public DButtonShape Shape { get; set; }
|
||||
/// <summary>Pressed look (btn-active); the neo theme renders it inset.</summary>
|
||||
[Parameter] public bool Active { get; set; }
|
||||
[Parameter] public bool Disabled { get; set; }
|
||||
[Parameter] public string Type { get; set; } = "button";
|
||||
[Parameter] public string Href { get; set; }
|
||||
[Parameter] public EventCallback<MouseEventArgs> OnClick { get; set; }
|
||||
|
||||
string CssClass => Cx("btn", ColorClass, VariantClass, SizeClass, ShapeClass,
|
||||
Active ? "btn-active" : null, Disabled && Href is not null ? "btn-disabled" : 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
|
||||
};
|
||||
|
||||
string VariantClass => Variant switch
|
||||
{
|
||||
DButtonVariant.Outline => "btn-outline",
|
||||
DButtonVariant.Dash => "btn-dash",
|
||||
DButtonVariant.Soft => "btn-soft",
|
||||
DButtonVariant.Ghost => "btn-ghost",
|
||||
DButtonVariant.Link => "btn-link",
|
||||
_ => null
|
||||
};
|
||||
|
||||
string SizeClass => Size switch
|
||||
{
|
||||
DSize.Xs => "btn-xs",
|
||||
DSize.Sm => "btn-sm",
|
||||
DSize.Lg => "btn-lg",
|
||||
DSize.Xl => "btn-xl",
|
||||
_ => null
|
||||
};
|
||||
|
||||
string ShapeClass => Shape switch
|
||||
{
|
||||
DButtonShape.Wide => "btn-wide",
|
||||
DButtonShape.Block => "btn-block",
|
||||
DButtonShape.Square => "btn-square",
|
||||
DButtonShape.Circle => "btn-circle",
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace decePubClient.Components.Daisy.Actions;
|
||||
|
||||
public enum DButtonVariant
|
||||
{
|
||||
Default,
|
||||
Outline,
|
||||
Dash,
|
||||
Soft,
|
||||
Ghost,
|
||||
Link
|
||||
}
|
||||
|
||||
public enum DButtonShape
|
||||
{
|
||||
Default,
|
||||
Wide,
|
||||
Block,
|
||||
Square,
|
||||
Circle
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Dropdown: https://daisyui.com/components/dropdown/ . The open state lives in C# (@bind-IsOpen):
|
||||
dropdown-open shows the content and dropdown-close keeps the focus-within rule from showing it while closed.
|
||||
While open, a transparent full-screen layer under the content closes it on an outside click; Escape closes it
|
||||
too. With Hover the CSS hover rule opens it instead. *@
|
||||
<div @attributes="AdditionalAttributes" class="@CssClass" @onkeydown="OnKeyDown">
|
||||
<div role="button" tabindex="0" class="@TriggerClass" aria-haspopup="true" aria-expanded="@(IsOpen ? "true" : "false")"
|
||||
@onclick="Toggle">
|
||||
@Trigger
|
||||
</div>
|
||||
@if (IsOpen)
|
||||
{
|
||||
<div class="fixed inset-0 z-[998] cursor-default" aria-hidden="true" @onclick="Close"></div>
|
||||
}
|
||||
<div tabindex="-1" class="@Cx("dropdown-content z-[999]", ContentClass)" @onclick="OnContentClick">
|
||||
@ChildContent
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public RenderFragment Trigger { get; set; }
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
[Parameter] public bool IsOpen { get; set; }
|
||||
[Parameter] public EventCallback<bool> IsOpenChanged { get; set; }
|
||||
[Parameter] public DDropdownPlacement Placement { get; set; }
|
||||
[Parameter] public DDropdownAlign Align { get; set; }
|
||||
/// <summary>Open on hover (dropdown-hover) as well as on click.</summary>
|
||||
[Parameter] public bool Hover { get; set; }
|
||||
/// <summary>Close after any click inside the content, e.g. on a menu item.</summary>
|
||||
[Parameter] public bool CloseOnContentClick { get; set; }
|
||||
[Parameter] public string TriggerClass { get; set; }
|
||||
[Parameter] public string ContentClass { get; set; }
|
||||
|
||||
string CssClass => Cx("dropdown", PlacementClass, AlignClass,
|
||||
IsOpen ? "dropdown-open" : Hover ? "dropdown-hover" : "dropdown-close", Class);
|
||||
|
||||
string PlacementClass => Placement switch
|
||||
{
|
||||
DDropdownPlacement.Top => "dropdown-top",
|
||||
DDropdownPlacement.Left => "dropdown-left",
|
||||
DDropdownPlacement.Right => "dropdown-right",
|
||||
_ => null
|
||||
};
|
||||
|
||||
string AlignClass => Align switch
|
||||
{
|
||||
DDropdownAlign.Center => "dropdown-center",
|
||||
DDropdownAlign.End => "dropdown-end",
|
||||
_ => null
|
||||
};
|
||||
|
||||
Task Toggle() => SetOpen(!IsOpen);
|
||||
|
||||
Task Close() => SetOpen(false);
|
||||
|
||||
Task OnContentClick() => CloseOnContentClick ? SetOpen(false) : Task.CompletedTask;
|
||||
|
||||
Task OnKeyDown(KeyboardEventArgs e) => e.Key == "Escape" && IsOpen ? SetOpen(false) : Task.CompletedTask;
|
||||
|
||||
async Task SetOpen(bool isOpen)
|
||||
{
|
||||
IsOpen = isOpen;
|
||||
await IsOpenChanged.InvokeAsync(isOpen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace decePubClient.Components.Daisy.Actions;
|
||||
|
||||
/// <summary>Which side of the trigger the content opens on; Bottom is daisyUI's default.</summary>
|
||||
public enum DDropdownPlacement
|
||||
{
|
||||
Bottom,
|
||||
Top,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
/// <summary>How the content lines up with the trigger along that side; Start is daisyUI's default.</summary>
|
||||
public enum DDropdownAlign
|
||||
{
|
||||
Start,
|
||||
Center,
|
||||
End
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
@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
|
||||
/// <span class="btn btn-circle btn-lg">.</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
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Modal: https://daisyui.com/components/modal/ . Always rendered; the open state lives in C# (@bind-IsOpen)
|
||||
and shows as modal-open. On opening, the box takes the focus (Blazor's FocusAsync) so that Escape, handled on the
|
||||
root, closes it; the backdrop button stretches over the area outside the box and closes it on click. *@
|
||||
<div @attributes="AdditionalAttributes" role="dialog" aria-modal="true" aria-labelledby="@(Heading is null ? null : uid)"
|
||||
class="@CssClass" @onkeydown="OnKeyDown">
|
||||
<div @ref="box" tabindex="-1" class="@Cx("modal-box focus:outline-none", BoxClass)">
|
||||
@if (Heading is not null)
|
||||
{
|
||||
<h3 id="@uid" class="text-lg font-bold">@Heading</h3>
|
||||
}
|
||||
@ChildContent
|
||||
@if (Actions is not null)
|
||||
{
|
||||
<div class="modal-action">
|
||||
@Actions
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (CloseOnBackdrop)
|
||||
{
|
||||
<div class="modal-backdrop">
|
||||
<button type="button" @onclick="Close">@CloseText</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public RenderFragment Heading { get; set; }
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
[Parameter] public RenderFragment Actions { get; set; }
|
||||
[Parameter] public bool IsOpen { get; set; }
|
||||
[Parameter] public EventCallback<bool> IsOpenChanged { get; set; }
|
||||
[Parameter] public DModalPlacement Placement { get; set; }
|
||||
/// <summary>Close on a click outside the box (renders the modal-backdrop).</summary>
|
||||
[Parameter] public bool CloseOnBackdrop { get; set; } = true;
|
||||
/// <summary>Text of the invisible backdrop button, read by screen readers.</summary>
|
||||
[Parameter] public string CloseText { get; set; } = "close";
|
||||
[Parameter] public string BoxClass { get; set; }
|
||||
|
||||
readonly string uid = "d" + Guid.NewGuid().ToString("N")[..8];
|
||||
ElementReference box;
|
||||
bool wasOpen;
|
||||
bool focusPending;
|
||||
|
||||
string CssClass => Cx("modal", PlacementClass, IsOpen ? "modal-open" : null, Class);
|
||||
|
||||
string PlacementClass => Placement switch
|
||||
{
|
||||
DModalPlacement.Top => "modal-top",
|
||||
DModalPlacement.Bottom => "modal-bottom",
|
||||
DModalPlacement.Start => "modal-start",
|
||||
DModalPlacement.End => "modal-end",
|
||||
_ => null
|
||||
};
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (IsOpen && !wasOpen)
|
||||
focusPending = true;
|
||||
wasOpen = IsOpen;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!focusPending)
|
||||
return;
|
||||
focusPending = false;
|
||||
await box.FocusAsync();
|
||||
}
|
||||
|
||||
Task Close() => SetOpen(false);
|
||||
|
||||
Task OnKeyDown(KeyboardEventArgs e) => e.Key == "Escape" && IsOpen ? SetOpen(false) : Task.CompletedTask;
|
||||
|
||||
async Task SetOpen(bool isOpen)
|
||||
{
|
||||
IsOpen = isOpen;
|
||||
wasOpen = isOpen;
|
||||
await IsOpenChanged.InvokeAsync(isOpen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace decePubClient.Components.Daisy.Actions;
|
||||
|
||||
/// <summary>Where the box sits on the screen; Middle is daisyUI's default.</summary>
|
||||
public enum DModalPlacement
|
||||
{
|
||||
Middle,
|
||||
Top,
|
||||
Bottom,
|
||||
Start,
|
||||
End
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Swap: https://daisyui.com/components/swap/ . A label around daisyUI's hidden checkbox: clicking anywhere on
|
||||
it toggles the checkbox, whose state is bound to Active (@bind-Active); On shows while checked, Off otherwise. *@
|
||||
<label @attributes="AdditionalAttributes" class="@CssClass">
|
||||
<input type="checkbox" checked="@Active" disabled="@Disabled" aria-label="@LabelText" @onchange="OnChange" />
|
||||
<div class="swap-on">@On</div>
|
||||
<div class="swap-off">@Off</div>
|
||||
</label>
|
||||
|
||||
@code {
|
||||
[Parameter] public RenderFragment On { get; set; }
|
||||
[Parameter] public RenderFragment Off { get; set; }
|
||||
[Parameter] public bool Active { get; set; }
|
||||
[Parameter] public EventCallback<bool> ActiveChanged { get; set; }
|
||||
[Parameter] public DSwapEffect Effect { get; set; }
|
||||
[Parameter] public bool Disabled { get; set; }
|
||||
/// <summary>Accessible name of the checkbox (aria-label), for swaps that show only icons.</summary>
|
||||
[Parameter] public string LabelText { get; set; }
|
||||
|
||||
string CssClass => Cx("swap", EffectClass, Disabled ? "cursor-not-allowed opacity-50" : null, Class);
|
||||
|
||||
string EffectClass => Effect switch
|
||||
{
|
||||
DSwapEffect.Rotate => "swap-rotate",
|
||||
DSwapEffect.Flip => "swap-flip",
|
||||
_ => null
|
||||
};
|
||||
|
||||
async Task OnChange(ChangeEventArgs e)
|
||||
{
|
||||
Active = e.Value is true;
|
||||
await ActiveChanged.InvokeAsync(Active);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace decePubClient.Components.Daisy.Actions;
|
||||
|
||||
public enum DSwapEffect
|
||||
{
|
||||
None,
|
||||
Rotate,
|
||||
Flip
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
@inherits DComponentBase
|
||||
|
||||
@* daisyUI Theme controller: https://daisyui.com/components/theme-controller/ . While checked, the page uses the theme
|
||||
named in Value (daisyUI's :root:has(.theme-controller:checked) rule). The app itself sets data-theme from C#, so
|
||||
this exists for completeness. Style it with class="toggle", "checkbox", "radio", "btn" and so on. For a radio
|
||||
group, pass the same name attribute to each and set Checked from one shared value: a radio raises no change event
|
||||
when another one unchecks it. *@
|
||||
<input @attributes="AdditionalAttributes" type="@(Radio ? "radio" : "checkbox")" value="@Value" class="@CssClass"
|
||||
checked="@Checked" @onchange="OnChange" />
|
||||
|
||||
@code {
|
||||
/// <summary>A daisyUI theme name, e.g. "neo-dark".</summary>
|
||||
[Parameter] public string Value { get; set; }
|
||||
[Parameter] public bool Checked { get; set; }
|
||||
[Parameter] public EventCallback<bool> CheckedChanged { get; set; }
|
||||
/// <summary>Render a radio instead of a checkbox.</summary>
|
||||
[Parameter] public bool Radio { get; set; }
|
||||
|
||||
string CssClass => Cx("theme-controller", Class);
|
||||
|
||||
async Task OnChange(ChangeEventArgs e)
|
||||
{
|
||||
// A checkbox reports its checked state; a radio only reports its value when it becomes checked.
|
||||
Checked = Radio || e.Value is true;
|
||||
await CheckedChanged.InvokeAsync(Checked);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user