@c9up/nebula 0.1.9 → 0.2.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 (132) 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/configure.d.ts +6 -0
  6. package/dist/configure.js +4 -22
  7. package/dist/lib/children.d.ts +30 -0
  8. package/dist/lib/id.d.ts +13 -29
  9. package/dist/lib/id.js +13 -39
  10. package/dist/lib/motion.d.ts +10 -0
  11. package/dist/lib/motion.js +10 -0
  12. package/dist/molecules/Accordion.d.ts +36 -15
  13. package/dist/molecules/Accordion.js +68 -45
  14. package/dist/molecules/Breadcrumb.d.ts +29 -11
  15. package/dist/molecules/Breadcrumb.js +52 -52
  16. package/dist/molecules/Collapsible.d.ts +18 -17
  17. package/dist/molecules/Collapsible.js +42 -34
  18. package/dist/molecules/Field.d.ts +66 -30
  19. package/dist/molecules/Field.js +106 -55
  20. package/dist/molecules/InputGroup.d.ts +39 -21
  21. package/dist/molecules/InputGroup.js +43 -27
  22. package/dist/molecules/InputOTP.d.ts +26 -3
  23. package/dist/molecules/InputOTP.js +109 -76
  24. package/dist/molecules/Message.js +5 -4
  25. package/dist/molecules/Pagination.d.ts +36 -11
  26. package/dist/molecules/Pagination.js +58 -74
  27. package/dist/molecules/RadioGroup.d.ts +25 -17
  28. package/dist/molecules/RadioGroup.js +47 -43
  29. package/dist/molecules/Resizable.d.ts +32 -7
  30. package/dist/molecules/Resizable.js +76 -49
  31. package/dist/molecules/Tabs.d.ts +49 -11
  32. package/dist/molecules/Tabs.js +107 -51
  33. package/dist/molecules/ToggleGroup.d.ts +16 -10
  34. package/dist/molecules/ToggleGroup.js +37 -21
  35. package/dist/molecules/index.d.ts +11 -11
  36. package/dist/molecules/index.js +11 -11
  37. package/dist/organisms/AlertDialog.d.ts +80 -28
  38. package/dist/organisms/AlertDialog.js +192 -67
  39. package/dist/organisms/Carousel.d.ts +25 -3
  40. package/dist/organisms/Carousel.js +75 -43
  41. package/dist/organisms/Combobox.d.ts +2 -1
  42. package/dist/organisms/Combobox.js +46 -16
  43. package/dist/organisms/Command.d.ts +73 -32
  44. package/dist/organisms/Command.js +209 -131
  45. package/dist/organisms/CommandDialog.js +5 -5
  46. package/dist/organisms/ContextMenu.d.ts +41 -19
  47. package/dist/organisms/ContextMenu.js +112 -71
  48. package/dist/organisms/DataTable.js +42 -8
  49. package/dist/organisms/Dialog.d.ts +97 -31
  50. package/dist/organisms/Dialog.js +193 -68
  51. package/dist/organisms/Drawer.d.ts +33 -10
  52. package/dist/organisms/Drawer.js +130 -52
  53. package/dist/organisms/DropdownMenu.d.ts +58 -11
  54. package/dist/organisms/DropdownMenu.js +137 -50
  55. package/dist/organisms/Form.js +9 -11
  56. package/dist/organisms/HoverCard.d.ts +39 -19
  57. package/dist/organisms/HoverCard.js +116 -40
  58. package/dist/organisms/Menubar.d.ts +55 -19
  59. package/dist/organisms/Menubar.js +166 -82
  60. package/dist/organisms/NavigationMenu.d.ts +77 -31
  61. package/dist/organisms/NavigationMenu.js +169 -98
  62. package/dist/organisms/Popover.d.ts +72 -12
  63. package/dist/organisms/Popover.js +132 -25
  64. package/dist/organisms/Questionnaire.js +5 -5
  65. package/dist/organisms/Select.d.ts +99 -18
  66. package/dist/organisms/Select.js +253 -111
  67. package/dist/organisms/Sheet.d.ts +57 -13
  68. package/dist/organisms/Sheet.js +141 -54
  69. package/dist/organisms/Sidebar.d.ts +146 -56
  70. package/dist/organisms/Sidebar.js +236 -128
  71. package/dist/organisms/Tooltip.d.ts +88 -14
  72. package/dist/organisms/Tooltip.js +210 -47
  73. package/dist/organisms/index.d.ts +15 -15
  74. package/dist/organisms/index.js +15 -15
  75. package/dist/primitives/floating.js +25 -0
  76. package/dist/primitives/floatingSurface.d.ts +11 -0
  77. package/dist/primitives/floatingSurface.js +8 -0
  78. package/dist/primitives/menu.d.ts +45 -1
  79. package/dist/primitives/menu.js +45 -14
  80. package/dist/primitives/menuParts.d.ts +113 -0
  81. package/dist/primitives/menuParts.js +207 -0
  82. package/dist/stubs.d.ts +13 -0
  83. package/dist/stubs.js +14 -0
  84. package/nebula.css +1 -1
  85. package/package.json +4 -3
  86. package/registry.json +18 -6
  87. package/src/atoms/Avatar.ts +141 -37
  88. package/src/atoms/index.ts +13 -1
  89. package/src/configure.ts +10 -23
  90. package/src/lib/children.ts +31 -0
  91. package/src/lib/id.ts +11 -39
  92. package/src/lib/motion.ts +12 -0
  93. package/src/molecules/Accordion.ts +120 -60
  94. package/src/molecules/Breadcrumb.ts +77 -76
  95. package/src/molecules/Collapsible.ts +77 -41
  96. package/src/molecules/Field.ts +187 -72
  97. package/src/molecules/InputGroup.ts +88 -35
  98. package/src/molecules/InputOTP.ts +150 -86
  99. package/src/molecules/Message.ts +6 -4
  100. package/src/molecules/Pagination.ts +96 -101
  101. package/src/molecules/RadioGroup.ts +70 -59
  102. package/src/molecules/Resizable.ts +138 -75
  103. package/src/molecules/Tabs.ts +187 -74
  104. package/src/molecules/ToggleGroup.ts +77 -38
  105. package/src/molecules/index.ts +85 -8
  106. package/src/organisms/AlertDialog.ts +319 -82
  107. package/src/organisms/Carousel.ts +129 -52
  108. package/src/organisms/Combobox.ts +64 -19
  109. package/src/organisms/Command.ts +342 -159
  110. package/src/organisms/CommandDialog.ts +6 -6
  111. package/src/organisms/ContextMenu.ts +185 -83
  112. package/src/organisms/DataTable.ts +56 -10
  113. package/src/organisms/Dialog.ts +312 -102
  114. package/src/organisms/Drawer.ts +219 -71
  115. package/src/organisms/DropdownMenu.ts +219 -61
  116. package/src/organisms/Form.ts +48 -34
  117. package/src/organisms/HoverCard.ts +187 -53
  118. package/src/organisms/Menubar.ts +247 -87
  119. package/src/organisms/NavigationMenu.ts +306 -128
  120. package/src/organisms/Popover.ts +215 -39
  121. package/src/organisms/Questionnaire.ts +9 -6
  122. package/src/organisms/Select.ts +397 -130
  123. package/src/organisms/Sheet.ts +252 -83
  124. package/src/organisms/Sidebar.ts +438 -185
  125. package/src/organisms/Tooltip.ts +315 -65
  126. package/src/organisms/index.ts +284 -14
  127. package/src/primitives/floating.ts +33 -0
  128. package/src/primitives/floatingSurface.ts +19 -0
  129. package/src/primitives/menu.ts +79 -18
  130. package/src/primitives/menuParts.ts +371 -0
  131. package/src/stubs.ts +16 -0
  132. package/stubs/config/nebula.stub +21 -0
