@zonsh/ui 0.2.0 → 0.4.1

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 (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -7,12 +7,16 @@ import { cn } from "../lib/cn.js";
7
7
  import { modPressed } from "../lib/platform.js";
8
8
  import { Button } from "./button.js";
9
9
  import { Drawer, DrawerContent, DrawerTitle } from "./drawer.js";
10
+ import { useMessages } from "./locale.js";
10
11
  import { ScrollArea } from "./scroll-area.js";
11
12
  import { Separator } from "./separator.js";
12
13
  import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
14
+ const defaultMessages = { navigation: "Navigation", toggle: "Toggle sidebar" };
13
15
  const SidebarContext = React.createContext(null);
14
16
  /** The sidebar's density: `default` 38px rows, `sm` 30px rows (`Sidebar size`). */
15
17
  const SidebarSizeContext = React.createContext("default");
18
+ /** The edge the sidebar is on (`Sidebar side`): its icon rail's tooltips open towards the page. */
19
+ const SidebarSideContext = React.createContext("left");
16
20
  /** Where a `Sidebar` is rendered: the desktop panel or the mobile sheet. */
17
21
  const SidebarSurfaceContext = React.createContext("panel");
18
22
  /**
@@ -313,8 +317,8 @@ function HoverGlide() {
313
317
  * Sidebar — section navigation for docs, settings and dashboards.
314
318
  *
315
319
  * A `<nav>` of `SidebarGroup`s, each with an eyebrow `SidebarGroupLabel` and 38px
316
- * `SidebarItem` rows at 12px radius. Rows are flat at rest, share one soft hover fill that glides
317
- * with the pointer, and take the raised material when current. The rule people break: marking the current page with a flat fill or
320
+ * `SidebarItem` rows at 12px radius. Rows are flat at rest, only their label brightens on hover
321
+ * (`hover="glide"` adds one soft fill that follows the pointer), and take the raised material when current. The rule people break: marking the current page with a flat fill or
318
322
  * a bold weight. Set `current` (it writes `aria-current="page"`) and let the material show it.
319
323
  * A sidebar never shows a scrollbar: a long one goes in `<ScrollArea scrollbar={false}>`.
320
324
  *
@@ -322,12 +326,13 @@ function HoverGlide() {
322
326
  * the page by a hairline, holding `SidebarHeader`, `SidebarContent` and `SidebarFooter`. It
323
327
  * collapses on desktop and turns into a sheet on mobile.
324
328
  */
325
- export function Sidebar({ side = "left", variant = "sidebar", size = "default", className, children, ...props }) {
329
+ export function Sidebar({ side = "left", variant = "sidebar", size = "default", hover = "text", className, children, ...props }) {
326
330
  const shell = React.useContext(SidebarContext);
331
+ const text = useMessages("sidebar", defaultMessages);
327
332
  const dense = size === "sm";
328
333
  // Dense: every control inside (the rows, a search field, a header button) is 30px.
329
334
  const sizeClass = dense ? "[--control-h:var(--control-h-sm)]" : undefined;
330
- const content = (_jsxs(SidebarSizeContext.Provider, { value: size, children: [_jsx(HoverGlide, {}), _jsx(CurrentGlide, {}), children] }));
335
+ const content = (_jsx(SidebarSizeContext.Provider, { value: size, children: _jsxs(SidebarSideContext.Provider, { value: side, children: [hover === "glide" && _jsx(HoverGlide, {}), _jsx(CurrentGlide, {}), children] }) }));
331
336
  if (!shell) {
332
337
  return (_jsx("nav", { "data-slot": "sidebar", "data-size": size, className: cn("relative isolate flex w-full flex-col", dense ? "gap-5" : "gap-7", sizeClass, className), ...props, children: content }));
333
338
  }
@@ -339,12 +344,12 @@ export function Sidebar({ side = "left", variant = "sidebar", size = "default",
339
344
  return (_jsx("nav", { "data-slot": "sidebar", "data-side": side, "data-variant": variant, "data-size": size, "data-state": "expanded", className: cn(panelClass, sizeClass, "sticky top-0 h-svh max-h-full w-(--sidebar-width) shrink-0 border-border/60", variant !== "sidebar" ? undefined : side === "left" ? "border-e" : "border-s", className), ...props, children: content }));
340
345
  }
341
346
  if (isMobile) {
342
- return (_jsx(Drawer, { side: side, open: openMobile, onOpenChange: setOpenMobile, children: _jsx(DrawerContent, { "data-slot": "sidebar-sheet", className: cn("w-[min(18rem,calc(100vw-3rem))] **:data-[slot=drawer-body]:gap-0 **:data-[slot=drawer-body]:p-0"), children: _jsxs(SidebarSurfaceContext.Provider, { value: "sheet", children: [_jsx(DrawerTitle, { className: "sr-only", children: props["aria-label"] ?? "Navigation" }), _jsx("nav", { "data-slot": "sidebar", "data-side": side, "data-size": size, className: cn(panelClass, "relative min-h-0 flex-1 bg-background", sizeClass, className), ...props, children: content })] }) }) }));
347
+ return (_jsx(Drawer, { side: side, open: openMobile, onOpenChange: setOpenMobile, children: _jsx(DrawerContent, { "data-slot": "sidebar-sheet", className: cn("w-[min(18rem,calc(100vw-3rem))] **:data-[slot=drawer-body]:gap-0 **:data-[slot=drawer-body]:p-0"), children: _jsxs(SidebarSurfaceContext.Provider, { value: "sheet", children: [_jsx(DrawerTitle, { className: "sr-only", children: props["aria-label"] ?? text.navigation }), _jsx("nav", { "data-slot": "sidebar", "data-side": side, "data-size": size, className: cn(panelClass, "relative min-h-0 flex-1 bg-background", sizeClass, className), ...props, children: content })] }) }) }));
343
348
  }
344
349
  const offcanvas = state === "collapsed" && collapsible === "offcanvas";
345
350
  return (_jsx("div", { "data-slot": "sidebar-shell", "data-variant": variant, "data-size": size, style: dense
346
351
  ? { "--sidebar-width-icon": "calc(var(--control-h-sm) + 25px)" }
347
- : undefined, "data-state": state, "data-collapsible": state === "collapsed" ? collapsible : undefined, "data-side": side, className: cn("group/sidebar sticky top-0 hidden h-svh max-h-full w-(--sidebar-width) shrink-0 overflow-clip md:block", "transition-[width] duration-(--duration) ease-brand", "data-[collapsible=icon]:w-(--sidebar-width-icon) data-[collapsible=offcanvas]:w-0"), children: _jsx("nav", { "data-slot": "sidebar", "data-side": side, "data-size": size, inert: offcanvas || undefined, className: cn(panelClass, sizeClass, "absolute inset-y-0 w-(--sidebar-width) border-border/60 transition-[width] duration-(--duration) ease-brand", "group-data-[collapsible=icon]/sidebar:w-(--sidebar-width-icon)", side === "left" ? "left-0" : "right-0", variant !== "sidebar" ? undefined : side === "left" ? "border-e" : "border-s", className), ...props, children: content }) }));
352
+ : undefined, "data-state": state, "data-collapsible": state === "collapsed" ? collapsible : undefined, "data-side": side, className: cn("group/sidebar sticky top-0 hidden h-svh max-h-full w-(--sidebar-width) shrink-0 overflow-clip md:block", "transition-[width] duration-(--duration) ease-brand", "data-[collapsible=icon]:w-(--sidebar-width-icon) data-[collapsible=offcanvas]:w-0"), children: _jsx("nav", { "data-slot": "sidebar", "data-side": side, "data-size": size, inert: offcanvas || undefined, className: cn(panelClass, sizeClass, "absolute inset-y-0 w-(--sidebar-width) border-border/60 transition-[width] duration-(--duration) ease-brand", "group-data-[collapsible=icon]/sidebar:w-(--sidebar-width-icon)", side === "left" ? "start-0" : "end-0", variant !== "sidebar" ? undefined : side === "left" ? "border-e" : "border-s", className), ...props, children: content }) }));
348
353
  }
