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
100 lines
3.3 KiB
Plaintext
100 lines
3.3 KiB
Plaintext
@inherits DComponentBase
|
|
|
|
@* daisyUI Pagination: https://daisyui.com/components/pagination/ . A join of btn join-items; the page is 1-based
|
|
(@bind-Current) and the current one is btn-active with aria-current="page". Beyond Siblings pages on each side of
|
|
the current one, runs of pages collapse into a disabled ellipsis; the first and last pages always show. *@
|
|
<div @attributes="AdditionalAttributes" class="@Cx("join", Direction == DDirection.Vertical ? "join-vertical" : null, Class)">
|
|
@if (ShowPreviousNext)
|
|
{
|
|
<button type="button" class="@ItemClass(false)" disabled="@(Current <= 1)" aria-label="@PreviousAriaLabel"
|
|
@onclick="() => Go(Current - 1)">
|
|
@PreviousText
|
|
</button>
|
|
}
|
|
@foreach (var number in Pages())
|
|
{
|
|
if (number == 0)
|
|
{
|
|
<button type="button" class="@Cx(ItemClass(false), "btn-disabled")" disabled aria-hidden="true">@EllipsisText</button>
|
|
}
|
|
else
|
|
{
|
|
var target = number;
|
|
<button type="button" class="@ItemClass(number == Current)" aria-current="@(number == Current ? "page" : null)"
|
|
@onclick="() => Go(target)">
|
|
@number
|
|
</button>
|
|
}
|
|
}
|
|
@if (ShowPreviousNext)
|
|
{
|
|
<button type="button" class="@ItemClass(false)" disabled="@(Current >= Count)" aria-label="@NextAriaLabel"
|
|
@onclick="() => Go(Current + 1)">
|
|
@NextText
|
|
</button>
|
|
}
|
|
</div>
|
|
|
|
@code {
|
|
/// <summary>The number of pages.</summary>
|
|
[Parameter] public int Count { get; set; }
|
|
/// <summary>The current page, from 1 to Count.</summary>
|
|
[Parameter] public int Current { get; set; } = 1;
|
|
[Parameter] public EventCallback<int> CurrentChanged { get; set; }
|
|
/// <summary>How many pages to show on each side of the current one before collapsing the rest into "…".</summary>
|
|
[Parameter] public int Siblings { get; set; } = 1;
|
|
[Parameter] public DSize Size { get; set; }
|
|
[Parameter] public DDirection Direction { get; set; }
|
|
[Parameter] public bool ShowPreviousNext { get; set; } = true;
|
|
[Parameter] public string PreviousText { get; set; } = "«";
|
|
[Parameter] public string NextText { get; set; } = "»";
|
|
[Parameter] public string PreviousAriaLabel { get; set; } = "Previous page";
|
|
[Parameter] public string NextAriaLabel { get; set; } = "Next page";
|
|
[Parameter] public string EllipsisText { get; set; } = "…";
|
|
|
|
string ItemClass(bool active) => Cx("join-item btn", SizeClass, active ? "btn-active" : null);
|
|
|
|
string SizeClass => Size switch
|
|
{
|
|
DSize.Xs => "btn-xs",
|
|
DSize.Sm => "btn-sm",
|
|
DSize.Lg => "btn-lg",
|
|
DSize.Xl => "btn-xl",
|
|
_ => null
|
|
};
|
|
|
|
// The pages to show in order, with 0 standing for an ellipsis. A gap of a single page shows that page instead.
|
|
IEnumerable<int> Pages()
|
|
{
|
|
if (Count <= 0)
|
|
yield break;
|
|
var current = Math.Clamp(Current, 1, Count);
|
|
var siblings = Math.Clamp(Siblings, 0, Count);
|
|
var from = Math.Max(1, current - siblings);
|
|
var to = Math.Min(Count, current + siblings);
|
|
if (from > 1)
|
|
{
|
|
yield return 1;
|
|
if (from > 2)
|
|
yield return from == 3 ? 2 : 0;
|
|
}
|
|
for (var page = from; page <= to; page++)
|
|
yield return page;
|
|
if (to < Count)
|
|
{
|
|
if (to < Count - 1)
|
|
yield return to == Count - 2 ? Count - 1 : 0;
|
|
yield return Count;
|
|
}
|
|
}
|
|
|
|
async Task Go(int page)
|
|
{
|
|
page = Math.Clamp(page, 1, Math.Max(Count, 1));
|
|
if (page == Current)
|
|
return;
|
|
Current = page;
|
|
await CurrentChanged.InvokeAsync(page);
|
|
}
|
|
}
|