@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
  *
@@ -17,29 +28,29 @@
17
28
  *
18
29
  * `cmd/ctrl + B` toggles it, the convention from every editor that has one.
19
30
  */
20
- import { booleanCookie, component, cookieState, html, onMount, onUnmount, signal, } from "@c9up/aurora";
31
+ import { booleanCookie, component, cookieState, createContext, html, inject, onMount, onUnmount, provide, signal, } from "@c9up/aurora";
21
32
  import { Button } from "../atoms/Button.js";
33
+ import { Input } from "../atoms/Input.js";
34
+ import { Separator } from "../atoms/Separator.js";
35
+ import { Skeleton } from "../atoms/Skeleton.js";
22
36
  import { slot } from "../lib/children.js";
23
37
  import { cn } from "../lib/cn.js";
38
+ import { cva } from "../lib/cva.js";
24
39
  import { PanelLeftIcon } from "../lib/icons.js";
25
40
  import { read } from "../lib/props.js";
26
41
  import { styledDiv } from "../lib/styled.js";
27
- import { Sheet } from "./Sheet.js";
28
- import { Tooltip } from "./Tooltip.js";
42
+ import { Sheet, SheetContent, SheetHeader, SheetTitle } from "./Sheet.js";
43
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./Tooltip.js";
29
44
  const COOKIE_NAME = "nebula:sidebar";
45
+ const COOKIE_MAX_AGE_DAYS = 365;
46
+ const MOBILE_BREAKPOINT = 768;
47
+ let sharedOpen;
30
48
  /**
31
- * The open/collapsed state, shared by every part of the sidebar.
32
- *
33
- * shadcn publishes this through a `SidebarProvider` and React context, so that
34
- * a menu item three levels down can know the sidebar is collapsed and show a
35
- * tooltip instead of a label. Aurora has no context, and the honest
36
- * replacement is a module-level signal: an app has one sidebar, so one signal
37
- * is the whole of what the provider was carrying.
49
+ * The cookie-backed open state, shared by every sidebar on the page.
38
50
  *
39
- * Created on first use rather than at import, because `cookieState` reads the
40
- * cookie immediately and this module is imported during SSR too.
51
+ * A module singleton and not a per-provider signal: the shell renders once and
52
+ * the trigger may sit in a header that is not inside the provider's subtree.
41
53
  */
