@c9up/nebula 0.2.2 → 0.2.4
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 +8 -7
- package/dist/atoms/Avatar.d.ts +14 -0
- package/dist/atoms/Avatar.js +46 -8
- 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/cli/add.d.ts +2 -0
- package/dist/cli/add.js +4 -1
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.js +4 -1
- package/dist/cli/projectConfig.d.ts +16 -0
- package/dist/cli/projectConfig.js +61 -0
- package/dist/console/AddCommand.js +6 -1
- package/dist/console/DiffCommand.js +6 -1
- package/dist/lib/children.d.ts +13 -8
- package/dist/lib/children.js +5 -0
- package/dist/lib/icons.d.ts +8 -0
- package/dist/lib/icons.js +8 -0
- package/dist/lib/image.js +12 -1
- package/dist/molecules/Breadcrumb.d.ts +11 -2
- package/dist/molecules/Breadcrumb.js +2 -2
- package/dist/molecules/InputOTP.d.ts +14 -0
- package/dist/molecules/InputOTP.js +71 -28
- 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/index.d.ts +4 -3
- package/dist/molecules/index.js +2 -1
- 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/Combobox.d.ts +13 -0
- package/dist/organisms/Combobox.js +5 -2
- package/dist/organisms/Command.js +56 -8
- 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/Form.d.ts +15 -0
- package/dist/organisms/Form.js +10 -0
- package/dist/organisms/Questionnaire.d.ts +4 -0
- package/dist/organisms/Questionnaire.js +5 -2
- package/dist/organisms/Select.d.ts +25 -4
- package/dist/organisms/Select.js +116 -15
- package/dist/organisms/Sheet.d.ts +2 -0
- package/dist/organisms/Sheet.js +2 -1
- package/dist/organisms/Sidebar.d.ts +10 -2
- package/dist/organisms/Sidebar.js +62 -29
- package/dist/organisms/Sonner.d.ts +243 -0
- package/dist/organisms/Sonner.js +909 -0
- package/dist/organisms/Toaster.d.ts +11 -0
- package/dist/organisms/Toaster.js +34 -9
- package/dist/organisms/Tooltip.d.ts +4 -0
- package/dist/organisms/index.d.ts +8 -2
- package/dist/organisms/index.js +7 -1
- package/dist/primitives/dismissable.d.ts +11 -4
- package/dist/primitives/dismissable.js +8 -6
- package/dist/primitives/floating.d.ts +5 -1
- package/dist/primitives/floating.js +32 -2
- package/dist/primitives/menu.js +2 -1
- package/dist/primitives/modalSurface.js +70 -36
- package/dist/primitives/presence.js +8 -5
- package/dist/templates/SettingsLayout.d.ts +2 -0
- package/dist/templates/SettingsLayout.js +1 -1
- package/nebula.css +2 -2
- package/package.json +3 -3
- package/registry.json +26 -0
- package/src/atoms/Avatar.ts +54 -7
- package/src/atoms/Checkbox.ts +1 -1
- package/src/atoms/Input.ts +6 -0
- package/src/cli/add.ts +7 -1
- package/src/cli/diff.ts +7 -1
- package/src/cli/projectConfig.ts +71 -0
- package/src/console/AddCommand.ts +6 -1
- package/src/console/DiffCommand.ts +6 -1
- package/src/lib/children.ts +15 -7
- package/src/lib/icons.ts +28 -0
- package/src/lib/image.ts +13 -1
- package/src/molecules/Breadcrumb.ts +15 -4
- package/src/molecules/InputOTP.ts +88 -28
- package/src/molecules/Pagination.ts +50 -8
- package/src/molecules/PieceMap.ts +136 -0
- package/src/molecules/Resizable.ts +3 -1
- package/src/molecules/index.ts +17 -0
- package/src/organisms/Calendar.ts +16 -2
- package/src/organisms/Carousel.ts +17 -5
- package/src/organisms/Combobox.ts +18 -2
- package/src/organisms/Command.ts +66 -7
- 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/Form.ts +21 -0
- package/src/organisms/Questionnaire.ts +10 -2
- package/src/organisms/Select.ts +140 -16
- package/src/organisms/Sheet.ts +5 -1
- package/src/organisms/Sidebar.ts +62 -23
- package/src/organisms/Sonner.ts +1366 -0
- package/src/organisms/Toaster.ts +38 -10
- package/src/organisms/Tooltip.ts +4 -0
- package/src/organisms/index.ts +30 -1
- package/src/primitives/dismissable.ts +16 -8
- package/src/primitives/floating.ts +40 -3
- package/src/primitives/menu.ts +2 -1
- package/src/primitives/modalSurface.ts +77 -40
- package/src/primitives/presence.ts +12 -9
- package/src/templates/SettingsLayout.ts +3 -1
|
@@ -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,21 @@ export interface SelectProps {
|
|
|
56
65
|
children?: Parts;
|
|
57
66
|
}
|
|
58
67
|
export declare const Select: (props?: SelectProps | undefined) => TemplateResult;
|
|
68
|
+
/**
|
|
69
|
+
* `id`, `label`, `labelledBy` and `describedBy`, as on `Combobox`: upstream's
|
|
70
|
+
* trigger takes every button prop, and these are the ones that name it — a
|
|
71
|
+
* `FieldLabel` points its `for` at the `id`, and a `<label for>` names a
|
|
72
|
+
* `<button>`. Without them the 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
|
+
/** Id(s) of the element(s) that name it (`aria-labelledby`). */
|
|
81
|
+
labelledBy?: Reactive<string | undefined>;
|
|
82
|
+
describedBy?: Reactive<string | undefined>;
|
|
62
83
|
class?: Reactive<string>;
|
|
63
84
|
}
|
|
64
85
|
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,10 @@ 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-labelledby="${accessor(props.labelledBy, undefined)}"
|
|
345
|
+
aria-describedby="${accessor(props.describedBy, undefined)}"
|
|
248
346
|
role="combobox"
|
|
249
347
|
aria-haspopup="listbox"
|
|
250
348
|
aria-expanded="${() => (select.open() ? "true" : "false")}"
|
|
@@ -314,6 +412,9 @@ export const SelectItem = component((props) => {
|
|
|
314
412
|
(typeof children === "string" ? children : props.value),
|
|
315
413
|
disabled: props.disabled === true,
|
|
316
414
|
});
|
|
415
|
+
// On each mount, not once: the same option is mounted again every time the
|
|
416
|
+
// list opens or closes, and unmounted when a signal drops it.
|
|
417
|
+
onMount(() => select.attachItem(props.value));
|
|
317
418
|
const chosen = () => select.value() === props.value;
|
|
318
419
|
return html `<div
|
|
319
420
|
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>
|
|
@@ -35,8 +35,10 @@ import { type Reactive } from "../lib/props.js";
|
|
|
35
35
|
/**
|
|
36
36
|
* The cookie-backed open state, shared by every sidebar on the page.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
* the trigger may sit in a header that is not inside the
|
|
38
|
+
* In the browser, a module singleton and not a per-provider signal: the shell
|
|
39
|
+
* renders once and the trigger may sit in a header that is not inside the
|
|
40
|
+
* provider's subtree. On the server a module is shared by every request, so
|
|
41
|
+
* each call reads the cookie of the request being rendered instead.
|
|
40
42
|
*/
|
|
41
43
|
export declare function sidebarState(defaultOpen?: boolean): Signal<boolean>;
|
|
42
44
|
export declare function sidebarCollapsed(): boolean;
|
|
@@ -70,16 +72,22 @@ export interface SidebarProps {
|
|
|
70
72
|
collapsible?: "icon" | "offcanvas" | "none";
|
|
71
73
|
/** Announced as the navigation landmark's name. */
|
|
72
74
|
label?: string;
|
|
75
|
+
/** The close cross of the sheet it turns into on mobile. Default `"Close"`. */
|
|
76
|
+
closeLabel?: string;
|
|
73
77
|
class?: Reactive<string>;
|
|
74
78
|
}
|
|
75
79
|
export declare const Sidebar: (props?: SidebarProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
76
80
|
export interface SidebarTriggerProps {
|
|
77
81
|
/** Overrides the provider's toggle — for a trigger outside the shell. */
|
|
78
82
|
onToggle?: () => void;
|
|
83
|
+
/** The button's accessible name. Default `"Toggle sidebar"`. */
|
|
84
|
+
label?: string;
|
|
79
85
|
class?: Reactive<string>;
|
|
80
86
|
}
|
|
81
87
|
export declare const SidebarTrigger: (props?: SidebarTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
82
88
|
export interface SidebarRailProps {
|
|
89
|
+
/** Accessible name and tooltip. Default `"Toggle sidebar"`. */
|
|
90
|
+
label?: string;
|
|
83
91
|
class?: Reactive<string>;
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
@@ -45,24 +45,33 @@ const COOKIE_NAME = "nebula:sidebar";
|
|
|
45
45
|
const COOKIE_MAX_AGE_DAYS = 365;
|
|
46
46
|
const MOBILE_BREAKPOINT = 768;
|
|
47
47
|
let sharedOpen;
|
|
48
|
+
function openFromCookie(defaultOpen) {
|
|
49
|
+
return cookieState(COOKIE_NAME, defaultOpen, booleanCookie, {
|
|
50
|
+
path: "/",
|
|
51
|
+
maxAge: COOKIE_MAX_AGE_DAYS * 24 * 60 * 60,
|
|
52
|
+
sameSite: "lax",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
48
55
|
/**
|
|
49
56
|
* The cookie-backed open state, shared by every sidebar on the page.
|
|
50
57
|
*
|
|
51
|
-
*
|
|
52
|
-
* the trigger may sit in a header that is not inside the
|
|
58
|
+
* In the browser, a module singleton and not a per-provider signal: the shell
|
|
59
|
+
* renders once and the trigger may sit in a header that is not inside the
|
|
60
|
+
* provider's subtree. On the server a module is shared by every request, so
|
|
61
|
+
* each call reads the cookie of the request being rendered instead.
|
|
53
62
|
*/
|
|
54
63
|
export function sidebarState(defaultOpen = true) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
sameSite: "lax",
|
|
59
|
-
});
|
|
64
|
+
if (typeof document === "undefined")
|
|
65
|
+
return openFromCookie(defaultOpen);
|
|
66
|
+
sharedOpen ??= openFromCookie(defaultOpen);
|
|
60
67
|
return sharedOpen;
|
|
61
68
|
}
|
|
62
69
|
export function sidebarCollapsed() {
|
|
63
70
|
return !sidebarState()();
|
|
64
71
|
}
|
|
65
72
|
const SidebarContext = createContext("SidebarProvider");
|
|
73
|
+
/** The same provider, for the parts that also work outside one. */
|
|
74
|
+
const NearestSidebar = createContext("SidebarProvider", null);
|
|
66
75
|
/**
|
|
67
76
|
* The sidebar's state, from inside it.
|
|
68
77
|
*
|
|
@@ -109,13 +118,14 @@ export const SidebarProvider = component((props) => {
|
|
|
109
118
|
const controlled = read(props.open);
|
|
110
119
|
return controlled === undefined ? open() : controlled;
|
|
111
120
|
}
|
|
112
|
-
provide(SidebarContext, {
|
|
121
|
+
const api = provide(SidebarContext, {
|
|
113
122
|
open: current,
|
|
114
123
|
isMobile: () => mobile(),
|
|
115
124
|
state: () => (current() ? "expanded" : "collapsed"),
|
|
116
125
|
setOpen,
|
|
117
126
|
toggleSidebar,
|
|
118
127
|
});
|
|
128
|
+
provide(NearestSidebar, api);
|
|
119
129
|
return html `<div
|
|
120
130
|
data-slot="sidebar-wrapper"
|
|
121
131
|
class="${() => cn("flex min-h-svh w-full", read(props.class))}"
|
|
@@ -132,6 +142,7 @@ export const Sidebar = component((props) => {
|
|
|
132
142
|
onOpenChange: (next) => sidebar.setOpen(next),
|
|
133
143
|
children: () => SheetContent({
|
|
134
144
|
side,
|
|
145
|
+
closeLabel: props.closeLabel,
|
|
135
146
|
class: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
|
|
136
147
|
children: () => html `${SheetHeader({
|
|
137
148
|
class: "p-0",
|
|
@@ -149,7 +160,11 @@ export const Sidebar = component((props) => {
|
|
|
149
160
|
data-slot="sidebar"
|
|
150
161
|
data-state="${() => sidebar.state()}"
|
|
151
162
|
data-side="${side}"
|
|
152
|
-
data-collapsible="${
|
|
163
|
+
data-collapsible="${() =>
|
|
164
|
+
// The mode only once collapsed, as upstream: every
|
|
165
|
+
// `group-data-[collapsible=icon]:` class keys off it, and set
|
|
166
|
+
// while expanded it squeezed the full-width bar to icons.
|
|
167
|
+
sidebar.state() === "collapsed" ? collapsible : ""}"
|
|
153
168
|
aria-label="${props.label ?? "Sidebar"}"
|
|
154
169
|
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
170
|
? "w-(--sidebar-width,16rem)"
|
|
@@ -163,20 +178,33 @@ export const Sidebar = component((props) => {
|
|
|
163
178
|
class="flex h-full w-full flex-col"
|
|
164
179
|
>${body}</div></nav>`}</div>`;
|
|
165
180
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
/** The provider's toggle, or the page-wide state's outside a provider. */
|
|
182
|
+
function toggleNearest() {
|
|
183
|
+
const sidebar = inject(NearestSidebar);
|
|
184
|
+
if (sidebar !== null)
|
|
185
|
+
return () => sidebar.toggleSidebar();
|
|
186
|
+
return () => {
|
|
187
|
+
const open = sidebarState();
|
|
188
|
+
open(!open());
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export const SidebarTrigger = component((props) => {
|
|
192
|
+
const toggle = toggleNearest();
|
|
193
|
+
return Button({
|
|
194
|
+
variant: "ghost",
|
|
195
|
+
size: "icon",
|
|
196
|
+
label: props.label ?? "Toggle sidebar",
|
|
197
|
+
class: () => cn("size-7", read(props.class)),
|
|
198
|
+
onClick: () => {
|
|
199
|
+
if (props.onToggle !== undefined) {
|
|
200
|
+
props.onToggle();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
toggle();
|
|
204
|
+
},
|
|
205
|
+
children: PanelLeftIcon({ class: "size-4" }),
|
|
206
|
+
});
|
|
207
|
+
});
|
|
180
208
|
/**
|
|
181
209
|
* The hit area along the sidebar's edge that toggles it.
|
|
182
210
|
*
|
|
@@ -185,15 +213,18 @@ export const SidebarTrigger = component((props) => Button({
|
|
|
185
213
|
* keyboard has `cmd/ctrl + B` and the trigger, so a third stop on every page
|
|
186
214
|
* would be noise.
|
|
187
215
|
*/
|
|
188
|
-
export const SidebarRail = component((props) =>
|
|
216
|
+
export const SidebarRail = component((props) => {
|
|
217
|
+
const toggle = toggleNearest();
|
|
218
|
+
return html `<button
|
|
189
219
|
type="button"
|
|
190
220
|
data-slot="sidebar-rail"
|
|
191
|
-
aria-label="Toggle sidebar"
|
|
221
|
+
aria-label="${props.label ?? "Toggle sidebar"}"
|
|
192
222
|
tabindex="-1"
|
|
193
|
-
title="Toggle sidebar"
|
|
223
|
+
title="${props.label ?? "Toggle sidebar"}"
|
|
194
224
|
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
|
-
@click="${
|
|
196
|
-
></button
|
|
225
|
+
@click="${toggle}"
|
|
226
|
+
></button>`;
|
|
227
|
+
});
|
|
197
228
|
/** The page beside the sidebar. */
|
|
198
229
|
export const SidebarInset = component((props) => html `<main
|
|
199
230
|
data-slot="sidebar-inset"
|
|
@@ -247,6 +278,8 @@ export const sidebarMenuButtonVariants = cva("peer/menu-button ring-sidebar-ring
|
|
|
247
278
|
defaultVariants: { variant: "default", size: "default" },
|
|
248
279
|
});
|
|
249
280
|
export const SidebarMenuButton = component((props) => {
|
|
281
|
+
const sidebar = inject(NearestSidebar);
|
|
282
|
+
const collapsed = () => sidebar === null ? sidebarCollapsed() : sidebar.state() === "collapsed";
|
|
250
283
|
const merged = () => cn(sidebarMenuButtonVariants({
|
|
251
284
|
variant: props.variant,
|
|
252
285
|
size: props.size,
|
|
@@ -272,7 +305,7 @@ export const SidebarMenuButton = component((props) => {
|
|
|
272
305
|
// Wrapped once, not toggled: swapping the wrapper on collapse would remount
|
|
273
306
|
// the entry and lose focus mid-keyboard-navigation. The tooltip decides for
|
|
274
307
|
// itself whether to open, which is the cheaper half to make conditional.
|
|
275
|
-
return html `${() =>
|
|
308
|
+
return html `${() => collapsed()
|
|
276
309
|
? Tooltip({
|
|
277
310
|
children: () => html `${TooltipTrigger({
|
|
278
311
|
children: () => entry,
|