tablo-ui 0.4.0

The Topcoat components Tablo renders: primitives synced from topcoat-ui-registry, plus its own composites.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
// SYNC: topcoat-ui-registry@0.10.0 sha256:08444f46d98808fcd942dac3db5a400d11116f38508aa3e2cd67c1ea6269a393 — do not hand-edit. Sync via `cargo xtask sync-topcoat-ui` (ADR-0007).
use topcoat::{
    Result,
    icon::{icon, iconify::iconify_icon},
    runtime::Expr,
    view::{Attributes, Child, Class, StaticClass, View, attributes, class, component, view},
};

use super::{
    button::{ButtonSize, ButtonVariant, button},
    input::input,
    separator::separator,
    sheet::{SheetSide, sheet, sheet_content},
    skeleton::skeleton,
};

/// The edge of the page occupied by a sidebar.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum SidebarSide {
    #[default]
    Left,
    Right,
}

impl SidebarSide {
    fn name(self) -> &'static str {
        match self {
            Self::Left => "left",
            Self::Right => "right",
        }
    }

    fn sheet(self) -> SheetSide {
        match self {
            Self::Left => SheetSide::Left,
            Self::Right => SheetSide::Right,
        }
    }
}

/// The desktop sidebar's surface and its relationship to the page.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum SidebarVariant {
    /// A panel separated from the page by a border.
    #[default]
    Sidebar,
    /// A rounded panel with space around it.
    Floating,
    /// A sidebar beside a rounded [`sidebar_inset`] content surface.
    Inset,
}

impl SidebarVariant {
    fn name(self) -> &'static str {
        match self {
            Self::Sidebar => "sidebar",
            Self::Floating => "floating",
            Self::Inset => "inset",
        }
    }
}

/// How the desktop sidebar behaves when its `open` expression is false.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum SidebarCollapsible {
    /// Hide the panel and release its space to the page.
    #[default]
    Offcanvas,
    /// Keep a narrow strip of menu icons visible.
    Icon,
    /// Keep the desktop panel expanded.
    None,
}

impl SidebarCollapsible {
    fn name(self) -> &'static str {
        match self {
            Self::Offcanvas => "offcanvas",
            Self::Icon => "icon",
            Self::None => "none",
        }
    }
}

/// The flex layout surrounding a sidebar and the page content.
///
/// On desktop, the page content scrolls within the viewport-height layout.
///
/// Set `--sidebar-width`, `--sidebar-width-mobile` and `--sidebar-width-icon`
/// through `attrs` to customize the widths. Place a right sidebar after the
/// page content. State belongs to the caller, which passes expressions to
/// [`sidebar`] and event handlers to [`sidebar_trigger`] and [`sidebar_rail`].
#[component]
pub async fn sidebar_provider(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="provider"
            class=(class!(
                "flex min-h-svh w-full md:h-svh md:overflow-hidden [--sidebar-width:16rem] [--sidebar-width-mobile:18rem] [--sidebar-width-icon:3rem] md:has-[[data-variant=inset]]:bg-sidebar",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </div>
    })
}

// Ordinary components nested in the panel inherit its palette too. The
// scoped aliases keep buttons, inputs and captions independent of the page.
const PANEL_THEME: StaticClass = class!(
    "[--background:var(--sidebar)] [--foreground:var(--sidebar-foreground)] \
     [--card:var(--sidebar)] [--card-foreground:var(--sidebar-foreground)] \
     [--primary:var(--sidebar-primary)] \
     [--primary-foreground:var(--sidebar-primary-foreground)] \
     [--border:var(--sidebar-border)] [--ring:var(--sidebar-ring)] \
     [--muted-foreground:color-mix(in_oklab,var(--sidebar-foreground)_70%,transparent)]",
);

