@c9up/nebula 0.2.1 → 0.2.3
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/README.md +11 -9
- package/dist/atoms/AccessibleIcon.d.ts +24 -0
- package/dist/atoms/AccessibleIcon.js +27 -0
- package/dist/atoms/Checkbox.d.ts +1 -1
- package/dist/atoms/Checkbox.js +1 -1
- package/dist/atoms/Input.d.ts +5 -0
- package/dist/atoms/Input.js +1 -0
- package/dist/atoms/VisuallyHidden.d.ts +30 -0
- package/dist/atoms/VisuallyHidden.js +35 -0
- package/dist/atoms/index.d.ts +2 -0
- package/dist/atoms/index.js +2 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +7 -4
- package/dist/lib/children.d.ts +13 -8
- package/dist/lib/children.js +5 -0
- package/dist/molecules/Breadcrumb.d.ts +11 -2
- package/dist/molecules/Breadcrumb.js +2 -2
- package/dist/molecules/InputOTP.d.ts +2 -0
- package/dist/molecules/InputOTP.js +3 -1
- package/dist/molecules/Pagination.d.ts +34 -2
- package/dist/molecules/Pagination.js +15 -6
- package/dist/molecules/PieceMap.d.ts +72 -0
- package/dist/molecules/PieceMap.js +78 -0
- package/dist/molecules/Resizable.d.ts +2 -0
- package/dist/molecules/Resizable.js +1 -1
- package/dist/molecules/Toolbar.d.ts +50 -0
- package/dist/molecules/Toolbar.js +70 -0
- package/dist/molecules/index.d.ts +10 -7
- package/dist/molecules/index.js +8 -5
- package/dist/organisms/Calendar.d.ts +13 -0
- package/dist/organisms/Calendar.js +2 -2
- package/dist/organisms/Carousel.d.ts +8 -0
- package/dist/organisms/Carousel.js +8 -5
- package/dist/organisms/DataTable.d.ts +23 -1
- package/dist/organisms/DataTable.js +57 -27
- package/dist/organisms/DatePicker.d.ts +7 -0
- package/dist/organisms/DatePicker.js +2 -1
- package/dist/organisms/DateRangePicker.d.ts +2 -0
- package/dist/organisms/DateRangePicker.js +2 -1
- package/dist/organisms/Dialog.d.ts +13 -3
- package/dist/organisms/Dialog.js +12 -5
- package/dist/organisms/Questionnaire.d.ts +4 -0
- package/dist/organisms/Questionnaire.js +5 -2
- package/dist/organisms/Select.d.ts +23 -4
- package/dist/organisms/Select.js +115 -15
- package/dist/organisms/Sheet.d.ts +2 -0
- package/dist/organisms/Sheet.js +2 -1
- package/dist/organisms/Sidebar.d.ts +6 -0
- package/dist/organisms/Sidebar.js +9 -4
- package/dist/organisms/Toaster.d.ts +80 -10
- package/dist/organisms/Toaster.js +152 -24
- package/dist/organisms/index.d.ts +3 -3
- package/dist/organisms/index.js +1 -1
- package/dist/primitives/direction.d.ts +38 -0
- package/dist/primitives/direction.js +57 -0
- package/dist/primitives/floating.js +25 -13
- package/dist/primitives/focusable.d.ts +10 -0
- package/dist/primitives/focusable.js +10 -1
- package/dist/primitives/index.d.ts +2 -1
- package/dist/primitives/index.js +2 -1
- package/dist/primitives/rovingFocus.js +14 -7
- package/dist/templates/SettingsLayout.d.ts +2 -0
- package/dist/templates/SettingsLayout.js +1 -1
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +76 -0
- package/src/atoms/AccessibleIcon.ts +39 -0
- package/src/atoms/Checkbox.ts +1 -1
- package/src/atoms/Input.ts +6 -0
- package/src/atoms/VisuallyHidden.ts +45 -0
- package/src/atoms/index.ts +8 -0
- package/src/index.ts +7 -4
- package/src/lib/children.ts +15 -7
- package/src/molecules/Breadcrumb.ts +15 -4
- package/src/molecules/InputOTP.ts +7 -1
- package/src/molecules/Pagination.ts +50 -8
- package/src/molecules/PieceMap.ts +136 -0
- package/src/molecules/Resizable.ts +3 -1
- package/src/molecules/Toolbar.ts +100 -0
- package/src/molecules/index.ts +28 -5
- package/src/organisms/Calendar.ts +16 -2
- package/src/organisms/Carousel.ts +17 -5
- package/src/organisms/DataTable.ts +95 -30
- package/src/organisms/DatePicker.ts +10 -2
- package/src/organisms/DateRangePicker.ts +4 -2
- package/src/organisms/Dialog.ts +17 -5
- package/src/organisms/Questionnaire.ts +10 -2
- package/src/organisms/Select.ts +137 -16
- package/src/organisms/Sheet.ts +5 -1
- package/src/organisms/Sidebar.ts +15 -4
- package/src/organisms/Toaster.ts +215 -37
- package/src/organisms/index.ts +9 -1
- package/src/primitives/direction.ts +61 -0
- package/src/primitives/floating.ts +29 -13
- package/src/primitives/focusable.ts +10 -1
- package/src/primitives/index.ts +7 -0
- package/src/primitives/rovingFocus.ts +18 -5
- package/src/templates/SettingsLayout.ts +3 -1
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
* wants — never the localised string on the button.
|
|
17
17
|
*/
|
|
18
18
|
import { type Reactive } from "../lib/props.js";
|
|
19
|
+
import { type CalendarLabels } from "./Calendar.js";
|
|
20
|
+
/** The calendar's words, plus the popup's accessible name. */
|
|
21
|
+
export interface DatePickerLabels extends CalendarLabels {
|
|
22
|
+
/** Default `"Choose a date"`, or `"Choose a date range"`. */
|
|
23
|
+
dialog: string;
|
|
24
|
+
}
|
|
19
25
|
export interface DatePickerProps {
|
|
20
26
|
name?: string;
|
|
21
27
|
value?: Reactive<Date | undefined>;
|
|
@@ -26,6 +32,7 @@ export interface DatePickerProps {
|
|
|
26
32
|
disabled?: Reactive<boolean>;
|
|
27
33
|
invalid?: Reactive<boolean>;
|
|
28
34
|
locale?: string;
|
|
35
|
+
labels?: Partial<DatePickerLabels>;
|
|
29
36
|
class?: Reactive<string>;
|
|
30
37
|
onValueChange?: (date: Date) => void;
|
|
31
38
|
}
|
|
@@ -65,7 +65,7 @@ export const DatePicker = component((props) => {
|
|
|
65
65
|
data-slot="date-picker-content"
|
|
66
66
|
id="${contentId}"
|
|
67
67
|
role="dialog"
|
|
68
|
-
aria-label="Choose a date"
|
|
68
|
+
aria-label="${props.labels?.dialog ?? "Choose a date"}"
|
|
69
69
|
class="${cn("bg-popover text-popover-foreground z-50 rounded-md border p-0 shadow-md outline-none", zoomInOut)}"
|
|
70
70
|
>
|
|
71
71
|
${Calendar({
|
|
@@ -74,6 +74,7 @@ export const DatePicker = component((props) => {
|
|
|
74
74
|
min: props.min,
|
|
75
75
|
max: props.max,
|
|
76
76
|
locale: props.locale,
|
|
77
|
+
labels: props.labels,
|
|
77
78
|
onValueChange: choose,
|
|
78
79
|
})}
|
|
79
80
|
</div>`,
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { type Reactive } from "../lib/props.js";
|
|
18
18
|
import { type DateRange } from "./Calendar.js";
|
|
19
|
+
import { type DatePickerLabels } from "./DatePicker.js";
|
|
19
20
|
export interface DateRangePickerProps {
|
|
20
21
|
/** Base name for the hidden inputs — `"stay"` posts `stay_from` / `stay_to`. */
|
|
21
22
|
name?: string;
|
|
@@ -27,6 +28,7 @@ export interface DateRangePickerProps {
|
|
|
27
28
|
disabled?: Reactive<boolean>;
|
|
28
29
|
invalid?: Reactive<boolean>;
|
|
29
30
|
locale?: string;
|
|
31
|
+
labels?: Partial<DatePickerLabels>;
|
|
30
32
|
class?: Reactive<string>;
|
|
31
33
|
/** Fires on both clicks — `to` is absent after the first. */
|
|
32
34
|
onValueChange?: (range: DateRange) => void;
|
|
@@ -70,7 +70,7 @@ export const DateRangePicker = component((props) => {
|
|
|
70
70
|
data-slot="date-range-picker-content"
|
|
71
71
|
id="${contentId}"
|
|
72
72
|
role="dialog"
|
|
73
|
-
aria-label="Choose a date range"
|
|
73
|
+
aria-label="${props.labels?.dialog ?? "Choose a date range"}"
|
|
74
74
|
class="${cn("bg-popover text-popover-foreground z-50 rounded-md border p-0 shadow-md outline-none", zoomInOut)}"
|
|
75
75
|
>
|
|
76
76
|
${Calendar({
|
|
@@ -80,6 +80,7 @@ export const DateRangePicker = component((props) => {
|
|
|
80
80
|
min: props.min,
|
|
81
81
|
max: props.max,
|
|
82
82
|
locale: props.locale,
|
|
83
|
+
labels: props.labels,
|
|
83
84
|
onRangeChange: pick,
|
|
84
85
|
})}
|
|
85
86
|
</div>`,
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* Dialog({ children: () => html`
|
|
8
8
|
* ${DialogTrigger({ children: "Edit" })}
|
|
9
9
|
* ${DialogContent({ children: () => html`
|
|
10
|
-
* ${DialogHeader({ children:
|
|
10
|
+
* ${DialogHeader({ children: html`
|
|
11
11
|
* ${DialogTitle({ children: "Edit profile" })}
|
|
12
12
|
* ${DialogDescription({ children: "Change it." })}
|
|
13
13
|
* ` })}
|
|
14
|
-
* ${DialogFooter({ children:
|
|
14
|
+
* ${DialogFooter({ children: Button({ children: "Save" }) })}
|
|
15
15
|
* ` })}
|
|
16
16
|
* ` })
|
|
17
17
|
*
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
* with the title's id and a panel rendered first would have had nothing to
|
|
22
22
|
* point at.
|
|
23
23
|
*
|
|
24
|
+
* Hence `DialogHeader` gets a VALUE: it takes a `Slot`, which the renderer calls
|
|
25
|
+
* when the panel renders, and a `DialogTitle` built in there registers after
|
|
26
|
+
* the panel has looked for one — it renders, and the panel stays unnamed (see
|
|
27
|
+
* `Parts`). Content that changes goes inside the title, not around it.
|
|
28
|
+
*
|
|
24
29
|
* The `panel` callback matters more than it looks. The overlay's root spans
|
|
25
30
|
* the viewport so the backdrop can, which means containment has to be answered
|
|
26
31
|
* against the panel — check the root and every click on the page counts as
|
|
@@ -29,7 +34,8 @@
|
|
|
29
34
|
* `aria-labelledby` points at the title and `aria-describedby` at the
|
|
30
35
|
* description, so a screen reader announces what the dialog is for on open. A
|
|
31
36
|
* dialog with neither announces only "dialog", which is why a missing
|
|
32
|
-
* `DialogTitle` is warned about
|
|
37
|
+
* `DialogTitle` is warned about rather than tolerated — as Radix did through
|
|
38
|
+
* 1.1; 1.3 counts its titles and no longer warns.
|
|
33
39
|
*/
|
|
34
40
|
import { type TemplateResult } from "@c9up/aurora";
|
|
35
41
|
import type { Parts, Slot } from "../lib/children.js";
|
|
@@ -83,6 +89,8 @@ export interface DialogContentProps {
|
|
|
83
89
|
children?: Parts;
|
|
84
90
|
/** The corner cross. */
|
|
85
91
|
showCloseButton?: boolean;
|
|
92
|
+
/** The cross's accessible name. Default `"Close"`. */
|
|
93
|
+
closeLabel?: string;
|
|
86
94
|
/** A click outside closes. `false` for a decision that must be made. */
|
|
87
95
|
dismissOnOutside?: boolean;
|
|
88
96
|
/** Escape closes. `false` for the same reason. */
|
|
@@ -105,6 +113,8 @@ export declare const DialogHeader: (props?: DialogSectionProps | undefined) => T
|
|
|
105
113
|
export interface DialogFooterProps extends DialogSectionProps {
|
|
106
114
|
/** Append a "Close" button after the children, as upstream can. */
|
|
107
115
|
showCloseButton?: boolean;
|
|
116
|
+
/** That button's text. Default `"Close"`. */
|
|
117
|
+
closeLabel?: string;
|
|
108
118
|
}
|
|
109
119
|
export declare const DialogFooter: (props?: DialogFooterProps | undefined) => TemplateResult;
|
|
110
120
|
export interface DialogTitleProps {
|
package/dist/organisms/Dialog.js
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* Dialog({ children: () => html`
|
|
8
8
|
* ${DialogTrigger({ children: "Edit" })}
|
|
9
9
|
* ${DialogContent({ children: () => html`
|
|
10
|
-
* ${DialogHeader({ children:
|
|
10
|
+
* ${DialogHeader({ children: html`
|
|
11
11
|
* ${DialogTitle({ children: "Edit profile" })}
|
|
12
12
|
* ${DialogDescription({ children: "Change it." })}
|
|
13
13
|
* ` })}
|
|
14
|
-
* ${DialogFooter({ children:
|
|
14
|
+
* ${DialogFooter({ children: Button({ children: "Save" }) })}
|
|
15
15
|
* ` })}
|
|
16
16
|
* ` })
|
|
17
17
|
*
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
* with the title's id and a panel rendered first would have had nothing to
|
|
22
22
|
* point at.
|
|
23
23
|
*
|
|
24
|
+
* Hence `DialogHeader` gets a VALUE: it takes a `Slot`, which the renderer calls
|
|
25
|
+
* when the panel renders, and a `DialogTitle` built in there registers after
|
|
26
|
+
* the panel has looked for one — it renders, and the panel stays unnamed (see
|
|
27
|
+
* `Parts`). Content that changes goes inside the title, not around it.
|
|
28
|
+
*
|
|
24
29
|
* The `panel` callback matters more than it looks. The overlay's root spans
|
|
25
30
|
* the viewport so the backdrop can, which means containment has to be answered
|
|
26
31
|
* against the panel — check the root and every click on the page counts as
|
|
@@ -29,7 +34,8 @@
|
|
|
29
34
|
* `aria-labelledby` points at the title and `aria-describedby` at the
|
|
30
35
|
* description, so a screen reader announces what the dialog is for on open. A
|
|
31
36
|
* dialog with neither announces only "dialog", which is why a missing
|
|
32
|
-
* `DialogTitle` is warned about
|
|
37
|
+
* `DialogTitle` is warned about rather than tolerated — as Radix did through
|
|
38
|
+
* 1.1; 1.3 counts its titles and no longer warns.
|
|
33
39
|
*/
|
|
34
40
|
import { component, createContext, html, inject, onUnmount, provide, signal, } from "@c9up/aurora";
|
|
35
41
|
import { Button } from "../atoms/Button.js";
|
|
@@ -165,6 +171,7 @@ export const DialogContent = component((props) => {
|
|
|
165
171
|
dialog.register({
|
|
166
172
|
body,
|
|
167
173
|
showCloseButton: props.showCloseButton ?? true,
|
|
174
|
+
closeLabel: props.closeLabel ?? "Close",
|
|
168
175
|
dismissOnOutside: props.dismissOnOutside ?? true,
|
|
169
176
|
dismissOnEscape: props.dismissOnEscape ?? true,
|
|
170
177
|
class: props.class,
|
|
@@ -182,7 +189,7 @@ export const DialogFooter = component((props) => {
|
|
|
182
189
|
type="button"
|
|
183
190
|
data-slot="dialog-close"
|
|
184
191
|
@click="${() => dialog.setOpen(false)}"
|
|
185
|
-
>${Button({ variant: "outline", children: "Close" })}</button>`
|
|
192
|
+
>${Button({ variant: "outline", children: props.closeLabel ?? "Close" })}</button>`
|
|
186
193
|
: null;
|
|
187
194
|
return html `<div
|
|
188
195
|
data-slot="dialog-footer"
|
|
@@ -214,7 +221,7 @@ function renderSurface(registered, ids) {
|
|
|
214
221
|
data-slot="dialog-close"
|
|
215
222
|
class="${closeButtonClasses}"
|
|
216
223
|
@click="${() => ids.close()}"
|
|
217
|
-
>${XIcon({ class: "size-4" })}<span class="sr-only"
|
|
224
|
+
>${XIcon({ class: "size-4" })}<span class="sr-only">${registered.closeLabel}</span></button>`
|
|
218
225
|
: null;
|
|
219
226
|
return html `<div data-slot="dialog-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
|
|
220
227
|
<div data-slot="dialog-overlay" class="${dialogBackdropClasses}"></div>
|
|
@@ -66,6 +66,10 @@ export interface QuestionnaireProps {
|
|
|
66
66
|
nextLabel?: string;
|
|
67
67
|
skipLabel?: string;
|
|
68
68
|
submitLabel?: string;
|
|
69
|
+
/** The progress bar's accessible name. Default `"Questionnaire progress"`. */
|
|
70
|
+
progressLabel?: string;
|
|
71
|
+
/** The counter under the bar. Default `"Question 2 of 5"`. */
|
|
72
|
+
counterLabel?: (position: number, total: number) => string;
|
|
69
73
|
class?: Reactive<string>;
|
|
70
74
|
}
|
|
71
75
|
/** Has this question been answered at all? */
|
|
@@ -58,6 +58,9 @@ export function isAnswered(question, answer) {
|
|
|
58
58
|
return asSet(answer).length > 0;
|
|
59
59
|
return asValue(answer).trim() !== "";
|
|
60
60
|
}
|
|
61
|
+
function questionOf(position, total) {
|
|
62
|
+
return `Question ${position} of ${total}`;
|
|
63
|
+
}
|
|
61
64
|
export const Questionnaire = component((props) => {
|
|
62
65
|
const total = props.questions.length;
|
|
63
66
|
const step = signal(0);
|
|
@@ -123,13 +126,13 @@ export const Questionnaire = component((props) => {
|
|
|
123
126
|
${Progress({
|
|
124
127
|
value: () => step() + 1,
|
|
125
128
|
max: total,
|
|
126
|
-
label: "Questionnaire progress",
|
|
129
|
+
label: props.progressLabel ?? "Questionnaire progress",
|
|
127
130
|
})}
|
|
128
131
|
<p
|
|
129
132
|
id="${counterId}"
|
|
130
133
|
aria-live="polite"
|
|
131
134
|
class="text-muted-foreground text-xs tabular-nums"
|
|
132
|
-
>${() =>
|
|
135
|
+
>${() => (props.counterLabel ?? questionOf)(step() + 1, total)}</p>
|
|
133
136
|
</div>`}
|
|
134
137
|
|
|
135
138
|
${() => renderQuestion()}
|
|
@@ -19,10 +19,19 @@
|
|
|
19
19
|
* ` })}
|
|
20
20
|
* ` })
|
|
21
21
|
*
|
|
22
|
-
* The items REGISTER themselves as they are built
|
|
23
|
-
*
|
|
24
|
-
* the
|
|
25
|
-
*
|
|
22
|
+
* The items REGISTER themselves as they are built: what each one is called and
|
|
23
|
+
* whether it is disabled, by value. WHICH options exist and in what order is
|
|
24
|
+
* read from the mounted list, as Radix's collection reads it — so options built
|
|
25
|
+
* in an accessor follow a signal:
|
|
26
|
+
*
|
|
27
|
+
* SelectContent({ children: () => html`${() => roles().map((role) =>
|
|
28
|
+
* SelectItem({ value: role.id, children: role.name }))}` })
|
|
29
|
+
*
|
|
30
|
+
* Closed, the list is still mounted, outside the document, as Radix renders a
|
|
31
|
+
* closed select's content into a DocumentFragment: the options exist, so the
|
|
32
|
+
* trigger shows the chosen one's label and the keyboard can walk them. Focus
|
|
33
|
+
* stays on the trigger and only `aria-activedescendant` moves, so the walk is
|
|
34
|
+
* over those options, not over focusable elements.
|
|
26
35
|
*
|
|
27
36
|
* What a native `<select>` was doing for free, and all of which has to be put
|
|
28
37
|
* back by hand:
|
|
@@ -56,9 +65,19 @@ export interface SelectProps {
|
|
|
56
65
|
children?: Parts;
|
|
57
66
|
}
|
|
58
67
|
export declare const Select: (props?: SelectProps | undefined) => TemplateResult;
|
|
68
|
+
/**
|
|
69
|
+
* `id`, `label` and `describedBy` as on `Input`: upstream's trigger takes every
|
|
70
|
+
* button prop, and these are the ones that name it — a `FieldLabel` points its
|
|
71
|
+
* `for` at the `id`, and a `<label for>` names a `<button>`. Without them the
|
|
72
|
+
* combobox's only name was the value it showed.
|
|
73
|
+
*/
|
|
59
74
|
export interface SelectTriggerProps {
|
|
60
75
|
children?: Slot;
|
|
61
76
|
size?: "default" | "sm";
|
|
77
|
+
id?: string;
|
|
78
|
+
/** Accessible name (`aria-label`), for a select no `<label>` names. */
|
|
79
|
+
label?: Reactive<string | undefined>;
|
|
80
|
+
describedBy?: Reactive<string | undefined>;
|
|
62
81
|
class?: Reactive<string>;
|
|
63
82
|
}
|
|
64
83
|
export declare const SelectTrigger: (props?: SelectTriggerProps | undefined) => TemplateResult;
|
package/dist/organisms/Select.js
CHANGED
|
@@ -19,10 +19,19 @@
|
|
|
19
19
|
* ` })}
|
|
20
20
|
* ` })
|
|
21
21
|
*
|
|
22
|
-
* The items REGISTER themselves as they are built
|
|
23
|
-
*
|
|
24
|
-
* the
|
|
25
|
-
*
|
|
22
|
+
* The items REGISTER themselves as they are built: what each one is called and
|
|
23
|
+
* whether it is disabled, by value. WHICH options exist and in what order is
|
|
24
|
+
* read from the mounted list, as Radix's collection reads it — so options built
|
|
25
|
+
* in an accessor follow a signal:
|
|
26
|
+
*
|
|
27
|
+
* SelectContent({ children: () => html`${() => roles().map((role) =>
|
|
28
|
+
* SelectItem({ value: role.id, children: role.name }))}` })
|
|
29
|
+
*
|
|
30
|
+
* Closed, the list is still mounted, outside the document, as Radix renders a
|
|
31
|
+
* closed select's content into a DocumentFragment: the options exist, so the
|
|
32
|
+
* trigger shows the chosen one's label and the keyboard can walk them. Focus
|
|
33
|
+
* stays on the trigger and only `aria-activedescendant` moves, so the walk is
|
|
34
|
+
* over those options, not over focusable elements.
|
|
26
35
|
*
|
|
27
36
|
* What a native `<select>` was doing for free, and all of which has to be put
|
|
28
37
|
* back by hand:
|
|
@@ -38,13 +47,13 @@
|
|
|
38
47
|
* The panel is sized to the trigger and capped at the space available below
|
|
39
48
|
* it, so a hundred-option list scrolls rather than running off the screen.
|
|
40
49
|
*/
|
|
41
|
-
import { component, createContext, html, inject, onUnmount, provide, signal, } from "@c9up/aurora";
|
|
50
|
+
import { component, createContext, effect, html, inject, onMount, onUnmount, provide, render, signal, untrack, } from "@c9up/aurora";
|
|
42
51
|
import { slot } from "../lib/children.js";
|
|
43
52
|
import { cn } from "../lib/cn.js";
|
|
44
53
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "../lib/icons.js";
|
|
45
54
|
import { uid } from "../lib/id.js";
|
|
46
55
|
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
47
|
-
import { read, readOr } from "../lib/props.js";
|
|
56
|
+
import { accessor, read, readOr } from "../lib/props.js";
|
|
48
57
|
import { controllable } from "../primitives/controllable.js";
|
|
49
58
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
50
59
|
import { focusSilently } from "../primitives/focusable.js";
|
|
@@ -54,9 +63,25 @@ const itemClasses = "relative flex w-full cursor-default items-center gap-2 roun
|
|
|
54
63
|
const scrollButtonClasses = "flex cursor-default items-center justify-center py-1";
|
|
55
64
|
const SelectContext = createContext("Select");
|
|
56
65
|
export const Select = component((props) => {
|
|
57
|
-
|
|
66
|
+
let triggerId = uid("select-trigger");
|
|
58
67
|
const listId = uid("select-list");
|
|
59
|
-
|
|
68
|
+
/** What each value's option is called, latest registration first. */
|
|
69
|
+
const registry = new Map();
|
|
70
|
+
/** Moves whenever an option registers, so the chosen label follows. */
|
|
71
|
+
const revision = signal(0);
|
|
72
|
+
/** How many mounted lists hold each value's option. */
|
|
73
|
+
const attached = new Map();
|
|
74
|
+
/** Whether a list has been mounted at all — never, on the server. */
|
|
75
|
+
let mountedOnce = false;
|
|
76
|
+
// Untracked read: called while the accessor building an option runs, and
|
|
77
|
+
// reading the counter there would make that accessor re-run on every change.
|
|
78
|
+
const bump = () => {
|
|
79
|
+
revision(untrack(() => revision()) + 1);
|
|
80
|
+
};
|
|
81
|
+
/** The open panel, once it has rendered. */
|
|
82
|
+
let panel = null;
|
|
83
|
+
/** Where the list is mounted while closed — outside the document. */
|
|
84
|
+
let closedHost = null;
|
|
60
85
|
/** Per instance, not per module: two selects may offer the same value. */
|
|
61
86
|
const optionIds = new Map();
|
|
62
87
|
let content;
|
|
@@ -71,7 +96,24 @@ export const Select = component((props) => {
|
|
|
71
96
|
});
|
|
72
97
|
/** The option the keyboard is on. Distinct from the selected one. */
|
|
73
98
|
const active = signal(undefined);
|
|
74
|
-
|
|
99
|
+
/**
|
|
100
|
+
* The options the list holds now, in its order. Read from the mounted list,
|
|
101
|
+
* which is what drops an option a signal removed and places one it added;
|
|
102
|
+
* before anything is mounted (on the server), in registration order.
|
|
103
|
+
*/
|
|
104
|
+
function items() {
|
|
105
|
+
const root = open() && panel?.isConnected === true ? panel : closedHost;
|
|
106
|
+
if (root === null)
|
|
107
|
+
return [...registry.values()];
|
|
108
|
+
const out = [];
|
|
109
|
+
for (const element of root.querySelectorAll("[data-slot=select-item]")) {
|
|
110
|
+
const item = registry.get(element.dataset.value ?? "");
|
|
111
|
+
if (item !== undefined && item.id === element.id)
|
|
112
|
+
out.push(item);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
const enabled = () => items().filter((item) => !item.disabled);
|
|
75
117
|
function choose(value) {
|
|
76
118
|
selection.set(value);
|
|
77
119
|
active(value);
|
|
@@ -161,7 +203,11 @@ export const Select = component((props) => {
|
|
|
161
203
|
}
|
|
162
204
|
}
|
|
163
205
|
provide(SelectContext, {
|
|
164
|
-
|
|
206
|
+
claimTriggerId(id) {
|
|
207
|
+
if (id !== undefined)
|
|
208
|
+
triggerId = id;
|
|
209
|
+
return triggerId;
|
|
210
|
+
},
|
|
165
211
|
listId,
|
|
166
212
|
open: () => open(),
|
|
167
213
|
value: () => selection.current(),
|
|
@@ -169,7 +215,17 @@ export const Select = component((props) => {
|
|
|
169
215
|
disabled: () => readOr(props.disabled, false),
|
|
170
216
|
invalid: () => read(props.invalid) === true,
|
|
171
217
|
required: props.required === true,
|
|
172
|
-
chosenLabel: () =>
|
|
218
|
+
chosenLabel: () => {
|
|
219
|
+
revision();
|
|
220
|
+
const current = selection.current();
|
|
221
|
+
if (current === undefined)
|
|
222
|
+
return undefined;
|
|
223
|
+
// An option a signal removed keeps its registration, but not its
|
|
224
|
+
// place in a list: its label must not stay on the trigger.
|
|
225
|
+
if (mountedOnce && !attached.has(current))
|
|
226
|
+
return undefined;
|
|
227
|
+
return registry.get(current)?.textValue;
|
|
228
|
+
},
|
|
173
229
|
itemId(value) {
|
|
174
230
|
let id = optionIds.get(value);
|
|
175
231
|
if (id === undefined) {
|
|
@@ -186,7 +242,21 @@ export const Select = component((props) => {
|
|
|
186
242
|
setActive: (value) => active(value),
|
|
187
243
|
onTriggerKeyDown,
|
|
188
244
|
registerItem(item) {
|
|
189
|
-
|
|
245
|
+
registry.set(item.value, item);
|
|
246
|
+
bump();
|
|
247
|
+
},
|
|
248
|
+
attachItem(value) {
|
|
249
|
+
mountedOnce = true;
|
|
250
|
+
attached.set(value, (attached.get(value) ?? 0) + 1);
|
|
251
|
+
bump();
|
|
252
|
+
return () => {
|
|
253
|
+
const left = (attached.get(value) ?? 1) - 1;
|
|
254
|
+
if (left > 0)
|
|
255
|
+
attached.set(value, left);
|
|
256
|
+
else
|
|
257
|
+
attached.delete(value);
|
|
258
|
+
bump();
|
|
259
|
+
};
|
|
190
260
|
},
|
|
191
261
|
registerContent(registered) {
|
|
192
262
|
content = registered;
|
|
@@ -210,7 +280,32 @@ export const Select = component((props) => {
|
|
|
210
280
|
// Focus never enters the panel — the listbox pattern keeps it on the
|
|
211
281
|
// trigger — so nothing here traps or moves it.
|
|
212
282
|
content: () => renderList(registered, { listId, triggerId }),
|
|
213
|
-
onOpened:
|
|
283
|
+
onOpened: (element) => {
|
|
284
|
+
panel = element;
|
|
285
|
+
scrollActiveIntoView(element);
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
onMount(() => {
|
|
289
|
+
let unmountClosed = null;
|
|
290
|
+
const stop = effect(() => {
|
|
291
|
+
if (open()) {
|
|
292
|
+
unmountClosed?.();
|
|
293
|
+
unmountClosed = null;
|
|
294
|
+
closedHost = null;
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (unmountClosed !== null)
|
|
298
|
+
return;
|
|
299
|
+
const host = document.createElement("div");
|
|
300
|
+
// Untracked: what the options read belongs to their own bindings,
|
|
301
|
+
// not to this effect, which only follows `open`.
|
|
302
|
+
unmountClosed = untrack(() => render(html `${registered.body}`, host));
|
|
303
|
+
closedHost = host;
|
|
304
|
+
});
|
|
305
|
+
return () => {
|
|
306
|
+
stop();
|
|
307
|
+
unmountClosed?.();
|
|
308
|
+
};
|
|
214
309
|
});
|
|
215
310
|
}
|
|
216
311
|
/**
|
|
@@ -223,7 +318,7 @@ export const Select = component((props) => {
|
|
|
223
318
|
const current = active() ?? selection.current();
|
|
224
319
|
if (current === undefined)
|
|
225
320
|
return;
|
|
226
|
-
const id =
|
|
321
|
+
const id = registry.get(current)?.id;
|
|
227
322
|
if (id === undefined)
|
|
228
323
|
return;
|
|
229
324
|
panel
|
|
@@ -244,7 +339,9 @@ export const SelectTrigger = component((props) => {
|
|
|
244
339
|
return html `<button
|
|
245
340
|
type="button"
|
|
246
341
|
data-slot="select-trigger"
|
|
247
|
-
id="${select.
|
|
342
|
+
id="${select.claimTriggerId(props.id)}"
|
|
343
|
+
aria-label="${accessor(props.label, undefined)}"
|
|
344
|
+
aria-describedby="${accessor(props.describedBy, undefined)}"
|
|
248
345
|
role="combobox"
|
|
249
346
|
aria-haspopup="listbox"
|
|
250
347
|
aria-expanded="${() => (select.open() ? "true" : "false")}"
|
|
@@ -314,6 +411,9 @@ export const SelectItem = component((props) => {
|
|
|
314
411
|
(typeof children === "string" ? children : props.value),
|
|
315
412
|
disabled: props.disabled === true,
|
|
316
413
|
});
|
|
414
|
+
// On each mount, not once: the same option is mounted again every time the
|
|
415
|
+
// list opens or closes, and unmounted when a signal drops it.
|
|
416
|
+
onMount(() => select.attachItem(props.value));
|
|
317
417
|
const chosen = () => select.value() === props.value;
|
|
318
418
|
return html `<div
|
|
319
419
|
data-slot="select-item"
|
|
@@ -50,6 +50,8 @@ export interface SheetContentProps {
|
|
|
50
50
|
/** Which edge it comes from. Default `"right"`. */
|
|
51
51
|
side?: Side;
|
|
52
52
|
showCloseButton?: boolean;
|
|
53
|
+
/** The corner cross's accessible name. Default `"Close"`. */
|
|
54
|
+
closeLabel?: string;
|
|
53
55
|
class?: Reactive<string>;
|
|
54
56
|
}
|
|
55
57
|
/**
|
package/dist/organisms/Sheet.js
CHANGED
|
@@ -138,6 +138,7 @@ export const SheetContent = component((props) => {
|
|
|
138
138
|
body,
|
|
139
139
|
side: props.side ?? "right",
|
|
140
140
|
showCloseButton: props.showCloseButton ?? true,
|
|
141
|
+
closeLabel: props.closeLabel ?? "Close",
|
|
141
142
|
class: props.class,
|
|
142
143
|
});
|
|
143
144
|
return html ``;
|
|
@@ -175,7 +176,7 @@ function renderSurface(registered, ids) {
|
|
|
175
176
|
data-slot="sheet-close"
|
|
176
177
|
class="${closeButtonClasses}"
|
|
177
178
|
@click="${() => ids.close()}"
|
|
178
|
-
>${XIcon({ class: "size-4" })}<span class="sr-only"
|
|
179
|
+
>${XIcon({ class: "size-4" })}<span class="sr-only">${registered.closeLabel}</span></button>`
|
|
179
180
|
: null;
|
|
180
181
|
return html `<div data-slot="sheet-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
|
|
181
182
|
<div data-slot="sheet-overlay" class="${dialogBackdropClasses}"></div>
|
|
@@ -70,16 +70,22 @@ export interface SidebarProps {
|
|
|
70
70
|
collapsible?: "icon" | "offcanvas" | "none";
|
|
71
71
|
/** Announced as the navigation landmark's name. */
|
|
72
72
|
label?: string;
|
|
73
|
+
/** The close cross of the sheet it turns into on mobile. Default `"Close"`. */
|
|
74
|
+
closeLabel?: string;
|
|
73
75
|
class?: Reactive<string>;
|
|
74
76
|
}
|
|
75
77
|
export declare const Sidebar: (props?: SidebarProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
76
78
|
export interface SidebarTriggerProps {
|
|
77
79
|
/** Overrides the provider's toggle — for a trigger outside the shell. */
|
|
78
80
|
onToggle?: () => void;
|
|
81
|
+
/** The button's accessible name. Default `"Toggle sidebar"`. */
|
|
82
|
+
label?: string;
|
|
79
83
|
class?: Reactive<string>;
|
|
80
84
|
}
|
|
81
85
|
export declare const SidebarTrigger: (props?: SidebarTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
82
86
|
export interface SidebarRailProps {
|
|
87
|
+
/** Accessible name and tooltip. Default `"Toggle sidebar"`. */
|
|
88
|
+
label?: string;
|
|
83
89
|
class?: Reactive<string>;
|
|
84
90
|
}
|
|
85
91
|
/**
|
|
@@ -132,6 +132,7 @@ export const Sidebar = component((props) => {
|
|
|
132
132
|
onOpenChange: (next) => sidebar.setOpen(next),
|
|
133
133
|
children: () => SheetContent({
|
|
134
134
|
side,
|
|
135
|
+
closeLabel: props.closeLabel,
|
|
135
136
|
class: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
|
|
136
137
|
children: () => html `${SheetHeader({
|
|
137
138
|
class: "p-0",
|
|
@@ -149,7 +150,11 @@ export const Sidebar = component((props) => {
|
|
|
149
150
|
data-slot="sidebar"
|
|
150
151
|
data-state="${() => sidebar.state()}"
|
|
151
152
|
data-side="${side}"
|
|
152
|
-
data-collapsible="${
|
|
153
|
+
data-collapsible="${() =>
|
|
154
|
+
// The mode only once collapsed, as upstream: every
|
|
155
|
+
// `group-data-[collapsible=icon]:` class keys off it, and set
|
|
156
|
+
// while expanded it squeezed the full-width bar to icons.
|
|
157
|
+
sidebar.state() === "collapsed" ? collapsible : ""}"
|
|
153
158
|
aria-label="${props.label ?? "Sidebar"}"
|
|
154
159
|
class="${() => cn("group bg-sidebar text-sidebar-foreground h-svh shrink-0 overflow-hidden transition-[width] duration-200 ease-linear motion-reduce:transition-none", side === "left" ? "border-r" : "border-l", sidebar.open()
|
|
155
160
|
? "w-(--sidebar-width,16rem)"
|
|
@@ -166,7 +171,7 @@ export const Sidebar = component((props) => {
|
|
|
166
171
|
export const SidebarTrigger = component((props) => Button({
|
|
167
172
|
variant: "ghost",
|
|
168
173
|
size: "icon",
|
|
169
|
-
label: "Toggle sidebar",
|
|
174
|
+
label: props.label ?? "Toggle sidebar",
|
|
170
175
|
class: () => cn("size-7", read(props.class)),
|
|
171
176
|
onClick: () => {
|
|
172
177
|
if (props.onToggle !== undefined) {
|
|
@@ -188,9 +193,9 @@ export const SidebarTrigger = component((props) => Button({
|
|
|
188
193
|
export const SidebarRail = component((props) => html `<button
|
|
189
194
|
type="button"
|
|
190
195
|
data-slot="sidebar-rail"
|
|
191
|
-
aria-label="Toggle sidebar"
|
|
196
|
+
aria-label="${props.label ?? "Toggle sidebar"}"
|
|
192
197
|
tabindex="-1"
|
|
193
|
-
title="Toggle sidebar"
|
|
198
|
+
title="${props.label ?? "Toggle sidebar"}"
|
|
194
199
|
class="${() => cn("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex", read(props.class))}"
|
|
195
200
|
@click="${() => sidebarState()(!sidebarState()())}"
|
|
196
201
|
></button>`);
|