@c9up/nebula 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/nebula.css +1 -1
- package/package.json +5 -4
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/lib/children.ts +31 -0
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- package/src/primitives/menuParts.ts +371 -0
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { component, html } from "@c9up/aurora";
|
|
15
15
|
import { buttonVariants } from "../atoms/Button.js";
|
|
16
|
+
import { slot } from "../lib/children.js";
|
|
16
17
|
import { cn } from "../lib/cn.js";
|
|
17
18
|
import { ChevronLeftIcon, ChevronRightIcon, MoreHorizontalIcon, } from "../lib/icons.js";
|
|
18
19
|
import { read } from "../lib/props.js";
|
|
@@ -57,88 +58,71 @@ function range(from, to) {
|
|
|
57
58
|
out.push(value);
|
|
58
59
|
return out;
|
|
59
60
|
}
|
|
60
|
-
export const Pagination = component((props) =>
|
|
61
|
-
const page = () => read(props.page) ?? 1;
|
|
62
|
-
const pageCount = () => Math.max(1, read(props.pageCount) ?? 1);
|
|
63
|
-
const go = (target) => (event) => {
|
|
64
|
-
if (props.onPageChange === undefined)
|
|
65
|
-
return;
|
|
66
|
-
// Only intercept when the caller wants callback-driven paging. With an
|
|
67
|
-
// `href` and no handler the link must navigate normally.
|
|
68
|
-
event.preventDefault();
|
|
69
|
-
props.onPageChange(Math.min(Math.max(target, 1), pageCount()));
|
|
70
|
-
};
|
|
71
|
-
return html `<nav
|
|
61
|
+
export const Pagination = component((props) => html `<nav
|
|
72
62
|
data-slot="pagination"
|
|
73
63
|
role="navigation"
|
|
74
64
|
aria-label="pagination"
|
|
75
65
|
class="${() => cn("mx-auto flex w-full justify-center", read(props.class))}"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
onClick: go(page() - 1),
|
|
85
|
-
size: "default",
|
|
86
|
-
extra: "gap-1 px-2.5 sm:pl-2.5",
|
|
87
|
-
})}
|
|
88
|
-
</li>
|
|
89
|
-
${() => pageWindow(page(), pageCount(), props.window ?? 7).map((entry, index) => entry === null
|
|
90
|
-
? html `<li aria-hidden="true">
|
|
91
|
-
<span class="flex size-9 items-center justify-center">
|
|
92
|
-
${MoreHorizontalIcon({ class: "size-4" })}
|
|
93
|
-
<span class="sr-only">More pages</span>
|
|
94
|
-
</span>
|
|
95
|
-
</li>`
|
|
96
|
-
: html `<li>
|
|
97
|
-
${link({
|
|
98
|
-
label: String(entry),
|
|
99
|
-
ariaLabel: `Go to page ${entry}`,
|
|
100
|
-
href: props.href?.(entry),
|
|
101
|
-
current: entry === page(),
|
|
102
|
-
onClick: go(entry),
|
|
103
|
-
size: "icon",
|
|
104
|
-
key: index,
|
|
105
|
-
})}
|
|
106
|
-
</li>`)}
|
|
107
|
-
<li>
|
|
108
|
-
${link({
|
|
109
|
-
label: html `<span class="hidden sm:block">Next</span>${ChevronRightIcon({ class: "size-4" })}`,
|
|
110
|
-
ariaLabel: "Go to next page",
|
|
111
|
-
href: props.href?.(page() + 1),
|
|
112
|
-
disabled: () => page() >= pageCount(),
|
|
113
|
-
onClick: go(page() + 1),
|
|
114
|
-
size: "default",
|
|
115
|
-
extra: "gap-1 px-2.5 sm:pr-2.5",
|
|
116
|
-
})}
|
|
117
|
-
</li>
|
|
118
|
-
</ul>
|
|
119
|
-
</nav>`;
|
|
120
|
-
});
|
|
66
|
+
>${slot(props.children)}</nav>`);
|
|
67
|
+
export const PaginationContent = component((props) => html `<ul
|
|
68
|
+
data-slot="pagination-content"
|
|
69
|
+
class="${() => cn("flex flex-row items-center gap-1", read(props.class))}"
|
|
70
|
+
>${slot(props.children)}</ul>`);
|
|
71
|
+
export const PaginationItem = component((props) => html `<li
|
|
72
|
+
data-slot="pagination-item"
|
|
73
|
+
>${slot(props.children)}</li>`);
|
|
121
74
|
/**
|
|
122
75
|
* One page link.
|
|
123
76
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
77
|
+
* An `<a>` whether or not it has an `href`, because that is what upstream
|
|
78
|
+
* renders and what a pagination IS: a list of destinations. `onSelect`
|
|
79
|
+
* intercepts only when it is given — with an `href` and no handler the link
|
|
80
|
+
* must navigate normally, which is what makes a server-rendered pagination
|
|
81
|
+
* work with JavaScript off.
|
|
128
82
|
*/
|
|
129
|
-
|
|
130
|
-
const
|
|
83
|
+
export const PaginationLink = component((props) => {
|
|
84
|
+
const active = () => read(props.isActive) === true;
|
|
85
|
+
function onClick(event) {
|
|
86
|
+
if (read(props.disabled) === true) {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (props.onSelect === undefined)
|
|
91
|
+
return;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
props.onSelect(event);
|
|
94
|
+
}
|
|
131
95
|
return html `<a
|
|
132
96
|
data-slot="pagination-link"
|
|
133
|
-
href="${
|
|
134
|
-
aria-
|
|
135
|
-
aria-
|
|
136
|
-
aria-disabled="${() => (disabled
|
|
137
|
-
|
|
97
|
+
href="${props.href}"
|
|
98
|
+
aria-current="${() => (active() ? "page" : undefined)}"
|
|
99
|
+
aria-label="${props["aria-label"]}"
|
|
100
|
+
aria-disabled="${() => (read(props.disabled) === true ? "true" : undefined)}"
|
|
101
|
+
data-active="${() => (active() ? "true" : "false")}"
|
|
138
102
|
class="${() => cn(buttonVariants({
|
|
139
|
-
variant:
|
|
140
|
-
size:
|
|
141
|
-
}),
|
|
142
|
-
@click="${
|
|
143
|
-
>${
|
|
144
|
-
}
|
|
103
|
+
variant: active() ? "outline" : "ghost",
|
|
104
|
+
size: props.size ?? "icon",
|
|
105
|
+
}), read(props.disabled) === true ? "pointer-events-none opacity-50" : "", read(props.class))}"
|
|
106
|
+
@click="${onClick}"
|
|
107
|
+
>${slot(props.children)}</a>`;
|
|
108
|
+
});
|
|
109
|
+
export const PaginationPrevious = component((props) => PaginationLink({
|
|
110
|
+
...props,
|
|
111
|
+
size: "default",
|
|
112
|
+
"aria-label": "Go to previous page",
|
|
113
|
+
class: () => cn("gap-1 px-2.5 sm:pl-2.5", read(props.class)),
|
|
114
|
+
children: html `${ChevronLeftIcon({})}<span class="hidden sm:block">Previous</span>`,
|
|
115
|
+
}));
|
|
116
|
+
export const PaginationNext = component((props) => PaginationLink({
|
|
117
|
+
...props,
|
|
118
|
+
size: "default",
|
|
119
|
+
"aria-label": "Go to next page",
|
|
120
|
+
class: () => cn("gap-1 px-2.5 sm:pr-2.5", read(props.class)),
|
|
121
|
+
children: html `<span class="hidden sm:block">Next</span>${ChevronRightIcon({})}`,
|
|
122
|
+
}));
|
|
123
|
+
/** Stands in for the pages that did not fit — see `pageWindow`. */
|
|
124
|
+
export const PaginationEllipsis = component((props) => html `<span
|
|
125
|
+
data-slot="pagination-ellipsis"
|
|
126
|
+
aria-hidden="true"
|
|
127
|
+
class="${() => cn("flex size-9 items-center justify-center", read(props.class))}"
|
|
128
|
+
>${MoreHorizontalIcon({ class: "size-4" })}<span class="sr-only">More pages</span></span>`);
|
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RadioGroup —
|
|
2
|
+
* RadioGroup — one choice from a set.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* styling freedom while the behaviour stays the browser's.
|
|
4
|
+
* RadioGroup({ name: "plan", children: () => html`
|
|
5
|
+
* ${RadioGroupItem({ value: "free", children: "Free" })}
|
|
6
|
+
* ${RadioGroupItem({ value: "pro", children: "Pro", description: "…" })}
|
|
7
|
+
* ` })
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* A real `<input type="radio">` per item, sharing a `name`. That is what makes
|
|
10
|
+
* the browser treat them as one group: arrow keys move between them, exactly
|
|
11
|
+
* one can be checked, and the control posts with a plain HTML form — none of
|
|
12
|
+
* which a `div` with `role="radio"` gets without reimplementing it.
|
|
13
|
+
*
|
|
14
|
+
* NAMED DEVIATION — upstream renders a `button` with `role="radio"`, because
|
|
15
|
+
* Radix needs one element it fully controls. Everything above is what that
|
|
16
|
+
* costs, so nebula keeps the native input and styles it with `appearance-none`.
|
|
17
|
+
* The `data-slot` names and the indicator are upstream's.
|
|
12
18
|
*/
|
|
13
|
-
import type {
|
|
19
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
14
20
|
import { type Reactive } from "../lib/props.js";
|
|
15
|
-
export interface RadioOption {
|
|
16
|
-
value: string;
|
|
17
|
-
label: Child;
|
|
18
|
-
description?: Child;
|
|
19
|
-
disabled?: boolean;
|
|
20
|
-
}
|
|
21
21
|
export interface RadioGroupProps {
|
|
22
22
|
/** Shared `name`, which is what makes the browser treat these as one group. */
|
|
23
23
|
name: string;
|
|
24
|
-
options: readonly RadioOption[];
|
|
25
24
|
value?: Reactive<string | undefined>;
|
|
26
25
|
defaultValue?: string;
|
|
27
26
|
disabled?: Reactive<boolean>;
|
|
28
27
|
orientation?: "vertical" | "horizontal";
|
|
29
|
-
class?: Reactive<string>;
|
|
30
28
|
onValueChange?: (value: string) => void;
|
|
29
|
+
class?: Reactive<string>;
|
|
30
|
+
children?: Parts;
|
|
31
31
|
}
|
|
32
32
|
export declare const RadioGroup: (props?: RadioGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
33
|
+
export interface RadioGroupItemProps {
|
|
34
|
+
value: string;
|
|
35
|
+
children?: Slot;
|
|
36
|
+
description?: Slot;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
class?: Reactive<string>;
|
|
39
|
+
}
|
|
40
|
+
export declare const RadioGroupItem: (props?: RadioGroupItemProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -1,65 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RadioGroup —
|
|
2
|
+
* RadioGroup — one choice from a set.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* styling freedom while the behaviour stays the browser's.
|
|
4
|
+
* RadioGroup({ name: "plan", children: () => html`
|
|
5
|
+
* ${RadioGroupItem({ value: "free", children: "Free" })}
|
|
6
|
+
* ${RadioGroupItem({ value: "pro", children: "Pro", description: "…" })}
|
|
7
|
+
* ` })
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* A real `<input type="radio">` per item, sharing a `name`. That is what makes
|
|
10
|
+
* the browser treat them as one group: arrow keys move between them, exactly
|
|
11
|
+
* one can be checked, and the control posts with a plain HTML form — none of
|
|
12
|
+
* which a `div` with `role="radio"` gets without reimplementing it.
|
|
13
|
+
*
|
|
14
|
+
* NAMED DEVIATION — upstream renders a `button` with `role="radio"`, because
|
|
15
|
+
* Radix needs one element it fully controls. Everything above is what that
|
|
16
|
+
* costs, so nebula keeps the native input and styles it with `appearance-none`.
|
|
17
|
+
* The `data-slot` names and the indicator are upstream's.
|
|
12
18
|
*/
|
|
13
|
-
import { component, html } from "@c9up/aurora";
|
|
19
|
+
import { component, createContext, html, inject, provide } from "@c9up/aurora";
|
|
20
|
+
import { slot } from "../lib/children.js";
|
|
14
21
|
import { cn } from "../lib/cn.js";
|
|
15
22
|
import { uid } from "../lib/id.js";
|
|
16
23
|
import { read, readOr } from "../lib/props.js";
|
|
17
|
-
const radioClasses = "peer
|
|
24
|
+
const radioClasses = "peer border-input dark:bg-input/30 checked:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aspect-square size-4 shrink-0 appearance-none rounded-full border bg-transparent shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
|
|
25
|
+
const RadioGroupContext = createContext("RadioGroup");
|
|
18
26
|
export const RadioGroup = component((props) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
provide(RadioGroupContext, {
|
|
28
|
+
name: props.name,
|
|
29
|
+
selected: () => {
|
|
30
|
+
const controlled = read(props.value);
|
|
31
|
+
return controlled === undefined ? props.defaultValue : controlled;
|
|
32
|
+
},
|
|
33
|
+
disabled: () => readOr(props.disabled, false),
|
|
34
|
+
choose: (value) => props.onValueChange?.(value),
|
|
35
|
+
});
|
|
23
36
|
return html `<div
|
|
24
|
-
role="radiogroup"
|
|
25
37
|
data-slot="radio-group"
|
|
38
|
+
role="radiogroup"
|
|
26
39
|
aria-orientation="${props.orientation ?? "vertical"}"
|
|
27
40
|
class="${() => cn("grid gap-3", props.orientation === "horizontal" ? "grid-flow-col auto-cols-max" : "", read(props.class))}"
|
|
28
|
-
|
|
29
|
-
${props.options.map((option) => renderOption(option, props, selected))}
|
|
30
|
-
</div>`;
|
|
41
|
+
>${props.children?.()}</div>`;
|
|
31
42
|
});
|
|
32
|
-
|
|
43
|
+
export const RadioGroupItem = component((props) => {
|
|
44
|
+
const group = inject(RadioGroupContext);
|
|
33
45
|
const id = uid("radio");
|
|
34
|
-
const descriptionId =
|
|
35
|
-
return html `<div class="flex items-start gap-3"
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
const descriptionId = props.description === undefined ? undefined : uid("radio-description");
|
|
47
|
+
return html `<div class="flex items-start gap-3"><span
|
|
48
|
+
class="relative flex size-4 shrink-0 items-center justify-center"
|
|
49
|
+
><input
|
|
38
50
|
type="radio"
|
|
39
51
|
data-slot="radio-group-item"
|
|
40
52
|
id="${id}"
|
|
41
|
-
name="${
|
|
42
|
-
value="${
|
|
53
|
+
name="${group.name}"
|
|
54
|
+
value="${props.value}"
|
|
43
55
|
aria-describedby="${descriptionId}"
|
|
44
|
-
?disabled="${() =>
|
|
45
|
-
.checked="${() => selected() ===
|
|
46
|
-
class="${radioClasses}"
|
|
47
|
-
@change="${() =>
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
?disabled="${() => props.disabled === true || group.disabled()}"
|
|
57
|
+
.checked="${() => group.selected() === props.value}"
|
|
58
|
+
class="${() => cn(radioClasses, read(props.class))}"
|
|
59
|
+
@change="${() => group.choose(props.value)}"
|
|
60
|
+
/><span
|
|
61
|
+
data-slot="radio-group-indicator"
|
|
50
62
|
class="bg-primary pointer-events-none absolute size-2 rounded-full opacity-0 transition-opacity peer-checked:opacity-100"
|
|
51
|
-
></span
|
|
52
|
-
</span>
|
|
53
|
-
<div class="grid gap-1 leading-none">
|
|
54
|
-
<label
|
|
63
|
+
></span></span><div class="grid gap-1 leading-none"><label
|
|
55
64
|
for="${id}"
|
|
56
65
|
class="text-sm leading-none font-medium select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50"
|
|
57
|
-
>${
|
|
58
|
-
${option.description === undefined
|
|
66
|
+
>${slot(props.children)}</label>${props.description === undefined
|
|
59
67
|
? null
|
|
60
|
-
: html `<p id="${descriptionId}" class="text-muted-foreground text-sm"
|
|
61
|
-
|
|
62
|
-
</p>`}
|
|
63
|
-
</div>
|
|
64
|
-
</div>`;
|
|
65
|
-
}
|
|
68
|
+
: html `<p id="${descriptionId}" class="text-muted-foreground text-sm">${slot(props.description)}</p>`}</div></div>`;
|
|
69
|
+
});
|
|
@@ -19,19 +19,44 @@
|
|
|
19
19
|
* move it. A resizable layout reachable only by dragging is unusable by
|
|
20
20
|
* keyboard, and this is the whole of what it takes to fix that.
|
|
21
21
|
*/
|
|
22
|
-
import {
|
|
22
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
23
23
|
import { type Reactive } from "../lib/props.js";
|
|
24
|
-
export interface
|
|
25
|
-
first?: Slot;
|
|
26
|
-
second?: Slot;
|
|
24
|
+
export interface ResizablePanelGroupProps {
|
|
27
25
|
direction?: "horizontal" | "vertical";
|
|
28
26
|
/** First pane's share at first render, in percent. Default `50`. */
|
|
29
27
|
defaultSize?: number;
|
|
30
28
|
minSize?: number;
|
|
31
29
|
maxSize?: number;
|
|
32
|
-
|
|
30
|
+
onResize?: (percent: number) => void;
|
|
31
|
+
class?: Reactive<string>;
|
|
32
|
+
children?: Parts;
|
|
33
|
+
}
|
|
34
|
+
export declare const ResizablePanelGroup: (props?: ResizablePanelGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
35
|
+
export interface ResizablePanelProps {
|
|
36
|
+
children?: Slot;
|
|
37
|
+
class?: Reactive<string>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One pane.
|
|
41
|
+
*
|
|
42
|
+
* NAMED DEVIATION — two panes, not n. Upstream's `react-resizable-panels`
|
|
43
|
+
* distributes a size array across any number of panels and persists it;
|
|
44
|
+
* `ResizablePanelGroup` here holds ONE split, so the first panel takes the
|
|
45
|
+
* share and the second takes the rest. The parts are upstream's so a layout
|
|
46
|
+
* written against them reads the same; a third panel would simply have no
|
|
47
|
+
* share of its own.
|
|
48
|
+
*/
|
|
49
|
+
export declare const ResizablePanel: (props?: ResizablePanelProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
50
|
+
export interface ResizableHandleProps {
|
|
51
|
+
/** Show the grip dots. */
|
|
33
52
|
withHandle?: boolean;
|
|
34
53
|
class?: Reactive<string>;
|
|
35
|
-
onResize?: (percent: number) => void;
|
|
36
54
|
}
|
|
37
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The divider.
|
|
57
|
+
*
|
|
58
|
+
* `role="separator"` with `aria-valuenow`, and it takes focus: the arrows,
|
|
59
|
+
* Home and End move it. A drag handle that only answers to a pointer is not
|
|
60
|
+
* reachable at all for a keyboard user, and there is no other way to resize.
|
|
61
|
+
*/
|
|
62
|
+
export declare const ResizableHandle: (props?: ResizableHandleProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -19,40 +19,82 @@
|
|
|
19
19
|
* move it. A resizable layout reachable only by dragging is unusable by
|
|
20
20
|
* keyboard, and this is the whole of what it takes to fix that.
|
|
21
21
|
*/
|
|
22
|
-
import { component, html, signal } from "@c9up/aurora";
|
|
22
|
+
import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
|
|
23
23
|
import { slot } from "../lib/children.js";
|
|
24
24
|
import { cn } from "../lib/cn.js";
|
|
25
25
|
import { GripVerticalIcon } from "../lib/icons.js";
|
|
26
26
|
import { uid } from "../lib/id.js";
|
|
27
27
|
import { read } from "../lib/props.js";
|
|
28
28
|
const KEYBOARD_STEP = 5;
|
|
29
|
-
|
|
29
|
+
const ResizableContext = createContext("ResizablePanelGroup");
|
|
30
|
+
export const ResizablePanelGroup = component((props) => {
|
|
30
31
|
const horizontal = props.direction !== "vertical";
|
|
31
32
|
const min = props.minSize ?? 10;
|
|
32
33
|
const max = props.maxSize ?? 90;
|
|
33
34
|
const size = signal(clamp(props.defaultSize ?? 50, min, max));
|
|
34
35
|
const rootId = uid("resizable");
|
|
36
|
+
let panels = 0;
|
|
35
37
|
function setSize(percent) {
|
|
36
38
|
const next = clamp(percent, min, max);
|
|
37
39
|
size(next);
|
|
38
40
|
props.onResize?.(next);
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
provide(ResizableContext, {
|
|
43
|
+
rootId,
|
|
44
|
+
horizontal,
|
|
45
|
+
min,
|
|
46
|
+
max,
|
|
47
|
+
size: () => size(),
|
|
48
|
+
setSize,
|
|
49
|
+
claimPanel() {
|
|
50
|
+
panels += 1;
|
|
51
|
+
return panels;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return html `<div
|
|
55
|
+
data-slot="resizable-panel-group"
|
|
56
|
+
id="${rootId}"
|
|
57
|
+
data-direction="${horizontal ? "horizontal" : "vertical"}"
|
|
58
|
+
class="${() => cn("flex h-full w-full", horizontal ? "flex-row" : "flex-col", read(props.class))}"
|
|
59
|
+
>${props.children?.()}</div>`;
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* One pane.
|
|
63
|
+
*
|
|
64
|
+
* NAMED DEVIATION — two panes, not n. Upstream's `react-resizable-panels`
|
|
65
|
+
* distributes a size array across any number of panels and persists it;
|
|
66
|
+
* `ResizablePanelGroup` here holds ONE split, so the first panel takes the
|
|
67
|
+
* share and the second takes the rest. The parts are upstream's so a layout
|
|
68
|
+
* written against them reads the same; a third panel would simply have no
|
|
69
|
+
* share of its own.
|
|
70
|
+
*/
|
|
71
|
+
export const ResizablePanel = component((props) => {
|
|
72
|
+
const group = inject(ResizableContext);
|
|
73
|
+
const first = group.claimPanel() === 1;
|
|
74
|
+
return html `<div
|
|
75
|
+
data-slot="resizable-panel"
|
|
76
|
+
class="${() => cn("overflow-hidden", first ? "" : "flex-1", read(props.class))}"
|
|
77
|
+
style="${() => (first ? `flex: 0 0 ${group.size()}%` : "")}"
|
|
78
|
+
>${slot(props.children)}</div>`;
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* The divider.
|
|
82
|
+
*
|
|
83
|
+
* `role="separator"` with `aria-valuenow`, and it takes focus: the arrows,
|
|
84
|
+
* Home and End move it. A drag handle that only answers to a pointer is not
|
|
85
|
+
* reachable at all for a keyboard user, and there is no other way to resize.
|
|
86
|
+
*/
|
|
87
|
+
export const ResizableHandle = component((props) => {
|
|
88
|
+
const group = inject(ResizableContext);
|
|
47
89
|
function percentAt(event) {
|
|
48
|
-
const root = document.getElementById(rootId);
|
|
90
|
+
const root = document.getElementById(group.rootId);
|
|
49
91
|
if (root === null)
|
|
50
92
|
return null;
|
|
51
93
|
const rect = root.getBoundingClientRect();
|
|
52
|
-
const span = horizontal ? rect.width : rect.height;
|
|
94
|
+
const span = group.horizontal ? rect.width : rect.height;
|
|
53
95
|
if (span === 0)
|
|
54
96
|
return null;
|
|
55
|
-
const offset = horizontal
|
|
97
|
+
const offset = group.horizontal
|
|
56
98
|
? event.clientX - rect.left
|
|
57
99
|
: event.clientY - rect.top;
|
|
58
100
|
return (offset / span) * 100;
|
|
@@ -66,7 +108,7 @@ export const Resizable = component((props) => {
|
|
|
66
108
|
const onMove = (move) => {
|
|
67
109
|
const percent = percentAt(move);
|
|
68
110
|
if (percent !== null)
|
|
69
|
-
setSize(percent);
|
|
111
|
+
group.setSize(percent);
|
|
70
112
|
};
|
|
71
113
|
const onUp = () => {
|
|
72
114
|
target.releasePointerCapture(event.pointerId);
|
|
@@ -79,57 +121,42 @@ export const Resizable = component((props) => {
|
|
|
79
121
|
target.addEventListener("pointercancel", onUp);
|
|
80
122
|
}
|
|
81
123
|
function onKeyDown(event) {
|
|
82
|
-
const back = horizontal ? "ArrowLeft" : "ArrowUp";
|
|
83
|
-
const forward = horizontal ? "ArrowRight" : "ArrowDown";
|
|
124
|
+
const back = group.horizontal ? "ArrowLeft" : "ArrowUp";
|
|
125
|
+
const forward = group.horizontal ? "ArrowRight" : "ArrowDown";
|
|
84
126
|
if (event.key === back) {
|
|
85
127
|
event.preventDefault();
|
|
86
|
-
setSize(size() - KEYBOARD_STEP);
|
|
128
|
+
group.setSize(group.size() - KEYBOARD_STEP);
|
|
87
129
|
}
|
|
88
130
|
else if (event.key === forward) {
|
|
89
131
|
event.preventDefault();
|
|
90
|
-
setSize(size() + KEYBOARD_STEP);
|
|
132
|
+
group.setSize(group.size() + KEYBOARD_STEP);
|
|
91
133
|
}
|
|
92
134
|
else if (event.key === "Home") {
|
|
93
135
|
event.preventDefault();
|
|
94
|
-
setSize(min);
|
|
136
|
+
group.setSize(group.min);
|
|
95
137
|
}
|
|
96
138
|
else if (event.key === "End") {
|
|
97
139
|
event.preventDefault();
|
|
98
|
-
setSize(max);
|
|
140
|
+
group.setSize(group.max);
|
|
99
141
|
}
|
|
100
142
|
}
|
|
101
143
|
return html `<div
|
|
102
|
-
data-slot="resizable-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
role="separator"
|
|
115
|
-
tabindex="0"
|
|
116
|
-
aria-orientation="${horizontal ? "vertical" : "horizontal"}"
|
|
117
|
-
aria-valuemin="${min}"
|
|
118
|
-
aria-valuemax="${max}"
|
|
119
|
-
aria-valuenow="${() => Math.round(size())}"
|
|
120
|
-
aria-label="Resize panes"
|
|
121
|
-
class="${cn("bg-border relative flex shrink-0 items-center justify-center outline-none", "focus-visible:ring-ring focus-visible:ring-1 focus-visible:ring-offset-1", horizontal ? "w-px cursor-col-resize" : "h-px cursor-row-resize")}"
|
|
122
|
-
@pointerdown="${onPointerDown}"
|
|
123
|
-
@keydown="${onKeyDown}"
|
|
124
|
-
>
|
|
125
|
-
${props.withHandle === true
|
|
144
|
+
data-slot="resizable-handle"
|
|
145
|
+
role="separator"
|
|
146
|
+
tabindex="0"
|
|
147
|
+
aria-orientation="${group.horizontal ? "vertical" : "horizontal"}"
|
|
148
|
+
aria-valuemin="${group.min}"
|
|
149
|
+
aria-valuemax="${group.max}"
|
|
150
|
+
aria-valuenow="${() => Math.round(group.size())}"
|
|
151
|
+
aria-label="Resize panes"
|
|
152
|
+
class="${() => cn("bg-border relative flex shrink-0 items-center justify-center outline-none", "focus-visible:ring-ring focus-visible:ring-1 focus-visible:ring-offset-1", group.horizontal ? "w-px cursor-col-resize" : "h-px cursor-row-resize", read(props.class))}"
|
|
153
|
+
@pointerdown="${onPointerDown}"
|
|
154
|
+
@keydown="${onKeyDown}"
|
|
155
|
+
>${props.withHandle === true
|
|
126
156
|
? html `<span
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
: null}
|
|
130
|
-
</div>
|
|
131
|
-
<div data-slot="resizable-panel" class="flex-1 overflow-hidden">${slot(props.second)}</div>
|
|
132
|
-
</div>`;
|
|
157
|
+
class="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border"
|
|
158
|
+
>${GripVerticalIcon({ class: "size-2.5" })}</span>`
|
|
159
|
+
: null}</div>`;
|
|
133
160
|
});
|
|
134
161
|
function clamp(value, min, max) {
|
|
135
162
|
return Math.min(Math.max(value, min), max);
|
package/dist/molecules/Tabs.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tabs — one panel visible at a time.
|
|
3
3
|
*
|
|
4
|
+
* Tabs({ defaultValue: "account", children: () => html`
|
|
5
|
+
* ${TabsList({ children: html`
|
|
6
|
+
* ${TabsTrigger({ value: "account", children: "Account" })}
|
|
7
|
+
* ${TabsTrigger({ value: "password", children: "Password" })}
|
|
8
|
+
* ` })}
|
|
9
|
+
* ${TabsContent({ value: "account", children: "…" })}
|
|
10
|
+
* ${TabsContent({ value: "password", children: "…" })}
|
|
11
|
+
* ` })
|
|
12
|
+
*
|
|
4
13
|
* The WAI-ARIA tabs pattern in full: the tab list is a single tab stop with
|
|
5
14
|
* arrows moving between tabs, each tab points at its panel with
|
|
6
|
-
* `aria-controls`, and each panel points back with `aria-labelledby`.
|
|
15
|
+
* `aria-controls`, and each panel points back with `aria-labelledby`. A
|
|
16
|
+
* trigger and its panel find each other through the shared `value` — the ids
|
|
17
|
+
* are minted once per value by the context, so neither has to know the other
|
|
18
|
+
* exists.
|
|
7
19
|
*
|
|
8
20
|
* Activation is automatic — moving to a tab selects it — which is the right
|
|
9
21
|
* default when panels are already rendered and switching costs nothing. The
|
|
@@ -15,23 +27,49 @@
|
|
|
15
27
|
* the accessibility tree, which is the behaviour `display: none` would give
|
|
16
28
|
* without also removing them from the DOM.
|
|
17
29
|
*/
|
|
18
|
-
import type {
|
|
30
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
31
|
+
import { type VariantProps } from "../lib/cva.js";
|
|
19
32
|
import { type Reactive } from "../lib/props.js";
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
33
|
+
export declare const tabsListVariants: (props?: (import("../index.js").VariantSelection<{
|
|
34
|
+
variant: {
|
|
35
|
+
default: string;
|
|
36
|
+
line: string;
|
|
37
|
+
};
|
|
38
|
+
}> & import("../index.js").ClassOverrides) | undefined) => string;
|
|
39
|
+
export type TabsListVariants = VariantProps<typeof tabsListVariants>;
|
|
26
40
|
export interface TabsProps {
|
|
27
|
-
|
|
28
|
-
/** Selected at first render. Defaults to the first enabled tab. */
|
|
41
|
+
/** Selected at first render. Defaults to the first trigger built. */
|
|
29
42
|
defaultValue?: string;
|
|
43
|
+
value?: Reactive<string | undefined>;
|
|
30
44
|
orientation?: "horizontal" | "vertical";
|
|
31
45
|
/** Selecting follows focus. Default `true`. */
|
|
32
46
|
activateOnFocus?: boolean;
|
|
33
47
|
onValueChange?: (value: string) => void;
|
|
34
48
|
class?: Reactive<string>;
|
|
35
|
-
|
|
49
|
+
children?: Parts;
|
|
36
50
|
}
|
|
37
51
|
export declare const Tabs: (props?: TabsProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
52
|
+
export interface TabsListProps extends TabsListVariants {
|
|
53
|
+
children?: Slot;
|
|
54
|
+
class?: Reactive<string>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The row of triggers, and the single tab stop that holds them.
|
|
58
|
+
*
|
|
59
|
+
* `rovingFocus` is wired here rather than in `Tabs`: it needs the element the
|
|
60
|
+
* tabs are actually in, and only this part has one.
|
|
61
|
+
*/
|
|
62
|
+
export declare const TabsList: (props?: TabsListProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
63
|
+
export interface TabsTriggerProps {
|
|
64
|
+
value: string;
|
|
65
|
+
children?: Slot;
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
class?: Reactive<string>;
|
|
68
|
+
}
|
|
69
|
+
export declare const TabsTrigger: (props?: TabsTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
70
|
+
export interface TabsContentProps {
|
|
71
|
+
value: string;
|
|
72
|
+
children?: Slot;
|
|
73
|
+
class?: Reactive<string>;
|
|
74
|
+
}
|
|
75
|
+
export declare const TabsContent: (props?: TabsContentProps | undefined) => import("@c9up/aurora").TemplateResult;
|