@glasshome/ui 1.35.3 → 1.36.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/lib/balance-rows.d.ts +7 -0
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +1591 -1537
- package/dist/solid/media-store.d.ts +14 -3
- package/package.json +1 -1
- package/src/lib/balance-rows.ts +62 -0
- package/src/solid/image-picker.tsx +39 -15
- package/src/solid/index.ts +3 -0
- package/src/solid/media-store.ts +28 -8
- package/src/solid/preview-tile.tsx +5 -1
- package/src/solid/schema-form.tsx +4 -6
- package/src/solid/toggle-group.tsx +14 -6
- package/src/styles/globals.css +9 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Accessor } from "solid-js";
|
|
1
2
|
export type StoredMedia = {
|
|
2
3
|
id: string;
|
|
3
4
|
mimeType: string;
|
|
@@ -26,17 +27,27 @@ export type MediaIndex = {
|
|
|
26
27
|
};
|
|
27
28
|
/** "thumb" is a server-side derivative, longest edge ~400px, for grids. */
|
|
28
29
|
export type MediaVariant = "original" | "thumb";
|
|
29
|
-
export interface
|
|
30
|
+
export interface MediaUrls {
|
|
31
|
+
url(id: string, variant?: MediaVariant): string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export interface MediaStore extends MediaUrls {
|
|
30
34
|
index(): Promise<MediaIndex>;
|
|
31
35
|
upload(file: File): Promise<StoredMedia>;
|
|
32
36
|
remove(id: string): Promise<void>;
|
|
33
37
|
url(id: string, variant?: MediaVariant): string;
|
|
38
|
+
/** false: this holder may not delete, so a gallery offers no Delete. */
|
|
39
|
+
readonly canRemove?: boolean;
|
|
34
40
|
}
|
|
35
41
|
/** `null` withholds the store from a tree, even where the host registered one. */
|
|
36
42
|
export declare const MediaStoreContext: import("solid-js").Context<MediaStore | null | undefined>;
|
|
37
|
-
/**
|
|
38
|
-
export declare
|
|
43
|
+
/** A tree's own url source, over the one the host provided. */
|
|
44
|
+
export declare const MediaUrlsContext: import("solid-js").Context<MediaUrls | undefined>;
|
|
45
|
+
/** Host apps call this once at startup; MediaStoreContext overrides it per-tree. An accessor is read each time a picker mounts. */
|
|
46
|
+
export declare function provideMediaStore(store: MediaStore | Accessor<MediaStore | null>): void;
|
|
47
|
+
/** Resolves stored ids to image urls in a tree that shows images but cannot manage them. */
|
|
48
|
+
export declare function provideMediaUrls(urls: MediaUrls): void;
|
|
39
49
|
export declare function useMediaStore(): MediaStore | undefined;
|
|
50
|
+
export declare function useMediaUrls(): MediaUrls | undefined;
|
|
40
51
|
/** One grid page. The picker and the library both slice by this, so neither can
|
|
41
52
|
* mount a whole 500-file library at once. */
|
|
42
53
|
export declare const MEDIA_PAGE_SIZE = 24;
|
package/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* A row of segments that runs out of width wraps into a grid whose rows hold an even count
|
|
2
|
+
* (four modes go two by two, five go three and two), never a full row and an orphan. */
|
|
3
|
+
|
|
4
|
+
/** Classes for the element holding the items: one row, then the balanced grid once `data-wrapped` is set. */
|
|
5
|
+
export const BALANCED_ROWS =
|
|
6
|
+
"grid grid-flow-col auto-cols-[minmax(max-content,1fr)] data-[wrapped]:grid-flow-row data-[wrapped]:grid-cols-[repeat(var(--balance-columns),minmax(max-content,1fr))]";
|
|
7
|
+
|
|
8
|
+
const fits = (items: HTMLElement) => items.scrollWidth <= items.clientWidth;
|
|
9
|
+
|
|
10
|
+
function fit(sizer: HTMLElement, items: HTMLElement, count: number): void {
|
|
11
|
+
const setColumns = (columns: number) =>
|
|
12
|
+
items.style.setProperty("--balance-columns", String(columns));
|
|
13
|
+
sizer.removeAttribute("data-wrapped");
|
|
14
|
+
items.removeAttribute("data-wrapped");
|
|
15
|
+
items.style.removeProperty("--balance-columns");
|
|
16
|
+
if (count < 2 || fits(items)) return;
|
|
17
|
+
sizer.setAttribute("data-wrapped", "");
|
|
18
|
+
items.setAttribute("data-wrapped", "");
|
|
19
|
+
let columns = count - 1;
|
|
20
|
+
for (; columns > 1; columns--) {
|
|
21
|
+
setColumns(columns);
|
|
22
|
+
if (fits(items)) break;
|
|
23
|
+
}
|
|
24
|
+
setColumns(Math.ceil(count / Math.ceil(count / Math.max(columns, 1))));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Lays `items` out in `BALANCED_ROWS`. `sizer` is the element that fills its line once wrapped
|
|
29
|
+
* (it takes `data-wrapped` too); `item` selects the items among `items`' children.
|
|
30
|
+
*/
|
|
31
|
+
export function balanceRows(sizer: HTMLElement, items: HTMLElement, item: string): () => void {
|
|
32
|
+
const each = () => items.querySelectorAll<HTMLElement>(`:scope > ${item}`);
|
|
33
|
+
const run = () => {
|
|
34
|
+
if (sizer.clientWidth === 0) return;
|
|
35
|
+
fit(sizer, items, each().length);
|
|
36
|
+
};
|
|
37
|
+
run();
|
|
38
|
+
// A frame late: a fit inside the observer's callback resizes what it observes.
|
|
39
|
+
let frame = 0;
|
|
40
|
+
const later = () => {
|
|
41
|
+
cancelAnimationFrame(frame);
|
|
42
|
+
frame = requestAnimationFrame(run);
|
|
43
|
+
};
|
|
44
|
+
// Items too: an icon or font that loads late widens a label without resizing the group.
|
|
45
|
+
const resize = new ResizeObserver(later);
|
|
46
|
+
const observe = () => {
|
|
47
|
+
resize.disconnect();
|
|
48
|
+
resize.observe(sizer);
|
|
49
|
+
for (const el of each()) resize.observe(el);
|
|
50
|
+
};
|
|
51
|
+
observe();
|
|
52
|
+
const children = new MutationObserver(() => {
|
|
53
|
+
observe();
|
|
54
|
+
later();
|
|
55
|
+
});
|
|
56
|
+
children.observe(items, { childList: true });
|
|
57
|
+
return () => {
|
|
58
|
+
cancelAnimationFrame(frame);
|
|
59
|
+
resize.disconnect();
|
|
60
|
+
children.disconnect();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -43,10 +43,12 @@ import {
|
|
|
43
43
|
MEDIA_PAGE_SIZE,
|
|
44
44
|
type MediaStore,
|
|
45
45
|
type MediaStoreError,
|
|
46
|
+
type MediaUrls,
|
|
46
47
|
presetValue,
|
|
47
48
|
type StoredMedia,
|
|
48
49
|
sortMediaForClearing,
|
|
49
50
|
useMediaStore,
|
|
51
|
+
useMediaUrls,
|
|
50
52
|
} from "./media-store.js";
|
|
51
53
|
import { MediaTile } from "./media-tile.js";
|
|
52
54
|
import {
|
|
@@ -71,25 +73,27 @@ export interface ImagePickerProps {
|
|
|
71
73
|
class?: string;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
const UNAVAILABLE = "Uploading images isn't available here.";
|
|
77
|
+
|
|
74
78
|
export function ImagePicker(props: ImagePickerProps) {
|
|
75
79
|
const store = useMediaStore();
|
|
80
|
+
const urls = useMediaUrls();
|
|
76
81
|
return (
|
|
77
82
|
<Show
|
|
78
83
|
when={store || props.presets}
|
|
79
84
|
fallback={
|
|
80
85
|
<div data-slot="image-picker" class={cn(props.class)}>
|
|
81
|
-
<Alert tone="info">
|
|
86
|
+
<Alert tone="info">{UNAVAILABLE}</Alert>
|
|
82
87
|
</div>
|
|
83
88
|
}
|
|
84
89
|
>
|
|
85
|
-
<ImageGallery {...props} store={store} />
|
|
90
|
+
<ImageGallery {...props} store={store} urls={urls} />
|
|
86
91
|
</Show>
|
|
87
92
|
);
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
type
|
|
91
|
-
|
|
92
|
-
| { kind: "media"; image: StoredMedia };
|
|
95
|
+
type MediaGalleryTile = { kind: "media"; image: StoredMedia };
|
|
96
|
+
type GalleryTile = { kind: "preset"; key: string; preset: ImagePreset } | MediaGalleryTile;
|
|
93
97
|
|
|
94
98
|
function PresetTile(props: { preset: ImagePreset; selected: boolean; onSelect: () => void }) {
|
|
95
99
|
return (
|
|
@@ -124,8 +128,11 @@ function PresetTile(props: { preset: ImagePreset; selected: boolean; onSelect: (
|
|
|
124
128
|
);
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
function ImageGallery(
|
|
131
|
+
function ImageGallery(
|
|
132
|
+
props: ImagePickerProps & { store: MediaStore | undefined; urls: MediaUrls | undefined },
|
|
133
|
+
) {
|
|
128
134
|
const store = props.store;
|
|
135
|
+
const uploadedUrl = () => props.urls?.url(props.value);
|
|
129
136
|
|
|
130
137
|
const [open, setOpen] = createSignal(false);
|
|
131
138
|
const [everOpened, setEverOpened] = createSignal(false);
|
|
@@ -137,6 +144,7 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
137
144
|
const thumbUrl = (id: string) => store?.url(id, "thumb") ?? "";
|
|
138
145
|
const brokenTiles = createBrokenMedia(thumbUrl);
|
|
139
146
|
let fileInput: HTMLInputElement | undefined;
|
|
147
|
+
let panel: HTMLElement | undefined;
|
|
140
148
|
|
|
141
149
|
const [index, { refetch }] = createResource(
|
|
142
150
|
() => everOpened() && store !== undefined,
|
|
@@ -149,15 +157,20 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
149
157
|
);
|
|
150
158
|
const loaded = () => (index.error === undefined ? index() : undefined);
|
|
151
159
|
const sorted = createMemo(() => sortMediaForClearing(loaded()?.media ?? []));
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
...Object.entries(props.presets ?? {}).map(([key, preset]): GalleryTile => ({
|
|
160
|
+
const presetTiles = createMemo(() =>
|
|
161
|
+
Object.entries(props.presets ?? {}).map(([key, preset]): GalleryTile => ({
|
|
155
162
|
kind: "preset",
|
|
156
163
|
key,
|
|
157
164
|
preset,
|
|
158
165
|
})),
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
);
|
|
167
|
+
// A reload hands back fresh objects; an unchanged upload keeps its tile, and the focus on it.
|
|
168
|
+
const mediaTiles = createMemo<MediaGalleryTile[]>((before) => {
|
|
169
|
+
const kept = new Map(before.map((tile) => [JSON.stringify(tile.image), tile]));
|
|
170
|
+
return sorted().map((image) => kept.get(JSON.stringify(image)) ?? { kind: "media", image });
|
|
171
|
+
}, []);
|
|
172
|
+
// Built-in pictures lead the grid; the household's uploads follow them.
|
|
173
|
+
const tiles = createMemo<GalleryTile[]>(() => [...presetTiles(), ...mediaTiles()]);
|
|
161
174
|
const pageCount = createMemo(() => Math.max(1, Math.ceil(tiles().length / MEDIA_PAGE_SIZE)));
|
|
162
175
|
const current = createMemo(() => Math.min(page(), pageCount() - 1));
|
|
163
176
|
const pageTiles = createMemo(() =>
|
|
@@ -247,7 +260,7 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
247
260
|
clearLabel="Clear image"
|
|
248
261
|
>
|
|
249
262
|
<Show
|
|
250
|
-
when={!thumbBroken() && props.value && (chosenPreset() ??
|
|
263
|
+
when={!thumbBroken() && props.value && (chosenPreset() ?? uploadedUrl())}
|
|
251
264
|
fallback={
|
|
252
265
|
<>
|
|
253
266
|
<Icon
|
|
@@ -263,7 +276,7 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
263
276
|
}
|
|
264
277
|
>
|
|
265
278
|
<img
|
|
266
|
-
src={chosenPreset()?.thumb ??
|
|
279
|
+
src={chosenPreset()?.thumb ?? uploadedUrl()}
|
|
267
280
|
alt=""
|
|
268
281
|
width={24}
|
|
269
282
|
height={24}
|
|
@@ -278,7 +291,14 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
278
291
|
</PickerTrigger>
|
|
279
292
|
</PopoverAnchor>
|
|
280
293
|
<PopoverContent
|
|
294
|
+
ref={(el: HTMLElement) => (panel = el)}
|
|
295
|
+
tabIndex={-1}
|
|
281
296
|
class="min-w-72"
|
|
297
|
+
// A key pressed as the gallery opens lands on the panel, never on a tile it would pick.
|
|
298
|
+
onOpenAutoFocus={(event: Event) => {
|
|
299
|
+
event.preventDefault();
|
|
300
|
+
panel?.focus({ preventScroll: true });
|
|
301
|
+
}}
|
|
282
302
|
onInteractOutside={(event) => {
|
|
283
303
|
// The delete confirmation takes focus; the gallery stays open to show the result.
|
|
284
304
|
if (pendingDelete()) event.preventDefault();
|
|
@@ -366,7 +386,11 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
366
386
|
selected={props.value === tile.image.id}
|
|
367
387
|
onSelect={() => pick(tile.image.id)}
|
|
368
388
|
onBroken={() => brokenTiles.markBroken(tile.image)}
|
|
369
|
-
onDelete={
|
|
389
|
+
onDelete={
|
|
390
|
+
store?.canRemove === false
|
|
391
|
+
? undefined
|
|
392
|
+
: () => setPendingDelete(tile.image)
|
|
393
|
+
}
|
|
370
394
|
/>
|
|
371
395
|
)
|
|
372
396
|
}
|
|
@@ -418,7 +442,7 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
|
|
|
418
442
|
</SectionMeta>
|
|
419
443
|
)}
|
|
420
444
|
</Show>
|
|
421
|
-
<Show when={store}>
|
|
445
|
+
<Show when={store} fallback={<SectionMeta>{UNAVAILABLE}</SectionMeta>}>
|
|
422
446
|
<input
|
|
423
447
|
ref={fileInput}
|
|
424
448
|
type="file"
|
package/src/solid/index.ts
CHANGED
|
@@ -271,10 +271,13 @@ export {
|
|
|
271
271
|
MediaStoreContext,
|
|
272
272
|
MediaStoreError,
|
|
273
273
|
type MediaStoreErrorKind,
|
|
274
|
+
type MediaUrls,
|
|
275
|
+
MediaUrlsContext,
|
|
274
276
|
type MediaVariant,
|
|
275
277
|
mediaUrl,
|
|
276
278
|
presetValue,
|
|
277
279
|
provideMediaStore,
|
|
280
|
+
provideMediaUrls,
|
|
278
281
|
type StoredMedia,
|
|
279
282
|
sortMediaForClearing,
|
|
280
283
|
useMediaStore,
|
package/src/solid/media-store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, createSignal, useContext } from "solid-js";
|
|
1
|
+
import { type Accessor, createContext, createSignal, useContext } from "solid-js";
|
|
2
2
|
|
|
3
3
|
export type StoredMedia = {
|
|
4
4
|
id: string;
|
|
@@ -49,26 +49,46 @@ export type MediaIndex = {
|
|
|
49
49
|
/** "thumb" is a server-side derivative, longest edge ~400px, for grids. */
|
|
50
50
|
export type MediaVariant = "original" | "thumb";
|
|
51
51
|
|
|
52
|
-
export interface
|
|
52
|
+
export interface MediaUrls {
|
|
53
|
+
url(id: string, variant?: MediaVariant): string | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface MediaStore extends MediaUrls {
|
|
53
57
|
index(): Promise<MediaIndex>;
|
|
54
58
|
upload(file: File): Promise<StoredMedia>;
|
|
55
59
|
remove(id: string): Promise<void>;
|
|
56
60
|
url(id: string, variant?: MediaVariant): string;
|
|
61
|
+
/** false: this holder may not delete, so a gallery offers no Delete. */
|
|
62
|
+
readonly canRemove?: boolean;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/** `null` withholds the store from a tree, even where the host registered one. */
|
|
60
66
|
export const MediaStoreContext = createContext<MediaStore | null>();
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
/** A tree's own url source, over the one the host provided. */
|
|
69
|
+
export const MediaUrlsContext = createContext<MediaUrls>();
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
let defaultStore: Accessor<MediaStore | null> = () => null;
|
|
72
|
+
let defaultUrls: MediaUrls | undefined;
|
|
73
|
+
|
|
74
|
+
/** Host apps call this once at startup; MediaStoreContext overrides it per-tree. An accessor is read each time a picker mounts. */
|
|
75
|
+
export function provideMediaStore(store: MediaStore | Accessor<MediaStore | null>): void {
|
|
76
|
+
defaultStore = typeof store === "function" ? store : () => store;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Resolves stored ids to image urls in a tree that shows images but cannot manage them. */
|
|
80
|
+
export function provideMediaUrls(urls: MediaUrls): void {
|
|
81
|
+
defaultUrls = urls;
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
export function useMediaStore(): MediaStore | undefined {
|
|
70
85
|
const scoped = useContext(MediaStoreContext);
|
|
71
|
-
|
|
86
|
+
if (scoped === null) return undefined;
|
|
87
|
+
return scoped ?? defaultStore() ?? undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function useMediaUrls(): MediaUrls | undefined {
|
|
91
|
+
return useMediaStore() ?? useContext(MediaUrlsContext) ?? defaultUrls;
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
/** One grid page. The picker and the library both slice by this, so neither can
|
|
@@ -124,7 +144,7 @@ export function imagePreset(value: string | null | undefined): string | undefine
|
|
|
124
144
|
|
|
125
145
|
export function mediaUrl(id: string | null | undefined): string | undefined {
|
|
126
146
|
if (!id || imagePreset(id) !== undefined) return undefined;
|
|
127
|
-
return
|
|
147
|
+
return useMediaUrls()?.url(id);
|
|
128
148
|
}
|
|
129
149
|
|
|
130
150
|
/**
|
|
@@ -67,7 +67,11 @@ export function PreviewTile(props: {
|
|
|
67
67
|
props.class,
|
|
68
68
|
)}
|
|
69
69
|
>
|
|
70
|
-
<div
|
|
70
|
+
<div
|
|
71
|
+
data-slot="preview-tile-face"
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
class={cn(TILE_FACE, SHAPE[props.shape ?? "wide"])}
|
|
74
|
+
>
|
|
71
75
|
{props.children}
|
|
72
76
|
</div>
|
|
73
77
|
<Show when={props.caption ?? true} fallback={<span class="sr-only">{props.label}</span>}>
|
|
@@ -25,7 +25,7 @@ import { IconPicker, type IconPickerProps } from "./icon-picker.js";
|
|
|
25
25
|
import { ImagePicker } from "./image-picker.js";
|
|
26
26
|
import { Input } from "./input.js";
|
|
27
27
|
import { createListReorder } from "./list-reorder.js";
|
|
28
|
-
import { type ImagePreset, imagePreset,
|
|
28
|
+
import { type ImagePreset, imagePreset, useMediaUrls } from "./media-store.js";
|
|
29
29
|
import { NumberField } from "./number-field.js";
|
|
30
30
|
import { OptionCard, OptionCardGroup } from "./option-card.js";
|
|
31
31
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
@@ -506,7 +506,7 @@ const LIST_GAP = { class: "gap-2", px: 8 } as const;
|
|
|
506
506
|
|
|
507
507
|
function ListControl(props: FieldProps) {
|
|
508
508
|
const itemSchema = () => itemsOf(props.prop);
|
|
509
|
-
const
|
|
509
|
+
const mediaUrls = useMediaUrls();
|
|
510
510
|
const [brokenThumbs, setBrokenThumbs] = createSignal<ReadonlySet<string>>(new Set());
|
|
511
511
|
|
|
512
512
|
// One image field is unambiguously the row's picture. Two would need the
|
|
@@ -524,10 +524,8 @@ function ListControl(props: FieldProps) {
|
|
|
524
524
|
const preset = imagePreset(id);
|
|
525
525
|
if (preset !== undefined)
|
|
526
526
|
return propertiesOf(itemSchema()).find(([k]) => k === key)?.[1].presets?.[preset]?.thumb;
|
|
527
|
-
const store = mediaStore;
|
|
528
|
-
if (!store) return undefined;
|
|
529
527
|
// A 32px row chip: the thumb variant, never the original.
|
|
530
|
-
return
|
|
528
|
+
return mediaUrls?.url(id, "thumb");
|
|
531
529
|
};
|
|
532
530
|
|
|
533
531
|
const liveThumbUrl = (item: unknown) => {
|
|
@@ -654,7 +652,7 @@ function ListControl(props: FieldProps) {
|
|
|
654
652
|
)}
|
|
655
653
|
aria-hidden="true"
|
|
656
654
|
/>
|
|
657
|
-
<Show when={imageKey() !== undefined &&
|
|
655
|
+
<Show when={imageKey() !== undefined && mediaUrls !== undefined}>
|
|
658
656
|
<span
|
|
659
657
|
class={cn(
|
|
660
658
|
FIELD_CHROME,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
splitProps,
|
|
12
12
|
useContext,
|
|
13
13
|
} from "solid-js";
|
|
14
|
+
import { BALANCED_ROWS, balanceRows } from "../lib/balance-rows.js";
|
|
14
15
|
import { TRACK_SURFACE } from "../lib/card-classes.js";
|
|
15
16
|
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
16
17
|
import { cn } from "../lib/utils.js";
|
|
@@ -48,8 +49,11 @@ const ToggleGroup: ParentComponent<
|
|
|
48
49
|
// union and mistypes `value`. Leave it in `rest` and just peek at it here.
|
|
49
50
|
const sliding = () => !(props as { multiple?: boolean }).multiple;
|
|
50
51
|
let root: HTMLDivElement | undefined;
|
|
52
|
+
let scope: HTMLDivElement | undefined;
|
|
51
53
|
onMount(() => {
|
|
52
|
-
if (
|
|
54
|
+
if (!root) return;
|
|
55
|
+
if (local.scroll) onCleanup(trackScroll(root, "[data-pressed]", "data-pressed"));
|
|
56
|
+
else onCleanup(balanceRows(root, scope ?? root, '[data-slot="toggle-group-item"]'));
|
|
53
57
|
});
|
|
54
58
|
return (
|
|
55
59
|
<ToggleGroupPrimitive
|
|
@@ -59,8 +63,12 @@ const ToggleGroup: ParentComponent<
|
|
|
59
63
|
data-size={local.size}
|
|
60
64
|
data-scroll={local.scroll ? "" : undefined}
|
|
61
65
|
class={cn(
|
|
62
|
-
`group/toggle-group
|
|
63
|
-
local.scroll
|
|
66
|
+
`group/toggle-group w-fit max-w-full items-center gap-y-1 rounded-lg data-[wrapped]:w-full ${TRACK_SURFACE} p-1 data-[variant=outline]:shadow-xs`,
|
|
67
|
+
local.scroll
|
|
68
|
+
? `flex [scrollbar-width:none] flex-nowrap overflow-x-auto ${SCROLL_TRACK_FADE}`
|
|
69
|
+
: sliding()
|
|
70
|
+
? "flex"
|
|
71
|
+
: BALANCED_ROWS,
|
|
64
72
|
local.class,
|
|
65
73
|
)}
|
|
66
74
|
{...rest}
|
|
@@ -70,14 +78,15 @@ const ToggleGroup: ParentComponent<
|
|
|
70
78
|
>
|
|
71
79
|
<Show when={sliding()} fallback={local.children}>
|
|
72
80
|
{/* w-full, not w-fit: a shrink-to-fit root still sizes to content, and a
|
|
73
|
-
`class="w-full"` root can finally let its
|
|
81
|
+
`class="w-full"` root can finally let its items share the width. */}
|
|
74
82
|
<SelectionScope
|
|
83
|
+
ref={scope}
|
|
75
84
|
marker="pressed"
|
|
76
85
|
tone={local.tone}
|
|
77
86
|
class={
|
|
78
87
|
local.scroll
|
|
79
88
|
? "flex w-max flex-nowrap items-center"
|
|
80
|
-
:
|
|
89
|
+
: `w-full items-center gap-y-1 ${BALANCED_ROWS}`
|
|
81
90
|
}
|
|
82
91
|
>
|
|
83
92
|
{local.children}
|
|
@@ -104,7 +113,6 @@ const ToggleGroupItem: Component<
|
|
|
104
113
|
variant: context.variant || local.variant,
|
|
105
114
|
size: context.size || local.size,
|
|
106
115
|
}),
|
|
107
|
-
// Wrapping is plain CSS: an item never shrinks below its label, so a row that runs out of width breaks.
|
|
108
116
|
"relative isolate min-w-max flex-1 shrink-0 rounded-md px-4 shadow-none focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first-of-type:border-l",
|
|
109
117
|
// A hover fill would read as a second, squarer selection, so hover only tints the text.
|
|
110
118
|
context.sliding
|
package/src/styles/globals.css
CHANGED
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
inherits: false;
|
|
84
84
|
initial-value: 0;
|
|
85
85
|
}
|
|
86
|
-
/* 1 when a .glass-halo beside the surface draws its outer glow instead. */
|
|
86
|
+
/* 1 when a .glass-halo beside the surface draws its outer glow and lift shadow instead. */
|
|
87
87
|
@property --glass-halo {
|
|
88
88
|
syntax: "<number>";
|
|
89
89
|
inherits: false;
|
|
@@ -365,15 +365,18 @@
|
|
|
365
365
|
--material-reach: calc(0.35 + var(--glass-lift) * 1.45);
|
|
366
366
|
--_glass-bloom: calc(var(--material-glow) * var(--material-reach) * var(--_material-glow-out));
|
|
367
367
|
}
|
|
368
|
-
/* A surface's outer glow as
|
|
369
|
-
* same tone and lift. Its z-index lifts the glow over neighbouring surfaces;
|
|
370
|
-
* the surface itself sets --glass-halo: 1 so
|
|
368
|
+
/* A surface's outer glow and lift shadow as their own layer, laid over the surface's
|
|
369
|
+
* box with the same tone and lift. Its z-index lifts the glow over neighbouring surfaces;
|
|
370
|
+
* the surface itself sets --glass-halo: 1 so neither is drawn twice. */
|
|
371
371
|
:where(.glass-halo) {
|
|
372
372
|
position: absolute;
|
|
373
373
|
inset: 0;
|
|
374
374
|
z-index: 1;
|
|
375
375
|
pointer-events: none;
|
|
376
|
-
box-shadow:
|
|
376
|
+
box-shadow:
|
|
377
|
+
calc(-10px * var(--_material-light-sin)) calc(10px * var(--_material-light-cos)) 30px -16px
|
|
378
|
+
oklch(0 0 0 / calc(var(--glass-lift) * var(--_material-shadow))),
|
|
379
|
+
0 0 var(--_glass-bloom) oklch(from var(--material-hue) l c h / 0.65);
|
|
377
380
|
}
|
|
378
381
|
|
|
379
382
|
/* The ONE glass formula. Neutral by default (--glass-tone transparent makes
|
|
@@ -452,7 +455,7 @@
|
|
|
452
455
|
inset 0 -2px 4px color-mix(in srgb, var(--glass-tone) var(--glass-glow), transparent),
|
|
453
456
|
0 1px 3px color-mix(in srgb, var(--glass-tone) var(--glass-drop), transparent),
|
|
454
457
|
calc(-10px * var(--_material-light-sin)) calc(10px * var(--_material-light-cos)) 30px -16px
|
|
455
|
-
oklch(0 0 0 / calc(var(--glass-lift) * var(--_material-shadow))),
|
|
458
|
+
oklch(0 0 0 / calc(var(--glass-lift) * var(--_material-shadow) * (1 - var(--glass-halo)))),
|
|
456
459
|
0 0 calc(var(--_glass-bloom) * (1 - var(--glass-halo)))
|
|
457
460
|
oklch(from var(--material-hue) l c h / 0.65),
|
|
458
461
|
inset 0 0 calc(var(--material-glow) * 0.9 * var(--_material-glow-in))
|