@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
@@ -9,40 +9,58 @@
9
9
  * own `:focus-visible` would draw a ring around the middle third of a control
10
10
  * that visually reads as one box.
11
11
  */
12
+ import { type ButtonVariants } from "../atoms/Button.js";
12
13
  import { type InputProps } from "../atoms/Input.js";
14
+ import { type TextareaProps } from "../atoms/Textarea.js";
13
15
  import { type Slot } from "../lib/children.js";
14
16
  import { type Reactive } from "../lib/props.js";
17
+ export declare const inputGroupControlClasses = "flex-1 rounded-none border-0 bg-transparent px-0 shadow-none outline-none focus-visible:border-0 focus-visible:ring-0 disabled:opacity-100 dark:bg-transparent";
15
18
  export interface InputGroupProps {
16
19
  children?: Slot;
17
- /** Before the input — an icon or a static prefix. */
18
- leading?: Slot;
19
- /** After the input — a unit, a button, a spinner. */
20
- trailing?: Slot;
21
20
  invalid?: Reactive<boolean>;
22
21
  disabled?: Reactive<boolean>;
23
22
  class?: Reactive<string>;
24
23
  }
25
24
  /**
26
- * Strip the inner input of its own chrome.
25
+ * InputGroup — a control with things attached to it.
27
26
  *
28
- * Put these ON the input. The group cannot do it from the outside: a descendant
29
- * variant like `[&_input]:border-0` has to exist as a literal for Tailwind to
30
- * generate a rule for it, and building one by joining this string at runtime
31
- * produces class names no stylesheet ever defines — the input keeps its border
32
- * and draws a second one inside the group's, with nothing raised to say so.
33
- *
34
- * {@link InputGroupInput} applies them for you. This export is for a caller
35
- * passing a plain `<input>` instead.
27
+ * The border, the ring and the invalid state live on the GROUP, not on the
28
+ * control: an input with its own border inside a bordered group draws two
29
+ * rectangles, and a focus ring around the input alone leaves the addons
30
+ * outside it. So the control gives all of that up — that is the whole of
31
+ * `inputGroupControlClasses` — and `focus-within` moves the ring to the group.
36
32
  */
