@c9up/nebula 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/atoms/Avatar.d.ts +36 -9
  2. package/dist/atoms/Avatar.js +66 -27
  3. package/dist/atoms/index.d.ts +1 -1
  4. package/dist/atoms/index.js +1 -1
  5. package/dist/lib/children.d.ts +30 -0
  6. package/dist/lib/motion.d.ts +10 -0
  7. package/dist/lib/motion.js +10 -0
  8. package/dist/molecules/Accordion.d.ts +36 -15
  9. package/dist/molecules/Accordion.js +68 -45
  10. package/dist/molecules/Breadcrumb.d.ts +29 -11
  11. package/dist/molecules/Breadcrumb.js +52 -52
  12. package/dist/molecules/Collapsible.d.ts +18 -17
  13. package/dist/molecules/Collapsible.js +42 -34
  14. package/dist/molecules/Field.d.ts +66 -30
  15. package/dist/molecules/Field.js +106 -55
  16. package/dist/molecules/InputGroup.d.ts +39 -21
  17. package/dist/molecules/InputGroup.js +43 -27
  18. package/dist/molecules/InputOTP.d.ts +26 -3
  19. package/dist/molecules/InputOTP.js +109 -76
  20. package/dist/molecules/Message.js +5 -4
  21. package/dist/molecules/Pagination.d.ts +36 -11
  22. package/dist/molecules/Pagination.js +58 -74
  23. package/dist/molecules/RadioGroup.d.ts +25 -17
  24. package/dist/molecules/RadioGroup.js +47 -43
  25. package/dist/molecules/Resizable.d.ts +32 -7
  26. package/dist/molecules/Resizable.js +76 -49
  27. package/dist/molecules/Tabs.d.ts +49 -11
  28. package/dist/molecules/Tabs.js +107 -51
  29. package/dist/molecules/ToggleGroup.d.ts +16 -10
  30. package/dist/molecules/ToggleGroup.js +37 -21
  31. package/dist/molecules/index.d.ts +11 -11
  32. package/dist/molecules/index.js +11 -11
  33. package/dist/organisms/AlertDialog.d.ts +80 -28
  34. package/dist/organisms/AlertDialog.js +192 -67
  35. package/dist/organisms/Carousel.d.ts +25 -3
  36. package/dist/organisms/Carousel.js +75 -43
  37. package/dist/organisms/Combobox.d.ts +2 -1
  38. package/dist/organisms/Combobox.js +46 -16
  39. package/dist/organisms/Command.d.ts +73 -32
  40. package/dist/organisms/Command.js +209 -131
  41. package/dist/organisms/CommandDialog.js +5 -5
  42. package/dist/organisms/ContextMenu.d.ts +41 -19
  43. package/dist/organisms/ContextMenu.js +112 -71
  44. package/dist/organisms/DataTable.js +42 -8
  45. package/dist/organisms/Dialog.d.ts +97 -31
  46. package/dist/organisms/Dialog.js +193 -68
  47. package/dist/organisms/Drawer.d.ts +33 -10
  48. package/dist/organisms/Drawer.js +130 -52
  49. package/dist/organisms/DropdownMenu.d.ts +58 -11
  50. package/dist/organisms/DropdownMenu.js +137 -50
  51. package/dist/organisms/Form.js +9 -11
  52. package/dist/organisms/HoverCard.d.ts +39 -19
  53. package/dist/organisms/HoverCard.js +116 -40
  54. package/dist/organisms/Menubar.d.ts +55 -19
  55. package/dist/organisms/Menubar.js +166 -82
  56. package/dist/organisms/NavigationMenu.d.ts +77 -31
  57. package/dist/organisms/NavigationMenu.js +169 -98
  58. package/dist/organisms/Popover.d.ts +72 -12
  59. package/dist/organisms/Popover.js +132 -25
  60. package/dist/organisms/Questionnaire.js +5 -5
  61. package/dist/organisms/Select.d.ts +99 -18
  62. package/dist/organisms/Select.js +253 -111
  63. package/dist/organisms/Sheet.d.ts +57 -13
  64. package/dist/organisms/Sheet.js +141 -54
  65. package/dist/organisms/Sidebar.d.ts +146 -56
  66. package/dist/organisms/Sidebar.js +236 -128
  67. package/dist/organisms/Tooltip.d.ts +88 -14
  68. package/dist/organisms/Tooltip.js +210 -47
  69. package/dist/organisms/index.d.ts +15 -15
  70. package/dist/organisms/index.js +15 -15
  71. package/dist/primitives/floating.js +25 -0
  72. package/dist/primitives/floatingSurface.d.ts +11 -0
  73. package/dist/primitives/floatingSurface.js +8 -0
  74. package/dist/primitives/menu.d.ts +45 -1
  75. package/dist/primitives/menu.js +45 -14
  76. package/dist/primitives/menuParts.d.ts +113 -0
  77. package/dist/primitives/menuParts.js +207 -0
  78. package/nebula.css +1 -1
  79. package/package.json +5 -4
  80. package/registry.json +18 -6
  81. package/src/atoms/Avatar.ts +141 -37
  82. package/src/atoms/index.ts +13 -1
  83. package/src/lib/children.ts +31 -0
  84. package/src/lib/motion.ts +12 -0
  85. package/src/molecules/Accordion.ts +120 -60
  86. package/src/molecules/Breadcrumb.ts +77 -76
  87. package/src/molecules/Collapsible.ts +77 -41
  88. package/src/molecules/Field.ts +187 -72
  89. package/src/molecules/InputGroup.ts +88 -35
  90. package/src/molecules/InputOTP.ts +150 -86
  91. package/src/molecules/Message.ts +6 -4
  92. package/src/molecules/Pagination.ts +96 -101
  93. package/src/molecules/RadioGroup.ts +70 -59
  94. package/src/molecules/Resizable.ts +138 -75
  95. package/src/molecules/Tabs.ts +187 -74
  96. package/src/molecules/ToggleGroup.ts +77 -38
  97. package/src/molecules/index.ts +85 -8
  98. package/src/organisms/AlertDialog.ts +319 -82
  99. package/src/organisms/Carousel.ts +129 -52
  100. package/src/organisms/Combobox.ts +64 -19
  101. package/src/organisms/Command.ts +342 -159
  102. package/src/organisms/CommandDialog.ts +6 -6
  103. package/src/organisms/ContextMenu.ts +185 -83
  104. package/src/organisms/DataTable.ts +56 -10
  105. package/src/organisms/Dialog.ts +312 -102
  106. package/src/organisms/Drawer.ts +219 -71
  107. package/src/organisms/DropdownMenu.ts +219 -61
  108. package/src/organisms/Form.ts +48 -34
  109. package/src/organisms/HoverCard.ts +187 -53
  110. package/src/organisms/Menubar.ts +247 -87
  111. package/src/organisms/NavigationMenu.ts +306 -128
  112. package/src/organisms/Popover.ts +215 -39
  113. package/src/organisms/Questionnaire.ts +9 -6
  114. package/src/organisms/Select.ts +397 -130
  115. package/src/organisms/Sheet.ts +252 -83
  116. package/src/organisms/Sidebar.ts +438 -185
  117. package/src/organisms/Tooltip.ts +315 -65
  118. package/src/organisms/index.ts +284 -14
  119. package/src/primitives/floating.ts +33 -0
  120. package/src/primitives/floatingSurface.ts +19 -0
  121. package/src/primitives/menu.ts +79 -18
  122. package/src/primitives/menuParts.ts +371 -0
