@c9up/nebula 0.1.9 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/configure.d.ts +6 -0
- package/dist/configure.js +4 -22
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/id.d.ts +13 -29
- package/dist/lib/id.js +13 -39
- 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/dist/stubs.d.ts +13 -0
- package/dist/stubs.js +14 -0
- package/nebula.css +1 -1
- package/package.json +4 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/configure.ts +10 -23
- package/src/lib/children.ts +31 -0
- package/src/lib/id.ts +11 -39
- 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
- package/src/stubs.ts +16 -0
- package/stubs/config/nebula.stub +21 -0
package/dist/molecules/Field.js
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Field — a
|
|
2
|
+
* Field — a labelled control with its help text and its error.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Field({ ids, children: () => html`
|
|
5
|
+
* ${FieldLabel({ children: "Email" })}
|
|
6
|
+
* ${Input({ id: ids.control, describedBy: ids.describedBy })}
|
|
7
|
+
* ${FieldDescription({ children: "We never share it." })}
|
|
8
|
+
* ${FieldError({ children: error })}
|
|
9
|
+
* ` })
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* The ids are the whole point of the component. Upstream leaves them to the
|
|
12
|
+
* caller — `<FieldLabel htmlFor="x">` beside `<Input id="x">` — which works
|
|
13
|
+
* until the two drift. `fieldIds()` mints a matching set and `Field` shares it
|
|
14
|
+
* through context, so the label, the description and the error all point at
|
|
15
|
+
* the right thing without anyone repeating a string. A caller still needs the
|
|
16
|
+
* set for the CONTROL, which is why `fieldIds()` is exported and may be passed
|
|
17
|
+
* in; left out, the field mints its own.
|
|
12
18
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* error: () => errors.email,
|
|
18
|
-
* children: Input({ id: email.control, describedBy: email.describedBy, invalid: … }),
|
|
19
|
-
* })
|
|
20
|
-
*
|
|
21
|
-
* The error slot is reactive and empty-tolerant: passing `() => errors.email`
|
|
22
|
-
* renders nothing until there is something to render, so a field does not
|
|
23
|
-
* reserve a blank line for an error that has not happened.
|
|
19
|
+
* `describedBy` names the description AND the error unconditionally. A screen
|
|
20
|
+
* reader skips an id that resolves to nothing, so listing an absent error is
|
|
21
|
+
* harmless — whereas recomputing the attribute when an error appears means the
|
|
22
|
+
* control has to re-render, which Aurora does not do.
|
|
24
23
|
*/
|
|
25
|
-
import { component, html } from "@c9up/aurora";
|
|
26
|
-
import { Label } from "../atoms/Label.js";
|
|
24
|
+
import { component, createContext, html, inject, provide } from "@c9up/aurora";
|
|
27
25
|
import { slot } from "../lib/children.js";
|
|
28
26
|
import { cn } from "../lib/cn.js";
|
|
29
27
|
import { uid } from "../lib/id.js";
|
|
30
28
|
import { read } from "../lib/props.js";
|
|
31
29
|
import { styledDiv } from "../lib/styled.js";
|
|
32
|
-
/** Mint the id set for one field. Call once, in the component that owns it. */
|
|
33
30
|
export function fieldIds() {
|
|
34
31
|
const control = uid("field");
|
|
35
32
|
const description = `${control}-description`;
|
|
@@ -39,44 +36,98 @@ export function fieldIds() {
|
|
|
39
36
|
label: `${control}-label`,
|
|
40
37
|
description,
|
|
41
38
|
error,
|
|
42
|
-
// Both are named unconditionally. A screen reader skips an id that
|
|
43
|
-
// resolves to nothing, so listing an absent error is harmless — whereas
|
|
44
|
-
// recomputing the attribute when an error appears means the control has to
|
|
45
|
-
// re-render, which Aurora does not do.
|
|
46
39
|
describedBy: `${description} ${error}`,
|
|
47
40
|
};
|
|
48
41
|
}
|
|
42
|
+
const FieldContext = createContext("Field");
|
|
49
43
|
export const Field = component((props) => {
|
|
50
|
-
const
|
|
44
|
+
const ids = props.ids ?? fieldIds();
|
|
45
|
+
const orientation = props.orientation ?? "vertical";
|
|
46
|
+
provide(FieldContext, { ids, required: props.required === true });
|
|
51
47
|
return html `<div
|
|
52
48
|
data-slot="field"
|
|
49
|
+
data-orientation="${orientation}"
|
|
53
50
|
data-disabled="${() => (read(props.disabled) === true ? "true" : undefined)}"
|
|
54
|
-
class="${() => cn("group flex
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
51
|
+
class="${() => cn("group/field flex w-full gap-3 data-[invalid=true]:text-destructive", orientation === "horizontal"
|
|
52
|
+
? "flex-row items-center justify-between"
|
|
53
|
+
: "flex-col", read(props.class))}"
|
|
54
|
+
>${props.children?.()}</div>`;
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* The label.
|
|
58
|
+
*
|
|
59
|
+
* A `<label>` with `for`, not a `<div>`: clicking it focuses the control, and
|
|
60
|
+
* that is not something `aria-labelledby` gives you.
|
|
61
|
+
*/
|
|
62
|
+
export const FieldLabel = component((props) => {
|
|
63
|
+
const field = inject(FieldContext);
|
|
64
|
+
return html `<label
|
|
65
|
+
data-slot="field-label"
|
|
66
|
+
id="${field.ids.label}"
|
|
67
|
+
for="${field.ids.control}"
|
|
68
|
+
class="${() => cn("group/field-label peer/field-label flex w-fit gap-2 text-sm leading-snug font-medium select-none group-data-[disabled=true]/field:opacity-50", read(props.class))}"
|
|
69
|
+
>${slot(props.children)}${field.required
|
|
70
|
+
? html `<span aria-hidden="true" class="text-destructive">*</span>`
|
|
71
|
+
: null}</label>`;
|
|
72
|
+
});
|
|
73
|
+
/** A heading inside a field that is not the control's label. */
|
|
74
|
+
export const FieldTitle = component((props) => html `<div
|
|
75
|
+
data-slot="field-label"
|
|
76
|
+
class="${() => cn("flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50", read(props.class))}"
|
|
77
|
+
>${slot(props.children)}</div>`);
|
|
78
|
+
export const FieldDescription = component((props) => {
|
|
79
|
+
const field = inject(FieldContext);
|
|
80
|
+
return html `<p
|
|
81
|
+
data-slot="field-description"
|
|
82
|
+
id="${field.ids.description}"
|
|
83
|
+
class="${() => cn("text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance", read(props.class))}"
|
|
84
|
+
>${slot(props.children)}</p>`;
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* The validation message.
|
|
88
|
+
*
|
|
89
|
+
* Always in the DOM, `empty:hidden` rather than conditionally rendered: the id
|
|
90
|
+
* `describedBy` names has to resolve to something the moment an error appears,
|
|
91
|
+
* and a node added later is announced late or not at all.
|
|
92
|
+
*/
|
|
93
|
+
export const FieldError = component((props) => {
|
|
94
|
+
const field = inject(FieldContext);
|
|
95
|
+
return html `<p
|
|
96
|
+
data-slot="field-error"
|
|
97
|
+
id="${field.ids.error}"
|
|
98
|
+
role="alert"
|
|
99
|
+
class="${() => cn("text-destructive text-sm font-normal empty:hidden", read(props.class))}"
|
|
100
|
+
>${() => {
|
|
101
|
+
const many = read(props.errors);
|
|
102
|
+
if (many !== undefined && many.length > 0) {
|
|
103
|
+
return many.length === 1
|
|
104
|
+
? (many[0] ?? "")
|
|
105
|
+
: html `<ul class="ml-4 flex list-disc flex-col gap-1">${many.map((message) => html `<li>${message}</li>`)}</ul>`;
|
|
106
|
+
}
|
|
107
|
+
return read(props.children) ?? "";
|
|
108
|
+
}}</p>`;
|
|
80
109
|
});
|
|
81
|
-
|
|
82
|
-
export const
|
|
110
|
+
/** Several fields stacked, with the spacing upstream gives a form. */
|
|
111
|
+
export const FieldGroup = styledDiv("field-group", "group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4");
|
|
112
|
+
/** The text half of a horizontal field, beside its control. */
|
|
113
|
+
export const FieldContent = styledDiv("field-content", "group/field-content flex flex-1 flex-col gap-1.5 leading-snug");
|
|
114
|
+
/** A `<fieldset>`, for a group of fields that answer one question together. */
|
|
115
|
+
export const FieldSet = component((props) => html `<fieldset
|
|
116
|
+
data-slot="field-set"
|
|
117
|
+
class="${() => cn("flex flex-col gap-6", read(props.class))}"
|
|
118
|
+
>${slot(props.children)}</fieldset>`);
|
|
119
|
+
export const FieldLegend = component((props) => html `<legend
|
|
120
|
+
data-slot="field-legend"
|
|
121
|
+
data-variant="${props.variant ?? "legend"}"
|
|
122
|
+
class="${() => cn("mb-3 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base", read(props.class))}"
|
|
123
|
+
>${slot(props.children)}</legend>`);
|
|
124
|
+
export const FieldSeparator = component((props) => html `<div
|
|
125
|
+
data-slot="field-separator"
|
|
126
|
+
data-content="${props.children === undefined ? undefined : ""}"
|
|
127
|
+
class="${() => cn("relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2", read(props.class))}"
|
|
128
|
+
><span class="bg-border absolute inset-x-0 top-1/2 h-px"></span>${props.children === undefined
|
|
129
|
+
? null
|
|
130
|
+
: html `<span
|
|
131
|
+
data-slot="field-separator-content"
|
|
132
|
+
class="bg-background text-muted-foreground relative mx-auto block w-fit px-2"
|
|
133
|
+
>${slot(props.children)}</span>`}</div>`);
|
|
@@ -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>`);
|