@glasshome/ui 1.36.0 → 1.37.1

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.
@@ -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,
@@ -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,
@@ -302,7 +303,7 @@ export { PickerSearch, type PickerSearchProps } from "./picker-search.js";
302
303
  export { PickerTrigger, type PickerTriggerProps } from "./picker-trigger.js";
303
304
  export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover.js";
304
305
  export { PortalMountContext, usePortalMount } from "./portal-mount.js";
305
- export { PreviewTile, PreviewTileGroup } from "./preview-tile.js";
306
+ export { PreviewTile, PreviewTileAction, PreviewTileGroup } from "./preview-tile.js";
306
307
  export { Progress } from "./progress.js";
307
308
  export { RadioGroup, RadioGroupItem } from "./radio-group.js";
308
309
  export { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "./resizable.js";
@@ -370,11 +371,14 @@ export {
370
371
  SheetTrigger,
371
372
  } from "./sheet.js";
372
373
  export { Skeleton } from "./skeleton.js";
374
+ export { SlotButton, type SlotButtonProps } from "./slot-button.js";
373
375
  export { Slider } from "./slider.js";
374
376
  export { SelectionHighlight, type SelectionMarker, SelectionScope } from "./selection.js";
375
377
  export { SlidingIndicator } from "./sliding-indicator.js";
376
378
  // Wave 4: React-Library Alternatives - Simpler
377
379
  export { GlassToast, Toaster, toast } from "./sonner.js";
380
+ export { FaceToggle, FaceToggleGroup } from "./face-toggle.js";
381
+ export { GlyphTile, GlyphTileGroup } from "./glyph-tile.js";
378
382
  export { Spinner } from "./spinner.js";
379
383
  export { Spotlight } from "./spotlight.js";
380
384
  export { StepIndicator } from "./step-indicator.js";
@@ -2,6 +2,7 @@ import { type JSX, Show, splitProps } from "solid-js";
2
2
  import { PICKER_TRIGGER } from "../lib/picker-classes.js";
3
3
  import { cn } from "../lib/utils.js";
4
4
  import { Icon } from "./icon.js";
5
+ import { useAnchorTrigger } from "./popover.js";
5
6
 
6
7
  export interface PickerTriggerProps extends Omit<
7
8
  JSX.ButtonHTMLAttributes<HTMLButtonElement>,
@@ -25,11 +26,17 @@ export function PickerTrigger(props: PickerTriggerProps) {
25
26
  "clearLabel",
26
27
  "class",
27
28
  "children",
29
+ "ref",
28
30
  ]);
31
+ const anchorTrigger = useAnchorTrigger();
29
32
 
30
33
  return (
31
34
  <div class="relative">
32
35
  <button
36
+ ref={(el) => {
37
+ anchorTrigger?.(el);
38
+ if (typeof own.ref === "function") own.ref(el);
39
+ }}
33
40
  type="button"
34
41
  data-slot={own.slot}
35
42
  data-expanded={own.open || undefined}
@@ -122,8 +122,19 @@ const PopoverContent: Component<PopoverContentProps> = (props) => {
122
122
  );
123
123
  };
124
124
 
125
+ /** Inside a PopoverAnchor: names the control that opens the popover, so focus goes back to it on close. */
126
+ const AnchorTriggerContext = createContext<(el: HTMLElement) => void>();
127
+
125
128
  const PopoverAnchor: Component<ComponentProps<typeof PopoverPrimitive.Anchor>> = (props) => {
126
- return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
129
+ const popover = usePopoverContext();
130
+ return (
131
+ <AnchorTriggerContext.Provider value={popover.setTriggerRef}>
132
+ <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
133
+ </AnchorTriggerContext.Provider>
134
+ );
127
135
  };
128
136
 
129
- export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger };
137
+ /** The control, inside a PopoverAnchor, that opens its popover. */
138
+ const useAnchorTrigger = () => useContext(AnchorTriggerContext);
139
+
140
+ export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger, useAnchorTrigger };
@@ -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>
@@ -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
+ }
@@ -82,6 +82,29 @@
82
82
  --animate-morph-out: morph-out calc(var(--duration-morph) / 2) var(--ease-contract) both;
83
83
  /* Unfilled once done, so the anchored panel's clip lets go and its shadow shows. */
84
84
  --animate-anchored-in: morph-in var(--duration-morph) var(--ease-morph) backwards;
85
+
86
+ /* A newcomer's glow: shown at once, gone by the end, nothing left behind. */
87
+ --animate-dock-arrive: dock-arrive var(--duration-arrive) var(--ease-emphasis) both;
88
+ /* Edit mode's sway: a loop that lasts exactly as long as the mode. */
89
+ --animate-dock-jiggle: dock-jiggle var(--duration-jiggle) ease-in-out infinite alternate;
90
+ }
91
+
92
+ @keyframes dock-jiggle {
93
+ from {
94
+ rotate: -1.4deg;
95
+ }
96
+ to {
97
+ rotate: 1.4deg;
98
+ }
99
+ }
100
+
101
+ @keyframes dock-arrive {
102
+ from {
103
+ opacity: 1;
104
+ }
105
+ to {
106
+ opacity: 0;
107
+ }
85
108
  }
86
109
 
87
110
  @keyframes collapsible-down {
@@ -294,6 +317,10 @@
294
317
  --duration-slide: 220ms;
295
318
  /* The hold fill: HOLD_MS - HOLD_GRACE_MS (lib/hold.ts), so it completes as the hold fires. */
296
319
  --duration-hold: 250ms;
320
+ /* How long a newcomer in the dock glows (DOCK_ARRIVE_MOTION). */
321
+ --duration-arrive: 2400ms;
322
+ /* One sway of the dock's edit mode (DOCK_EDIT_MOTION). */
323
+ --duration-jiggle: 140ms;
297
324
  /* Ambient motion is an event (SPEC motion rule 5): 1 while the host holds
298
325
  * html[data-motion="live"], else 0. Inherits into widget shadow roots, so a
299
326
  * loop multiplies its duration by it: calc(var(--motion-ambient, 0) * 1s).
@@ -583,6 +610,8 @@ html[data-motion="live"] {
583
610
  --duration-expand: 0ms;
584
611
  --duration-morph: 0ms;
585
612
  --duration-hold: 0ms;
613
+ --duration-arrive: 0ms;
614
+ --duration-jiggle: 0ms;
586
615
  --duration-slide: 0ms;
587
616
  }
588
617
  /* tw-animate enter/exit classes carry their own fallback duration. */
@@ -612,6 +641,8 @@ html[data-motion="live"] {
612
641
  --duration-expand: 0ms;
613
642
  --duration-morph: 0ms;
614
643
  --duration-hold: 0ms;
644
+ --duration-arrive: 0ms;
645
+ --duration-jiggle: 0ms;
615
646
  --duration-slide: 0ms;
616
647
  }
617
648
  .reduce-motion,