/// A desktop panel that becomes a sheet over the page below `md` (48rem).
///
/// The `--sidebar-*` theme tokens control its colors independently of cards,
/// sheets and page content. Nested controls inherit the sidebar palette.
///
/// `open` controls desktop expansion. `mobile_open` independently controls
/// the mobile sheet, so it can start closed while desktop starts expanded.
/// Pass runtime expressions reading the caller's signals to make both live.
/// Header, content and footer children are rendered once and shared between
/// viewport sizes, preserving their inputs and signal identities.
///
/// `attrs` apply to the outer wrapper. `sheet_attrs` apply to the sheet and
/// accept a label, an ID, and event handlers for Escape or backdrop dismissal.
/// Include a close button in the mobile header. Like [`sheet`], this is a
/// visual overlay; focus trapping requires additional application scripting.
#[component]
pub async fn sidebar(
    #[into]
    #[default(true.into())]
    open: Expr<bool>,
    #[into]
    #[default(false.into())]
    mobile_open: Expr<bool>,
    #[default] side: SidebarSide,
    #[default] variant: SidebarVariant,
    #[default] collapsible: SidebarCollapsible,
    #[default] mut attrs: Attributes,
    #[default] mut sheet_attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    let open = if collapsible == SidebarCollapsible::None {
        true.into()
    } else {
        open
    };
    let collapse = collapsible.name();

    Ok(view! {
        <aside
            data-sidebar="sidebar"
            data-side=(side.name())
            data-variant=(variant.name())
            :data-state=$(if open { "expanded" } else { "collapsed" })
            :data-collapsible=$(if open { "" } else { collapse })
            class=(class!(
                "group/sidebar relative w-0 shrink-0 text-sidebar-foreground md:sticky md:top-0 md:h-svh md:w-(--sidebar-width) md:self-start md:transition-[width] md:duration-200 md:data-[collapsible=offcanvas]:w-0 motion-reduce:transition-none",
                if variant == SidebarVariant::Floating {
                    "md:p-2 md:data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+1rem+2px)] md:data-[collapsible=offcanvas]:px-0"
                } else {
                    "md:data-[collapsible=icon]:w-(--sidebar-width-icon)"
                },
                "md:py-2" if variant == SidebarVariant::Inset,
                attrs.remove("class"),
            ))
            (attrs)
        >
            sheet(
                open: mobile_open,
                attrs: attributes! {
                    role="navigation"
                    aria-label="Sidebar"
                    class=(class!(
                        "md:relative md:inset-auto md:flex md:overflow-visible md:bg-transparent md:opacity-100 md:backdrop-blur-none md:starting:open:opacity-100 md:transition-none md:group-data-[collapsible=offcanvas]/sidebar:invisible motion-reduce:transition-none",
                        sheet_attrs.remove("class"),
                    ))
                    (sheet_attrs)
                },
                sheet_content(
                    side: side.sheet(),
                    attrs: attributes! {
                        data-sidebar="panel"
                        class=(class!(
                            PANEL_THEME,
                            "relative [&]:w-(--sidebar-width-mobile) [&]:max-w-[calc(100vw-3rem)] [&]:gap-0 [&]:overflow-hidden [&]:p-0 md:[&]:w-full md:[&]:max-w-none md:[&]:translate-x-0 md:[&]:transition-none motion-reduce:transition-none",
                            match variant {
                                SidebarVariant::Sidebar => "md:shadow-none",
                                SidebarVariant::Floating => "md:rounded-xl md:border md:shadow-sm",
                                SidebarVariant::Inset => "md:border-0 md:bg-transparent md:shadow-none",
                            },
                        ))
                    },
                    (child)
                )
            )
        </aside>
    })
}

/// A sidebar toggle button. Pass its signal update as an `@click` attribute.
///
/// `open` controls the accessible expanded state. Set `aria-controls` in
/// `attrs` to the controlled panel's ID. Responsive triggers can use separate
/// desktop and mobile expressions and handlers.
#[component]
pub async fn sidebar_trigger(
    #[into]
    #[default(true.into())]
    open: Expr<bool>,
    #[default] attrs: Attributes,
) -> Result<impl View> {
    Ok(view! {
        button(
            variant: ButtonVariant::Ghost,
            size: ButtonSize::Icon,
            attrs: attributes! {
                type="button"
                data-sidebar="trigger"
                aria-label="Toggle sidebar"
                :aria-expanded=$(if open { "true" } else { "false" })
                (attrs)
            },
            icon(data: iconify_icon!("lucide:panel-left"))
        )
    })
}

