@c9up/nebula 0.2.0 → 0.2.2

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 (50) hide show
  1. package/README.md +11 -9
  2. package/dist/atoms/AccessibleIcon.d.ts +24 -0
  3. package/dist/atoms/AccessibleIcon.js +27 -0
  4. package/dist/atoms/VisuallyHidden.d.ts +30 -0
  5. package/dist/atoms/VisuallyHidden.js +35 -0
  6. package/dist/atoms/index.d.ts +2 -0
  7. package/dist/atoms/index.js +2 -0
  8. package/dist/configure.d.ts +6 -0
  9. package/dist/configure.js +4 -22
  10. package/dist/index.d.ts +7 -4
  11. package/dist/index.js +7 -4
  12. package/dist/lib/id.d.ts +13 -29
  13. package/dist/lib/id.js +13 -39
  14. package/dist/molecules/Toolbar.d.ts +50 -0
  15. package/dist/molecules/Toolbar.js +70 -0
  16. package/dist/molecules/index.d.ts +7 -5
  17. package/dist/molecules/index.js +7 -5
  18. package/dist/organisms/Toaster.d.ts +78 -10
  19. package/dist/organisms/Toaster.js +146 -20
  20. package/dist/organisms/index.d.ts +1 -1
  21. package/dist/primitives/direction.d.ts +38 -0
  22. package/dist/primitives/direction.js +57 -0
  23. package/dist/primitives/floating.js +1 -12
  24. package/dist/primitives/focusable.d.ts +10 -0
  25. package/dist/primitives/focusable.js +10 -1
  26. package/dist/primitives/index.d.ts +2 -1
  27. package/dist/primitives/index.js +2 -1
  28. package/dist/primitives/rovingFocus.js +14 -7
  29. package/dist/stubs.d.ts +13 -0
  30. package/dist/stubs.js +14 -0
  31. package/nebula.css +1 -1
  32. package/package.json +4 -3
  33. package/registry.json +63 -0
  34. package/src/atoms/AccessibleIcon.ts +39 -0
  35. package/src/atoms/VisuallyHidden.ts +45 -0
  36. package/src/atoms/index.ts +8 -0
  37. package/src/configure.ts +10 -23
  38. package/src/index.ts +7 -4
  39. package/src/lib/id.ts +11 -39
  40. package/src/molecules/Toolbar.ts +100 -0
  41. package/src/molecules/index.ts +14 -5
  42. package/src/organisms/Toaster.ts +207 -33
  43. package/src/organisms/index.ts +2 -0
  44. package/src/primitives/direction.ts +61 -0
  45. package/src/primitives/floating.ts +2 -12
  46. package/src/primitives/focusable.ts +10 -1
  47. package/src/primitives/index.ts +7 -0
  48. package/src/primitives/rovingFocus.ts +18 -5
  49. package/src/stubs.ts +16 -0
  50. package/stubs/config/nebula.stub +21 -0
