@c9up/nebula 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/lib/children.ts +31 -0
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- package/src/primitives/menuParts.ts +371 -0
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { component, html } from "@c9up/aurora";
|
|
16
16
|
import { buttonVariants } from "../atoms/Button.js";
|
|
17
|
-
import type
|
|
17
|
+
import { type Slot, slot } from "../lib/children.js";
|
|
18
18
|
import { cn } from "../lib/cn.js";
|
|
19
19
|
import {
|
|
20
20
|
ChevronLeftIcon,
|
|
@@ -23,18 +23,6 @@ import {
|
|
|
23
23
|
} from "../lib/icons.js";
|
|
24
24
|
import { type Reactive, read } from "../lib/props.js";
|
|
25
25
|
|
|
26
|
-
export interface PaginationProps {
|
|
27
|
-
page: Reactive<number>;
|
|
28
|
-
pageCount: Reactive<number>;
|
|
29
|
-
/** How many numbered links to show, ellipses included. Default `7`. */
|
|
30
|
-
window?: number;
|
|
31
|
-
/** Build an href per page. Omit for a button-driven pagination. */
|
|
32
|
-
href?: (page: number) => string;
|
|
33
|
-
onPageChange?: (page: number) => void;
|
|
34
|
-
class?: Reactive<string>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** `null` marks a gap that renders as an ellipsis. */
|
|
38
26
|
export type PageSlot = number | null;
|
|
39
27
|
|
|
40
28
|
/**
|
|
@@ -86,112 +74,119 @@ function range(from: number, to: number): number[] {
|
|
|
86
74
|
return out;
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
export
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const go = (target: number) => (event: MouseEvent) => {
|
|
94
|
-
if (props.onPageChange === undefined) return;
|
|
95
|
-
// Only intercept when the caller wants callback-driven paging. With an
|
|
96
|
-
// `href` and no handler the link must navigate normally.
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
props.onPageChange(Math.min(Math.max(target, 1), pageCount()));
|
|
99
|
-
};
|
|
77
|
+
export interface PaginationProps {
|
|
78
|
+
children?: Slot;
|
|
79
|
+
class?: Reactive<string>;
|
|
80
|
+
}
|
|
100
81
|
|
|
101
|
-
|
|
82
|
+
export const Pagination = component<PaginationProps>(
|
|
83
|
+
(props) => html`<nav
|
|
102
84
|
data-slot="pagination"
|
|
103
85
|
role="navigation"
|
|
104
86
|
aria-label="pagination"
|
|
105
87
|
class="${() => cn("mx-auto flex w-full justify-center", read(props.class))}"
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
(entry, index) =>
|
|
122
|
-
entry === null
|
|
123
|
-
? html`<li aria-hidden="true">
|
|
124
|
-
<span class="flex size-9 items-center justify-center">
|
|
125
|
-
${MoreHorizontalIcon({ class: "size-4" })}
|
|
126
|
-
<span class="sr-only">More pages</span>
|
|
127
|
-
</span>
|
|
128
|
-
</li>`
|
|
129
|
-
: html`<li>
|
|
130
|
-
${link({
|
|
131
|
-
label: String(entry),
|
|
132
|
-
ariaLabel: `Go to page ${entry}`,
|
|
133
|
-
href: props.href?.(entry),
|
|
134
|
-
current: entry === page(),
|
|
135
|
-
onClick: go(entry),
|
|
136
|
-
size: "icon",
|
|
137
|
-
key: index,
|
|
138
|
-
})}
|
|
139
|
-
</li>`,
|
|
140
|
-
)}
|
|
141
|
-
<li>
|
|
142
|
-
${link({
|
|
143
|
-
label: html`<span class="hidden sm:block">Next</span>${ChevronRightIcon({ class: "size-4" })}`,
|
|
144
|
-
ariaLabel: "Go to next page",
|
|
145
|
-
href: props.href?.(page() + 1),
|
|
146
|
-
disabled: () => page() >= pageCount(),
|
|
147
|
-
onClick: go(page() + 1),
|
|
148
|
-
size: "default",
|
|
149
|
-
extra: "gap-1 px-2.5 sm:pr-2.5",
|
|
150
|
-
})}
|
|
151
|
-
</li>
|
|
152
|
-
</ul>
|
|
153
|
-
</nav>`;
|
|
154
|
-
});
|
|
88
|
+
>${slot(props.children)}</nav>`,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export const PaginationContent = component<PaginationProps>(
|
|
92
|
+
(props) => html`<ul
|
|
93
|
+
data-slot="pagination-content"
|
|
94
|
+
class="${() => cn("flex flex-row items-center gap-1", read(props.class))}"
|
|
95
|
+
>${slot(props.children)}</ul>`,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
export const PaginationItem = component<PaginationProps>(
|
|
99
|
+
(props) => html`<li
|
|
100
|
+
data-slot="pagination-item"
|
|
101
|
+
>${slot(props.children)}</li>`,
|
|
102
|
+
);
|
|
155
103
|
|
|
156
|
-
interface
|
|
157
|
-
|
|
158
|
-
ariaLabel: string;
|
|
104
|
+
export interface PaginationLinkProps {
|
|
105
|
+
children?: Slot;
|
|
159
106
|
href?: string;
|
|
160
|
-
current
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
107
|
+
/** The page the user is on. Carries `aria-current="page"`. */
|
|
108
|
+
isActive?: Reactive<boolean>;
|
|
109
|
+
size?: "default" | "icon";
|
|
110
|
+
disabled?: Reactive<boolean>;
|
|
111
|
+
onSelect?: (event: MouseEvent) => void;
|
|
112
|
+
"aria-label"?: string;
|
|
113
|
+
class?: Reactive<string>;
|
|
166
114
|
}
|
|
167
115
|
|
|
168
116
|
/**
|
|
169
117
|
* One page link.
|
|
170
118
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
119
|
+
* An `<a>` whether or not it has an `href`, because that is what upstream
|
|
120
|
+
* renders and what a pagination IS: a list of destinations. `onSelect`
|
|
121
|
+
* intercepts only when it is given — with an `href` and no handler the link
|
|
122
|
+
* must navigate normally, which is what makes a server-rendered pagination
|
|
123
|
+
* work with JavaScript off.
|
|
175
124
|
*/
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
125
|
+
export const PaginationLink = component<PaginationLinkProps>((props) => {
|
|
126
|
+
const active = (): boolean => read(props.isActive) === true;
|
|
127
|
+
function onClick(event: MouseEvent): void {
|
|
128
|
+
if (read(props.disabled) === true) {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (props.onSelect === undefined) return;
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
props.onSelect(event);
|
|
135
|
+
}
|
|
179
136
|
return html`<a
|
|
180
137
|
data-slot="pagination-link"
|
|
181
|
-
href="${
|
|
182
|
-
aria-
|
|
183
|
-
aria-
|
|
184
|
-
aria-disabled="${() => (disabled
|
|
185
|
-
|
|
138
|
+
href="${props.href}"
|
|
139
|
+
aria-current="${() => (active() ? "page" : undefined)}"
|
|
140
|
+
aria-label="${props["aria-label"]}"
|
|
141
|
+
aria-disabled="${() => (read(props.disabled) === true ? "true" : undefined)}"
|
|
142
|
+
data-active="${() => (active() ? "true" : "false")}"
|
|
186
143
|
class="${() =>
|
|
187
144
|
cn(
|
|
188
145
|
buttonVariants({
|
|
189
|
-
variant:
|
|
190
|
-
size:
|
|
146
|
+
variant: active() ? "outline" : "ghost",
|
|
147
|
+
size: props.size ?? "icon",
|
|
191
148
|
}),
|
|
192
|
-
|
|
193
|
-
|
|
149
|
+
read(props.disabled) === true ? "pointer-events-none opacity-50" : "",
|
|
150
|
+
read(props.class),
|
|
194
151
|
)}"
|
|
195
|
-
@click="${
|
|
196
|
-
>${
|
|
152
|
+
@click="${onClick}"
|
|
153
|
+
>${slot(props.children)}</a>`;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export type PaginationStepProps = Omit<
|
|
157
|
+
PaginationLinkProps,
|
|
158
|
+
"size" | "isActive" | "aria-label"
|
|
159
|
+
>;
|
|
160
|
+
|
|
161
|
+
export const PaginationPrevious = component<PaginationStepProps>((props) =>
|
|
162
|
+
PaginationLink({
|
|
163
|
+
...props,
|
|
164
|
+
size: "default",
|
|
165
|
+
"aria-label": "Go to previous page",
|
|
166
|
+
class: () => cn("gap-1 px-2.5 sm:pl-2.5", read(props.class)),
|
|
167
|
+
children: html`${ChevronLeftIcon({})}<span class="hidden sm:block">Previous</span>`,
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
export const PaginationNext = component<PaginationStepProps>((props) =>
|
|
172
|
+
PaginationLink({
|
|
173
|
+
...props,
|
|
174
|
+
size: "default",
|
|
175
|
+
"aria-label": "Go to next page",
|
|
176
|
+
class: () => cn("gap-1 px-2.5 sm:pr-2.5", read(props.class)),
|
|
177
|
+
children: html`<span class="hidden sm:block">Next</span>${ChevronRightIcon({})}`,
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
export interface PaginationEllipsisProps {
|
|
182
|
+
class?: Reactive<string>;
|
|
197
183
|
}
|
|
184
|
+
|
|
185
|
+
/** Stands in for the pages that did not fit — see `pageWindow`. */
|
|
186
|
+
export const PaginationEllipsis = component<PaginationEllipsisProps>(
|
|
187
|
+
(props) => html`<span
|
|
188
|
+
data-slot="pagination-ellipsis"
|
|
189
|
+
aria-hidden="true"
|
|
190
|
+
class="${() => cn("flex size-9 items-center justify-center", read(props.class))}"
|
|
191
|
+
>${MoreHorizontalIcon({ class: "size-4" })}<span class="sr-only">More pages</span></span>`,
|
|
192
|
+
);
|
|
@@ -1,53 +1,67 @@
|
|
|
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
19
|
|
|
14
|
-
import { component, html } from "@c9up/aurora";
|
|
15
|
-
import type {
|
|
20
|
+
import { component, createContext, html, inject, provide } from "@c9up/aurora";
|
|
21
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
22
|
+
import { slot } from "../lib/children.js";
|
|
16
23
|
import { cn } from "../lib/cn.js";
|
|
17
24
|
import { uid } from "../lib/id.js";
|
|
18
25
|
import { type Reactive, read, readOr } from "../lib/props.js";
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
const radioClasses =
|
|
28
|
+
"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";
|
|
29
|
+
|
|
30
|
+
interface RadioGroupApi {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly selected: () => string | undefined;
|
|
33
|
+
readonly disabled: () => boolean;
|
|
34
|
+
choose(value: string): void;
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
const RadioGroupContext = createContext<RadioGroupApi>("RadioGroup");
|
|
38
|
+
|
|
27
39
|
export interface RadioGroupProps {
|
|
28
40
|
/** Shared `name`, which is what makes the browser treat these as one group. */
|
|
29
41
|
name: string;
|
|
30
|
-
options: readonly RadioOption[];
|
|
31
42
|
value?: Reactive<string | undefined>;
|
|
32
43
|
defaultValue?: string;
|
|
33
44
|
disabled?: Reactive<boolean>;
|
|
34
45
|
orientation?: "vertical" | "horizontal";
|
|
35
|
-
class?: Reactive<string>;
|
|
36
46
|
onValueChange?: (value: string) => void;
|
|
47
|
+
class?: Reactive<string>;
|
|
48
|
+
children?: Parts;
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
const radioClasses =
|
|
40
|
-
"peer size-4 shrink-0 appearance-none rounded-full border border-input bg-transparent shadow-xs outline-none transition-shadow dark:bg-input/30 checked:border-primary focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
|
|
41
|
-
|
|
42
51
|
export const RadioGroup = component<RadioGroupProps>((props) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
provide<RadioGroupApi>(RadioGroupContext, {
|
|
53
|
+
name: props.name,
|
|
54
|
+
selected: () => {
|
|
55
|
+
const controlled = read(props.value);
|
|
56
|
+
return controlled === undefined ? props.defaultValue : controlled;
|
|
57
|
+
},
|
|
58
|
+
disabled: () => readOr(props.disabled, false),
|
|
59
|
+
choose: (value) => props.onValueChange?.(value),
|
|
60
|
+
});
|
|
47
61
|
|
|
48
62
|
return html`<div
|
|
49
|
-
role="radiogroup"
|
|
50
63
|
data-slot="radio-group"
|
|
64
|
+
role="radiogroup"
|
|
51
65
|
aria-orientation="${props.orientation ?? "vertical"}"
|
|
52
66
|
class="${() =>
|
|
53
67
|
cn(
|
|
@@ -55,50 +69,47 @@ export const RadioGroup = component<RadioGroupProps>((props) => {
|
|
|
55
69
|
props.orientation === "horizontal" ? "grid-flow-col auto-cols-max" : "",
|
|
56
70
|
read(props.class),
|
|
57
71
|
)}"
|
|
58
|
-
|
|
59
|
-
${props.options.map((option) => renderOption(option, props, selected))}
|
|
60
|
-
</div>`;
|
|
72
|
+
>${props.children?.()}</div>`;
|
|
61
73
|
});
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
export interface RadioGroupItemProps {
|
|
76
|
+
value: string;
|
|
77
|
+
children?: Slot;
|
|
78
|
+
description?: Slot;
|
|
79
|
+
disabled?: boolean;
|
|
80
|
+
class?: Reactive<string>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const RadioGroupItem = component<RadioGroupItemProps>((props) => {
|
|
84
|
+
const group = inject(RadioGroupContext);
|
|
68
85
|
const id = uid("radio");
|
|
69
86
|
const descriptionId =
|
|
70
|
-
|
|
87
|
+
props.description === undefined ? undefined : uid("radio-description");
|
|
71
88
|
|
|
72
|
-
return html`<div class="flex items-start gap-3"
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
return html`<div class="flex items-start gap-3"><span
|
|
90
|
+
class="relative flex size-4 shrink-0 items-center justify-center"
|
|
91
|
+
><input
|
|
75
92
|
type="radio"
|
|
76
93
|
data-slot="radio-group-item"
|
|
77
94
|
id="${id}"
|
|
78
|
-
name="${
|
|
79
|
-
value="${
|
|
95
|
+
name="${group.name}"
|
|
96
|
+
value="${props.value}"
|
|
80
97
|
aria-describedby="${descriptionId}"
|
|
81
|
-
?disabled="${() =>
|
|
82
|
-
.checked="${() => selected() ===
|
|
83
|
-
class="${radioClasses}"
|
|
84
|
-
@change="${() =>
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
?disabled="${() => props.disabled === true || group.disabled()}"
|
|
99
|
+
.checked="${() => group.selected() === props.value}"
|
|
100
|
+
class="${() => cn(radioClasses, read(props.class))}"
|
|
101
|
+
@change="${() => group.choose(props.value)}"
|
|
102
|
+
/><span
|
|
103
|
+
data-slot="radio-group-indicator"
|
|
87
104
|
class="bg-primary pointer-events-none absolute size-2 rounded-full opacity-0 transition-opacity peer-checked:opacity-100"
|
|
88
|
-
></span
|
|
89
|
-
</span>
|
|
90
|
-
<div class="grid gap-1 leading-none">
|
|
91
|
-
<label
|
|
105
|
+
></span></span><div class="grid gap-1 leading-none"><label
|
|
92
106
|
for="${id}"
|
|
93
107
|
class="text-sm leading-none font-medium select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50"
|
|
94
|
-
>${
|
|
95
|
-
|
|
96
|
-
option.description === undefined
|
|
108
|
+
>${slot(props.children)}</label>${
|
|
109
|
+
props.description === undefined
|
|
97
110
|
? null
|
|
98
|
-
: html`<p id="${descriptionId}" class="text-muted-foreground text-sm"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
</div>`;
|
|
104
|
-
}
|
|
111
|
+
: html`<p id="${descriptionId}" class="text-muted-foreground text-sm">${slot(
|
|
112
|
+
props.description,
|
|
113
|
+
)}</p>`
|
|
114
|
+
}</div></div>`;
|
|
115
|
+
});
|