/// A desktop edge button that toggles the sidebar on click.
///
/// Pass its signal update as an `@click` attribute.
#[component]
pub async fn sidebar_rail(
    #[into]
    #[default(true.into())]
    open: Expr<bool>,
    #[default] mut attrs: Attributes,
) -> Result<impl View> {
    Ok(view! {
        <button
            type="button"
            data-sidebar="rail"
            aria-label="Toggle sidebar"
            title="Toggle sidebar"
            :aria-expanded=$(if open { "true" } else { "false" })
            class=(class!(
                "absolute inset-y-0 z-10 hidden w-2 cursor-pointer outline-none after:absolute after:inset-y-0 after:w-px hover:after:bg-sidebar-border focus-visible:after:bg-sidebar-ring md:block group-data-[side=left]/sidebar:right-0 group-data-[side=left]/sidebar:after:right-0 group-data-[side=right]/sidebar:left-0 group-data-[side=right]/sidebar:after:left-0",
                attrs.remove("class"),
            ))
            (attrs)
        ></button>
    })
}

/// The page content beside a sidebar, scrollable independently on desktop.
///
/// An immediate [`sidebar_header`] child becomes a sticky toolbar. Its height
/// and bottom border match the sidebar header without extra classes.
#[component]
pub async fn sidebar_inset(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <main
            data-sidebar="inset"
            class=(class!(
                "relative flex min-w-0 flex-1 flex-col bg-background md:min-h-0 md:overflow-y-auto [&>[data-sidebar=header]]:sticky [&>[data-sidebar=header]]:top-0 [&>[data-sidebar=header]]:z-20 [&>[data-sidebar=header]]:flex-row [&>[data-sidebar=header]]:items-center [&>[data-sidebar=header]]:justify-start [&>[data-sidebar=header]]:gap-3 [&>[data-sidebar=header]]:bg-background [&>[data-sidebar=header]]:px-4 [&>[data-sidebar=header]>[aria-orientation=vertical]]:h-4 md:in-[[data-sidebar=provider]:has([data-variant=floating])]:my-[calc(--spacing(2)+1px)] md:in-[[data-sidebar=provider]:has([data-variant=inset])]:m-2 md:in-[[data-sidebar=provider]:has([data-variant=inset][data-side=left])]:ml-0 md:in-[[data-sidebar=provider]:has([data-variant=inset][data-side=right])]:mr-0 md:in-[[data-sidebar=provider]:has([data-variant=inset])]:rounded-xl md:in-[[data-sidebar=provider]:has([data-variant=inset])]:shadow-sm md:in-[[data-sidebar=provider]:has([data-variant=inset])]:ring-1 md:in-[[data-sidebar=provider]:has([data-variant=inset])]:ring-sidebar-border",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </main>
    })
}

/// A header for the sidebar or its page content.
///
/// Its height and divider stay fixed when menu buttons collapse to icons.
/// Inside [`sidebar_inset`], it lays out its children as a sticky toolbar.
#[component]
pub async fn sidebar_header(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="header"
            class=(class!(
                "flex h-14 shrink-0 flex-col justify-center gap-2 border-b border-border px-2",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </div>
    })
}

/// The fixed footer below the sidebar's scrolling content.
#[component]
pub async fn sidebar_footer(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="footer"
            class=(class!("flex shrink-0 flex-col gap-2 p-2", attrs.remove("class")))
            (attrs)
        >
            (child)
        </div>
    })
}

/// The scrollable region between the header and footer.
#[component]
pub async fn sidebar_content(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="content"
            class=(class!(
                "flex min-h-0 flex-1 flex-col gap-2 overflow-x-hidden overflow-y-auto overscroll-contain",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </div>
    })
}

/// A section containing a label, an optional action and related menu items.
#[component]
pub async fn sidebar_group(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="group"
            class=(class!(
                "relative flex min-w-0 flex-col gap-1 p-2",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </div>
    })
}

/// A group's caption, hidden when the desktop sidebar collapses to icons.
#[component]
pub async fn sidebar_group_label(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="group-label"
            class=(class!(
                "flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 md:group-data-[collapsible=icon]/sidebar:hidden",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </div>
    })
}

