@tristan2828/ui-foundation 4.67.1 → 4.68.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.
@@ -3,28 +3,29 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [Palettes](#palettes) · lines 37–103
7
- - [Glow](#glow) · lines 105–123
8
- - [Semantic tones](#semantic-tones) · lines 125–153
9
- - [The three badge styles](#the-three-badge-styles) · lines 155–172
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 174–203
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 205–218
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 220–264
13
- - [Categorical colour](#categorical-colour) · lines 266–336
14
- - [Shapes and sizes](#shapes-and-sizes) · lines 338–359
15
- - [Typography](#typography) · lines 361–455
16
- - [Written text (notes)](#written-text-notes) · lines 395–455
17
- - [Density](#density) · lines 457–514
18
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 516–630
19
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 632–701
20
- - [Notices](#notices) · lines 703–731
21
- - [A value over time](#a-value-over-time) · lines 733–819
22
- - [Several values over time](#several-values-over-time) · lines 782–819
23
- - [A list as a board](#a-list-as-a-board) · lines 821–872
24
- - [A list as cards](#a-list-as-cards) · lines 874–920
25
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 922–944
26
- - [Picking at random](#picking-at-random) · lines 946–977
27
- - [Filling in what's missing](#filling-in-whats-missing) · lines 979–1046
6
+ - [Palettes](#palettes) · lines 38–104
7
+ - [Glow](#glow) · lines 106–124
8
+ - [Semantic tones](#semantic-tones) · lines 126–154
9
+ - [The three badge styles](#the-three-badge-styles) · lines 156–173
10
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 175–204
11
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 206–219
12
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 221–265
13
+ - [Categorical colour](#categorical-colour) · lines 267–337
14
+ - [Shapes and sizes](#shapes-and-sizes) · lines 339–360
15
+ - [Typography](#typography) · lines 362–456
16
+ - [Written text (notes)](#written-text-notes) · lines 396–456
17
+ - [Density](#density) · lines 458–544
18
+ - [Rows on this device](#rows-on-this-device) · lines 517–544
19
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 546–660
20
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 662–731
21
+ - [Notices](#notices) · lines 733–761
22
+ - [A value over time](#a-value-over-time) · lines 763–849
23
+ - [Several values over time](#several-values-over-time) · lines 812–849
24
+ - [A list as a board](#a-list-as-a-board) · lines 851–902
25
+ - [A list as cards](#a-list-as-cards) · lines 904–950
26
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 952–974
27
+ - [Picking at random](#picking-at-random) · lines 976–1007
28
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1009–1076
28
29
 
29
30
  <!-- /index -->
30
31
 
@@ -513,6 +514,35 @@ set, not a `DataTable` prop:
513
514
  measure that every step changes what it should, and that the default
514
515
  keeps today's sizes.
515
516
 
517
+ ### Rows on this device
518
+
519
+ An app can let each device choose its table rows: `rowsPicker` on
520
+ `FoundationProviders` adds **Rows on this device** to the shell's look
521
+ menu (under the palettes, or a menu of its own beside the light/dark
522
+ toggle in an app without a palette).
523
+
524
+ ```tsx
525
+ <FoundationProviders palette="indigo-cyan" palettePicker rowsPicker …>
526
+ ```
527
+
528
+ | Rows | Table cell padding (vertical) | Header height |
529
+ |---|---|---|
530
+ | Compact *(the default)* | 4px | 32px |
531
+ | Regular | 8px | 40px, the size before 4.63 |
532
+
533
+ - The choice is kept in this device's `localStorage`
534
+ (`ui-foundation:rows`), like the palette, so a phone and a laptop can
535
+ differ. A new device starts compact; without `rowsPicker` every device
536
+ is compact and a saved choice is ignored.
537
+ - It rides on `<html>` as `data-rows="regular"`, so every table follows it
538
+ with no prop: `DataTable`, the `Table` primitive and tables in notes. A
539
+ `data-density` on a nearer ancestor still wins, so a hub's
540
+ `data-density="compact"` wrapper keeps its tables compact.
541
+ - Regular is not `comfortable` (12px, 48px): the names are different
542
+ sizes. `useRows()` reads the choice, for a screen that must know it.
543
+ - Content inside cells (an inline editor, a button, a badge) must fit both
544
+ heights; check a cell like that at both.
545
+
516
546
  ## Widget cards (hub pages)
517
547
 
518
548
  A hub page (an app's home screen) shows a few small widgets from
@@ -1,5 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ChevronRightIcon, LogOutIcon, MoonIcon, PaletteIcon, SunIcon } from 'lucide-react';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronRightIcon, LogOutIcon, MoonIcon, PaletteIcon, Rows3Icon, SunIcon } from 'lucide-react';
3
3
  import { useTheme } from 'next-themes';
4
4
  import { useEffect, useId, useState } from 'react';
5
5
  import { Link, Navigate, Outlet, useLocation } from 'react-router';
@@ -12,10 +12,12 @@ import { useErrorReporter } from '../../error-reporting/error-reporting-context.
12
12
  import { ReportRoutePattern } from '../../error-reporting/error-reporting-provider.js';
13
13
  import { useShellDocumentTitle } from '../../hooks/use-document-title.js';
14
14
  import { usePalette } from '../../hooks/use-palette.js';
15
+ import { useRows } from '../../hooks/use-rows.js';
15
16
  import { isPaletteName, PALETTE_LABELS, PALETTES } from '../../lib/palettes.js';
17
+ import { isRowsName, ROWS, ROWS_LABELS } from '../../lib/rows.js';
16
18
  import { cn } from 'cn';
17
19
  import { Button } from '../ui/button.js';
18
- import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
20
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
19
21
  import { Skeleton } from '../ui/skeleton.js';
20
22
  import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarTrigger, useSidebar, } from '../ui/sidebar.js';
21
23
  import { Toaster } from '../ui/sonner.js';
@@ -40,13 +42,15 @@ function CloseMobileSidebarOnNavigate() {
40
42
  return null;
41
43
  }
42
44
  // The header's look control: an app with a palette is always dark, so it
43
- // has no light/dark toggle, and with the picker on it gets the palette
44
- // menu in its place (design-language.md "Palettes").
45
+ // has no light/dark toggle, and with the picker on it gets the look menu
46
+ // in its place (design-language.md "Palettes"). With the rows picker the
47
+ // same menu offers the table rows (design-language.md "Density"); an app
48
+ // without a palette keeps its toggle beside it.
45
49
  function LookControl() {
46
50
  const { palette, picker } = usePalette();
47
- if (!palette)
48
- return _jsx(ThemeToggle, {});
49
- return picker ? _jsx(PalettePicker, { palette: palette }) : null;
51
+ const rows = useRows();
52
+ const pickPalette = palette && picker ? palette : null;
53
+ return (_jsxs(_Fragment, { children: [!palette && _jsx(ThemeToggle, {}), (pickPalette || rows.picker) && _jsx(LookMenu, { palette: pickPalette })] }));
50
54
  }
51
55
  // Each palette's swatch is its own background with its accent and second
52
56
  // colour on it, read from the palette primitives, so the menu shows all
@@ -55,12 +59,18 @@ function PaletteSwatch({ name }) {
55
59
  const colour = (part) => `var(--palette-${name}-${part})`;
56
60
  return (_jsxs("span", { "aria-hidden": true, className: "flex h-4 w-7 shrink-0 items-center justify-center gap-0.5 rounded-sm border border-border", style: { background: colour('background') }, children: [_jsx("span", { className: "size-2 rounded-full", style: { background: colour('accent') } }), _jsx("span", { className: "size-2 rounded-full", style: { background: colour('second') } })] }));
57
61
  }
58
- function PalettePicker({ palette }) {
62
+ // `palette` is null when only the rows are offered: the trigger is then
63
+ // the rows' own.
64
+ function LookMenu({ palette }) {
59
65
  const { setPalette } = usePalette();
60
- return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": `Palette: ${PALETTE_LABELS[palette]}` }), children: _jsx(PaletteIcon, {}) }), _jsx(DropdownMenuContent, { align: "end", className: "w-60", children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Palette on this device" }), _jsx(DropdownMenuRadioGroup, { value: palette, onValueChange: (next) => {
61
- if (isPaletteName(next))
62
- setPalette(next);
63
- }, children: PALETTES.map((name) => (_jsxs(DropdownMenuRadioItem, { value: name, children: [_jsx(PaletteSwatch, { name: name }), PALETTE_LABELS[name]] }, name))) })] }) })] }));
66
+ const { rows, picker: pickRows, setRows } = useRows();
67
+ return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": palette ? `Palette: ${PALETTE_LABELS[palette]}` : `Rows: ${ROWS_LABELS[rows]}` }), children: palette ? _jsx(PaletteIcon, {}) : _jsx(Rows3Icon, {}) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-60", children: [palette && (_jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Palette on this device" }), _jsx(DropdownMenuRadioGroup, { value: palette, onValueChange: (next) => {
68
+ if (isPaletteName(next))
69
+ setPalette(next);
70
+ }, children: PALETTES.map((name) => (_jsxs(DropdownMenuRadioItem, { value: name, children: [_jsx(PaletteSwatch, { name: name }), PALETTE_LABELS[name]] }, name))) })] })), palette && pickRows && _jsx(DropdownMenuSeparator, {}), pickRows && (_jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Rows on this device" }), _jsx(DropdownMenuRadioGroup, { value: rows, onValueChange: (next) => {
71
+ if (isRowsName(next))
72
+ setRows(next);
73
+ }, children: ROWS.map((name) => (_jsx(DropdownMenuRadioItem, { value: name, children: ROWS_LABELS[name] }, name))) })] }))] })] }));
64
74
  }
65
75
  function ThemeToggle() {
66
76
  const { resolvedTheme, setTheme } = useTheme();
@@ -2,7 +2,7 @@ import { type QueryClient } from '@tanstack/react-query';
2
2
  import { type ReactNode } from 'react';
3
3
  import type { PaletteName } from '../../lib/palettes.js';
4
4
  import { type ErrorReportingOptions } from '../../error-reporting/reporter.js';
5
- export declare function FoundationProviders({ mockMode, queryClient, errorReporting, palette, palettePicker, children, }: {
5
+ export declare function FoundationProviders({ mockMode, queryClient, errorReporting, palette, palettePicker, rowsPicker, children, }: {
6
6
  /** Whether the API is served by MSW — the app's own IS_MOCK_MODE. */
7
7
  mockMode: boolean;
8
8
  /** Defaults to createQueryClient(); pass one to share it with code outside React. */
@@ -26,5 +26,11 @@ export declare function FoundationProviders({ mockMode, queryClient, errorReport
26
26
  * is remembered on this device. A new device starts on `palette`.
27
27
  */
28
28
  palettePicker?: boolean;
29
+ /**
30
+ * The shell's look menu offers the table rows, Compact (the default) or
31
+ * Regular, remembered on this device (design-language.md "Density",
32
+ * "Rows on this device"). Off, every device is compact.
33
+ */
34
+ rowsPicker?: boolean;
29
35
  children: ReactNode;
30
36
  }): import("react").JSX.Element;
@@ -6,6 +6,7 @@ import { AuthProvider } from '../../auth/use-auth.js';
6
6
  import { MockModeBanner } from './mock-mode-banner.js';
7
7
  import { ThemeProvider } from '../theme-provider.js';
8
8
  import { PaletteProvider } from './palette-provider.js';
9
+ import { RowsProvider } from './rows-provider.js';
9
10
  import { ErrorReportingProvider } from '../../error-reporting/error-reporting-provider.js';
10
11
  import { resolveErrorReporting } from '../../error-reporting/reporter.js';
11
12
  import { browserStaleChunkReload } from '../../lib/stale-chunk-reload.js';
@@ -17,9 +18,9 @@ import { browserStaleChunkReload } from '../../lib/stale-chunk-reload.js';
17
18
  // router: it queries too, and shows on every route like the mock banner.
18
19
  // It also reloads the page once when a lazy chunk is gone after a deploy
19
20
  // (lib/stale-chunk-reload.ts), so no app adds its own listener.
20
- export function FoundationProviders({ mockMode, queryClient, errorReporting, palette, palettePicker = false, children, }) {
21
+ export function FoundationProviders({ mockMode, queryClient, errorReporting, palette, palettePicker = false, rowsPicker = false, children, }) {
21
22
  const [client] = useState(() => queryClient ?? createQueryClient());
22
23
  const reporting = resolveErrorReporting(errorReporting);
23
24
  useEffect(() => browserStaleChunkReload().install(window), []);
24
- return (_jsx(ThemeProvider, { attribute: "class", defaultTheme: "system", enableSystem: true, forcedTheme: palette ? 'dark' : undefined, children: _jsxs(PaletteProvider, { palette: palette, picker: palettePicker, children: [_jsx(MockModeBanner, { active: mockMode }), _jsx(QueryClientProvider, { client: client, children: _jsx(AuthProvider, { children: reporting ? _jsx(ErrorReportingProvider, { options: reporting, children: children }) : children }) })] }) }));
25
+ return (_jsx(ThemeProvider, { attribute: "class", defaultTheme: "system", enableSystem: true, forcedTheme: palette ? 'dark' : undefined, children: _jsx(PaletteProvider, { palette: palette, picker: palettePicker, children: _jsxs(RowsProvider, { picker: rowsPicker, children: [_jsx(MockModeBanner, { active: mockMode }), _jsx(QueryClientProvider, { client: client, children: _jsx(AuthProvider, { children: reporting ? _jsx(ErrorReportingProvider, { options: reporting, children: children }) : children }) })] }) }) }));
25
26
  }
@@ -0,0 +1,13 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type RowsStore } from '../../lib/rows.js';
3
+ /**
4
+ * Puts this device's rows on <html> as data-rows (lib/rows.ts).
5
+ * FoundationProviders renders it; an app doesn't. Without `picker` the
6
+ * rows stay compact and a saved choice is ignored.
7
+ */
8
+ export declare function RowsProvider({ picker, store, children, }: {
9
+ picker?: boolean;
10
+ /** For tests; the browser's localStorage by default. */
11
+ store?: RowsStore;
12
+ children: ReactNode;
13
+ }): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useLayoutEffect, useMemo, useSyncExternalStore } from 'react';
3
+ import { RowsContext } from '../../hooks/use-rows.js';
4
+ import { browserRowsStore, subscribeToBrowserRowsStore } from '../../lib/rows.js';
5
+ /**
6
+ * Puts this device's rows on <html> as data-rows (lib/rows.ts).
7
+ * FoundationProviders renders it; an app doesn't. Without `picker` the
8
+ * rows stay compact and a saved choice is ignored.
9
+ */
10
+ export function RowsProvider({ picker = false, store = browserRowsStore, children, }) {
11
+ const subscribe = useCallback((listener) => (store === browserRowsStore ? subscribeToBrowserRowsStore(listener) : store.subscribe(listener)), [store]);
12
+ const saved = useSyncExternalStore(subscribe, store.get, () => null);
13
+ const rows = (picker && saved) || 'compact';
14
+ // Before paint, so the first frame already has the rows.
15
+ useLayoutEffect(() => {
16
+ const root = document.documentElement;
17
+ if (rows === 'compact')
18
+ delete root.dataset.rows;
19
+ else
20
+ root.dataset.rows = rows;
21
+ return () => {
22
+ delete root.dataset.rows;
23
+ };
24
+ }, [rows]);
25
+ const value = useMemo(() => ({
26
+ rows,
27
+ picker,
28
+ setRows: (next) => {
29
+ if (picker)
30
+ store.set(next);
31
+ },
32
+ }), [rows, picker, store]);
33
+ return _jsx(RowsContext.Provider, { value: value, children: children });
34
+ }
@@ -0,0 +1,12 @@
1
+ import type { RowsName } from '../lib/rows.js';
2
+ export type RowsState = {
3
+ /** The rows on screen: 'compact' unless this device picked 'regular'. */
4
+ rows: RowsName;
5
+ /** Whether this app lets a device pick (FoundationProviders' `rowsPicker`). */
6
+ picker: boolean;
7
+ /** Saves `rows` as this device's choice. Does nothing without the picker. */
8
+ setRows: (rows: RowsName) => void;
9
+ };
10
+ export declare const RowsContext: import("react").Context<RowsState>;
11
+ /** This device's table rows and, with the picker on, a way to change them. */
12
+ export declare function useRows(): RowsState;
@@ -0,0 +1,7 @@
1
+ import { createContext, useContext } from 'react';
2
+ const NO_PICKER = { rows: 'compact', picker: false, setRows: () => { } };
3
+ export const RowsContext = createContext(NO_PICKER);
4
+ /** This device's table rows and, with the picker on, a way to change them. */
5
+ export function useRows() {
6
+ return useContext(RowsContext);
7
+ }
package/dist/index.d.ts CHANGED
@@ -78,6 +78,8 @@ export { usePrefersReducedMotion } from './hooks/use-prefers-reduced-motion.js';
78
78
  export { useMuted } from './hooks/use-muted.js';
79
79
  export { usePalette, type PaletteState } from './hooks/use-palette.js';
80
80
  export { PALETTE_LABELS, PALETTE_STORAGE_KEY, PALETTES, isPaletteName, type PaletteName } from './lib/palettes.js';
81
+ export { useRows, type RowsState } from './hooks/use-rows.js';
82
+ export { ROWS, ROWS_LABELS, ROWS_STORAGE_KEY, isRowsName, type RowsName } from './lib/rows.js';
81
83
  export { createPushController, usePushPermission, type PushController, type PushControllerOptions, type PushEnvironment, type PushPermission, type PushStatus, } from './hooks/use-push-permission.js';
82
84
  export { cn } from './lib/utils.js';
83
85
  export { canVibrate, cancelCues, chime, cuesInSync, hush, onCuesRecovered, say, sequence, unlockAudio, vibrate, type ChimeOptions, type Cue, type CueTime, type SayOptions, type SequenceOptions, } from './lib/audio-cues.js';
package/dist/index.js CHANGED
@@ -81,6 +81,8 @@ export { usePrefersReducedMotion } from './hooks/use-prefers-reduced-motion.js';
81
81
  export { useMuted } from './hooks/use-muted.js';
82
82
  export { usePalette } from './hooks/use-palette.js';
83
83
  export { PALETTE_LABELS, PALETTE_STORAGE_KEY, PALETTES, isPaletteName } from './lib/palettes.js';
84
+ export { useRows } from './hooks/use-rows.js';
85
+ export { ROWS, ROWS_LABELS, ROWS_STORAGE_KEY, isRowsName } from './lib/rows.js';
84
86
  export { createPushController, usePushPermission, } from './hooks/use-push-permission.js';
85
87
  // Utilities
86
88
  export { cn } from './lib/utils.js';
@@ -0,0 +1,13 @@
1
+ export type StorageLike = Pick<Storage, 'getItem' | 'setItem'>;
2
+ export type DeviceChoiceStore<T extends string> = {
3
+ /** The saved choice, or null when there is none (or storage is blocked, or it names no choice). */
4
+ get: () => T | null;
5
+ set: (value: T) => void;
6
+ subscribe: (listener: () => void) => () => void;
7
+ /** Another tab saved a choice: forget the in-memory one and re-read. */
8
+ changedElsewhere: () => void;
9
+ };
10
+ export declare function createDeviceChoiceStore<T extends string>(key: string, isChoice: (value: unknown) => value is T, getStorage: () => StorageLike | undefined): DeviceChoiceStore<T>;
11
+ /** Subscribes to `store`, and (once) to other tabs' saves under `key`. */
12
+ export declare function otherTabsSubscriber<T extends string>(store: DeviceChoiceStore<T>, key: string): (listener: () => void) => () => void;
13
+ export declare const browserStorage: () => Storage | undefined;
@@ -0,0 +1,59 @@
1
+ // A look chosen on this device and kept in localStorage: the palette
2
+ // (lib/palettes.ts) and the table rows (lib/rows.ts). A saved value is read
3
+ // back only when it is one of the choices; when storage is blocked or full
4
+ // the choice is kept for this page; another tab's save replaces it.
5
+ export function createDeviceChoiceStore(key, isChoice, getStorage) {
6
+ // What this page chose, for when storage refuses it.
7
+ let memory = null;
8
+ const listeners = new Set();
9
+ const notify = () => {
10
+ for (const listener of listeners)
11
+ listener();
12
+ };
13
+ return {
14
+ get() {
15
+ if (memory)
16
+ return memory;
17
+ try {
18
+ const stored = getStorage()?.getItem(key);
19
+ return isChoice(stored) ? stored : null;
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ },
25
+ set(value) {
26
+ memory = value;
27
+ try {
28
+ getStorage()?.setItem(key, value);
29
+ }
30
+ catch {
31
+ // Storage blocked or full: kept for this page only.
32
+ }
33
+ notify();
34
+ },
35
+ subscribe(listener) {
36
+ listeners.add(listener);
37
+ return () => listeners.delete(listener);
38
+ },
39
+ changedElsewhere() {
40
+ memory = null;
41
+ notify();
42
+ },
43
+ };
44
+ }
45
+ /** Subscribes to `store`, and (once) to other tabs' saves under `key`. */
46
+ export function otherTabsSubscriber(store, key) {
47
+ let listening = false;
48
+ return (listener) => {
49
+ if (!listening && typeof window !== 'undefined') {
50
+ listening = true;
51
+ window.addEventListener('storage', (event) => {
52
+ if (event.key === key || event.key === null)
53
+ store.changedElsewhere();
54
+ });
55
+ }
56
+ return store.subscribe(listener);
57
+ };
58
+ }
59
+ export const browserStorage = () => (typeof window === 'undefined' ? undefined : window.localStorage);
@@ -1,3 +1,4 @@
1
+ import { type DeviceChoiceStore, type StorageLike } from './device-choice.js';
1
2
  export declare const PALETTES: readonly ["indigo-cyan", "indigo-rose", "graphite-periwinkle", "violet"];
2
3
  export type PaletteName = (typeof PALETTES)[number];
3
4
  /** Each palette's name as a person reads it, in the guide's ranked order. */
@@ -5,17 +6,8 @@ export declare const PALETTE_LABELS: Record<PaletteName, string>;
5
6
  /** Where a device's chosen palette is kept. */
6
7
  export declare const PALETTE_STORAGE_KEY = "ui-foundation:palette";
7
8
  export declare function isPaletteName(value: unknown): value is PaletteName;
8
- type StorageLike = Pick<Storage, 'getItem' | 'setItem'>;
9
- export type PaletteStore = {
10
- /** The saved choice, or null when there is none (or storage is blocked, or it names no palette). */
11
- get: () => PaletteName | null;
12
- set: (palette: PaletteName) => void;
13
- subscribe: (listener: () => void) => () => void;
14
- /** Another tab saved a choice: forget the in-memory one and re-read. */
15
- changedElsewhere: () => void;
16
- };
9
+ export type PaletteStore = DeviceChoiceStore<PaletteName>;
17
10
  /** The store under usePalette, taking the storage so its rules are unit tested (tests/palettes.test.ts). */
18
11
  export declare function createPaletteStore(getStorage: () => StorageLike | undefined): PaletteStore;
19
12
  export declare const browserPaletteStore: PaletteStore;
20
- export declare function subscribeToBrowserPaletteStore(listener: () => void): () => void;
21
- export {};
13
+ export declare const subscribeToBrowserPaletteStore: (listener: () => void) => () => void;
@@ -6,6 +6,7 @@
6
6
  // palette rides on <html> as data-palette, so popups portaled to <body>
7
7
  // wear it too, and styles/theme.css's `.dark[data-palette]` blocks do the
8
8
  // rest (components/app/palette-provider.tsx, hooks/use-palette.ts).
9
+ import { browserStorage, createDeviceChoiceStore, otherTabsSubscriber } from './device-choice.js';
9
10
  export const PALETTES = ['indigo-cyan', 'indigo-rose', 'graphite-periwinkle', 'violet'];
10
11
  /** Each palette's name as a person reads it, in the guide's ranked order. */
11
12
  export const PALETTE_LABELS = {
@@ -21,54 +22,7 @@ export function isPaletteName(value) {
21
22
  }
22
23
  /** The store under usePalette, taking the storage so its rules are unit tested (tests/palettes.test.ts). */
23
24
  export function createPaletteStore(getStorage) {
24
- // What this page chose, for when storage refuses it.
25
- let memory = null;
26
- const listeners = new Set();
27
- const notify = () => {
28
- for (const listener of listeners)
29
- listener();
30
- };
31
- return {
32
- get() {
33
- if (memory)
34
- return memory;
35
- try {
36
- const stored = getStorage()?.getItem(PALETTE_STORAGE_KEY);
37
- return isPaletteName(stored) ? stored : null;
38
- }
39
- catch {
40
- return null;
41
- }
42
- },
43
- set(palette) {
44
- memory = palette;
45
- try {
46
- getStorage()?.setItem(PALETTE_STORAGE_KEY, palette);
47
- }
48
- catch {
49
- // Storage blocked or full: kept for this page only.
50
- }
51
- notify();
52
- },
53
- subscribe(listener) {
54
- listeners.add(listener);
55
- return () => listeners.delete(listener);
56
- },
57
- changedElsewhere() {
58
- memory = null;
59
- notify();
60
- },
61
- };
62
- }
63
- export const browserPaletteStore = createPaletteStore(() => (typeof window === 'undefined' ? undefined : window.localStorage));
64
- let listeningForOtherTabs = false;
65
- export function subscribeToBrowserPaletteStore(listener) {
66
- if (!listeningForOtherTabs && typeof window !== 'undefined') {
67
- listeningForOtherTabs = true;
68
- window.addEventListener('storage', (event) => {
69
- if (event.key === PALETTE_STORAGE_KEY || event.key === null)
70
- browserPaletteStore.changedElsewhere();
71
- });
72
- }
73
- return browserPaletteStore.subscribe(listener);
25
+ return createDeviceChoiceStore(PALETTE_STORAGE_KEY, isPaletteName, getStorage);
74
26
  }
27
+ export const browserPaletteStore = createPaletteStore(browserStorage);
28
+ export const subscribeToBrowserPaletteStore = otherTabsSubscriber(browserPaletteStore, PALETTE_STORAGE_KEY);
@@ -0,0 +1,12 @@
1
+ import { type DeviceChoiceStore, type StorageLike } from './device-choice.js';
2
+ export declare const ROWS: readonly ["compact", "regular"];
3
+ export type RowsName = (typeof ROWS)[number];
4
+ export declare const ROWS_LABELS: Record<RowsName, string>;
5
+ /** Where a device's chosen rows are kept. */
6
+ export declare const ROWS_STORAGE_KEY = "ui-foundation:rows";
7
+ export declare function isRowsName(value: unknown): value is RowsName;
8
+ export type RowsStore = DeviceChoiceStore<RowsName>;
9
+ /** The store under useRows (tests/rows.test.ts). */
10
+ export declare function createRowsStore(getStorage: () => StorageLike | undefined): RowsStore;
11
+ export declare const browserRowsStore: RowsStore;
12
+ export declare const subscribeToBrowserRowsStore: (listener: () => void) => () => void;
@@ -0,0 +1,25 @@
1
+ // How tall a table's rows are on this device (design-language.md
2
+ // "Density", "Rows on this device"). Compact is the default; with
3
+ // FoundationProviders' `rowsPicker` the app shell's look menu offers
4
+ // Regular too, remembered on this device (localStorage, this store). The
5
+ // choice rides on <html> as data-rows, and styles/theme.css's
6
+ // [data-rows="regular"] retunes every table's cells under it: DataTable,
7
+ // the Table primitive and tables in notes. A data-density on a nearer
8
+ // ancestor (a hub's compact wrapper) still wins there.
9
+ import { browserStorage, createDeviceChoiceStore, otherTabsSubscriber } from './device-choice.js';
10
+ export const ROWS = ['compact', 'regular'];
11
+ export const ROWS_LABELS = {
12
+ compact: 'Compact',
13
+ regular: 'Regular',
14
+ };
15
+ /** Where a device's chosen rows are kept. */
16
+ export const ROWS_STORAGE_KEY = 'ui-foundation:rows';
17
+ export function isRowsName(value) {
18
+ return typeof value === 'string' && ROWS.includes(value);
19
+ }
20
+ /** The store under useRows (tests/rows.test.ts). */
21
+ export function createRowsStore(getStorage) {
22
+ return createDeviceChoiceStore(ROWS_STORAGE_KEY, isRowsName, getStorage);
23
+ }
24
+ export const browserRowsStore = createRowsStore(browserStorage);
25
+ export const subscribeToBrowserRowsStore = otherTabsSubscriber(browserRowsStore, ROWS_STORAGE_KEY);
@@ -98,6 +98,13 @@ export type A11ySuiteOptions = {
98
98
  * locator that matches each of them: Playwright's strict mode refuses
99
99
  * `expect(page.locator('[data-state="success"]')).toBeVisible()` as soon
100
100
  * as two match. Use it before reading or scanning a screen.
101
+ *
102
+ * It waits on the first *visible* data view. A responsive component can
103
+ * render two elements that both carry `data-state` and show one of them by
104
+ * viewport: a `ModuleStrip mobile="row"` puts each `ModuleCard` (hidden on a
105
+ * phone) beside its chip (hidden from `md` up). The card comes first in the
106
+ * document, so on a phone `.first()` alone is the hidden one and the wait
107
+ * never ended.
101
108
  */
102
109
  export declare function expectDataViewsLoaded(page: Page, { success }?: {
103
110
  success?: boolean;
@@ -213,10 +213,17 @@ const NAV_PAGE_BUDGET_MS = 10_000;
213
213
  * locator that matches each of them: Playwright's strict mode refuses
214
214
  * `expect(page.locator('[data-state="success"]')).toBeVisible()` as soon
215
215
  * as two match. Use it before reading or scanning a screen.
216
+ *
217
+ * It waits on the first *visible* data view. A responsive component can
218
+ * render two elements that both carry `data-state` and show one of them by
219
+ * viewport: a `ModuleStrip mobile="row"` puts each `ModuleCard` (hidden on a
220
+ * phone) beside its chip (hidden from `md` up). The card comes first in the
221
+ * document, so on a phone `.first()` alone is the hidden one and the wait
222
+ * never ended.
216
223
  */
217
224
  export async function expectDataViewsLoaded(page, { success = true } = {}) {
218
225
  if (success)
219
- await expect(page.locator('[data-state="success"]').first()).toBeVisible();
226
+ await expect(page.locator('[data-state="success"]').filter({ visible: true }).first()).toBeVisible();
220
227
  // A data view renders its skeleton from its first paint, so once the
221
228
  // screen is up every one of them is either loading or settled.
222
229
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.67.1",
3
+ "version": "4.68.1",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/styles/theme.css CHANGED
@@ -390,6 +390,17 @@
390
390
  --sidebar-ring: var(--gray-400);
391
391
  }
392
392
 
393
+ /*
394
+ * Regular rows, a device's pick in the shell's look menu (lib/rows.ts,
395
+ * FoundationProviders' rowsPicker): RowsProvider puts data-rows on <html>.
396
+ * The size every table had before 4.63. A data-density on a nearer
397
+ * ancestor still wins, since it is declared closer to the cells.
398
+ */
399
+ [data-rows="regular"] {
400
+ --table-cell-py: 0.5rem;
401
+ --table-head-height: 2.5rem;
402
+ }
403
+
393
404
  [data-density="compact"] {
394
405
  --table-cell-py: 0.25rem; /* the default's, since the default is compact */
395
406
  --table-head-height: 2rem;