@glasshome/ui 1.42.0 → 1.44.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 +8 -5
- package/dist/index.js +2 -2
- package/dist/lib/anchor-placement.d.ts +4 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +16 -3
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +6 -4
- package/dist/lib/behavior/focus-scope.d.ts +9 -1
- package/dist/lib/behavior/hide-outside.d.ts +1 -1
- package/dist/lib/behavior/layer-stack.d.ts +3 -2
- package/dist/lib/behavior/menu.d.ts +62 -0
- package/dist/lib/behavior/modal-root.d.ts +2 -0
- package/dist/lib/behavior/range.d.ts +44 -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 +2 -1
- package/dist/lib/overlay-classes.d.ts +1 -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 -45
- 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/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.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/data-table.d.ts +4 -2
- package/dist/solid/dialog-parts.d.ts +8 -8
- 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 +1 -1
- package/dist/solid/index.js +7752 -13493
- 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 +1 -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 +1 -1
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +22 -22
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CxAii-e9.js → utils-BbIeGt7o.js} +376 -314
- package/package.json +3 -6
- package/src/lib/anchor-placement.ts +10 -3
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +41 -9
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +56 -28
- package/src/lib/behavior/dismiss.ts +61 -21
- package/src/lib/behavior/focus-scope.ts +75 -9
- package/src/lib/behavior/hide-outside.ts +2 -2
- package/src/lib/behavior/layer-stack.ts +33 -8
- package/src/lib/behavior/menu.ts +462 -0
- package/src/lib/behavior/modal-root.tsx +24 -18
- package/src/lib/behavior/polymorphic.tsx +1 -1
- package/src/lib/behavior/presence.ts +1 -1
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/clipboard.ts +2 -3
- 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 +8 -9
- package/src/lib/overlay-classes.ts +1 -3
- 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 -118
- 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/area-picker.tsx +4 -4
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/bottom-sheet/arbitration.ts +4 -11
- package/src/solid/bottom-sheet/bottom-sheet.tsx +4 -5
- package/src/solid/bottom-sheet/drag-controller.ts +7 -20
- package/src/solid/button.tsx +12 -6
- 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 +285 -94
- package/src/solid/data-table.tsx +48 -22
- package/src/solid/dialog-parts.tsx +39 -17
- package/src/solid/dock.tsx +44 -43
- package/src/solid/dropdown-menu.tsx +252 -115
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +3 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +5 -6
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +287 -25
- package/src/solid/icon-picker.tsx +1 -2
- package/src/solid/image-picker.tsx +2 -2
- package/src/solid/index.ts +1 -3
- package/src/solid/input-group.tsx +2 -2
- package/src/solid/item.tsx +1 -1
- package/src/solid/menu-parts.tsx +610 -155
- package/src/solid/option-card.tsx +7 -13
- package/src/solid/picker-row.tsx +5 -1
- package/src/solid/popover.tsx +423 -80
- 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 +1 -1
- 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 +939 -95
- package/src/solid/selection.tsx +165 -74
- package/src/solid/sheet.tsx +1 -1
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +4 -16
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/tabs.tsx +12 -6
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +34 -101
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +24 -24
- package/src/styles/globals.css +61 -50
- package/src/styles/theme.css +12 -6
- package/src/tokens/material.ts +11 -2
package/src/solid/accordion.tsx
CHANGED
|
@@ -1,14 +1,292 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Accessor,
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createContext,
|
|
6
|
+
createSignal,
|
|
7
|
+
createUniqueId,
|
|
8
|
+
type JSX,
|
|
9
|
+
type ParentComponent,
|
|
10
|
+
splitProps,
|
|
11
|
+
useContext,
|
|
12
|
+
type ValidComponent,
|
|
13
|
+
} from "solid-js";
|
|
14
|
+
import { type Collection, createCollection } from "../lib/behavior/collection.js";
|
|
15
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
16
|
+
import { focusWithoutTracking, trackFocus } from "../lib/behavior/focus-scope.js";
|
|
17
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
18
|
+
import { callEventHandler, effect, merge } from "../lib/behavior/solid.js";
|
|
3
19
|
import { cn } from "../lib/utils.js";
|
|
20
|
+
import {
|
|
21
|
+
CollapsibleContentRoot,
|
|
22
|
+
CollapsibleRoot,
|
|
23
|
+
CollapsibleTriggerRoot,
|
|
24
|
+
useCollapsible,
|
|
25
|
+
} from "./collapsible.js";
|
|
4
26
|
import { Icon } from "./icon.js";
|
|
5
27
|
|
|
6
|
-
|
|
28
|
+
type AccordionProps = Omit<ComponentProps<"div">, "onChange"> & {
|
|
29
|
+
as?: ValidComponent;
|
|
30
|
+
value?: string[];
|
|
31
|
+
defaultValue?: string[];
|
|
32
|
+
onChange?: (value: string[]) => void;
|
|
33
|
+
multiple?: boolean;
|
|
34
|
+
collapsible?: boolean;
|
|
35
|
+
shouldFocusWrap?: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type AccordionItemProps = Omit<ComponentProps<"div">, "onChange"> & {
|
|
39
|
+
as?: ValidComponent;
|
|
40
|
+
value: string;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
forceMount?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type AccordionHeaderProps = ComponentProps<"h3"> & { as?: ValidComponent };
|
|
46
|
+
type AccordionTriggerProps = ComponentProps<"button"> & { as?: ValidComponent };
|
|
47
|
+
type AccordionContentProps = ComponentProps<"div"> & { as?: ValidComponent };
|
|
48
|
+
|
|
49
|
+
interface AccordionContextValue {
|
|
50
|
+
rootId: Accessor<string>;
|
|
51
|
+
isOpen: (value: string) => boolean;
|
|
52
|
+
toggle: (value: string) => void;
|
|
53
|
+
collection: Collection;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface AccordionItemContextValue {
|
|
57
|
+
value: Accessor<string>;
|
|
58
|
+
itemId: Accessor<string>;
|
|
59
|
+
triggerId: Accessor<string | undefined>;
|
|
60
|
+
setTriggerId: (id: string | undefined) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const AccordionContext = createContext<AccordionContextValue>();
|
|
64
|
+
const AccordionItemContext = createContext<AccordionItemContextValue>();
|
|
65
|
+
|
|
66
|
+
function useAccordion(): AccordionContextValue {
|
|
67
|
+
const ctx = useContext(AccordionContext);
|
|
68
|
+
if (!ctx) throw new Error("An accordion part renders inside an Accordion");
|
|
69
|
+
return ctx;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function useAccordionItem(): AccordionItemContextValue {
|
|
73
|
+
const ctx = useContext(AccordionItemContext);
|
|
74
|
+
if (!ctx) throw new Error("An accordion part renders inside an AccordionItem");
|
|
75
|
+
return ctx;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const NAVIGATION_KEYS = new Set(["ArrowDown", "ArrowUp", "Home", "End"]);
|
|
79
|
+
|
|
80
|
+
const AccordionRoot: Component<AccordionProps> = (props) => {
|
|
81
|
+
const fallbackId = `accordion-${createUniqueId()}`;
|
|
82
|
+
const [local, others] = splitProps(props, [
|
|
83
|
+
"as",
|
|
84
|
+
"ref",
|
|
85
|
+
"value",
|
|
86
|
+
"defaultValue",
|
|
87
|
+
"onChange",
|
|
88
|
+
"multiple",
|
|
89
|
+
"collapsible",
|
|
90
|
+
"shouldFocusWrap",
|
|
91
|
+
]);
|
|
92
|
+
const [value, setValue] = createControllableSignal<string[]>({
|
|
93
|
+
value: () => local.value,
|
|
94
|
+
defaultValue: () => local.defaultValue ?? [],
|
|
95
|
+
onChange: (next) => local.onChange?.(next),
|
|
96
|
+
});
|
|
97
|
+
const mayEmpty = () => !!local.multiple || !!local.collapsible;
|
|
98
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
99
|
+
const collection = createCollection({
|
|
100
|
+
root: el,
|
|
101
|
+
itemSelector: "[data-key]",
|
|
102
|
+
orientation: () => "vertical",
|
|
103
|
+
focus: "roving",
|
|
104
|
+
loop: () => local.shouldFocusWrap ?? true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const toggle = (item: string) => {
|
|
108
|
+
const current = value();
|
|
109
|
+
if (current.includes(item)) {
|
|
110
|
+
if (local.multiple) setValue(current.filter((v) => v !== item));
|
|
111
|
+
else if (local.collapsible) setValue([]);
|
|
112
|
+
} else setValue(local.multiple ? [...current, item] : [item]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
effect(el, (node) => {
|
|
116
|
+
if (!node) return;
|
|
117
|
+
const keydown = (event: KeyboardEvent) => {
|
|
118
|
+
const onTrigger = event.target instanceof HTMLElement && event.target.matches("[data-key]");
|
|
119
|
+
if (onTrigger && NAVIGATION_KEYS.has(event.key)) return collection.onKeyDown(event);
|
|
120
|
+
if (event.key !== "Escape" || event.defaultPrevented || !mayEmpty()) return;
|
|
121
|
+
if (value().length === 0) return;
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
setValue([]);
|
|
124
|
+
};
|
|
125
|
+
node.addEventListener("keydown", keydown);
|
|
126
|
+
return () => node.removeEventListener("keydown", keydown);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const ctx: AccordionContextValue = {
|
|
130
|
+
rootId: () => others.id ?? fallbackId,
|
|
131
|
+
isOpen: (item) => value().includes(item),
|
|
132
|
+
toggle,
|
|
133
|
+
collection,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<AccordionContext.Provider value={ctx}>
|
|
138
|
+
<Polymorphic
|
|
139
|
+
{...merge({ id: fallbackId }, others, {
|
|
140
|
+
as: local.as,
|
|
141
|
+
defaultAs: "div" as ValidComponent,
|
|
142
|
+
ref: (node: HTMLElement) => {
|
|
143
|
+
setEl(node);
|
|
144
|
+
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
145
|
+
},
|
|
146
|
+
})}
|
|
147
|
+
/>
|
|
148
|
+
</AccordionContext.Provider>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const AccordionItemRoot: Component<AccordionItemProps> = (props) => {
|
|
153
|
+
const accordion = useAccordion();
|
|
154
|
+
const fallbackId = `${accordion.rootId()}-item-${createUniqueId()}`;
|
|
155
|
+
const [local, others] = splitProps(props, ["value", "disabled"]);
|
|
156
|
+
const [triggerId, setTriggerId] = createSignal<string>();
|
|
157
|
+
const itemId = () => others.id ?? fallbackId;
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<AccordionItemContext.Provider
|
|
161
|
+
value={{ value: () => local.value, itemId, triggerId, setTriggerId }}
|
|
162
|
+
>
|
|
163
|
+
<CollapsibleRoot
|
|
164
|
+
{...merge({ id: fallbackId }, others, {
|
|
165
|
+
get open() {
|
|
166
|
+
return accordion.isOpen(local.value);
|
|
167
|
+
},
|
|
168
|
+
onOpenChange: () => accordion.toggle(local.value),
|
|
169
|
+
get disabled() {
|
|
170
|
+
return local.disabled;
|
|
171
|
+
},
|
|
172
|
+
})}
|
|
173
|
+
/>
|
|
174
|
+
</AccordionItemContext.Provider>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const AccordionHeader: Component<AccordionHeaderProps> = (props) => {
|
|
179
|
+
const collapsible = useCollapsible();
|
|
180
|
+
const [local, others] = splitProps(props, ["as"]);
|
|
181
|
+
return (
|
|
182
|
+
<Polymorphic
|
|
183
|
+
{...merge(collapsible.markers, others, { as: local.as, defaultAs: "h3" as ValidComponent })}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const AccordionTriggerRoot: Component<AccordionTriggerProps> = (props) => {
|
|
189
|
+
const accordion = useAccordion();
|
|
190
|
+
const item = useAccordionItem();
|
|
191
|
+
const collapsible = useCollapsible();
|
|
192
|
+
const [local, others] = splitProps(props, ["ref", "onClick"]);
|
|
193
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
194
|
+
const id = () => others.id ?? `${item.itemId()}-trigger`;
|
|
195
|
+
effect(id, (value) => {
|
|
196
|
+
item.setTriggerId(value);
|
|
197
|
+
return () => item.setTriggerId(undefined);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
let focused: ReturnType<typeof trackFocus> | undefined;
|
|
201
|
+
effect(el, (node) => {
|
|
202
|
+
if (!node) return;
|
|
203
|
+
const tracked = trackFocus(node);
|
|
204
|
+
focused = tracked;
|
|
205
|
+
const focus = () => accordion.collection.highlight(item.value(), "pointer");
|
|
206
|
+
node.addEventListener("focus", focus);
|
|
207
|
+
return () => {
|
|
208
|
+
tracked.stop();
|
|
209
|
+
node.removeEventListener("focus", focus);
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const click: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (event) => {
|
|
214
|
+
callEventHandler(event, local.onClick);
|
|
215
|
+
// WebKit leaves a clicked button unfocused, and the arrows move from the focused trigger.
|
|
216
|
+
const node = el();
|
|
217
|
+
if (node && !collapsible.disabled() && !focused?.has()) focusWithoutTracking(node);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<CollapsibleTriggerRoot
|
|
222
|
+
{...merge(
|
|
223
|
+
{
|
|
224
|
+
get "data-key"() {
|
|
225
|
+
return item.value();
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
others,
|
|
229
|
+
{
|
|
230
|
+
get id() {
|
|
231
|
+
return id();
|
|
232
|
+
},
|
|
233
|
+
onClick: click,
|
|
234
|
+
ref: (node: HTMLButtonElement) => {
|
|
235
|
+
setEl(node);
|
|
236
|
+
if (typeof local.ref === "function") local.ref(node);
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
)}
|
|
240
|
+
/>
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const CONTENT_VARS = {
|
|
245
|
+
"--accordion-content-height": "var(--collapsible-content-height)",
|
|
246
|
+
"--accordion-content-width": "var(--collapsible-content-width)",
|
|
247
|
+
"--kb-accordion-content-height": "var(--kb-collapsible-content-height)",
|
|
248
|
+
"--kb-accordion-content-width": "var(--kb-collapsible-content-width)",
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const CONTENT_VARS_CSS = Object.entries(CONTENT_VARS)
|
|
252
|
+
.map(([name, value]) => `${name}:${value};`)
|
|
253
|
+
.join("");
|
|
254
|
+
|
|
255
|
+
const AccordionContentRoot: Component<AccordionContentProps> = (props) => {
|
|
256
|
+
const item = useAccordionItem();
|
|
257
|
+
const [local, others] = splitProps(props, ["style"]);
|
|
258
|
+
return (
|
|
259
|
+
<CollapsibleContentRoot
|
|
260
|
+
{...merge(
|
|
261
|
+
{
|
|
262
|
+
role: "region" as const,
|
|
263
|
+
get "aria-labelledby"() {
|
|
264
|
+
return item.triggerId();
|
|
265
|
+
},
|
|
266
|
+
get style() {
|
|
267
|
+
return typeof local.style === "string"
|
|
268
|
+
? `${CONTENT_VARS_CSS}${local.style}`
|
|
269
|
+
: { ...CONTENT_VARS, ...local.style };
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
others,
|
|
273
|
+
)}
|
|
274
|
+
/>
|
|
275
|
+
);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const Accordion = Object.assign(AccordionRoot, {
|
|
279
|
+
Root: AccordionRoot,
|
|
280
|
+
Item: AccordionItemRoot,
|
|
281
|
+
Header: AccordionHeader,
|
|
282
|
+
Trigger: AccordionTriggerRoot,
|
|
283
|
+
Content: AccordionContentRoot,
|
|
284
|
+
});
|
|
7
285
|
|
|
8
|
-
const AccordionItem: Component<
|
|
286
|
+
const AccordionItem: Component<AccordionItemProps> = (props) => {
|
|
9
287
|
const [local, rest] = splitProps(props, ["class"]);
|
|
10
288
|
return (
|
|
11
|
-
<
|
|
289
|
+
<AccordionItemRoot
|
|
12
290
|
data-slot="accordion-item"
|
|
13
291
|
class={cn("border-b last:border-b-0", local.class)}
|
|
14
292
|
{...rest}
|
|
@@ -16,16 +294,14 @@ const AccordionItem: Component<ComponentProps<typeof AccordionPrimitive.Item>> =
|
|
|
16
294
|
);
|
|
17
295
|
};
|
|
18
296
|
|
|
19
|
-
const AccordionTrigger: ParentComponent<
|
|
20
|
-
props,
|
|
21
|
-
) => {
|
|
297
|
+
const AccordionTrigger: ParentComponent<AccordionTriggerProps> = (props) => {
|
|
22
298
|
const [local, rest] = splitProps(props, ["class", "children"]);
|
|
23
299
|
return (
|
|
24
|
-
<
|
|
25
|
-
<
|
|
300
|
+
<AccordionHeader class="flex">
|
|
301
|
+
<AccordionTriggerRoot
|
|
26
302
|
data-slot="accordion-trigger"
|
|
27
303
|
class={cn(
|
|
28
|
-
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-expanded]>[data-slot=icon]]:rotate-180",
|
|
304
|
+
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all duration-(--duration-state) outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-expanded]>[data-slot=icon]]:rotate-180",
|
|
29
305
|
local.class,
|
|
30
306
|
)}
|
|
31
307
|
{...rest}
|
|
@@ -35,25 +311,23 @@ const AccordionTrigger: ParentComponent<ComponentProps<typeof AccordionPrimitive
|
|
|
35
311
|
icon="lucide:chevron-down"
|
|
36
312
|
width={16}
|
|
37
313
|
height={16}
|
|
38
|
-
class="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-
|
|
314
|
+
class="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-(--duration-expand)"
|
|
39
315
|
/>
|
|
40
|
-
</
|
|
41
|
-
</
|
|
316
|
+
</AccordionTriggerRoot>
|
|
317
|
+
</AccordionHeader>
|
|
42
318
|
);
|
|
43
319
|
};
|
|
44
320
|
|
|
45
|
-
const AccordionContent: ParentComponent<
|
|
46
|
-
props,
|
|
47
|
-
) => {
|
|
321
|
+
const AccordionContent: ParentComponent<AccordionContentProps> = (props) => {
|
|
48
322
|
const [local, rest] = splitProps(props, ["class", "children"]);
|
|
49
323
|
return (
|
|
50
|
-
<
|
|
324
|
+
<AccordionContentRoot
|
|
51
325
|
data-slot="accordion-content"
|
|
52
|
-
class="data-[closed]:animate-accordion-up data-[expanded]:animate-accordion-down overflow-hidden text-sm"
|
|
326
|
+
class="data-[closed]:animate-accordion-up data-[expanded]:animate-accordion-down overflow-hidden text-sm duration-(--duration-expand)"
|
|
53
327
|
{...rest}
|
|
54
328
|
>
|
|
55
329
|
<div class={cn("pt-0 pb-4", local.class)}>{local.children}</div>
|
|
56
|
-
</
|
|
330
|
+
</AccordionContentRoot>
|
|
57
331
|
);
|
|
58
332
|
};
|
|
59
333
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
2
|
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
3
|
-
import { MENU_ITEM } from "../lib/menu-classes.js";
|
|
4
|
-
import { STAGGER } from "../lib/motion-classes.js";
|
|
3
|
+
import { MENU_ITEM, MENU_ITEM_RADIUS } from "../lib/menu-classes.js";
|
|
5
4
|
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
6
5
|
import { cn } from "../lib/utils.js";
|
|
7
6
|
import { useEntityData } from "./entity-data.js";
|
|
@@ -192,7 +191,8 @@ export function AreaPicker(props: AreaPickerProps) {
|
|
|
192
191
|
/>
|
|
193
192
|
<SelectionScope
|
|
194
193
|
marker="highlighted"
|
|
195
|
-
|
|
194
|
+
radius={MENU_ITEM_RADIUS}
|
|
195
|
+
class={cn("flex flex-col gap-0.5 p-1", PICKER_LIST)}
|
|
196
196
|
onMouseLeave={() => setHovered(null)}
|
|
197
197
|
>
|
|
198
198
|
<Show when={filtered().length === 0 && missing().length === 0}>
|
|
@@ -215,7 +215,7 @@ export function AreaPicker(props: AreaPickerProps) {
|
|
|
215
215
|
as="button"
|
|
216
216
|
type="button"
|
|
217
217
|
data-slot="area-picker-row"
|
|
218
|
-
|
|
218
|
+
highlighted={highlightedId() === area.id}
|
|
219
219
|
aria-pressed={multi() ? isSelected(area.id) : undefined}
|
|
220
220
|
icon={area.icon || "mdi:home-floor-1"}
|
|
221
221
|
title={area.name}
|
package/src/solid/avatar.tsx
CHANGED
|
@@ -1,40 +1,114 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Accessor,
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createContext,
|
|
6
|
+
createSignal,
|
|
7
|
+
Show,
|
|
8
|
+
splitProps,
|
|
9
|
+
useContext,
|
|
10
|
+
} from "solid-js";
|
|
11
|
+
import { effect } from "../lib/behavior/solid.js";
|
|
3
12
|
import { cn } from "../lib/utils.js";
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
type LoadingStatus = "idle" | "loading" | "loaded" | "error";
|
|
15
|
+
|
|
16
|
+
type AvatarProps = ComponentProps<"span"> & {
|
|
17
|
+
fallbackDelay?: number;
|
|
18
|
+
onLoadingStatusChange?: (status: LoadingStatus) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
interface AvatarContextValue {
|
|
22
|
+
fallbackDelay: Accessor<number | undefined>;
|
|
23
|
+
status: Accessor<LoadingStatus>;
|
|
24
|
+
report: (status: LoadingStatus) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const AvatarContext = createContext<AvatarContextValue>();
|
|
28
|
+
|
|
29
|
+
function useAvatar(): AvatarContextValue {
|
|
30
|
+
const ctx = useContext(AvatarContext);
|
|
31
|
+
if (!ctx) throw new Error("An avatar part renders inside an Avatar");
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const Avatar: Component<AvatarProps> = (props) => {
|
|
36
|
+
const [local, rest] = splitProps(props, ["class", "fallbackDelay", "onLoadingStatusChange"]);
|
|
37
|
+
const [status, setStatus] = createSignal<LoadingStatus>("idle");
|
|
38
|
+
const ctx: AvatarContextValue = {
|
|
39
|
+
fallbackDelay: () => local.fallbackDelay,
|
|
40
|
+
status,
|
|
41
|
+
report: (next) => {
|
|
42
|
+
setStatus(next);
|
|
43
|
+
local.onLoadingStatusChange?.(next);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
7
46
|
return (
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
47
|
+
<AvatarContext.Provider value={ctx}>
|
|
48
|
+
<span
|
|
49
|
+
data-slot="avatar"
|
|
50
|
+
class={cn("relative flex size-10 shrink-0 overflow-hidden rounded-full", local.class)}
|
|
51
|
+
{...rest}
|
|
52
|
+
/>
|
|
53
|
+
</AvatarContext.Provider>
|
|
13
54
|
);
|
|
14
55
|
};
|
|
15
56
|
|
|
16
|
-
const AvatarImage: Component<ComponentProps<
|
|
57
|
+
const AvatarImage: Component<ComponentProps<"img">> = (props) => {
|
|
58
|
+
const ctx = useAvatar();
|
|
17
59
|
const [local, rest] = splitProps(props, ["class"]);
|
|
60
|
+
const [status, setStatus] = createSignal<LoadingStatus>("idle");
|
|
61
|
+
|
|
62
|
+
// A detached probe, so the photo replaces the fallback only once it has decoded.
|
|
63
|
+
effect(
|
|
64
|
+
() => props.src,
|
|
65
|
+
(src) => {
|
|
66
|
+
if (!src) return void setStatus("error");
|
|
67
|
+
let live = true;
|
|
68
|
+
const probe = document.createElement("img");
|
|
69
|
+
const settle = (next: LoadingStatus) => () => live && setStatus(next);
|
|
70
|
+
setStatus("loading");
|
|
71
|
+
if (props.crossOrigin !== undefined) probe.crossOrigin = props.crossOrigin;
|
|
72
|
+
if (props.referrerPolicy !== undefined) probe.referrerPolicy = props.referrerPolicy;
|
|
73
|
+
probe.onload = settle("loaded");
|
|
74
|
+
probe.onerror = settle("error");
|
|
75
|
+
probe.src = src;
|
|
76
|
+
return () => {
|
|
77
|
+
live = false;
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
effect(status, (next) => {
|
|
82
|
+
if (next !== "idle") ctx.report(next);
|
|
83
|
+
});
|
|
84
|
+
|
|
18
85
|
return (
|
|
19
|
-
<
|
|
20
|
-
data-slot="avatar-image"
|
|
21
|
-
|
|
22
|
-
{...rest}
|
|
23
|
-
/>
|
|
86
|
+
<Show when={status() === "loaded"}>
|
|
87
|
+
<img data-slot="avatar-image" class={cn("aspect-square size-full", local.class)} {...rest} />
|
|
88
|
+
</Show>
|
|
24
89
|
);
|
|
25
90
|
};
|
|
26
91
|
|
|
27
|
-
const AvatarFallback: Component<ComponentProps<
|
|
92
|
+
const AvatarFallback: Component<ComponentProps<"span">> = (props) => {
|
|
93
|
+
const ctx = useAvatar();
|
|
28
94
|
const [local, rest] = splitProps(props, ["class"]);
|
|
95
|
+
const [due, setDue] = createSignal(ctx.fallbackDelay() === undefined);
|
|
96
|
+
effect(ctx.fallbackDelay, (delay) => {
|
|
97
|
+
if (delay === undefined) return;
|
|
98
|
+
const timer = setTimeout(() => setDue(true), delay);
|
|
99
|
+
return () => clearTimeout(timer);
|
|
100
|
+
});
|
|
29
101
|
return (
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
102
|
+
<Show when={due() && ctx.status() !== "loaded"}>
|
|
103
|
+
<span
|
|
104
|
+
data-slot="avatar-fallback"
|
|
105
|
+
class={cn(
|
|
106
|
+
"glass flex size-full items-center justify-center rounded-full font-semibold [--glass-tone:var(--primary)]",
|
|
107
|
+
local.class,
|
|
108
|
+
)}
|
|
109
|
+
{...rest}
|
|
110
|
+
/>
|
|
111
|
+
</Show>
|
|
38
112
|
);
|
|
39
113
|
};
|
|
40
114
|
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
// Decides drag vs scroll. Walks event.target ancestors; if any
|
|
2
|
-
//
|
|
3
|
-
// Markers: data-sheet-no-drag (abort), data-sheet-scroll (force scrollable).
|
|
1
|
+
// Decides drag vs scroll. Walks event.target ancestors; if any can still scroll in the drag
|
|
2
|
+
// direction, yield to scroll. Marker: data-sheet-no-drag (abort).
|
|
4
3
|
|
|
5
4
|
type Direction = "down" | "up";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
if (el.hasAttribute("data-sheet-scroll")) return true;
|
|
9
|
-
const overflowY = getComputedStyle(el).overflowY;
|
|
10
|
-
if (overflowY !== "auto" && overflowY !== "scroll" && overflowY !== "overlay") return false;
|
|
11
|
-
return el.scrollHeight > el.clientHeight;
|
|
12
|
-
}
|
|
13
|
-
|
|
6
|
+
// Geometry alone: only a scroller holds a scrollTop, and a false "up" costs just the rubber band.
|
|
14
7
|
function canScrollFurther(el: Element, dir: Direction): boolean {
|
|
15
8
|
if (dir === "down") return el.scrollTop > 0;
|
|
16
9
|
return el.scrollTop + el.clientHeight < el.scrollHeight - 1;
|
|
@@ -32,7 +25,7 @@ export function shouldDrag(target: Element | null, root: Element, dy: number, dx
|
|
|
32
25
|
const dir: Direction = dy > 0 ? "down" : "up";
|
|
33
26
|
let cur: Element | null = target;
|
|
34
27
|
while (cur && cur !== root.parentElement) {
|
|
35
|
-
if (
|
|
28
|
+
if (canScrollFurther(cur, dir)) return false;
|
|
36
29
|
if (cur === root) break;
|
|
37
30
|
cur = cur.parentElement;
|
|
38
31
|
}
|
|
@@ -259,7 +259,7 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
|
|
|
259
259
|
createEffect(() => {
|
|
260
260
|
const node = ctx.contentRef();
|
|
261
261
|
if (!node) return;
|
|
262
|
-
if (
|
|
262
|
+
if (!present()) return;
|
|
263
263
|
const handle = watchKeyboard(node);
|
|
264
264
|
onCleanup(() => handle.destroy());
|
|
265
265
|
});
|
|
@@ -323,13 +323,12 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
|
|
|
323
323
|
"--bs-duration": `${TRANSITION_MS}ms`,
|
|
324
324
|
"--bs-ease": EASE,
|
|
325
325
|
"will-change": "transform",
|
|
326
|
-
"touch-action": "
|
|
326
|
+
"touch-action": "none",
|
|
327
327
|
"-webkit-tap-highlight-color": "transparent",
|
|
328
328
|
}}
|
|
329
329
|
class={cn(
|
|
330
330
|
"bs-content",
|
|
331
|
-
`fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col ${SCROLL_CONTAIN} rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none`,
|
|
332
|
-
"after:absolute after:inset-x-0 after:top-full after:h-1/2 after:bg-inherit",
|
|
331
|
+
`fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col ${SCROLL_CONTAIN} overflow-hidden rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none [--glass-edge:transparent]`,
|
|
333
332
|
local.class,
|
|
334
333
|
)}
|
|
335
334
|
>
|
|
@@ -409,7 +408,7 @@ const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
|
|
|
409
408
|
);
|
|
410
409
|
};
|
|
411
410
|
|
|
412
|
-
/** @deprecated
|
|
411
|
+
/** @deprecated The shared modal parts; removed in 2.0.0. */
|
|
413
412
|
export {
|
|
414
413
|
BottomSheet,
|
|
415
414
|
BottomSheetBody,
|
|
@@ -11,6 +11,7 @@ import type { SheetState } from "./state-machine.js";
|
|
|
11
11
|
import { VelocityTracker } from "./velocity.js";
|
|
12
12
|
|
|
13
13
|
const TRANSITION_CSS = `transform ${TRANSITION_MS}ms ${EASE}`;
|
|
14
|
+
const reducedMotion = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
14
15
|
|
|
15
16
|
interface DragHandle {
|
|
16
17
|
destroy: () => void;
|
|
@@ -37,8 +38,6 @@ export function attachDrag(opts: DragOptions): DragHandle {
|
|
|
37
38
|
let startX = 0;
|
|
38
39
|
let pointerTarget: Element | null = null;
|
|
39
40
|
let dy = 0;
|
|
40
|
-
let raf = 0;
|
|
41
|
-
let pendingDy: number | null = null;
|
|
42
41
|
let movedPastDeadZone = false;
|
|
43
42
|
let dragAborted = false;
|
|
44
43
|
let height = 0;
|
|
@@ -50,21 +49,13 @@ export function attachDrag(opts: DragOptions): DragHandle {
|
|
|
50
49
|
return s === "open" || s === "pressing";
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (pendingDy === null) return;
|
|
56
|
-
const value = pendingDy;
|
|
57
|
-
pendingDy = null;
|
|
52
|
+
// Written in the move itself: pointermove is already frame-aligned, and a guest's rAF costs a second trip through the realm.
|
|
53
|
+
const follow = (value: number) => {
|
|
58
54
|
const applied = value < 0 ? dampen(-value) * -1 : value;
|
|
59
55
|
shownDy = applied;
|
|
60
56
|
el.style.transform = `translate3d(0, ${applied}px, 0)`;
|
|
61
57
|
};
|
|
62
58
|
|
|
63
|
-
const schedule = (newDy: number) => {
|
|
64
|
-
pendingDy = newDy;
|
|
65
|
-
if (raf === 0) raf = requestAnimationFrame(flushFrame);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
59
|
const onPointerDown = (e: PointerEvent) => {
|
|
69
60
|
if (e.button !== 0 && e.pointerType !== "touch") return;
|
|
70
61
|
if (!isDraggableState()) return;
|
|
@@ -121,22 +112,17 @@ export function attachDrag(opts: DragOptions): DragHandle {
|
|
|
121
112
|
}
|
|
122
113
|
tracker.add(totalDy, e.timeStamp);
|
|
123
114
|
dy = totalDy;
|
|
124
|
-
|
|
115
|
+
follow(dy);
|
|
125
116
|
};
|
|
126
117
|
|
|
127
118
|
const cleanupDrag = () => {
|
|
128
|
-
if (raf !== 0) {
|
|
129
|
-
cancelAnimationFrame(raf);
|
|
130
|
-
raf = 0;
|
|
131
|
-
}
|
|
132
|
-
pendingDy = null;
|
|
133
119
|
pointerId = null;
|
|
134
120
|
pointerTarget = null;
|
|
135
121
|
dragAborted = false;
|
|
136
122
|
};
|
|
137
123
|
|
|
138
124
|
const settleClose = () => {
|
|
139
|
-
el.style.transition = TRANSITION_CSS;
|
|
125
|
+
el.style.transition = reducedMotion() ? "none" : TRANSITION_CSS;
|
|
140
126
|
el.style.animation = "none";
|
|
141
127
|
el.style.transform = "translate3d(0, 100%, 0)";
|
|
142
128
|
requestClose();
|
|
@@ -144,7 +130,8 @@ export function attachDrag(opts: DragOptions): DragHandle {
|
|
|
144
130
|
|
|
145
131
|
const settleSnap = () => {
|
|
146
132
|
setState("snapping");
|
|
147
|
-
if (shownDy === 0) {
|
|
133
|
+
if (shownDy === 0 || reducedMotion()) {
|
|
134
|
+
shownDy = 0;
|
|
148
135
|
el.style.transition = "";
|
|
149
136
|
el.style.animation = "";
|
|
150
137
|
el.style.transform = "";
|