37
- export declare const inputGroupControlClasses = "flex-1 border-0 bg-transparent px-0 shadow-none outline-none focus-visible:border-0 focus-visible:ring-0 disabled:opacity-100";
38
33
  export declare const InputGroup: (props?: InputGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
34
+ export declare const InputGroupInput: (props?: InputProps | undefined) => import("@c9up/aurora").TemplateResult;
35
+ export declare const InputGroupTextarea: (props?: TextareaProps | undefined) => import("@c9up/aurora").TemplateResult;
36
+ export interface InputGroupAddonProps {
37
+ children?: Slot;
38
+ /** Which end it sits at. `block-*` stacks it above or below the control. */
39
+ align?: "inline-start" | "inline-end" | "block-start" | "block-end";
40
+ class?: Reactive<string>;
41
+ }
42
+ /** An icon, a unit, a button — anything beside the control. */
43
+ export declare const InputGroupAddon: (props?: InputGroupAddonProps | undefined) => import("@c9up/aurora").TemplateResult;
44
+ export interface InputGroupButtonProps {
45
+ children?: Slot;
46
+ type?: "button" | "submit" | "reset";
47
+ variant?: ButtonVariants["variant"];
48
+ size?: ButtonVariants["size"];
49
+ disabled?: Reactive<boolean>;
50
+ onClick?: (event: MouseEvent) => void;
51
+ class?: Reactive<string>;
52
+ }
39
53
  /**
40
- * The input that belongs inside an {@link InputGroup}.
54
+ * A button inside the group.
41
55
  *
42
- * Same component as {@link Input}, with the group's stripping applied first so
43
- * a caller's own `class` still wins. This is where the classes have to live:
44
- * the group carries the border and the ring, and the input has to bring none
45
- * of its own.
56
+ * `ghost` and the smallest size by default: a filled button the height of the
57
+ * field turns the group into two controls side by side, which is exactly what
58
+ * the group exists to avoid looking like.
46
59
  */
47
- export declare const InputGroupInput: (props?: InputProps | undefined) => import("@c9up/aurora").TemplateResult;
48
- export declare const InputGroupAddon: (props?: import("./Card.js").CardProps) => import("@c9up/aurora").TemplateResult;
60
+ export declare const InputGroupButton: (props?: InputGroupButtonProps | undefined) => import("@c9up/aurora").TemplateResult;
61
+ export interface InputGroupTextProps {
62
+ children?: Slot;
63
+ class?: Reactive<string>;
64
+ }
65
+ /** Static text in the group — a currency symbol, a domain suffix. */
66
+ export declare const InputGroupText: (props?: InputGroupTextProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -10,44 +10,60 @@
10
10
  * that visually reads as one box.
11
11
  */
12
12
  import { component, html } from "@c9up/aurora";
13
+ import { Button } from "../atoms/Button.js";
13
14
  import { Input } from "../atoms/Input.js";
15
+ import { Textarea } from "../atoms/Textarea.js";
14
16
  import { slot } from "../lib/children.js";
15
17
  import { cn } from "../lib/cn.js";
16
18
  import { read } from "../lib/props.js";
17
- import { styledDiv } from "../lib/styled.js";
19
+ export const inputGroupControlClasses = "flex-1 rounded-none border-0 bg-transparent px-0 shadow-none outline-none focus-visible:border-0 focus-visible:ring-0 disabled:opacity-100 dark:bg-transparent";
18
20
  /**
19
- * Strip the inner input of its own chrome.
21
+ * InputGroup — a control with things attached to it.
20
22
  *
21
- * Put these ON the input. The group cannot do it from the outside: a descendant
22
- * variant like `[&_input]:border-0` has to exist as a literal for Tailwind to
23
- * generate a rule for it, and building one by joining this string at runtime
24
- * produces class names no stylesheet ever defines — the input keeps its border
25
- * and draws a second one inside the group's, with nothing raised to say so.
26
- *
27
- * {@link InputGroupInput} applies them for you. This export is for a caller
28
- * passing a plain `<input>` instead.
23
+ * The border, the ring and the invalid state live on the GROUP, not on the
24
+ * control: an input with its own border inside a bordered group draws two
25
+ * rectangles, and a focus ring around the input alone leaves the addons
26
+ * outside it. So the control gives all of that up — that is the whole of
27
+ * `inputGroupControlClasses` — and `focus-within` moves the ring to the group.
29
28
  */
30
- export const inputGroupControlClasses = "flex-1 border-0 bg-transparent px-0 shadow-none outline-none focus-visible:border-0 focus-visible:ring-0 disabled:opacity-100";
31
- export const InputGroup = component((props) => {
32
- return html `<div
29
+ export const InputGroup = component((props) => html `<div
33
30
  data-slot="input-group"
34
31
  data-disabled="${() => (read(props.disabled) === true ? "" : undefined)}"
35
32
  aria-invalid="${() => (read(props.invalid) === true ? "true" : undefined)}"
36
- class="${() => cn("border-input dark:bg-input/30 flex h-9 w-full min-w-0 items-center gap-2 rounded-md border bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow]", "focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]", "aria-invalid:border-destructive aria-invalid:ring-destructive/20", "data-[disabled]:pointer-events-none data-[disabled]:opacity-50", read(props.class))}"
37
- >
38
- ${slot(props.leading)}${slot(props.children)}${slot(props.trailing)}
39
- </div>`;
40
- });
41
- /**
42
- * The input that belongs inside an {@link InputGroup}.
43
- *
44
- * Same component as {@link Input}, with the group's stripping applied first so
45
- * a caller's own `class` still wins. This is where the classes have to live:
46
- * the group carries the border and the ring, and the input has to bring none
47
- * of its own.
48
- */
33
+ class="${() => cn("group/input-group border-input dark:bg-input/30 relative flex h-9 w-full min-w-0 items-center gap-2 rounded-md border bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none", "focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]", "aria-invalid:border-destructive aria-invalid:ring-destructive/20", "data-[disabled]:pointer-events-none data-[disabled]:opacity-50", read(props.class))}"
34
+ >${slot(props.children)}</div>`);
49
35
  export const InputGroupInput = component((props) => Input({
50
36
  ...props,
51
37
  class: () => cn(inputGroupControlClasses, read(props.class)),
52
38
  }));
53
- export const InputGroupAddon = styledDiv("input-group-addon", "text-muted-foreground flex shrink-0 items-center gap-2 [&_svg:not([class*='size-'])]:size-4");
39
+ export const InputGroupTextarea = component((props) => Textarea({
40
+ ...props,
41
+ class: () => cn(inputGroupControlClasses, "resize-none py-3", read(props.class)),
42
+ }));
43
+ /** An icon, a unit, a button — anything beside the control. */
44
+ export const InputGroupAddon = component((props) => html `<div
45
+ data-slot="input-group-addon"
46
+ data-align="${props.align ?? "inline-start"}"
47
+ class="${() => cn("text-muted-foreground flex shrink-0 items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", read(props.class))}"
48
+ >${slot(props.children)}</div>`);
49
+ /**
50
+ * A button inside the group.
51
+ *
52
+ * `ghost` and the smallest size by default: a filled button the height of the
53
+ * field turns the group into two controls side by side, which is exactly what
54
+ * the group exists to avoid looking like.
55
+ */
56
+ export const InputGroupButton = component((props) => Button({
57
+ type: props.type ?? "button",
58
+ variant: props.variant ?? "ghost",
59
+ size: props.size ?? "sm",
60
+ disabled: props.disabled,
61
+ onClick: props.onClick,
62
+ class: () => cn("shadow-none", read(props.class)),
63
+ children: props.children,
64
+ }));
65
+ /** Static text in the group — a currency symbol, a domain suffix. */
66
+ export const InputGroupText = component((props) => html `<span
67
+ data-slot="input-group-text"
68
+ class="${() => cn("text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", read(props.class))}"
69
+ >${slot(props.children)}</span>`);
@@ -17,17 +17,40 @@
17
17
  * The joined value is mirrored into a hidden input so the control submits as
18
18
  * one field, rather than six.
19
19
  */
20
+ import type { Parts, Slot } from "../lib/children.js";
20
21
  import { type Reactive } from "../lib/props.js";
21
22
  export interface InputOTPProps {
22
- /** Number of boxes. Default `6`. */
23
+ /** Number of boxes. Default `6` — and it must match the slots built. */
23
24
  length?: number;
24
25
  name?: string;
25
26
  disabled?: Reactive<boolean>;
26
- /** Insert a visual gap after this many boxes. `3` gives `123 456`. */
27
- groupAfter?: number;
28
27
  class?: Reactive<string>;
29
28
  onValueChange?: (value: string) => void;
30
29
  /** Fired once every box is filled. */
31
30
  onComplete?: (value: string) => void;
31
+ children?: Parts;
32
32
  }
33
33
  export declare const InputOTP: (props?: InputOTPProps | undefined) => import("@c9up/aurora").TemplateResult;
34
+ export interface InputOTPGroupProps {
35
+ children?: Slot;
36
+ class?: Reactive<string>;
37
+ }
38
+ /** A run of boxes with no gap between them. */
39
+ export declare const InputOTPGroup: (props?: InputOTPGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
40
+ export interface InputOTPSlotProps {
41
+ class?: Reactive<string>;
42
+ }
43
+ /**
44
+ * One box.
45
+ *
46
+ * Claims its index as it is built, so the slots need no index prop and cannot
47
+ * be numbered wrongly. A real `<input>` per box rather than a single field
48
+ * with drawn cells: it is what gives each box its own caret, its own
49
+ * `autocomplete` and the one-time-code hint the platform fills from an SMS.
50
+ */
51
+ export declare const InputOTPSlot: (props?: InputOTPSlotProps | undefined) => import("@c9up/aurora").TemplateResult;
52
+ export interface InputOTPSeparatorProps {
53
+ class?: Reactive<string>;
54
+ }
55
+ /** The dash between two groups. Decorative — the boxes carry the labels. */
56
+ export declare const InputOTPSeparator: (props?: InputOTPSeparatorProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -17,15 +17,19 @@
17
17
  * The joined value is mirrored into a hidden input so the control submits as
18
18
  * one field, rather than six.
19
19
  */
20
- import { component, html, signal } from "@c9up/aurora";
20
+ import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
21
+ import { slot } from "../lib/children.js";
21
22
  import { cn } from "../lib/cn.js";
23
+ import { MinusIcon } from "../lib/icons.js";
22
24
  import { uid } from "../lib/id.js";
23
25
  import { read, readOr } from "../lib/props.js";
24
26
  const slotClasses = "border-input relative flex size-9 items-center justify-center border-y border-r text-center text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md focus:border-ring focus:ring-ring/50 focus:z-10 focus:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
27
+ const InputOTPContext = createContext("InputOTP");
25
28
  export const InputOTP = component((props) => {
26
29
  const length = props.length ?? 6;
27
30
  const groupId = uid("input-otp");
28
31
  const characters = signal(new Array(length).fill(""));
32
+ let claimed = 0;
29
33
  function boxes() {
30
34
  const root = document.getElementById(groupId);
31
35
  if (root === null)
@@ -54,87 +58,116 @@ export const InputOTP = component((props) => {
54
58
  next[index] = character;
55
59
  commit(next);
56
60
  }
57
- function onInput(index, event) {
58
- const target = event.target;
59
- if (!(target instanceof HTMLInputElement))
60
- return;
61
- // A box already holding a character receives the new one appended; keep
62
- // the last, which is what the user just typed.
63
- const typed = target.value.slice(-1);
64
- target.value = typed;
65
- write(index, typed);
66
- if (typed !== "" && index < length - 1)
67
- focusBox(index + 1);
68
- }
69
- function onKeyDown(index, event) {
70
- if (event.key === "Backspace") {
71
- if (characters()[index] === "" && index > 0) {
61
+ provide(InputOTPContext, {
62
+ length,
63
+ disabled: () => readOr(props.disabled, false),
64
+ claimSlot() {
65
+ const index = claimed;
66
+ claimed += 1;
67
+ return index;
68
+ },
69
+ onInput(index, event) {
70
+ const target = event.target;
71
+ if (!(target instanceof HTMLInputElement))
72
+ return;
73
+ // A box already holding a character receives the new one appended; keep
74
+ // the last, which is what the user just typed.
75
+ const typed = target.value.slice(-1);
76
+ target.value = typed;
77
+ write(index, typed);
78
+ if (typed !== "" && index < length - 1)
79
+ focusBox(index + 1);
80
+ },
81
+ onKeyDown(index, event) {
82
+ if (event.key === "Backspace") {
83
+ if (characters()[index] === "" && index > 0) {
84
+ event.preventDefault();
85
+ write(index - 1, "");
86
+ focusBox(index - 1);
87
+ }
88
+ return;
89
+ }
90
+ if (event.key === "ArrowLeft") {
72
91
  event.preventDefault();
73
- write(index - 1, "");
74
92
  focusBox(index - 1);
93
+ return;
75
94
  }
76
- return;
77
- }
78
- if (event.key === "ArrowLeft") {
79
- event.preventDefault();
80
- focusBox(index - 1);
81
- return;
82
- }
83
- if (event.key === "ArrowRight") {
95
+ if (event.key === "ArrowRight") {
96
+ event.preventDefault();
97
+ focusBox(index + 1);
98
+ }
99
+ },
100
+ onPaste(index, event) {
101
+ const pasted = event.clipboardData?.getData("text") ?? "";
102
+ if (pasted === "")
103
+ return;
84
104
  event.preventDefault();
85
- focusBox(index + 1);
86
- }
87
- }
88
- function onPaste(index, event) {
89
- const pasted = event.clipboardData?.getData("text") ?? "";
90
- if (pasted === "")
91
- return;
92
- event.preventDefault();
93
- const next = [...characters()];
94
- let cursor = index;
95
- for (const character of pasted) {
96
- if (cursor >= length)
97
- break;
98
- next[cursor] = character;
99
- cursor += 1;
100
- }
101
- commit(next);
102
- // Reflect into the DOM: the boxes are uncontrolled between keystrokes, so
103
- // writing the signal alone would leave the pasted characters invisible.
104
- const inputs = boxes();
105
- next.forEach((character, position) => {
106
- const input = inputs[position];
107
- if (input !== undefined)
108
- input.value = character;
109
- });
110
- focusBox(Math.min(cursor, length - 1));
111
- }
112
- const indices = Array.from({ length }, (_unused, index) => index);
105
+ const next = [...characters()];
106
+ let cursor = index;
107
+ for (const character of pasted) {
108
+ if (cursor >= length)
109
+ break;
110
+ next[cursor] = character;
111
+ cursor += 1;
112
+ }
113
+ commit(next);
114
+ // Reflect into the DOM: the boxes are uncontrolled between keystrokes,
115
+ // so writing the signal alone would leave the pasted characters
116
+ // invisible.
117
+ const inputs = boxes();
118
+ next.forEach((character, position) => {
119
+ const input = inputs[position];
120
+ if (input !== undefined)
121
+ input.value = character;
122
+ });
123
+ focusBox(Math.min(cursor, length - 1));
124
+ },
125
+ });
113
126
  return html `<div
114
127
  data-slot="input-otp"
115
128
  id="${groupId}"
116
129
  class="${() => cn("flex items-center gap-2", read(props.class))}"
117
- >
118
- <div class="flex items-center">
119
- ${indices.map((index) => html `${props.groupAfter !== undefined &&
120
- index > 0 &&
121
- index % props.groupAfter === 0
122
- ? html `<span aria-hidden="true" class="mx-1 text-muted-foreground">-</span>`
123
- : null}<input
124
- data-slot="input-otp-slot"
125
- data-otp-index="${index}"
126
- type="text"
127
- inputmode="numeric"
128
- autocomplete="${index === 0 ? "one-time-code" : "off"}"
129
- maxlength="1"
130
- aria-label="${`Character ${index + 1} of ${length}`}"
131
- ?disabled="${() => readOr(props.disabled, false)}"
132
- class="${slotClasses}"
133
- @input="${(event) => onInput(index, event)}"
134
- @keydown="${(event) => onKeyDown(index, event)}"
135
- @paste="${(event) => onPaste(index, event)}"
136
- />`)}
137
- </div>
138
- <input type="hidden" name="${props.name}" .value="${() => characters().join("")}" />
139
- </div>`;
130
+ >${props.children?.()}<input
131
+ type="hidden"
132
+ name="${props.name}"
133
+ .value="${() => characters().join("")}"
134
+ /></div>`;
135
+ });
136
+ /** A run of boxes with no gap between them. */
137
+ export const InputOTPGroup = component((props) => html `<div
138
+ data-slot="input-otp-group"
139
+ class="${() => cn("flex items-center", read(props.class))}"
140
+ >${slot(props.children)}</div>`);
141
+ /**
142
+ * One box.
143
+ *
144
+ * Claims its index as it is built, so the slots need no index prop and cannot
145
+ * be numbered wrongly. A real `<input>` per box rather than a single field
146
+ * with drawn cells: it is what gives each box its own caret, its own
147
+ * `autocomplete` and the one-time-code hint the platform fills from an SMS.
148
+ */
149
+ export const InputOTPSlot = component((props) => {
150
+ const otp = inject(InputOTPContext);
151
+ const index = otp.claimSlot();
152
+ return html `<input
153
+ data-slot="input-otp-slot"
154
+ data-otp-index="${index}"
155
+ type="text"
156
+ inputmode="numeric"
157
+ autocomplete="${index === 0 ? "one-time-code" : "off"}"
158
+ maxlength="1"
159
+ aria-label="${`Character ${index + 1} of ${otp.length}`}"
160
+ ?disabled="${() => otp.disabled()}"
161
+ class="${() => cn(slotClasses, read(props.class))}"
162
+ @input="${(event) => otp.onInput(index, event)}"
163
+ @keydown="${(event) => otp.onKeyDown(index, event)}"
164
+ @paste="${(event) => otp.onPaste(index, event)}"
165
+ />`;
140
166
  });
167
+ /** The dash between two groups. Decorative — the boxes carry the labels. */
168
+ export const InputOTPSeparator = component((props) => html `<div
169
+ data-slot="input-otp-separator"
170
+ role="separator"
171
+ aria-hidden="true"
172
+ class="${() => cn("text-muted-foreground mx-1", read(props.class))}"
173
+ >${MinusIcon({ class: "size-4" })}</div>`);
@@ -16,7 +16,7 @@
16
16
  * four unrelated things.
17
17
  */
18
18
  import { component, html } from "@c9up/aurora";
19
- import { Avatar } from "../atoms/Avatar.js";
19
+ import { Avatar, AvatarFallback, AvatarImage } from "../atoms/Avatar.js";
20
20
  import { slot } from "../lib/children.js";
21
21
  import { cn } from "../lib/cn.js";
22
22
  import { read } from "../lib/props.js";
@@ -39,10 +39,11 @@ export const Message = component((props) => {
39
39
  >
40
40
  ${hasAvatar
41
41
  ? Avatar({
42
- src: props.avatarSrc,
43
- alt: typeof props.author === "string" ? props.author : "",
44
- fallback: props.avatarFallback,
45
42
  class: "size-7 shrink-0",
43
+ children: () => html `${AvatarImage({
44
+ src: props.avatarSrc,
45
+ alt: typeof props.author === "string" ? props.author : "",
46
+ })}${AvatarFallback({ children: props.avatarFallback })}`,
46
47
  })
47
48
  : null}
48
49
  <div class="${cn("flex min-w-0 flex-1 flex-col gap-1", outgoing ? "items-end" : "items-start")}">
@@ -11,18 +11,8 @@
11
11
  * `aria-current="page"` marks the current page. Without it the only signal is
12
12
  * the highlight, which a screen-reader user does not get.
13
13
  */
14
+ import { type Slot } from "../lib/children.js";
14
15
  import { type Reactive } from "../lib/props.js";
15
- export interface PaginationProps {
16
- page: Reactive<number>;
17
- pageCount: Reactive<number>;
18
- /** How many numbered links to show, ellipses included. Default `7`. */
19
- window?: number;
20
- /** Build an href per page. Omit for a button-driven pagination. */
21
- href?: (page: number) => string;
22
- onPageChange?: (page: number) => void;
23
- class?: Reactive<string>;
24
- }
25
- /** `null` marks a gap that renders as an ellipsis. */
26
16
  export type PageSlot = number | null;
27
17
  /**
28
18
  * Which page numbers to show, at a fixed total width.
@@ -38,4 +28,39 @@ export type PageSlot = number | null;
38
28
  * for it. That is the case a naive implementation gets wrong.
39
29
  */
40
30
  export declare function pageWindow(page: number, pageCount: number, size?: number): readonly PageSlot[];
31
+ export interface PaginationProps {
32
+ children?: Slot;
33
+ class?: Reactive<string>;
34
+ }
41
35
  export declare const Pagination: (props?: PaginationProps | undefined) => import("@c9up/aurora").TemplateResult;
36
+ export declare const PaginationContent: (props?: PaginationProps | undefined) => import("@c9up/aurora").TemplateResult;
37
+ export declare const PaginationItem: (props?: PaginationProps | undefined) => import("@c9up/aurora").TemplateResult;
38
+ export interface PaginationLinkProps {
39
+ children?: Slot;
40
+ href?: string;
41
+ /** The page the user is on. Carries `aria-current="page"`. */
42
+ isActive?: Reactive<boolean>;
43
+ size?: "default" | "icon";
44
+ disabled?: Reactive<boolean>;
45
+ onSelect?: (event: MouseEvent) => void;
46
+ "aria-label"?: string;
47
+ class?: Reactive<string>;
48
+ }
49
+ /**
50
+ * One page link.
51
+ *
52
+ * An `<a>` whether or not it has an `href`, because that is what upstream
53
+ * renders and what a pagination IS: a list of destinations. `onSelect`
54
+ * intercepts only when it is given — with an `href` and no handler the link
55
+ * must navigate normally, which is what makes a server-rendered pagination
56
+ * work with JavaScript off.
57
+ */
58
+ export declare const PaginationLink: (props?: PaginationLinkProps | undefined) => import("@c9up/aurora").TemplateResult;
59
+ export type PaginationStepProps = Omit<PaginationLinkProps, "size" | "isActive" | "aria-label">;
60
+ export declare const PaginationPrevious: (props?: PaginationStepProps | undefined) => import("@c9up/aurora").TemplateResult;
61
+ export declare const PaginationNext: (props?: PaginationStepProps | undefined) => import("@c9up/aurora").TemplateResult;
62
+ export interface PaginationEllipsisProps {
63
+ class?: Reactive<string>;
64
+ }
65
+ /** Stands in for the pages that did not fit — see `pageWindow`. */
66
+ export declare const PaginationEllipsis: (props?: PaginationEllipsisProps | undefined) => import("@c9up/aurora").TemplateResult;