@glasshome/ui 1.31.1 → 1.32.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.
@@ -1,11 +1,8 @@
1
1
  import { DropdownMenu as MenuPrimitive } from "@kobalte/core/dropdown-menu";
2
2
  import { type Component, type ComponentProps, type ParentComponent } from "solid-js";
3
3
  export declare const MENU_CONTENT_CLASS: string;
4
- /** Every menu content and sub content wraps its rows in one sliding highlight,
5
- * keyed off Kobalte's roving-focus attribute. The highlighted row's own
6
- * --glass-tone (set inline by MenuItemPart) is mirrored onto the indicator,
7
- * since --glass-tone does not inherit and the indicator is a sibling, not
8
- * an ancestor, of the rows it highlights. */
4
+ /** Every menu content and sub content wraps its rows in one selection scope, keyed off
5
+ * Kobalte's highlighted row. */
9
6
  export declare const MenuContentIndicator: ParentComponent;
10
7
  type ToneProps = {
11
8
  tone?: string;
@@ -0,0 +1,21 @@
1
+ import { type ComponentProps, type JSX } from "solid-js";
2
+ /** The attribute (without `data-`) that marks the active item: Kobalte's, or the caller's own. */
3
+ export type SelectionMarker = "pressed" | "selected" | "highlighted" | "lit";
4
+ /**
5
+ * The glass behind an item while it is the active one. Render it as the first child of every
6
+ * item inside a `SelectionScope`; CSS shows the one whose item carries the scope's marker, so
7
+ * layout keeps it in place and nothing measures it at rest. Renders nothing outside a scope.
8
+ */
9
+ export declare function SelectionHighlight(): JSX.Element;
10
+ interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
11
+ marker: SelectionMarker;
12
+ /** CSS colour for the highlight's glass. Default `var(--material-accent)`. */
13
+ tone?: string;
14
+ style?: JSX.CSSProperties;
15
+ }
16
+ /**
17
+ * Wraps items that each render a `SelectionHighlight`. When the marker moves to another item,
18
+ * one flyer animates from the old item to the new one and hands off to its resting highlight.
19
+ */
20
+ export declare function SelectionScope(props: SelectionScopeProps): JSX.Element;
21
+ export {};
@@ -30,5 +30,6 @@ interface SlidingIndicatorProps extends ComponentProps<"div"> {
30
30
  wrapped?: boolean;
31
31
  children: JSX.Element;
32
32
  }
33
+ /** @deprecated Use `SelectionScope` with a `SelectionHighlight` in each item; removed in 2.0. */
33
34
  export declare function SlidingIndicator(props: SlidingIndicatorProps): JSX.Element;
34
35
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.31.1",
3
+ "version": "1.32.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "keywords": [
6
6
  "components",
@@ -1,5 +1,5 @@
1
1
  /* One menu row, label and separator for every listbox and menu (Select,
2
- * DropdownMenu, ContextMenu, pickers). Highlight comes from SlidingIndicator,
2
+ * DropdownMenu, ContextMenu, pickers). Highlight comes from SelectionHighlight,
3
3
  * so the row itself paints no background. A toned row (MenuItemPart sets
4
4
  * data-tone) guards off the muted svg color so its icon inherits the row's
5
5
  * own currentColor instead.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * A panel that opens on pointerdown under the pointer (an overlaid Select, a menu anchored on
3
+ * its trigger) would receive that press's release, and Kobalte acts on release. Only a press
4
+ * that starts inside the panel may act; with or without an opening animation.
5
+ */
6
+ export function ignoreOpeningRelease(panel: HTMLElement): () => void {
7
+ let pressedInside = false;
8
+ const onDown = () => {
9
+ pressedInside = true;
10
+ };
11
+ const onUp = (event: PointerEvent) => {
12
+ if (pressedInside) {
13
+ pressedInside = false;
14
+ return;
15
+ }
16
+ event.stopPropagation();
17
+ event.preventDefault();
18
+ };
19
+ panel.addEventListener("pointerdown", onDown, true);
20
+ panel.addEventListener("pointerup", onUp, true);
21
+ return () => {
22
+ panel.removeEventListener("pointerdown", onDown, true);
23
+ panel.removeEventListener("pointerup", onUp, true);
24
+ };
25
+ }
@@ -9,7 +9,7 @@ import { PickerRow } from "./picker-row.js";
9
9
  import { PickerSearch } from "./picker-search.js";
