@c9up/nebula 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/atoms/Avatar.d.ts +36 -9
  2. package/dist/atoms/Avatar.js +66 -27
  3. package/dist/atoms/index.d.ts +1 -1
  4. package/dist/atoms/index.js +1 -1
  5. package/dist/lib/children.d.ts +30 -0
  6. package/dist/lib/motion.d.ts +10 -0
  7. package/dist/lib/motion.js +10 -0
  8. package/dist/molecules/Accordion.d.ts +36 -15
  9. package/dist/molecules/Accordion.js +68 -45
  10. package/dist/molecules/Breadcrumb.d.ts +29 -11
  11. package/dist/molecules/Breadcrumb.js +52 -52
  12. package/dist/molecules/Collapsible.d.ts +18 -17
  13. package/dist/molecules/Collapsible.js +42 -34
  14. package/dist/molecules/Field.d.ts +66 -30
  15. package/dist/molecules/Field.js +106 -55
  16. package/dist/molecules/InputGroup.d.ts +39 -21
  17. package/dist/molecules/InputGroup.js +43 -27
  18. package/dist/molecules/InputOTP.d.ts +26 -3
  19. package/dist/molecules/InputOTP.js +109 -76
  20. package/dist/molecules/Message.js +5 -4
  21. package/dist/molecules/Pagination.d.ts +36 -11
  22. package/dist/molecules/Pagination.js +58 -74
  23. package/dist/molecules/RadioGroup.d.ts +25 -17
  24. package/dist/molecules/RadioGroup.js +47 -43
  25. package/dist/molecules/Resizable.d.ts +32 -7
  26. package/dist/molecules/Resizable.js +76 -49
  27. package/dist/molecules/Tabs.d.ts +49 -11
  28. package/dist/molecules/Tabs.js +107 -51
  29. package/dist/molecules/ToggleGroup.d.ts +16 -10
  30. package/dist/molecules/ToggleGroup.js +37 -21
  31. package/dist/molecules/index.d.ts +11 -11
  32. package/dist/molecules/index.js +11 -11
  33. package/dist/organisms/AlertDialog.d.ts +80 -28
  34. package/dist/organisms/AlertDialog.js +192 -67
  35. package/dist/organisms/Carousel.d.ts +25 -3
  36. package/dist/organisms/Carousel.js +75 -43
  37. package/dist/organisms/Combobox.d.ts +2 -1
  38. package/dist/organisms/Combobox.js +46 -16
  39. package/dist/organisms/Command.d.ts +73 -32
  40. package/dist/organisms/Command.js +209 -131
  41. package/dist/organisms/CommandDialog.js +5 -5
  42. package/dist/organisms/ContextMenu.d.ts +41 -19
  43. package/dist/organisms/ContextMenu.js +112 -71
  44. package/dist/organisms/DataTable.js +42 -8
  45. package/dist/organisms/Dialog.d.ts +97 -31
  46. package/dist/organisms/Dialog.js +193 -68
  47. package/dist/organisms/Drawer.d.ts +33 -10
  48. package/dist/organisms/Drawer.js +130 -52
  49. package/dist/organisms/DropdownMenu.d.ts +58 -11
  50. package/dist/organisms/DropdownMenu.js +137 -50
  51. package/dist/organisms/Form.js +9 -11
  52. package/dist/organisms/HoverCard.d.ts +39 -19
  53. package/dist/organisms/HoverCard.js +116 -40
  54. package/dist/organisms/Menubar.d.ts +55 -19
  55. package/dist/organisms/Menubar.js +166 -82
  56. package/dist/organisms/NavigationMenu.d.ts +77 -31
  57. package/dist/organisms/NavigationMenu.js +169 -98
  58. package/dist/organisms/Popover.d.ts +72 -12
  59. package/dist/organisms/Popover.js +132 -25
  60. package/dist/organisms/Questionnaire.js +5 -5
  61. package/dist/organisms/Select.d.ts +99 -18
  62. package/dist/organisms/Select.js +253 -111
  63. package/dist/organisms/Sheet.d.ts +57 -13
  64. package/dist/organisms/Sheet.js +141 -54
  65. package/dist/organisms/Sidebar.d.ts +146 -56
  66. package/dist/organisms/Sidebar.js +236 -128
  67. package/dist/organisms/Tooltip.d.ts +88 -14
  68. package/dist/organisms/Tooltip.js +210 -47
  69. package/dist/organisms/index.d.ts +15 -15
  70. package/dist/organisms/index.js +15 -15
  71. package/dist/primitives/floating.js +25 -0
  72. package/dist/primitives/floatingSurface.d.ts +11 -0
  73. package/dist/primitives/floatingSurface.js +8 -0
  74. package/dist/primitives/menu.d.ts +45 -1
  75. package/dist/primitives/menu.js +45 -14
  76. package/dist/primitives/menuParts.d.ts +113 -0
  77. package/dist/primitives/menuParts.js +207 -0
  78. package/nebula.css +1 -1
  79. package/package.json +5 -4
  80. package/registry.json +18 -6
  81. package/src/atoms/Avatar.ts +141 -37
  82. package/src/atoms/index.ts +13 -1
  83. package/src/lib/children.ts +31 -0
  84. package/src/lib/motion.ts +12 -0
  85. package/src/molecules/Accordion.ts +120 -60
  86. package/src/molecules/Breadcrumb.ts +77 -76
  87. package/src/molecules/Collapsible.ts +77 -41
  88. package/src/molecules/Field.ts +187 -72
  89. package/src/molecules/InputGroup.ts +88 -35
  90. package/src/molecules/InputOTP.ts +150 -86
  91. package/src/molecules/Message.ts +6 -4
  92. package/src/molecules/Pagination.ts +96 -101
  93. package/src/molecules/RadioGroup.ts +70 -59
  94. package/src/molecules/Resizable.ts +138 -75
  95. package/src/molecules/Tabs.ts +187 -74
  96. package/src/molecules/ToggleGroup.ts +77 -38
  97. package/src/molecules/index.ts +85 -8
  98. package/src/organisms/AlertDialog.ts +319 -82
  99. package/src/organisms/Carousel.ts +129 -52
  100. package/src/organisms/Combobox.ts +64 -19
  101. package/src/organisms/Command.ts +342 -159
  102. package/src/organisms/CommandDialog.ts +6 -6
  103. package/src/organisms/ContextMenu.ts +185 -83
  104. package/src/organisms/DataTable.ts +56 -10
  105. package/src/organisms/Dialog.ts +312 -102
  106. package/src/organisms/Drawer.ts +219 -71
  107. package/src/organisms/DropdownMenu.ts +219 -61
  108. package/src/organisms/Form.ts +48 -34
  109. package/src/organisms/HoverCard.ts +187 -53
  110. package/src/organisms/Menubar.ts +247 -87
  111. package/src/organisms/NavigationMenu.ts +306 -128
  112. package/src/organisms/Popover.ts +215 -39
  113. package/src/organisms/Questionnaire.ts +9 -6
  114. package/src/organisms/Select.ts +397 -130
  115. package/src/organisms/Sheet.ts +252 -83
  116. package/src/organisms/Sidebar.ts +438 -185
  117. package/src/organisms/Tooltip.ts +315 -65
  118. package/src/organisms/index.ts +284 -14
  119. package/src/primitives/floating.ts +33 -0
  120. package/src/primitives/floatingSurface.ts +19 -0
  121. package/src/primitives/menu.ts +79 -18
  122. package/src/primitives/menuParts.ts +371 -0
