@c9up/nebula 0.1.9 → 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.
- package/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/lib/children.ts +31 -0
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- 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
|
-
*
|
|
25
|
+
* InputGroup — a control with things attached to it.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
-
*
|
|
54
|
+
* A button inside the group.
|
|
41
55
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* the group
|
|
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
|
|
48
|
-
export
|
|
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
|
-
|
|
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
|
-
*
|
|
21
|
+
* InputGroup — a control with things attached to it.
|
|
20
22
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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
|
|
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
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
next
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
119
|
-
${
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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;
|