@tristan2828/ui-foundation 4.79.0 → 4.80.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.
@@ -3,34 +3,35 @@
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 43–110
7
- - [Glow](#glow) · lines 112–130
8
- - [Semantic tones](#semantic-tones) · lines 132–160
9
- - [The three badge styles](#the-three-badge-styles) · lines 162–179
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 181–210
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 212–225
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 227–271
13
- - [Categorical colour](#categorical-colour) · lines 273–343
14
- - [Heat scale](#heat-scale) · lines 345–406
15
- - [Depth ramps](#depth-ramps) · lines 408–486
16
- - [A stored colour](#a-stored-colour) · lines 488–536
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 538–559
18
- - [Typography](#typography) · lines 561–681
19
- - [Written text (notes)](#written-text-notes) · lines 595–681
20
- - [Density](#density) · lines 683–769
21
- - [Rows on this device](#rows-on-this-device) · lines 742–769
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 771–885
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 887–964
24
- - [Notices](#notices) · lines 966–994
25
- - [A value over time](#a-value-over-time) · lines 996–1082
26
- - [Several values over time](#several-values-over-time) · lines 1045–1082
27
- - [A list as a board](#a-list-as-a-board) · lines 1084–1135
28
- - [A list as cards](#a-list-as-cards) · lines 1137–1183
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1185–1207
30
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1209–1253
31
- - [Picking at random](#picking-at-random) · lines 1255–1286
32
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1288–1355
33
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1357–1382
6
+ - [Palettes](#palettes) · lines 44–111
7
+ - [Glow](#glow) · lines 113–131
8
+ - [Semantic tones](#semantic-tones) · lines 133–161
9
+ - [The three badge styles](#the-three-badge-styles) · lines 163–180
10
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 182–211
11
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 213–226
12
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 228–272
13
+ - [Categorical colour](#categorical-colour) · lines 274–344
14
+ - [Heat scale](#heat-scale) · lines 346–407
15
+ - [Depth ramps](#depth-ramps) · lines 409–487
16
+ - [A stored colour](#a-stored-colour) · lines 489–537
17
+ - [Shapes and sizes](#shapes-and-sizes) · lines 539–560
18
+ - [Typography](#typography) · lines 562–682
19
+ - [Written text (notes)](#written-text-notes) · lines 596–682
20
+ - [Density](#density) · lines 684–770
21
+ - [Rows on this device](#rows-on-this-device) · lines 743–770
22
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 772–886
23
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 888–965
24
+ - [Notices](#notices) · lines 967–995
25
+ - [A value over time](#a-value-over-time) · lines 997–1083
26
+ - [Several values over time](#several-values-over-time) · lines 1046–1083
27
+ - [A list as a board](#a-list-as-a-board) · lines 1085–1136
28
+ - [A list as cards](#a-list-as-cards) · lines 1138–1184
29
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1186–1208
30
+ - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1210–1254
31
+ - [Picking at random](#picking-at-random) · lines 1256–1287
32
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1289–1356
33
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1358–1383
34
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1385–1431
34
35
 
35
36
  <!-- /index -->
36
37
 
@@ -1380,3 +1381,51 @@ both themes and every palette.
1380
1381
  - **A list in place under group headings** heads each group in
1381
1382
  `type-label text-muted-foreground` (an `<h3>` under the section's
1382
1383
  title), with `gap-4` between groups and the list's own `gap-2` inside.
1384
+
1385
+ ## The sidebar and the phone's bar
1386
+
1387
+ `AppShell`'s navigation (4.80), all set in the app's `nav` and
1388
+ `bottomBar`; an app that sets none of it looks as it did, except the
1389
+ current entry's bar and the phone's back arrow, which every app gets.
1390
+
1391
+ ```tsx
1392
+ const nav: NavEntry[] = [
1393
+ { to: '/', label: 'Home', icon: HomeIcon, end: true },
1394
+ { label: 'Every day', items: [{ to: '/news', label: 'News', icon: NewspaperIcon, count: unread, countLabel: 'unread' }] },
1395
+ { label: 'Home and money', items: [{ to: '/finance', label: 'Finance', icon: WalletIcon, children: [
1396
+ { label: 'Money', items: [accounts, savings] },
1397
+ { label: 'Spending', items: [budget] },
1398
+ ] }] },
1399
+ { label: 'Tools', placement: 'bottom', items: [fillIn, roadmap] },
1400
+ ]
1401
+ const bottomBar: BottomBarItem[] = [
1402
+ { to: '/', label: 'Home', icon: HouseIcon },
1403
+ { group: 'Every day', icon: SunIcon, sheet: 'tiles' },
1404
+ ]
1405
+ ```
1406
+
1407
+ - **The current entry:** the sidebar's tint and a 3px `--primary` bar
1408
+ at its start, the same mark as a selected or hovered table row, in the
1409
+ sidebar and on the icon rail.
1410
+ - **Headings among a module's pages** (a group `{ label, items }` in an
1411
+ entry's `children`): small caption headings in the sidebar's muted
1412
+ text, each heading's pages a list named by it. Use them for a module
1413
+ with more than about six pages, a few words each; the rail's tooltip
1414
+ names the headings ("Finance: Money, Spending").
1415
+ - **Counts** (`count`, `countLabel`): a plain number at the entry's end
1416
+ in the muted text tone, never a coloured badge; on the icon rail a dot
1417
+ in `--primary` on the icon. Only on entries that ask you to act
1418
+ (unread, to fill in, new); 0 shows nothing. `countLabel` is what the
1419
+ number counts, read after the entry's name ("News 24 unread").
1420
+ - **A section at the foot** (`placement: 'bottom'`): under every other
1421
+ section and `sidebarExtra`, pushed to the sidebar's foot when there's
1422
+ room; for tools rather than modules.
1423
+ - **A phone's back arrow:** below 48rem, a page below a nav entry (a
1424
+ record under Accounts) shows "‹ Accounts" in `--link` at the header's
1425
+ start, linking to the entry. With a `bottomBar` it takes the menu
1426
+ button's place; without one the menu button stays beside it. An
1427
+ entry's own page keeps the menu button.
1428
+ - **An area's sheet as tiles** (`sheet: 'tiles'`): a three-column grid,
1429
+ one tile per entry, the icon in `--link` over the label, bordered,
1430
+ 44px tall at least; the tile holding the page has a `--primary`
1431
+ border. The entries' own pages are left to the module.
@@ -3,14 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  // sections in thumb reach, where the sidebar is a sheet behind the
4
4
  // header's menu button. An item is a link, or a nav section by its label,
5
5
  // which opens a sheet from the bottom listing that section's entries (and
6
- // their children, under them). The sheet closes on navigation, as the
6
+ // their children, under them, by heading where they have them), or with
7
+ // `sheet: 'tiles'` a grid of the entries as tiles, icon over label, like
8
+ // a phone's home screen. The sheet closes on navigation, as the
7
9
  // sidebar's does. The item holding the current page is marked
8
10
  // (`aria-current`). Shown below the md breakpoint only (the sidebar's own
9
11
  // mobile breakpoint); the shell pads its content by the bar's height and
10
12
  // the phone's safe area, so a page's last row clears it.
11
- import { useState } from 'react';
13
+ import { useId, useState } from 'react';
12
14
  import { Link, useLocation } from 'react-router';
13
- import { bottomBarCurrent, bottomBarSection } from './app-shell-nav.js';
15
+ import { bottomBarCurrent, bottomBarSection, childItems, isNavItemGroup, } from './app-shell-nav.js';
14
16
  import { Sheet, SheetContent, SheetHeader, SheetTitle } from '../ui/sheet.js';
15
17
  const ITEM_CLASS = 'flex min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-md px-1 type-caption text-muted-foreground ' +
16
18
  'outline-none focus-visible:ring-3 focus-visible:ring-ring/50 aria-[current]:text-foreground aria-[current]:font-medium ' +
@@ -23,8 +25,30 @@ const SHEET_LINK_CLASS = 'flex min-h-11 items-center gap-3 rounded-md px-3 type-
23
25
  * plus the bar (4rem and its 1px border) and the phone's safe area.
24
26
  */
25
27
  export const BOTTOM_BAR_PADDING = 'max-md:pb-[calc(--spacing(22)+1px+env(safe-area-inset-bottom))]';
26
- function SheetLinks({ items, activeTo }) {
27
- return (_jsx("ul", { className: "flex flex-col gap-0.5", children: items.map(({ to, label, icon: Icon, children }) => (_jsxs("li", { children: [_jsxs(Link, { to: to, "aria-current": to === activeTo ? 'page' : undefined, className: SHEET_LINK_CLASS, children: [_jsx(Icon, {}), _jsx("span", { className: "truncate", children: label })] }), children && children.length > 0 && (_jsx("div", { className: "ml-5 border-l border-border pl-2", children: _jsx(SheetLinks, { items: children, activeTo: activeTo }) }))] }, to))) }));
28
+ // A tile: the entry's icon over its label, a finger's target at least.
29
+ const TILE_CLASS = 'flex min-h-11 min-w-0 flex-col items-center justify-center gap-1 rounded-lg border border-border bg-background px-1.5 py-2.5 ' +
30
+ 'text-center type-caption text-foreground outline-none hover:bg-accent focus-visible:ring-3 focus-visible:ring-ring/50 ' +
31
+ 'aria-[current]:border-primary aria-[current]:font-medium [&>svg]:size-5 [&>svg]:shrink-0 [&>svg]:text-link';
32
+ function SheetLink({ item, activeTo }) {
33
+ const { to, label, icon: Icon, children } = item;
34
+ return (_jsxs("li", { children: [_jsxs(Link, { to: to, "aria-current": to === activeTo ? 'page' : undefined, className: SHEET_LINK_CLASS, children: [_jsx(Icon, {}), _jsx("span", { className: "truncate", children: label })] }), children && children.length > 0 && (_jsx("div", { className: "ml-5 border-l border-border pl-2", children: _jsx(SheetChildren, { items: children, activeTo: activeTo }) }))] }));
35
+ }
36
+ function SheetGroup({ label, items, activeTo }) {
37
+ const headingId = useId();
38
+ return (_jsxs("li", { children: [_jsx("span", { id: headingId, className: "block px-3 pt-2 pb-0.5 type-caption text-muted-foreground", children: label }), _jsx("ul", { "aria-labelledby": headingId, className: "flex flex-col gap-0.5", children: items.map((item) => (_jsx(SheetLink, { item: item, activeTo: activeTo }, item.to))) })] }));
39
+ }
40
+ function SheetChildren({ items, activeTo }) {
41
+ return (_jsx("ul", { className: "flex flex-col gap-0.5", children: items.map((child) => isNavItemGroup(child) ? (_jsx(SheetGroup, { label: child.label, items: child.items, activeTo: activeTo }, `group:${child.label}`)) : (_jsx(SheetLink, { item: child, activeTo: activeTo }, child.to))) }));
42
+ }
43
+ // The tiles (#N8): one per entry, its pages left to the module itself. The
44
+ // tile holding the current page, its own or one of its pages, is marked.
45
+ function SheetTiles({ items, activeTo }) {
46
+ return (_jsx("ul", { "data-slot": "app-shell-sheet-tiles", className: "grid grid-cols-3 gap-2", children: items.map((item) => {
47
+ const { to, label, icon: Icon } = item;
48
+ // "page" on the module's own page, "true" on one of its pages.
49
+ const current = to === activeTo ? 'page' : childItems(item).some((child) => child.to === activeTo) ? 'true' : undefined;
50
+ return (_jsx("li", { className: "flex min-w-0", children: _jsxs(Link, { to: to, "aria-current": current, className: `${TILE_CLASS} flex-1`, children: [_jsx(Icon, { "aria-hidden": "true" }), _jsx("span", { className: "max-w-full break-words", children: label })] }) }, to));
51
+ }) }));
28
52
  }
29
53
  export function BottomBar({ items, nav, activeTo, }) {
30
54
  // The section open, and the location it was opened at: following a link
@@ -37,6 +61,7 @@ export function BottomBar({ items, nav, activeTo, }) {
37
61
  const shown = items.slice(0, 5);
38
62
  const current = bottomBarCurrent(shown, nav, activeTo);
39
63
  const section = openGroup === null ? undefined : bottomBarSection(nav, openGroup);
64
+ const tiles = shown.some((item) => 'group' in item && item.group === openGroup && item.sheet === 'tiles');
40
65
  return (_jsxs(_Fragment, { children: [_jsx("nav", { "aria-label": "Bottom bar", "data-slot": "app-shell-bottom-bar", className: "fixed inset-x-0 bottom-0 z-20 border-t border-border bg-background pb-[env(safe-area-inset-bottom)] md:hidden", children: _jsx("ul", { className: "flex h-16 items-stretch gap-1 px-2 py-1.5", children: shown.map((item, index) => {
41
66
  const Icon = item.icon;
42
67
  const isCurrent = index === current;
@@ -45,5 +70,5 @@ export function BottomBar({ items, nav, activeTo, }) {
45
70
  }
46
71
  const label = item.label ?? item.group;
47
72
  return (_jsx("li", { className: "flex min-w-0 flex-1", children: _jsxs("button", { type: "button", "aria-haspopup": "dialog", "aria-expanded": openGroup === item.group, "aria-current": isCurrent ? 'true' : undefined, onClick: () => setOpenGroup(item.group), className: ITEM_CLASS, children: [_jsx(Icon, { "aria-hidden": "true" }), _jsx("span", { className: "max-w-full truncate", children: label })] }) }, `group:${item.group}`));
48
- }) }) }), _jsx(Sheet, { open: section !== undefined, onOpenChange: (open) => !open && setOpenGroup(null), children: _jsx(SheetContent, { side: "bottom", className: "max-h-[80dvh] gap-2 pb-[calc(--spacing(4)+env(safe-area-inset-bottom))] md:hidden", children: section && (_jsxs(_Fragment, { children: [_jsx(SheetHeader, { className: "pb-0", children: _jsx(SheetTitle, { children: section.label }) }), _jsx("nav", { "aria-label": section.label, className: "overflow-y-auto px-2", children: _jsx(SheetLinks, { items: section.items, activeTo: activeTo }) })] })) }) })] }));
73
+ }) }) }), _jsx(Sheet, { open: section !== undefined, onOpenChange: (open) => !open && setOpenGroup(null), children: _jsx(SheetContent, { side: "bottom", className: "max-h-[80dvh] gap-2 pb-[calc(--spacing(4)+env(safe-area-inset-bottom))] md:hidden", children: section && (_jsxs(_Fragment, { children: [_jsx(SheetHeader, { className: "pb-0", children: _jsx(SheetTitle, { children: section.label }) }), _jsx("nav", { "aria-label": section.label, className: "overflow-y-auto px-2", children: tiles ? (_jsx(SheetTiles, { items: section.items, activeTo: activeTo })) : (_jsx(SheetChildren, { items: section.items, activeTo: activeTo })) })] })) }) })] }));
49
74
  }
@@ -16,11 +16,43 @@ export type NavItem = {
16
16
  * channels under YouTube, its series under Comics. They show while the
17
17
  * page is this entry or one of them (`open: 'current'`), or always
18
18
  * (`'always'`). On the icon rail they're named in this entry's tooltip.
19
+ * A long module's pages can sit under small headings: a child can be a
20
+ * group (`{ label: 'Money', items }`), and the tooltip then names the
21
+ * headings.
19
22
  */
20
- children?: readonly NavItem[];
23
+ children?: readonly NavChild[];
21
24
  /** When `children` show: while you're in them (`'current'`, the default) or `'always'`. */
22
25
  open?: 'current' | 'always';
26
+ /**
27
+ * A number on the entry that asks you to act (unread articles, records
28
+ * to fill in), drawn at its end in the muted tone; a dot on the icon
29
+ * rail. None, or 0, shows nothing. The app passes it from a query.
30
+ */
31
+ count?: number;
32
+ /**
33
+ * What the count counts, for screen readers: 'unread' reads "24
34
+ * unread". Without it the number is read alone.
35
+ */
36
+ countLabel?: string;
37
+ };
38
+ /**
39
+ * A small heading over some of a module's pages, in its entry's
40
+ * `children`: Finance's Money, Spending and Taxes.
41
+ */
42
+ export type NavItemGroup = {
43
+ label: string;
44
+ items: readonly NavItem[];
23
45
  };
46
+ /** One of an entry's `children`: a page, or a heading over pages. */
47
+ export type NavChild = NavItem | NavItemGroup;
48
+ export declare function isNavItemGroup(child: NavChild): child is NavItemGroup;
49
+ /** An entry's pages, its groups' included, in order. */
50
+ export declare function childItems(item: NavItem): NavItem[];
51
+ /**
52
+ * The rail's tooltip for an entry: its label, then what's under it, by
53
+ * heading where it has them ("Finance: Money, Spending, Taxes").
54
+ */
55
+ export declare function navTooltip(item: NavItem): string;
24
56
  /** A labelled group of sidebar entries: one module's pages, say. */
25
57
  export type NavSection = {
26
58
  label: string;
@@ -34,6 +66,12 @@ export type NavSection = {
34
66
  collapsible?: boolean;
35
67
  /** Whether a collapsible section starts open for someone who has never folded it. Defaults to true. */
36
68
  defaultOpen?: boolean;
69
+ /**
70
+ * Where the section sits: in order with the rest (`'top'`, the
71
+ * default), or at the sidebar's foot, under every other section
72
+ * (`'bottom'`: a Tools group, say).
73
+ */
74
+ placement?: 'top' | 'bottom';
37
75
  };
38
76
  /** One entry of `AppShell`'s `nav`: a page, or a labelled section of pages. */
39
77
  export type NavEntry = NavItem | NavSection;
@@ -45,11 +83,14 @@ export type NavGroup = {
45
83
  /** From its section: the label folds it (NavSection's `collapsible`). */
46
84
  collapsible?: boolean;
47
85
  defaultOpen?: boolean;
86
+ /** From its section: at the sidebar's foot (NavSection's `placement`). */
87
+ placement?: 'bottom';
48
88
  };
49
89
  /**
50
90
  * The sidebar groups for a nav, in order. A flat nav (no sections) is the
51
91
  * one "Navigation" group it always was. Otherwise each section is its own
52
92
  * labelled group, and each run of plain items between them an unlabelled one.
93
+ * Sections placed at the bottom come last, in their own order.
53
94
  */
54
95
  export declare function navGroups(nav: readonly NavEntry[]): NavGroup[];
55
96
  /** Each item and, after it, its children: every page a list of items links. */
@@ -84,6 +125,16 @@ export declare function activeNavTo(nav: readonly NavEntry[], pathname: string):
84
125
  * itself, or on a page no entry covers.
85
126
  */
86
127
  export declare function navPageLabel(nav: readonly NavEntry[], pathname: string): string | undefined;
128
+ /**
129
+ * Where a phone's back arrow goes: the current entry, when the page is
130
+ * below it (a record under Accounts reads "‹ Accounts"). None on an
131
+ * entry's own page, or a page no entry covers: the header keeps its menu
132
+ * button there.
133
+ */
134
+ export declare function navBackTarget(nav: readonly NavEntry[], pathname: string): {
135
+ label: string;
136
+ to: string;
137
+ } | undefined;
87
138
  /**
88
139
  * One item of `AppShell`'s `bottomBar`, the phone's bar of shortcuts: a
89
140
  * page, or one of the nav's sections by its label, which opens a sheet of
@@ -98,6 +149,12 @@ export type BottomBarItem = {
98
149
  group: string;
99
150
  label?: string;
100
151
  icon: IconComponent;
152
+ /**
153
+ * How its sheet shows the section: a list of its entries with their
154
+ * pages (`'list'`, the default), or a grid of tiles, one per entry,
155
+ * icon over label, like a phone's home screen (`'tiles'`).
156
+ */
157
+ sheet?: 'list' | 'tiles';
101
158
  };
102
159
  /** The nav's section with this label, if there is one. */
103
160
  export declare function bottomBarSection(nav: readonly NavEntry[], label: string): NavSection | undefined;
@@ -1,3 +1,20 @@
1
+ export function isNavItemGroup(child) {
2
+ return 'items' in child;
3
+ }
4
+ /** An entry's pages, its groups' included, in order. */
5
+ export function childItems(item) {
6
+ return (item.children ?? []).flatMap((child) => (isNavItemGroup(child) ? child.items : [child]));
7
+ }
8
+ /**
9
+ * The rail's tooltip for an entry: its label, then what's under it, by
10
+ * heading where it has them ("Finance: Money, Spending, Taxes").
11
+ */
12
+ export function navTooltip(item) {
13
+ const children = item.children ?? [];
14
+ if (!children.length)
15
+ return item.label;
16
+ return `${item.label}: ${children.map((child) => child.label).join(', ')}`;
17
+ }
1
18
  export function isNavSection(entry) {
2
19
  return 'items' in entry;
3
20
  }
@@ -5,6 +22,7 @@ export function isNavSection(entry) {
5
22
  * The sidebar groups for a nav, in order. A flat nav (no sections) is the
6
23
  * one "Navigation" group it always was. Otherwise each section is its own
7
24
  * labelled group, and each run of plain items between them an unlabelled one.
25
+ * Sections placed at the bottom come last, in their own order.
8
26
  */
9
27
  export function navGroups(nav) {
10
28
  if (!nav.some(isNavSection))
@@ -20,6 +38,7 @@ export function navGroups(nav) {
20
38
  label: entry.label,
21
39
  items: entry.items,
22
40
  ...(entry.collapsible && { collapsible: true, defaultOpen: entry.defaultOpen ?? true }),
41
+ ...(entry.placement === 'bottom' && { placement: 'bottom' }),
23
42
  });
24
43
  }
25
44
  else {
@@ -28,11 +47,11 @@ export function navGroups(nav) {
28
47
  }
29
48
  if (run.length)
30
49
  groups.push({ items: run });
31
- return groups;
50
+ return [...groups.filter((group) => !group.placement), ...groups.filter((group) => group.placement)];
32
51
  }
33
52
  /** Each item and, after it, its children: every page a list of items links. */
34
53
  export function withChildren(items) {
35
- return items.flatMap((item) => [item, ...(item.children ?? [])]);
54
+ return items.flatMap((item) => [item, ...childItems(item)]);
36
55
  }
37
56
  /** Every page in a nav, sections' items and children included, in order. */
38
57
  export function navItems(nav) {
@@ -45,7 +64,7 @@ export function navItems(nav) {
45
64
  export function childrenOpen(item, activeTo) {
46
65
  if (!item.children?.length)
47
66
  return false;
48
- return item.open === 'always' || item.to === activeTo || item.children.some((child) => child.to === activeTo);
67
+ return item.open === 'always' || item.to === activeTo || childItems(item).some((child) => child.to === activeTo);
49
68
  }
50
69
  /**
51
70
  * The path a `to` names, without its query string or hash: what an entry is
@@ -100,6 +119,20 @@ export function navPageLabel(nav, pathname) {
100
119
  const item = activeNavItem(nav, pathname);
101
120
  return item && navPathname(item.to) !== '/' ? item.label : undefined;
102
121
  }
122
+ /**
123
+ * Where a phone's back arrow goes: the current entry, when the page is
124
+ * below it (a record under Accounts reads "‹ Accounts"). None on an
125
+ * entry's own page, or a page no entry covers: the header keeps its menu
126
+ * button there.
127
+ */
128
+ export function navBackTarget(nav, pathname) {
129
+ const item = activeNavItem(nav, pathname);
130
+ if (!item)
131
+ return undefined;
132
+ const path = navPathname(item.to);
133
+ const trimmed = pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname;
134
+ return trimmed === path ? undefined : { label: item.label, to: item.to };
135
+ }
103
136
  /** The nav's section with this label, if there is one. */
104
137
  export function bottomBarSection(nav, label) {
105
138
  return nav.find((entry) => isNavSection(entry) && entry.label === label);
@@ -2,7 +2,7 @@ import { type ReactNode } from 'react';
2
2
  import { type BottomBarItem, type NavEntry } from './app-shell-nav.js';
3
3
  import { type AppShellVersion } from './app-shell-version.js';
4
4
  import type { IconComponent } from './icon-component.js';
5
- export type { BottomBarItem, NavEntry, NavItem, NavSection } from './app-shell-nav.js';
5
+ export type { BottomBarItem, NavChild, NavEntry, NavItem, NavItemGroup, NavSection } from './app-shell-nav.js';
6
6
  export type { AppShellVersion } from './app-shell-version.js';
7
7
  export type AppShellProps = {
8
8
  /**
@@ -31,7 +31,12 @@ export type AppShellProps = {
31
31
  * remembered per browser (`defaultOpen` for the first visit); the one
32
32
  * holding the current page stays open, and the icon rail shows every
33
33
  * section's items. An entry's `children` (a module's own pages) show
34
- * under it while you're on one of them.
34
+ * under it while you're on one of them, under small headings where they
35
+ * are groups (`{ label, items }`). The current entry has the tint and a
36
+ * bar at its start; an entry's `count` shows at its end (a dot on the
37
+ * rail); a section with `placement: 'bottom'` sits at the sidebar's foot.
38
+ * On a phone, a page below an entry shows a back arrow to it in the
39
+ * header (design-language.md "The sidebar and the phone's bar").
35
40
  */
36
41
  nav: readonly NavEntry[];
37
42
  /**
@@ -58,9 +63,11 @@ export type AppShellProps = {
58
63
  * breakpoint), in thumb reach: at most five, each a page
59
64
  * (`{ to, label, icon }`) or a nav section by its label
60
65
  * (`{ group: 'Every day', icon }`, with an optional shorter `label`),
61
- * which opens a sheet of that section's entries. The item holding the
66
+ * which opens a sheet of that section's entries (as tiles with
67
+ * `sheet: 'tiles'`). The item holding the
62
68
  * current page is marked. The header's menu button stays, for
63
- * everything. The shell pads its content so nothing sits under the bar.
69
+ * everything, except on a page below a nav entry, where the back arrow
70
+ * takes its place. The shell pads its content so nothing sits under the bar.
64
71
  */
65
72
  bottomBar?: readonly BottomBarItem[];
66
73
  };
@@ -1,11 +1,11 @@
1
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';
2
+ import { ChevronLeftIcon, 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';
6
6
  import { useAuth } from '../../auth/use-auth.js';
7
7
  import { BottomBar, BOTTOM_BAR_PADDING } from './app-shell-bottom-bar.js';
8
- import { activeNavTo, childrenOpen, navGroups, navPageLabel, withChildren, } from './app-shell-nav.js';
8
+ import { activeNavTo, childItems, childrenOpen, isNavItemGroup, navBackTarget, navGroups, navPageLabel, navTooltip, withChildren, } from './app-shell-nav.js';
9
9
  import { versionHref, versionLabel } from './app-shell-version.js';
10
10
  import { ErrorState } from './error-state.js';
11
11
  import { useErrorReporter } from '../../error-reporting/error-reporting-context.js';
@@ -16,7 +16,7 @@ import { useRows } from '../../hooks/use-rows.js';
16
16
  import { isPaletteName, PALETTE_LABELS, PALETTES } from '../../lib/palettes.js';
17
17
  import { isRowsName, ROWS, ROWS_LABELS } from '../../lib/rows.js';
18
18
  import { cn } from 'cn';
19
- import { Button } from '../ui/button.js';
19
+ import { Button, buttonVariants } from '../ui/button.js';
20
20
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
21
21
  import { Skeleton } from '../ui/skeleton.js';
22
22
  import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarTrigger, useSidebar, } from '../ui/sidebar.js';
@@ -86,6 +86,28 @@ function VersionEntry({ version }) {
86
86
  const className = 'block truncate px-2 type-caption text-sidebar-foreground/70 group-data-[collapsible=icon]:hidden';
87
87
  return href ? (_jsx("a", { href: href, target: "_blank", rel: "noreferrer", className: `${className} hover:underline`, children: label })) : (_jsx("span", { className: className, children: label }));
88
88
  }
89
+ // The current entry's mark (#N2): the sidebar's tint and a 3px bar in
90
+ // the accent at its start, the same mark as a selected or hovered table
91
+ // row, in the sidebar and on the rail.
92
+ const ACTIVE_MARK = 'data-active:shadow-[inset_3px_0_0_0_var(--primary)]';
93
+ // An entry's count (#N3): a plain number at its end in the muted tone,
94
+ // read with what it counts; on the icon rail, a dot on the icon.
95
+ function NavCount({ count, countLabel }) {
96
+ if (!count)
97
+ return null;
98
+ return (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", "data-slot": "nav-count", className: "ml-auto shrink-0 type-caption text-muted-foreground tabular-nums group-data-[collapsible=icon]:hidden", children: count }), _jsx("span", { className: "sr-only", children: countLabel ? `${count} ${countLabel}` : count }), _jsx("span", { "aria-hidden": "true", "data-slot": "nav-count-dot", className: "pointer-events-none absolute top-1 right-1 hidden size-1.5 rounded-full bg-primary group-data-[collapsible=icon]:block" })] }));
99
+ }
100
+ function NavSubLink({ item, activeTo }) {
101
+ const { to, label, icon: Icon, count, countLabel } = item;
102
+ const isActive = to === activeTo;
103
+ return (_jsx(SidebarMenuSubItem, { children: _jsxs(SidebarMenuSubButton, { isActive: isActive, className: ACTIVE_MARK, render: _jsx(Link, { to: to, "aria-current": isActive ? 'page' : undefined }), children: [_jsx(Icon, {}), _jsx("span", { className: "min-w-0 flex-1 truncate", children: label }), _jsx(NavCount, { count: count, countLabel: countLabel })] }) }));
104
+ }
105
+ // A heading among a module's pages (#N1): a small label over its pages,
106
+ // a list named by it, so a screen reader hears "Money, list".
107
+ function NavSubGroup({ group, activeTo }) {
108
+ const headingId = useId();
109
+ return (_jsxs("li", { "data-slot": "nav-sub-group", className: "flex flex-col gap-1", children: [_jsx("span", { id: headingId, className: "px-2 pt-1.5 type-caption text-sidebar-foreground/70", children: group.label }), _jsx("ul", { "aria-labelledby": headingId, className: "flex flex-col gap-1", children: group.items.map((item) => (_jsx(NavSubLink, { item: item, activeTo: activeTo }, item.to))) })] }));
110
+ }
89
111
  // One group's entries. A plain Link, not NavLink: NavLink marks every
90
112
  // matching entry current, and only the most specific one should be
91
113
  // (activeNavTo).
@@ -94,18 +116,15 @@ function VersionEntry({ version }) {
94
116
  // as its pages, shown while you're in them (childrenOpen) and otherwise
95
117
  // in the page but hidden, as a folded section's are. The icon rail has no
96
118
  // room for them: there the entry looks current while one of them is, and
97
- // its tooltip names them.
119
+ // its tooltip names them (or their headings).
98
120
  function NavMenu({ items, activeTo }) {
99
121
  const { state, isMobile } = useSidebar();
100
122
  const rail = state === 'collapsed' && !isMobile;
101
123
  return (_jsx(SidebarMenu, { children: items.map((item) => {
102
- const { to, label, icon: Icon, children } = item;
124
+ const { to, label, icon: Icon, children, count, countLabel } = item;
103
125
  const isActive = to === activeTo;
104
- const childActive = children?.some((child) => child.to === activeTo) ?? false;
105
- return (_jsxs(SidebarMenuItem, { children: [_jsxs(SidebarMenuButton, { isActive: isActive || (rail && childActive), tooltip: children?.length ? `${label}: ${children.map((child) => child.label).join(', ')}` : label, render: _jsx(Link, { to: to, "aria-current": isActive ? 'page' : undefined }), children: [_jsx(Icon, {}), _jsx("span", { children: label })] }), children && children.length > 0 && (_jsx(SidebarMenuSub, { hidden: !childrenOpen(item, activeTo), children: children.map(({ to: childTo, label: childLabel, icon: ChildIcon }) => {
106
- const isChildActive = childTo === activeTo;
107
- return (_jsx(SidebarMenuSubItem, { children: _jsxs(SidebarMenuSubButton, { isActive: isChildActive, render: _jsx(Link, { to: childTo, "aria-current": isChildActive ? 'page' : undefined }), children: [_jsx(ChildIcon, {}), _jsx("span", { children: childLabel })] }) }, childTo));
108
- }) }))] }, to));
126
+ const childActive = childItems(item).some((child) => child.to === activeTo);
127
+ return (_jsxs(SidebarMenuItem, { children: [_jsxs(SidebarMenuButton, { isActive: isActive || (rail && childActive), tooltip: navTooltip(item), className: cn('relative', ACTIVE_MARK), render: _jsx(Link, { to: to, "aria-current": isActive ? 'page' : undefined }), children: [_jsx(Icon, {}), _jsx("span", { className: "min-w-0 flex-1 truncate", children: label }), _jsx(NavCount, { count: count, countLabel: countLabel })] }), children && children.length > 0 && (_jsx(SidebarMenuSub, { hidden: !childrenOpen(item, activeTo), children: children.map((child) => isNavItemGroup(child) ? (_jsx(NavSubGroup, { group: child, activeTo: activeTo }, `group:${child.label}`)) : (_jsx(NavSubLink, { item: child, activeTo: activeTo }, child.to))) }))] }, to));
109
128
  }) }));
110
129
  }
111
130
  // Whether a collapsible section is open, remembered per browser by its
@@ -157,6 +176,12 @@ function CollapsibleNavGroup({ group, activeTo }) {
157
176
  storeSectionOpen(group.label, !open);
158
177
  } }), className: "w-full justify-between text-left hover:bg-sidebar-accent hover:text-sidebar-accent-foreground aria-disabled:hover:bg-transparent aria-disabled:hover:text-sidebar-foreground/70", children: [group.label, _jsx(ChevronRightIcon, { "aria-hidden": "true", className: cn('transition-transform', open && 'rotate-90') })] }), _jsx(SidebarGroupContent, { id: contentId, hidden: !open, children: _jsx(NavMenu, { items: group.items, activeTo: activeTo }) })] }));
159
178
  }
179
+ // The phone's back arrow (#N7), below the md breakpoint only: the
180
+ // shell's own way up from a page below a nav entry. Its label is the
181
+ // place it goes, so it reads "Back to Accounts".
182
+ function PhoneBack({ back }) {
183
+ return (_jsxs(Link, { to: back.to, "data-slot": "app-shell-back", "aria-label": `Back to ${back.label}`, className: cn(buttonVariants({ variant: 'ghost', size: 'sm' }), '-ml-2 max-w-[60vw] gap-0.5 px-1.5 text-link hover:text-link md:hidden'), children: [_jsx(ChevronLeftIcon, { "aria-hidden": "true" }), _jsx("span", { className: "truncate", children: back.label })] }));
184
+ }
160
185
  function AppShellSkeleton() {
161
186
  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" })] })] }));
162
187
  }
@@ -190,11 +215,14 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
190
215
  return _jsx(Navigate, { to: "/login", replace: true, state: isLoggingOut ? undefined : { from } });
191
216
  }
192
217
  const activeTo = activeNavTo(nav, location.pathname);
193
- return (_jsxs(TooltipProvider, { children: [reporter && _jsx(ReportRoutePattern, { reporter: reporter }), _jsxs(SidebarProvider, { defaultOpen: storedSidebarOpen(defaultSidebarOpen), children: [_jsx(CloseMobileSidebarOnNavigate, {}), _jsx("nav", { "aria-label": "Primary", children: _jsxs(Sidebar, { collapsible: "icon", children: [_jsx(SidebarHeader, { children: _jsxs("div", { className: "flex items-center gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [Logo && (_jsx(Logo, { "aria-hidden": "true", className: "size-5 shrink-0 text-sidebar-foreground group-data-[collapsible=icon]:size-4" })), _jsx("span", { className: "truncate text-sm font-semibold text-sidebar-foreground group-data-[collapsible=icon]:hidden", children: title })] }) }), _jsxs(SidebarContent, { children: [navGroups(nav).map((group, groupIndex) => group.collapsible && group.label !== undefined ? (_jsx(CollapsibleNavGroup, { group: { ...group, label: group.label }, activeTo: activeTo }, `${groupIndex}:${group.label}`)) : (_jsxs(SidebarGroup, { children: [group.label !== undefined && _jsx(SidebarGroupLabel, { children: group.label }), _jsx(SidebarGroupContent, { children: _jsx(NavMenu, { items: group.items, activeTo: activeTo }) })] }, `${groupIndex}:${group.label ?? ''}`))), sidebarExtra] }), _jsxs(SidebarFooter, { children: [version && _jsx(VersionEntry, { version: version }), _jsxs("div", { className: "flex items-center justify-between gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [_jsx("span", { className: "truncate type-caption text-sidebar-foreground/70 group-data-[collapsible=icon]:hidden", children: user.name }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Log out", onClick: () => {
218
+ const back = navBackTarget(nav, location.pathname);
219
+ const groups = navGroups(nav);
220
+ const renderGroup = (group, groupIndex) => group.collapsible && group.label !== undefined ? (_jsx(CollapsibleNavGroup, { group: { ...group, label: group.label }, activeTo: activeTo }, `${group.placement ?? 'top'}:${groupIndex}:${group.label}`)) : (_jsxs(SidebarGroup, { children: [group.label !== undefined && _jsx(SidebarGroupLabel, { children: group.label }), _jsx(SidebarGroupContent, { children: _jsx(NavMenu, { items: group.items, activeTo: activeTo }) })] }, `${group.placement ?? 'top'}:${groupIndex}:${group.label ?? ''}`));
221
+ return (_jsxs(TooltipProvider, { children: [reporter && _jsx(ReportRoutePattern, { reporter: reporter }), _jsxs(SidebarProvider, { defaultOpen: storedSidebarOpen(defaultSidebarOpen), children: [_jsx(CloseMobileSidebarOnNavigate, {}), _jsx("nav", { "aria-label": "Primary", children: _jsxs(Sidebar, { collapsible: "icon", children: [_jsx(SidebarHeader, { children: _jsxs("div", { className: "flex items-center gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [Logo && (_jsx(Logo, { "aria-hidden": "true", className: "size-5 shrink-0 text-sidebar-foreground group-data-[collapsible=icon]:size-4" })), _jsx("span", { className: "truncate text-sm font-semibold text-sidebar-foreground group-data-[collapsible=icon]:hidden", children: title })] }) }), _jsxs(SidebarContent, { children: [groups.filter((group) => !group.placement).map(renderGroup), sidebarExtra, groups.some((group) => group.placement) && (_jsx("div", { "data-slot": "nav-foot", className: "mt-auto flex flex-col", children: groups.filter((group) => group.placement).map(renderGroup) }))] }), _jsxs(SidebarFooter, { children: [version && _jsx(VersionEntry, { version: version }), _jsxs("div", { className: "flex items-center justify-between gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [_jsx("span", { className: "truncate type-caption text-sidebar-foreground/70 group-data-[collapsible=icon]:hidden", children: user.name }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Log out", onClick: () => {
194
222
  setIsLoggingOut(true);
195
223
  // A failed request still ends the session on screen
196
224
  // (AuthProvider), so this stays a deliberate logout: a
197
225
  // clean /login, never the previous user's page as `from`.
198
226
  logout().catch(() => { });
199
- }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsxs(SidebarInset, { className: "min-w-0", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [_jsx(SidebarTrigger, {}), _jsx("div", { className: "flex-1" }), _jsx(LookControl, {})] }), _jsx("div", { className: cn('flex-1 p-6', bottomBar?.length && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) })] }), bottomBar && bottomBar.length > 0 && _jsx(BottomBar, { items: bottomBar, nav: nav, activeTo: activeTo })] }), _jsx(Toaster, { position: "top-center" })] }));
227
+ }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsxs(SidebarInset, { className: "min-w-0", 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 && bottomBar?.length && 'max-md:hidden') }), _jsx("div", { className: "flex-1" }), _jsx(LookControl, {})] }), _jsx("div", { className: cn('flex-1 p-6', bottomBar?.length && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) })] }), bottomBar && bottomBar.length > 0 && _jsx(BottomBar, { items: bottomBar, nav: nav, activeTo: activeTo })] }), _jsx(Toaster, { position: "top-center" })] }));
200
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.79.0",
3
+ "version": "4.80.0",
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": {