@@ -1,23 +1,50 @@
1
1
  /**
2
2
  * Avatar — a user's picture, with a fallback when there is none.
3
3
  *
4
- * shadcn splits this into `Avatar` / `AvatarImage` / `AvatarFallback` because
5
- * Radix needs three components to track the image's load state across them.
6
- * nebula tracks it in one signal inside one component, so the API is a `src`
7
- * and a `fallback`.
4
+ * Avatar({ children: () => html`
5
+ * ${AvatarImage({ src: user.photo, alt: user.name })}
6
+ * ${AvatarFallback({ children: initials })}
7
+ * ` })
8
8
  *
9
9
  * Three states, not two. An image that has not loaded *yet* must not show the
10
10
  * fallback — swapping initials in and a photo over them a moment later is the
11
11
  * flicker this component exists to avoid. So the fallback appears only once
12
- * the image has actually failed, or when there was no `src` to begin with.
12
+ * the image has actually failed, or when there is no `AvatarImage` at all.
13
+ *
14
+ * That is what the context carries: the image reports its own load state up,
15
+ * the fallback reads it, and neither knows the other exists. Radix needs the
16
+ * same three pieces for the same reason.
13
17
  */
14
- import { type Slot } from "../lib/children.js";
18
+ import type { Parts, Slot } from "../lib/children.js";
15
19
  import { type Reactive } from "../lib/props.js";
