@glasshome/ui 1.14.0 → 1.16.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.
@@ -0,0 +1,11 @@
1
+ import { type JSX } from "solid-js";
2
+ export interface PickerTriggerProps extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> {
3
+ /** data-slot for the button, so each picker keeps its own test and style hook. */
4
+ slot: string;
5
+ open: boolean;
6
+ onToggle: () => void;
7
+ /** Passed only when there is a value to drop: its presence paints the clear button. */
8
+ onClear?: () => void;
9
+ clearLabel?: string;
10
+ }
11
+ export declare function PickerTrigger(props: PickerTriggerProps): JSX.Element;
@@ -41,6 +41,16 @@ type ListRowProps = {
41
41
  openLabel?: string;
42
42
  class?: string;
43
43
  };
44
+ /**
45
+ * One labelled fact: the name on the left, the value hard against the right.
46
+ * The counterpart of ListRow for a detail panel, where the rows are key/value
47
+ * rather than navigable items.
48
+ */
49
+ export declare function FactRow(props: {
50
+ label: JSX.Element;
51
+ children: JSX.Element;
52
+ class?: string;
53
+ }): JSX.Element;
44
54
  /**
45
55
  * One item in a settings list. Fixed slots so every list reads the same
46
56
  * whatever it holds; the row itself, not a nested button, is what you press.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/glasshome/ui#readme",
@@ -1,12 +1,13 @@
1
1
  import { createMemo, createSignal, For, Show } from "solid-js";
2
2
  import { MENU_ITEM } from "../lib/menu-classes.js";
3
3
  import { STAGGER } from "../lib/motion-classes.js";
4
- import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
4
+ import { PICKER_LIST } from "../lib/picker-classes.js";
5
5
  import { cn } from "../lib/utils.js";
6
6
  import { useEntityData } from "./entity-data.js";
7
7
  import { Icon } from "./icon.js";
8
8
  import { PickerRow } from "./picker-row.js";
9
9
  import { PickerSearch } from "./picker-search.js";
10
+ import { PickerTrigger } from "./picker-trigger.js";
10
11
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
11
12
  import { SlidingIndicator } from "./sliding-indicator.js";
12
13
 
@@ -106,6 +107,15 @@ export function AreaPicker(props: AreaPickerProps) {
106
107
  setSearch("");
107
108
  };
108
109
 
110
+ const showTriggerClear = () =>
111
+ props.allowClear !== false && (multi() ? selected().length > 0 : Boolean(props.value));
112
+
113
+ const clearSelection = () => {
114
+ if (props.disabled) return;
115
+ props.onChange?.("");
116
+ props.onValuesChange?.([]);
117
+ };
118
+
109
119
  const toggleArea = (areaId: string) => {
110
120
  if (props.disabled) return;
111
121
  const current = selected();
@@ -127,14 +137,14 @@ export function AreaPicker(props: AreaPickerProps) {
127
137
  modal
128
138
  >
129
139
  <PopoverAnchor as="div" class={props.class}>
130
- <button
131
- type="button"
132
- data-slot="area-picker-trigger"
133
- data-expanded={open() || undefined}
140
+ <PickerTrigger
141
+ slot="area-picker-trigger"
142
+ open={open()}
143
+ onToggle={() => setOpen(!open())}
134
144
  aria-labelledby={props["aria-labelledby"]}
135
- class={PICKER_TRIGGER}
136
145
  disabled={props.disabled}
137
- onClick={() => setOpen(!open())}
146
+ onClear={showTriggerClear() ? clearSelection : undefined}
147
+ clearLabel={multi() ? "Clear areas" : "Clear area"}
138
148
  >
139
149
  <Show
140
150
  when={triggerArea()}
@@ -160,13 +170,7 @@ export function AreaPicker(props: AreaPickerProps) {
160
170
  </>
161
171
  )}
162
172
  </Show>
163
- <Icon
164
- icon="mdi:chevron-down"
165
- width={16}
166
- height={16}
167
- class="shrink-0 text-muted-foreground"
168
- />
169
- </button>
173
+ </PickerTrigger>
170
174
  </PopoverAnchor>
171
175
  <PopoverContent
172
176
  onOpenAutoFocus={(e) => e.preventDefault()}
@@ -10,10 +10,11 @@ import { Skeleton } from "./skeleton.js";
10
10
  import { TABLE_HEAD_CELL_CLASS, TABLE_HEAD_LABEL_CLASS } from "./table.js";
11
11
 
12
12
  /**
13
- * Generic data-table vocabulary: sticky-less header, row height/padding, border
13
+ * Generic data-table vocabulary: head strip, row height/padding, border
14
14
  * treatment, hover, numeric alignment, toolbar (search/filter/sort), bulk bar,
15
- * and empty/loading/error states. Each list renders its own row markup but
16
- * shares these primitives + class tokens. Presentational only — no app data.
15
+ * and empty/loading/error states. A list composes DataTableRow for the shared
16
+ * press and keyboard behaviour, or the class tokens for bespoke markup.
17
+ * Presentational only — no app data.
17
18
  *
18
19
  * Tables live inside a card; go edge-to-edge with `TABLE_BLEED` (cancels the
19
20
  * card's p-3) and re-add the inset via the cell padding tokens.
@@ -32,7 +33,10 @@ export const TABLE_CELL_X = "px-4";
32
33
  export const TABLE_ROW_CLASS =
33
34
  "flex items-center gap-4 border-border/50 border-b px-4 py-2.5 transition-colors last:border-b-0 hover:bg-foreground/[0.03]";
34
35
  export const TABLE_HEAD_CLASS = "flex items-center gap-4 border-border/50 border-b px-4 py-2";
35
- export const TABLE_SCROLL_CLASS = "max-h-[600px] overflow-auto gh-scroll";
36
+ /* No vertical cap: a table inside a page that already scrolls got a second
37
+ * scrollbar and hid most of its own rows. A list that genuinely boxes adds its
38
+ * own max-h. */
39
+ export const TABLE_SCROLL_CLASS = "overflow-x-auto gh-scroll";
36
40
  export const TABLE_NUM_CELL_CLASS = "text-right text-muted-foreground text-xs tabular-nums";