10
10
  import { PickerTrigger } from "./picker-trigger.js";
11
11
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
12
- import { SlidingIndicator } from "./sliding-indicator.js";
12
+ import { SelectionScope } from "./selection.js";
13
13
 
14
14
  interface AreaPickerBaseProps {
15
15
  placeholder?: string;
@@ -87,9 +87,7 @@ export function AreaPicker(props: AreaPickerProps) {
87
87
  return only.length === 1 ? areaList().find((a) => a.id === only[0]) : undefined;
88
88
  });
89
89
 
90
- // One glass pill (SlidingIndicator) tracks the highlighted row and animates
91
- // between rows, exactly like the Select. Hover wins; otherwise the pill rests
92
- // on a selected row, which in multi mode is the first one still listed.
90
+ // Hover wins; otherwise the highlight rests on a selected row (in multi mode the first still listed).
93
91
  const [hovered, setHovered] = createSignal<string | null>(null);
94
92
  const restingId = createMemo(() => {
95
93
  const list = filtered();
@@ -183,10 +181,8 @@ export function AreaPicker(props: AreaPickerProps) {
183
181
  placeholder="Search areas..."
184
182
  aria-label="Search areas"
185
183
  />
186
- <SlidingIndicator
187
- activeSelector="[data-highlighted]"
188
- orientation="vertical"
189
- indicatorClass="rounded-sm"
184
+ <SelectionScope
185
+ marker="highlighted"
190
186
  class={cn("flex flex-col gap-0.5 p-1", STAGGER, PICKER_LIST)}
191
187
  onMouseLeave={() => setHovered(null)}
192
188
  >
@@ -222,7 +218,7 @@ export function AreaPicker(props: AreaPickerProps) {
222
218
  />
223
219
  )}
224
220
  </For>
225
- </SlidingIndicator>
221
+ </SelectionScope>
226
222
  </div>
227
223
  </PopoverContent>
228
224
  </Popover>
@@ -18,7 +18,7 @@ import { HOLD_MOTION, PRESS_DIP } from "../lib/motion-classes.js";
18
18
  import { cn } from "../lib/utils.js";
19
19
  import { Badge } from "./badge.js";
20
20
  import { pageCount, pageOf, pageOffset, stripWidth } from "./dock-paging.js";
21
- import { SlidingIndicator } from "./sliding-indicator.js";
21
+ import { SelectionHighlight, SelectionScope } from "./selection.js";
22
22
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
23
23
 
24
24
  interface DockItem {
@@ -48,7 +48,7 @@ interface DockIconButtonProps extends ComponentProps<"button"> {
48
48
  icon: Component<{ class?: string }> | JSX.Element;
49
49
  label: string;
50
50
  isActive?: boolean;
51
- /** Sits on the sliding pill: the active item, or the one a drag would land on. */
51
+ /** Wears the selection highlight: the active item, or the one a drag would land on. */
52
52
  lit?: boolean;
53
53
  badge?: number;
54
54
  }
@@ -73,14 +73,16 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
73
73
  type="button"
74
74
  data-slot="dock-item"
75
75
  class={cn(
76
- "group relative flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
76
+ "group relative isolate flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
77
77
  PRESS_DIP,
78
78
  local.class,
79
79
  )}
80
80
  aria-label={local.label}
81
81
  aria-current={local.isActive ? "page" : undefined}
82
+ data-lit={local.lit ? "" : undefined}
82
83
  {...rest}
83
84
  >
85
+ <SelectionHighlight />
84
86
  <div
85
87
  data-slot="dock-item-icon"
86
88
  class={cn(
@@ -146,7 +148,6 @@ const Dock: Component<DockProps> = (props) => {
146
148
  const [page, setPage] = createSignal(0);
147
149
  const [viewportWidth, setViewportWidth] = createSignal(0);
148
150
 
149
- // The moving background: the shared SlidingIndicator tracks the active item.
150
151
  // A memo: the items list is rebuilt on every hover change, and only a new active item may scroll the strip.
151
152
  const activeIndex = createMemo(() => {
152
153
  const i = local.items.findIndex((it) => it.isActive);
@@ -331,7 +332,7 @@ const Dock: Component<DockProps> = (props) => {
331
332
  "min-width": needsScroll() ? "auto" : "fit-content",
332
333
  }}
333
334
  >
334
- <SlidingIndicator active={pillIndex()} class="flex items-center gap-0.5 sm:gap-1">
335
+ <SelectionScope marker="lit" class="flex items-center gap-0.5 sm:gap-1">
335
336
  <Index each={local.items}>
336
337
  {(item, i) => (
337
338
  <DockIconButton
@@ -347,7 +348,7 @@ const Dock: Component<DockProps> = (props) => {
347
348
  />
348
349
  )}
349
350
  </Index>
350
- </SlidingIndicator>
351
+ </SelectionScope>
351
352
  </div>
352
353
  <Show when={pages() > 1}>
353
354
  <div
@@ -26,7 +26,7 @@ import { PICKER_ROW_HEIGHT, PickerRow } from "./picker-row.js";
26
26
  import { PickerSearch } from "./picker-search.js";
27
27
  import { PickerTrigger } from "./picker-trigger.js";
28
28
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
29
- import { SlidingIndicator } from "./sliding-indicator.js";
29
+ import { SelectionScope } from "./selection.js";
30
30
 
31
31
  interface EntitySelectorProps {
32
32
  entityIds: string[];
@@ -529,10 +529,8 @@ export function EntitySelector(props: EntitySelectorProps) {
529
529
  </div>
530
530
  }
531
531
  >
532
- <SlidingIndicator
533
- activeSelector="[data-highlighted]"
534
- orientation="vertical"
535
- indicatorClass="rounded-sm"
532
+ <SelectionScope
533
+ marker="highlighted"
536
534
  role="presentation"
537
535
  style={{ height: `${totalHeight()}px` }}
538
536
  >
@@ -554,7 +552,7 @@ export function EntitySelector(props: EntitySelectorProps) {
554
552
  )
555
553
  }
556
554
  </For>
557
- </SlidingIndicator>
555
+ </SelectionScope>
558
556
  </Show>
559
557
  </div>
560
558
  <Show when={diagnosticCount() > 0 || props.deviceClass}>
@@ -367,6 +367,7 @@ export {
367
367
  } from "./sheet.js";
368
368
  export { Skeleton } from "./skeleton.js";
369
369
  export { Slider } from "./slider.js";
370
+ export { SelectionHighlight, type SelectionMarker, SelectionScope } from "./selection.js";
370
371
  export { SlidingIndicator } from "./sliding-indicator.js";
371
372
  // Wave 4: React-Library Alternatives - Simpler
372
373
  export { GlassToast, Toaster, toast } from "./sonner.js";
@@ -1,20 +1,13 @@
1
1
  import { DropdownMenu as MenuPrimitive } from "@kobalte/core/dropdown-menu";
2
- import {
3
- type Component,
4
- type ComponentProps,
5
- createSignal,
6
- onCleanup,
7
- onMount,
8
- type ParentComponent,
9
- splitProps,
10
- } from "solid-js";
2
+ import { type Component, type ComponentProps, type ParentComponent, splitProps } from "solid-js";
11
3
  import { glassToneText } from "../lib/glass-tone.js";
12
4
  import { MENU_ITEM, MENU_ITEM_BASE, MENU_LABEL, MENU_SEPARATOR } from "../lib/menu-classes.js";
13
5
  import { STAGGER } from "../lib/motion-classes.js";
6
+ import { ignoreOpeningRelease } from "../lib/opening-release.js";
14
7
  import { FLOATING_PANEL } from "../lib/overlay-classes.js";
15
8
  import { cn } from "../lib/utils.js";
16
9
  import { Icon } from "./icon.js";
17
- import { SlidingIndicator } from "./sliding-indicator.js";
10
+ import { SelectionHighlight, SelectionScope } from "./selection.js";
18
11
 
19
12
  /*
20
13
  * DropdownMenu and ContextMenu are two Root flavors over one Kobalte Menu
@@ -29,52 +22,15 @@ import { SlidingIndicator } from "./sliding-indicator.js";
29
22
  * ContextMenu unfolds from the pointer. */
30
23
  export const MENU_CONTENT_CLASS = cn(FLOATING_PANEL, "min-w-[8rem] overflow-hidden p-1");
31
24
 
32
- /** Every menu content and sub content wraps its rows in one sliding highlight,
33
- * keyed off Kobalte's roving-focus attribute. The highlighted row's own
34
- * --glass-tone (set inline by MenuItemPart) is mirrored onto the indicator,
35
- * since --glass-tone does not inherit and the indicator is a sibling, not
36
- * an ancestor, of the rows it highlights. */
37
- export const MenuContentIndicator: ParentComponent = (props) => {
38
- let containerRef: HTMLDivElement | undefined;
39
- const [tone, setTone] = createSignal<string | undefined>(undefined);
40
-
41
- const syncTone = () => {
42
- const highlighted = containerRef?.querySelector<HTMLElement>("[data-highlighted]");
43
- setTone(highlighted?.style.getPropertyValue("--glass-tone") || undefined);
44
- };
45
-
46
- onMount(() => {
47
- if (!containerRef) return;
48
- const mo = new MutationObserver(syncTone);
49
- mo.observe(containerRef, {
50
- subtree: true,
51
- attributes: true,
52
- attributeFilter: ["data-highlighted"],
53
- });
54
- containerRef.addEventListener("focusin", syncTone);
55
- syncTone();
56
- onCleanup(() => {
57
- mo.disconnect();
58
- containerRef?.removeEventListener("focusin", syncTone);
59
- });
60
- });
61
-
62
- return (
63
- <SlidingIndicator
64
- ref={containerRef}
65
- // The one element between role="menu" and its role="menuitem" rows:
66
- // an unnamed div there breaks the menu's ownership in the a11y tree.
67
- role="none"
68
- class={STAGGER}
69
- activeSelector="[data-highlighted]"
70
- orientation="vertical"
71
- indicatorClass="rounded-sm"
72
- indicatorTone={tone()}
73
- >
74
- {props.children}
75
- </SlidingIndicator>
76
- );
77
- };
25
+ /** Every menu content and sub content wraps its rows in one selection scope, keyed off
26
+ * Kobalte's highlighted row. */
27
+ export const MenuContentIndicator: ParentComponent = (props) => (
28
+ // The one element between role="menu" and its role="menuitem" rows:
29
+ // an unnamed div there breaks the menu's ownership in the a11y tree.
30
+ <SelectionScope ref={ignoreOpeningRelease} role="none" class={STAGGER} marker="highlighted">
31
+ {props.children}
32
+ </SelectionScope>
33
+ );
78
34
 
79
35
  type ToneProps = {
80
36
  tone?: string;
@@ -87,7 +43,7 @@ function resolveTone(local: ToneProps): string | undefined {
87
43
  }
88
44
 
89
45
  function toneStyle(tone: string | undefined) {
90
- return tone ? { "--glass-tone": tone, color: glassToneText(tone) } : undefined;
46
+ return tone ? { "--selection-tone": tone, color: glassToneText(tone) } : undefined;
91
47
  }
92
48
 
93
49
  type MenuItemProps = ComponentProps<typeof MenuPrimitive.Item> &
@@ -113,6 +69,7 @@ export const MenuItemPart: Component<MenuItemProps> = (props) => {
113
69
  "variant",
114
70
  "slotName",
115
71
  "style",
72
+ "children",
116
73
  ]);
117
74
  const tone = () => resolveTone(local);
118
75
  return (
@@ -125,7 +82,10 @@ export const MenuItemPart: Component<MenuItemProps> = (props) => {
125
82
  class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
126
83
  style={{ ...toneStyle(tone()), ...local.style }}
127
84
  {...rest}
128
- />
85
+ >
86
+ <SelectionHighlight />
87
+ {local.children}
88
+ </MenuPrimitive.Item>
129
89
  );
130
90
  };
131
91
 
@@ -179,6 +139,7 @@ export const MenuSubTriggerPart: ParentComponent<MenuSubTriggerProps> = (props)
179
139
  class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
180
140
  {...rest}
181
141
  >
142
+ <SelectionHighlight />
182
143
  {local.children}
183
144
  <Icon icon="lucide:chevron-right" width={16} height={16} class="ml-auto" />
184
145
  </MenuPrimitive.SubTrigger>
@@ -214,6 +175,7 @@ export const MenuCheckboxItemPart: ParentComponent<MenuCheckboxItemProps> = (pro
214
175
  class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
215
176
  {...rest}
216
177
  >
178
+ <SelectionHighlight />
217
179
  <span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
218
180
  <MenuPrimitive.ItemIndicator>
219
181
  <Icon icon="lucide:check" width={16} height={16} class="size-4" />
@@ -236,6 +198,7 @@ export const MenuRadioItemPart: ParentComponent<MenuRadioItemProps> = (props) =>
236
198
  class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
237
199
  {...rest}
238
200
  >
201
+ <SelectionHighlight />
239
202
  <span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
240
203
  <MenuPrimitive.ItemIndicator>
241
204
  {/* mdi:circle is filled; lucide:circle is stroke-only and invisible at 8px. */}
@@ -5,6 +5,7 @@ import { ICON_PILL, ICON_PILL_TINT } from "../lib/pill-classes.js";
5
5
  import { cn } from "../lib/utils.js";
6
6
  import { Checkbox } from "./checkbox.js";
7
7
  import { Icon } from "./icon.js";
8
+ import { SelectionHighlight } from "./selection.js";
8
9
 
9
10
  /* One row for every picker that lists things with an icon (entities, areas):
10
11
  * icon well, title over a muted line, optional meta, and the selection
@@ -47,6 +48,7 @@ export function PickerRow(props: PickerRowProps) {
47
48
  style={{ "min-height": `${PICKER_ROW_HEIGHT}px` }}
48
49
  {...rest}
49
50
  >
51
+ <SelectionHighlight />
50
52
  <Show when={local.icon}>
51
53
  {(icon) => (
52
54
  <div
@@ -4,11 +4,12 @@ import { CONTROL_H, INPUT_SURFACE } from "../lib/input-classes.js";
4
4
  import { Z_CLASS } from "../lib/layers.js";
5
5
  import { MENU_ITEM, MENU_LABEL, MENU_SEPARATOR } from "../lib/menu-classes.js";
6
6
  import { FIELD_MOTION, STAGGER } from "../lib/motion-classes.js";
7
+ import { ignoreOpeningRelease } from "../lib/opening-release.js";
7
8
  import { anchorToTriggerTop } from "../lib/overlay-classes.js";
8
9
  import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
9
10
  import { cn } from "../lib/utils.js";
10
11
  import { Icon } from "./icon.js";
11
- import { SlidingIndicator } from "./sliding-indicator.js";
12
+ import { SelectionHighlight, SelectionScope } from "./selection.js";
12
13
 
13
14
  const Select = ((props: ComponentProps<typeof SelectPrimitive>) => (
14
15
  <SelectPrimitive gutter={0} getAnchorRect={anchorToTriggerTop} flip={false} overlap {...props} />
@@ -65,14 +66,13 @@ const SelectContent: ParentComponent<
65
66
  )}
66
67
  {...rest}
67
68
  >
68
- <SlidingIndicator
69
- activeSelector="[data-highlighted]"
70
- orientation="vertical"
71
- indicatorClass="rounded-sm"
69
+ <SelectionScope
70
+ ref={ignoreOpeningRelease}
71
+ marker="highlighted"
72
72
  class={cn("w-full", PICKER_LIST)}
73
73
  >
74
74
  <SelectPrimitive.Listbox class={cn(STAGGER, local.listboxClass)} />
75
- </SlidingIndicator>
75
+ </SelectionScope>
76
76
  </SelectPrimitive.Content>
77
77
  </SelectPrimitive.Portal>
78
78
  );
@@ -101,6 +101,7 @@ const SelectItem: ParentComponent<ComponentProps<typeof SelectPrimitive.Item>> =
101
101
  )}
102
102
  {...rest}
103
103
  >
104
+ <SelectionHighlight />
104
105
  <span class="absolute right-2 flex size-3.5 items-center justify-center">
105
106
  <SelectPrimitive.ItemIndicator>
106
107
  <Icon icon="lucide:check" width={16} height={16} class="size-4 text-current" />