@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
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { component, html } from "@c9up/aurora";
15
15
  import { buttonVariants } from "../atoms/Button.js";
16
+ import { slot } from "../lib/children.js";
16
17
  import { cn } from "../lib/cn.js";
17
18
  import { ChevronLeftIcon, ChevronRightIcon, MoreHorizontalIcon, } from "../lib/icons.js";
18
19
  import { read } from "../lib/props.js";
@@ -57,88 +58,71 @@ function range(from, to) {
57
58
  out.push(value);
58
59
  return out;
59
60
  }
60
- export const Pagination = component((props) => {
61
- const page = () => read(props.page) ?? 1;
62
- const pageCount = () => Math.max(1, read(props.pageCount) ?? 1);
63
- const go = (target) => (event) => {
64
- if (props.onPageChange === undefined)
65
- return;
66
- // Only intercept when the caller wants callback-driven paging. With an
67
- // `href` and no handler the link must navigate normally.
68
- event.preventDefault();
69
- props.onPageChange(Math.min(Math.max(target, 1), pageCount()));
70
- };
71
- return html `<nav
61
+ export const Pagination = component((props) => html `<nav
72
62
  data-slot="pagination"
73
63
  role="navigation"
74
64
  aria-label="pagination"
75
65
  class="${() => cn("mx-auto flex w-full justify-center", read(props.class))}"
76
- >
77
- <ul data-slot="pagination-content" class="flex flex-row items-center gap-1">
78
- <li>
79
- ${link({
80
- label: html `${ChevronLeftIcon({ class: "size-4" })}<span class="hidden sm:block">Previous</span>`,
81
- ariaLabel: "Go to previous page",
82
- href: props.href?.(page() - 1),
83
- disabled: () => page() <= 1,
84
- onClick: go(page() - 1),
85
- size: "default",
86
- extra: "gap-1 px-2.5 sm:pl-2.5",
87
- })}
88
- </li>
89
- ${() => pageWindow(page(), pageCount(), props.window ?? 7).map((entry, index) => entry === null
90
- ? html `<li aria-hidden="true">
91
- <span class="flex size-9 items-center justify-center">
92
- ${MoreHorizontalIcon({ class: "size-4" })}
93
- <span class="sr-only">More pages</span>
94
- </span>
95
- </li>`
96
- : html `<li>
97
- ${link({
98
- label: String(entry),
99
- ariaLabel: `Go to page ${entry}`,
100
- href: props.href?.(entry),
101
- current: entry === page(),
102
- onClick: go(entry),
103
- size: "icon",
104
- key: index,
105
- })}
106
- </li>`)}
107
- <li>
108
- ${link({
109
- label: html `<span class="hidden sm:block">Next</span>${ChevronRightIcon({ class: "size-4" })}`,
110
- ariaLabel: "Go to next page",
111
- href: props.href?.(page() + 1),
112
- disabled: () => page() >= pageCount(),
113
- onClick: go(page() + 1),
114
- size: "default",
115
- extra: "gap-1 px-2.5 sm:pr-2.5",
116
- })}
117
- </li>
118
- </ul>
119
- </nav>`;
120
- });
66
+ >${slot(props.children)}</nav>`);
67
+ export const PaginationContent = component((props) => html `<ul
68
+ data-slot="pagination-content"
69
+ class="${() => cn("flex flex-row items-center gap-1", read(props.class))}"
70
+ >${slot(props.children)}</ul>`);
71
+ export const PaginationItem = component((props) => html `<li
72
+ data-slot="pagination-item"
73
+ >${slot(props.children)}</li>`);
121
74
  /**
122
75
  * One page link.
123
76
  *
124
- * Always an `<a>`, even without an `href`: pagination is navigation, and the
125
- * role is what a screen reader uses to offer "list of links" here. The
126
- * disabled ends carry `aria-disabled` plus `pointer-events-none` rather than
127
- * being removed, so the control keeps its width at both ends of the range.
77
+ * An `<a>` whether or not it has an `href`, because that is what upstream
78
+ * renders and what a pagination IS: a list of destinations. `onSelect`
79
+ * intercepts only when it is given — with an `href` and no handler the link
80
+ * must navigate normally, which is what makes a server-rendered pagination
81
+ * work with JavaScript off.
128
82
  */
129
- function link(spec) {
130
- const disabled = () => spec.disabled?.() === true;
83
+ export const PaginationLink = component((props) => {
84
+ const active = () => read(props.isActive) === true;
85
+ function onClick(event) {
86
+ if (read(props.disabled) === true) {
87
+ event.preventDefault();
88
+ return;
89
+ }
90
+ if (props.onSelect === undefined)
91
+ return;
92
+ event.preventDefault();
93
+ props.onSelect(event);
94
+ }
131
95
  return html `<a
132
96
  data-slot="pagination-link"
133
- href="${spec.href}"
134
- aria-label="${spec.ariaLabel}"
135
- aria-current="${spec.current === true ? "page" : undefined}"
136
- aria-disabled="${() => (disabled() ? "true" : undefined)}"
137
- tabindex="${() => (disabled() ? -1 : 0)}"
97
+ href="${props.href}"
98
+ aria-current="${() => (active() ? "page" : undefined)}"
99
+ aria-label="${props["aria-label"]}"
100
+ aria-disabled="${() => (read(props.disabled) === true ? "true" : undefined)}"
101
+ data-active="${() => (active() ? "true" : "false")}"
138
102
  class="${() => cn(buttonVariants({
139
- variant: spec.current === true ? "outline" : "ghost",
140
- size: spec.size,
141
- }), spec.extra, disabled() ? "pointer-events-none opacity-50" : "")}"
142
- @click="${spec.onClick}"
143
- >${spec.label}</a>`;
144
- }
103
+ variant: active() ? "outline" : "ghost",
104
+ size: props.size ?? "icon",
105
+ }), read(props.disabled) === true ? "pointer-events-none opacity-50" : "", read(props.class))}"
106
+ @click="${onClick}"
107
+ >${slot(props.children)}</a>`;
108
+ });
109
+ export const PaginationPrevious = component((props) => PaginationLink({
110
+ ...props,
111
+ size: "default",
112
+ "aria-label": "Go to previous page",
113
+ class: () => cn("gap-1 px-2.5 sm:pl-2.5", read(props.class)),
114
+ children: html `${ChevronLeftIcon({})}<span class="hidden sm:block">Previous</span>`,
115
+ }));
116
+ export const PaginationNext = component((props) => PaginationLink({
117
+ ...props,
118
+ size: "default",
119
+ "aria-label": "Go to next page",
120
+ class: () => cn("gap-1 px-2.5 sm:pr-2.5", read(props.class)),
121
+ children: html `<span class="hidden sm:block">Next</span>${ChevronRightIcon({})}`,
122
+ }));
123
+ /** Stands in for the pages that did not fit — see `pageWindow`. */
124
+ export const PaginationEllipsis = component((props) => html `<span
125
+ data-slot="pagination-ellipsis"
126
+ aria-hidden="true"
127
+ class="${() => cn("flex size-9 items-center justify-center", read(props.class))}"
128
+ >${MoreHorizontalIcon({ class: "size-4" })}<span class="sr-only">More pages</span></span>`);
@@ -1,32 +1,40 @@
1
1
  /**
2
- * RadioGroup — pick exactly one option.
2
+ * RadioGroup — one choice from a set.
3
3
  *
4
- * Native `<input type="radio">` throughout. The browser already implements the
5
- * radio group pattern on a shared `name`: arrows move and select, only one can
6
- * be checked, and the group is one tab stop. Radix reimplements all of that
7
- * because it needs a stylable element; `appearance-none` gets nebula the same
8
- * styling freedom while the behaviour stays the browser's.
4
+ * RadioGroup({ name: "plan", children: () => html`
5
+ * ${RadioGroupItem({ value: "free", children: "Free" })}
6
+ * ${RadioGroupItem({ value: "pro", children: "Pro", description: "…" })}
7
+ * ` })
9
8
  *
10
- * The indicator dot is a sibling shown by `peer-checked:`, so selecting a
11
- * radio runs no JavaScript at all.
9
+ * A real `<input type="radio">` per item, sharing a `name`. That is what makes
10
+ * the browser treat them as one group: arrow keys move between them, exactly
11
+ * one can be checked, and the control posts with a plain HTML form — none of
12
+ * which a `div` with `role="radio"` gets without reimplementing it.
13
+ *
14
+ * NAMED DEVIATION — upstream renders a `button` with `role="radio"`, because
15
+ * Radix needs one element it fully controls. Everything above is what that
16
+ * costs, so nebula keeps the native input and styles it with `appearance-none`.
17
+ * The `data-slot` names and the indicator are upstream's.
12
18
  */
13
- import type { Child } 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 RadioOption {
16
- value: string;
17
- label: Child;
18
- description?: Child;
19
- disabled?: boolean;
20
- }
21
21
  export interface RadioGroupProps {
22
22
  /** Shared `name`, which is what makes the browser treat these as one group. */
23
23
  name: string;
24
- options: readonly RadioOption[];
25
24
  value?: Reactive<string | undefined>;
26
25
  defaultValue?: string;
27
26
  disabled?: Reactive<boolean>;
28
27
  orientation?: "vertical" | "horizontal";
29
- class?: Reactive<string>;
30
28
  onValueChange?: (value: string) => void;
29
+ class?: Reactive<string>;
30
+ children?: Parts;
31
31
  }
32
32
  export declare const RadioGroup: (props?: RadioGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
33
+ export interface RadioGroupItemProps {
34
+ value: string;
35
+ children?: Slot;
36
+ description?: Slot;
37
+ disabled?: boolean;
38
+ class?: Reactive<string>;
39
+ }
40
+ export declare const RadioGroupItem: (props?: RadioGroupItemProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -1,65 +1,69 @@
1
1
  /**
2
- * RadioGroup — pick exactly one option.
2
+ * RadioGroup — one choice from a set.
3
3
  *
4
- * Native `<input type="radio">` throughout. The browser already implements the
5
- * radio group pattern on a shared `name`: arrows move and select, only one can
6
- * be checked, and the group is one tab stop. Radix reimplements all of that
7
- * because it needs a stylable element; `appearance-none` gets nebula the same
8
- * styling freedom while the behaviour stays the browser's.
4
+ * RadioGroup({ name: "plan", children: () => html`
5
+ * ${RadioGroupItem({ value: "free", children: "Free" })}
6
+ * ${RadioGroupItem({ value: "pro", children: "Pro", description: "…" })}
7
+ * ` })
9
8
  *
10
- * The indicator dot is a sibling shown by `peer-checked:`, so selecting a
11
- * radio runs no JavaScript at all.
9
+ * A real `<input type="radio">` per item, sharing a `name`. That is what makes
10
+ * the browser treat them as one group: arrow keys move between them, exactly
11
+ * one can be checked, and the control posts with a plain HTML form — none of
12
+ * which a `div` with `role="radio"` gets without reimplementing it.
13
+ *
14
+ * NAMED DEVIATION — upstream renders a `button` with `role="radio"`, because
15
+ * Radix needs one element it fully controls. Everything above is what that
16
+ * costs, so nebula keeps the native input and styles it with `appearance-none`.
17
+ * The `data-slot` names and the indicator are upstream's.
12
18
  */
13
- import { component, html } from "@c9up/aurora";
19
+ import { component, createContext, html, inject, provide } from "@c9up/aurora";
20
+ import { slot } from "../lib/children.js";
14
21
  import { cn } from "../lib/cn.js";
15
22
  import { uid } from "../lib/id.js";
16
23
  import { read, readOr } from "../lib/props.js";
17
- const radioClasses = "peer size-4 shrink-0 appearance-none rounded-full border border-input bg-transparent shadow-xs outline-none transition-shadow dark:bg-input/30 checked:border-primary focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
24
+ const radioClasses = "peer border-input dark:bg-input/30 checked:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aspect-square size-4 shrink-0 appearance-none rounded-full border bg-transparent shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
25
+ const RadioGroupContext = createContext("RadioGroup");
18
26
  export const RadioGroup = component((props) => {
19
- const selected = () => {
20
- const controlled = read(props.value);
21
- return controlled === undefined ? props.defaultValue : controlled;
22
- };
27
+ provide(RadioGroupContext, {
28
+ name: props.name,
29
+ selected: () => {
30
+ const controlled = read(props.value);
31
+ return controlled === undefined ? props.defaultValue : controlled;
32
+ },
33
+ disabled: () => readOr(props.disabled, false),
34
+ choose: (value) => props.onValueChange?.(value),
35
+ });
23
36
  return html `<div