package/README.md CHANGED
@@ -8,7 +8,7 @@ Part of **[Ream](https://github.com/C9up/ream)** — a Rust-powered, AdonisJS-co
8
8
 
9
9
  shadcn/ui is React. [Aurora](https://github.com/C9up/aurora) is a tagged-template DOM runtime with signals and no build step. nebula is the shadcn component set — the same markup, the same Tailwind classes, the same behaviour — written for Aurora.
10
10
 
11
- Sixty-nine components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
11
+ Seventy-four components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
12
12
 
13
13
  ## Installation
14
14
 
@@ -82,7 +82,7 @@ Several of those are narrower than what they replace — see [parity with shadcn
82
82
 
83
83
  Checked against shadcn's published component list, not from memory. Every one of its components has a counterpart here — including the conversational set (`Bubble`, `Message`, `MessageScroller`, `Attachment`, `Marker`), `NativeSelect` and `Questionnaire` — and the ~40 simple ones are faithful down to the class strings, the variants and the ARIA attributes.
84
84
 
85
- Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvider` is React context; Aurora has none, and the direction belongs on `<html dir>` — what it was really buying is [RTL support](#right-to-left), which is handled in the placement engine instead. `Form` has been folded into `Field` upstream; nebula ships both, with `Form` binding Aurora's own form controller. The components shadcn builds by wrapping a third-party library are reimplementations, and they are narrower. Stated plainly, because "complete port" would not be true:
85
+ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvider` is React context. Aurora has context, and these components use it, but the direction belongs on `<html dir>` — what it was really buying is [RTL support](#right-to-left), which is handled in the placement engine instead. `Form` has been folded into `Field` upstream; nebula ships both, with `Form` binding Aurora's own form controller. The components shadcn builds by wrapping a third-party library are reimplementations, and they are narrower. Stated plainly, because "complete port" would not be true:
86
86
 
87
87
  | Component | shadcn | nebula |
88
88
  | --- | --- | --- |
@@ -90,7 +90,7 @@ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvide
90
90
  | DataTable | TanStack Table (column grouping, virtualisation, pinning, faceted filters, server-side) | sort, filter, page, select — in memory |
91
91
  | Sidebar | ~15 parts | the parts that are not re-skinned atoms — see below |
92
92
  | Carousel | embla (loop, autoplay, N slides per view) | scroll-snap, one slide per view, no loop or autoplay |
93
- | Toaster | sonner (promise toasts, arbitrary JSX, multiple positions) | four variants, action, pause on hover |
93
+ | Toaster | Base UI's manager (display priority, anchored toasts, typed payload) — or sonner, with six positions | five variants, promise toasts, update and dedup by id, action, `onClose`, pause on hover, four corners |
94
94
  | Resizable | arbitrary nesting, persisted layouts, collapse-to-zero | two panes, one handle |
95
95
  | Combobox | single, multi-select and creatable recipes | single-select |
96
96
  | ScrollArea | scrollbars redrawn by Radix | native scrollbars, styled |
@@ -98,7 +98,7 @@ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvide
98
98
  | Questionnaire | branching logic, validation schemas | linear steps; single, multiple, freeform, skippable |
99
99
  | Bubble / Message | rich composition slots | the parts nebula's own layout needs |
100
100
 
101
- Two API-wide differences, both consequences of the runtime rather than choices about scope: there is no `asChild` (a compiled template has no element to clone), and compound components take data rather than children (Aurora has no React context).
101
+ Two API-wide differences, both consequences of the runtime rather than choices about scope: there is no `asChild` (a compiled template has no element to clone), and compound components take data rather than children (Aurora's context lives on a stack during setup, so a part passed as a lazy slot is built after that frame has popped — see below).
102
102
 
103
103
  **The Sidebar deserves its own note**, because porting it part-for-part would have fought the atomic taxonomy rather than following it. `SidebarInput`, `SidebarSeparator` and `SidebarMenuSkeleton` are the existing `Input`, `Separator` and `Skeleton` atoms with a prefix — redeclaring them would break the composition rule the whole library is organised on. `SidebarProvider` is React context, and nebula's sidebar owns its own shared signal instead. `SidebarInset` is the content column beside the rail, which is `AppShell`, a template. What was genuinely missing and has been added: `SidebarMenuSub`, `SidebarMenuSubItem`, `SidebarMenuAction`, a badge slot, and tooltips when the rail is collapsed.
104
104
 
@@ -194,11 +194,11 @@ resources/pages/
194
194
  The rule is composition, not complexity. Slider is an atom though it is interactive, because it is one input. Card is a molecule though it is trivial, because it assembles parts.
195
195
 
196
196
  <details>
197
- <summary><strong>All 69 components</strong></summary>
197
+ <summary><strong>All 74 components</strong></summary>
198
198
 
199
- **atoms (19)** — AspectRatio, Avatar, Badge, Button, Checkbox, Input, Kbd, Label, Marker, NativeSelect, Progress, ScrollArea, Separator, Skeleton, Slider, Spinner, Switch, Textarea, Toggle
199
+ **atoms (22)** — AccessibleIcon, AspectRatio, Avatar, Badge, Button, Checkbox, Image, Input, Kbd, Label, Marker, NativeSelect, Progress, ScrollArea, Separator, Skeleton, Slider, Spinner, Switch, Textarea, Toggle, VisuallyHidden
200
200
 
201
- **molecules (21)** — Accordion, Alert, Attachment, Breadcrumb, Bubble, ButtonGroup, Card, Collapsible, Empty, Field, InputGroup, InputOTP, Item, Message, Pagination, RadioGroup, Resizable, Table, Tabs, ToggleGroup, Typography
201
+ **molecules (23)** — Accordion, Alert, Attachment, Breadcrumb, Bubble, ButtonGroup, Card, Collapsible, Empty, Field, InputGroup, InputOTP, Item, Message, Pagination, Picture, RadioGroup, Resizable, Table, Tabs, ToggleGroup, Toolbar, Typography
202
202
 
203
203
  **organisms (26)** — AlertDialog, Calendar, Carousel, Chart, Combobox, Command, CommandDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, Dialog, Drawer, DropdownMenu, Form, HoverCard, Menubar, MessageScroller, NavigationMenu, Popover, Questionnaire, Select, Sheet, Sidebar, Toaster, Tooltip
204
204
 
@@ -217,7 +217,9 @@ shadcn composes through React context:
217
217
  </Tabs>
218
218
  ```
219
219
 
220
- Aurora has no context, and the workarounds — a factory returning bound parts, a handle threaded through props — are more machinery for less clarity. So compound components take data:
220
+ Aurora **does** have context — `createContext` / `provide` / `inject` — and these components use it: `Tabs` provides a `TabsApi` that `TabsTrigger` and `TabsContent` inject. What they do not do is take their parts as children.
221
+
222
+ Context here lives on a stack during a component's **setup**, which is synchronous. A part handed in as a `Slot` thunk is built later, by the renderer, when that frame has already popped — so the shadcn shape, where a child reads the parent it was nested inside, cannot read anything. Taking data keeps every part built during setup, while the context is still there. So compound components take data:
221
223
 
222
224
  ```ts
223
225
  Tabs({
@@ -273,7 +275,7 @@ The headless layer is most of this package, and it is where shadcn's behaviour a
273
275
  ## Development
274
276
 
275
277
  ```bash
276
- pnpm test # 391 unit tests
278
+ pnpm test # 593 unit tests
277
279
  pnpm typecheck
278
280
  pnpm lint
279
281
  pnpm registry # regenerate registry.json from the source tree
@@ -0,0 +1,24 @@
1
+ /**
2
+ * AccessibleIcon — an icon with a name only a screen reader hears.
3
+ *
4
+ * An icon on its own is a picture of a word. Sighted users read the picture;
5
+ * a screen reader reads nothing at all, because an `<svg>` with no label is
6
+ * announced as nothing — which is how a delete button becomes an unlabelled
7
+ * button in the middle of a row of unlabelled buttons.
8
+ *
9
+ * Two halves, and both matter. The icon is marked `aria-hidden` so its own
10
+ * internals — a `<title>`, a stray `<text>` — are not announced on top of the
11
+ * label; the label is visually hidden text beside it. `aria-label` on the
12
+ * parent would do for a plain string, but it does not survive translation
13
+ * tooling the way real text does, and it cannot carry markup.
14
+ */
15
+ import { type Slot } from "../lib/children.js";
16
+ import { type Reactive } from "../lib/props.js";
17
+ export interface AccessibleIconProps {
18
+ /** The icon. Hidden from the accessibility tree. */
19
+ children?: Slot;
20
+ /** What the icon means, in words. */
21
+ label: Reactive<string>;
22
+ class?: Reactive<string>;
23
+ }
24
+ export declare const AccessibleIcon: (props?: AccessibleIconProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * AccessibleIcon — an icon with a name only a screen reader hears.
3
+ *
4
+ * An icon on its own is a picture of a word. Sighted users read the picture;
5
+ * a screen reader reads nothing at all, because an `<svg>` with no label is
6
+ * announced as nothing — which is how a delete button becomes an unlabelled
7
+ * button in the middle of a row of unlabelled buttons.
8
+ *
9
+ * Two halves, and both matter. The icon is marked `aria-hidden` so its own
10
+ * internals — a `<title>`, a stray `<text>` — are not announced on top of the
11
+ * label; the label is visually hidden text beside it. `aria-label` on the
12
+ * parent would do for a plain string, but it does not survive translation
13
+ * tooling the way real text does, and it cannot carry markup.
14
+ */
15
+ import { component, html } from "@c9up/aurora";
16
+ import { slot } from "../lib/children.js";
17
+ import { cn } from "../lib/cn.js";
18
+ import { read } from "../lib/props.js";
19
+ import { VisuallyHidden } from "./VisuallyHidden.js";
20
+ export const AccessibleIcon = component((props) => {
21
+ return html `<span
22
+ data-slot="accessible-icon"
23
+ class="${() => cn("contents", read(props.class))}"
24
+ ><span aria-hidden="true" class="contents">${slot(props.children)}</span>${VisuallyHidden({
25
+ children: () => read(props.label),
26
+ })}</span>`;
27
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * VisuallyHidden — text for a screen reader and nothing else.
3
+ *
4
+ * Not `display: none`, which removes it from the accessibility tree as well,
5
+ * and not `opacity: 0`, which keeps it taking space. The clip rectangle is the
6
+ * one technique that leaves the node announced and unrendered, and it is
7
+ * fiddly enough that hand-writing it in each component is how one of them ends
8
+ * up subtly wrong.
9
+ *
10
+ * Its main job is the label a sighted user does not need: a dialog whose title
11
+ * is a logo, an icon button, a table caption. `aria-label` covers some of
12
+ * those, but not the ones where the content is real markup — a heading that a
13
+ * `aria-labelledby` has to point at, for instance.
14
+ *
15
+ * `focusable` keeps it hidden until it is tabbed to, which is what a skip link
16
+ * needs: invisible in the layout, and visible the moment it has focus.
17
+ *
18
+ * Always a `<span>`. Radix takes an `asChild` here so a hidden heading can be
19
+ * a real `<h2>`; aurora's template parser fixes the tag at compile time, so
20
+ * the equivalent is to put this inside the heading rather than to become one.
21
+ */
22
+ import { type Slot } from "../lib/children.js";
23
+ import { type Reactive } from "../lib/props.js";
24
+ export interface VisuallyHiddenProps {
25
+ children?: Slot;
26
+ /** Reveal it once focused — for a skip link. Default `false`. */
27
+ focusable?: boolean;
28
+ class?: Reactive<string>;
29
+ }
30
+ export declare const VisuallyHidden: (props?: VisuallyHiddenProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * VisuallyHidden — text for a screen reader and nothing else.
3
+ *
4
+ * Not `display: none`, which removes it from the accessibility tree as well,
5
+ * and not `opacity: 0`, which keeps it taking space. The clip rectangle is the
6
+ * one technique that leaves the node announced and unrendered, and it is
7
+ * fiddly enough that hand-writing it in each component is how one of them ends
8
+ * up subtly wrong.
9
+ *
10
+ * Its main job is the label a sighted user does not need: a dialog whose title
11
+ * is a logo, an icon button, a table caption. `aria-label` covers some of
12
+ * those, but not the ones where the content is real markup — a heading that a
13
+ * `aria-labelledby` has to point at, for instance.
14
+ *
15
+ * `focusable` keeps it hidden until it is tabbed to, which is what a skip link
16
+ * needs: invisible in the layout, and visible the moment it has focus.
17
+ *
18
+ * Always a `<span>`. Radix takes an `asChild` here so a hidden heading can be
19
+ * a real `<h2>`; aurora's template parser fixes the tag at compile time, so
20
+ * the equivalent is to put this inside the heading rather than to become one.
21
+ */
22
+ import { component, html } from "@c9up/aurora";
23
+ import { slot } from "../lib/children.js";
24
+ import { cn } from "../lib/cn.js";
25
+ import { read } from "../lib/props.js";
26
+ /** Tailwind's own `sr-only`, plus its counterpart for the focusable case. */
27
+ const HIDDEN = "sr-only";
28
+ const FOCUSABLE = "sr-only focus-within:not-sr-only focus:not-sr-only";
29
+ export const VisuallyHidden = component((props) => {
30
+ const base = props.focusable === true ? FOCUSABLE : HIDDEN;
31
+ return html `<span
32
+ data-slot="visually-hidden"
33
+ class="${() => cn(base, read(props.class))}"
34
+ >${slot(props.children)}</span>`;
35
+ });
@@ -11,6 +11,7 @@
11
11
  * a molecule despite being simpler than Slider, because it assembles parts.
12
12
  * Slider is an atom despite being interactive, because it is one input.
13
13
  */
14
+ export { AccessibleIcon, type AccessibleIconProps, } from "./AccessibleIcon.js";
14
15
  export { AspectRatio, type AspectRatioProps } from "./AspectRatio.js";
15
16
  export { Avatar, AvatarBadge, type AvatarBadgeProps, AvatarFallback, type AvatarFallbackProps, AvatarGroup, AvatarGroupCount, type AvatarGroupProps, AvatarImage, type AvatarImageProps, type AvatarProps, } from "./Avatar.js";
16
17
  export { Badge, type BadgeProps, type BadgeVariants, badgeVariants, } from "./Badge.js";
@@ -31,3 +32,4 @@ export { Spinner, type SpinnerProps } from "./Spinner.js";
31
32
  export { Switch, type SwitchProps, switchTrackClasses } from "./Switch.js";
32
33
  export { Textarea, type TextareaProps, textareaClasses } from "./Textarea.js";
33
34
  export { Toggle, type ToggleProps, type ToggleVariants, toggleVariants, } from "./Toggle.js";
35
+ export { VisuallyHidden, type VisuallyHiddenProps, } from "./VisuallyHidden.js";
@@ -11,6 +11,7 @@
11
11
  * a molecule despite being simpler than Slider, because it assembles parts.
12
12
  * Slider is an atom despite being interactive, because it is one input.
13
13
  */
14
+ export { AccessibleIcon, } from "./AccessibleIcon.js";
14
15
  export { AspectRatio } from "./AspectRatio.js";
15
16
  export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, } from "./Avatar.js";
16
17
  export { Badge, badgeVariants, } from "./Badge.js";
@@ -31,3 +32,4 @@ export { Spinner } from "./Spinner.js";
31
32
  export { Switch, switchTrackClasses } from "./Switch.js";
32
33
  export { Textarea, textareaClasses } from "./Textarea.js";
33
34
  export { Toggle, toggleVariants, } from "./Toggle.js";
35
+ export { VisuallyHidden, } from "./VisuallyHidden.js";
@@ -29,6 +29,12 @@ interface Codemods {
29
29
  }): Promise<void>;
30
30
  /** Appends to `reamrc.commands` — the channel for package-shipped commands. */
31
31
  registerCommand(importPath: string): Promise<void>;
32
+ makeUsingStub(stubsRoot: string, stubPath: string, state?: Record<string, string | number | boolean>, options?: {
33
+ force?: boolean;
34
+ }): Promise<{
35
+ path: string;
36
+ contents: string;
37
+ }>;
32
38
  }
33
39
  /** Flags forwarded from `ream add` / `ream configure`, as the CLI encodes them. */
34
40
  type Flags = Record<string, string[] | undefined>;
package/dist/configure.js CHANGED
@@ -19,27 +19,7 @@ import { readFile } from "node:fs/promises";
19
19
  import { resolve } from "node:path";
20
20
  import { adapterFor, isAdapterName } from "./adapters/index.js";
21
21
  import { resolveConfig } from "./config.js";
22
- function configFile(adapter) {
23
- return `import { defineConfig } from '@c9up/nebula'
24
-
25
- /**
26
- * nebula — component registry and style adapter.
27
- *
28
- * Changing \`adapter\` and re-running \`ream configure @c9up/nebula\` swaps the
29
- * CSS engine. The components themselves are untouched: all three adapters
30
- * consume the same class names.
31
- */
32
- export default defineConfig({
33
- adapter: '${adapter}',
34
- paths: {
35
- // Where \`ream nebula:add\` copies components. The atomic layers live under it.
36
- components: 'resources/pages',
37
- css: 'resources/css/app.css',
38
- output: 'public/app.css',
39
- },
40
- })
41
- `;
42
- }
22
+ import { stubsRoot } from "./stubs.js";
43
23
  /**
44
24
  * Read the adapter from the forwarded flags.
45
25
  *
@@ -60,7 +40,9 @@ export async function configure(codemods, flags = {}) {
60
40
  const name = adapterFrom(flags);
61
41
  const adapter = adapterFor(name);
62
42
  const config = resolveConfig({ adapter: name });
63
- await codemods.writeFile("config/nebula.ts", configFile(name));
43
+ await codemods.makeUsingStub(stubsRoot, "config/nebula.stub", {
44
+ adapter: name,
45
+ });
64
46
  // `reamrc.commands` is the channel Ream provides for commands a package
65
47
  // ships, which directory discovery cannot see. `ream` forwards any
66
48
  // unrecognised name to the app's console kernel, so these exist without a
package/dist/index.d.ts CHANGED
@@ -13,10 +13,13 @@
13
13
  * icons are inlined, and the date maths is `Date` and `Intl`.
14
14
  *
15
15
  * **Compound components take data, not children.** shadcn composes through
16
- * React context — `<Tabs><TabsList><TabsTrigger>`. Aurora has no context, and
17
- * the workarounds are worse than the problem, so those components take an
18
- * `items` array and named slots. The rendered markup is unchanged, which means
19
- * shadcn's CSS and its examples still read across.
16
+ * React context — `<Tabs><TabsList><TabsTrigger>`. Aurora has context too, and
17
+ * these components use it; what they do not do is take their parts as children.
18
+ * Context here lives on a stack during a component's SETUP, so a part handed in
19
+ * as a `Slot` thunk is built later, once that frame has popped, and reads
20
+ * nothing. An `items` array and named slots keep every part built while the
21
+ * context is still there. The rendered markup is unchanged, which means shadcn's
22
+ * CSS and its examples still read across.
20
23
  *
21
24
  * **The atomic layer is a property of the component.** An atom renders its own
22
25
  * markup and composes nothing from nebula; a molecule assembles atoms or owns
package/dist/index.js CHANGED
@@ -13,10 +13,13 @@
13
13
  * icons are inlined, and the date maths is `Date` and `Intl`.
14
14
  *
15
15
  * **Compound components take data, not children.** shadcn composes through
16
- * React context — `<Tabs><TabsList><TabsTrigger>`. Aurora has no context, and
17
- * the workarounds are worse than the problem, so those components take an
18
- * `items` array and named slots. The rendered markup is unchanged, which means
19
- * shadcn's CSS and its examples still read across.
16
+ * React context — `<Tabs><TabsList><TabsTrigger>`. Aurora has context too, and
17
+ * these components use it; what they do not do is take their parts as children.
18
+ * Context here lives on a stack during a component's SETUP, so a part handed in
19
+ * as a `Slot` thunk is built later, once that frame has popped, and reads
20
+ * nothing. An `items` array and named slots keep every part built while the
21
+ * context is still there. The rendered markup is unchanged, which means shadcn's
22
+ * CSS and its examples still read across.
20
23
  *
21
24
  * **The atomic layer is a property of the component.** An atom renders its own
22
25
  * markup and composes nothing from nebula; a molecule assembles atoms or owns
package/dist/lib/id.d.ts CHANGED
@@ -1,31 +1,15 @@
1
1
  /**
2
- * Stable element ids.
3
- *
4
- * Radix leans on React's `useId` to wire ARIA relationships — a trigger's
5
- * `aria-controls` has to name the id its content actually carries. Aurora has
6
- * no equivalent, and nebula needs one for two reasons: the ARIA wiring above,
7
- * and element lookup. Aurora templates have no `ref` directive, so a component
8
- * that must measure or focus a node finds it by id inside `onMount()`.
9
- *
10
- * The counter is monotonic per module instance, so the sequence depends only
11
- * on the order components are constructed in. That order is identical on the
12
- * server and in the browser for the same tree, which is what makes the ids
13
- * survive hydration — the same property React's `useId` relies on.
14
- *
15
- * `resetIds()` exists for the server: a long-lived process renders many
16
- * requests, and without a reset the counter climbs forever and every response
17
- * ships different markup, defeating any HTML cache. Call it once per render
18
- * pass, before the tree is built.
19
- */
20
- /** Mint an id unique within this render pass. */
21
- export declare function uid(prefix?: string): string;
22
- /** Restart the sequence. Call once per SSR render, before building the tree. */
23
- export declare function resetIds(): void;
24
- /**
25
- * Look an element up by the id a component minted for it.
26
- *
27
- * Returns `null` off the DOM (SSR) or before mount rather than throwing, so
28
- * callers can run the same code in both environments. Every consumer inside
29
- * nebula is in `onMount`, where the node is live.
2
+ * Stable element ids — aurora's counter, re-exported.
3
+ *
4
+ * It was nebula's own, and that was the bug: aurora resets its sequence at the
5
+ * start of each render pass (`renderPage` server-side, `hydrate` in the
6
+ * browser), and a second counter living here saw none of those resets. A
7
+ * long-lived server therefore shipped `tooltip-trigger-14` while the browser,
8
+ * hydrating from zero, minted `tooltip-trigger-1` and looked it up — so
9
+ * `byId` answered `null`, `floatingSurface` had no anchor, and the tooltip
10
+ * never opened although its mount hook had run and its trigger was wired.
11
+ *
12
+ * Every id nebula mints has to come from the same counter aurora resets; the
13
+ * names are kept so nothing importing them has to change.
30
14
  */
31
- export declare function byId(id: string): HTMLElement | null;
15
+ export { byId, resetIds, uid } from "@c9up/aurora";
package/dist/lib/id.js CHANGED
@@ -1,41 +1,15 @@
1
1
  /**
2
- * Stable element ids.
3
- *
4
- * Radix leans on React's `useId` to wire ARIA relationships — a trigger's
5
- * `aria-controls` has to name the id its content actually carries. Aurora has
6
- * no equivalent, and nebula needs one for two reasons: the ARIA wiring above,
7
- * and element lookup. Aurora templates have no `ref` directive, so a component
8
- * that must measure or focus a node finds it by id inside `onMount()`.
9
- *
10
- * The counter is monotonic per module instance, so the sequence depends only
11
- * on the order components are constructed in. That order is identical on the
12
- * server and in the browser for the same tree, which is what makes the ids
13
- * survive hydration — the same property React's `useId` relies on.
14
- *
15
- * `resetIds()` exists for the server: a long-lived process renders many
16
- * requests, and without a reset the counter climbs forever and every response
17
- * ships different markup, defeating any HTML cache. Call it once per render
18
- * pass, before the tree is built.
19
- */
20
- let counter = 0;
21
- /** Mint an id unique within this render pass. */
22
- export function uid(prefix = "nebula") {
23
- counter += 1;
24
- return `${prefix}-${counter}`;
25
- }
26
- /** Restart the sequence. Call once per SSR render, before building the tree. */
27
- export function resetIds() {
28
- counter = 0;
29
- }
30
- /**
31
- * Look an element up by the id a component minted for it.
32
- *
33
- * Returns `null` off the DOM (SSR) or before mount rather than throwing, so
34
- * callers can run the same code in both environments. Every consumer inside
35
- * nebula is in `onMount`, where the node is live.
2
+ * Stable element ids — aurora's counter, re-exported.
3
+ *
4
+ * It was nebula's own, and that was the bug: aurora resets its sequence at the
5
+ * start of each render pass (`renderPage` server-side, `hydrate` in the
6
+ * browser), and a second counter living here saw none of those resets. A
7
+ * long-lived server therefore shipped `tooltip-trigger-14` while the browser,
8
+ * hydrating from zero, minted `tooltip-trigger-1` and looked it up — so
9
+ * `byId` answered `null`, `floatingSurface` had no anchor, and the tooltip
10
+ * never opened although its mount hook had run and its trigger was wired.
11
+ *
12
+ * Every id nebula mints has to come from the same counter aurora resets; the
13
+ * names are kept so nothing importing them has to change.
36
14
  */
37
- export function byId(id) {
38
- if (typeof document === "undefined")
39
- return null;
40
- return document.getElementById(id);
41
- }
15
+ export { byId, resetIds, uid } from "@c9up/aurora";
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Toolbar — a row of controls that behaves as one tab stop.
3
+ *
4
+ * Radix ships this as a primitive and shadcn styles no equivalent, which is
5
+ * why it is easy to miss: a page builds a `<div class="flex gap-2">` full of
6
+ * buttons and it looks right. What it is not is navigable. Eleven buttons in a
7
+ * formatting bar are eleven presses of Tab to get past, and a keyboard user
8
+ * reaching the content below pays for every one of them.
9
+ *
10
+ * The WAI-ARIA toolbar pattern says: one tab stop, arrows move inside it. That
11
+ * is `rovingFocus`, which nebula already owns for menus and tab lists — the
12
+ * only thing a toolbar adds is `role="toolbar"`, the orientation, and a
13
+ * separator that is announced as one.
14
+ *
15
+ * The items are whatever the caller puts in — `Button`, `Toggle`, a `Select`
16
+ * trigger, a plain `<a>` — found by the same tabbable selector the focus trap
17
+ * uses. No marker attribute to remember: a control that a keyboard could
18
+ * reach on its own is a control the arrows reach here, and one that could not
19
+ * was never in the tab order to begin with.
20
+ */
21
+ import { type ButtonProps } from "../atoms/Button.js";
22
+ import { type Slot } from "../lib/children.js";
23
+ import { type Reactive } from "../lib/props.js";
24
+ export interface ToolbarProps {
25
+ children?: Slot;
26
+ /** Which arrows move focus. Default `"horizontal"`, as a toolbar reads. */
27
+ orientation?: "horizontal" | "vertical";
28
+ /** Wrap from the last control back to the first. Default `true`. */
29
+ loop?: boolean;
30
+ /** Announced name — a page with two toolbars needs to tell them apart. */
31
+ label?: Reactive<string>;
32
+ class?: Reactive<string>;
33
+ }
34
+ export declare const Toolbar: (props?: ToolbarProps | undefined) => import("@c9up/aurora").TemplateResult;
35
+ export interface ToolbarButtonProps extends ButtonProps {
36
+ }
37
+ /**
38
+ * A control inside the bar.
39
+ *
40
+ * `Button` with the defaults a toolbar wants — ghost, small — so a row of them
41
+ * reads as a bar rather than as six primary actions competing for attention.
42
+ * Nothing else: a plain `Button` dropped in the bar navigates identically,
43
+ * which is the point of finding items by focusability.
44
+ */
45
+ export declare const ToolbarButton: (props?: ToolbarButtonProps | undefined) => import("@c9up/aurora").TemplateResult;
46
+ export interface ToolbarSeparatorProps {
47
+ class?: Reactive<string>;
48
+ }
49
+ /** A boundary between groups of controls, announced as one. */
50
+ export declare const ToolbarSeparator: (props?: ToolbarSeparatorProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Toolbar — a row of controls that behaves as one tab stop.
3
+ *
4
+ * Radix ships this as a primitive and shadcn styles no equivalent, which is
5
+ * why it is easy to miss: a page builds a `<div class="flex gap-2">` full of
6
+ * buttons and it looks right. What it is not is navigable. Eleven buttons in a
7
+ * formatting bar are eleven presses of Tab to get past, and a keyboard user
8
+ * reaching the content below pays for every one of them.
9
+ *
10
+ * The WAI-ARIA toolbar pattern says: one tab stop, arrows move inside it. That
11
+ * is `rovingFocus`, which nebula already owns for menus and tab lists — the
12
+ * only thing a toolbar adds is `role="toolbar"`, the orientation, and a
13
+ * separator that is announced as one.
14
+ *
15
+ * The items are whatever the caller puts in — `Button`, `Toggle`, a `Select`
16
+ * trigger, a plain `<a>` — found by the same tabbable selector the focus trap
17
+ * uses. No marker attribute to remember: a control that a keyboard could
18
+ * reach on its own is a control the arrows reach here, and one that could not
19
+ * was never in the tab order to begin with.
20
+ */
21
+ import { component, html, onMount, onUnmount, uid } from "@c9up/aurora";
22
+ import { Button } from "../atoms/Button.js";
23
+ import { Separator } from "../atoms/Separator.js";
24
+ import { slot } from "../lib/children.js";
25
+ import { cn } from "../lib/cn.js";
26
+ import { read } from "../lib/props.js";
27
+ import { FOCUSABLE_SELECTOR } from "../primitives/focusable.js";
28
+ import { rovingFocus } from "../primitives/rovingFocus.js";
29
+ export const Toolbar = component((props) => {
30
+ const orientation = props.orientation ?? "horizontal";
31
+ const barId = uid("toolbar");
32
+ let group;
33
+ onMount(() => {
34
+ group = rovingFocus({
35
+ container: () => document.getElementById(barId),
36
+ itemSelector: FOCUSABLE_SELECTOR,
37
+ orientation,
38
+ loop: props.loop !== false,
39
+ });
40
+ // The controls exist by now; without this none of them carries
41
+ // `tabindex="0"` and the bar cannot be reached by Tab at all.
42
+ group.sync();
43
+ });
44
+ onUnmount(() => group?.destroy());
45
+ return html `<div
46
+ data-slot="toolbar"
47
+ id="${barId}"
48
+ role="toolbar"
49
+ aria-orientation="${orientation}"
50
+ aria-label="${() => read(props.label) ?? ""}"
51
+ class="${() => cn("flex items-center gap-1", orientation === "vertical" ? "flex-col" : "flex-row", read(props.class))}"
52
+ >${slot(props.children)}</div>`;
53
+ });
54
+ /**
55
+ * A control inside the bar.
56
+ *
57
+ * `Button` with the defaults a toolbar wants — ghost, small — so a row of them
58
+ * reads as a bar rather than as six primary actions competing for attention.
59
+ * Nothing else: a plain `Button` dropped in the bar navigates identically,
60
+ * which is the point of finding items by focusability.
61
+ */
62
+ export const ToolbarButton = component((props) => Button({ variant: "ghost", size: "sm", ...props }));
63
+ /** A boundary between groups of controls, announced as one. */
64
+ export const ToolbarSeparator = component((props) => {
65
+ return Separator({
66
+ orientation: "vertical",
67
+ decorative: false,
68
+ class: () => cn("mx-1 h-6 self-center", read(props.class)),
69
+ });
70
+ });
@@ -8,11 +8,12 @@
8
8
  * organisms.
9
9
  *
10
10
  * Compound components are data-driven — `Accordion({ items: [...] })`, not
11
- * `<Accordion><AccordionItem>`. shadcn's compound API is a React-context
12
- * artifact; Aurora has no context, and the alternatives (a factory returning
13
- * bound parts, a handle threaded through props) are more machinery for less
14
- * clarity. The rendered markup is unchanged, so shadcn's CSS and its examples
15
- * still read across.
11
+ * `<Accordion><AccordionItem>`. Not for want of context: Aurora has it and these
12
+ * components use it. It lives on a stack during SETUP, so a part passed as a
13
+ * `Slot` thunk is built after that frame has popped and has nothing to read —
14
+ * which is exactly the shape `<Accordion><AccordionItem>` would need. Data keeps
15
+ * every part built while the context is there. The rendered markup is unchanged,
16
+ * so shadcn's CSS and its examples still read across.
16
17
  */
17
18
  export { Accordion, AccordionContent, type AccordionContentProps, AccordionItem, type AccordionItemProps, type AccordionProps, AccordionTrigger, type AccordionTriggerProps, } from "./Accordion.js";
18
19
  export { Alert, AlertDescription, type AlertProps, AlertTitle, type AlertVariants, alertVariants, } from "./Alert.js";
@@ -35,4 +36,5 @@ export { ResizableHandle, type ResizableHandleProps, ResizablePanel, ResizablePa
35
36
  export { Table, TableBody, TableCaption, TableCell, type TableCellProps, TableFooter, TableHead, TableHeader, type TableProps, TableRow, type TableRowProps, } from "./Table.js";
36
37
  export { Tabs, TabsContent, type TabsContentProps, TabsList, type TabsListProps, type TabsListVariants, type TabsProps, TabsTrigger, type TabsTriggerProps, tabsListVariants, } from "./Tabs.js";
37
38
  export { ToggleGroup, ToggleGroupItem, type ToggleGroupItemProps, type ToggleGroupProps, } from "./ToggleGroup.js";
39
+ export { Toolbar, ToolbarButton, type ToolbarButtonProps, type ToolbarProps, ToolbarSeparator, type ToolbarSeparatorProps, } from "./Toolbar.js";
38
40
  export { Blockquote, H1, H2, H3, H4, InlineCode, Large, Lead, List, Muted, P, Small, type TypographyProps, } from "./Typography.js";
@@ -8,11 +8,12 @@
8
8
  * organisms.
9
9
  *
10
10
  * Compound components are data-driven — `Accordion({ items: [...] })`, not
11
- * `<Accordion><AccordionItem>`. shadcn's compound API is a React-context
12
- * artifact; Aurora has no context, and the alternatives (a factory returning
13
- * bound parts, a handle threaded through props) are more machinery for less
14
- * clarity. The rendered markup is unchanged, so shadcn's CSS and its examples
15
- * still read across.
11
+ * `<Accordion><AccordionItem>`. Not for want of context: Aurora has it and these
12
+ * components use it. It lives on a stack during SETUP, so a part passed as a
13
+ * `Slot` thunk is built after that frame has popped and has nothing to read —
14
+ * which is exactly the shape `<Accordion><AccordionItem>` would need. Data keeps
15
+ * every part built while the context is there. The rendered markup is unchanged,
16
+ * so shadcn's CSS and its examples still read across.
16
17
  */
17
18
  export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "./Accordion.js";
18
19
  export { Alert, AlertDescription, AlertTitle, alertVariants, } from "./Alert.js";
@@ -35,4 +36,5 @@ export { ResizableHandle, ResizablePanel, ResizablePanelGroup, } from "./Resizab
35
36
  export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "./Table.js";
36
37
  export { Tabs, TabsContent, TabsList, TabsTrigger, tabsListVariants, } from "./Tabs.js";
37
38
  export { ToggleGroup, ToggleGroupItem, } from "./ToggleGroup.js";
39
+ export { Toolbar, ToolbarButton, ToolbarSeparator, } from "./Toolbar.js";
38
40
  export { Blockquote, H1, H2, H3, H4, InlineCode, Large, Lead, List, Muted, P, Small, } from "./Typography.js";