@@ -1,6 +1,17 @@
1
1
  /**
2
2
  * Sidebar — the application shell's navigation column.
3
3
  *
4
+ * SidebarProvider({ children: () => html`
5
+ * ${Sidebar({ children: () => SidebarContent({ children:
6
+ * SidebarGroup({ children: SidebarMenu({ children:
7
+ * SidebarMenuItem({ children:
8
+ * SidebarMenuButton({ href: "/", tooltip: "Home", children: "Home" })
9
+ * })
10
+ * }) })
11
+ * }) })}
12
+ * ${SidebarInset({ children: page })}
13
+ * ` })
14
+ *
4
15
  * Two presentations from one definition, because a sidebar is not a component
5
16
  * so much as a layout decision that changes with the viewport:
6
17
  *
@@ -22,38 +33,41 @@ import {
22
33
  booleanCookie,
23
34
  component,
24
35
  cookieState,
36
+ createContext,
25
37
  html,
38
+ inject,
26
39
  onMount,
27
40
  onUnmount,
41
+ provide,
28
42
  type Signal,
29
43
  signal,
30
44
  } from "@c9up/aurora";
31
45
  import { Button } from "../atoms/Button.js";
32
- import type { Child, Slot } from "../lib/children.js";
46
+ import { Input } from "../atoms/Input.js";
47
+ import { Separator } from "../atoms/Separator.js";
48
+ import { Skeleton } from "../atoms/Skeleton.js";
49
+ import type { Parts, Slot } from "../lib/children.js";
33
50
  import { slot } from "../lib/children.js";
34
51
  import { cn } from "../lib/cn.js";
52
+ import { cva, type VariantProps } from "../lib/cva.js";
35
53
  import { PanelLeftIcon } from "../lib/icons.js";
36
54
  import { type Reactive, read } from "../lib/props.js";
37
- import { type StyledProps, styledDiv } from "../lib/styled.js";
38
- import { Sheet } from "./Sheet.js";
39
- import { Tooltip } from "./Tooltip.js";
55
+ import { styledDiv } from "../lib/styled.js";
56
+ import { Sheet, SheetContent, SheetHeader, SheetTitle } from "./Sheet.js";
57
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./Tooltip.js";
40
58
 
41
59
  const COOKIE_NAME = "nebula:sidebar";
60
+ const COOKIE_MAX_AGE_DAYS = 365;
61
+ const MOBILE_BREAKPOINT = 768;
62
+
63
+ let sharedOpen: Signal<boolean> | undefined;
42
64
 
43
65
  /**
44
- * The open/collapsed state, shared by every part of the sidebar.
45
- *
46
- * shadcn publishes this through a `SidebarProvider` and React context, so that
47
- * a menu item three levels down can know the sidebar is collapsed and show a
48
- * tooltip instead of a label. Aurora has no context, and the honest
49
- * replacement is a module-level signal: an app has one sidebar, so one signal
50
- * is the whole of what the provider was carrying.
66
+ * The cookie-backed open state, shared by every sidebar on the page.
51
67
  *
52
- * Created on first use rather than at import, because `cookieState` reads the
53
- * cookie immediately and this module is imported during SSR too.
68
+ * A module singleton and not a per-provider signal: the shell renders once and
69
+ * the trigger may sit in a header that is not inside the provider's subtree.
54
70
  */