24
- role="radiogroup"
25
37
  data-slot="radio-group"
38
+ role="radiogroup"
26
39
  aria-orientation="${props.orientation ?? "vertical"}"
27
40
  class="${() => cn("grid gap-3", props.orientation === "horizontal" ? "grid-flow-col auto-cols-max" : "", read(props.class))}"
28
- >
29
- ${props.options.map((option) => renderOption(option, props, selected))}
30
- </div>`;
41
+ >${props.children?.()}</div>`;
31
42
  });
32
- function renderOption(option, props, selected) {
43
+ export const RadioGroupItem = component((props) => {
44
+ const group = inject(RadioGroupContext);
33
45
  const id = uid("radio");
34
- const descriptionId = option.description === undefined ? undefined : uid("radio-description");
35
- return html `<div class="flex items-start gap-3">
36
- <span class="relative flex size-4 shrink-0 items-center justify-center">
37
- <input
46
+ const descriptionId = props.description === undefined ? undefined : uid("radio-description");
47
+ return html `<div class="flex items-start gap-3"><span
48
+ class="relative flex size-4 shrink-0 items-center justify-center"
49
+ ><input
38
50
  type="radio"
39
51
  data-slot="radio-group-item"
40
52
  id="${id}"
41
- name="${props.name}"
42
- value="${option.value}"
53
+ name="${group.name}"
54
+ value="${props.value}"
43
55
  aria-describedby="${descriptionId}"
44
- ?disabled="${() => option.disabled === true || readOr(props.disabled, false)}"
45
- .checked="${() => selected() === option.value}"
46
- class="${radioClasses}"
47
- @change="${() => props.onValueChange?.(option.value)}"
48
- />
49
- <span
56
+ ?disabled="${() => props.disabled === true || group.disabled()}"
57
+ .checked="${() => group.selected() === props.value}"
58
+ class="${() => cn(radioClasses, read(props.class))}"
59
+ @change="${() => group.choose(props.value)}"
60
+ /><span
61
+ data-slot="radio-group-indicator"
50
62
  class="bg-primary pointer-events-none absolute size-2 rounded-full opacity-0 transition-opacity peer-checked:opacity-100"
51
- ></span>
52
- </span>
53
- <div class="grid gap-1 leading-none">
54
- <label
63
+ ></span></span><div class="grid gap-1 leading-none"><label
55
64
  for="${id}"
56
65
  class="text-sm leading-none font-medium select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50"
57
- >${option.label}</label>
58
- ${option.description === undefined
66
+ >${slot(props.children)}</label>${props.description === undefined
59
67
  ? null
60
- : html `<p id="${descriptionId}" class="text-muted-foreground text-sm">
61
- ${option.description}
62
- </p>`}
63
- </div>
64
- </div>`;
65
- }
68
+ : html `<p id="${descriptionId}" class="text-muted-foreground text-sm">${slot(props.description)}</p>`}</div></div>`;
69
+ });
@@ -19,19 +19,44 @@
19
19
  * move it. A resizable layout reachable only by dragging is unusable by
20
20
  * keyboard, and this is the whole of what it takes to fix that.
21
21
  */
22
- import { type Slot } from "../lib/children.js";
22
+ import type { Parts, Slot } from "../lib/children.js";
23
23
  import { type Reactive } from "../lib/props.js";
24
- export interface ResizableProps {
25
- first?: Slot;
26
- second?: Slot;
24
+ export interface ResizablePanelGroupProps {
27
25
  direction?: "horizontal" | "vertical";
28
26
  /** First pane's share at first render, in percent. Default `50`. */
29
27
  defaultSize?: number;
30
28
  minSize?: number;
31
29
  maxSize?: number;
32
- /** Show the grip dots on the handle. */
30
+ onResize?: (percent: number) => void;
31
+ class?: Reactive<string>;
32
+ children?: Parts;
33
+ }
34
+ export declare const ResizablePanelGroup: (props?: ResizablePanelGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
35
+ export interface ResizablePanelProps {
36
+ children?: Slot;
37
+ class?: Reactive<string>;
38
+ }
39
+ /**
40
+ * One pane.
41
+ *
42
+ * NAMED DEVIATION — two panes, not n. Upstream's `react-resizable-panels`
43
+ * distributes a size array across any number of panels and persists it;
44
+ * `ResizablePanelGroup` here holds ONE split, so the first panel takes the
45
+ * share and the second takes the rest. The parts are upstream's so a layout
46
+ * written against them reads the same; a third panel would simply have no
47
+ * share of its own.
48
+ */
49
+ export declare const ResizablePanel: (props?: ResizablePanelProps | undefined) => import("@c9up/aurora").TemplateResult;
50
+ export interface ResizableHandleProps {
51
+ /** Show the grip dots. */
33
52
  withHandle?: boolean;
34
53
  class?: Reactive<string>;
35
- onResize?: (percent: number) => void;
36
54
  }
37
- export declare const Resizable: (props?: ResizableProps | undefined) => import("@c9up/aurora").TemplateResult;
55
+ /**
56
+ * The divider.
57
+ *
58
+ * `role="separator"` with `aria-valuenow`, and it takes focus: the arrows,
59
+ * Home and End move it. A drag handle that only answers to a pointer is not
60
+ * reachable at all for a keyboard user, and there is no other way to resize.
61
+ */
62
+ export declare const ResizableHandle: (props?: ResizableHandleProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -19,40 +19,82 @@
19
19
  * move it. A resizable layout reachable only by dragging is unusable by
20
20
  * keyboard, and this is the whole of what it takes to fix that.
21
21
  */
22
- import { component, html, signal } from "@c9up/aurora";
22
+ import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
23
23
  import { slot } from "../lib/children.js";
24
24
  import { cn } from "../lib/cn.js";
25
25
  import { GripVerticalIcon } from "../lib/icons.js";
26
26
  import { uid } from "../lib/id.js";
27
27
  import { read } from "../lib/props.js";
28
28
  const KEYBOARD_STEP = 5;
29
- export const Resizable = component((props) => {
29
+ const ResizableContext = createContext("ResizablePanelGroup");
30
+ export const ResizablePanelGroup = component((props) => {
30
31
  const horizontal = props.direction !== "vertical";
31
32
  const min = props.minSize ?? 10;
32
33
  const max = props.maxSize ?? 90;
33
34
  const size = signal(clamp(props.defaultSize ?? 50, min, max));
34
35
  const rootId = uid("resizable");
36
+ let panels = 0;
35
37
  function setSize(percent) {
36
38
  const next = clamp(percent, min, max);
37
39
  size(next);
38
40
  props.onResize?.(next);
39
41
  }
40
- /**
41
- * Convert a pointer position into a percentage of the group.
42
- *
43
- * Measured against the group's own rect on every move rather than a rect
44
- * cached at drag start: the window can be resized mid-drag, and a stale rect
45
- * makes the divider drift away from the pointer.
46
- */
42
+ provide(ResizableContext, {
43
+ rootId,
44
+ horizontal,
45
+ min,
46
+ max,
47
+ size: () => size(),
48
+ setSize,
49
+ claimPanel() {
50
+ panels += 1;
51
+ return panels;
52
+ },
53
+ });
54
+ return html `<div
55
+ data-slot="resizable-panel-group"
56
+ id="${rootId}"
57
+ data-direction="${horizontal ? "horizontal" : "vertical"}"
58
+ class="${() => cn("flex h-full w-full", horizontal ? "flex-row" : "flex-col", read(props.class))}"
59
+ >${props.children?.()}</div>`;
60
+ });
61
+ /**
62
+ * One pane.
63
+ *
64
+ * NAMED DEVIATION — two panes, not n. Upstream's `react-resizable-panels`
65
+ * distributes a size array across any number of panels and persists it;
66
+ * `ResizablePanelGroup` here holds ONE split, so the first panel takes the
67
+ * share and the second takes the rest. The parts are upstream's so a layout
68
+ * written against them reads the same; a third panel would simply have no
69
+ * share of its own.
70
+ */
71
+ export const ResizablePanel = component((props) => {
72
+ const group = inject(ResizableContext);
73
+ const first = group.claimPanel() === 1;
74
+ return html `<div
75
+ data-slot="resizable-panel"
76
+ class="${() => cn("overflow-hidden", first ? "" : "flex-1", read(props.class))}"
77
+ style="${() => (first ? `flex: 0 0 ${group.size()}%` : "")}"
78
+ >${slot(props.children)}</div>`;
79
+ });
80
+ /**
81
+ * The divider.
82
+ *
83
+ * `role="separator"` with `aria-valuenow`, and it takes focus: the arrows,
84
+ * Home and End move it. A drag handle that only answers to a pointer is not
85
+ * reachable at all for a keyboard user, and there is no other way to resize.
86
+ */
87
+ export const ResizableHandle = component((props) => {
88
+ const group = inject(ResizableContext);
47
89
  function percentAt(event) {
48
- const root = document.getElementById(rootId);
90
+ const root = document.getElementById(group.rootId);
49
91
  if (root === null)
50
92
  return null;
51
93
  const rect = root.getBoundingClientRect();
52
- const span = horizontal ? rect.width : rect.height;
94
+ const span = group.horizontal ? rect.width : rect.height;
53
95
  if (span === 0)
54
96
  return null;
55
- const offset = horizontal
97
+ const offset = group.horizontal
56
98
  ? event.clientX - rect.left
57
99
  : event.clientY - rect.top;
58
100
  return (offset / span) * 100;
@@ -66,7 +108,7 @@ export const Resizable = component((props) => {
66
108
  const onMove = (move) => {
67
109
  const percent = percentAt(move);
68
110
  if (percent !== null)
69
- setSize(percent);
111
+ group.setSize(percent);
70
112
  };
71
113
  const onUp = () => {
72
114
  target.releasePointerCapture(event.pointerId);
@@ -79,57 +121,42 @@ export const Resizable = component((props) => {
79
121
  target.addEventListener("pointercancel", onUp);
80
122
  }
81
123
  function onKeyDown(event) {
82
- const back = horizontal ? "ArrowLeft" : "ArrowUp";
83
- const forward = horizontal ? "ArrowRight" : "ArrowDown";
124
+ const back = group.horizontal ? "ArrowLeft" : "ArrowUp";
125
+ const forward = group.horizontal ? "ArrowRight" : "ArrowDown";
84
126
  if (event.key === back) {
85
127
  event.preventDefault();
86
- setSize(size() - KEYBOARD_STEP);
128
+ group.setSize(group.size() - KEYBOARD_STEP);
87
129
  }
88
130
  else if (event.key === forward) {
89
131
  event.preventDefault();
90
- setSize(size() + KEYBOARD_STEP);
132
+ group.setSize(group.size() + KEYBOARD_STEP);
91
133
  }
92
134
  else if (event.key === "Home") {
93
135
  event.preventDefault();
94
- setSize(min);
136
+ group.setSize(group.min);
95
137
  }
96
138
  else if (event.key === "End") {
97
139
  event.preventDefault();
98
- setSize(max);
140
+ group.setSize(group.max);
99
141
  }
100
142
  }
101
143
  return html `<div
102
- data-slot="resizable-group"
103
- id="${rootId}"
104
- data-direction="${horizontal ? "horizontal" : "vertical"}"
105
- class="${() => cn("flex h-full w-full", horizontal ? "flex-row" : "flex-col", read(props.class))}"
106
- >
107
- <div
108
- data-slot="resizable-panel"
109
- class="overflow-hidden"
110
- style="${() => `flex: 0 0 ${size()}%`}"
111
- >${slot(props.first)}</div>
112
- <div
113
- data-slot="resizable-handle"
114
- role="separator"
115
- tabindex="0"
116
- aria-orientation="${horizontal ? "vertical" : "horizontal"}"
117
- aria-valuemin="${min}"
118
- aria-valuemax="${max}"
119
- aria-valuenow="${() => Math.round(size())}"
120
- aria-label="Resize panes"
121
- class="${cn("bg-border relative flex shrink-0 items-center justify-center outline-none", "focus-visible:ring-ring focus-visible:ring-1 focus-visible:ring-offset-1", horizontal ? "w-px cursor-col-resize" : "h-px cursor-row-resize")}"
122
- @pointerdown="${onPointerDown}"
123
- @keydown="${onKeyDown}"
124
- >
125
- ${props.withHandle === true
144
+ data-slot="resizable-handle"
145
+ role="separator"
146
+ tabindex="0"
147
+ aria-orientation="${group.horizontal ? "vertical" : "horizontal"}"
148
+ aria-valuemin="${group.min}"
149
+ aria-valuemax="${group.max}"
150
+ aria-valuenow="${() => Math.round(group.size())}"
151
+ aria-label="Resize panes"
152
+ class="${() => cn("bg-border relative flex shrink-0 items-center justify-center outline-none", "focus-visible:ring-ring focus-visible:ring-1 focus-visible:ring-offset-1", group.horizontal ? "w-px cursor-col-resize" : "h-px cursor-row-resize", read(props.class))}"
153
+ @pointerdown="${onPointerDown}"
154
+ @keydown="${onKeyDown}"
155
+ >${props.withHandle === true
126
156
  ? html `<span
127
- class="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border"
128
- >${GripVerticalIcon({ class: "size-2.5" })}</span>`
129
- : null}
130
- </div>
131
- <div data-slot="resizable-panel" class="flex-1 overflow-hidden">${slot(props.second)}</div>
132
- </div>`;
157
+ class="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border"
158
+ >${GripVerticalIcon({ class: "size-2.5" })}</span>`
159
+ : null}</div>`;
133
160
  });
134
161
  function clamp(value, min, max) {
135
162
  return Math.min(Math.max(value, min), max);
@@ -1,9 +1,21 @@
1
1
  /**
2
2
  * Tabs — one panel visible at a time.
3
3
  *
4
+ * Tabs({ defaultValue: "account", children: () => html`
5
+ * ${TabsList({ children: html`
6
+ * ${TabsTrigger({ value: "account", children: "Account" })}
7
+ * ${TabsTrigger({ value: "password", children: "Password" })}
8
+ * ` })}
9
+ * ${TabsContent({ value: "account", children: "…" })}
10
+ * ${TabsContent({ value: "password", children: "…" })}
11
+ * ` })
12
+ *
4
13
  * The WAI-ARIA tabs pattern in full: the tab list is a single tab stop with
5
14
  * arrows moving between tabs, each tab points at its panel with
6
- * `aria-controls`, and each panel points back with `aria-labelledby`.
15
+ * `aria-controls`, and each panel points back with `aria-labelledby`. A
16
+ * trigger and its panel find each other through the shared `value` — the ids
17
+ * are minted once per value by the context, so neither has to know the other
18
+ * exists.
7
19
  *
8
20
  * Activation is automatic — moving to a tab selects it — which is the right
9
21
  * default when panels are already rendered and switching costs nothing. The
@@ -15,23 +27,49 @@
15
27
  * the accessibility tree, which is the behaviour `display: none` would give
16
28
  * without also removing them from the DOM.
17
29
  */
18
- import type { Child, Slot } from "../lib/children.js";
30
+ import type { Parts, Slot } from "../lib/children.js";
31
+ import { type VariantProps } from "../lib/cva.js";
19
32
  import { type Reactive } from "../lib/props.js";
20
- export interface TabItem {
21
- value: string;
22
- label: Child;
23
- content: Slot;
24
- disabled?: boolean;
25
- }
33
+ export declare const tabsListVariants: (props?: (import("../index.js").VariantSelection<{
34
+ variant: {
35
+ default: string;
36
+ line: string;
37
+ };
38
+ }> & import("../index.js").ClassOverrides) | undefined) => string;
39
+ export type TabsListVariants = VariantProps<typeof tabsListVariants>;
26
40
  export interface TabsProps {
27
- items: readonly TabItem[];
28
- /** Selected at first render. Defaults to the first enabled tab. */
41
+ /** Selected at first render. Defaults to the first trigger built. */
29
42
  defaultValue?: string;
43
+ value?: Reactive<string | undefined>;
30
44
  orientation?: "horizontal" | "vertical";
31
45
  /** Selecting follows focus. Default `true`. */
32
46
  activateOnFocus?: boolean;
33
47
  onValueChange?: (value: string) => void;
34
48
  class?: Reactive<string>;
35
- listClass?: Reactive<string>;
49
+ children?: Parts;
36
50
  }
37
51
  export declare const Tabs: (props?: TabsProps | undefined) => import("@c9up/aurora").TemplateResult;
52
+ export interface TabsListProps extends TabsListVariants {
53
+ children?: Slot;
54
+ class?: Reactive<string>;
55
+ }
56
+ /**
57
+ * The row of triggers, and the single tab stop that holds them.
58
+ *
59
+ * `rovingFocus` is wired here rather than in `Tabs`: it needs the element the
60
+ * tabs are actually in, and only this part has one.
61
+ */
62
+ export declare const TabsList: (props?: TabsListProps | undefined) => import("@c9up/aurora").TemplateResult;
63
+ export interface TabsTriggerProps {
64
+ value: string;
65
+ children?: Slot;
66
+ disabled?: boolean;
67
+ class?: Reactive<string>;
68
+ }
69
+ export declare const TabsTrigger: (props?: TabsTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
70
+ export interface TabsContentProps {
71
+ value: string;
72
+ children?: Slot;
73
+ class?: Reactive<string>;
74
+ }
75
+ export declare const TabsContent: (props?: TabsContentProps | undefined) => import("@c9up/aurora").TemplateResult;