@glasshome/ui 1.35.4 → 1.37.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.
Files changed (40) hide show
  1. package/SPEC.md +11 -1
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.js +3 -3
  4. package/dist/lib/balance-rows.d.ts +7 -0
  5. package/dist/lib/dock-slot-classes.d.ts +1 -0
  6. package/dist/lib/hold.d.ts +33 -1
  7. package/dist/lib/motion-classes.d.ts +2 -0
  8. package/dist/solid/dock-edit.d.ts +28 -0
  9. package/dist/solid/dock-paging.d.ts +13 -0
  10. package/dist/solid/dock.d.ts +18 -1
  11. package/dist/solid/face-toggle.d.ts +17 -0
  12. package/dist/solid/glyph-tile.d.ts +18 -0
  13. package/dist/solid/icon-picker.d.ts +4 -0
  14. package/dist/solid/index.d.ts +8 -4
  15. package/dist/solid/index.js +5894 -5224
  16. package/dist/solid/media-store.d.ts +14 -3
  17. package/dist/solid/preview-tile.d.ts +14 -0
  18. package/dist/solid/slot-button.d.ts +9 -0
  19. package/dist/{utils-BhU5YZKh.js → utils-Duqv3Sgo.js} +680 -624
  20. package/package.json +1 -1
  21. package/src/index.ts +2 -1
  22. package/src/lib/balance-rows.ts +62 -0
  23. package/src/lib/dock-slot-classes.ts +4 -0
  24. package/src/lib/hold.ts +154 -3
  25. package/src/lib/motion-classes.ts +11 -0
  26. package/src/solid/dashboard-preview.tsx +21 -4
  27. package/src/solid/dock-edit.tsx +267 -0
  28. package/src/solid/dock-paging.ts +37 -0
  29. package/src/solid/dock.tsx +254 -73
  30. package/src/solid/face-toggle.tsx +93 -0
  31. package/src/solid/glyph-tile.tsx +77 -0
  32. package/src/solid/icon-picker.tsx +40 -21
  33. package/src/solid/image-picker.tsx +39 -15
  34. package/src/solid/index.ts +10 -3
  35. package/src/solid/media-store.ts +28 -8
  36. package/src/solid/preview-tile.tsx +75 -4
  37. package/src/solid/schema-form.tsx +4 -6
  38. package/src/solid/slot-button.tsx +45 -0
  39. package/src/solid/toggle-group.tsx +14 -6
  40. package/src/styles/theme.css +31 -0
@@ -6,7 +6,8 @@ import { cn } from "../lib/utils.js";
6
6
  import { Icon, iconSearch } from "./icon.js";
7
7
  import { PickerSearch } from "./picker-search.js";
8
8
  import { PickerTrigger } from "./picker-trigger.js";
9
- import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
9
+ import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover.js";
10
+ import { SlotButton } from "./slot-button.js";
10
11
 
11
12
  export const ICON_SEARCH_DEBOUNCE_MS = 300;
12
13
 