42
- let sharedOpen;
43
54
  export function sidebarState(defaultOpen = true) {
44
55
  sharedOpen ??= cookieState(COOKIE_NAME, defaultOpen, booleanCookie, {
45
56
  path: "/",
@@ -48,21 +59,27 @@ export function sidebarState(defaultOpen = true) {
48
59
  });
49
60
  return sharedOpen;
50
61
  }
51
- /** Is the sidebar collapsed to its icon rail right now? */
52
62
  export function sidebarCollapsed() {
53
63
  return !sidebarState()();
54
64
  }
55
- const COOKIE_MAX_AGE_DAYS = 365;
56
- /** Below this width the sidebar becomes a Sheet. Matches Tailwind's `md`. */
57
- const MOBILE_BREAKPOINT = 768;
58
- export const Sidebar = component((props) => {
59
- const side = props.side ?? "left";
60
- const collapsible = props.collapsible ?? "icon";
61
- // The shared signal, so the menu items collapse in step with the panel.
65
+ const SidebarContext = createContext("SidebarProvider");
66
+ /**
67
+ * The sidebar's state, from inside it.
68
+ *
69
+ * Call from a component setup, as upstream's hook is called from a render.
70
+ */
71
+ export function useSidebar() {
72
+ return inject(SidebarContext);
73
+ }
74
+ export const SidebarProvider = component((props) => {
62
75
  const open = sidebarState(props.defaultOpen ?? true);
63
76
  const mobile = signal(false);
64
- function toggle() {
65
- open(!open());
77
+ function setOpen(next) {
78
+ open(next);
79
+ props.onOpenChange?.(next);
80
+ }
81
+ function toggleSidebar() {
82
+ setOpen(!open());
66
83
  }
67
84
  function onKeyDown(event) {
68
85
  if (event.key !== "b" && event.key !== "B")
@@ -70,7 +87,7 @@ export const Sidebar = component((props) => {
70
87
  if (!event.metaKey && !event.ctrlKey)
71
88
  return;
72
89
  event.preventDefault();
73
- toggle();
90
+ toggleSidebar();
74
91
  }
75
92
  // `matchMedia` rather than a resize listener: it fires only when the
76
93
  // breakpoint is actually crossed, not on every pixel of a window drag.
@@ -88,144 +105,235 @@ export const Sidebar = component((props) => {
88
105
  media?.removeEventListener("change", syncMobile);
89
106
  document.removeEventListener("keydown", onKeyDown);
90
107
  });
91
- const body = () => html `<div data-slot="sidebar-inner" class="flex h-full w-full flex-col">
92
- ${props.header === undefined
93
- ? null
94
- : html `<div data-slot="sidebar-header" class="flex flex-col gap-2 p-2">
95
- ${slot(props.header)}
96
- </div>`}
97
- <div data-slot="sidebar-body" class="min-h-0 flex-1 overflow-auto p-2">
98
- ${slot(props.children)}
99
- </div>
100
- ${props.footer === undefined
101
- ? null
102
- : html `<div data-slot="sidebar-footer" class="flex flex-col gap-2 p-2">
103
- ${slot(props.footer)}
104
- </div>`}
105
- </div>`;
106
- return html `<div data-slot="sidebar-root">
107
- ${() => mobile()
108
+ function current() {
109
+ const controlled = read(props.open);
110
+ return controlled === undefined ? open() : controlled;
111
+ }
112
+ provide(SidebarContext, {
113
+ open: current,
114
+ isMobile: () => mobile(),
115
+ state: () => (current() ? "expanded" : "collapsed"),
116
+ setOpen,
117
+ toggleSidebar,
118
+ });
119
+ return html `<div
120
+ data-slot="sidebar-wrapper"
121
+ class="${() => cn("flex min-h-svh w-full", read(props.class))}"
122
+ >${props.children?.()}</div>`;
123
+ });
124
+ export const Sidebar = component((props) => {
125
+ const sidebar = useSidebar();
126
+ const side = props.side ?? "left";
127
+ const collapsible = props.collapsible ?? "icon";
128
+ const body = props.children?.();
129
+ return html `<div data-slot="sidebar-root">${() => sidebar.isMobile()
108
130
  ? Sheet({
109
- title: props.label ?? "Navigation",
110
- srOnlyTitle: true,
111
- side,
112
- open: () => open(),
113
- onOpenChange: (next) => open(next),
114
- children: body(),
115
- contentClass: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
131
+ open: () => sidebar.open(),
132
+ onOpenChange: (next) => sidebar.setOpen(next),
133
+ children: () => SheetContent({
134
+ side,
135
+ class: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
136
+ children: () => html `${SheetHeader({
137
+ class: "p-0",
138
+ // A VALUE: `SheetHeader` takes a `Slot`, and a part that
139
+ // reads context must be built while the context is still
140
+ // on the stack.
141
+ children: SheetTitle({
142
+ children: props.label ?? "Navigation",
143
+ srOnly: true,
144
+ }),
145
+ })}${body}`,
146
+ }),
116
147
  })
117
148
  : html `<nav
118
- data-slot="sidebar"
119
- data-state="${() => (open() ? "expanded" : "collapsed")}"
120
- data-side="${side}"
121
- data-collapsible="${collapsible}"
122
- aria-label="${props.label ?? "Sidebar"}"
123
- class="${() => cn("bg-sidebar text-sidebar-foreground h-svh shrink-0 overflow-hidden transition-[width] duration-200 ease-linear motion-reduce:transition-none", side === "left" ? "border-r" : "border-l", open()
149
+ data-slot="sidebar"
150
+ data-state="${() => sidebar.state()}"
151
+ data-side="${side}"
152
+ data-collapsible="${collapsible}"
153
+ aria-label="${props.label ?? "Sidebar"}"
154
+ class="${() => cn("group bg-sidebar text-sidebar-foreground h-svh shrink-0 overflow-hidden transition-[width] duration-200 ease-linear motion-reduce:transition-none", side === "left" ? "border-r" : "border-l", sidebar.open()
124
155
  ? "w-(--sidebar-width,16rem)"
125
156
  : collapsible === "icon"
126
157
  ? "w-(--sidebar-width-icon,3rem)"
127
- : "w-0 border-0", read(props.class))}"
128
- >${body()}</nav>`}
129
- </div>`;
158
+ : collapsible === "none"
159
+ ? "w-(--sidebar-width,16rem)"
160
+ : "w-0 border-0", read(props.class))}"
161
+ ><div
162
+ data-slot="sidebar-inner"
163
+ class="flex h-full w-full flex-col"
164
+ >${body}</div></nav>`}</div>`;
130
165
  });
166
+ export const SidebarTrigger = component((props) => Button({
167
+ variant: "ghost",
168
+ size: "icon",
169
+ label: "Toggle sidebar",
170
+ class: () => cn("size-7", read(props.class)),
171
+ onClick: () => {
172
+ if (props.onToggle !== undefined) {
173
+ props.onToggle();
174
+ return;
175
+ }
176
+ sidebarState()(!sidebarState()());
177
+ },
178
+ children: PanelLeftIcon({ class: "size-4" }),
179
+ }));
131
180
  /**
132
- * The button that opens and closes the sidebar.
181
+ * The hit area along the sidebar's edge that toggles it.
133
182
  *
134
- * Kept apart from `Sidebar` because it belongs in the page header, not in the
135
- * panel — a trigger inside an off-canvas sidebar disappears with it, and there
136
- * is then no way back.
183
+ * A wider target than the trigger button and always where the eye already is.
184
+ * `title` rather than a visible label, and it stays out of the tab order: the
185
+ * keyboard has `cmd/ctrl + B` and the trigger, so a third stop on every page
186
+ * would be noise.
137
187
  */
138
- export const SidebarTrigger = component((props) => {
139
- return Button({
140
- variant: "ghost",
141
- size: "icon",
142
- label: "Toggle sidebar",
143
- class: props.class,
144
- onClick: props.onToggle,
145
- children: PanelLeftIcon({ class: "size-4" }),
146
- });
188
+ export const SidebarRail = component((props) => html `<button
189
+ type="button"
190
+ data-slot="sidebar-rail"
191
+ aria-label="Toggle sidebar"
192
+ tabindex="-1"
193
+ title="Toggle sidebar"
194
+ class="${() => cn("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", read(props.class))}"
195
+ @click="${() => sidebarState()(!sidebarState()())}"
196
+ ></button>`);
197
+ /** The page beside the sidebar. */
198
+ export const SidebarInset = component((props) => html `<main
199
+ data-slot="sidebar-inset"
200
+ class="${() => cn("bg-background relative flex w-full flex-1 flex-col", read(props.class))}"
201
+ >${slot(props.children)}</main>`);
202
+ /** A search field sized for the column. */
203
+ export const SidebarInput = component((props) => Input({
204
+ placeholder: props.placeholder,
205
+ value: props.value,
206
+ onInput: props.onInput,
207
+ class: () => cn("bg-background h-8 w-full shadow-none", read(props.class)),
208
+ }));
209
+ export const SidebarHeader = styledDiv("sidebar-header", "flex flex-col gap-2 p-2");
210
+ export const SidebarFooter = styledDiv("sidebar-footer", "flex flex-col gap-2 p-2");
211
+ export const SidebarContent = styledDiv("sidebar-content", "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden");
212
+ export const SidebarSeparator = component((props) => Separator({
213
+ class: () => cn("bg-sidebar-border mx-2 w-auto", read(props.class)),
214
+ }));
215
+ export const SidebarGroup = styledDiv("sidebar-group", "relative flex w-full min-w-0 flex-col p-2");
216
+ export const SidebarGroupLabel = styledDiv("sidebar-group-label", "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");
217
+ export const SidebarGroupContent = styledDiv("sidebar-group-content", "w-full text-sm");
218
+ /** A control in a group's corner — "add", "filter". */
219
+ export const SidebarGroupAction = component((props) => html `<button
220
+ type="button"
221
+ data-slot="sidebar-group-action"
222
+ aria-label="${props.label}"
223
+ class="${() => cn("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", read(props.class))}"
224
+ @click="${props.onClick}"
225
+ >${slot(props.children)}</button>`);
226
+ export const SidebarMenu = component((props) => html `<ul
227
+ data-slot="sidebar-menu"
228
+ class="${() => cn("flex w-full min-w-0 flex-col gap-1", read(props.class))}"
229
+ >${slot(props.children)}</ul>`);
230
+ /** One row. Holds a button, and optionally an action and a badge beside it. */
231
+ export const SidebarMenuItem = component((props) => html `<li
232
+ data-slot="sidebar-menu-item"
233
+ class="${() => cn("group/menu-item relative", read(props.class))}"
234
+ >${slot(props.children)}</li>`);
235
+ export const sidebarMenuButtonVariants = cva("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", {
236
+ variants: {
237
+ variant: {
238
+ default: "",
239
+ outline: "bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:shadow-[0_0_0_1px_var(--sidebar-accent)]",
240
+ },
241
+ size: {
242
+ default: "h-8 text-sm",
243
+ sm: "h-7 text-xs",
244
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
245
+ },
246
+ },
247
+ defaultVariants: { variant: "default", size: "default" },
147
248
  });
148
- export const SidebarGroup = styledDiv("sidebar-group", "flex w-full flex-col gap-1 p-2");
149
- export const SidebarGroupLabel = styledDiv("sidebar-group-label", "text-sidebar-foreground/70 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium");
150
- export const SidebarMenu = styledDiv("sidebar-menu", "flex w-full min-w-0 flex-col gap-1");
151
- /**
152
- * One navigation entry.
153
- *
154
- * `aria-current="page"` on the active entry, not just a highlight class. The
155
- * highlight tells a sighted user where they are; without the attribute nobody
156
- * else is told at all.
157
- */
158
- export const SidebarMenuItem = component((props) => {
159
- const classes = "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";
160
- /**
161
- * The label and badge fold away with the rail, the icon does not.
162
- *
163
- * `sr-only` rather than `hidden`: the entry keeps its accessible name when
164
- * collapsed, so a screen reader still reads "Settings" off a column that
165
- * shows only a cog.
166
- */
167
- const foldable = () => (sidebarCollapsed() ? "sr-only" : "truncate");
168
- const body = html `${props.icon}<span class="${foldable}">${props.label}</span>${() => props.badge === undefined || sidebarCollapsed()
169
- ? null
170
- : html `<span
171
- data-slot="sidebar-menu-badge"
172
- 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"
173
- >${props.badge}</span>`}`;
174
- // Reactive, because `props.class` may be a signal — a caller dimming an
175
- // entry as its state changes should not have to remount it.
176
- const merged = () => cn(classes, read(props.class));
249
+ export const SidebarMenuButton = component((props) => {
250
+ const merged = () => cn(sidebarMenuButtonVariants({
251
+ variant: props.variant,
252
+ size: props.size,
253
+ }), read(props.class));
177
254
  const entry = props.href !== undefined
178
255
  ? html `<a
179
- data-slot="sidebar-menu-item"
256
+ data-slot="sidebar-menu-button"
180
257
  href="${props.href}"
258
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
181
259
  aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
182
260
  class="${merged}"
183
- >${body}</a>`
261
+ >${slot(props.children)}</a>`
184
262
  : html `<button
185
263
  type="button"
186
- data-slot="sidebar-menu-item"
264
+ data-slot="sidebar-menu-button"
265
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
187
266
  aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
188
267
  class="${merged}"
189
268
  @click="${props.onClick}"
190
- >${body}</button>`;
269
+ >${slot(props.children)}</button>`;
191
270
  if (props.tooltip === undefined)
192
271
  return entry;
193
272
  // Wrapped once, not toggled: swapping the wrapper on collapse would remount
194
273
  // the entry and lose focus mid-keyboard-navigation. The tooltip decides for
195
274
  // itself whether to open, which is the cheaper half to make conditional.
196
275
  return html `${() => sidebarCollapsed()
197
- ? Tooltip({ trigger: entry, content: props.tooltip, placement: "right" })
276
+ ? Tooltip({
277
+ children: () => html `${TooltipTrigger({
278
+ children: () => entry,
279
+ })}${TooltipContent({ children: props.tooltip, side: "right" })}`,
280
+ })
198
281
  : entry}`;
199
282
  });
200
- /**
201
- * A second control on a menu row — a "more" menu, a remove button.
202
- *
203
- * Absolutely positioned rather than a flex sibling, so it can overlap a long
204
- * label instead of squeezing it. It disappears with the rail: there is no room
205
- * for two controls in an icon-width column, and the row's own action is the
206
- * one that matters.
207
- */
208
- export const SidebarMenuAction = component((props) => {
209
- return html `<button
283
+ /** A second control on a row — a "more" menu, a remove button. */
284
+ export const SidebarMenuAction = component((props) => html `<button
210
285
  type="button"
211
286
  data-slot="sidebar-menu-action"
212
- aria-label="${props.tooltip}"
213
- class="${() => cn("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", sidebarCollapsed() ? "hidden" : "")}"
287
+ aria-label="${props.label}"
288
+ class="${() => cn("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", read(props.class))}"
214
289
  @click="${props.onClick}"
215
- >${props.icon ?? props.label}</button>`;
216
- });
290
+ >${slot(props.children)}</button>`);
291
+ /** A count or a status dot at the end of a row. */
292
+ export const SidebarMenuBadge = component((props) => html `<div
293
+ data-slot="sidebar-menu-badge"
294
+ class="${() => cn("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", read(props.class))}"
295
+ >${slot(props.children)}</div>`);
217
296
  /**
218
- * A nested list under a menu entry.
297
+ * A placeholder row while the navigation loads.
219
298
  *
220
- * A real `<ul>`, so the nesting is structure a screen reader can announce
221
- * rather than an indent. Hidden entirely when collapsed — an indented tree in
222
- * an icon-width rail is unreadable, and the parent entry is still reachable.
299
+ * The widths vary per row, which is what stops a loading column from reading
300
+ * as a bar chart. Seeded from a random draw the moment the row is built, so it
301
+ * does not shift on every re-render.
223
302
  */
224
- export const SidebarMenuSub = component((props) => {
225
- return html `<ul
303
+ export const SidebarMenuSkeleton = component((props) => {
304
+ const width = `${Math.floor(Math.random() * 40) + 50}%`;
305
+ return html `<div
306
+ data-slot="sidebar-menu-skeleton"
307
+ class="${() => cn("flex h-8 items-center gap-2 rounded-md px-2", read(props.class))}"
308
+ >${props.showIcon === true ? Skeleton({ class: "size-4 rounded-md" }) : null}<div class="flex-1" style="${`max-width: ${width}`}">${Skeleton({
309
+ class: "h-4 w-full",
310
+ })}</div></div>`;
311
+ });
312
+ export const SidebarMenuSub = component((props) => html `<ul
226
313
  data-slot="sidebar-menu-sub"
227
- class="${() => cn("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", sidebarCollapsed() ? "hidden" : "", read(props.class))}"
228
- >${slot(props.children)}</ul>`;
314
+ class="${() => cn("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", read(props.class))}"
315
+ >${slot(props.children)}</ul>`);
316
+ export const SidebarMenuSubItem = component((props) => html `<li
317
+ data-slot="sidebar-menu-sub-item"
318
+ class="${() => cn("group/menu-sub-item relative", read(props.class))}"
319
+ >${slot(props.children)}</li>`);
320
+ export const SidebarMenuSubButton = component((props) => {
321
+ const merged = () => cn("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", props.size === "sm" ? "text-xs" : "text-sm", read(props.class));
322
+ if (props.href !== undefined) {
323
+ return html `<a
324
+ data-slot="sidebar-menu-sub-button"
325
+ href="${props.href}"
326
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
327
+ aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
328
+ class="${merged}"
329
+ >${slot(props.children)}</a>`;
330
+ }
331
+ return html `<button
332
+ type="button"
333
+ data-slot="sidebar-menu-sub-button"
334
+ data-active="${() => (read(props.active) === true ? "true" : undefined)}"
335
+ aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
336
+ class="${merged}"
337
+ @click="${props.onClick}"
338
+ >${slot(props.children)}</button>`;
229
339
  });
230
- /** One row of a nested list. Wrap a `SidebarMenuItem` in it. */
231
- export const SidebarMenuSubItem = styledDiv("sidebar-menu-sub-item", "relative flex min-w-0 items-center");
@@ -1,6 +1,23 @@
1
1
  /**
2
2
  * Tooltip — a label that appears on hover or focus.
3
3
  *
4
+ * Four parts, as upstream: a `TooltipProvider` that owns the timing for a
5
+ * group, a `Tooltip` that owns one tooltip's state, a `TooltipTrigger` and a
6
+ * `TooltipContent`. The state lives in the middle and both ends read it
7
+ * through context, which is why the trigger can describe content it never
8
+ * sees.
9
+ *
10
+ * TooltipProvider({ children: () => html`
11
+ * ${Tooltip({ children: () => html`
12
+ * ${TooltipTrigger({ children: () => Button({ children: "Save" }) })}
13
+ * ${TooltipContent({ children: "Saves and closes" })}
14
+ * ` })}
15
+ * ` })
16
+ *
17
+ * The `() =>` is not decoration. Aurora builds eagerly, so children handed
18
+ * over already built would have run before the provider existed and found no
19
+ * context — see `Parts`.
20
+ *
4
21
  * Three rules separate a usable tooltip from an irritating one, and all three
5
22
  * are about time rather than appearance:
6
23
  *
@@ -11,8 +28,9 @@
11
28
  * halfway.
12
29
  * - **No delay between neighbours.** Once one tooltip is showing, the next one
13
30
  * appears instantly; the user has clearly decided to browse the toolbar, and
14
- * re-serving the delay each time makes the interface feel stuck. That is why
15
- * `lastClosedAt` is module state and not per-component.
31
+ * re-serving the delay each time makes the interface feel stuck. That is
32
+ * what `skipDelayDuration` bounds, and why the window belongs to the
33
+ * provider rather than to either tooltip.
16
34
  *
17
35
  * Focus opens it with no delay at all. A keyboard user landing on a control
18
36
  * has already committed to it, and a delay just looks like lag.
@@ -21,19 +39,75 @@
21
39
  * tooltip supplements a control's name; it is not the name. A button labelled
22
40
  * only by its tooltip is unlabelled to anything that does not hover.
23
41
  */
24
- import type { Child } from "../lib/children.js";
25
- import { type Slot } from "../lib/children.js";
42
+ import { type TemplateResult } from "@c9up/aurora";
43
+ import type { Child, Parts, Slot } from "../lib/children.js";
26
44
  import { type Reactive } from "../lib/props.js";
27
- import type { Placement } from "../primitives/floating.js";
45
+ import type { Align, Side } from "../primitives/floating.js";
46
+ export interface TooltipProviderProps {
47
+ /** Hover delay before opening, in ms. */
48
+ delayDuration?: number;
49
+ /** How long after one closes that the next in the group opens instantly. */
50
+ skipDelayDuration?: number;
51
+ /** Close as soon as the pointer leaves the trigger, even towards the tooltip. */
52
+ disableHoverableContent?: boolean;
53
+ children?: Parts;
54
+ }
55
+ /**
56
+ * Timing shared by every tooltip inside it.
57
+ *
58
+ * Renders no element of its own, exactly as upstream: it is a context holder,
59
+ * and giving it a wrapper would put a box into a layout that did not ask for
60
+ * one. `data-slot="tooltip-provider"` is inert upstream for the same reason.
61
+ */
62
+ export declare const TooltipProvider: (props?: TooltipProviderProps | undefined) => TemplateResult;
28
63
  export interface TooltipProps {
29
- /** The control being described. */
30
- trigger?: Slot;
31
- /** The tooltip text. Keep it to a phrase. */
32
- content?: Child;
33
- placement?: Placement;
34
- openDelay?: number;
35
- closeDelay?: number;
64
+ /** Controlled state. Omit to let the tooltip own it. */
65
+ open?: Reactive<boolean>;
66
+ defaultOpen?: boolean;
67
+ onOpenChange?: (open: boolean) => void;
68
+ /** Overrides the provider's delay for this tooltip only. */
69
+ delayDuration?: number;
70
+ disableHoverableContent?: boolean;
71
+ children?: Parts;
72
+ }
73
+ /**
74
+ * One tooltip: the state its trigger and its content both read.
75
+ *
76
+ * Renders no element of its own — see `TooltipProvider`. The parts are built
77
+ * here, inside setup, which is what puts the context within their reach; the
78
+ * content registers itself during that call, so the floating surface can be
79
+ * wired straight afterwards.
80
+ */
81
+ export declare const Tooltip: (props?: TooltipProps | undefined) => TemplateResult;
82
+ export interface TooltipTriggerProps {
83
+ children?: Slot;
36
84
  class?: Reactive<string>;
37
- contentClass?: Reactive<string>;
38
85
  }
39
- export declare const Tooltip: (props?: TooltipProps | undefined) => import("@c9up/aurora").TemplateResult;
86
+ /**
87
+ * The control being described.
88
+ *
89
+ * NAMED DEVIATION — a wrapping `<span>`, where upstream is used as
90
+ * `<TooltipTrigger asChild>` and merges onto the control itself. `asChild`
91
+ * needs an element to merge INTO, and Aurora has no element until the template
92
+ * is rendered; a `<button>` wrapper would nest a button inside a button, which
93
+ * is invalid and unfocusable. `inline-flex` keeps the wrapper out of the
94
+ * layout. Focus still opens it because `focusin` bubbles out of the control.
95
+ */
96
+ export declare const TooltipTrigger: (props?: TooltipTriggerProps | undefined) => TemplateResult;
97
+ export interface TooltipContentProps {
98
+ children?: Child;
99
+ /** Which edge of the trigger to sit on. Flips when there is no room. */
100
+ side?: Side;
101
+ align?: Align;
102
+ sideOffset?: number;
103
+ class?: Reactive<string>;
104
+ }
105
+ /**
106
+ * The label itself.
107
+ *
108
+ * Renders nothing where it is written: the tooltip portals its content out of
109
+ * the tree when it opens, so this registers what to build and returns an empty
110
+ * template. Writing it inside `Tooltip` — rather than passing content as a
111
+ * prop — is what keeps the call site shaped like the thing it describes.
112
+ */
113
+ export declare const TooltipContent: (props?: TooltipContentProps | undefined) => TemplateResult;