@tristan2828/ui-foundation 4.141.0 → 4.142.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,47 +3,48 @@
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 56–138
7
- - [Glow](#glow) · lines 140–159
8
- - [Semantic tones](#semantic-tones) · lines 161–189
9
- - [The three badge styles](#the-three-badge-styles) · lines 191–208
10
- - [Status marks](#status-marks) · lines 210–253
11
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 255–284
12
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 286–297
13
- - [Logos and brand marks](#logos-and-brand-marks) · lines 299–339
14
- - [Categorical colour](#categorical-colour) · lines 341–406
15
- - [Heat scale](#heat-scale) · lines 408–460
16
- - [Depth ramps](#depth-ramps) · lines 462–529
17
- - [A stored colour](#a-stored-colour) · lines 531–578
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 580–601
19
- - [Typography](#typography) · lines 603–773
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 637–669
21
- - [Written text (notes)](#written-text-notes) · lines 671–773
22
- - [Density](#density) · lines 775–896
23
- - [Rows on this device](#rows-on-this-device) · lines 842–869
24
- - [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 871–896
25
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 898–1008
26
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1010–1082
27
- - [Notices](#notices) · lines 1084–1111
28
- - [A value over time](#a-value-over-time) · lines 1113–1243
29
- - [Several values over time](#several-values-over-time) · lines 1162–1200
30
- - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1202–1243
31
- - [A list as a board](#a-list-as-a-board) · lines 1245–1355
32
- - [Order, groups and the header](#order-groups-and-the-header) · lines 1298–1355
33
- - [A list as cards](#a-list-as-cards) · lines 1357–1404
34
- - [Images full screen](#images-full-screen) · lines 1406–1452
35
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1454–1490
36
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1492–1528
37
- - [A few equal things](#a-few-equal-things) · lines 1530–1645
38
- - [An overview page](#an-overview-page) · lines 1647–1712
39
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1714–1777
40
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1779–1866
41
- - [Picking at random](#picking-at-random) · lines 1868–1899
42
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1901–1968
43
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1970–1989
44
- - [A quick add line](#a-quick-add-line) · lines 1991–2019
45
- - [A month calendar](#a-month-calendar) · lines 2021–2051
46
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2053–2112
6
+ - [Palettes](#palettes) · lines 57–140
7
+ - [Glow](#glow) · lines 142–161
8
+ - [Semantic tones](#semantic-tones) · lines 163–191
9
+ - [The three badge styles](#the-three-badge-styles) · lines 193–210
10
+ - [Status marks](#status-marks) · lines 212–255
11
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 257–286
12
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 288–299
13
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 301–341
14
+ - [Categorical colour](#categorical-colour) · lines 343–408
15
+ - [Heat scale](#heat-scale) · lines 410–462
16
+ - [Depth ramps](#depth-ramps) · lines 464–531
17
+ - [A stored colour](#a-stored-colour) · lines 533–580
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 582–603
19
+ - [Typography](#typography) · lines 605–775
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 639–671
21
+ - [Written text (notes)](#written-text-notes) · lines 673–775
22
+ - [Density](#density) · lines 777–899
23
+ - [Rows on this device](#rows-on-this-device) · lines 844–872
24
+ - [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 874–899
25
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 901–1011
26
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1013–1085
27
+ - [Notices](#notices) · lines 1087–1114
28
+ - [A value over time](#a-value-over-time) · lines 1116–1246
29
+ - [Several values over time](#several-values-over-time) · lines 1165–1203
30
+ - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1205–1246
31
+ - [A list as a board](#a-list-as-a-board) · lines 1248–1358
32
+ - [Order, groups and the header](#order-groups-and-the-header) · lines 1301–1358
33
+ - [A list as cards](#a-list-as-cards) · lines 1360–1407
34
+ - [Images full screen](#images-full-screen) · lines 1409–1455
35
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1457–1493
36
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1495–1531
37
+ - [A few equal things](#a-few-equal-things) · lines 1533–1648
38
+ - [An overview page](#an-overview-page) · lines 1650–1715
39
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1717–1780
40
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1782–1869
41
+ - [Picking at random](#picking-at-random) · lines 1871–1902
42
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1904–1971
43
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1973–1992
44
+ - [A quick add line](#a-quick-add-line) · lines 1994–2022
45
+ - [A month calendar](#a-month-calendar) · lines 2024–2054
46
+ - [A settings page](#a-settings-page) · lines 2056–2113
47
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2115–2174
47
48
 
48
49
  <!-- /index -->
49
50
 
@@ -73,7 +74,8 @@ And one light one, which an app opts into by name (`LIGHT_PALETTES`):
73
74
 
74
75
  **How an app picks one.** `<FoundationProviders palette="indigo-cyan">`
75
76
  names the app's default. Add `palettePicker` and the app shell's header
76
- offers the four dark ones (with swatches); the one picked is remembered
77
+ offers the four dark ones (with swatches), or a page does, as tiles
78
+ (`PaletteSetting`, "A settings page"); the one picked is remembered
77
79
  on that device, and a new device starts on the default. `usePalette()`
78
80
  reads the palette on screen. Without `palette`, nothing changes: light and
79
81
  dark follow the system, with the toggle in the header.
@@ -844,7 +846,8 @@ set, not a `DataTable` prop:
844
846
  An app can let each device choose its table rows: `rowsPicker` on
845
847
  `FoundationProviders` adds **Rows on this device** to the shell's look
846
848
  menu (under the palettes, or a menu of its own beside the light/dark
847
- toggle in an app without a palette).
849
+ toggle in an app without a palette). `RowsSetting` offers the same choice
850
+ on a page ("A settings page").
848
851
 
849
852
  ```tsx
850
853
  <FoundationProviders palette="indigo-cyan" palettePicker rowsPicker …>
@@ -2050,6 +2053,65 @@ package's `MonthCalendar`. Not a date picker, which is
2050
2053
  - `today` comes from the app's own day (`todayIn`); every day is a plain
2051
2054
  `'YYYY-MM-DD'`, so no zone moves one.
2052
2055
 
2056
+ ## A settings page
2057
+
2058
+ One page for what an app lets a person choose: the groups listed down the
2059
+ side, the one you're on beside them as a card of rows. Parts the app puts
2060
+ together, so a group's routes, its rows and where a choice is kept are the
2061
+ app's:
2062
+
2063
+ ```tsx
2064
+ const GROUPS = [
2065
+ { to: '/settings', label: 'Look' },
2066
+ { to: '/settings/notifications', label: 'Notifications' },
2067
+ ]
2068
+
2069
+ // the layout route
2070
+ <SettingsPage title="Settings" groups={GROUPS}><Outlet /></SettingsPage>
2071
+
2072
+ // a group's route
2073
+ <SettingsCard>
2074
+ <SettingsRow
2075
+ label="Text Size"
2076
+ help="For this browser only."
2077
+ control={(aria) => <ChoiceButtons {...aria} options={SIZES} value={size} onValueChange={save} />}
2078
+ />
2079
+ <PaletteSetting />
2080
+ <RowsSetting />
2081
+ </SettingsCard>
2082
+ ```
2083
+
2084
+ - **Each group is a route**, so it has an address, Back and a deep link.
2085
+ The first is the layout's index route, at the page's own address. A
2086
+ group that holds nothing is left out, and has no route: send an unknown
2087
+ path under the page to the first group.
2088
+ - **The current group** is marked as the sidebar marks its entry, a tint
2089
+ and a 3px bar, and stays marked on a page below it. Past the first, the
2090
+ bar's trail reads "Settings / Notifications" and a phone's back arrow
2091
+ goes to the first; a page below a group puts up its own trail.
2092
+ - **In a box under 40rem** (a phone, or a window the sidebar has narrowed)
2093
+ the groups wrap in a row above the card, each 40px tall.
2094
+ - **A row** is its label, one short line of help and its control. Spread
2095
+ what the `control` function is handed on the control: it names it by the
2096
+ label and the help. A control that is one thing (a select, a switch)
2097
+ also gets an `id`, and the row its `htmlFor`.
2098
+ - **`layout="below"`** is for a control with a size of its own: tiles, a
2099
+ list to order. Everything that fits on a line stays beside its label;
2100
+ it drops under the words by itself where it doesn't fit.
2101
+ - **A table goes after the card**, as any framed list: a
2102
+ `DataTable look="framed"` under its `ListHeader`. The card stops at 832px
2103
+ and the table doesn't.
2104
+ - **A choice kept on the device says so** in its help: "For this browser
2105
+ only." A row has no saving state: a device's choice saves at once, and a
2106
+ control that saves to a server shows its own.
2107
+ - **`PaletteSetting` and `RowsSetting`** are the shell's look menu as rows,
2108
+ kept under the same keys. Each draws nothing where the app doesn't let a
2109
+ device pick, so a page can always render them.
2110
+ - **With both on a page, `<AppShell lookMenu={false}>`** takes the look menu
2111
+ out of the header. `palettePicker` and `rowsPicker` stay on: they say a
2112
+ device may choose, and its choice applies. Don't turn the menu off before
2113
+ the page has the two: a device that picked would have no way back.
2114
+
2053
2115
  ## The sidebar and the phone's bar
2054
2116
 
2055
2117
  `AppShell`'s navigation, all set in the app's `nav` and `bottomBar`, and
@@ -128,11 +128,19 @@ export declare function navPathname(to: string): string;
128
128
  /** Every `to` in a nav, each once, in order: the pages its sidebar links. */
129
129
  export declare function navTargets(nav: readonly NavEntry[]): string[];
130
130
  /**
131
- * The one entry to mark active: the most specific that matches, by the path
132
- * of its `to` (its query string ignored). With '/tasks' and
133
- * '/tasks/categories' both in the nav, '/tasks/categories/2' marks
134
- * Categories only, and '/tasks/3' marks Tasks. Of two entries with the same
135
- * path, the first.
131
+ * The one of a list of links that `pathname` is at or under: the most
132
+ * specific that matches, by the path of its `to` (its query string
133
+ * ignored). Of two with the same path, the first. The rule for the nav's
134
+ * entries (activeNavItem) and for a settings page's groups.
135
+ */
136
+ export declare function mostSpecificTo<T extends {
137
+ to: string;
138
+ end?: boolean;
139
+ }>(items: readonly T[], pathname: string): T | undefined;
140
+ /**
141
+ * The one entry to mark active: the most specific that matches
142
+ * (mostSpecificTo). With '/tasks' and '/tasks/categories' both in the nav,
143
+ * '/tasks/categories/2' marks Categories only, and '/tasks/3' marks Tasks.
136
144
  */
137
145
  export declare function activeNavItem(nav: readonly NavEntry[], pathname: string): NavItem | undefined;
138
146
  /** The `to` of the one entry to mark active (`activeNavItem`). */
@@ -89,16 +89,15 @@ function matches(path, end, pathname) {
89
89
  return pathname.startsWith(path.endsWith('/') ? path : `${path}/`);
90
90
  }
91
91
  /**
92
- * The one entry to mark active: the most specific that matches, by the path
93
- * of its `to` (its query string ignored). With '/tasks' and
94
- * '/tasks/categories' both in the nav, '/tasks/categories/2' marks
95
- * Categories only, and '/tasks/3' marks Tasks. Of two entries with the same
96
- * path, the first.
92
+ * The one of a list of links that `pathname` is at or under: the most
93
+ * specific that matches, by the path of its `to` (its query string
94
+ * ignored). Of two with the same path, the first. The rule for the nav's
95
+ * entries (activeNavItem) and for a settings page's groups.
97
96
  */
98
- export function activeNavItem(nav, pathname) {
97
+ export function mostSpecificTo(items, pathname) {
99
98
  let best;
100
99
  let bestLength = -1;
101
- for (const item of navItems(nav)) {
100
+ for (const item of items) {
102
101
  const path = navPathname(item.to);
103
102
  if (matches(path, item.end, pathname) && path.length > bestLength) {
104
103
  best = item;
@@ -107,6 +106,14 @@ export function activeNavItem(nav, pathname) {
107
106
  }
108
107
  return best;
109
108
  }
109
+ /**
110
+ * The one entry to mark active: the most specific that matches
111
+ * (mostSpecificTo). With '/tasks' and '/tasks/categories' both in the nav,
112
+ * '/tasks/categories/2' marks Categories only, and '/tasks/3' marks Tasks.
113
+ */
114
+ export function activeNavItem(nav, pathname) {
115
+ return mostSpecificTo(navItems(nav), pathname);
116
+ }
110
117
  /** The `to` of the one entry to mark active (`activeNavItem`). */
111
118
  export function activeNavTo(nav, pathname) {
112
119
  return activeNavItem(nav, pathname)?.to;
@@ -86,6 +86,17 @@ export type AppShellProps = {
86
86
  * pages under them. Keep the labels short: a word or two.
87
87
  */
88
88
  navLook?: NavLook;
89
+ /**
90
+ * The header's look menu: the palettes and the table rows, for a device
91
+ * to pick from. Drawn where the app lets a device pick
92
+ * (`FoundationProviders`' `palettePicker` and `rowsPicker`). `false`
93
+ * draws none, for an app that offers them on a settings page instead;
94
+ * what a device picked still applies. Put `PaletteSetting` and
95
+ * `RowsSetting` on a page first: with the menu off and neither on a
96
+ * page, a device that picked has no way to change back. The light/dark
97
+ * toggle of an app without a palette isn't part of it and stays.
98
+ */
99
+ lookMenu?: boolean;
89
100
  /**
90
101
  * Search in the header: a box ("Search", or `placeholder`) from
91
102
  * md up and a button on a phone (the bottom bar's Search instead, where
@@ -96,4 +107,4 @@ export type AppShellProps = {
96
107
  */
97
108
  search?: AppShellSearch;
98
109
  };
99
- export declare function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarOpen, version, bottomBar, navLook, search, }: AppShellProps): import("react").JSX.Element;
110
+ export declare function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarOpen, version, bottomBar, navLook, lookMenu, search, }: AppShellProps): import("react").JSX.Element;
@@ -50,12 +50,14 @@ function CloseMobileSidebarOnNavigate() {
50
50
  // with a light palette, always light), so it has no light/dark toggle, and with the picker on it gets the look menu
51
51
  // in its place (design-language.md "Palettes"). With the rows picker the
52
52
  // same menu offers the table rows (design-language.md "Density"); an app
53
- // without a palette keeps its toggle beside it.
54
- function LookControl() {
53
+ // without a palette keeps its toggle beside it. With `menu` off (AppShell's
54
+ // `lookMenu`) only the toggle is left, and the choices are a settings
55
+ // page's (look-settings.tsx).
56
+ function LookControl({ menu }) {
55
57
  const { palette, picker } = usePalette();
56
58
  const rows = useRows();
57
59
  const pickPalette = picker && isPaletteName(palette) ? palette : null;
58
- return (_jsxs(_Fragment, { children: [!palette && _jsx(ThemeToggle, {}), (pickPalette || rows.picker) && _jsx(LookMenu, { palette: pickPalette })] }));
60
+ return (_jsxs(_Fragment, { children: [!palette && _jsx(ThemeToggle, {}), menu && (pickPalette || rows.picker) && _jsx(LookMenu, { palette: pickPalette })] }));
59
61
  }
60
62
  // Each palette's swatch is its own background with its accent and second
61
63
  // colour on it, read from the palette primitives, so the menu shows all
@@ -219,7 +221,7 @@ function PhoneBack({ back }) {
219
221
  function AppShellSkeleton() {
220
222
  return (_jsxs("div", { className: "flex h-screen w-full gap-4 p-4", "data-state": "loading", children: [_jsx(Skeleton, { className: "h-full w-56 shrink-0" }), _jsxs("div", { className: "flex-1 space-y-4 pt-2", children: [_jsx(Skeleton, { className: "h-8 w-64" }), _jsx(Skeleton, { className: "h-40 w-full" })] })] }));
221
223
  }
222
- export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarOpen = true, version, bottomBar, navLook = 'list', search, }) {
224
+ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarOpen = true, version, bottomBar, navLook = 'list', lookMenu = true, search, }) {
223
225
  const { user, status, error, retry, logout } = useAuth();
224
226
  const location = useLocation();
225
227
  const reporter = useErrorReporter();
@@ -272,5 +274,5 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
272
274
  // (AuthProvider), so this stays a deliberate logout: a
273
275
  // clean /login, never the previous user's page as `from`.
274
276
  logout().catch(() => { });
275
- }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsx(PageTrailContext.Provider, { value: trailSlot, children: _jsxs("div", { "data-slot": "app-shell-column", className: "flex w-full min-w-0 flex-1 flex-col bg-background", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [back && _jsx(PhoneBack, { back: back }), _jsx(SidebarTrigger, { className: cn(back && hasBar && 'max-md:hidden') }), _jsx("div", { "data-slot": "app-shell-trail", className: "min-w-0 flex-1", children: trail.length > 0 && _jsx(PageTrail, { crumbs: trail, "aria-label": "You are here", className: "max-md:hidden" }) }), search && _jsx(SearchPalette, { ref: paletteRef, search: search, nav: nav, onBar: bottomBarHasSearch(barItems) }), _jsx(LookControl, {})] }), _jsx(OfflineNotice, {}), _jsx(SidebarInset, { className: "min-w-0", children: _jsx("div", { className: cn('flex-1 p-6', hasBar && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) }) })] }) }), hasBar && (_jsx(BottomBar, { items: barItems, nav: nav, activeTo: activeTo, navLook: navLook, onSearch: (opener) => paletteRef.current?.openFrom(opener) }))] }), _jsx(Toaster, {})] }));
277
+ }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsx(PageTrailContext.Provider, { value: trailSlot, children: _jsxs("div", { "data-slot": "app-shell-column", className: "flex w-full min-w-0 flex-1 flex-col bg-background", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [back && _jsx(PhoneBack, { back: back }), _jsx(SidebarTrigger, { className: cn(back && hasBar && 'max-md:hidden') }), _jsx("div", { "data-slot": "app-shell-trail", className: "min-w-0 flex-1", children: trail.length > 0 && _jsx(PageTrail, { crumbs: trail, "aria-label": "You are here", className: "max-md:hidden" }) }), search && _jsx(SearchPalette, { ref: paletteRef, search: search, nav: nav, onBar: bottomBarHasSearch(barItems) }), _jsx(LookControl, { menu: lookMenu })] }), _jsx(OfflineNotice, {}), _jsx(SidebarInset, { className: "min-w-0", children: _jsx("div", { className: cn('flex-1 p-6', hasBar && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) }) })] }) }), hasBar && (_jsx(BottomBar, { items: barItems, nav: nav, activeTo: activeTo, navLook: navLook, onSearch: (opener) => paletteRef.current?.openFrom(opener) }))] }), _jsx(Toaster, {})] }));
276
278
  }
@@ -23,15 +23,17 @@ export declare function FoundationProviders({ mockMode, queryClient, errorReport
23
23
  */
24
24
  palette?: AppPaletteName;
25
25
  /**
26
- * With `palette`: the shell offers all four palettes, and the one picked
27
- * is remembered on this device. A new device starts on `palette`.
26
+ * With `palette`: a device may pick any of the four palettes, in the
27
+ * shell's look menu or on a settings page (`PaletteSetting`), and the one
28
+ * picked is remembered on this device. A new device starts on `palette`.
28
29
  * Ignored with a light palette, which is never in the picker.
29
30
  */
30
31
  palettePicker?: boolean;
31
32
  /**
32
- * The shell's look menu offers the table rows, Compact (the default) or
33
- * Regular, remembered on this device (design-language.md "Density",
34
- * "Rows on this device"). Off, every device is compact.
33
+ * A device may pick its table rows, Compact (the default) or Regular, in
34
+ * the shell's look menu or on a settings page (`RowsSetting`), remembered
35
+ * on this device (design-language.md "Density", "Rows on this device").
36
+ * Off, every device is compact.
35
37
  */
36
38
  rowsPicker?: boolean;
37
39
  children: ReactNode;
@@ -0,0 +1,24 @@
1
+ import type { ReactNode } from 'react';
2
+ export type PaletteSettingProps = {
3
+ /** Defaults to "Palette". */
4
+ label?: string;
5
+ /** Defaults to "For this browser only." */
6
+ help?: ReactNode;
7
+ };
8
+ /**
9
+ * This device's palette, as a settings row of tiles, each a small page in
10
+ * its palette's colours: one radio group, the page changing at once. Draws
11
+ * nothing unless the app lets a device pick (`palettePicker`).
12
+ */
13
+ export declare function PaletteSetting({ label, help }: PaletteSettingProps): import("react").JSX.Element | null;
14
+ export type RowsSettingProps = {
15
+ /** Defaults to "Table Rows". */
16
+ label?: string;
17
+ /** Defaults to "For this browser only." */
18
+ help?: ReactNode;
19
+ };
20
+ /**
21
+ * This device's table rows, Compact or Regular, as a settings row. Draws
22
+ * nothing unless the app lets a device pick (`rowsPicker`).
23
+ */
24
+ export declare function RowsSetting({ label, help }: RowsSettingProps): import("react").JSX.Element | null;
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from 'cn';
3
+ import { RadioGroup, RadioGroupItem } from '../ui/radio-group.js';
4
+ import { usePalette } from '../../hooks/use-palette.js';
5
+ import { useRows } from '../../hooks/use-rows.js';
6
+ import { isPaletteName, PALETTE_LABELS, PALETTES } from '../../lib/palettes.js';
7
+ import { ROWS, ROWS_LABELS } from '../../lib/rows.js';
8
+ import { ChoiceButtons } from './choice-buttons.js';
9
+ import { SettingsRow } from './settings-page.js';
10
+ const THIS_BROWSER = 'For this browser only.';
11
+ // A tile: the preview and its name, one radio. The picked one's edge is
12
+ // twice as thick as well as another colour; the focused one wears the
13
+ // focus ring.
14
+ const TILE = cn('relative cursor-pointer overflow-hidden rounded-lg border border-border bg-card', 'has-data-checked:border-primary has-data-checked:ring-1 has-data-checked:ring-primary', 'has-[:focus-visible]:border-ring has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/50');
15
+ // A small page in the palette's own colours: a sidebar's strip, then a
16
+ // title, a line and a button. Read from the palette primitives, so every
17
+ // tile shows its own whichever palette is on screen.
18
+ function PalettePreview({ name }) {
19
+ const colour = (part) => `var(--palette-${name}-${part})`;
20
+ const bar = (part, className) => (_jsx("span", { className: cn('h-1.25 rounded-full', className), style: { background: colour(part) } }));
21
+ return (_jsxs("span", { "aria-hidden": true, className: "grid h-16 grid-cols-[--spacing(8.5)_minmax(0,1fr)] border-b border-border", style: { background: colour('background') }, children: [_jsxs("span", { className: "flex flex-col gap-1.25 px-1.5 py-2", style: { background: colour('panel') }, children: [bar('accent'), bar('dim'), bar('dim')] }), _jsxs("span", { className: "flex flex-col gap-1.5 p-2.25", children: [bar('dim', 'w-[70%]'), bar('second', 'w-[40%]'), bar('accent', 'h-2.5 w-[28%]')] })] }));
22
+ }
23
+ /**
24
+ * This device's palette, as a settings row of tiles, each a small page in
25
+ * its palette's colours: one radio group, the page changing at once. Draws
26
+ * nothing unless the app lets a device pick (`palettePicker`).
27
+ */
28
+ export function PaletteSetting({ label = 'Palette', help = THIS_BROWSER }) {
29
+ const { palette, picker, setPalette } = usePalette();
30
+ if (!picker)
31
+ return null;
32
+ return (_jsx(SettingsRow, { label: label, help: help, layout: "below", control: (aria) => (_jsx(RadioGroup, { ...aria, "data-slot": "palette-tiles", value: palette, onValueChange: (next) => {
33
+ if (isPaletteName(next))
34
+ setPalette(next);
35
+ }, className: "max-w-180 grid-cols-[repeat(auto-fit,minmax(min(100%,--spacing(35)),1fr))] gap-3", children: PALETTES.map((name) => (_jsxs("label", { "data-slot": "palette-tile", className: TILE, children: [_jsx(RadioGroupItem, { value: name, className: "sr-only!" }), _jsx(PalettePreview, { name: name }), _jsx("span", { className: "block px-2.5 py-2 type-caption", children: PALETTE_LABELS[name] })] }, name))) })) }));
36
+ }
37
+ const ROWS_OPTIONS = ROWS.map((value) => ({ value, label: ROWS_LABELS[value] }));
38
+ /**
39
+ * This device's table rows, Compact or Regular, as a settings row. Draws
40
+ * nothing unless the app lets a device pick (`rowsPicker`).
41
+ */
42
+ export function RowsSetting({ label = 'Table Rows', help = THIS_BROWSER }) {
43
+ const { rows, picker, setRows } = useRows();
44
+ if (!picker)
45
+ return null;
46
+ return (_jsx(SettingsRow, { label: label, help: help, control: (aria) => (_jsx(ChoiceButtons, { ...aria, options: ROWS_OPTIONS, value: rows, onValueChange: (next) => {
47
+ if (next)
48
+ setRows(next);
49
+ } })) }));
50
+ }
@@ -0,0 +1,75 @@
1
+ import { type ReactNode } from 'react';
2
+ /** One group of settings: the address its route is at, and its name. */
3
+ export type SettingsGroup = {
4
+ to: string;
5
+ label: string;
6
+ };
7
+ export type SettingsPageProps = {
8
+ /** The page's name: its heading, the groups' landmark and the top of the trail. */
9
+ title: string;
10
+ /**
11
+ * The groups, in order, each at its own route under the page. The first
12
+ * is at the page's own address (the layout's index route). Leave out a
13
+ * group that holds nothing.
14
+ */
15
+ groups: readonly SettingsGroup[];
16
+ /** The current group: the layout route's `<Outlet />`. */
17
+ children: ReactNode;
18
+ className?: string;
19
+ };
20
+ /**
21
+ * The layout of a settings page, inside a router: `title`, the links to
22
+ * `groups` down the side (in a row above, in a box under 40rem), and the
23
+ * current group. Past the first group it puts the page's trail in the
24
+ * shell's bar.
25
+ *
26
+ * <Route path="settings" element={<SettingsPage title="Settings" groups={GROUPS}><Outlet /></SettingsPage>}>
27
+ * <Route index element={<LookSettings />} />
28
+ * <Route path="notifications" element={<NotificationSettings />} />
29
+ * </Route>
30
+ */
31
+ export declare function SettingsPage({ title, groups, children, className }: SettingsPageProps): import("react").JSX.Element;
32
+ export type SettingsCardProps = {
33
+ /** The group's `SettingsRow`s. */
34
+ children: ReactNode;
35
+ className?: string;
36
+ };
37
+ /**
38
+ * A group's rows, in a bordered card that stops growing at 832px (a step
39
+ * of the spacing scale, so it grows with the density). It has no heading:
40
+ * the group's name is the link beside it. A table the group holds goes
41
+ * after it.
42
+ */
43
+ export declare function SettingsCard({ children, className }: SettingsCardProps): import("react").JSX.Element;
44
+ /** What names a row's control: spread it on the control. */
45
+ export type SettingsRowAria = {
46
+ 'aria-labelledby': string;
47
+ /** Only with `help`. */
48
+ 'aria-describedby'?: string;
49
+ };
50
+ export type SettingsRowProps = {
51
+ label: string;
52
+ /** One short line under the label. */
53
+ help?: ReactNode;
54
+ /**
55
+ * The setting's control, or a function handed the `aria-*` that name it
56
+ * by the row's label and help, to spread on it.
57
+ */
58
+ control: ReactNode | ((aria: SettingsRowAria) => ReactNode);
59
+ /**
60
+ * `'beside'` (the default): the control at the row's end, dropping under
61
+ * the words where they don't fit on a line. `'below'`: always under
62
+ * them, at the row's full width, for a control with a size of its own
63
+ * (tiles, a list).
64
+ */
65
+ layout?: 'beside' | 'below';
66
+ /**
67
+ * The control's id, where it is one thing a label can name (a select, a
68
+ * switch): the label is then its `<label>`, and a click on the words
69
+ * reaches it. A group of buttons or radios has none.
70
+ */
71
+ htmlFor?: string;
72
+ className?: string;
73
+ };
74
+ /** One setting in a `SettingsCard`: what it is, and its control. */
75
+ export declare function SettingsRow({ label, help, control, layout, htmlFor, className }: SettingsRowProps): import("react").JSX.Element;
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A settings page: its groups listed down the side, the one you're on
3
+ // beside them as a card of rows (design-language.md "A settings page").
4
+ // Parts an app puts together, not one component from a list:
5
+ //
6
+ // - SettingsPage is the layout route: the title, the groups' links and the
7
+ // current group's content. The routes are the app's, one per group, the
8
+ // first at the page's own address.
9
+ // - SettingsCard holds a group's rows; what else the group has (a table)
10
+ // goes after it.
11
+ // - SettingsRow is one setting: its label and help, and its control beside
12
+ // them or, with `layout="below"`, under them.
13
+ //
14
+ // Where a choice is kept, and any saving, is the control's own.
15
+ import { useId } from 'react';
16
+ import { Link, useLocation } from 'react-router';
17
+ import { cn } from 'cn';
18
+ import { Card } from '../ui/card.js';
19
+ import { mostSpecificTo, navPathname } from './app-shell-nav.js';
20
+ import { usePageTrail } from './page-trail-context.js';
21
+ // A group's link: marked as the sidebar marks its current entry, a tint and
22
+ // a 3px bar in the accent at its start. In a narrow box it is a finger's
23
+ // target.
24
+ const GROUP = cn('flex items-center rounded-md px-2.5 py-1.75 type-body text-foreground outline-none', 'focus-visible:ring-3 focus-visible:ring-ring/50', '@max-[40rem]/settings:min-h-10');
25
+ const CURRENT_GROUP = 'bg-primary/15 shadow-[inset_3px_0_0_0_var(--primary)]';
26
+ /**
27
+ * The layout of a settings page, inside a router: `title`, the links to
28
+ * `groups` down the side (in a row above, in a box under 40rem), and the
29
+ * current group. Past the first group it puts the page's trail in the
30
+ * shell's bar.
31
+ *
32
+ * <Route path="settings" element={<SettingsPage title="Settings" groups={GROUPS}><Outlet /></SettingsPage>}>
33
+ * <Route index element={<LookSettings />} />
34
+ * <Route path="notifications" element={<NotificationSettings />} />
35
+ * </Route>
36
+ */
37
+ export function SettingsPage({ title, groups, children, className }) {
38
+ const id = useId();
39
+ const { pathname } = useLocation();
40
+ const current = mostSpecificTo(groups, pathname);
41
+ const currentId = current && `${id}-${groups.indexOf(current)}`;
42
+ // On a group's own page only: a page below one puts up its own trail,
43
+ // which a parent's would win over.
44
+ const trimmed = pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname;
45
+ const onGroup = current && current !== groups[0] && navPathname(current.to) === trimmed;
46
+ usePageTrail(onGroup ? [{ label: title, href: groups[0].to }, { label: current.label }] : null);
47
+ return (_jsxs("div", { "data-slot": "settings-page", className: cn('@container/settings w-full min-w-0', className), children: [_jsx("h1", { className: "mb-4 type-page-title text-foreground", children: title }), _jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)] gap-4 @min-[40rem]/settings:grid-cols-[--spacing(45)_minmax(0,1fr)] @min-[40rem]/settings:gap-7", children: [_jsx("nav", { "data-slot": "settings-groups", "aria-label": title, children: _jsx("ul", { className: "flex flex-wrap gap-1 @min-[40rem]/settings:flex-col @min-[40rem]/settings:gap-0.5", children: groups.map((group, index) => {
48
+ const isCurrent = group === current;
49
+ return (_jsx("li", { children: _jsx(Link, { to: group.to, id: `${id}-${index}`, "data-slot": "settings-group", "aria-current": isCurrent ? 'page' : undefined, className: cn(GROUP, isCurrent ? CURRENT_GROUP : 'hover:bg-muted'), children: group.label }) }, group.to));
50
+ }) }) }), _jsx("section", { "data-slot": "settings-content", "aria-labelledby": currentId, className: "flex min-w-0 flex-col gap-4", children: children })] })] }));
51
+ }
52
+ /**
53
+ * A group's rows, in a bordered card that stops growing at 832px (a step
54
+ * of the spacing scale, so it grows with the density). It has no heading:
55
+ * the group's name is the link beside it. A table the group holds goes
56
+ * after it.
57
+ */
58
+ export function SettingsCard({ children, className }) {
59
+ return (_jsx(Card, { "data-slot": "settings-card", className: cn('max-w-208 gap-0 divide-y divide-border py-0', className), children: children }));
60
+ }
61
+ /** One setting in a `SettingsCard`: what it is, and its control. */
62
+ export function SettingsRow({ label, help, control, layout = 'beside', htmlFor, className }) {
63
+ const id = useId();
64
+ const labelId = `${id}-label`;
65
+ const helpId = `${id}-help`;
66
+ const aria = { 'aria-labelledby': labelId, ...(help ? { 'aria-describedby': helpId } : {}) };
67
+ const below = layout === 'below';
68
+ return (_jsxs("div", { "data-slot": "settings-row", "data-layout": layout, className: cn('flex px-4 py-3', below ? 'flex-col gap-2.5' : 'flex-wrap items-center justify-between gap-x-5 gap-y-2', className), children: [_jsxs("div", { className: cn('flex min-w-0 flex-col items-start gap-0.5', !below && 'flex-[1_1_--spacing(60)]'), children: [htmlFor ? (_jsx("label", { id: labelId, htmlFor: htmlFor, className: "type-body font-medium", children: label })) : (_jsx("span", { id: labelId, className: "type-body font-medium", children: label })), help && (_jsx("div", { id: helpId, className: "type-caption text-muted-foreground", children: help }))] }), _jsx("div", { "data-slot": "settings-row-control", className: below ? 'w-full min-w-0' : 'max-w-full', children: typeof control === 'function' ? control(aria) : control })] }));
69
+ }
package/dist/index.d.ts CHANGED
@@ -84,6 +84,8 @@ export { StageCircle, type StageCircleProps, type StageCircleStage, type StageCi
84
84
  export { Notice, type NoticeProps, type NoticeTone } from './components/app/notice.js';
85
85
  export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
86
86
  export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, type ListHeaderSecondaryAction, type ListHeaderSibling, } from './components/app/list-header.js';
87
+ export { SettingsCard, SettingsPage, SettingsRow, type SettingsCardProps, type SettingsGroup, type SettingsPageProps, type SettingsRowAria, type SettingsRowProps, } from './components/app/settings-page.js';
88
+ export { PaletteSetting, RowsSetting, type PaletteSettingProps, type RowsSettingProps } from './components/app/look-settings.js';
87
89
  export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
88
90
  export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemStep, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
89
91
  export { StepTrack, type StepTrackProps, type StepTrackState, type StepTrackStep, } from './components/app/step-track.js';
package/dist/index.js CHANGED
@@ -95,6 +95,8 @@ export { StageCircle, } from './components/app/stage-circle.js';
95
95
  export { Notice } from './components/app/notice.js';
96
96
  export { ValueList } from './components/app/value-list.js';
97
97
  export { ListHeader, } from './components/app/list-header.js';
98
+ export { SettingsCard, SettingsPage, SettingsRow, } from './components/app/settings-page.js';
99
+ export { PaletteSetting, RowsSetting } from './components/app/look-settings.js';
98
100
  export { Timeline } from './components/app/timeline.js';
99
101
  export { EqualItems, } from './components/app/equal-items.js';
100
102
  export { StepTrack, } from './components/app/step-track.js';
@@ -1,8 +1,8 @@
1
1
  // The four palettes (design-language.md "Palettes"): an app's own dark
2
2
  // look, one of those the shared style guide chose. FoundationProviders'
3
- // `palette` names the app's default; with `palettePicker` the app shell
4
- // offers all four and the choice is remembered on this device
5
- // (localStorage, this store). A new device starts on the default. The
3
+ // `palette` names the app's default; with `palettePicker` the app shell's
4
+ // look menu or a settings page (PaletteSetting) offers all four and the
5
+ // choice is remembered on this device (localStorage, this store). A new device starts on the default. The
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).
package/dist/lib/rows.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // How tall a table's rows are on this device (design-language.md
2
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
3
+ // FoundationProviders' `rowsPicker` the app shell's look menu or a settings
4
+ // page (RowsSetting) offers Regular too, remembered on this device
5
+ // (localStorage, this store). The choice rides on <html> as data-rows, and styles/theme.css's
6
6
  // [data-rows="regular"] retunes every table's cells under it: DataTable,
7
7
  // the Table primitive and tables in notes. A data-density on a nearer
8
8
  // ancestor (a hub's compact wrapper) still wins there.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.141.0",
3
+ "version": "4.142.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": {