37
41
 
38
42
  export type SortDirection = "asc" | "desc";
@@ -115,6 +119,78 @@ export function TableSearchInput(props: {
115
119
  );
116
120
  }
117
121
 
122
+ /**
123
+ * One row of a flex data table. The row itself is what you press: activation
124
+ * rides on a real button covering it, the same mechanism `ListRow` uses, so a
125
+ * row reachable by Tab is also openable by Enter. Cells go in `children`;
126
+ * anything separately clickable goes in `actions`, which stacks above the
127
+ * overlay.
128
+ */
129
+ export function DataTableRow(props: {
130
+ children: JSX.Element;
131
+ /** Activates the whole row. Requires `openLabel`. */
132
+ onOpen?: () => void;
133
+ /** The whole row is a link. Requires `openLabel`. */
134
+ href?: string;
135
+ /** Accessible name for the whole-row activation. */
136
+ openLabel?: string;
137
+ selected?: boolean;
138
+ actions?: JSX.Element;
139
+ class?: string;
140
+ }) {
141
+ const opens = () => props.onOpen !== undefined || props.href !== undefined;
142
+ return (
143
+ <div
144
+ data-slot="data-table-row"
145
+ data-state={props.selected ? "selected" : undefined}
146
+ class={cn(
147
+ TABLE_ROW_CLASS,
148
+ // Same selected treatment the semantic TableRow uses, keyed off the
149
+ // same data-state, so the two table families read alike.
150
+ "relative data-[state=selected]:bg-muted",
151
+ opens() && "cursor-pointer",
152
+ props.class,
153
+ )}
154
+ >
155
+ <Show when={props.href}>
156
+ {(href) => (
157
+ <a href={href()} class="absolute inset-0 outline-none">
158
+ <span class="sr-only">{props.openLabel}</span>
159
+ </a>
160
+ )}
161
+ </Show>
162
+ <Show when={props.href === undefined && props.onOpen}>
163
+ <button
164
+ type="button"
165
+ class="absolute inset-0 outline-none"
166
+ aria-label={props.openLabel}
167
+ onClick={() => props.onOpen?.()}
168
+ />
169
+ </Show>
170
+ {props.children}
171
+ <Show when={props.actions}>
172
+ <div class="relative flex shrink-0 items-center gap-1">{props.actions}</div>
173
+ </Show>
174
+ </div>
175
+ );
176
+ }
177
+
178
+ /**
179
+ * Column header strip. `sticky` keeps the labels against the top of the
180
+ * scrollport while a long list scrolls under them, which needs its own
181
+ * background so rows do not read through the glass.
182
+ */
183
+ export function DataTableHead(props: { children: JSX.Element; sticky?: boolean; class?: string }) {
184
+ return (
185
+ <div
186
+ data-slot="data-table-head"
187
+ class={cn(TABLE_HEAD_CLASS, props.sticky && "sticky top-0 z-10 bg-background", props.class)}
188
+ >
189
+ {props.children}
190
+ </div>
191
+ );
192
+ }
193
+
118
194
  /** Sortable column header button. `align="end"` for numeric columns. */