349
354
  /** The top of an app-shell sidebar: a logo, a workspace switcher, a search row. Never scrolls. */
350
355
  export function SidebarHeader({ className, ...props }) {
@@ -396,10 +401,11 @@ function textOf(node) {
396
401
  /**
397
402
  * One navigation row. Renders an `<a>`; pass `render={<Link to="…" />}` for router links.
398
403
  * Leading icons are 16px; a trailing `Kbd`, `Tag` or `SidebarMenuBadge` is pushed to the end
399
- * with `ml-auto`. In an icon-collapsed app shell it shrinks to a 38px square with a tooltip.
404
+ * with `ms-auto`. In an icon-collapsed app shell it shrinks to a 38px square with a tooltip.
400
405
  */
401
406
  export function SidebarItem({ current, tooltip, render, ref, className, children, onClick, ...props }) {
402
407
  const shell = React.useContext(SidebarContext);
408
+ const side = React.useContext(SidebarSideContext);
403
409
  const surface = React.useContext(SidebarSurfaceContext);
404
410
  const dense = React.useContext(SidebarSizeContext) === "sm";
405
411
  const inShell = shell !== null;
@@ -423,9 +429,11 @@ export function SidebarItem({ current, tooltip, render, ref, className, children
423
429
  className: cn(
424
430
  // cursor-pointer: rows may render as a <button> (theme switch, account menu), which has no pointer by default.
425
431
  "flex min-h-(--control-h) w-full cursor-pointer items-center rounded-button material-row font-body leading-none no-underline focus-ring select-none", dense ? "gap-2 px-2.5 text-[13px]" : "gap-2.5 px-3 text-sm", "aria-disabled:pointer-events-none aria-disabled:opacity-50",
426
- // Hover is quieter than current: the label brightens over the sidebar's gliding fill (HoverGlide),
432
+ // Hover is quieter than current: the label brightens (over the gliding fill with hover="glide"),
427
433
  // the row itself takes no fill, edge or shadow. The raised row means "you are here".
428
434
  "hover:not-aria-[current=page]:bg-transparent! hover:not-aria-[current=page]:bg-none! hover:not-aria-[current=page]:shadow-none!",
435
+ // A row rests in the muted ink, so the hovered one stands out in full: black, or white in dark mode.
436
+ "not-aria-[current=page]:text-muted-foreground hover:not-aria-[current=page]:text-foreground",
429
437
  // While the current row glides (CurrentGlide), the old and new rows stay flat.
430
438
  "data-glide:transition-none! data-[glide=hidden]:bg-transparent! data-[glide=hidden]:bg-none! data-[glide=hidden]:shadow-none!", "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", inShell && "overflow-hidden whitespace-nowrap", inShell &&
431
439
  // A square in the icon rail with the 16px icon centred: (row - icon - border) / 2 a side.
@@ -439,11 +447,11 @@ export function SidebarItem({ current, tooltip, render, ref, className, children
439
447
  const label = tooltip ?? textOf(children);
440
448
  if (!label)
441
449
  return element;
442
- return (_jsxs(Tooltip, { disabled: !iconRail, children: [_jsx(TooltipTrigger, { render: element }), _jsx(TooltipContent, { side: "right", align: "center", sideOffset: 10, children: label })] }));
450
+ return (_jsxs(Tooltip, { disabled: !iconRail, children: [_jsx(TooltipTrigger, { render: element }), _jsx(TooltipContent, { side: side === "left" ? "inline-end" : "inline-start", align: "center", sideOffset: 10, children: label })] }));
443
451
  }
444
452
  /** A count at the end of a row ("12"): mono, tabular, muted. Hidden in the icon rail. */
445
453
  export function SidebarMenuBadge({ className, ...props }) {
446
- return (_jsx("span", { "data-slot": "sidebar-menu-badge", className: cn("ml-auto pl-2 font-mono text-xs leading-none text-muted-foreground tabular-nums group-data-[collapsible=icon]/sidebar:hidden", className), ...props }));
454
+ return (_jsx("span", { "data-slot": "sidebar-menu-badge", className: cn("ms-auto ps-2 font-mono text-xs leading-none text-muted-foreground tabular-nums group-data-[collapsible=icon]/sidebar:hidden", className), ...props }));
447
455
  }
448
456
  /* ── Controls ──────────────────────────────────────────────────────────────── */
449
457
  /**
@@ -452,14 +460,15 @@ export function SidebarMenuBadge({ className, ...props }) {
452
460
  */
453
461
  export function SidebarTrigger({ variant = "ghost", size = "icon", className, children, onClick, ...props }) {
454
462
  const { toggleSidebar, isMobile, open, openMobile } = useSidebar();
455
- return (_jsx(Button, { "data-slot": "sidebar-trigger", variant: variant, size: size, "aria-label": "Toggle sidebar", "aria-expanded": isMobile ? openMobile : open, className: cn("text-muted-foreground",
463
+ const text = useMessages("sidebar", defaultMessages);
464
+ return (_jsx(Button, { "data-slot": "sidebar-trigger", variant: variant, size: size, "aria-label": text.toggle, "aria-expanded": isMobile ? openMobile : open, className: cn("text-muted-foreground",
456
465
  // The circle pads its glyph by ~10px; pull what follows in, and give a separator after
457
466
  // it a little more room, so the gaps either side of the separator read the same.
458
- size === "icon" && "-mr-1.5 [&+[data-slot=separator]]:mr-1", size === "icon-sm" && "-mr-1 [&+[data-slot=separator]]:mr-0.75", className), onClick: (event) => {
467
+ size === "icon" && "-me-1.5 [&+[data-slot=separator]]:me-1", size === "icon-sm" && "-me-1 [&+[data-slot=separator]]:me-0.75", className), onClick: (event) => {
459
468
  onClick?.(event);
460
469
  if (!event.defaultPrevented)
461
470
  toggleSidebar();
462
- }, ...props, children: children ?? _jsx(PanelLeftIcon, { "aria-hidden": true }) }));
471
+ }, ...props, children: children ?? _jsx(PanelLeftIcon, { "aria-hidden": true, className: "rtl:-scale-x-100" }) }));
463
472
  }
464
473
  /**
465
474
  * A thin strip along the sidebar's inner edge: hover shows the hairline in `--control-focus`,
@@ -468,15 +477,20 @@ export function SidebarTrigger({ variant = "ghost", size = "icon", className, ch
468
477
  export function SidebarRail({ className, onClick, ...props }) {
469
478
  const { toggleSidebar, state, isMobile, collapsible } = useSidebar();
470
479
  const surface = React.useContext(SidebarSurfaceContext);
480
+ const text = useMessages("sidebar", defaultMessages);
471
481
  if (isMobile || surface === "sheet" || collapsible === "none")
472
482
  return null;
473
- return (_jsx("button", { type: "button", "data-slot": "sidebar-rail", "aria-label": "Toggle sidebar", title: "Toggle sidebar", tabIndex: -1, onClick: (event) => {
483
+ return (_jsx("button", { type: "button", "data-slot": "sidebar-rail", "aria-label": text.toggle, title: text.toggle, tabIndex: -1, onClick: (event) => {
474
484
  onClick?.(event);
475
485
  if (!event.defaultPrevented)
476
486
  toggleSidebar();
477
- }, className: cn("absolute inset-y-0 z-20 w-2 border-0 bg-transparent p-0 outline-none", "after:absolute after:inset-y-0 after:w-px after:bg-transparent after:transition-[background-color] after:duration-(--duration) after:ease-brand after:content-[''] hover:after:bg-control-focus", "group-data-[side=left]/sidebar:right-0 group-data-[side=right]/sidebar:left-0 group-data-[side=left]/sidebar:after:right-[-1px] group-data-[side=right]/sidebar:after:left-[-1px]", state === "expanded"
478
- ? "group-data-[side=left]/sidebar:cursor-w-resize group-data-[side=right]/sidebar:cursor-e-resize"
479
- : "group-data-[side=left]/sidebar:cursor-e-resize group-data-[side=right]/sidebar:cursor-w-resize", className), ...props }));
487
+ }, className: cn("absolute inset-y-0 z-20 w-2 border-0 bg-transparent p-0 outline-none", "after:absolute after:inset-y-0 after:w-px after:bg-transparent after:transition-[background-color] after:duration-(--duration) after:ease-brand after:content-[''] hover:after:bg-control-focus",
488
+ // On the edge next to the page: the end of a start sidebar, in either direction.
489
+ "group-data-[side=left]/sidebar:end-0 group-data-[side=right]/sidebar:start-0 group-data-[side=left]/sidebar:after:-end-px group-data-[side=right]/sidebar:after:-start-px",
490
+ // The cursor points the way the panel will go: towards its edge to close, away to open.
491
+ state === "expanded"
492
+ ? "group-data-[side=left]/sidebar:cursor-w-resize group-data-[side=right]/sidebar:cursor-e-resize rtl:group-data-[side=left]/sidebar:cursor-e-resize rtl:group-data-[side=right]/sidebar:cursor-w-resize"
493
+ : "group-data-[side=left]/sidebar:cursor-e-resize group-data-[side=right]/sidebar:cursor-w-resize rtl:group-data-[side=left]/sidebar:cursor-w-resize rtl:group-data-[side=right]/sidebar:cursor-e-resize", className), ...props }));
480
494
  }
481
495
  /**
482
496
  * The main area beside an app-shell sidebar: a `<main>` column that takes the remaining width.
@@ -485,5 +499,7 @@ export function SidebarRail({ className, onClick, ...props }) {
485
499
  * Otherwise it has no fill of its own: the page ground shows through.
486
500
  */
487
501
  export function SidebarInset({ className, ...props }) {
488
- return (_jsx("main", { "data-slot": "sidebar-inset", className: cn("relative flex min-w-0 flex-1 flex-col", className), ...props }));
502
+ return (_jsx("main", { "data-slot": "sidebar-inset",
503
+ // Clear of a BottomNav on a phone: --bottom-nav-h is 0 wherever no bar is shown.
504
+ className: cn("relative flex min-w-0 flex-1 flex-col pb-(--bottom-nav-h)", className), ...props }));
489
505
  }
@@ -1,4 +1,19 @@
1
1
  import * as React from "react";
2
+ export interface SiteHeaderMessages {
3
+ /** The name of the links' `nav` landmark. */
4
+ nav: string;
5
+ /** The phone menu button. */
6
+ openMenu: string;
7
+ /** The phone panel's close button. */
8
+ closeMenu: string;
9
+ /** The phone panel's title. */
10
+ menu: string;
11
+ }
12
+ declare module "./locale" {
13
+ interface Messages {
14
+ siteHeader: SiteHeaderMessages;
15
+ }
16
+ }
2
17
  /** A page inside a `SiteHeaderLink`'s dropdown panel. */
3
18
  export interface SiteHeaderLinkItem {
4
19
  label: React.ReactNode;
@@ -28,32 +43,51 @@ export interface SiteHeaderProps extends Omit<React.ComponentProps<"header">, "c
28
43
  logo: React.ReactNode;
29
44
  /** Primary navigation, in order, about five links: e.g. "Product", "Docs", "Pricing", "Blog", "About". */
30
45
  links: SiteHeaderLink[];
31
- /** Right-most slot, after the hairline divider: locale switch, theme toggle, one CTA at most. */
46
+ /** The slot at the end: locale switch, theme toggle, one CTA at most. */
32
47
  actions?: React.ReactNode;
33
48
  /**
34
- * Force the scrolled treatment (background/80, blur, hairline). By default it switches on
35
- * once the window scrolls past `scrollThreshold`.
49
+ * Where the links sit. `end` (default): with the actions at the end of the bar, after a hairline
50
+ * divider. `start`: right after the logo, with the actions on their own at the end — for an app
51
+ * whose bar reads logo, sections, then search and account.
52
+ */
53
+ align?: "start" | "end";
54
+ /**
55
+ * Force the scrolled treatment (the page ground and a hairline), e.g. for a page that scrolls
56
+ * in a container of its own. By default it comes in as the window scrolls past
57
+ * `scrollThreshold`, over the bar's own height.
36
58
  */
37
59
  scrolled?: boolean;
38
- /** Pixels of scroll before the header gains its background. Defaults to 8. */
60
+ /** Pixels of scroll before the ground starts to come in. Defaults to 8. */
39
61
  scrollThreshold?: number;
40
- /** Accessible name of the `<nav>`. Defaults to "Main". */
62
+ /** Accessible name of the `<nav>`. Defaults to "Main", or `messages.siteHeader.nav`. */
41
63
  navLabel?: string;
42
- /** Accessible names for the mobile menu buttons. */
64
+ /**
65
+ * Accessible names for the mobile menu buttons. Default `messages.siteHeader` `openMenu`,
66
+ * `closeMenu` and `menu`.
67
+ */
43
68
  menuLabels?: {
44
69
  open?: string;
45
70
  close?: string;
46
71
  title?: string;
47
72
  };
73
+ /**
74
+ * The phone menu: below 48rem of header the links fold into a menu button that opens a full
75
+ * panel. `false` leaves it out, for an app with navigation of its own on phones (a bottom tab
76
+ * bar): the links show from 48rem up, and the actions stay in the bar at every width.
77
+ * Default `true`.
78
+ */
79
+ menu?: boolean;
48
80
  }
49
81
  /**
50
82
  * SiteHeader — the sticky top bar of an zon site, composed from `NavigationMenu`.
51
83
  *
52
84
  * `NavigationMenu` is the primitive (links, triggers, the shared dropdown popup); SiteHeader
53
- * is the pattern around it: logo left; the menu, a hairline divider and an actions slot right;
54
- * transparent at the top of the page, `background/80` with a backdrop blur and a hairline once
55
- * the page scrolls; and below `md` a full-height panel opened by a menu button. Give an entry
56
- * `items` and it opens a dropdown panel. The rule people break: filling the bar with buttons.
57
- * One CTA at most — the links are the navigation, the actions slot is for locale and theme.
85
+ * is the pattern around it: logo at the start; the menu, a hairline divider and an actions slot at
86
+ * the end (or the menu beside the logo, with `align="start"`); transparent at the top of the page,
87
+ * and once it scrolls the page ground itself (its colour, grain and faint light, lined up with the
88
+ * page's) fading in over a hairline, so content passes under the bar rather than through a band of
89
+ * another colour; and below 48rem of bar a full-height panel opened by a menu button. Give an
90
+ * entry `items` and it opens a dropdown panel. The rule people break: filling the bar with
91
+ * buttons. One CTA at most — the links are the navigation, the actions slot is for locale and theme.
58
92
  */
59
- export declare function SiteHeader({ logo, links, actions, scrolled: scrolledProp, scrollThreshold, navLabel, menuLabels, className, dir, ...props }: SiteHeaderProps): React.JSX.Element;
93
+ export declare function SiteHeader({ logo, links, actions, align, scrolled: scrolledProp, scrollThreshold, navLabel: navLabelProp, menuLabels, menu, className, style, dir, ...props }: SiteHeaderProps): React.JSX.Element;
@@ -7,7 +7,14 @@ import * as React from "react";
7
7
  import { cn } from "../lib/cn.js";
8
8
  import { usePopupDir } from "./_overlay.js";
9
9
  import { Button } from "./button.js";
10
+ import { useMessages } from "./locale.js";
10
11
  import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "./navigation-menu.js";
12
+ const defaultMessages = {
13
+ nav: "Main",
14
+ openMenu: "Open menu",
15
+ closeMenu: "Close menu",
16
+ menu: "Menu",
17
+ };
11
18
  /** A link in the mobile panel: a plain `<a>`, or the entry's router link through `render`. */
12
19
  function PanelLink({ render, href, ...props }) {
13
20
  return useRender({
@@ -16,35 +23,72 @@ function PanelLink({ render, href, ...props }) {
16
23
  props: { ...props, href: render ? undefined : href },
17
24
  });
18
25
  }
19
- function useScrolled(threshold, forced) {
26
+ /**
27
+ * Whether the window has scrolled past `threshold`, and the scrolled ground with it: 0 until
28
+ * `threshold`, then up to 1 over the bar's own height. Where the browser ties animations to the
29
+ * scroll, the stylesheet draws it from the scroll position itself (navigation.css), in the same
30
+ * frame the page moves; this measures the bar's height for it (`--site-header-span`). Elsewhere it
31
+ * writes the ground as `--site-header-ground`, once a frame. Tied to the scroll, the bar is solid
32
+ * by the time content a bar's height down reaches it, however fast the page moves.
33
+ */
34
+ function useScrollGround(ref, threshold, forced) {
20
35
  const [scrolled, setScrolled] = React.useState(false);
21
36
  React.useEffect(() => {
22
- if (forced !== undefined || typeof window === "undefined")
37
+ const header = ref.current;
38
+ if (forced !== undefined || !header)
23
39
  return;
24
- const update = () => setScrolled(window.scrollY > threshold);
40
+ const linked = typeof CSS !== "undefined" && CSS.supports("animation-timeline: scroll()");
41
+ let frame = 0;
42
+ let span = 0;
43
+ const update = () => {
44
+ frame = 0;
45
+ const y = window.scrollY;
46
+ // Written only when it changes: a style change while the page scrolls makes work for the
47
+ // browser in the very frames the bar has to keep up in.
48
+ const height = Math.max(header.offsetHeight, 1);
49
+ if (height !== span)
50
+ header.style.setProperty("--site-header-span", `${(span = height)}px`);
51
+ if (!linked)
52
+ header.style.setProperty("--site-header-ground", String(Math.min(1, Math.max(0, (y - threshold) / span))));
53
+ setScrolled(y > threshold);
54
+ };
55
+ const schedule = () => {
56
+ frame ||= requestAnimationFrame(update);
57
+ };
25
58
  update();
26
- window.addEventListener("scroll", update, { passive: true });
27
- return () => window.removeEventListener("scroll", update);
28
- }, [threshold, forced]);
59
+ window.addEventListener("scroll", schedule, { passive: true });
60
+ window.addEventListener("resize", schedule, { passive: true });
61
+ return () => {
62
+ cancelAnimationFrame(frame);
63
+ window.removeEventListener("scroll", schedule);
64
+ window.removeEventListener("resize", schedule);
65
+ header.style.removeProperty("--site-header-span");
66
+ header.style.removeProperty("--site-header-ground");
67
+ };
68
+ }, [ref, threshold, forced]);
29
69
  return forced ?? scrolled;
30
70
  }
31
71
  /**
32
72
  * SiteHeader — the sticky top bar of an zon site, composed from `NavigationMenu`.
33
73
  *
34
74
  * `NavigationMenu` is the primitive (links, triggers, the shared dropdown popup); SiteHeader
35
- * is the pattern around it: logo left; the menu, a hairline divider and an actions slot right;
36
- * transparent at the top of the page, `background/80` with a backdrop blur and a hairline once
37
- * the page scrolls; and below `md` a full-height panel opened by a menu button. Give an entry
38
- * `items` and it opens a dropdown panel. The rule people break: filling the bar with buttons.
39
- * One CTA at most — the links are the navigation, the actions slot is for locale and theme.
75
+ * is the pattern around it: logo at the start; the menu, a hairline divider and an actions slot at
76
+ * the end (or the menu beside the logo, with `align="start"`); transparent at the top of the page,
77
+ * and once it scrolls the page ground itself (its colour, grain and faint light, lined up with the
78
+ * page's) fading in over a hairline, so content passes under the bar rather than through a band of
79
+ * another colour; and below 48rem of bar a full-height panel opened by a menu button. Give an
80
+ * entry `items` and it opens a dropdown panel. The rule people break: filling the bar with
81
+ * buttons. One CTA at most — the links are the navigation, the actions slot is for locale and theme.
40
82
  */
41
- export function SiteHeader({ logo, links, actions, scrolled: scrolledProp, scrollThreshold = 8, navLabel = "Main", menuLabels, className, dir, ...props }) {
42
- const scrolled = useScrolled(scrollThreshold, scrolledProp);
83
+ export function SiteHeader({ logo, links, actions, align = "end", scrolled: scrolledProp, scrollThreshold = 8, navLabel: navLabelProp, menuLabels, menu = true, className, style, dir, ...props }) {
84
+ const text = useMessages("siteHeader", defaultMessages);
85
+ const navLabel = navLabelProp ?? text.nav;
86
+ const headerRef = React.useRef(null);
87
+ const menuButtonRef = React.useRef(null);
88
+ const scrolled = useScrollGround(headerRef, scrollThreshold, scrolledProp);
43
89
  const [open, setOpen] = React.useState(false);
44
90
  // The phone panel is portalled out of the page: it takes the header's direction itself.
45
91
  const panelDir = usePopupDir(dir);
46
- const headerRef = React.useRef(null);
47
- const menuButtonRef = React.useRef(null);
48
92
  // The header switches by its own width, not the window's: a container query hides the menu
49
93
  // button from 48rem of header up. Close the panel once the header grows past that and the
50
94
  // button is gone.
@@ -60,8 +104,18 @@ export function SiteHeader({ logo, links, actions, scrolled: scrolledProp, scrol
60
104
  observer.observe(header);
61
105
  return () => observer.disconnect();
62
106
  }, [open]);
63
- return (_jsx("header", { ref: headerRef, "data-slot": "site-header", "data-scrolled": scrolled ? "" : undefined, dir: dir, className: cn("@container/site-header sticky top-0 z-40 w-full border-b border-transparent", "transition-[background-color,border-color,backdrop-filter] duration-(--duration) ease-(--ease)", "data-scrolled:border-border/60 data-scrolled:bg-background/80 data-scrolled:backdrop-blur-md", className), ...props, children: _jsxs("div", { className: "container-page flex min-h-16 items-center justify-between gap-6", children: [_jsx("div", { "data-slot": "site-header-logo", className: "flex shrink-0 items-center", children: logo }), _jsxs("div", { className: "hidden items-center gap-4 @3xl/site-header:flex", children: [_jsx(NavigationMenu, { "aria-label": navLabel, children: _jsx(NavigationMenuList, { children: links.map((link, i) => (_jsx(NavigationMenuItem, { children: link.items?.length ? (_jsxs(_Fragment, { children: [_jsx(NavigationMenuTrigger, { children: link.label }), _jsx(NavigationMenuContent, { children: _jsx("ul", { className: "m-0 grid list-none gap-1 p-0 sm:w-[400px]", children: link.items.map((item, j) => (_jsx("li", { children: _jsxs(NavigationMenuLink, { variant: "row", href: item.render ? undefined : item.href, render: item.render, active: item.current, children: [item.label, item.description != null && _jsx("small", { children: item.description })] }) }, j))) }) })] })) : (_jsx(NavigationMenuLink, { href: link.render ? undefined : link.href, render: link.render, active: link.current, children: link.label })) }, i))) }) }), actions != null && (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: "h-5 w-px bg-border" }), _jsx("div", { "data-slot": "site-header-actions", className: "flex items-center gap-2", children: actions })] }))] }), _jsxs(BaseDialog.Root, { open: open, onOpenChange: setOpen, children: [_jsx(BaseDialog.Trigger, { ref: menuButtonRef, render: _jsx(Button, { variant: "ghost", size: "icon", className: "@3xl/site-header:hidden" }), "aria-label": menuLabels?.open ?? "Open menu", children: _jsx(MenuIcon, {}) }), _jsx(BaseDialog.Portal, { children: _jsxs(BaseDialog.Popup, { "data-slot": "site-header-panel", dir: panelDir, className: cn("fixed inset-0 z-50 flex flex-col overflow-y-auto bg-background text-foreground outline-none", "transition-[opacity,translate] duration-(--duration) ease-(--ease)", "data-ending-style:-translate-y-2 data-ending-style:opacity-0 data-starting-style:-translate-y-2 data-starting-style:opacity-0"), children: [_jsx(BaseDialog.Title, { className: "sr-only", children: menuLabels?.title ?? "Menu" }), _jsxs("div", { className: "container-page flex min-h-16 items-center justify-between gap-6 border-b border-border/60", children: [_jsx("div", { className: "flex shrink-0 items-center", children: logo }), _jsx(BaseDialog.Close, { render: _jsx(Button, { variant: "ghost", size: "icon" }), "aria-label": menuLabels?.close ?? "Close menu", children: _jsx(XIcon, {}) })] }), _jsx("nav", { "aria-label": navLabel, className: "container-page flex-1", children: _jsx("ul", { className: "m-0 list-none p-0", children: links.map((link, i) => {
64
- const index = (_jsx("span", { className: "w-6 shrink-0 font-mono text-[12px] text-muted-foreground tabular-nums", children: String(i + 1).padStart(2, "0") }));
65
- return (_jsxs("li", { className: "border-b border-border/60", children: [link.href != null || link.render != null ? (_jsxs(PanelLink, { render: link.render, href: link.href, "aria-current": link.current ? "page" : undefined, onClick: () => setOpen(false), className: "flex items-baseline gap-5 py-5 text-foreground no-underline focus-ring", children: [index, _jsx("span", { className: "display text-[32px]", children: link.label })] })) : (_jsxs("div", { className: "flex items-baseline gap-5 pt-5 pb-2 text-foreground", children: [index, _jsx("span", { className: "display text-[32px]", children: link.label })] })), link.items?.length ? (_jsx("ul", { className: "m-0 -mt-1 list-none ps-11 pb-4", children: link.items.map((item, j) => (_jsx("li", { children: _jsx(PanelLink, { render: item.render, href: item.href, "aria-current": item.current ? "page" : undefined, onClick: () => setOpen(false), className: "flex min-h-(--control-h) items-center text-[17px] text-foreground-soft no-underline focus-ring aria-[current=page]:text-foreground", children: item.label }) }, j))) })) : null] }, i));
66
- }) }) }), actions != null && (_jsx("div", { className: "container-page flex items-center gap-3 py-6", children: actions }))] }) })] })] }) }));
107
+ const nav = (_jsx(NavigationMenu, { "aria-label": navLabel,
108
+ // Beside the logo, or without the phone menu, the links leave the bar below 48rem of it.
109
+ className: cn((align === "start" || !menu) && "hidden @3xl/site-header:block"), children: _jsx(NavigationMenuList, { children: links.map((link, i) => (_jsx(NavigationMenuItem, { children: link.items?.length ? (_jsxs(_Fragment, { children: [_jsx(NavigationMenuTrigger, { children: link.label }), _jsx(NavigationMenuContent, { children: _jsx("ul", { className: "m-0 grid list-none gap-1 p-0 sm:w-[400px]", children: link.items.map((item, j) => (_jsx("li", { children: _jsxs(NavigationMenuLink, { variant: "row", href: item.render ? undefined : item.href, render: item.render, active: item.current, children: [item.label, item.description != null && _jsx("small", { children: item.description })] }) }, j))) }) })] })) : (_jsx(NavigationMenuLink, { href: link.render ? undefined : link.href, render: link.render, active: link.current, children: link.label })) }, i))) }) }));
110
+ const actionsSlot = actions != null && (_jsx("div", { "data-slot": "site-header-actions", className: "flex items-center gap-2", children: actions }));
111
+ return (_jsxs("header", { ref: headerRef, "data-slot": "site-header", "data-scrolled": scrolled ? "" : undefined, "data-forced": scrolledProp === undefined ? undefined : "", dir: dir,
112
+ // The ground and its hairline are drawn in navigation.css, from --site-header-ground.
113
+ className: cn("@container/site-header sticky top-0 z-40 w-full border-b", className), style: {
114
+ ...style,
115
+ "--site-header-from": `${scrollThreshold}px`,
116
+ ...(scrolledProp !== undefined && { "--site-header-ground": scrolledProp ? 1 : 0 }),
117
+ }, ...props, children: [_jsx("span", { "aria-hidden": true, "data-slot": "site-header-ground" }), _jsxs("div", { className: cn("container-page flex min-h-16 items-center", align === "start" ? "gap-8" : "justify-between gap-6"), children: [_jsx("div", { "data-slot": "site-header-logo", className: "flex shrink-0 items-center", children: logo }), align === "start" ? (_jsxs(_Fragment, { children: [nav, actionsSlot && (_jsx("div", { className: cn("ms-auto items-center", menu ? "hidden @3xl/site-header:flex" : "flex"), children: actionsSlot }))] })) : (_jsxs("div", { className: cn("items-center gap-4", menu ? "hidden @3xl/site-header:flex" : "flex"), children: [nav, actionsSlot && (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: cn("h-5 w-px bg-border", !menu && "hidden @3xl/site-header:block") }), actionsSlot] }))] })), menu && (_jsxs(BaseDialog.Root, { open: open, onOpenChange: setOpen, children: [_jsx(BaseDialog.Trigger, { ref: menuButtonRef, render: _jsx(Button, { variant: "ghost", size: "icon", className: cn("@3xl/site-header:hidden", align === "start" && "ms-auto") }), "aria-label": menuLabels?.open ?? text.openMenu, children: _jsx(MenuIcon, {}) }), _jsx(BaseDialog.Portal, { children: _jsxs(BaseDialog.Popup, { "data-slot": "site-header-panel", dir: panelDir, className: cn("fixed inset-0 z-50 flex flex-col overflow-y-auto bg-background text-foreground outline-none", "pt-[env(safe-area-inset-top,0px)] pb-[env(safe-area-inset-bottom,0px)]", "transition-[opacity,translate] duration-(--duration) ease-(--ease)", "data-ending-style:-translate-y-2 data-ending-style:opacity-0 data-starting-style:-translate-y-2 data-starting-style:opacity-0"), children: [_jsx(BaseDialog.Title, { className: "sr-only", children: menuLabels?.title ?? text.menu }), _jsxs("div", { className: "container-page flex min-h-16 items-center justify-between gap-6 border-b border-border/60", children: [_jsx("div", { className: "flex shrink-0 items-center", children: logo }), _jsx(BaseDialog.Close, { render: _jsx(Button, { variant: "ghost", size: "icon" }), "aria-label": menuLabels?.close ?? text.closeMenu, children: _jsx(XIcon, {}) })] }), _jsx("nav", { "aria-label": navLabel, className: "container-page flex-1", children: _jsx("ul", { className: "m-0 list-none p-0", children: links.map((link, i) => {
118
+ const index = (_jsx("span", { className: "w-6 shrink-0 font-mono text-[12px] text-muted-foreground tabular-nums", children: String(i + 1).padStart(2, "0") }));
119
+ return (_jsxs("li", { className: "border-b border-border/60", children: [link.href != null || link.render != null ? (_jsxs(PanelLink, { render: link.render, href: link.href, "aria-current": link.current ? "page" : undefined, onClick: () => setOpen(false), className: "flex items-baseline gap-5 py-5 text-foreground no-underline focus-ring", children: [index, _jsx("span", { className: "display text-[32px]", children: link.label })] })) : (_jsxs("div", { className: "flex items-baseline gap-5 pt-5 pb-2 text-foreground", children: [index, _jsx("span", { className: "display text-[32px]", children: link.label })] })), link.items?.length ? (_jsx("ul", { className: "m-0 -mt-1 list-none ps-11 pb-4", children: link.items.map((item, j) => (_jsx("li", { children: _jsx(PanelLink, { render: item.render, href: item.href, "aria-current": item.current ? "page" : undefined, onClick: () => setOpen(false), className: "flex min-h-(--control-h) items-center text-[17px] text-foreground-soft no-underline focus-ring aria-[current=page]:text-foreground", children: item.label }) }, j))) })) : null] }, i));
120
+ }) }) }), actions != null && (_jsx("div", { className: "container-page flex items-center gap-3 py-6", children: actions }))] }) })] }))] })] }));
67
121
  }