// Shared button styles for group and menu actions. Each sets its own position.
const ACTION: StaticClass = class!(
    "absolute flex size-6 items-center justify-center rounded-md text-sidebar-foreground/70 outline-none hover:bg-sidebar-accent/50 hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-sidebar-ring disabled:pointer-events-none disabled:opacity-50 md:group-data-[collapsible=icon]/sidebar:hidden [&_svg]:size-4",
);

/// An icon button beside the group label. Give it an accessible label.
#[component]
pub async fn sidebar_group_action(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <button
            type="button"
            data-sidebar="group-action"
            class=(class!(ACTION, "top-3 right-3", attrs.remove("class")))
            (attrs)
        >
            (child)
        </button>
    })
}

/// The body of a sidebar group.
#[component]
pub async fn sidebar_group_content(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="group-content"
            class=(class!("w-full text-sm", attrs.remove("class")))
            (attrs)
        >
            (child)
        </div>
    })
}

/// A list of sidebar menu items.
#[component]
pub async fn sidebar_menu(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <ul
            data-sidebar="menu"
            class=(class!("flex min-w-0 flex-col gap-1", attrs.remove("class")))
            (attrs)
        >
            (child)
        </ul>
    })
}

/// One menu row containing a button or link and optional actions or submenus.
#[component]
pub async fn sidebar_menu_item(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <li
            data-sidebar="menu-item"
            class=(class!("group/menu-item relative", attrs.remove("class")))
            (attrs)
        >
            (child)
        </li>
    })
}

/// A text input styled for a sidebar header or group.
#[component]
pub async fn sidebar_input(#[default] mut attrs: Attributes) -> Result<impl View> {
    Ok(view! {
        input(
            attrs: attributes! {
                data-sidebar="input"
                class=(class!(
                    "bg-background md:group-data-[collapsible=icon]/sidebar:hidden",
                    attrs.remove("class"),
                ))
                (attrs)
            }
        )
    })
}

/// A rule between sidebar sections.
#[component]
pub async fn sidebar_separator(#[default] attrs: Attributes) -> Result<impl View> {
    Ok(view! { separator(attrs: attributes! { data-sidebar="separator" (attrs) }) })
}

/// The visual style of a sidebar menu button.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum SidebarMenuButtonVariant {
    #[default]
    Default,
    Outline,
}

impl SidebarMenuButtonVariant {
    fn classes(self) -> StaticClass {
        match self {
            Self::Default => class!("border-transparent"),
            Self::Outline => class!("border-sidebar-border bg-sidebar shadow-xs"),
        }
    }
}

/// The size of a sidebar menu button.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum SidebarMenuButtonSize {
    Sm,
    #[default]
    Md,
    Lg,
}

impl SidebarMenuButtonSize {
    fn classes(self) -> StaticClass {
        match self {
            Self::Sm => class!("h-7 text-xs"),
            Self::Md => class!("h-8 text-sm"),
            Self::Lg => class!("h-12 text-sm"),
        }
    }
}

const MENU_BUTTON: StaticClass = class!(
    "flex w-full min-w-0 items-center gap-2 overflow-hidden rounded-md border px-2 text-left outline-none transition-colors hover:bg-sidebar-accent/50 hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-sidebar-ring disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground data-[active=true]:font-medium has-[+[data-sidebar=menu-action]]:pr-8 has-[+[data-sidebar=menu-badge]]:pr-8 [&>svg]:size-4 [&>svg]:shrink-0 [&>span:last-child]:truncate md:group-data-[collapsible=icon]/sidebar:size-8 md:group-data-[collapsible=icon]/sidebar:justify-center md:group-data-[collapsible=icon]/sidebar:p-0 md:group-data-[collapsible=icon]/sidebar:[&>span:last-child]:sr-only",
);

/// Classes for styling another element as a sidebar menu button.
///
/// Set `data-active="true"` for active styling. Put the label in a `<span>`
/// after the icon so it remains accessible when the sidebar collapses.
#[must_use]
pub fn sidebar_menu_button_variants(
    variant: SidebarMenuButtonVariant,
    size: SidebarMenuButtonSize,
) -> Class<(StaticClass, StaticClass, StaticClass)> {
    class!(MENU_BUTTON, variant.classes(), size.classes())
}