@@ -257,7 +258,11 @@ export interface IconPickerProps {
257
258
  value: string;
258
259
  onChange: (value: string) => void;
259
260
  placeholder?: string;
261
+ /** `slot` is a dock-shaped button showing the icon, for a form that is picking what a dock item will wear. */
262
+ variant?: "field" | "slot";
260
263
  class?: string;
264
+ /** Names a `slot` trigger, which shows no text of its own. */
265
+ "aria-label"?: string;
261
266
  /** @deprecated Pass `search` to `provideIcons` once; removed in 2.0.0. */
262
267
  searchIcons?: (query: string, prefix: string) => Promise<string[]>;
263
268
  /** Id of the element naming the trigger, for forms that label it outside. */
@@ -265,6 +270,7 @@ export interface IconPickerProps {
265
270
  }
266
271
 
267
272
  export function IconPicker(props: IconPickerProps) {
273
+ const slot = () => props.variant === "slot";
268
274
  const [open, setOpen] = createSignal(false);
269
275
  const [search, setSearch] = createSignal("");
270
276
  const [activeLib, setActiveLib] = createSignal("");
@@ -334,30 +340,43 @@ export function IconPicker(props: IconPickerProps) {
334
340
  };
335
341
 
336
342
  return (
337
- <Popover surface="field" open={open()} onOpenChange={setOpen} modal>
338
- <PopoverAnchor as="div" class={props.class}>
339
- <PickerTrigger
340
- slot="icon-picker-trigger"
341
- open={open()}
342
- onToggle={() => setOpen(!open())}
343
+ <Popover surface={slot() ? "overlay" : "field"} open={open()} onOpenChange={setOpen} modal>
344
+ <Show when={slot()}>
345
+ <PopoverTrigger
346
+ as={SlotButton}
347
+ aria-label={props["aria-label"] ?? "Icon"}
343
348
  aria-labelledby={props["aria-labelledby"]}
344
- onClear={props.value.trim() ? clearIcon : undefined}
345
- clearLabel="Clear icon"
349
+ class={props.class}
346
350
  >
347
- <Show
348
- when={props.value.trim()}
349
- fallback={
350
- <span class="text-muted-foreground flex-1 text-left">
351
- {props.placeholder ?? "mdi:home"}
352
- </span>
353
- }
351
+ <Icon icon={props.value.trim() || "lucide:smile-plus"} width={22} height={22} />
352
+ </PopoverTrigger>
353
+ </Show>
354
+ <Show when={!slot()}>
355
+ <PopoverAnchor as="div" class={props.class}>
356
+ <PickerTrigger
357
+ slot="icon-picker-trigger"
358
+ open={open()}
359
+ onToggle={() => setOpen(!open())}
360
+ aria-labelledby={props["aria-labelledby"]}
361
+ onClear={props.value.trim() ? clearIcon : undefined}
362
+ clearLabel="Clear icon"
354
363
  >
355
- <Icon icon={props.value.trim()} width={18} height={18} class="shrink-0" />
356
- <span class="flex-1 truncate text-left">{props.value}</span>
357
- </Show>
358
- </PickerTrigger>
359
- </PopoverAnchor>
364
+ <Show
365
+ when={props.value.trim()}
366
+ fallback={
367
+ <span class="text-muted-foreground flex-1 text-left">
368
+ {props.placeholder ?? "mdi:home"}
369
+ </span>
370
+ }
371
+ >
372
+ <Icon icon={props.value.trim()} width={18} height={18} class="shrink-0" />
373
+ <span class="flex-1 truncate text-left">{props.value}</span>
374
+ </Show>
375
+ </PickerTrigger>
376
+ </PopoverAnchor>
377
+ </Show>
360
378
  <PopoverContent
379
+ class={slot() ? "w-[min(22rem,calc(100vw-2rem))] p-0" : undefined}
361
380
  onOpenAutoFocus={(e) => {
362
381
  e.preventDefault();
363
382
  // preventScroll: the panel is portalled at (0,0) until the popper places it,
@@ -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">This dashboard cannot store images.</Alert>
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 GalleryTile =
91
- | { kind: "preset"; key: string; preset: ImagePreset }
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(props: ImagePickerProps & { store: MediaStore | undefined }) {
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
- // Built-in pictures lead the grid; the household's uploads follow them.
153
- const tiles = createMemo<GalleryTile[]>(() => [
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
- ...sorted().map((image): GalleryTile => ({ kind: "media", image })),
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() ?? store)}
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 ?? store?.url(props.value)}
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={() => setPendingDelete(tile.image)}
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"
@@ -6,7 +6,8 @@ export { type Color, parseColor } from "@kobalte/core/colors";
6
6
  // Floating glass panel + its shared surface token.
7
7
  export { SECTION_ROW_SURFACE } from "../lib/card-classes.js";
8
8
  export { copyImage, copyText } from "../lib/clipboard.js";
9
- export { HOLD_GRACE_MS, HOLD_MS, spendLongPress } from "../lib/hold.js";
9
+ export { createHold, HOLD_GRACE_MS, HOLD_MS, spendLongPress } from "../lib/hold.js";
10
+ export type { Hold, HoldOptions, HoldPress } from "../lib/hold.js";
10
11
  export { RISE_MOTION, SETTLE_MOTION, TRAVEL_MOTION } from "../lib/motion-classes.js";
11
12
  export { OVERLAY_SURFACE } from "../lib/overlay-classes.js";
12
13
  // Section tokens re-exported from the Solid entry for convenience.
@@ -152,7 +153,7 @@ export {
152
153
  DialogTrigger,
153
154
  } from "./dialog.js";
154
155
  export type { ModalSize } from "./dialog-parts.js";
155
- export type { DockIconButtonProps, DockItem, DockProps } from "./dock.js";
156
+ export type { DockIconButtonProps, DockItem, DockPlacement, DockProps } from "./dock.js";
156
157
  export { Dock } from "./dock.js";
157
158
  export {
158
159
  DockedPanel,
@@ -271,10 +272,13 @@ export {
271
272
  MediaStoreContext,
272
273
  MediaStoreError,
273
274
  type MediaStoreErrorKind,
275
+ type MediaUrls,
276
+ MediaUrlsContext,
274
277
  type MediaVariant,
275
278
  mediaUrl,
276
279
  presetValue,
277
280
  provideMediaStore,
281
+ provideMediaUrls,
278
282
  type StoredMedia,
279
283
  sortMediaForClearing,
280
284
  useMediaStore,
@@ -299,7 +303,7 @@ export { PickerSearch, type PickerSearchProps } from "./picker-search.js";
299
303
  export { PickerTrigger, type PickerTriggerProps } from "./picker-trigger.js";
300
304
  export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover.js";
301
305
  export { PortalMountContext, usePortalMount } from "./portal-mount.js";
302
- export { PreviewTile, PreviewTileGroup } from "./preview-tile.js";
306
+ export { PreviewTile, PreviewTileAction, PreviewTileGroup } from "./preview-tile.js";
303
307
  export { Progress } from "./progress.js";
304
308
  export { RadioGroup, RadioGroupItem } from "./radio-group.js";
305
309
  export { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "./resizable.js";
@@ -367,11 +371,14 @@ export {
367
371
  SheetTrigger,
368
372
  } from "./sheet.js";
369
373
  export { Skeleton } from "./skeleton.js";
374
+ export { SlotButton, type SlotButtonProps } from "./slot-button.js";
370
375
  export { Slider } from "./slider.js";
371
376
  export { SelectionHighlight, type SelectionMarker, SelectionScope } from "./selection.js";
372
377
  export { SlidingIndicator } from "./sliding-indicator.js";
373
378
  // Wave 4: React-Library Alternatives - Simpler
374
379
  export { GlassToast, Toaster, toast } from "./sonner.js";
380
+ export { FaceToggle, FaceToggleGroup } from "./face-toggle.js";
381
+ export { GlyphTile, GlyphTileGroup } from "./glyph-tile.js";
375
382
  export { Spinner } from "./spinner.js";
376
383
  export { Spotlight } from "./spotlight.js";
377
384
  export { StepIndicator } from "./step-indicator.js";
@@ -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 MediaStore {
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
- let defaultStore: MediaStore | undefined;
68
+ /** A tree's own url source, over the one the host provided. */
69
+ export const MediaUrlsContext = createContext<MediaUrls>();
63
70
 
64
- /** Host apps call this once at startup; MediaStoreContext overrides it per-tree. */
65
- export function provideMediaStore(store: MediaStore): void {
66
- defaultStore = store;
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
- return scoped === null ? undefined : (scoped ?? defaultStore);
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 useMediaStore()?.url(id);
147
+ return useMediaUrls()?.url(id);
128
148
  }
129
149
 
130
150
  /**
@@ -1,12 +1,13 @@
1
1
  import type { JSX } from "solid-js";
2
- import { Show } from "solid-js";
2
+ import { children, onCleanup, onMount, Show } from "solid-js";
3
+ import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
3
4
  import { cn } from "../lib/utils.js";
4
5
  import { Icon } from "./icon.js";
5
6
  import { isItemActivation, RadioGroup, RadioGroupItem } from "./radio-group.js";
6
7
 
7
8
  const COLUMNS = { 2: "grid-cols-2", 3: "grid-cols-3", 4: "grid-cols-4" } as const;
8
9
 
9
- const SHAPE = { wide: "aspect-[16/10]", tile: "aspect-[5/4]" } as const;
10
+ const SHAPE = { film: "aspect-video", wide: "aspect-[16/10]", tile: "aspect-[5/4]" } as const;
10
11
 
11
12
  /* The face is the affordance: the radio control is suppressed and a ring on
12
13
  * the face carries the picked state, the focus ring rides the same edge.
@@ -14,18 +15,38 @@ const SHAPE = { wide: "aspect-[16/10]", tile: "aspect-[5/4]" } as const;
14
15
  const TILE_FACE =
15
16
  "relative w-full overflow-hidden rounded-lg border border-border/60 transition-glass duration-200 group-active/preview-tile:scale-[0.97] group-data-[checked]/preview-tile:border-transparent after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-[inherit] after:ring-inset after:transition-glass group-data-[checked]/preview-tile:after:ring-2 group-data-[checked]/preview-tile:after:ring-primary group-has-[:focus-visible]/preview-tile:after:ring-[3px] group-has-[:focus-visible]/preview-tile:after:ring-ring/50";
16
17
 
18
+ const SM_COLUMNS = { 2: "sm:grid-cols-2", 3: "sm:grid-cols-3", 4: "sm:grid-cols-4" } as const;
19
+
20
+ /* A row of fixed-width tiles below `sm`, faded where it is clipped; a grid from `sm` up.
21
+ * The caller bleeds the row to its container's edge with a negative margin and matching padding. */
22
+ const SCROLL_ROW = `relative flex flex-row overflow-x-auto overscroll-x-contain snap-x snap-proximity py-0.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden ${SCROLL_TRACK_FADE} sm:grid sm:overflow-visible [&>*]:w-39 [&>*]:shrink-0 [&>*]:snap-start sm:[&>*]:w-auto`;
23
+
17
24
  export function PreviewTileGroup(props: {
18
25
  value: string | null;
19
26
  onChange: (value: string) => void;
20
27
  "aria-label": string;
21
28
  columns?: keyof typeof COLUMNS;
29
+ /** A row that scrolls sideways below `sm`, a grid of `columns` from `sm` up. */
30
+ scroll?: boolean;
22
31
  class?: string;
23
32
  children: JSX.Element;
24
33
  }) {
34
+ let group: HTMLElement | undefined;
35
+ onMount(() => {
36
+ if (props.scroll && group) onCleanup(trackScroll(group, "[data-checked]", "data-checked"));
37
+ });
25
38
  return (
26
39
  <RadioGroup
40
+ ref={(el: HTMLElement) => {
41
+ group = el;
42
+ }}
27
43
  data-slot="preview-tile-group"
28
- class={cn("grid gap-2.5", COLUMNS[props.columns ?? 2], props.class)}
44
+ class={cn(
45
+ props.scroll
46
+ ? `gap-2 ${SCROLL_ROW} ${SM_COLUMNS[props.columns ?? 2]} sm:gap-x-3 sm:gap-y-4`
47
+ : `grid gap-2.5 ${COLUMNS[props.columns ?? 2]}`,
48
+ props.class,
49
+ )}
29
50
  value={props.value ?? ""}
30
51
  onChange={props.onChange}
31
52
  aria-label={props["aria-label"]}
@@ -35,6 +56,50 @@ export function PreviewTileGroup(props: {
35
56
  );
36
57
  }
37
58
 
59
+ /** A button among the tiles that picks nothing: the way to a larger set. A glyph draws a dashed face; children draw a picture on a solid one. */
60
+ export function PreviewTileAction(props: {
61
+ label: string;
62
+ icon?: string;
63
+ onClick?: () => void;
64
+ shape?: keyof typeof SHAPE;
65
+ class?: string;
66
+ children?: JSX.Element;
67
+ }) {
68
+ const picture = children(() => props.children);
69
+ return (
70
+ <button
71
+ type="button"
72
+ data-slot="preview-tile-action"
73
+ onClick={() => props.onClick?.()}
74
+ class={cn("group/preview-tile-action flex min-w-0 flex-col gap-1.5 text-start", props.class)}
75
+ >
76
+ <div
77
+ data-slot="preview-tile-face"
78
+ aria-hidden="true"
79
+ class={cn(
80
+ "border-border transition-glass after:transition-glass group-focus-visible/preview-tile-action:after:ring-ring/50 relative w-full overflow-hidden rounded-lg border duration-200 group-active/preview-tile-action:scale-[0.97] after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-[inherit] after:ring-inset group-focus-visible/preview-tile-action:after:ring-[3px]",
81
+ picture()
82
+ ? "border-border/60 group-hover/preview-tile-action:border-border"
83
+ : "text-muted-foreground group-hover/preview-tile-action:text-foreground grid place-items-center border-dashed",
84
+ SHAPE[props.shape ?? "wide"],
85
+ )}
86
+ >
87
+ <Show
88
+ when={picture()}
89
+ fallback={
90
+ <Show when={props.icon}>{(icon) => <Icon icon={icon()} width={20} height={20} />}</Show>
91
+ }
92
+ >
93
+ {picture()}
94
+ </Show>
95
+ </div>
96
+ <span data-slot="preview-tile-caption" class="text-foreground truncate text-xs font-medium">
97
+ {props.label}
98
+ </span>
99
+ </button>
100
+ );
101
+ }
102
+
38
103
  /** A choice shown as what it produces: a picture, a preview card, a shape. */
39
104
  export function PreviewTile(props: {
40
105
  value: string;
@@ -47,6 +112,8 @@ export function PreviewTile(props: {
47
112
  /** Beside the caption, after the label: provenance like `SourceMarks`. */
48
113
  marks?: JSX.Element;
49
114
  shape?: keyof typeof SHAPE;
115
+ /** An outline face with its content centred, for the choice that adds nothing. */
116
+ dashed?: boolean;
50
117
  disabled?: boolean;
51
118
  class?: string;
52
119
  /** Fires on every click, including a re-pick of the checked tile. */
@@ -70,7 +137,11 @@ export function PreviewTile(props: {
70
137
  <div
71
138
  data-slot="preview-tile-face"
72
139
  aria-hidden="true"
73
- class={cn(TILE_FACE, SHAPE[props.shape ?? "wide"])}
140
+ class={cn(
141
+ TILE_FACE,
142
+ SHAPE[props.shape ?? "wide"],
143
+ props.dashed && "text-muted-foreground grid place-items-center border-dashed",
144
+ )}
74
145
  >
75
146
  {props.children}
76
147
  </div>
@@ -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, useMediaStore } from "./media-store.js";
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 mediaStore = useMediaStore();
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 store.url(id, "thumb");
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 && mediaStore !== undefined}>
655
+ <Show when={imageKey() !== undefined && mediaUrls !== undefined}>
658
656
  <span
659
657
  class={cn(
660
658
  FIELD_CHROME,
@@ -0,0 +1,45 @@
1
+ import { type JSX, Show, splitProps } from "solid-js";
2
+ import { DOCK_SLOT_SHAPE } from "../lib/dock-slot-classes.js";
3
+ import { FIELD_CHROME } from "../lib/input-classes.js";
4
+ import { cn } from "../lib/utils.js";
5
+
6
+ export interface SlotButtonProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
7
+ /** An empty place for something to land: the add slot's dashed outline. */
8
+ dashed?: boolean;
9
+ /** A name under the slot; it names the button too. */
10
+ label?: string;
11
+ }
12
+
13
+ /** A button in the dock's slot shape: it holds the icon a dock item will wear. */
14
+ export function SlotButton(props: SlotButtonProps) {
15
+ const [own, rest] = splitProps(props, ["dashed", "label", "class", "children"]);
16
+ return (
17
+ <button
18
+ type="button"
19
+ data-slot="slot-button"
20
+ class={cn(
21
+ "group/slot-button flex min-w-0 touch-manipulation flex-col items-center gap-1.5 rounded-lg text-xs font-medium outline-none",
22
+ own.class,
23
+ )}
24
+ {...rest}
25
+ >
26
+ <span
27
+ data-slot="slot-button-face"
28
+ class={cn(
29
+ DOCK_SLOT_SHAPE,
30
+ "transition-glass group-focus-visible/slot-button:ring-ring/50 shrink-0 duration-200 group-focus-visible/slot-button:ring-[3px] group-active/slot-button:scale-[0.97]",
31
+ own.dashed
32
+ ? "text-muted-foreground border-foreground/30 group-hover/slot-button:text-foreground group-hover/slot-button:border-foreground/60 border-2 border-dashed"
33
+ : `${FIELD_CHROME} text-foreground`,
34
+ )}
35
+ >
36
+ {own.children}
37
+ </span>
38
+ <Show when={own.label}>
39
+ <span data-slot="slot-button-label" class="text-foreground max-w-full truncate">
40
+ {own.label}
41
+ </span>
42
+ </Show>
43
+ </button>
44
+ );
45
+ }
@@ -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 (local.scroll && root) onCleanup(trackScroll(root, "[data-pressed]", "data-pressed"));
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 flex w-fit max-w-full flex-wrap items-center gap-y-1 rounded-lg ${TRACK_SURFACE} p-1 data-[variant=outline]:shadow-xs`,
63
- local.scroll && `[scrollbar-width:none] flex-nowrap overflow-x-auto ${SCROLL_TRACK_FADE}`,
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 flex-1 items share the width. */}
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
- : "flex w-full flex-wrap items-center gap-y-1"
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