@@ -5,6 +5,7 @@ import * as React from "react";
5
5
  import { cn, sx } from "../lib/cn.js";
6
6
  import { useFormReset } from "../lib/form-reset.js";
7
7
  import { mergeRefs } from "../lib/merge-refs.js";
8
+ import { useLocale } from "./locale.js";
8
9
  /* ── Squash and stretch ────────────────────────────────────────────────────── */
9
10
  /** How far a thumb stretches at most (0.4 = 40% longer along the track). */
10
11
  const MAX_STRETCH = 0.4;
@@ -123,7 +124,8 @@ thumbAlignment = "edge", className, children, ref, ...props }) {
123
124
  const [resetKey, formRef] = useFormReset();
124
125
  const refs = React.useMemo(() => mergeRefs(formRef, ref), [formRef, ref]);
125
126
  useSquash(control, squash, resetKey);
126
- return (_jsxs(BaseSlider.Root, { ref: refs, "data-slot": "slider", thumbAlignment: thumbAlignment, className: sx("group/slider flex w-full flex-col gap-2 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-disabled:[&>[data-slot=slider-control]]:opacity-55", className), ...props, children: [hasHeader && (_jsxs("div", { "data-slot": "slider-header", className: "flex items-baseline justify-between gap-4", children: [label != null && (_jsx(BaseSlider.Label, { "data-slot": "slider-label", className: "text-sm leading-snug font-medium text-foreground select-none group-data-disabled/slider:text-foreground-soft", children: label })), showValue && (_jsx(BaseSlider.Value, { "data-slot": "slider-value", className: "ms-auto font-mono text-xs text-muted-foreground tabular-nums group-data-disabled/slider:opacity-55", children: (formatted) => formatted.join(" – ") }))] })), _jsx(BaseSlider.Control, { ref: control, "data-slot": "slider-control", className: "flex w-full touch-none items-center py-2 select-none data-disabled:cursor-not-allowed data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-32 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col data-[orientation=vertical]:px-2 data-[orientation=vertical]:py-0", children: _jsxs(BaseSlider.Track, { "data-slot": "slider-track", className: "relative h-1.5 w-full material-field rounded-full select-none data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5", children: [_jsx(BaseSlider.Indicator, { "data-slot": "slider-indicator", className: "rounded-full bg-foreground-soft select-none" }), Array.from({ length: count }, (_, index) => (_jsx(BaseSlider.Thumb, { index: index, "aria-label": thumbLabels?.[index], "data-slot": "slider-thumb", className: cn("size-[18px] cursor-grab rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent select-none", "shadow-thumb", "transition-[background-color,box-shadow] duration-(--duration) ease-brand", "hover:not-data-disabled:bg-control-hover data-dragging:cursor-grabbing",
127
+ const locale = useLocale();
128
+ return (_jsxs(BaseSlider.Root, { ref: refs, "data-slot": "slider", thumbAlignment: thumbAlignment, className: sx("group/slider flex w-full flex-col gap-2 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-disabled:[&>[data-slot=slider-control]]:opacity-55", className), locale: locale, ...props, children: [hasHeader && (_jsxs("div", { "data-slot": "slider-header", className: "flex items-baseline justify-between gap-4", children: [label != null && (_jsx(BaseSlider.Label, { "data-slot": "slider-label", className: "text-sm leading-snug font-medium text-foreground select-none group-data-disabled/slider:text-foreground-soft", children: label })), showValue && (_jsx(BaseSlider.Value, { "data-slot": "slider-value", className: "ms-auto font-mono text-xs text-muted-foreground tabular-nums group-data-disabled/slider:opacity-55", children: (formatted) => formatted.join(" – ") }))] })), _jsx(BaseSlider.Control, { ref: control, "data-slot": "slider-control", className: "flex w-full touch-none items-center py-2 select-none data-disabled:cursor-not-allowed data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-32 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col data-[orientation=vertical]:px-2 data-[orientation=vertical]:py-0", children: _jsxs(BaseSlider.Track, { "data-slot": "slider-track", className: "relative h-1.5 w-full material-field rounded-full select-none data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5", children: [_jsx(BaseSlider.Indicator, { "data-slot": "slider-indicator", className: "rounded-full bg-foreground-soft select-none" }), Array.from({ length: count }, (_, index) => (_jsx(BaseSlider.Thumb, { index: index, "aria-label": thumbLabels?.[index], "data-slot": "slider-thumb", className: cn("size-[18px] cursor-grab rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent select-none", "shadow-thumb", "transition-[background-color,box-shadow] duration-(--duration) ease-brand", "hover:not-data-disabled:bg-control-hover data-dragging:cursor-grabbing",
127
129
  // Held, it takes the hover fill; with `squash`, dragged, it squashes and stretches (useSquash).
128
130
  "active:not-data-disabled:bg-control-hover data-dragging:bg-control-hover", "has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-0 has-[:focus-visible]:outline-control-focus", "data-disabled:cursor-not-allowed") }, index))), children] }) })] }, resetKey));
129
131
  }
@@ -0,0 +1,178 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ import * as React from "react";
3
+ import { type ButtonProps } from "./button.js";
4
+ /** Where an item is, as it is read out: the list's label (when it has one), and its position. */
5
+ export interface SortableAnnouncedPlace {
6
+ /** The list's `label`, if it has one. */
7
+ list?: string;
8
+ /** 1-based. */
9
+ position: number;
10
+ /** Items in the list. */
11
+ count: number;
12
+ }
13
+ export interface SortableMessages {
14
+ /** The handle's accessible name: "Move Chapter 3". */
15
+ handle: (item: string) => string;
16
+ /** The handle's description: how to move an item with the keyboard. */
17
+ instructions: string;
18
+ /** A pointer drag started. */
19
+ pickedUp: (item: string, place: SortableAnnouncedPlace) => string;
20
+ /** Picked up with the keyboard: also says which keys move it. */
21
+ pickedUpKeyboard: (item: string, place: SortableAnnouncedPlace) => string;
22
+ /** An arrow key moved it within its list. */
23
+ movedWithin: (item: string, place: SortableAnnouncedPlace) => string;
24
+ /** An arrow key moved it into another list. */
25
+ movedTo: (item: string, place: SortableAnnouncedPlace) => string;
26
+ /** Moved by `useSortable().move` — from a menu, say. */
27
+ moved: (item: string, place: SortableAnnouncedPlace) => string;
28
+ dropped: (item: string, place: SortableAnnouncedPlace) => string;
29
+ cancelled: (item: string, place: SortableAnnouncedPlace) => string;
30
+ /** An arrow key at the end of the list, or past the last list. */
31
+ cannotMove: (item: string, place: SortableAnnouncedPlace) => string;
32
+ }
33
+ declare module "./locale" {
34
+ interface Messages {
35
+ sortable: SortableMessages;
36
+ }
37
+ }
38
+ /** Several lists, by id, each an ordered list of item ids — the columns of a board. */
39
+ export type SortableLists = Record<string, string[]>;
40
+ /** One list (an array of item ids) or several (`SortableLists`). */
41
+ export type SortableValue = string[] | SortableLists;
42
+ /** A place in the lists: the list's id (`""` for a single list) and the index in it. */
43
+ export interface SortablePlace {
44
+ list: string;
45
+ index: number;
46
+ }
47
+ export interface SortableMoveDetails {
48
+ /** The item's id. */
49
+ item: string;
50
+ from: SortablePlace;
51
+ to: SortablePlace;
52
+ /** What moved it: a drag, a key, `useSortable().move`, or putting it back on a cancel. */
53
+ source: "pointer" | "keyboard" | "api" | "cancel";
54
+ }
55
+ export interface SortableMoveEndDetails {
56
+ item: string;
57
+ /** Where it was picked up. */
58
+ from: SortablePlace;
59
+ /** Where it was put down — `from` again when cancelled. */
60
+ to: SortablePlace;
61
+ cancelled: boolean;
62
+ }
63
+ /**
64
+ * Takes `item` out of wherever it is and puts it at `to` — the index in the target list without
65
+ * the item. Works on one list (`to.list` is ignored) and on several. The value is not changed; a
66
+ * new one is returned. Every way of moving an item should go through it.
67
+ */
68
+ export declare function moveSortableItem<V extends SortableValue>(value: V, item: string, to: Partial<SortablePlace>): V;
69
+ interface ItemContextValue {
70
+ value: string;
71
+ label: string;
72
+ disabled: boolean;
73
+ dragging: boolean;
74
+ lifted: boolean;
75
+ overlay: boolean;
76
+ }
77
+ /** The item a part is in: its value, and whether it is being dragged, lifted, or is the copy under the pointer. */
78
+ export declare function useSortableItem(): ItemContextValue;
79
+ export interface UseSortable {
80
+ /**
81
+ * Move an item without a drag — from a "Move to" menu, say — and announce it. `index` defaults
82
+ * to the end of the list. `focus` is a selector inside the item to focus after the move, as the
83
+ * item remounts in another list; by default focus is left alone.
84
+ */
85
+ move: (item: string, to: Partial<SortablePlace>, options?: {
86
+ focus?: string;
87
+ }) => void;
88
+ /** The item being dragged with the pointer, if any. */
89
+ dragging: string | null;
90
+ /** The item picked up with the keyboard, if any. */
91
+ lifted: string | null;
92
+ }
93
+ /** The Sortable around a part: `move` an item from your own controls, and what is moving now. */
94
+ export declare function useSortable(): UseSortable;
95
+ export interface SortableProps<V extends SortableValue = SortableValue> extends Omit<useRender.ComponentProps<"div">, "defaultValue" | "onChange"> {
96
+ /** The order: an array of item ids for one list, or `{ [listId]: ids }` for several. */
97
+ value?: V;
98
+ /** The order to start from, uncontrolled. */
99
+ defaultValue?: V;
100
+ /**
101
+ * Called with the new order on every move — each arrow key while an item is lifted, a drop, a
102
+ * cancel that puts it back. Save on `onMoveEnd` instead if every step would be a request.
103
+ */
104
+ onValueChange?: (value: V, details: SortableMoveDetails) => void;
105
+ /** Called once an item is put down, or put back. */
106
+ onMoveEnd?: (details: SortableMoveEndDetails) => void;
107
+ /**
108
+ * The copy that follows the pointer. By default it is a copy of the item's own element; return
109
+ * your own to draw it differently (`useSortableItem().overlay` is true inside it).
110
+ */
111
+ overlay?: (item: string) => React.ReactNode;
112
+ /** Drag only from a `SortableHandle`, so text in the items can be selected. */
113
+ handleOnly?: boolean;
114
+ /** Announcements and the handle's name; a LocaleProvider sets them for every Sortable. */
115
+ labels?: Partial<SortableMessages>;
116
+ }
117
+ /**
118
+ * Sortable — reorderable lists: one list, a row, a wrapping grid, or several lists that items
119
+ * move between, as the columns of a board.
120
+ *
121
+ * Drag an item with the mouse, a pen or — after a long press, so a swipe still scrolls — a finger:
122
+ * a copy follows the pointer, the other items slide aside to open a gap where it will land (in a
123
+ * grid, slot to slot across the row breaks), and on release the copy glides into the gap (or
124
+ * home, on a cancel), taking the size of its place. Over a list of narrower or wider items the
125
+ * copy takes their width. Edges scroll as it nears them.
126
+ * Every item has a `SortableHandle`: Space or Enter picks the item up, the arrows move it — the
127
+ * items slide into their new order — Space drops it and Escape puts it back. Every move is read
128
+ * out in a polite live region. No drag-and-drop library: measured once, moved by transforms.
129
+ *
130
+ * Compose `Sortable` → `SortableList` → `SortableItem` → `SortableHandle`. The rule people break:
131
+ * leaving out the handle. Without it there is no keyboard way to move an item.
132
+ */
133
+ export declare function Sortable<V extends SortableValue = SortableValue>({ value: valueProp, defaultValue, onValueChange, onMoveEnd, overlay, handleOnly, labels, render, className, children, ref, ...props }: SortableProps<V>): React.JSX.Element;
134
+ export interface SortableListProps extends useRender.ComponentProps<"ol"> {
135
+ /** The list's key in a `Sortable` of several lists. Leave it out for a single list. */
136
+ id?: string;
137
+ /**
138
+ * `vertical` (default) stacks the items; `horizontal` lines them up in a row; `grid` lays them
139
+ * out in rows that wrap — Left and Right move an item by one, Up and Down by a row. Items that
140
+ * wrap move as a grid, by pointer and by key, whatever the orientation.
141
+ */
142
+ orientation?: "vertical" | "horizontal" | "grid";
143
+ /**
144
+ * The list's name in announcements ("Moved to Qualified, position 2 of 4"); also its
145
+ * `aria-label` unless it has an `aria-label` or `aria-labelledby` of its own.
146
+ */
147
+ label?: string;
148
+ }
149
+ /**
150
+ * One list of items, an `<ol>` by default. Items keep the order of `value`; render them in it.
151
+ * Lay it out yourself (`flex flex-col gap-2`, a row with `flex-row`, a `grid grid-cols-3`). While
152
+ * an item is dragged the others slide aside to open a gap of its size where it will land — in a
153
+ * grid each moves into the slot of its neighbour, across the row breaks.
154
+ */
155
+ export declare function SortableList({ id, orientation, label, render, className, children, ref, ...props }: SortableListProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
156
+ export interface SortableItemProps extends useRender.ComponentProps<"li"> {
157
+ /** The item's id, as it is in `value`. */
158
+ value: string;
159
+ /** Its name in announcements and on its handle ("Move Chapter 3"). Defaults to `value`. */
160
+ label?: string;
161
+ /** Not moved by drag or keyboard; its handle is disabled. */
162
+ disabled?: boolean;
163
+ }
164
+ /**
165
+ * One item, an `<li>` by default. Dragged, it leaves its place (`data-dragging`, hidden) while a
166
+ * copy follows the pointer and the other items slide around the gap; picked up with the keyboard
167
+ * it has `data-lifted`, and it slides with the others as the arrows move it. Presses on buttons,
168
+ * links and fields inside it keep their own clicks.
169
+ */
170
+ export declare function SortableItem({ value, label, disabled, render, className, children, onPointerDown, onContextMenu, ref, ...props }: SortableItemProps): React.JSX.Element;
171
+ export type SortableHandleProps = ButtonProps;
172
+ /**
173
+ * The grip that moves an item: drag it — at once, even on touch — or focus it and press Space.
174
+ * A ghost 30px icon button named "Move {label}", described by the keyboard instructions, with
175
+ * `aria-pressed` while the item is lifted. Without children it draws a grip in the list's direction.
176
+ */
177
+ export declare function SortableHandle({ variant, size, className, children, onKeyDown, onBlur, ref, ...props }: SortableHandleProps): React.JSX.Element;
178
+ export {};