@glasshome/ui 1.41.0 → 1.43.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 +34 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +26 -0
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +32 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +13 -0
- package/dist/lib/behavior/focus-scope.d.ts +24 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +34 -0
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +68 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/behavior/solid.d.ts +13 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +5 -2
- package/dist/lib/overlay-classes.d.ts +4 -0
- package/dist/lib/page-cover.d.ts +8 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -43
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/alert-dialog.d.ts +5 -8
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
- package/dist/solid/bottom-sheet/constants.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/dialog-parts.d.ts +53 -16
- package/dist/solid/dialog.d.ts +7 -10
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +5 -2
- package/dist/solid/index.js +8671 -14317
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +3 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +6 -9
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- 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/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
- package/package.json +6 -7
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +77 -4
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +106 -0
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +218 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +185 -0
- package/src/lib/behavior/focus-scope.ts +227 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +150 -0
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +452 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +4 -4
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +33 -8
- package/src/lib/overlay-classes.ts +8 -3
- package/src/lib/page-cover.ts +47 -0
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -136
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +5 -3
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
- 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/button.tsx +12 -6
- package/src/solid/card.tsx +5 -4
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +287 -86
- package/src/solid/dialog-parts.tsx +135 -46
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +6 -5
- package/src/solid/dropdown-menu.tsx +252 -107
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +5 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +9 -9
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +288 -21
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +6 -5
- package/src/solid/index.ts +5 -4
- package/src/solid/input-group.tsx +7 -5
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +5 -5
- package/src/solid/logo.tsx +5 -4
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +10 -5
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +424 -71
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +10 -10
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +950 -95
- package/src/solid/selection.tsx +142 -66
- package/src/solid/sheet.tsx +48 -80
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +1 -1
- package/src/solid/sonner.tsx +1 -1
- 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 +377 -52
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +237 -95
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +64 -10
- package/src/styles/theme.css +12 -4
- package/src/tokens/material.ts +11 -2
- 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,9 +1,26 @@
|
|
|
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, trackFocus } 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";
|
|
6
|
-
import { SEGMENT_ITEM } from "../lib/segment-classes.js";
|
|
23
|
+
import { SEGMENT_ITEM, SEGMENT_RADIUS } from "../lib/segment-classes.js";
|
|
7
24
|
import { cn } from "../lib/utils.js";
|
|
8
25
|
import { Icon } from "./icon.js";
|
|
9
26
|
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
@@ -13,69 +30,332 @@ 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]", ctx.value));
|
|
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
|
-
<SelectionScope
|
|
227
|
+
<SelectionScope
|
|
228
|
+
marker="selected"
|
|
229
|
+
radius={SEGMENT_RADIUS}
|
|
230
|
+
class="flex h-full w-max min-w-full items-center gap-1"
|
|
231
|
+
>
|
|
54
232
|
{local.children}
|
|
55
233
|
</SelectionScope>
|
|
56
|
-
</
|
|
234
|
+
</Polymorphic>
|
|
57
235
|
);
|
|
58
236
|
};
|
|
59
237
|
|
|
238
|
+
type TabsTriggerProps = ComponentProps<"button"> & {
|
|
239
|
+
as?: ValidComponent;
|
|
240
|
+
value: string;
|
|
241
|
+
disabled?: boolean;
|
|
242
|
+
icon?: string;
|
|
243
|
+
inline?: boolean;
|
|
244
|
+
};
|
|
245
|
+
|
|
60
246
|
/** `icon` stacks a glyph over the word, so a tab row reads apart from the toggle groups under it.
|
|
61
247
|
* `inline` sets the glyph beside the word instead, for a row that stands alone. */
|
|
62
|
-
const TabsTrigger: Component<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
248
|
+
const TabsTrigger: Component<TabsTriggerProps> = (props) => {
|
|
249
|
+
const ctx = useTabs();
|
|
250
|
+
const [local, others] = splitProps(props, [
|
|
251
|
+
"class",
|
|
252
|
+
"icon",
|
|
253
|
+
"inline",
|
|
254
|
+
"children",
|
|
255
|
+
"value",
|
|
256
|
+
"disabled",
|
|
257
|
+
"id",
|
|
258
|
+
"ref",
|
|
259
|
+
"as",
|
|
260
|
+
]);
|
|
261
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
262
|
+
const disabled = () => local.disabled || ctx.disabled();
|
|
263
|
+
effect(disabled, () => ctx.collection.refresh());
|
|
264
|
+
onCleanup(() => ctx.collection.refresh());
|
|
265
|
+
const selected = () => ctx.value() === local.value;
|
|
266
|
+
|
|
267
|
+
effect(
|
|
268
|
+
() => [local.value, local.id] as const,
|
|
269
|
+
([key, custom]) => ctx.register("trigger", key, custom),
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
effect(el, (node) => {
|
|
273
|
+
if (!node) return;
|
|
274
|
+
let mousePressed = false;
|
|
275
|
+
const focused = trackFocus(node);
|
|
276
|
+
const choose = () => {
|
|
277
|
+
if (disabled()) return;
|
|
278
|
+
ctx.select(local.value);
|
|
279
|
+
ctx.collection.highlight(local.value, "pointer");
|
|
280
|
+
};
|
|
281
|
+
// A mouse selects on press, so focus lands on a tab already selected and is announced so.
|
|
282
|
+
const pointerdown = (event: PointerEvent) => {
|
|
283
|
+
mousePressed = event.pointerType === "mouse" && event.button === 0;
|
|
284
|
+
if (mousePressed) choose();
|
|
285
|
+
};
|
|
286
|
+
const click = (event: MouseEvent) => {
|
|
287
|
+
// WebKit leaves a clicked button unfocused.
|
|
288
|
+
if (!disabled() && !focused.has()) focusWithoutTracking(node);
|
|
289
|
+
if (event.detail === 0 || !mousePressed) choose();
|
|
290
|
+
mousePressed = false;
|
|
291
|
+
};
|
|
292
|
+
const focus = () => ctx.collection.highlight(local.value, "pointer");
|
|
293
|
+
node.addEventListener("pointerdown", pointerdown);
|
|
294
|
+
node.addEventListener("click", click);
|
|
295
|
+
node.addEventListener("focus", focus);
|
|
296
|
+
return () => {
|
|
297
|
+
focused.stop();
|
|
298
|
+
node.removeEventListener("pointerdown", pointerdown);
|
|
299
|
+
node.removeEventListener("click", click);
|
|
300
|
+
node.removeEventListener("focus", focus);
|
|
301
|
+
};
|
|
302
|
+
});
|
|
303
|
+
|
|
66
304
|
return (
|
|
67
|
-
<
|
|
68
|
-
data-slot
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
305
|
+
<Polymorphic
|
|
306
|
+
{...merge({ "data-slot": "tabs-trigger" }, others, {
|
|
307
|
+
as: local.as,
|
|
308
|
+
defaultAs: "button" as ValidComponent,
|
|
309
|
+
ref: (node: HTMLElement) => {
|
|
310
|
+
setEl(node);
|
|
311
|
+
if (typeof local.ref === "function") local.ref(node as HTMLButtonElement);
|
|
312
|
+
},
|
|
313
|
+
get id() {
|
|
314
|
+
return ctx.triggerId(local.value);
|
|
315
|
+
},
|
|
316
|
+
role: "tab",
|
|
317
|
+
get tabIndex() {
|
|
318
|
+
return disabled() ? undefined : ctx.collection.tabIndex(local.value);
|
|
319
|
+
},
|
|
320
|
+
get disabled() {
|
|
321
|
+
return disabled();
|
|
322
|
+
},
|
|
323
|
+
get "aria-selected"() {
|
|
324
|
+
return selected();
|
|
325
|
+
},
|
|
326
|
+
get "aria-disabled"() {
|
|
327
|
+
return disabled() || undefined;
|
|
328
|
+
},
|
|
329
|
+
get "aria-controls"() {
|
|
330
|
+
return selected() ? ctx.contentId(local.value) : undefined;
|
|
331
|
+
},
|
|
332
|
+
get "data-key"() {
|
|
333
|
+
return local.value;
|
|
334
|
+
},
|
|
335
|
+
get "data-orientation"() {
|
|
336
|
+
return ctx.orientation();
|
|
337
|
+
},
|
|
338
|
+
get "data-selected"() {
|
|
339
|
+
return selected() ? "" : undefined;
|
|
340
|
+
},
|
|
341
|
+
get "data-highlighted"() {
|
|
342
|
+
return ctx.collection.highlighted() === local.value ? "" : undefined;
|
|
343
|
+
},
|
|
344
|
+
get "data-disabled"() {
|
|
345
|
+
return disabled() ? "" : undefined;
|
|
346
|
+
},
|
|
347
|
+
get class() {
|
|
348
|
+
return cn(
|
|
349
|
+
SEGMENT_ITEM,
|
|
350
|
+
PRESS_DIP,
|
|
351
|
+
"not-data-[selected]:hover:text-foreground relative isolate data-[selected]:text-(--material-accent)",
|
|
352
|
+
local.icon && !local.inline && "h-auto flex-1 flex-col gap-1 py-2 text-xs",
|
|
353
|
+
local.class,
|
|
354
|
+
);
|
|
355
|
+
},
|
|
356
|
+
})}
|
|
77
357
|
>
|
|
78
|
-
<SelectionHighlight />
|
|
358
|
+
<SelectionHighlight active={selected()} />
|
|
79
359
|
{local.icon && (
|
|
80
360
|
<Icon
|
|
81
361
|
data-slot={local.inline ? "tabs-trigger-inline-icon" : "tabs-trigger-icon"}
|
|
@@ -86,22 +366,67 @@ const TabsTrigger: Component<
|
|
|
86
366
|
/>
|
|
87
367
|
)}
|
|
88
368
|
{local.children}
|
|
89
|
-
</
|
|
369
|
+
</Polymorphic>
|
|
90
370
|
);
|
|
91
371
|
};
|
|
92
372
|
|
|
93
|
-
|
|
94
|
-
|
|
373
|
+
type TabsContentProps = ComponentProps<"div"> & {
|
|
374
|
+
as?: ValidComponent;
|
|
375
|
+
value: string;
|
|
376
|
+
forceMount?: boolean;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const TabsContent: Component<TabsContentProps> = (props) => {
|
|
380
|
+
const ctx = useTabs();
|
|
381
|
+
const [local, others] = splitProps(props, ["class", "value", "forceMount", "id", "ref", "as"]);
|
|
382
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
383
|
+
const [holdsTabStop, setHoldsTabStop] = createSignal(false);
|
|
384
|
+
const selected = () => ctx.value() === local.value;
|
|
385
|
+
|
|
386
|
+
effect(
|
|
387
|
+
() => [local.value, local.id] as const,
|
|
388
|
+
([key, custom]) => ctx.register("content", key, custom),
|
|
389
|
+
);
|
|
390
|
+
effect(el, (node) => {
|
|
391
|
+
if (node) setHoldsTabStop(node.querySelector(CANDIDATES) !== null);
|
|
392
|
+
});
|
|
393
|
+
|
|
95
394
|
return (
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
395
|
+
<Show when={local.forceMount || selected()}>
|
|
396
|
+
<Polymorphic
|
|
397
|
+
{...merge({ "data-slot": "tabs-content" }, others, {
|
|
398
|
+
as: local.as,
|
|
399
|
+
defaultAs: "div" as ValidComponent,
|
|
400
|
+
ref: (node: HTMLElement) => {
|
|
401
|
+
setEl(node);
|
|
402
|
+
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
403
|
+
},
|
|
404
|
+
get id() {
|
|
405
|
+
return ctx.contentId(local.value);
|
|
406
|
+
},
|
|
407
|
+
role: "tabpanel",
|
|
408
|
+
get tabIndex() {
|
|
409
|
+
return holdsTabStop() ? undefined : 0;
|
|
410
|
+
},
|
|
411
|
+
get "aria-labelledby"() {
|
|
412
|
+
return ctx.triggerId(local.value);
|
|
413
|
+
},
|
|
414
|
+
get "data-orientation"() {
|
|
415
|
+
return ctx.orientation();
|
|
416
|
+
},
|
|
417
|
+
get "data-selected"() {
|
|
418
|
+
return selected() ? "" : undefined;
|
|
419
|
+
},
|
|
420
|
+
get class() {
|
|
421
|
+
return cn(
|
|
422
|
+
SETTLE_MOTION,
|
|
423
|
+
"focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-[3px]",
|
|
424
|
+
local.class,
|
|
425
|
+
);
|
|
426
|
+
},
|
|
427
|
+
})}
|
|
428
|
+
/>
|
|
429
|
+
</Show>
|
|
105
430
|
);
|
|
106
431
|
};
|
|
107
432
|
|
package/src/solid/term.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Popover as PopoverPrimitive } from "@kobalte/core/popover";
|
|
2
1
|
import { type JSX, Show } from "solid-js";
|
|
3
2
|
import { cn } from "../lib/utils.js";
|
|
4
3
|
import { Icon } from "./icon.js";
|
|
5
|
-
import { Popover, PopoverContent } from "./popover.js";
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
6
5
|
import { SectionIcon } from "./section-card.js";
|
|
7
6
|
|
|
8
7
|
export interface TermDefinition {
|
|
@@ -17,7 +16,7 @@ export interface TermDefinition {
|
|
|
17
16
|
export function Term(props: { term: TermDefinition; children?: JSX.Element; class?: string }) {
|
|
18
17
|
return (
|
|
19
18
|
<Popover>
|
|
20
|
-
<
|
|
19
|
+
<PopoverTrigger
|
|
21
20
|
data-slot="term"
|
|
22
21
|
class={cn(
|
|
23
22
|
"decoration-muted-foreground/60 hover:decoration-foreground cursor-help underline decoration-dotted underline-offset-4 outline-none focus-visible:rounded-sm focus-visible:ring-2 focus-visible:ring-[var(--material-accent)]",
|
|
@@ -25,7 +24,7 @@ export function Term(props: { term: TermDefinition; children?: JSX.Element; clas
|
|
|
25
24
|
)}
|
|
26
25
|
>
|
|
27
26
|
{props.children ?? props.term.title}
|
|
28
|
-
</
|
|
27
|
+
</PopoverTrigger>
|
|
29
28
|
<PopoverContent class="flex w-72 items-start gap-3 text-left">
|
|
30
29
|
<SectionIcon icon={props.term.icon} tone="var(--material-accent)" size="sm" />
|
|
31
30
|
<div class="flex min-w-0 flex-col gap-1">
|