@glasshome/ui 1.41.0 → 1.42.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/SPEC.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/anchor-placement.d.ts +30 -0
- package/dist/lib/behavior/anchored.d.ts +12 -0
- package/dist/lib/behavior/collection.d.ts +24 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +11 -0
- package/dist/lib/behavior/focus-scope.d.ts +18 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +33 -0
- package/dist/lib/behavior/modal-root.d.ts +66 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/solid.d.ts +13 -0
- package/dist/lib/motion-classes.d.ts +5 -2
- package/dist/lib/overlay-classes.d.ts +3 -0
- package/dist/lib/page-cover.d.ts +8 -0
- package/dist/lib/shadow-layer.d.ts +8 -6
- package/dist/solid/alert-dialog.d.ts +5 -8
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
- package/dist/solid/bottom-sheet/constants.d.ts +1 -1
- package/dist/solid/dialog-parts.d.ts +51 -14
- package/dist/solid/dialog.d.ts +7 -10
- package/dist/solid/index.d.ts +4 -1
- package/dist/solid/index.js +7797 -7710
- package/dist/solid/responsive-dialog.d.ts +2 -0
- package/dist/solid/sheet.d.ts +5 -8
- package/dist/solid/stale-veil.d.ts +7 -0
- package/dist/solid/tabs.d.ts +28 -9
- package/dist/solid/toggle-group.d.ts +30 -5
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/{utils-CGN4X-2O.js → utils-CxAii-e9.js} +606 -414
- package/package.json +4 -2
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +68 -2
- package/src/lib/behavior/anchored.ts +88 -0
- package/src/lib/behavior/collection.ts +181 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +145 -0
- package/src/lib/behavior/focus-scope.ts +202 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +125 -0
- package/src/lib/behavior/modal-root.tsx +446 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +3 -2
- package/src/lib/motion-classes.ts +27 -2
- package/src/lib/overlay-classes.ts +7 -0
- package/src/lib/page-cover.ts +47 -0
- package/src/lib/shadow-layer.ts +48 -66
- package/src/solid/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +2 -1
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +72 -128
- package/src/solid/bottom-sheet/constants.ts +3 -1
- package/src/solid/bottom-sheet/drag-controller.ts +11 -0
- package/src/solid/breadcrumb.tsx +4 -4
- package/src/solid/button-group.tsx +4 -4
- package/src/solid/card.tsx +5 -4
- package/src/solid/context-menu.tsx +12 -2
- package/src/solid/dialog-parts.tsx +132 -43
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +3 -3
- package/src/solid/dropdown-menu.tsx +15 -7
- package/src/solid/entity-selector.tsx +2 -1
- package/src/solid/form.tsx +4 -3
- package/src/solid/hover-card.tsx +7 -2
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +5 -4
- package/src/solid/index.ts +4 -1
- package/src/solid/input-group.tsx +5 -3
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +4 -4
- package/src/solid/logo.tsx +5 -4
- package/src/solid/picker-row.tsx +5 -4
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +18 -10
- package/src/solid/responsive-dialog.tsx +9 -9
- package/src/solid/sheet.tsx +47 -79
- package/src/solid/spotlight.tsx +23 -11
- package/src/solid/stale-veil.tsx +20 -0
- package/src/solid/switch.tsx +8 -6
- package/src/solid/tabs.tsx +368 -49
- package/src/solid/toggle-group.tsx +305 -93
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +3 -3
- package/src/styles/theme.css +5 -0
- package/dist/lib/when-animations-settle.d.ts +0 -4
- package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
- package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
- package/src/lib/when-animations-settle.ts +0 -12
- package/src/solid/bottom-sheet/focus-trap.ts +0 -63
- package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
- package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
package/src/solid/tabs.tsx
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Accessor,
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createContext,
|
|
6
|
+
createSignal,
|
|
7
|
+
createUniqueId,
|
|
8
|
+
onCleanup,
|
|
9
|
+
onMount,
|
|
10
|
+
Show,
|
|
11
|
+
splitProps,
|
|
12
|
+
useContext,
|
|
13
|
+
type ValidComponent,
|
|
14
|
+
} from "solid-js";
|
|
15
|
+
import { type Collection, createCollection } from "../lib/behavior/collection.js";
|
|
16
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
17
|
+
import { CANDIDATES, focusWithoutTracking, hasFocus } from "../lib/behavior/focus-scope.js";
|
|
18
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
19
|
+
import { effect, merge } from "../lib/behavior/solid.js";
|
|
3
20
|
import { TRACK_SURFACE } from "../lib/card-classes.js";
|
|
4
21
|
import { PRESS_DIP, SETTLE_MOTION } from "../lib/motion-classes.js";
|
|
5
22
|
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
@@ -13,67 +30,324 @@ import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
|
13
30
|
* them. */
|
|
14
31
|
type TabsLayout = "stack" | "split";
|
|
15
32
|
|
|
33
|
+
type Orientation = "horizontal" | "vertical";
|
|
34
|
+
|
|
16
35
|
const TABS_LAYOUT: Record<TabsLayout, string> = {
|
|
17
36
|
stack: "flex flex-col gap-2",
|
|
18
37
|
split: "contents",
|
|
19
38
|
};
|
|
20
39
|
|
|
21
|
-
type TabsProps = ComponentProps<
|
|
40
|
+
type TabsProps = Omit<ComponentProps<"div">, "onChange"> & {
|
|
41
|
+
as?: ValidComponent;
|
|
42
|
+
layout?: TabsLayout;
|
|
43
|
+
value?: string;
|
|
44
|
+
defaultValue?: string;
|
|
45
|
+
onChange?: (value: string) => void;
|
|
46
|
+
orientation?: Orientation;
|
|
47
|
+
activationMode?: "automatic" | "manual";
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface TabsContextValue {
|
|
52
|
+
value: Accessor<string | undefined>;
|
|
53
|
+
select: (value: string) => void;
|
|
54
|
+
orientation: Accessor<Orientation>;
|
|
55
|
+
disabled: Accessor<boolean>;
|
|
56
|
+
automatic: Accessor<boolean>;
|
|
57
|
+
collection: Collection;
|
|
58
|
+
setList: (el: HTMLElement | undefined) => void;
|
|
59
|
+
register: (part: "trigger" | "content", value: string, id: string | undefined) => () => void;
|
|
60
|
+
triggerId: (value: string) => string;
|
|
61
|
+
contentId: (value: string) => string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const TabsContext = createContext<TabsContextValue | null>(null);
|
|
65
|
+
|
|
66
|
+
const useTabs = (): TabsContextValue => {
|
|
67
|
+
const ctx = useContext(TabsContext);
|
|
68
|
+
if (!ctx) throw new Error("Tabs parts render inside a Tabs");
|
|
69
|
+
return ctx;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const TAB = '[role="tab"][data-key]';
|
|
73
|
+
|
|
74
|
+
type Ids = Record<string, string | undefined>;
|
|
22
75
|
|
|
23
76
|
const Tabs: Component<TabsProps> = (props) => {
|
|
24
|
-
const [local, others] = splitProps(props, [
|
|
77
|
+
const [local, others] = splitProps(props, [
|
|
78
|
+
"class",
|
|
79
|
+
"layout",
|
|
80
|
+
"value",
|
|
81
|
+
"defaultValue",
|
|
82
|
+
"onChange",
|
|
83
|
+
"orientation",
|
|
84
|
+
"activationMode",
|
|
85
|
+
"disabled",
|
|
86
|
+
"id",
|
|
87
|
+
"as",
|
|
88
|
+
]);
|
|
89
|
+
const fallbackId = `tabs-${createUniqueId()}`;
|
|
90
|
+
const id = () => local.id ?? fallbackId;
|
|
91
|
+
const orientation = () => local.orientation ?? "horizontal";
|
|
92
|
+
const [value, setValue] = createControllableSignal<string | undefined>({
|
|
93
|
+
value: () => local.value,
|
|
94
|
+
defaultValue: () => local.defaultValue,
|
|
95
|
+
onChange: (next) => next !== undefined && local.onChange?.(next),
|
|
96
|
+
});
|
|
97
|
+
const [list, setList] = createSignal<HTMLElement>();
|
|
98
|
+
const [triggerIds, setTriggerIds] = createSignal<Ids>({});
|
|
99
|
+
const [contentIds, setContentIds] = createSignal<Ids>({});
|
|
100
|
+
const collection = createCollection({
|
|
101
|
+
root: list,
|
|
102
|
+
itemSelector: TAB,
|
|
103
|
+
orientation,
|
|
104
|
+
focus: "roving",
|
|
105
|
+
loop: () => true,
|
|
106
|
+
dir: () => (list()?.closest("[dir]")?.getAttribute("dir") === "rtl" ? "rtl" : "ltr"),
|
|
107
|
+
preferred: () => {
|
|
108
|
+
const current = value();
|
|
109
|
+
return current === undefined ? [] : [current];
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const select = (next: string) => {
|
|
114
|
+
if (next === value()) local.onChange?.(next);
|
|
115
|
+
else setValue(next);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
effect(
|
|
119
|
+
() => [list(), value(), triggerIds()] as const,
|
|
120
|
+
([el, current]) => {
|
|
121
|
+
if (!el) return;
|
|
122
|
+
const tabs = [...el.querySelectorAll<HTMLElement>(TAB)];
|
|
123
|
+
if (tabs.some((tab) => tab.dataset.key === current)) return;
|
|
124
|
+
const first = tabs.find((tab) => !tab.hasAttribute("data-disabled")) ?? tabs[0];
|
|
125
|
+
if (first?.dataset.key !== undefined) setValue(first.dataset.key);
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const register: TabsContextValue["register"] = (part, key, custom) => {
|
|
130
|
+
const set = part === "trigger" ? setTriggerIds : setContentIds;
|
|
131
|
+
set((ids) => ({ ...ids, [key]: custom }));
|
|
132
|
+
return () =>
|
|
133
|
+
set((ids) => {
|
|
134
|
+
const { [key]: _gone, ...kept } = ids;
|
|
135
|
+
return kept;
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const context: TabsContextValue = {
|
|
140
|
+
value,
|
|
141
|
+
select,
|
|
142
|
+
orientation,
|
|
143
|
+
disabled: () => local.disabled ?? false,
|
|
144
|
+
automatic: () => (local.activationMode ?? "automatic") === "automatic",
|
|
145
|
+
collection,
|
|
146
|
+
setList,
|
|
147
|
+
register,
|
|
148
|
+
triggerId: (key) => triggerIds()[key] ?? `${id()}-trigger-${key}`,
|
|
149
|
+
contentId: (key) => contentIds()[key] ?? `${id()}-content-${key}`,
|
|
150
|
+
};
|
|
151
|
+
|
|
25
152
|
return (
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
153
|
+
<TabsContext.Provider value={context}>
|
|
154
|
+
<Polymorphic
|
|
155
|
+
{...merge({ "data-slot": "tabs" }, others, {
|
|
156
|
+
as: local.as,
|
|
157
|
+
defaultAs: "div" as ValidComponent,
|
|
158
|
+
get id() {
|
|
159
|
+
return id();
|
|
160
|
+
},
|
|
161
|
+
get "data-orientation"() {
|
|
162
|
+
return orientation();
|
|
163
|
+
},
|
|
164
|
+
get "data-layout"() {
|
|
165
|
+
return local.layout ?? "stack";
|
|
166
|
+
},
|
|
167
|
+
get class() {
|
|
168
|
+
return cn(TABS_LAYOUT[local.layout ?? "stack"], local.class);
|
|
169
|
+
},
|
|
170
|
+
})}
|
|
171
|
+
/>
|
|
172
|
+
</TabsContext.Provider>
|
|
32
173
|
);
|
|
33
174
|
};
|
|
34
175
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
176
|
+
type TabsListProps = ComponentProps<"div"> & { as?: ValidComponent };
|
|
177
|
+
|
|
178
|
+
const TabsList: Component<TabsListProps> = (props) => {
|
|
179
|
+
const ctx = useTabs();
|
|
180
|
+
const [local, others] = splitProps(props, ["class", "children", "ref", "as"]);
|
|
181
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
38
182
|
onMount(() => {
|
|
39
|
-
|
|
183
|
+
const listEl = el();
|
|
184
|
+
if (listEl) onCleanup(trackScroll(listEl, "[data-selected]", "data-selected"));
|
|
185
|
+
});
|
|
186
|
+
onCleanup(() => ctx.setList(undefined));
|
|
187
|
+
|
|
188
|
+
effect(el, (node) => {
|
|
189
|
+
if (!node) return;
|
|
190
|
+
const keydown = (event: KeyboardEvent) => {
|
|
191
|
+
const before = ctx.collection.highlighted();
|
|
192
|
+
ctx.collection.onKeyDown(event);
|
|
193
|
+
const after = ctx.collection.highlighted();
|
|
194
|
+
if (after !== undefined && after !== before && ctx.automatic()) ctx.select(after);
|
|
195
|
+
};
|
|
196
|
+
node.addEventListener("keydown", keydown);
|
|
197
|
+
return () => node.removeEventListener("keydown", keydown);
|
|
40
198
|
});
|
|
199
|
+
|
|
41
200
|
return (
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
201
|
+
<Polymorphic
|
|
202
|
+
{...merge({ "data-slot": "tabs-list" }, others, {
|
|
203
|
+
as: local.as,
|
|
204
|
+
defaultAs: "div" as ValidComponent,
|
|
205
|
+
ref: (node: HTMLElement) => {
|
|
206
|
+
setEl(node);
|
|
207
|
+
ctx.setList(node);
|
|
208
|
+
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
209
|
+
},
|
|
210
|
+
role: "tablist",
|
|
211
|
+
get "aria-orientation"() {
|
|
212
|
+
return ctx.orientation();
|
|
213
|
+
},
|
|
214
|
+
get "data-orientation"() {
|
|
215
|
+
return ctx.orientation();
|
|
216
|
+
},
|
|
217
|
+
get class() {
|
|
218
|
+
return cn(
|
|
219
|
+
`scrollbar-hide inline-flex h-9 w-full items-center overflow-x-auto rounded-lg has-[[data-slot=tabs-trigger-icon]]:h-auto ${TRACK_SURFACE} ${SCROLL_TRACK_FADE} text-muted-foreground p-1`,
|
|
220
|
+
local.class,
|
|
221
|
+
);
|
|
222
|
+
},
|
|
223
|
+
})}
|
|
50
224
|
>
|
|
51
225
|
{/* w-max so triggers keep their natural width and the track scrolls;
|
|
52
226
|
w-full alone squeezed them past the rounded edge, unreachable. */}
|
|
53
227
|
<SelectionScope marker="selected" class="flex h-full w-max min-w-full items-center gap-1">
|
|
54
228
|
{local.children}
|
|
55
229
|
</SelectionScope>
|
|
56
|
-
</
|
|
230
|
+
</Polymorphic>
|
|
57
231
|
);
|
|
58
232
|
};
|
|
59
233
|
|
|
234
|
+
type TabsTriggerProps = ComponentProps<"button"> & {
|
|
235
|
+
as?: ValidComponent;
|
|
236
|
+
value: string;
|
|
237
|
+
disabled?: boolean;
|
|
238
|
+
icon?: string;
|
|
239
|
+
inline?: boolean;
|
|
240
|
+
};
|
|
241
|
+
|
|
60
242
|
/** `icon` stacks a glyph over the word, so a tab row reads apart from the toggle groups under it.
|
|
61
243
|
* `inline` sets the glyph beside the word instead, for a row that stands alone. */
|
|
62
|
-
const TabsTrigger: Component<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
244
|
+
const TabsTrigger: Component<TabsTriggerProps> = (props) => {
|
|
245
|
+
const ctx = useTabs();
|
|
246
|
+
const [local, others] = splitProps(props, [
|
|
247
|
+
"class",
|
|
248
|
+
"icon",
|
|
249
|
+
"inline",
|
|
250
|
+
"children",
|
|
251
|
+
"value",
|
|
252
|
+
"disabled",
|
|
253
|
+
"id",
|
|
254
|
+
"ref",
|
|
255
|
+
"as",
|
|
256
|
+
]);
|
|
257
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
258
|
+
const disabled = () => local.disabled || ctx.disabled();
|
|
259
|
+
effect(disabled, () => ctx.collection.refresh());
|
|
260
|
+
onCleanup(() => ctx.collection.refresh());
|
|
261
|
+
const selected = () => ctx.value() === local.value;
|
|
262
|
+
|
|
263
|
+
effect(
|
|
264
|
+
() => [local.value, local.id] as const,
|
|
265
|
+
([key, custom]) => ctx.register("trigger", key, custom),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
effect(el, (node) => {
|
|
269
|
+
if (!node) return;
|
|
270
|
+
let mousePressed = false;
|
|
271
|
+
const choose = () => {
|
|
272
|
+
if (disabled()) return;
|
|
273
|
+
ctx.select(local.value);
|
|
274
|
+
ctx.collection.highlight(local.value, "pointer");
|
|
275
|
+
};
|
|
276
|
+
// A mouse selects on press, so focus lands on a tab already selected and is announced so.
|
|
277
|
+
const pointerdown = (event: PointerEvent) => {
|
|
278
|
+
mousePressed = event.pointerType === "mouse" && event.button === 0;
|
|
279
|
+
if (mousePressed) choose();
|
|
280
|
+
};
|
|
281
|
+
const click = (event: MouseEvent) => {
|
|
282
|
+
// WebKit leaves a clicked button unfocused.
|
|
283
|
+
if (!disabled() && !hasFocus(node)) focusWithoutTracking(node);
|
|
284
|
+
if (event.detail === 0 || !mousePressed) choose();
|
|
285
|
+
mousePressed = false;
|
|
286
|
+
};
|
|
287
|
+
const focus = () => ctx.collection.highlight(local.value, "pointer");
|
|
288
|
+
node.addEventListener("pointerdown", pointerdown);
|
|
289
|
+
node.addEventListener("click", click);
|
|
290
|
+
node.addEventListener("focus", focus);
|
|
291
|
+
return () => {
|
|
292
|
+
node.removeEventListener("pointerdown", pointerdown);
|
|
293
|
+
node.removeEventListener("click", click);
|
|
294
|
+
node.removeEventListener("focus", focus);
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
|
|
66
298
|
return (
|
|
67
|
-
<
|
|
68
|
-
data-slot
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
299
|
+
<Polymorphic
|
|
300
|
+
{...merge({ "data-slot": "tabs-trigger" }, others, {
|
|
301
|
+
as: local.as,
|
|
302
|
+
defaultAs: "button" as ValidComponent,
|
|
303
|
+
ref: (node: HTMLElement) => {
|
|
304
|
+
setEl(node);
|
|
305
|
+
if (typeof local.ref === "function") local.ref(node as HTMLButtonElement);
|
|
306
|
+
},
|
|
307
|
+
get id() {
|
|
308
|
+
return ctx.triggerId(local.value);
|
|
309
|
+
},
|
|
310
|
+
role: "tab",
|
|
311
|
+
get tabIndex() {
|
|
312
|
+
return disabled() ? undefined : ctx.collection.tabIndex(local.value);
|
|
313
|
+
},
|
|
314
|
+
get disabled() {
|
|
315
|
+
return disabled();
|
|
316
|
+
},
|
|
317
|
+
get "aria-selected"() {
|
|
318
|
+
return selected();
|
|
319
|
+
},
|
|
320
|
+
get "aria-disabled"() {
|
|
321
|
+
return disabled() || undefined;
|
|
322
|
+
},
|
|
323
|
+
get "aria-controls"() {
|
|
324
|
+
return selected() ? ctx.contentId(local.value) : undefined;
|
|
325
|
+
},
|
|
326
|
+
get "data-key"() {
|
|
327
|
+
return local.value;
|
|
328
|
+
},
|
|
329
|
+
get "data-orientation"() {
|
|
330
|
+
return ctx.orientation();
|
|
331
|
+
},
|
|
332
|
+
get "data-selected"() {
|
|
333
|
+
return selected() ? "" : undefined;
|
|
334
|
+
},
|
|
335
|
+
get "data-highlighted"() {
|
|
336
|
+
return ctx.collection.highlighted() === local.value ? "" : undefined;
|
|
337
|
+
},
|
|
338
|
+
get "data-disabled"() {
|
|
339
|
+
return disabled() ? "" : undefined;
|
|
340
|
+
},
|
|
341
|
+
get class() {
|
|
342
|
+
return cn(
|
|
343
|
+
SEGMENT_ITEM,
|
|
344
|
+
PRESS_DIP,
|
|
345
|
+
"not-data-[selected]:hover:text-foreground relative isolate data-[selected]:text-(--material-accent)",
|
|
346
|
+
local.icon && !local.inline && "h-auto flex-1 flex-col gap-1 py-2 text-xs",
|
|
347
|
+
local.class,
|
|
348
|
+
);
|
|
349
|
+
},
|
|
350
|
+
})}
|
|
77
351
|
>
|
|
78
352
|
<SelectionHighlight />
|
|
79
353
|
{local.icon && (
|
|
@@ -86,22 +360,67 @@ const TabsTrigger: Component<
|
|
|
86
360
|
/>
|
|
87
361
|
)}
|
|
88
362
|
{local.children}
|
|
89
|
-
</
|
|
363
|
+
</Polymorphic>
|
|
90
364
|
);
|
|
91
365
|
};
|
|
92
366
|
|
|
93
|
-
|
|
94
|
-
|
|
367
|
+
type TabsContentProps = ComponentProps<"div"> & {
|
|
368
|
+
as?: ValidComponent;
|
|
369
|
+
value: string;
|
|
370
|
+
forceMount?: boolean;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const TabsContent: Component<TabsContentProps> = (props) => {
|
|
374
|
+
const ctx = useTabs();
|
|
375
|
+
const [local, others] = splitProps(props, ["class", "value", "forceMount", "id", "ref", "as"]);
|
|
376
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
377
|
+
const [holdsTabStop, setHoldsTabStop] = createSignal(false);
|
|
378
|
+
const selected = () => ctx.value() === local.value;
|
|
379
|
+
|
|
380
|
+
effect(
|
|
381
|
+
() => [local.value, local.id] as const,
|
|
382
|
+
([key, custom]) => ctx.register("content", key, custom),
|
|
383
|
+
);
|
|
384
|
+
effect(el, (node) => {
|
|
385
|
+
if (node) setHoldsTabStop(node.querySelector(CANDIDATES) !== null);
|
|
386
|
+
});
|
|
387
|
+
|
|
95
388
|
return (
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
389
|
+
<Show when={local.forceMount || selected()}>
|
|
390
|
+
<Polymorphic
|
|
391
|
+
{...merge({ "data-slot": "tabs-content" }, others, {
|
|
392
|
+
as: local.as,
|
|
393
|
+
defaultAs: "div" as ValidComponent,
|
|
394
|
+
ref: (node: HTMLElement) => {
|
|
395
|
+
setEl(node);
|
|
396
|
+
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
397
|
+
},
|
|
398
|
+
get id() {
|
|
399
|
+
return ctx.contentId(local.value);
|
|
400
|
+
},
|
|
401
|
+
role: "tabpanel",
|
|
402
|
+
get tabIndex() {
|
|
403
|
+
return holdsTabStop() ? undefined : 0;
|
|
404
|
+
},
|
|
405
|
+
get "aria-labelledby"() {
|
|
406
|
+
return ctx.triggerId(local.value);
|
|
407
|
+
},
|
|
408
|
+
get "data-orientation"() {
|
|
409
|
+
return ctx.orientation();
|
|
410
|
+
},
|
|
411
|
+
get "data-selected"() {
|
|
412
|
+
return selected() ? "" : undefined;
|
|
413
|
+
},
|
|
414
|
+
get class() {
|
|
415
|
+
return cn(
|
|
416
|
+
SETTLE_MOTION,
|
|
417
|
+
"focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-[3px]",
|
|
418
|
+
local.class,
|
|
419
|
+
);
|
|
420
|
+
},
|
|
421
|
+
})}
|
|
422
|
+
/>
|
|
423
|
+
</Show>
|
|
105
424
|
);
|
|
106
425
|
};
|
|
107
426
|
|