@@ -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;
@@ -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
@@ -12,62 +21,53 @@
12
21
  * conveys the sequence.
13
22
  */
14
23
  import { component, html } from "@c9up/aurora";
24
+ import { slot } from "../lib/children.js";
15
25
  import { cn } from "../lib/cn.js";
16
26
  import { ChevronRightIcon, MoreHorizontalIcon } from "../lib/icons.js";
17
27
  import { read } from "../lib/props.js";
18
- export const Breadcrumb = component((props) => {
19
- return html `<nav
28
+ export const Breadcrumb = component((props) => html `<nav
20
29
  data-slot="breadcrumb"
21
30
  aria-label="breadcrumb"
22
31
  class="${() => cn(read(props.class))}"
23
- >
24
- <ol
25
- data-slot="breadcrumb-list"
26
- class="text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5"
27
- >
28
- ${props.items.map((item, index) => renderCrumb(item, index === props.items.length - 1, index > 0, props.separator))}
29
- </ol>
30
- </nav>`;
31
- });
32
- function renderCrumb(item, isLast, needsSeparator, separator) {
33
- return [
34
- needsSeparator
35
- ? html `<li
36
- data-slot="breadcrumb-separator"
37
- role="presentation"
38
- aria-hidden="true"
39
- class="[&>svg]:size-3.5"
40
- >${separator ?? ChevronRightIcon()}</li>`
41
- : null,
42
- html `<li data-slot="breadcrumb-item" class="inline-flex items-center gap-1.5">
43
- ${renderCrumbBody(item, isLast)}
44
- </li>`,
45
- ];
46
- }
47
- function renderCrumbBody(item, isLast) {
48
- if (item.ellipsis === true) {
49
- return html `<span
50
- data-slot="breadcrumb-ellipsis"
51
- role="presentation"
52
- aria-hidden="true"
53
- class="flex size-9 items-center justify-center"
54
- >
55
- ${MoreHorizontalIcon({ class: "size-4" })}
56
- <span class="sr-only">More</span>
57
- </span>`;
58
- }
59
- if (isLast || item.href === undefined) {
60
- return html `<span
61
- data-slot="breadcrumb-page"
62
- role="link"
63
- aria-disabled="true"
64
- aria-current="page"
65
- class="text-foreground font-normal"
66
- >${item.label}</span>`;
67
- }
68
- return html `<a
32
+ >${slot(props.children)}</nav>`);
33
+ export const BreadcrumbList = component((props) => html `<ol
34
+ data-slot="breadcrumb-list"
35
+ class="${() => cn("text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5", read(props.class))}"
36
+ >${slot(props.children)}</ol>`);
37
+ export const BreadcrumbItem = component((props) => html `<li
38
+ data-slot="breadcrumb-item"
39
+ class="${() => cn("inline-flex items-center gap-1.5", read(props.class))}"
40
+ >${slot(props.children)}</li>`);
41
+ export const BreadcrumbLink = component((props) => html `<a
69
42
  data-slot="breadcrumb-link"
70
- href="${item.href}"
71
- class="hover:text-foreground transition-colors"
72
- >${item.label}</a>`;
73
- }
43
+ href="${props.href}"
44
+ class="${() => cn("hover:text-foreground transition-colors", read(props.class))}"
45
+ >${slot(props.children)}</a>`);
46
+ /**
47
+ * The crumb for where you already are.
48
+ *
49
+ * `role="link"` with `aria-disabled` rather than an `<a>` without an `href`:
50
+ * upstream's shape, and it keeps the crumb in the same role as its siblings so
51
+ * a reader announces a consistent list.
52
+ */
53
+ export const BreadcrumbPage = component((props) => html `<span
54
+ data-slot="breadcrumb-page"
55
+ role="link"
56
+ aria-disabled="true"
57
+ aria-current="page"
58
+ class="${() => cn("text-foreground font-normal", read(props.class))}"
59
+ >${slot(props.children)}</span>`);
60
+ /** The chevron. Defaults to one; give children to replace it. */
61
+ export const BreadcrumbSeparator = component((props) => html `<li
62
+ data-slot="breadcrumb-separator"
63
+ role="presentation"
64
+ aria-hidden="true"
65
+ class="${() => cn("[&>svg]:size-3.5", read(props.class))}"
66
+ >${props.children === undefined ? ChevronRightIcon() : slot(props.children)}</li>`);
67
+ /** Stands in for ancestors that did not fit. */
68
+ export const BreadcrumbEllipsis = component((props) => html `<span
69
+ data-slot="breadcrumb-ellipsis"
70
+ role="presentation"
71
+ aria-hidden="true"
72
+ class="${() => cn("flex size-9 items-center justify-center", read(props.class))}"
73
+ >${MoreHorizontalIcon({ class: "size-4" })}<span class="sr-only">More</span></span>`);
@@ -1,17 +1,13 @@
1
1
  /**
2
2
  * Collapsible — a trigger that shows and hides a panel.
3
3
  *
4
- * Two things differ from Radix, both deliberate.
4
+ * Collapsible({ children: () => html`
5
+ * ${CollapsibleTrigger({ children: "Show more" })}
6
+ * ${CollapsibleContent({ children: "…" })}
7
+ * ` })
5
8
  *
6
- * **The API.** Radix composes through React context: `<Collapsible>` publishes
7
- * state that `<CollapsibleTrigger>` and `<CollapsibleContent>` read from
8
- * anywhere below it. Aurora has no context, and the usual workarounds — a
9
- * factory returning bound parts, or threading a handle through props — trade a
10
- * real problem for a clumsier one. So the parts are props: `trigger` and
11
- * `children`. The rendered markup is identical to shadcn's; only the call
12
- * shape changes.
13
- *
14
- * **The animation.** Radix measures the content and publishes its height as
9
+ * One deviation from upstream remains, and it is the animation. Radix measures
10
+ * the content and publishes its height as
15
11
  * `--radix-collapsible-content-height` for the keyframes to interpolate,
16
12
  * because `height: auto` is not animatable. A CSS grid whose single row goes
17
13
  * from `0fr` to `1fr` animates the same transition with no measurement, no
@@ -22,19 +18,24 @@
22
18
  * and stays in the accessibility tree, and a keyboard user tabs into content
23
19
  * that is not on screen.
24
20
  */
25
- import { type Slot } from "../lib/children.js";
21
+ import type { Parts, Slot } from "../lib/children.js";
26
22
  import { type Reactive } from "../lib/props.js";
27
23
  export interface CollapsibleProps {
28
- /** The clickable summary. Rendered inside a button. */
29
- trigger?: Slot;
30
- /** The panel revealed when open. */
31
- children?: Slot;
32
24
  open?: Reactive<boolean>;
33
25
  defaultOpen?: boolean;
34
26
  disabled?: Reactive<boolean>;
35
27
  onOpenChange?: (open: boolean) => void;
36
28
  class?: Reactive<string>;
37
- triggerClass?: Reactive<string>;
38
- contentClass?: Reactive<string>;
29
+ children?: Parts;
39
30
  }
40
31
  export declare const Collapsible: (props?: CollapsibleProps | undefined) => import("@c9up/aurora").TemplateResult;
32
+ export interface CollapsibleTriggerProps {
33
+ children?: Slot;
34
+ class?: Reactive<string>;
35
+ }
36
+ export declare const CollapsibleTrigger: (props?: CollapsibleTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
37
+ export interface CollapsibleContentProps {
38
+ children?: Slot;
39
+ class?: Reactive<string>;
40
+ }
41
+ export declare const CollapsibleContent: (props?: CollapsibleContentProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -1,17 +1,13 @@
1
1
  /**
2
2
  * Collapsible — a trigger that shows and hides a panel.
3
3
  *
4
- * Two things differ from Radix, both deliberate.
4
+ * Collapsible({ children: () => html`
5
+ * ${CollapsibleTrigger({ children: "Show more" })}
6
+ * ${CollapsibleContent({ children: "…" })}
7
+ * ` })
5
8
  *
6
- * **The API.** Radix composes through React context: `<Collapsible>` publishes
7
- * state that `<CollapsibleTrigger>` and `<CollapsibleContent>` read from
8
- * anywhere below it. Aurora has no context, and the usual workarounds — a
9
- * factory returning bound parts, or threading a handle through props — trade a
10
- * real problem for a clumsier one. So the parts are props: `trigger` and
11
- * `children`. The rendered markup is identical to shadcn's; only the call
12
- * shape changes.
13
- *
14
- * **The animation.** Radix measures the content and publishes its height as
9
+ * One deviation from upstream remains, and it is the animation. Radix measures
10
+ * the content and publishes its height as
15
11
  * `--radix-collapsible-content-height` for the keyframes to interpolate,
16
12
  * because `height: auto` is not animatable. A CSS grid whose single row goes
17
13
  * from `0fr` to `1fr` animates the same transition with no measurement, no
@@ -22,12 +18,13 @@
22
18
  * and stays in the accessibility tree, and a keyboard user tabs into content
23
19
  * that is not on screen.
24
20
  */
25
- import { component, html } from "@c9up/aurora";
21
+ import { component, createContext, html, inject, provide } from "@c9up/aurora";
26
22
  import { slot } from "../lib/children.js";
27
23
  import { cn } from "../lib/cn.js";
28
24
  import { uid } from "../lib/id.js";
29
25
  import { read, readOr } from "../lib/props.js";
30
26
  import { controllable } from "../primitives/controllable.js";
27
+ const CollapsibleContext = createContext("Collapsible");
31
28
  export const Collapsible = component((props) => {
32
29
  const state = controllable({
33
30
  value: props.open,
@@ -36,36 +33,47 @@ export const Collapsible = component((props) => {
36
33
  });
37
34
  const contentId = uid("collapsible-content");
38
35
  const triggerId = uid("collapsible-trigger");
39
- const toggle = () => {
40
- if (readOr(props.disabled, false))
41
- return;
42
- state.set(!state.current());
43
- };
36
+ provide(CollapsibleContext, {
37
+ triggerId,
38
+ contentId,
39
+ open: () => state.current(),
40
+ disabled: () => readOr(props.disabled, false),
41
+ toggle() {
42
+ if (readOr(props.disabled, false))
43
+ return;
44
+ state.set(!state.current());
45
+ },
46
+ });
44
47
  return html `<div
45
48
  data-slot="collapsible"
46
49
  data-state="${() => (state.current() ? "open" : "closed")}"
47
50
  class="${() => cn("flex flex-col", read(props.class))}"
48
- >
49
- <button
51
+ >${props.children?.()}</div>`;
52
+ });
53
+ export const CollapsibleTrigger = component((props) => {
54
+ const collapsible = inject(CollapsibleContext);
55
+ return html `<button
50
56
  type="button"
51
57
  data-slot="collapsible-trigger"
52
- id="${triggerId}"
53
- aria-expanded="${() => (state.current() ? "true" : "false")}"
54
- aria-controls="${contentId}"
55
- ?disabled="${() => readOr(props.disabled, false)}"
56
- class="${() => cn("flex items-center justify-between gap-2 outline-none disabled:opacity-50", read(props.triggerClass))}"
57
- @click="${toggle}"
58
- >${slot(props.trigger)}</button>
59
- <div
58
+ id="${collapsible.triggerId}"
59
+ data-state="${() => (collapsible.open() ? "open" : "closed")}"
60
+ aria-expanded="${() => (collapsible.open() ? "true" : "false")}"
61
+ aria-controls="${collapsible.contentId}"
62
+ ?disabled="${() => collapsible.disabled()}"
63
+ class="${() => cn("flex items-center justify-between gap-2 outline-none disabled:opacity-50", read(props.class))}"
64
+ @click="${() => collapsible.toggle()}"
65
+ >${slot(props.children)}</button>`;
66
+ });
67
+ export const CollapsibleContent = component((props) => {
68
+ const collapsible = inject(CollapsibleContext);
69
+ return html `<div
60
70
  data-slot="collapsible-content"
61
- id="${contentId}"
71
+ id="${collapsible.contentId}"
62
72
  role="region"
63
- aria-labelledby="${triggerId}"
64
- ?inert="${() => !state.current()}"
73
+ data-state="${() => (collapsible.open() ? "open" : "closed")}"
74
+ aria-labelledby="${collapsible.triggerId}"
75
+ ?inert="${() => !collapsible.open()}"
65
76
  class="grid transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none"
66
- style="${() => `grid-template-rows: ${state.current() ? "1fr" : "0fr"}`}"
67
- >
68
- <div class="${() => cn("overflow-hidden", read(props.contentClass))}">${slot(props.children)}</div>
69
- </div>
70
- </div>`;
77
+ style="${() => `grid-template-rows: ${collapsible.open() ? "1fr" : "0fr"}`}"
78
+ ><div class="${() => cn("overflow-hidden", read(props.class))}">${slot(props.children)}</div></div>`;
71
79
  });
@@ -1,28 +1,27 @@
1
1
  /**
2
- * Field — a form control with its label, hint and error.
2
+ * Field — a labelled control with its help text and its error.
3
3
  *
4
- * The reason this exists rather than each form writing the four elements by
5
- * hand is the wiring. A control must point at its description and its error
6
- * with `aria-describedby`, and at its own label with `for`/`id`. Done by hand
7
- * that is three ids to invent and keep in step per field, and the failure is
8
- * silent — a sighted user sees the error, a screen-reader user does not.
4
+ * Field({ ids, children: () => html`
5
+ * ${FieldLabel({ children: "Email" })}
6
+ * ${Input({ id: ids.control, describedBy: ids.describedBy })}
7
+ * ${FieldDescription({ children: "We never share it." })}
8
+ * ${FieldError({ children: error })}
9
+ * ` })
9
10
  *
10
- * `Field` mints the ids and returns them, so the control gets them by
11
- * destructuring rather than by convention:
11
+ * The ids are the whole point of the component. Upstream leaves them to the
12
+ * caller — `<FieldLabel htmlFor="x">` beside `<Input id="x">` — which works
13
+ * until the two drift. `fieldIds()` mints a matching set and `Field` shares it
14
+ * through context, so the label, the description and the error all point at
15
+ * the right thing without anyone repeating a string. A caller still needs the
16
+ * set for the CONTROL, which is why `fieldIds()` is exported and may be passed
17
+ * in; left out, the field mints its own.
12
18
  *
13
- * const email = fieldIds()
14
- * Field({
15
- * ids: email,
16
- * label: "Email",
17
- * error: () => errors.email,
18
- * children: Input({ id: email.control, describedBy: email.describedBy, invalid: … }),
19
- * })
20
- *
21
- * The error slot is reactive and empty-tolerant: passing `() => errors.email`
22
- * renders nothing until there is something to render, so a field does not
23
- * reserve a blank line for an error that has not happened.
19
+ * `describedBy` names the description AND the error unconditionally. A screen
20
+ * reader skips an id that resolves to nothing, so listing an absent error is
21
+ * harmless — whereas recomputing the attribute when an error appears means the
22
+ * control has to re-render, which Aurora does not do.
24
23
  */
25
- import type { Child, Slot } from "../lib/children.js";
24
+ import type { Parts, Slot } from "../lib/children.js";
26
25
  import { type Reactive } from "../lib/props.js";
27
26
  export interface FieldIds {
28
27
  /** Put on the control. The label's `for` points here. */
@@ -33,22 +32,59 @@ export interface FieldIds {
33
32
  /** Ready-made `aria-describedby` naming both the description and the error. */
34
33
  readonly describedBy: string;
35
34
  }
36
- /** Mint the id set for one field. Call once, in the component that owns it. */
37
35
  export declare function fieldIds(): FieldIds;
38
36
  export interface FieldProps {
39
- ids: FieldIds;
40
- label?: Child;
41
- /** The control itself. */
42
- children?: Slot;
43
- /** Static help text under the control. */
44
- description?: Child;
45
- /** Validation message. Reactive — renders nothing while absent. */
46
- error?: Reactive<string | undefined>;
37
+ /** Reuse a set the caller already put on the control. */
38
+ ids?: FieldIds;
47
39
  required?: boolean;
48
40
  disabled?: Reactive<boolean>;
49
41
  orientation?: "vertical" | "horizontal";
50
42
  class?: Reactive<string>;
43
+ children?: Parts;
51
44
  }
52
45
  export declare const Field: (props?: FieldProps | undefined) => import("@c9up/aurora").TemplateResult;
46
+ export interface FieldSectionProps {
47
+ children?: Slot;
48
+ class?: Reactive<string>;
49
+ }
50
+ /**
51
+ * The label.
52
+ *
53
+ * A `<label>` with `for`, not a `<div>`: clicking it focuses the control, and
54
+ * that is not something `aria-labelledby` gives you.
55
+ */
56
+ export declare const FieldLabel: (props?: FieldSectionProps | undefined) => import("@c9up/aurora").TemplateResult;
57
+ /** A heading inside a field that is not the control's label. */
58
+ export declare const FieldTitle: (props?: FieldSectionProps | undefined) => import("@c9up/aurora").TemplateResult;
59
+ export declare const FieldDescription: (props?: FieldSectionProps | undefined) => import("@c9up/aurora").TemplateResult;
60
+ export interface FieldErrorProps {
61
+ /** Reactive — renders nothing while absent. */
62
+ children?: Reactive<string | undefined>;
63
+ /** Several messages, rendered as a list. */
64
+ errors?: Reactive<readonly string[] | undefined>;
65
+ class?: Reactive<string>;
66
+ }
67
+ /**
68
+ * The validation message.
69
+ *
70
+ * Always in the DOM, `empty:hidden` rather than conditionally rendered: the id
71
+ * `describedBy` names has to resolve to something the moment an error appears,
72
+ * and a node added later is announced late or not at all.
73
+ */
74
+ export declare const FieldError: (props?: FieldErrorProps | undefined) => import("@c9up/aurora").TemplateResult;
75
+ /** Several fields stacked, with the spacing upstream gives a form. */
53
76
  export declare const FieldGroup: (props?: import("./Card.js").CardProps) => import("@c9up/aurora").TemplateResult;
54
- export declare const FieldSeparator: (props?: import("./Card.js").CardProps) => import("@c9up/aurora").TemplateResult;
77
+ /** The text half of a horizontal field, beside its control. */
78
+ export declare const FieldContent: (props?: import("./Card.js").CardProps) => import("@c9up/aurora").TemplateResult;
79
+ /** A `<fieldset>`, for a group of fields that answer one question together. */
80
+ export declare const FieldSet: (props?: FieldSectionProps | undefined) => import("@c9up/aurora").TemplateResult;
81
+ export interface FieldLegendProps extends FieldSectionProps {
82
+ variant?: "legend" | "label";
83
+ }
84
+ export declare const FieldLegend: (props?: FieldLegendProps | undefined) => import("@c9up/aurora").TemplateResult;
85
+ export interface FieldSeparatorProps {
86
+ /** A word in the middle of the rule — "or". */
87
+ children?: Slot;
88
+ class?: Reactive<string>;
89
+ }
90
+ export declare const FieldSeparator: (props?: FieldSeparatorProps | undefined) => import("@c9up/aurora").TemplateResult;