/// A menu action, or a navigation link when `href` is supplied.
///
/// Put an icon before a `<span>` containing the label. `tooltip` supplies a
/// native title hint for the icon-only state. `active` accepts a boolean or
/// runtime expression. Event handlers and other attributes are forwarded.
#[component]
pub async fn sidebar_menu_button(
    #[default] variant: SidebarMenuButtonVariant,
    #[default] size: SidebarMenuButtonSize,
    #[into]
    #[default(false.into())]
    active: Expr<bool>,
    #[default] href: Option<&str>,
    #[default] tooltip: Option<&str>,
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    let attrs = attributes! {
        data-sidebar="menu-button"
        :data-active=$(if active { "true" } else { "false" })
        :aria-current=$(active.then_some("page"))
        title=(tooltip)
        class=(class!(
            sidebar_menu_button_variants(variant, size),
            attrs.remove("class"),
        ))
        (attrs)
    };

    Ok(view! {
        if let Some(href) = href {
            <a href=(href) (attrs)>(child)</a>
        } else {
            <button type="button" (attrs)>(child)</button>
        }
    })
}

/// An independent action beside a menu button. Give it an accessible label.
#[component]
pub async fn sidebar_menu_action(
    #[default] show_on_hover: bool,
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <button
            type="button"
            data-sidebar="menu-action"
            class=(class!(
                ACTION,
                "top-1 right-1",
                "md:opacity-0 md:group-hover/menu-item:opacity-100 md:group-focus-within/menu-item:opacity-100" if show_on_hover,
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </button>
    })
}

/// A count or status beside a menu button.
#[component]
pub async fn sidebar_menu_badge(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <span
            data-sidebar="menu-badge"
            class=(class!(
                "pointer-events-none absolute top-1 right-1 flex h-6 min-w-6 items-center justify-center rounded-md px-1 text-xs tabular-nums text-sidebar-foreground/70 md:group-data-[collapsible=icon]/sidebar:hidden",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </span>
    })
}

/// A placeholder matching a menu row, optionally including an icon.
#[component]
pub async fn sidebar_menu_skeleton(
    #[default] show_icon: bool,
    #[default] mut attrs: Attributes,
) -> Result<impl View> {
    Ok(view! {
        <div
            data-sidebar="menu-skeleton"
            aria-hidden="true"
            class=(class!(
                "flex h-8 items-center gap-2 rounded-md px-2",
                attrs.remove("class"),
            ))
            (attrs)
        >
            if show_icon {
                skeleton(attrs: attributes! { class="size-4 shrink-0" })
            }
            skeleton(
                attrs: attributes! {
                    class="h-4 w-3/4 md:group-data-[collapsible=icon]/sidebar:hidden"
                }
            )
        </div>
    })
}

/// A nested menu, hidden when the sidebar collapses to icons.
#[component]
pub async fn sidebar_menu_sub(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <ul
            data-sidebar="menu-sub"
            class=(class!(
                "mx-3.5 flex min-w-0 flex-col gap-1 border-l border-sidebar-border px-2.5 py-1 md:group-data-[collapsible=icon]/sidebar:hidden",
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </ul>
    })
}

/// One row of a nested sidebar menu.
#[component]
pub async fn sidebar_menu_sub_item(
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <li
            data-sidebar="menu-sub-item"
            class=(class!("relative", attrs.remove("class")))
            (attrs)
        >
            (child)
        </li>
    })
}

/// A nested menu link. Pass its destination through the `href` attribute.
#[component]
pub async fn sidebar_menu_sub_button(
    #[into]
    #[default(false.into())]
    active: Expr<bool>,
    #[default] size: SidebarMenuButtonSize,
    #[default] mut attrs: Attributes,
    #[default] child: Child<'_>,
) -> Result<impl View> {
    Ok(view! {
        <a
            data-sidebar="menu-sub-button"
            :aria-current=$(active.then_some("page"))
            class=(class!(
                "flex min-w-0 items-center gap-2 rounded-md px-2 text-sidebar-foreground/70 outline-none hover:bg-sidebar-accent/50 hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-sidebar-ring aria-[current=page]:bg-sidebar-accent aria-[current=page]:text-sidebar-accent-foreground aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0 [&>span:last-child]:truncate",
                size.classes(),
                attrs.remove("class"),
            ))
            (attrs)
        >
            (child)
        </a>
    })
}