55
- let sharedOpen: Signal<boolean> | undefined;
56
-
57
71
  export function sidebarState(defaultOpen = true): Signal<boolean> {
58
72
  sharedOpen ??= cookieState(COOKIE_NAME, defaultOpen, booleanCookie, {
59
73
  path: "/",
@@ -63,45 +77,56 @@ export function sidebarState(defaultOpen = true): Signal<boolean> {
63
77
  return sharedOpen;
64
78
  }
65
79
 
66
- /** Is the sidebar collapsed to its icon rail right now? */
67
80
  export function sidebarCollapsed(): boolean {
68
81
  return !sidebarState()();
69
82
  }
70
- const COOKIE_MAX_AGE_DAYS = 365;
71
- /** Below this width the sidebar becomes a Sheet. Matches Tailwind's `md`. */
72
- const MOBILE_BREAKPOINT = 768;
73
83
 
74
- export interface SidebarProps {
75
- children?: Slot;
76
- header?: Slot;
77
- footer?: Slot;
78
- /** Which edge. Default `"left"`. */
79
- side?: "left" | "right";
80
- /** What collapsing does: shrink to icons, or disappear. Default `"icon"`. */
81
- collapsible?: "icon" | "offcanvas";
84
+ export interface SidebarApi {
85
+ readonly open: () => boolean;
86
+ readonly isMobile: () => boolean;
87
+ readonly state: () => "expanded" | "collapsed";
88
+ setOpen(next: boolean): void;
89
+ toggleSidebar(): void;
90
+ }
91
+
92
+ const SidebarContext = createContext<SidebarApi>("SidebarProvider");
93
+
94
+ /**
95
+ * The sidebar's state, from inside it.
96
+ *
97
+ * Call from a component setup, as upstream's hook is called from a render.
98
+ */
99
+ export function useSidebar(): SidebarApi {
100
+ return inject(SidebarContext);
101
+ }
102
+
103
+ export interface SidebarProviderProps {
82
104
  /** Starting state. Read from the cookie when there is one. */
83
105
  defaultOpen?: boolean;
84
- /** Announced as the navigation landmark's name. */
85
- label?: string;
106
+ open?: Reactive<boolean>;
107
+ onOpenChange?: (open: boolean) => void;
86
108
  class?: Reactive<string>;
109
+ children?: Parts;
87
110
  }
88
111
 
89
- export const Sidebar = component<SidebarProps>((props) => {
90
- const side = props.side ?? "left";
91
- const collapsible = props.collapsible ?? "icon";
92
- // The shared signal, so the menu items collapse in step with the panel.
112
+ export const SidebarProvider = component<SidebarProviderProps>((props) => {
93
113
  const open = sidebarState(props.defaultOpen ?? true);
94
114
  const mobile = signal(false);
95
115
 
96
- function toggle(): void {
97
- open(!open());
116
+ function setOpen(next: boolean): void {
117
+ open(next);
118
+ props.onOpenChange?.(next);
119
+ }
120
+
121
+ function toggleSidebar(): void {
122
+ setOpen(!open());
98
123
  }
99
124
 
100
125
  function onKeyDown(event: KeyboardEvent): void {
101
126
  if (event.key !== "b" && event.key !== "B") return;
102
127
  if (!event.metaKey && !event.ctrlKey) return;
103
128
  event.preventDefault();
104
- toggle();
129
+ toggleSidebar();
105
130
  }
106
131
 
107
132
  // `matchMedia` rather than a resize listener: it fires only when the
@@ -123,102 +148,283 @@ export const Sidebar = component<SidebarProps>((props) => {
123
148
  document.removeEventListener("keydown", onKeyDown);
124
149
  });
125
150
 
126
- const body = (): Child =>
127
- html`<div data-slot="sidebar-inner" class="flex h-full w-full flex-col">
128
- ${
129
- props.header === undefined
130
- ? null
131
- : html`<div data-slot="sidebar-header" class="flex flex-col gap-2 p-2">
132
- ${slot(props.header)}
133
- </div>`
134
- }
135
- <div data-slot="sidebar-body" class="min-h-0 flex-1 overflow-auto p-2">
136
- ${slot(props.children)}
137
- </div>
138
- ${
139
- props.footer === undefined
140
- ? null
141
- : html`<div data-slot="sidebar-footer" class="flex flex-col gap-2 p-2">
142
- ${slot(props.footer)}
143
- </div>`
144
- }
145
- </div>`;
146
-
147
- return html`<div data-slot="sidebar-root">
148
- ${() =>
149
- mobile()
150
- ? Sheet({
151
- title: props.label ?? "Navigation",
152
- srOnlyTitle: true,
153
- side,
154
- open: () => open(),
155
- onOpenChange: (next) => open(next),
156
- children: body(),
157
- contentClass: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
158
- })
159
- : html`<nav
160
- data-slot="sidebar"
161
- data-state="${() => (open() ? "expanded" : "collapsed")}"
162
- data-side="${side}"
163
- data-collapsible="${collapsible}"
164
- aria-label="${props.label ?? "Sidebar"}"
165
- class="${() =>
166
- cn(
167
- "bg-sidebar text-sidebar-foreground h-svh shrink-0 overflow-hidden transition-[width] duration-200 ease-linear motion-reduce:transition-none",
168
- side === "left" ? "border-r" : "border-l",
169
- open()
170
- ? "w-(--sidebar-width,16rem)"
171
- : collapsible === "icon"
172
- ? "w-(--sidebar-width-icon,3rem)"
151
+ function current(): boolean {
152
+ const controlled = read(props.open);
153
+ return controlled === undefined ? open() : controlled;
154
+ }
155
+
156
+ provide<SidebarApi>(SidebarContext, {
157
+ open: current,
158
+ isMobile: () => mobile(),
159
+ state: () => (current() ? "expanded" : "collapsed"),
160
+ setOpen,
161
+ toggleSidebar,
162
+ });
163
+
164
+ return html`<div
165
+ data-slot="sidebar-wrapper"
166
+ class="${() => cn("flex min-h-svh w-full", read(props.class))}"
167
+ >${props.children?.()}</div>`;
168
+ });
169
+
170
+ export interface SidebarProps {
171
+ children?: Parts;
172
+ /** Which edge. Default `"left"`. */
173
+ side?: "left" | "right";
174
+ /** What collapsing does: shrink to icons, or disappear. Default `"icon"`. */
175
+ collapsible?: "icon" | "offcanvas" | "none";
176
+ /** Announced as the navigation landmark's name. */
177
+ label?: string;
178
+ class?: Reactive<string>;
179
+ }
180
+
181
+ export const Sidebar = component<SidebarProps>((props) => {
182
+ const sidebar = useSidebar();
183
+ const side = props.side ?? "left";
184
+ const collapsible = props.collapsible ?? "icon";
185
+ const body = props.children?.();
186
+
187
+ return html`<div data-slot="sidebar-root">${() =>
188
+ sidebar.isMobile()
189
+ ? Sheet({
190
+ open: () => sidebar.open(),
191
+ onOpenChange: (next) => sidebar.setOpen(next),
192
+ children: () =>
193
+ SheetContent({
194
+ side,
195
+ class: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
196
+ children: () =>
197
+ html`${SheetHeader({
198
+ class: "p-0",
199
+ // A VALUE: `SheetHeader` takes a `Slot`, and a part that
200
+ // reads context must be built while the context is still
201
+ // on the stack.
202
+ children: SheetTitle({
203
+ children: props.label ?? "Navigation",
204
+ srOnly: true,
205
+ }),
206
+ })}${body}`,
207
+ }),
208
+ })
209
+ : html`<nav
210
+ data-slot="sidebar"
211
+ data-state="${() => sidebar.state()}"
212
+ data-side="${side}"
213
+ data-collapsible="${collapsible}"
214
+ aria-label="${props.label ?? "Sidebar"}"
215
+ class="${() =>
216
+ cn(
217
+ "group bg-sidebar text-sidebar-foreground h-svh shrink-0 overflow-hidden transition-[width] duration-200 ease-linear motion-reduce:transition-none",
218
+ side === "left" ? "border-r" : "border-l",
219
+ sidebar.open()
220
+ ? "w-(--sidebar-width,16rem)"
221
+ : collapsible === "icon"
222
+ ? "w-(--sidebar-width-icon,3rem)"
223
+ : collapsible === "none"
224
+ ? "w-(--sidebar-width,16rem)"
173
225
  : "w-0 border-0",
174
- read(props.class),
175
- )}"
176
- >${body()}</nav>`}
177
- </div>`;
226
+ read(props.class),
227
+ )}"
228
+ ><div
229
+ data-slot="sidebar-inner"
230
+ class="flex h-full w-full flex-col"
231
+ >${body}</div></nav>`}</div>`;
178
232
  });
179
233
 
180
234
  export interface SidebarTriggerProps {
181
- onToggle: () => void;
235
+ /** Overrides the provider's toggle — for a trigger outside the shell. */
236
+ onToggle?: () => void;
182
237
  class?: Reactive<string>;
183
238
  }
184
239
 
185
- /**
186
- * The button that opens and closes the sidebar.
187
- *
188
- * Kept apart from `Sidebar` because it belongs in the page header, not in the
189
- * panel — a trigger inside an off-canvas sidebar disappears with it, and there
190
- * is then no way back.
191
- */
192
- export const SidebarTrigger = component<SidebarTriggerProps>((props) => {
193
- return Button({
240
+ export const SidebarTrigger = component<SidebarTriggerProps>((props) =>
241
+ Button({
194
242
  variant: "ghost",
195
243
  size: "icon",
196
244
  label: "Toggle sidebar",
197
- class: props.class,
198
- onClick: props.onToggle,
245
+ class: () => cn("size-7", read(props.class)),
246
+ onClick: () => {
247
+ if (props.onToggle !== undefined) {
248
+ props.onToggle();
249
+ return;
250
+ }
251
+ sidebarState()(!sidebarState()());
252
+ },
199
253
  children: PanelLeftIcon({ class: "size-4" }),
200
- });
201
- });
254
+ }),
255
+ );
256
+
257
+ export interface SidebarRailProps {
258
+ class?: Reactive<string>;
259
+ }
260
+
261
+ /**
262
+ * The hit area along the sidebar's edge that toggles it.
263
+ *
264
+ * A wider target than the trigger button and always where the eye already is.
265
+ * `title` rather than a visible label, and it stays out of the tab order: the
266
+ * keyboard has `cmd/ctrl + B` and the trigger, so a third stop on every page
267
+ * would be noise.
268
+ */
269
+ export const SidebarRail = component<SidebarRailProps>(
270
+ (props) => html`<button
271
+ type="button"
272
+ data-slot="sidebar-rail"
273
+ aria-label="Toggle sidebar"
274
+ tabindex="-1"
275
+ title="Toggle sidebar"
276
+ class="${() =>
277
+ cn(
278
+ "hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
279
+ read(props.class),
280
+ )}"
281
+ @click="${() => sidebarState()(!sidebarState()())}"
282
+ ></button>`,
283
+ );
284
+
285
+ export interface SidebarInsetProps {
286
+ children?: Slot;
287
+ class?: Reactive<string>;
288
+ }
289
+
290
+ /** The page beside the sidebar. */
291
+ export const SidebarInset = component<SidebarInsetProps>(
292
+ (props) => html`<main
293
+ data-slot="sidebar-inset"
294
+ class="${() =>
295
+ cn(
296
+ "bg-background relative flex w-full flex-1 flex-col",
297
+ read(props.class),
298
+ )}"
299
+ >${slot(props.children)}</main>`,
300
+ );
301
+
302
+ export interface SidebarInputProps {
303
+ placeholder?: string;
304
+ value?: Reactive<string>;
305
+ onInput?: (value: string) => void;
306
+ class?: Reactive<string>;
307
+ }
308
+
309
+ /** A search field sized for the column. */
310
+ export const SidebarInput = component<SidebarInputProps>((props) =>
311
+ Input({
312
+ placeholder: props.placeholder,
313
+ value: props.value,
314
+ onInput: props.onInput,
315
+ class: () => cn("bg-background h-8 w-full shadow-none", read(props.class)),
316
+ }),
317
+ );
318
+
319
+ export const SidebarHeader = styledDiv(
320
+ "sidebar-header",
321
+ "flex flex-col gap-2 p-2",
322
+ );
323
+
324
+ export const SidebarFooter = styledDiv(
325
+ "sidebar-footer",
326
+ "flex flex-col gap-2 p-2",
327
+ );
328
+
329
+ export const SidebarContent = styledDiv(
330
+ "sidebar-content",
331
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
332
+ );
333
+
334
+ export interface SidebarSeparatorProps {
335
+ class?: Reactive<string>;
336
+ }
337
+
338
+ export const SidebarSeparator = component<SidebarSeparatorProps>((props) =>
339
+ Separator({
340
+ class: () => cn("bg-sidebar-border mx-2 w-auto", read(props.class)),
341
+ }),
342
+ );
202
343
 
203
344
  export const SidebarGroup = styledDiv(
204
345
  "sidebar-group",
205
- "flex w-full flex-col gap-1 p-2",
346
+ "relative flex w-full min-w-0 flex-col p-2",
206
347
  );
207
348
 
208
349
  export const SidebarGroupLabel = styledDiv(
209
350
  "sidebar-group-label",
210
- "text-sidebar-foreground/70 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium",
351
+ "text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium transition-[margin,opacity] duration-200 ease-linear outline-hidden focus-visible:ring-2 group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 [&>svg]:size-4 [&>svg]:shrink-0",
211
352
  );
212
353
 
213
- export const SidebarMenu = styledDiv(
214
- "sidebar-menu",
215
- "flex w-full min-w-0 flex-col gap-1",
354
+ export const SidebarGroupContent = styledDiv(
355
+ "sidebar-group-content",
356
+ "w-full text-sm",
216
357
  );
217
358
 
218
- export interface SidebarMenuItemProps {
219
- label: Child;
359
+ export interface SidebarActionProps {
360
+ children?: Slot;
361
+ label?: string;
362
+ onClick?: () => void;
363
+ class?: Reactive<string>;
364
+ }
365
+
366
+ /** A control in a group's corner — "add", "filter". */
367
+ export const SidebarGroupAction = component<SidebarActionProps>(
368
+ (props) => html`<button
369
+ type="button"
370
+ data-slot="sidebar-group-action"
371
+ aria-label="${props.label}"
372
+ class="${() =>
373
+ cn(
374
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-hidden focus-visible:ring-2 group-data-[collapsible=icon]:hidden [&>svg]:size-4 [&>svg]:shrink-0",
375
+ read(props.class),
376
+ )}"
377
+ @click="${props.onClick}"
378
+ >${slot(props.children)}</button>`,
379
+ );
380
+
381
+ export const SidebarMenu = component<{
382
+ children?: Slot;
383
+ class?: Reactive<string>;
384
+ }>(
385
+ (props) => html`<ul
386
+ data-slot="sidebar-menu"
387
+ class="${() => cn("flex w-full min-w-0 flex-col gap-1", read(props.class))}"
388
+ >${slot(props.children)}</ul>`,
389
+ );
390
+
391
+ /** One row. Holds a button, and optionally an action and a badge beside it. */
392
+ export const SidebarMenuItem = component<{
393
+ children?: Slot;
394
+ class?: Reactive<string>;
395
+ }>(
396
+ (props) => html`<li
397
+ data-slot="sidebar-menu-item"
398
+ class="${() => cn("group/menu-item relative", read(props.class))}"
399
+ >${slot(props.children)}</li>`,
400
+ );
401
+
402
+ export const sidebarMenuButtonVariants = cva(
403
+ "peer/menu-button ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden transition-[width,height,padding] group-has-data-[slot=sidebar-menu-action]/menu-item:pr-8 focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:font-medium group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
404
+ {
405
+ variants: {
406
+ variant: {
407
+ default: "",
408
+ outline:
409
+ "bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:shadow-[0_0_0_1px_var(--sidebar-accent)]",
410
+ },
411
+ size: {
412
+ default: "h-8 text-sm",
413
+ sm: "h-7 text-xs",
414
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
415
+ },
416
+ },
417
+ defaultVariants: { variant: "default", size: "default" },
418
+ },
419
+ );
420
+
421
+ export type SidebarMenuButtonVariants = VariantProps<
422
+ typeof sidebarMenuButtonVariants
423
+ >;
424
+
425
+ export interface SidebarMenuButtonProps extends SidebarMenuButtonVariants {
426
+ children?: Slot;
220
427
  href?: string;
221
- icon?: Child;
222
428
  active?: Reactive<boolean>;
223
429
  /**
224
430
  * Shown as a tooltip while the sidebar is collapsed to icons.
@@ -228,67 +434,37 @@ export interface SidebarMenuItemProps {
228
434
  * unlabelled glyphs, so give one to every entry that has an icon.
229
435
  */
230
436
  tooltip?: string;
231
- /** A trailing control — the count of unread items, a status dot. */
232
- badge?: Child;
233
- /**
234
- * Extra classes, merged over the defaults.
235
- *
236
- * Every other component in this library takes one; this one did not, and a
237
- * caller who wanted something as ordinary as dimming a disabled entry had
238
- * to work around it. `cn` is tailwind-merge, so an override wins over the
239
- * default it collides with rather than fighting it on specificity.
240
- */
241
- class?: Reactive<string>;
242
437
  onClick?: () => void;
438
+ class?: Reactive<string>;
243
439
  }
244
440
 
245
- /**
246
- * One navigation entry.
247
- *
248
- * `aria-current="page"` on the active entry, not just a highlight class. The
249
- * highlight tells a sighted user where they are; without the attribute nobody
250
- * else is told at all.
251
- */
252
- export const SidebarMenuItem = component<SidebarMenuItemProps>((props) => {
253
- const classes =
254
- "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground aria-[current=page]:bg-sidebar-accent aria-[current=page]:font-medium flex h-8 w-full items-center gap-2 overflow-hidden rounded-md px-2 text-left text-sm outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring [&>svg]:size-4 [&>svg]:shrink-0";
255
-
256
- /**
257
- * The label and badge fold away with the rail, the icon does not.
258
- *
259
- * `sr-only` rather than `hidden`: the entry keeps its accessible name when
260
- * collapsed, so a screen reader still reads "Settings" off a column that
261
- * shows only a cog.
262
- */
263
- const foldable = (): string => (sidebarCollapsed() ? "sr-only" : "truncate");
264
-
265
- const body = html`${props.icon}<span class="${foldable}">${props.label}</span>${() =>
266
- props.badge === undefined || sidebarCollapsed()
267
- ? null
268
- : html`<span
269
- data-slot="sidebar-menu-badge"
270
- class="text-sidebar-foreground/70 ml-auto flex h-5 min-w-5 shrink-0 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums"
271
- >${props.badge}</span>`}`;
272
-
273
- // Reactive, because `props.class` may be a signal — a caller dimming an
274
- // entry as its state changes should not have to remount it.
275
- const merged = () => cn(classes, read(props.class));
441
+ export const SidebarMenuButton = component<SidebarMenuButtonProps>((props) => {
442
+ const merged = (): string =>
443
+ cn(
444
+ sidebarMenuButtonVariants({
445
+ variant: props.variant,
446
+ size: props.size,
447
+ }),
448
+ read(props.class),
449
+ );
276
450
 
277
451
  const entry =
278
452
  props.href !== undefined
279
453
  ? html`<a
280
- data-slot="sidebar-menu-item"
454
+ data-slot="sidebar-menu-button"
281
455
  href="${props.href}"
456
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
282
457
  aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
283
458
  class="${merged}"
284
- >${body}</a>`
459
+ >${slot(props.children)}</a>`
285
460
  : html`<button
286
461
  type="button"
287
- data-slot="sidebar-menu-item"
462
+ data-slot="sidebar-menu-button"
463
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
288
464
  aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
289
465
  class="${merged}"
290
466
  @click="${props.onClick}"
291
- >${body}</button>`;
467
+ >${slot(props.children)}</button>`;
292
468
 
293
469
  if (props.tooltip === undefined) return entry;
294
470
 
@@ -297,53 +473,130 @@ export const SidebarMenuItem = component<SidebarMenuItemProps>((props) => {
297
473
  // itself whether to open, which is the cheaper half to make conditional.
298
474
  return html`${() =>
299
475
  sidebarCollapsed()
300
- ? Tooltip({ trigger: entry, content: props.tooltip, placement: "right" })
476
+ ? Tooltip({
477
+ children: () =>
478
+ html`${TooltipTrigger({
479
+ children: () => entry,
480
+ })}${TooltipContent({ children: props.tooltip, side: "right" })}`,
481
+ })
301
482
  : entry}`;
302
483
  });
303
484
 
304
- /**
305
- * A second control on a menu row — a "more" menu, a remove button.
306
- *
307
- * Absolutely positioned rather than a flex sibling, so it can overlap a long
308
- * label instead of squeezing it. It disappears with the rail: there is no room
309
- * for two controls in an icon-width column, and the row's own action is the
310
- * one that matters.
311
- */
312
- export const SidebarMenuAction = component<SidebarMenuItemProps>((props) => {
313
- return html`<button
485
+ /** A second control on a row — a "more" menu, a remove button. */
486
+ export const SidebarMenuAction = component<SidebarActionProps>(
487
+ (props) => html`<button
314
488
  type="button"
315
489
  data-slot="sidebar-menu-action"
316
- aria-label="${props.tooltip}"
490
+ aria-label="${props.label}"
317
491
  class="${() =>
318
492
  cn(
319
- "text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-1 right-1 flex aspect-square w-5 items-center justify-center rounded-md outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring [&>svg]:size-4 [&>svg]:shrink-0",
320
- sidebarCollapsed() ? "hidden" : "",
493
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-hidden focus-visible:ring-2 group-data-[collapsible=icon]:hidden [&>svg]:size-4 [&>svg]:shrink-0",
494
+ read(props.class),
321
495
  )}"
322
496
  @click="${props.onClick}"
323
- >${props.icon ?? props.label}</button>`;
324
- });
497
+ >${slot(props.children)}</button>`,
498
+ );
499
+
500
+ /** A count or a status dot at the end of a row. */
501
+ export const SidebarMenuBadge = component<{
502
+ children?: Slot;
503
+ class?: Reactive<string>;
504
+ }>(
505
+ (props) => html`<div
506
+ data-slot="sidebar-menu-badge"
507
+ class="${() =>
508
+ cn(
509
+ "text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none group-data-[collapsible=icon]:hidden",
510
+ read(props.class),
511
+ )}"
512
+ >${slot(props.children)}</div>`,
513
+ );
514
+
515
+ export interface SidebarMenuSkeletonProps {
516
+ /** Leave room for an icon, as the real rows have. */
517
+ showIcon?: boolean;
518
+ class?: Reactive<string>;
519
+ }
325
520
 
326
521
  /**
327
- * A nested list under a menu entry.
522
+ * A placeholder row while the navigation loads.
328
523
  *
329
- * A real `<ul>`, so the nesting is structure a screen reader can announce
330
- * rather than an indent. Hidden entirely when collapsed — an indented tree in
331
- * an icon-width rail is unreadable, and the parent entry is still reachable.
524
+ * The widths vary per row, which is what stops a loading column from reading
525
+ * as a bar chart. Seeded from a random draw the moment the row is built, so it
526
+ * does not shift on every re-render.
332
527
  */
333
- export const SidebarMenuSub = component<StyledProps>((props) => {
334
- return html`<ul
528
+ export const SidebarMenuSkeleton = component<SidebarMenuSkeletonProps>(
529
+ (props) => {
530
+ const width = `${Math.floor(Math.random() * 40) + 50}%`;
531
+ return html`<div
532
+ data-slot="sidebar-menu-skeleton"
533
+ class="${() =>
534
+ cn("flex h-8 items-center gap-2 rounded-md px-2", read(props.class))}"
535
+ >${
536
+ props.showIcon === true ? Skeleton({ class: "size-4 rounded-md" }) : null
537
+ }<div class="flex-1" style="${`max-width: ${width}`}">${Skeleton({
538
+ class: "h-4 w-full",
539
+ })}</div></div>`;
540
+ },
541
+ );
542
+
543
+ export const SidebarMenuSub = component<{
544
+ children?: Slot;
545
+ class?: Reactive<string>;
546
+ }>(
547
+ (props) => html`<ul
335
548
  data-slot="sidebar-menu-sub"
336
549
  class="${() =>
337
550
  cn(
338
- "border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
339
- sidebarCollapsed() ? "hidden" : "",
551
+ "border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5 group-data-[collapsible=icon]:hidden",
340
552
  read(props.class),
341
553
  )}"
342
- >${slot(props.children)}</ul>`;
343
- });
554
+ >${slot(props.children)}</ul>`,
555
+ );
344
556
 
345
- /** One row of a nested list. Wrap a `SidebarMenuItem` in it. */
346
- export const SidebarMenuSubItem = styledDiv(
347
- "sidebar-menu-sub-item",
348
- "relative flex min-w-0 items-center",
557
+ export const SidebarMenuSubItem = component<{
558
+ children?: Slot;
559
+ class?: Reactive<string>;
560
+ }>(
561
+ (props) => html`<li
562
+ data-slot="sidebar-menu-sub-item"
563
+ class="${() => cn("group/menu-sub-item relative", read(props.class))}"
564
+ >${slot(props.children)}</li>`,
565
+ );
566
+
567
+ export interface SidebarMenuSubButtonProps {
568
+ children?: Slot;
569
+ href?: string;
570
+ active?: Reactive<boolean>;
571
+ size?: "sm" | "md";
572
+ onClick?: () => void;
573
+ class?: Reactive<string>;
574
+ }
575
+
576
+ export const SidebarMenuSubButton = component<SidebarMenuSubButtonProps>(
577
+ (props) => {
578
+ const merged = (): string =>
579
+ cn(
580
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 group-data-[collapsible=icon]:hidden [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
581
+ props.size === "sm" ? "text-xs" : "text-sm",
582
+ read(props.class),
583
+ );
584
+ if (props.href !== undefined) {
585
+ return html`<a
586
+ data-slot="sidebar-menu-sub-button"
587
+ href="${props.href}"
588
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
589
+ aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
590
+ class="${merged}"
591
+ >${slot(props.children)}</a>`;
592
+ }
593
+ return html`<button
594
+ type="button"
595
+ data-slot="sidebar-menu-sub-button"
596
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
597
+ aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
598
+ class="${merged}"
599
+ @click="${props.onClick}"
600
+ >${slot(props.children)}</button>`;
601
+ },
349
602
  );