16
20
  export interface AvatarProps {
21
+ size?: "sm" | "default" | "lg";
22
+ class?: Reactive<string>;
23
+ children?: Parts;
24
+ }
25
+ export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/aurora").TemplateResult;
26
+ export interface AvatarImageProps {
17
27
  src?: Reactive<string | undefined>;
18
28
  alt?: Reactive<string>;
19
- /** Shown when there is no image, or it failed. Usually initials. */
20
- fallback?: Slot;
21
29
  class?: Reactive<string>;
22
30
  }
23
- export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/aurora").TemplateResult;
31
+ export declare const AvatarImage: (props?: AvatarImageProps | undefined) => import("@c9up/aurora").TemplateResult;
32
+ export interface AvatarFallbackProps {
33
+ children?: Slot;
34
+ class?: Reactive<string>;
35
+ }
36
+ export declare const AvatarFallback: (props?: AvatarFallbackProps | undefined) => import("@c9up/aurora").TemplateResult;
37
+ export interface AvatarBadgeProps {
38
+ children?: Slot;
39
+ class?: Reactive<string>;
40
+ }
41
+ /** A status dot in the corner — online, unread, verified. */
42
+ export declare const AvatarBadge: (props?: AvatarBadgeProps | undefined) => import("@c9up/aurora").TemplateResult;
43
+ export interface AvatarGroupProps {
44
+ children?: Slot;
45
+ class?: Reactive<string>;
46
+ }
47
+ /** Overlapping avatars, each ringed so the stack reads as separate faces. */
48
+ export declare const AvatarGroup: (props?: AvatarGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
49
+ /** The "+3" that closes a group. */
50
+ export declare const AvatarGroupCount: (props?: AvatarGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -1,46 +1,85 @@
1
1
  /**
2
2
  * Avatar — a user's picture, with a fallback when there is none.
3
3
  *
4
- * shadcn splits this into `Avatar` / `AvatarImage` / `AvatarFallback` because
5
- * Radix needs three components to track the image's load state across them.
6
- * nebula tracks it in one signal inside one component, so the API is a `src`
7
- * and a `fallback`.
4
+ * Avatar({ children: () => html`
5
+ * ${AvatarImage({ src: user.photo, alt: user.name })}
6
+ * ${AvatarFallback({ children: initials })}
7
+ * ` })
8
8
  *
9
9
  * Three states, not two. An image that has not loaded *yet* must not show the
10
10
  * fallback — swapping initials in and a photo over them a moment later is the
11
11
  * flicker this component exists to avoid. So the fallback appears only once
12
- * the image has actually failed, or when there was no `src` to begin with.
12
+ * the image has actually failed, or when there is no `AvatarImage` at all.
13
+ *
14
+ * That is what the context carries: the image reports its own load state up,
15
+ * the fallback reads it, and neither knows the other exists. Radix needs the
16
+ * same three pieces for the same reason.
13
17
  */
14
- import { component, html, signal } from "@c9up/aurora";
18
+ import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
15
19
  import { slot } from "../lib/children.js";
16
20
  import { cn } from "../lib/cn.js";
17
21
  import { read, readOr } from "../lib/props.js";
22
+ const AvatarContext = createContext("Avatar");
18
23
  export const Avatar = component((props) => {
19
- const state = signal("pending");
24
+ // `absent` until an image says otherwise: an avatar with no `AvatarImage`
25
+ // is a fallback-only avatar, and it must not wait for a load that will
26
+ // never happen.
27
+ const state = signal("absent");
28
+ provide(AvatarContext, {
29
+ state: () => state(),
30
+ setState: (next) => state(next),
31
+ });
32
+ return html `<span
33
+ data-slot="avatar"
34
+ data-size="${props.size ?? "default"}"
35
+ class="${() => cn("group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6", read(props.class))}"
36
+ >${props.children?.()}</span>`;
37
+ });
38
+ export const AvatarImage = component((props) => {
39
+ const avatar = inject(AvatarContext);
20
40
  const hasSrc = () => {
21
41
  const src = read(props.src);
22
42
  return src !== undefined && src !== "";
23
43
  };
24
- const showFallback = () => !hasSrc() || state() === "failed";
25
- return html `<span
26
- data-slot="avatar"
27
- class="${() => cn("relative flex size-8 shrink-0 overflow-hidden rounded-full", read(props.class))}"
28
- >
29
- ${() => hasSrc() && state() !== "failed"
44
+ // Reported during setup, so the fallback built after it already reads the
45
+ // right state rather than flashing through `absent`.
46
+ avatar.setState(hasSrc() ? "pending" : "absent");
47
+ return html `${() => hasSrc() && avatar.state() !== "failed"
30
48
  ? html `<img
31
- data-slot="avatar-image"
32
- src="${() => read(props.src)}"
33
- alt="${() => readOr(props.alt, "")}"
34
- class="aspect-square size-full object-cover"
35
- @load="${() => state("loaded")}"
36
- @error="${() => state("failed")}"
37
- />`
38
- : null}
39
- ${() => showFallback()
49
+ data-slot="avatar-image"
50
+ src="${() => read(props.src)}"
51
+ alt="${() => readOr(props.alt, "")}"
52
+ class="${() => cn("aspect-square size-full object-cover", read(props.class))}"
53
+ @load="${() => avatar.setState("loaded")}"
54
+ @error="${() => avatar.setState("failed")}"
55
+ />`
56
+ : null}`;
57
+ });
58
+ export const AvatarFallback = component((props) => {
59
+ const avatar = inject(AvatarContext);
60
+ const show = () => {
61
+ const state = avatar.state();
62
+ return state === "absent" || state === "failed";
63
+ };
64
+ return html `${() => show()
40
65
  ? html `<span
41
- data-slot="avatar-fallback"
42
- class="bg-muted flex size-full items-center justify-center rounded-full text-xs font-medium"
43
- >${slot(props.fallback)}</span>`
44
- : null}
45
- </span>`;
66
+ data-slot="avatar-fallback"
67
+ class="${() => cn("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs", read(props.class))}"
68
+ >${slot(props.children)}</span>`
69
+ : null}`;
46
70
  });
71
+ /** A status dot in the corner — online, unread, verified. */
72
+ export const AvatarBadge = component((props) => html `<span
73
+ data-slot="avatar-badge"
74
+ class="${() => cn("bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full ring-2 select-none", "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden", "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2", "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2", read(props.class))}"
75
+ >${slot(props.children)}</span>`);
76
+ /** Overlapping avatars, each ringed so the stack reads as separate faces. */
77
+ export const AvatarGroup = component((props) => html `<div
78
+ data-slot="avatar-group"
79
+ class="${() => cn("group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background", read(props.class))}"
80
+ >${slot(props.children)}</div>`);
81
+ /** The "+3" that closes a group. */
82
+ export const AvatarGroupCount = component((props) => html `<span
83
+ data-slot="avatar-group-count"
84
+ class="${() => cn("bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3", read(props.class))}"
85
+ >${slot(props.children)}</span>`);
@@ -12,7 +12,7 @@
12
12
  * Slider is an atom despite being interactive, because it is one input.
13
13
  */
14
14
  export { AspectRatio, type AspectRatioProps } from "./AspectRatio.js";
15
- export { Avatar, type AvatarProps } from "./Avatar.js";
15
+ export { Avatar, AvatarBadge, type AvatarBadgeProps, AvatarFallback, type AvatarFallbackProps, AvatarGroup, AvatarGroupCount, type AvatarGroupProps, AvatarImage, type AvatarImageProps, type AvatarProps, } from "./Avatar.js";
16
16
  export { Badge, type BadgeProps, type BadgeVariants, badgeVariants, } from "./Badge.js";
17
17
  export { Button, type ButtonProps, type ButtonVariants, buttonVariants, } from "./Button.js";
18
18
  export { Checkbox, type CheckboxProps, checkboxClasses } from "./Checkbox.js";
@@ -12,7 +12,7 @@
12
12
  * Slider is an atom despite being interactive, because it is one input.
13
13
  */
14
14
  export { AspectRatio } from "./AspectRatio.js";
15
- export { Avatar } from "./Avatar.js";
15
+ export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, } from "./Avatar.js";
16
16
  export { Badge, badgeVariants, } from "./Badge.js";
17
17
  export { Button, buttonVariants, } from "./Button.js";
18
18
  export { Checkbox, checkboxClasses } from "./Checkbox.js";
@@ -17,6 +17,36 @@ import type { Reactive } from "./props.js";
17
17
  export type Child = TemplateResult | Node | string | number | boolean | null | undefined | readonly Child[];
18
18
  /** Content that may be constant or recomputed. */
19
19
  export type Slot = Reactive<Child>;
20
+ /**
21
+ * The children of a component that PROVIDES context, as a function.
22
+ *
23
+ * A compound component — `Tooltip`, `Select`, `DropdownMenu` — shares its
24
+ * state with its parts through Aurora's context, and context reaches only what
25
+ * the provider creates inside its own setup. Aurora evaluates eagerly, so
26
+ * children handed over already built ran before the provider existed:
27
+ *
28
+ * Tooltip({ children: TooltipTrigger({ … }) }) // ✗ built too early
29
+ * Tooltip({ children: () => TooltipTrigger({ … }) }) // ✓ the setup calls it
30
+ *
31
+ * This is the aurora spelling of what JSX gets from deferring an element tree.
32
+ * `Parts` names it so the type makes the requirement, rather than a blank
33
+ * surface at runtime.
34
+ *
35
+ * Called ONCE, during setup — the structure of a compound component is fixed,
36
+ * and its moving pieces are signals inside the parts.
37
+ *
38
+ * The same rule read from the other end: a part that READS context must be
39
+ * built eagerly too, so it must not be hidden inside a `Slot`. `Slot` exists
40
+ * for content that CHANGES, and the renderer calls it later, by which time
41
+ * there is no context left to read:
42
+ *
43
+ * DialogHeader({ children: html`${DialogTitle(…)}` }) // ✓ a value
44
+ * DialogHeader({ children: () => html`${DialogTitle(…)}` }) // ✗ too late
45
+ *
46
+ * So: write `() =>` for a component that PROVIDES (its type says `Parts`), and
47
+ * a plain value everywhere else unless the content really does change.
48
+ */
49
+ export type Parts = () => Child;
20
50
  /**
21
51
  * Bind content into a template so it stays live.
22
52
  *
@@ -29,6 +29,16 @@ import type { Side } from "../primitives/floating.js";
29
29
  * once, so reduced motion gets an instant close with no branch in the component.
30
30
  */
31
31
  export declare const zoomInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 motion-reduce:animate-none";
32
+ /**
33
+ * The entrance offset every anchored surface shares.
34
+ *
35
+ * shadcn puts these four on popover, dropdown, select, tooltip, hover card,
36
+ * menubar and context-menu content alike, so the surface slides in from the
37
+ * edge it is anchored against and the motion points back at whatever opened
38
+ * it. `data-side` is written by `autoPosition` after any flip, so a menu that
39
+ * flipped above its trigger slides the other way without a second class.
40
+ */
41
+ export declare const slideInFromSide = "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
32
42
  /** Backdrops and tooltips — no movement, just opacity. */
33
43
  export declare const fadeInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 motion-reduce:animate-none";
34
44
  /**
@@ -28,6 +28,16 @@
28
28
  * once, so reduced motion gets an instant close with no branch in the component.
29
29
  */
30
30
  export const zoomInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 motion-reduce:animate-none";
31
+ /**
32
+ * The entrance offset every anchored surface shares.
33
+ *
34
+ * shadcn puts these four on popover, dropdown, select, tooltip, hover card,
35
+ * menubar and context-menu content alike, so the surface slides in from the
36
+ * edge it is anchored against and the motion points back at whatever opened
37
+ * it. `data-side` is written by `autoPosition` after any flip, so a menu that
38
+ * flipped above its trigger slides the other way without a second class.
39
+ */
40
+ export const slideInFromSide = "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
31
41
  /** Backdrops and tooltips — no movement, just opacity. */
32
42
  export const fadeInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 motion-reduce:animate-none";
33
43
  /**
@@ -1,28 +1,25 @@
1
1
  /**
2
2
  * Accordion — a stack of collapsible sections.
3
3
  *
4
- * Data-driven rather than composed: an accordion is a list, and describing it
5
- * as one is both shorter to write and the only shape that lets the group
6
- * enforce `type: "single"` — which needs to know about every section at once,
7
- * something Radix can only do through context.
4
+ * Accordion({ type: "single", children: () => html`
5
+ * ${AccordionItem({ value: "a", children: () => html`
6
+ * ${AccordionTrigger({ children: "Shipping" })}
7
+ * ${AccordionContent({ children: "Two to four days." })}
8
+ * ` })}
9
+ * ` })
10
+ *
11
+ * `type: "single"` needs to know about every section at once, which is what
12
+ * the context carries: the group owns the open SET and each item asks whether
13
+ * it is in it. Radix does the same, for the same reason.
8
14
  *
9
15
  * The keyboard behaviour is the WAI-ARIA accordion pattern, delegated to
10
16
  * `rovingFocus` over the headers: arrows move between sections, Home and End
11
17
  * jump to the ends, and the headers are one tab stop rather than one each.
12
18
  */
13
- import type { Child, Slot } from "../lib/children.js";
19
+ import type { Parts, Slot } from "../lib/children.js";
14
20
  import { type Reactive } from "../lib/props.js";
15
- export interface AccordionItem {
16
- /** Stable key. Used for the open-state set and for the ARIA ids. */
17
- value: string;
18
- /** The header content. */
19
- trigger: Child;
20
- /** The panel content. */
21
- content: Slot;
22
- disabled?: boolean;
23
- }
24
21
  export interface AccordionProps {
25
- items: readonly AccordionItem[];
22
+ children?: Parts;
26
23
  /** `"single"` closes the open section when another opens. Default `"single"`. */
27
24
  type?: "single" | "multiple";
28
25
  /** Open at first render. A string, or several for `type: "multiple"`. */
@@ -33,3 +30,27 @@ export interface AccordionProps {
33
30
  class?: Reactive<string>;
34
31
  }
35
32
  export declare const Accordion: (props?: AccordionProps | undefined) => import("@c9up/aurora").TemplateResult;
33
+ export interface AccordionItemProps {
34
+ /** Stable key. Used for the open-state set and for the ARIA ids. */
35
+ value: string;
36
+ disabled?: boolean;
37
+ class?: Reactive<string>;
38
+ children?: Parts;
39
+ }
40
+ /**
41
+ * One section.
42
+ *
43
+ * Provides a second context of its own, so the trigger and the panel inside it
44
+ * share their ids without the caller repeating the value on each.
45
+ */
46
+ export declare const AccordionItem: (props?: AccordionItemProps | undefined) => import("@c9up/aurora").TemplateResult;
47
+ export interface AccordionTriggerProps {
48
+ children?: Slot;
49
+ class?: Reactive<string>;
50
+ }
51
+ export declare const AccordionTrigger: (props?: AccordionTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
52
+ export interface AccordionContentProps {
53
+ children?: Slot;
54
+ class?: Reactive<string>;
55
+ }
56
+ export declare const AccordionContent: (props?: AccordionContentProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -1,22 +1,30 @@
1
1
  /**
2
2
  * Accordion — a stack of collapsible sections.
3
3
  *
4
- * Data-driven rather than composed: an accordion is a list, and describing it
5
- * as one is both shorter to write and the only shape that lets the group
6
- * enforce `type: "single"` — which needs to know about every section at once,
7
- * something Radix can only do through context.
4
+ * Accordion({ type: "single", children: () => html`
5
+ * ${AccordionItem({ value: "a", children: () => html`
6
+ * ${AccordionTrigger({ children: "Shipping" })}
7
+ * ${AccordionContent({ children: "Two to four days." })}
8
+ * ` })}
9
+ * ` })
10
+ *
11
+ * `type: "single"` needs to know about every section at once, which is what
12
+ * the context carries: the group owns the open SET and each item asks whether
13
+ * it is in it. Radix does the same, for the same reason.
8
14
  *
9
15
  * The keyboard behaviour is the WAI-ARIA accordion pattern, delegated to
10
16
  * `rovingFocus` over the headers: arrows move between sections, Home and End
11
17
  * jump to the ends, and the headers are one tab stop rather than one each.
12
18
  */
13
- import { component, html, onMount, onUnmount, signal } from "@c9up/aurora";
19
+ import { component, createContext, html, inject, onMount, onUnmount, provide, signal, } from "@c9up/aurora";
14
20
  import { slot } from "../lib/children.js";
15
21
  import { cn } from "../lib/cn.js";
16
22
  import { ChevronDownIcon } from "../lib/icons.js";
17
23
  import { uid } from "../lib/id.js";
18
24
  import { read } from "../lib/props.js";
19
25
  import { rovingFocus } from "../primitives/rovingFocus.js";
26
+ const AccordionContext = createContext("Accordion");
27
+ const AccordionItemContext = createContext("AccordionItem");
20
28
  export const Accordion = component((props) => {
21
29
  const type = props.type ?? "single";
22
30
  const open = signal(normaliseInitial(props.defaultValue));
@@ -42,56 +50,71 @@ export const Accordion = component((props) => {
42
50
  group.sync();
43
51
  });
44
52
  onUnmount(() => group?.destroy());
53
+ provide(AccordionContext, { isOpen, toggle });
45
54
  return html `<div
46
55
  data-slot="accordion"
47
56
  id="${rootId}"
48
57
  class="${() => cn("flex w-full flex-col", read(props.class))}"
49
- >
50
- ${props.items.map((item) => renderItem(item, isOpen, toggle))}
51
- </div>`;
58
+ >${props.children?.()}</div>`;
52
59
  });
53
- function renderItem(item, isOpen, toggle) {
60
+ /**
61
+ * One section.
62
+ *
63
+ * Provides a second context of its own, so the trigger and the panel inside it
64
+ * share their ids without the caller repeating the value on each.
65
+ */
66
+ export const AccordionItem = component((props) => {
67
+ const accordion = inject(AccordionContext);
54
68
  const triggerId = uid("accordion-trigger");
55
69
  const panelId = uid("accordion-panel");
56
- const state = () => (isOpen(item.value) ? "open" : "closed");
70
+ const open = () => accordion.isOpen(props.value);
71
+ provide(AccordionItemContext, {
72
+ value: props.value,
73
+ triggerId,
74
+ panelId,
75
+ disabled: props.disabled === true,
76
+ open,
77
+ toggle: () => accordion.toggle(props.value),
78
+ });
57
79
  return html `<div
58
80
  data-slot="accordion-item"
59
- data-state="${state}"
60
- class="border-b last:border-b-0"
61
- >
62
- <h3 class="flex">
63
- <button
64
- type="button"
65
- data-slot="accordion-trigger"
66
- data-nebula-item
67
- data-state="${state}"
68
- data-disabled="${item.disabled === true ? "" : undefined}"
69
- id="${triggerId}"
70
- aria-expanded="${() => (isOpen(item.value) ? "true" : "false")}"
71
- aria-controls="${panelId}"
72
- ?disabled="${item.disabled === true}"
73
- class="focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium outline-none transition-all hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180"
74
- @click="${() => toggle(item.value)}"
75
- >
76
- ${item.trigger}
77
- ${ChevronDownIcon({
81
+ data-state="${() => (open() ? "open" : "closed")}"
82
+ class="${() => cn("border-b last:border-b-0", read(props.class))}"
83
+ >${props.children?.()}</div>`;
84
+ });
85
+ export const AccordionTrigger = component((props) => {
86
+ const item = inject(AccordionItemContext);
87
+ return html `<h3 class="flex"><button
88
+ type="button"
89
+ data-slot="accordion-trigger"
90
+ data-nebula-item
91
+ data-state="${() => (item.open() ? "open" : "closed")}"
92
+ data-disabled="${item.disabled ? "" : undefined}"
93
+ id="${item.triggerId}"
94
+ aria-expanded="${() => (item.open() ? "true" : "false")}"
95
+ aria-controls="${item.panelId}"
96
+ ?disabled="${item.disabled}"
97
+ class="${() => cn("focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium outline-none transition-all hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180", read(props.class))}"
98
+ @click="${() => item.toggle()}"
99
+ >${slot(props.children)}${ChevronDownIcon({
78
100
  class: "text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200",
79
- })}
80
- </button>
81
- </h3>
82
- <div
83
- data-slot="accordion-content"
84
- id="${panelId}"
85
- role="region"
86
- aria-labelledby="${triggerId}"
87
- ?inert="${() => !isOpen(item.value)}"
88
- class="grid text-sm transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none"
89
- style="${() => `grid-template-rows: ${isOpen(item.value) ? "1fr" : "0fr"}`}"
90
- >
91
- <div class="overflow-hidden"><div class="pt-0 pb-4">${slot(item.content)}</div></div>
92
- </div>
93
- </div>`;
94
- }
101
+ })}</button></h3>`;
102
+ });
103
+ export const AccordionContent = component((props) => {
104
+ const item = inject(AccordionItemContext);
105
+ return html `<div
106
+ data-slot="accordion-content"
107
+ id="${item.panelId}"
108
+ role="region"
109
+ data-state="${() => (item.open() ? "open" : "closed")}"
110
+ aria-labelledby="${item.triggerId}"
111
+ ?inert="${() => !item.open()}"
112
+ class="grid text-sm transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none"
113
+ style="${() => `grid-template-rows: ${item.open() ? "1fr" : "0fr"}`}"
114
+ ><div class="overflow-hidden"><div
115
+ class="${() => cn("pt-0 pb-4", read(props.class))}"
116
+ >${slot(props.children)}</div></div></div>`;
117
+ });
95
118
  function normaliseInitial(value) {
96
119
  if (value === undefined)
97
120
  return [];
@@ -1,6 +1,15 @@
1
1
  /**
2
2
  * Breadcrumb — the trail back up the hierarchy.
3
3
  *
4
+ * Breadcrumb({ children: BreadcrumbList({ children: html`
5
+ * ${BreadcrumbItem({ children: BreadcrumbLink({ href: "/", children: "Home" }) })}
6
+ * ${BreadcrumbSeparator({})}
7
+ * ${BreadcrumbItem({ children: BreadcrumbPage({ children: "Settings" }) })}
8
+ * ` }) })
9
+ *
10
+ * Every part is presentational, so none of them takes `Parts` — there is no
11
+ * context here to be inside of.
12
+ *
4
13
  * `aria-label="breadcrumb"` on the `<nav>` and `aria-current="page"` on the
5
14
  * last entry. Both matter: the label is how a screen reader distinguishes this
6
15
  * navigation from the other landmarks on the page, and `aria-current` is what
@@ -11,19 +20,28 @@
11
20
  * aloud, a chevron between every crumb is noise; the list structure already
12
21
  * conveys the sequence.
13
22
  */
14
- import type { Child } from "../lib/children.js";
23
+ import { type Slot } from "../lib/children.js";
15
24
  import { type Reactive } from "../lib/props.js";
16
- export interface Crumb {
17
- label: Child;
18
- /** Absent on the current page, and on a collapsed ellipsis. */
19
- href?: string;
20
- /** Renders an ellipsis standing in for hidden ancestors. */
21
- ellipsis?: boolean;
22
- }
23
25
  export interface BreadcrumbProps {
24
- items: readonly Crumb[];
25
- /** Replaces the chevron between entries. */
26
- separator?: Child;
26
+ children?: Slot;
27
27
  class?: Reactive<string>;
28
28
  }
29
29
  export declare const Breadcrumb: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
30
+ export declare const BreadcrumbList: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
31
+ export declare const BreadcrumbItem: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
32
+ export interface BreadcrumbLinkProps extends BreadcrumbProps {
33
+ href?: string;
34
+ }
35
+ export declare const BreadcrumbLink: (props?: BreadcrumbLinkProps | undefined) => import("@c9up/aurora").TemplateResult;
36
+ /**
37
+ * The crumb for where you already are.
38
+ *
39
+ * `role="link"` with `aria-disabled` rather than an `<a>` without an `href`:
40
+ * upstream's shape, and it keeps the crumb in the same role as its siblings so
41
+ * a reader announces a consistent list.
42
+ */
43
+ export declare const BreadcrumbPage: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
44
+ /** The chevron. Defaults to one; give children to replace it. */
45
+ export declare const BreadcrumbSeparator: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
46
+ /** Stands in for ancestors that did not fit. */
47
+ export declare const BreadcrumbEllipsis: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;