119
195
  export function TableSortHeader(props: {
120
196
  label: string;
@@ -10,7 +10,7 @@ import {
10
10
  Show,
11
11
  } from "solid-js";
12
12
  import { MENU_LABEL } from "../lib/menu-classes.js";
13
- import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
13
+ import { PICKER_LIST } from "../lib/picker-classes.js";
14
14
  import { createIsMobile } from "../lib/use-is-mobile.js";
15
15
  import { cn } from "../lib/utils.js";
16
16
  import {
@@ -24,6 +24,7 @@ import { type EntityViewLike, useEntityData } from "./entity-data.js";
24
24
  import { Icon } from "./icon.js";
25
25
  import { PICKER_ROW_HEIGHT, PickerRow } from "./picker-row.js";
26
26
  import { PickerSearch } from "./picker-search.js";
27
+ import { PickerTrigger } from "./picker-trigger.js";
27
28
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
28
29
  import { SlidingIndicator } from "./sliding-indicator.js";
29
30
 
@@ -309,9 +310,10 @@ export function EntitySelector(props: EntitySelectorProps) {
309
310
  setActiveIndex(0);
310
311
  };
311
312
 
313
+ // A re-tap on the picked entity clears it, the way every picker toggles.
312
314
  const toggleEntity = (entityId: string) => {
313
315
  if (props.multiple === false) {
314
- props.onEntityIdsChange([entityId]);
316
+ props.onEntityIdsChange(props.entityIds.includes(entityId) ? [] : [entityId]);
315
317
  closePicker();
316
318
  return;
317
319
  }
@@ -375,59 +377,40 @@ export function EntitySelector(props: EntitySelectorProps) {
375
377
  };
376
378
 
377
379
  const isSingle = () => props.multiple === false;
378
- const showTriggerClear = () => isSingle() && props.entityIds.length > 0;
380
+ const showTriggerClear = () => props.entityIds.length > 0;
379
381
 
380
382
  const clearSelection = () => {
381
383
  props.onEntityIdsChange([]);
382
384
  };
383
385
 
384
386
  const TriggerButton = (p: { onClick: () => void }) => (
385
- <div class="relative">
386
- <button
387
- type="button"
388
- role="combobox"
389
- data-slot="entity-selector-trigger"
390
- data-expanded={open() || undefined}
391
- aria-labelledby={props["aria-labelledby"]}
392
- aria-expanded={open()}
393
- aria-controls={listboxId}
394
- aria-haspopup="listbox"
395
- class={cn(PICKER_TRIGGER, showTriggerClear() && "pr-14")}
396
- onClick={p.onClick}
387
+ <PickerTrigger
388
+ slot="entity-selector-trigger"
389
+ role="combobox"
390
+ open={open()}
391
+ onToggle={p.onClick}
392
+ aria-labelledby={props["aria-labelledby"]}
393
+ aria-expanded={open()}
394
+ aria-controls={listboxId}
395
+ aria-haspopup="listbox"
396
+ onClear={showTriggerClear() ? clearSelection : undefined}
397
+ >
398
+ <Show when={triggerIcon()}>
399
+ {(icon) => (
400
+ <Icon icon={icon()} width={16} height={16} class="shrink-0 text-muted-foreground" />
401
+ )}
402
+ </Show>
403
+ <Show
404
+ when={triggerLabel()}
405
+ fallback={
406
+ <span class="flex-1 truncate text-left text-muted-foreground">
407
+ Select {props.domain} {isSingle() ? "entity" : "entities"}...
408
+ </span>
409
+ }
397
410
  >
398
- <Show when={triggerIcon()}>
399
- {(icon) => (
400
- <Icon icon={icon()} width={16} height={16} class="shrink-0 text-muted-foreground" />
401
- )}
402
- </Show>
403
- <Show
404
- when={triggerLabel()}
405
- fallback={
406
- <span class="flex-1 truncate text-left text-muted-foreground">
407
- Select {props.domain} {isSingle() ? "entity" : "entities"}...
408
- </span>
409
- }
410
- >
411
- {(label) => <span class="flex-1 truncate text-left">{label()}</span>}
412
- </Show>
413
- <Icon
414
- icon="mdi:chevron-down"
415
- width={16}
416
- height={16}
417
- class={`shrink-0 text-muted-foreground transition-transform ${open() ? "rotate-180" : ""}`}
418
- />
419
- </button>
420
- <Show when={showTriggerClear()}>
421
- <button
422
- type="button"
423
- aria-label="Clear selection"
424
- class="absolute top-1/2 right-8 flex -translate-y-1/2 items-center rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground"
425
- onClick={clearSelection}
426
- >
427
- <Icon icon="mdi:close-circle" width={16} height={16} />
428
- </button>
411
+ {(label) => <span class="flex-1 truncate text-left">{label()}</span>}
429
412
  </Show>
430
- </div>
413
+ </PickerTrigger>
431
414
  );
432
415
 
433
416
  const EntityRow = (p: { id: string; entityIndex: number; top: number }) => {
@@ -1,10 +1,11 @@
1
1
  import { createMemo, createSignal, For, Show } from "solid-js";
2
2
  import { STAGGER } from "../lib/motion-classes.js";
3
- import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
3
+ import { PICKER_LIST } from "../lib/picker-classes.js";
4
4
  import { CHIP, ICON_PILL_TINT } from "../lib/pill-classes.js";
5
5
  import { cn } from "../lib/utils.js";
6
6
  import { Icon } from "./icon.js";
7
7
  import { PickerSearch } from "./picker-search.js";
8
+ import { PickerTrigger } from "./picker-trigger.js";
8
9
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
9
10
 
10
11
  const ICON_LIBRARIES = [
@@ -311,12 +312,15 @@ export function IconPicker(props: IconPickerProps) {
311
312
  return defaultIcons().filter((icon) => icon.toLowerCase().includes(q));
312
313
  });
313
314
 
315
+ // A re-tap on the picked icon clears it, the way every picker toggles.
314
316
  const selectIcon = (icon: string) => {
315
- props.onChange(icon);
317
+ props.onChange(icon === props.value.trim() ? "" : icon);
316
318
  setOpen(false);
317
319
  setSearch("");
318
320
  };
319
321
 
322
+ const clearIcon = () => props.onChange("");
323
+
320
324
  const handleLibChange = (prefix: string) => {
321
325
  setActiveLib(prefix);
322
326
  setApiResults([]);
@@ -328,13 +332,13 @@ export function IconPicker(props: IconPickerProps) {
328
332
  return (
329
333
  <Popover surface="field" open={open()} onOpenChange={setOpen} modal>
330
334
  <PopoverAnchor as="div" class={props.class}>
331
- <button
332
- type="button"
333
- data-slot="icon-picker-trigger"
334
- data-expanded={open() || undefined}
335
+ <PickerTrigger
336
+ slot="icon-picker-trigger"
337
+ open={open()}
338
+ onToggle={() => setOpen(!open())}
335
339
  aria-labelledby={props["aria-labelledby"]}
336
- class={PICKER_TRIGGER}
337
- onClick={() => setOpen(!open())}
340
+ onClear={props.value.trim() ? clearIcon : undefined}
341
+ clearLabel="Clear icon"
338
342
  >
339
343
  <Show
340
344
  when={props.value.trim()}
@@ -347,13 +351,7 @@ export function IconPicker(props: IconPickerProps) {
347
351
  <Icon icon={props.value.trim()} width={18} height={18} class="shrink-0" />
348
352
  <span class="flex-1 truncate text-left">{props.value}</span>
349
353
  </Show>
350
- <Icon
351
- icon="mdi:chevron-down"
352
- width={16}
353
- height={16}
354
- class="shrink-0 text-muted-foreground"
355
- />
356
- </button>
354
+ </PickerTrigger>
357
355
  </PopoverAnchor>
358
356
  <PopoverContent
359
357
  onOpenAutoFocus={(e) => {
@@ -8,7 +8,7 @@ import {
8
8
  Show,
9
9
  Switch,
10
10
  } from "solid-js";
11
- import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
11
+ import { PICKER_LIST } from "../lib/picker-classes.js";
12
12
  import { cn } from "../lib/utils.js";
13
13
  import { Alert } from "./alert.js";
14
14
  import {
@@ -49,6 +49,7 @@ import {
49
49
  PaginationNext,
50
50
  PaginationPrevious,
51
51
  } from "./pagination.js";
52
+ import { PickerTrigger } from "./picker-trigger.js";
52
53
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
53
54
  import { SectionMeta } from "./section-card.js";
54
55
  import { Skeleton } from "./skeleton.js";
@@ -103,6 +104,11 @@ export function ImagePicker(props: ImagePickerProps) {
103
104
  : `This image is used in ${used} widget${used === 1 ? "" : "s"}. Deleting it will leave those widgets without an image.`;
104
105
  });
105
106
 
107
+ const clearImage = () => {
108
+ props.onChange("");
109
+ setThumbBroken(false);
110
+ };
111
+
106
112
  const openGallery = (next: boolean) => {
107
113
  if (next) setEverOpened(true);
108
114
  setOpen(next);
@@ -154,13 +160,13 @@ export function ImagePicker(props: ImagePickerProps) {
154
160
  <div data-slot="image-picker" class={cn(props.class)}>
155
161
  <Popover surface="field" open={open()} onOpenChange={openGallery} modal>
156
162
  <PopoverAnchor as="div">
157
- <button
158
- type="button"
163
+ <PickerTrigger
159
164
  id={props.id}
160
- data-slot="image-picker-trigger"
161
- data-expanded={open() || undefined}
162
- class={PICKER_TRIGGER}
163
- onClick={() => openGallery(!open())}
165
+ slot="image-picker-trigger"
166
+ open={open()}
167
+ onToggle={() => openGallery(!open())}
168
+ onClear={props.value ? clearImage : undefined}
169
+ clearLabel="Clear image"
164
170
  >
165
171
  <Show
166
172
  when={!thumbBroken() && props.value}
@@ -189,13 +195,7 @@ export function ImagePicker(props: ImagePickerProps) {
189
195
  />
190
196
  <span class="flex-1 truncate text-left">Image selected</span>
191
197
  </Show>
192
- <Icon
193
- icon="lucide:chevron-down"
194
- width={16}
195
- height={16}
196
- class="shrink-0 text-muted-foreground"
197
- />
198
- </button>
198
+ </PickerTrigger>
199
199
  </PopoverAnchor>
200
200
  <PopoverContent class="min-w-72" onInteractOutside={() => setOpen(false)}>
201
201
  {/* The panel owns no padding: the gallery body owns its own inset. */}
@@ -268,7 +268,7 @@ export function ImagePicker(props: ImagePickerProps) {
268
268
  markUnused
269
269
  selected={props.value === image.id}
270
270
  onSelect={() => {
271
- props.onChange(image.id);
271
+ props.onChange(props.value === image.id ? "" : image.id);
272
272
  setThumbBroken(false);
273
273
  setOpen(false);
274
274
  }}
@@ -123,6 +123,8 @@ export {
123
123
  export { CopyButton } from "./copy-button.js";
124
124
  export { CountPill } from "./count-pill.js";
125
125
  export {
126
+ DataTableHead,
127
+ DataTableRow,
126
128
  type SortDirection,
127
129
  TABLE_BLEED,
128
130
  TABLE_CELL_X,
@@ -300,6 +302,7 @@ export {
300
302
  export { PasswordInput } from "./password-input.js";
301
303
  export { PICKER_ROW_HEIGHT, PickerRow } from "./picker-row.js";
302
304
  export { PickerSearch, type PickerSearchProps } from "./picker-search.js";
305
+ export { PickerTrigger, type PickerTriggerProps } from "./picker-trigger.js";
303
306
  export {
304
307
  Popover,
305
308
  PopoverAnchor,
@@ -333,6 +336,7 @@ export {
333
336
  export { ScopeIndicator } from "./scope-indicator.js";
334
337
  export { ScrollArea, ScrollBar } from "./scroll-area.js";
335
338
  export {
339
+ FactRow,
336
340
  type GlassSurface,
337
341
  ListRow,
338
342
  NOOP_GLASS,
@@ -0,0 +1,68 @@
1
+ import { type JSX, Show, splitProps } from "solid-js";
2
+ import { PICKER_TRIGGER } from "../lib/picker-classes.js";
3
+ import { cn } from "../lib/utils.js";
4
+ import { Icon } from "./icon.js";
5
+
6
+ export interface PickerTriggerProps
7
+ extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> {
8
+ /** data-slot for the button, so each picker keeps its own test and style hook. */
9
+ slot: string;
10
+ open: boolean;
11
+ onToggle: () => void;
12
+ /** Passed only when there is a value to drop: its presence paints the clear button. */
13
+ onClear?: () => void;
14
+ clearLabel?: string;
15
+ }
16
+
17
+ export function PickerTrigger(props: PickerTriggerProps) {
18
+ const [own, rest] = splitProps(props, [
19
+ "slot",
20
+ "open",
21
+ "onToggle",
22
+ "onClear",
23
+ "clearLabel",
24
+ "class",
25
+ "children",
26
+ ]);
27
+
28
+ return (
29
+ <div class="relative">
30
+ <button
31
+ type="button"
32
+ data-slot={own.slot}
33
+ data-expanded={own.open || undefined}
34
+ class={cn(PICKER_TRIGGER, own.class)}
35
+ onClick={() => own.onToggle()}
36
+ {...rest}
37
+ >
38
+ {own.children}
39
+ {/* The clear button cannot nest inside the trigger button, so it is
40
+ positioned over this gap, left of the chevron. */}
41
+ <Show when={own.onClear}>
42
+ <span class="w-6 shrink-0" />
43
+ </Show>
44
+ <Icon
45
+ icon="lucide:chevron-down"
46
+ width={16}
47
+ height={16}
48
+ class={cn(
49
+ "shrink-0 text-muted-foreground transition-transform",
50
+ own.open && "rotate-180",
51
+ )}
52
+ />
53
+ </button>
54
+ <Show when={own.onClear}>
55
+ <button
56
+ type="button"
57
+ data-slot="picker-trigger-clear"
58
+ aria-label={own.clearLabel ?? "Clear selection"}
59
+ disabled={rest.disabled}
60
+ class="absolute top-1/2 right-9 flex -translate-y-1/2 items-center rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50"
61
+ onClick={() => own.onClear?.()}
62
+ >
63
+ <Icon icon="lucide:circle-x" width={16} height={16} />
64
+ </button>
65
+ </Show>
66
+ </div>
67
+ );
68
+ }
@@ -146,6 +146,23 @@ type ListRowProps = {
146
146
  class?: string;
147
147
  };
148
148
 
149
+ /**
150
+ * One labelled fact: the name on the left, the value hard against the right.
151
+ * The counterpart of ListRow for a detail panel, where the rows are key/value
152
+ * rather than navigable items.
153
+ */
154
+ export function FactRow(props: { label: JSX.Element; children: JSX.Element; class?: string }) {
155
+ return (
156
+ <div
157
+ data-slot="fact-row"
158
+ class={cn("flex items-baseline justify-between gap-3 py-1.5", props.class)}
159
+ >
160
+ <span class="shrink-0 text-muted-foreground text-xs">{props.label}</span>
161
+ <span class="min-w-0 text-right text-sm">{props.children}</span>
162
+ </div>
163
+ );
164
+ }
165
+
149
166
  /**
150
167
  * One item in a settings list. Fixed slots so every list reads the same
151
168
  * whatever it holds; the row itself, not a nested button, is what you press.
@@ -1,5 +1,5 @@
1
1
  import { Tabs as TabsPrimitive } from "@kobalte/core/tabs";
2
- import { type Component, type ComponentProps, splitProps } from "solid-js";
2
+ import { type Component, type ComponentProps, onCleanup, onMount, splitProps } from "solid-js";
3
3
  import { TRACK_SURFACE } from "../lib/card-classes.js";
4
4
  import { PRESS_DIP, SETTLE_MOTION } from "../lib/motion-classes.js";
5
5
  import { SEGMENT_ITEM } from "../lib/segment-classes.js";
@@ -30,21 +30,54 @@ const Tabs: Component<TabsProps> = (props) => {
30
30
  );
31
31
  };
32
32
 
33
+ /** Keeps the selected trigger centred in the scrolled track, so a deep link to
34
+ * a tab past the fold does not land on a track scrolled to the first one.
35
+ * Drives scrollLeft rather than scrollIntoView, which would scroll the page
36
+ * with it. */
37
+ function followSelection(list: HTMLElement): () => void {
38
+ const reveal = () => {
39
+ if (list.scrollWidth <= list.clientWidth) return;
40
+ const selected = list.querySelector("[data-selected]");
41
+ if (!selected) return;
42
+ const track = list.getBoundingClientRect();
43
+ const item = selected.getBoundingClientRect();
44
+ const left = list.scrollLeft + (item.left - track.left) - (track.width - item.width) / 2;
45
+ const smooth = !matchMedia("(prefers-reduced-motion: reduce)").matches;
46
+ list.scrollTo({ left, behavior: smooth ? "smooth" : "auto" });
47
+ };
48
+ // The track has no width during mount, so the first pass has to wait for
49
+ // layout or it measures a track that cannot scroll yet.
50
+ const first = requestAnimationFrame(reveal);
51
+ const observer = new MutationObserver(reveal);
52
+ observer.observe(list, { attributes: true, attributeFilter: ["data-selected"], subtree: true });
53
+ return () => {
54
+ cancelAnimationFrame(first);
55
+ observer.disconnect();
56
+ };
57
+ }
58
+
33
59
  const TabsList: Component<ComponentProps<typeof TabsPrimitive.List>> = (props) => {
34
60
  const [local, others] = splitProps(props, ["class", "children"]);
61
+ let listRef: HTMLDivElement | undefined;
62
+ onMount(() => {
63
+ if (listRef) onCleanup(followSelection(listRef));
64
+ });
35
65
  return (
36
66
  <TabsPrimitive.List
67
+ ref={listRef}
37
68
  data-slot="tabs-list"
38
69
  class={cn(
39
- `inline-flex h-9 w-full items-center rounded-lg ${TRACK_SURFACE} p-1 text-muted-foreground`,
70
+ `scrollbar-hide inline-flex h-9 w-full items-center overflow-x-auto rounded-lg ${TRACK_SURFACE} p-1 text-muted-foreground`,
40
71
  local.class,
41
72
  )}
42
73
  {...others}
43
74
  >
75
+ {/* w-max so triggers keep their natural width and the track scrolls;
76
+ w-full alone squeezed them past the rounded edge, unreachable. */}
44
77
  <SlidingIndicator
45
78
  activeSelector="[data-selected]"
46
79
  indicatorClass="rounded-md"
47
- class="flex h-full w-full items-center gap-1"
80
+ class="flex h-full w-max min-w-full items-center gap-1"
48
81
  >
49
82
  {local.children}
50
83
  </SlidingIndicator>