@tristan2828/ui-foundation 4.85.0 → 4.86.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.
package/README.md CHANGED
@@ -18,7 +18,7 @@ than installing this by hand:
18
18
 
19
19
  | Import | What |
20
20
  |---|---|
21
- | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For the page standards (`docs/foundation/design-language.md` "Parts of the page standards"): `ValueList`, `ListHeader`, `Timeline`, `NeedsYou`, `Freshness`, `PartEmpty`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. For the form standard (`docs/foundation/add-an-entity.md` "Forms"): `FormSection`, `OptionSelect`, `countFormErrors`, `fieldRows`; from `/ui/field`, `Field` takes `size`, `solo` and `kind`, and `FieldLabel` takes `required`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
21
+ | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For the page standards (`docs/foundation/design-language.md` "Parts of the page standards"): `ValueList`, `ListHeader`, `Timeline`, `NeedsYou`, `Freshness`, `PartEmpty`. For a list's tools (`docs/foundation/cell-patterns.md` 25 and 26): `FilterBar`, `FilterSelect`, `RelatedTable`, and DataTable's `views`, `columnsMenu`, `rowActions`, `phoneRow`, `limit` and `viewAll`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. For the form standard (`docs/foundation/add-an-entity.md` "Forms"): `FormSection`, `OptionSelect`, `countFormErrors`, `fieldRows`; from `/ui/field`, `Field` takes `size`, `solo` and `kind`, and `FieldLabel` takes `required`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
22
22
  | `@tristan2828/ui-foundation/ui/<name>` | shadcn primitives: badge, button, calendar, card, checkbox, combobox, dialog, empty, field, input, input-group, label, popover, select, separator, sheet, sidebar, skeleton, sonner, spinner, switch, table, textarea, tooltip |
23
23
  | `@tristan2828/ui-foundation/gateway` | `safeFetch`, `toAppError`, `networkError` — for an app's `src/api/gateway/` only |
24
24
  | `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `environmentHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `exposeMswForE2E` |
@@ -4,27 +4,27 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 43–65
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 67–809
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 67–812
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 109–116
9
9
  - Step 2: `npm run gen:api` · lines 117–118
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 119–130
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 131–140
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 141–145
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 146–696
14
- - Step 7: Register routes · lines 697–712
15
- - Step 8: Add Playwright specs for all three screens · lines 713–791
16
- - Step 9: Register the nav entry and route names · lines 792–806
17
- - Step 10: `npm run verify`. · lines 807–809
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 811–1069
19
- - [The record view](#the-record-view) · lines 960–999
20
- - [Forms](#forms) · lines 1001–1042
21
- - [Dialogs](#dialogs) · lines 1044–1069
22
- - [What not to copy](#what-not-to-copy) · lines 1071–1097
23
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1099–1116
24
- - [Deleting](#deleting) · lines 1118–1147
25
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1149–1170
26
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1172–1181
27
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1184–1223
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 146–699
14
+ - Step 7: Register routes · lines 700–715
15
+ - Step 8: Add Playwright specs for all three screens · lines 716–794
16
+ - Step 9: Register the nav entry and route names · lines 795–809
17
+ - Step 10: `npm run verify`. · lines 810–812
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 814–1072
19
+ - [The record view](#the-record-view) · lines 963–1002
20
+ - [Forms](#forms) · lines 1004–1045
21
+ - [Dialogs](#dialogs) · lines 1047–1072
22
+ - [What not to copy](#what-not-to-copy) · lines 1074–1100
23
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1102–1119
24
+ - [Deleting](#deleting) · lines 1121–1150
25
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1152–1173
26
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1175–1184
27
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1187–1226
28
28
 
29
29
  <!-- /index -->
30
30
 
@@ -377,7 +377,10 @@ is a filled-in example while the Widgets demo is still here).
377
377
  `<SecondaryFilters>`, as the template does with Extra Categories,
378
378
  Progress and In Stock. Pass it each filter that's on as an
379
379
  `ActiveFilter` (its chip text and how to take it off) and an
380
- `onClear` that clears them all in one `setFilters` call.
380
+ `onClear` that clears them all in one `setFilters` call. A list on
381
+ the list page standard uses `FilterBar` for all of it, with
382
+ `views`, `columnsMenu`, `rowActions` and `phoneRow` on the
383
+ DataTable (cell-patterns.md 25).
381
384
  - `src/routes/widgets/widget-view.tsx` →
382
385
  `src/routes/<entity>/<entity>-view.tsx` — thin consumer of the
383
386
  foundation's `<EntityView>`. Swap the title, badges and sections for
@@ -3,43 +3,45 @@
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
- - [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 71–90
7
- - [1. Plain text](#1-plain-text) · lines 92–145
8
- - [2. Icon + label](#2-icon--label) · lines 147–170
9
- - [3. Icon in a badge](#3-icon-in-a-badge) · lines 172–185
10
- - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 187–264
11
- - [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines 212–264
12
- - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 266–279
13
- - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 281–293
14
- - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 295–316
15
- - [8. Date, relative](#8-date-relative) · lines 318–355
16
- - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 357–405
17
- - [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 375–405
18
- - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 407–457
19
- - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 425–457
20
- - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 459–499
21
- - [12. Boolean](#12-boolean) · lines 501–531
22
- - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 533–569
23
- - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 553–569
24
- - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 571–588
25
- - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 590–699
26
- - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 616–699
27
- - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 701–736
28
- - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 738–811
29
- - [18. Editable value](#18-editable-value) · lines 813–1456
30
- - [Presets: one line per field](#presets-one-line-per-field) · lines 1098–1156
31
- - [Several fields edited as one](#several-fields-edited-as-one) · lines 1158–1194
32
- - [A link and its label](#a-link-and-its-label) · lines 1196–1220
33
- - [A list of sub-items](#a-list-of-sub-items) · lines 1222–1355
34
- - [In a table's rows](#in-a-tables-rows) · lines 1357–1442
35
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1444–1456
36
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1458–1524
37
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1526–1590
38
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1592–1690
39
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1692–1721
40
- - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1723–1761
41
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1763–1839
42
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1841–1864
6
+ - [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 73–92
7
+ - [1. Plain text](#1-plain-text) · lines 94–147
8
+ - [2. Icon + label](#2-icon--label) · lines 149–172
9
+ - [3. Icon in a badge](#3-icon-in-a-badge) · lines 174–187
10
+ - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 189–266
11
+ - [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines 214–266
12
+ - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 268–281
13
+ - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 283–295
14
+ - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 297–318
15
+ - [8. Date, relative](#8-date-relative) · lines 320–357
16
+ - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 359–407
17
+ - [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 377–407
18
+ - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 409–459
19
+ - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 427–459
20
+ - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 461–501
21
+ - [12. Boolean](#12-boolean) · lines 503–533
22
+ - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 535–571
23
+ - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 555–571
24
+ - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 573–590
25
+ - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 592–701
26
+ - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 618–701
27
+ - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 703–738
28
+ - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 740–813
29
+ - [18. Editable value](#18-editable-value) · lines 815–1458
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1100–1158
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1160–1196
32
+ - [A link and its label](#a-link-and-its-label) · lines 1198–1222
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1224–1357
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1359–1444
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1446–1458
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1460–1526
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1528–1592
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1594–1692
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1694–1723
40
+ - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1725–1763
41
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1765–1841
42
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1843–1866
43
+ - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1868–1954
44
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 1956–1992
43
45
 
44
46
  <!-- /index -->
45
47
 
@@ -1862,3 +1864,129 @@ import { ColorSwatch } from '@tristan2828/ui-foundation'
1862
1864
 
1863
1865
  The package's fixture `app/ColorSwatch` "In a table" renders it; its
1864
1866
  checks measure the ring at 3:1 in both themes and every palette.
1867
+
1868
+ ## 25. A list's tools: views, filters, columns, row actions, a phone's rows
1869
+
1870
+ The rest of the list page standard (4.86): what sits above a list's rows,
1871
+ at the end of each row, and what a phone gets instead of the table. Each
1872
+ is a prop or a part; leave it out and the list is as before.
1873
+
1874
+ ```tsx
1875
+ import { DataTable, FilterBar, FilterSelect, MultiChoice } from '@tristan2828/ui-foundation'
1876
+
1877
+ const VIEWS = {
1878
+ current: { label: 'Current', filters: { status: 'active' } },
1879
+ review: { label: 'To review', filters: { status: 'watch' }, columns: ['name', 'status', 'notes'] },
1880
+ all: { label: 'All' },
1881
+ }
1882
+ const { filters, multiFilters, setFilter, setFilters, setMultiFilter, activeView, applyView, ... } =
1883
+ useTableUrlState(FILTERS, MULTI, VIEWS)
1884
+
1885
+ <DataTable
1886
+ views={VIEWS} activeView={activeView} onViewChange={applyView}
1887
+ columnsMenu={{ storageKey: 'my-app:plants:columns' }}
1888
+ rowActions={(plant) => [
1889
+ { label: 'Water', icon: DropletIcon, onSelect: () => water(plant) },
1890
+ { label: 'Delete', icon: Trash2Icon, tone: 'destructive', onSelect: () => remove(plant) },
1891
+ ]}
1892
+ phoneRow={{
1893
+ title: (plant) => plant.name,
1894
+ status: (plant) => <StatusBadge status={plant.status} />,
1895
+ facts: (plant) => [plant.light, `Watered ${plant.watered}`],
1896
+ }}
1897
+ toolbar={
1898
+ <FilterBar
1899
+ search={{ value: filters.search, onChange: (value) => setFilter('search', value), placeholder: 'Search by name' }}
1900
+ primary={<>
1901
+ <FilterSelect label="Status" options={STATUS_OPTIONS} value={filters.status}
1902
+ onValueChange={(value) => setFilter('status', value)} />
1903
+ <MultiChoice label="Rooms" placeholder="Any room" aria-label="Filter by rooms" options={ROOMS}
1904
+ value={multiFilters.rooms} onValueChange={(rooms) => setMultiFilter('rooms', rooms)} />
1905
+ </>}
1906
+ primaryActive={/* the chips of the two, for a phone */}
1907
+ secondary={<>{/* the rest, each a FilterSelect */}</>}
1908
+ active={/* the chips of the rest */}
1909
+ onClear={() => setFilters({ light: '', kind: '' })}
1910
+ onClearAll={() => setFilters({ status: '', light: '', kind: '', rooms: [] })}
1911
+ />
1912
+ }
1913
+ … />
1914
+ ```
1915
+
1916
+ - **Saved views are pills** above the toolbar (L3): useTableUrlState's
1917
+ views, each with its `label`, in order. The view on is pressed; none is
1918
+ once the filters move off every view. Under 48rem they stay on one line
1919
+ that scrolls sideways. Replaces a hand-written row of view buttons; a
1920
+ Deleted view goes in ListHeader's ⋯ menu as Show deleted instead.
1921
+ - **The filters** (L4): `FilterBar` holds search, the two filters used
1922
+ most (`primary`), and the rest behind Filters (`secondary`, with their
1923
+ chips, as `SecondaryFilters` draws them). No captions over controls:
1924
+ each names itself. `FilterSelect` says "Any status" while off and
1925
+ "Status: Active" on; `MultiChoice`'s `label` makes it "Rooms: Hall +1"
1926
+ instead of a chip per pick. Below 48rem search and Filters share a line
1927
+ and every filter, primary ones too, is in Filters' bottom sheet, so pass
1928
+ `primaryActive` (their chips) and an `onClearAll` that clears them all
1929
+ in one `setFilters` call.
1930
+ - **The Columns menu** (L5) sits at the end of the toolbar: a tick for
1931
+ every column but the first (the name) and the actions, remembered on
1932
+ this device under `storageKey` as every column's id in order and the
1933
+ unticked ones, so a column added later shows. Until something is ticked
1934
+ it starts from `visibleColumns`. While a view with `columns` is on, the
1935
+ view's columns show and the ticks can't change. A column whose `header`
1936
+ isn't a string names itself in the menu with `meta.label`. It isn't
1937
+ shown with the phone's row list.
1938
+ - **Row actions** (L9) take a column of their own, pinned to the right
1939
+ edge with its header for screen readers only. One action is its icon,
1940
+ its label the tooltip and accessible name; two or more are a ⋯ menu.
1941
+ A click on them never opens the row. Return `[]` for a row with none.
1942
+ Drop a hand-made Actions column and `pinLastColumn` when moving to it.
1943
+ - **A phone gets a row list** (L11) under 48rem: the `title`, the
1944
+ `status` at the line's end and one muted line of the `facts` that matter
1945
+ (two, usually), between dots. The whole row is the target, 44px at
1946
+ least, and opens as `opens` says: a link to the record, so a long press
1947
+ or a modified click works as a link's does. `title` is plain text (the
1948
+ row is already the link). Row actions sit at the row's end; headings,
1949
+ paging and every state hold. A card layout, when picked, wins.
1950
+ - The fixtures' `app/DataTable tools` ListTools, ListToolsFiltered and
1951
+ OneRowAction stories hold all of it, under axe and the token check in
1952
+ both themes; `e2e/data-table-tools.spec.ts` checks the pills, the stored
1953
+ pick and a view's columns winning, the ⋯ menu, the 44px rows, the
1954
+ phone's line and sheet.
1955
+
1956
+ ## 26. A record's related list, capped
1957
+
1958
+ A list of records related to this one, in a section of its view (a
1959
+ provider's visits, a project's tasks): the ten newest, then View all N to
1960
+ the whole list filtered to this record (R8), so a long list doesn't push
1961
+ the rest of the record away. With tabs (EntityView's), each such list
1962
+ counts as a group.
1963
+
1964
+ ```tsx
1965
+ import { RelatedTable } from '@tristan2828/ui-foundation'
1966
+
1967
+ const visits = useVisits({ provider: provider.id, sort: 'date:desc', page: 1, pageSize: 10 })
1968
+ <RelatedTable
1969
+ columns={VISIT_COLUMNS}
1970
+ opens={{ kind: 'dialog', to: (visit) => `/health/visits/${visit.id}` }}
1971
+ data={visits.data?.items ?? []}
1972
+ total={visits.data?.total ?? 0}
1973
+ isLoading={visits.isLoading}
1974
+ error={visits.error}
1975
+ onRetry={() => visits.refetch()}
1976
+ emptyTitle="No visits yet"
1977
+ viewAll={{ to: `/health/visits?provider=${provider.id}` }}
1978
+ phoneRow={{ title: (visit) => visit.what, facts: (visit) => [visit.date, visit.kind] }}
1979
+ />
1980
+ ```
1981
+
1982
+ - **`limit`** is 10 unless set; ask the server for that many, newest
1983
+ first. No pagination bar, and the headers aren't sort buttons (View all
1984
+ has the list's own sorting).
1985
+ - **View all** shows only when `total` is over the rows shown, its text
1986
+ "View all 19" unless `viewAll.label` says otherwise. It's a link, so a
1987
+ modified click opens a tab.
1988
+ - **`opens` is required**, as on any list. Everything else a DataTable
1989
+ takes for its rows (`rowActions`, `phoneRow`, `highlightRow`) works.
1990
+ - On a DataTable of your own, `limit` and `viewAll` do the same.
1991
+ - The fixture `app/DataTable tools` Related draws a capped list and a
1992
+ short one with no link; the spec follows View all.
@@ -0,0 +1,98 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { Navigator } from 'react-router';
3
+ import type { IconComponent } from './icon-component.js';
4
+ import { type ColumnsPick } from './table-columns.js';
5
+ /**
6
+ * A saved view as DataTable's `views` reads it: useTableUrlState's
7
+ * TableView, which has these two among its fields.
8
+ */
9
+ export type DataTableView = {
10
+ /** The pill's word ("Current"); the view's id unless set. */
11
+ label?: string;
12
+ /** The columns this view shows; while it's on they win over the Columns menu. */
13
+ columns?: readonly string[];
14
+ };
15
+ export declare function ViewPills({ views, value, onValueChange, label, }: {
16
+ views: readonly {
17
+ id: string;
18
+ label: string;
19
+ }[];
20
+ value: string | null;
21
+ onValueChange: (id: string) => void;
22
+ label: string;
23
+ }): import("react").JSX.Element;
24
+ export type DataTableColumnsMenu = {
25
+ /**
26
+ * Where the pick is remembered on this device, one key per list
27
+ * (`"my-app:medications:columns"`).
28
+ */
29
+ storageKey: string;
30
+ /** The button's text: "Columns" unless set. */
31
+ label?: string;
32
+ };
33
+ export declare function ColumnsMenu({ columns, visible, fixed, pick, onPickChange, setByView, label, }: {
34
+ /** Every column the menu can tick, in order, with its name. */
35
+ columns: readonly {
36
+ id: string;
37
+ label: string;
38
+ }[];
39
+ /** Every column id showing now, ticked or not tickable. */
40
+ visible: readonly string[];
41
+ /** Columns always shown (the name, the actions): never in the menu. */
42
+ fixed: readonly string[];
43
+ pick: ColumnsPick | null;
44
+ onPickChange: (pick: ColumnsPick | null) => void;
45
+ /** A view on that sets its own columns: the ticks show them and can't change. */
46
+ setByView: boolean;
47
+ label?: string;
48
+ }): import("react").JSX.Element;
49
+ /** One of a row's actions (DataTable `rowActions`). */
50
+ export type DataTableRowAction = {
51
+ /** What it does ("Delete"): the menu item's text, or the icon's tooltip and name when it's the only one. */
52
+ label: string;
53
+ /** Drawn alone when it's the row's only action, beside the label in the ⋯ menu. */
54
+ icon?: IconComponent;
55
+ onSelect: () => void;
56
+ /** `destructive` for Delete and the like. */
57
+ tone?: 'default' | 'destructive';
58
+ disabled?: boolean;
59
+ };
60
+ export declare function RowActions({ actions, rowLabel }: {
61
+ actions: readonly DataTableRowAction[];
62
+ rowLabel?: string;
63
+ }): import("react").JSX.Element | null;
64
+ /** What a row shows in the row list a phone gets (DataTable `phoneRow`). */
65
+ export type DataTablePhoneRow<TData> = {
66
+ /** The record's name: plain text, since the whole row is the link or button. */
67
+ title: (row: TData) => ReactNode;
68
+ /** Beside the name, at the end of the line: the status badge. */
69
+ status?: (row: TData) => ReactNode;
70
+ /** The facts that matter (two, usually) on one muted line under it, between dots; empty ones are left out. */
71
+ facts?: (row: TData) => readonly ReactNode[];
72
+ };
73
+ export declare function PhoneRow<TData>({ row, phoneRow, actions, highlighted, href, onOpen, }: {
74
+ row: TData;
75
+ phoneRow: DataTablePhoneRow<TData>;
76
+ actions?: ReactNode;
77
+ highlighted: boolean;
78
+ /** The record's address: the row is a link to it. */
79
+ href?: string;
80
+ /** What a plain click (or Enter) on the row does; with no `href`, the row is a button. */
81
+ onOpen?: () => void;
82
+ }): import("react").JSX.Element;
83
+ export declare const PHONE_LIST_CLASS = "flex flex-col overflow-hidden rounded-lg border border-border";
84
+ export declare function PhoneRowsSkeleton(): import("react").JSX.Element;
85
+ /** Where a capped list's whole list is (DataTable `viewAll`). */
86
+ export type DataTableViewAll = {
87
+ /** The list, filtered to this record (`/health/visits?provider=12`). */
88
+ to: string;
89
+ /** How many there are: the table's `total` unless set. */
90
+ total?: number;
91
+ /** The link's text: "View all <total>" unless set. */
92
+ label?: string;
93
+ };
94
+ export declare function ViewAllLink({ viewAll, total, navigator }: {
95
+ viewAll: DataTableViewAll;
96
+ total: number;
97
+ navigator?: Navigator;
98
+ }): import("react").JSX.Element;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Columns3Icon, EllipsisIcon } from 'lucide-react';
3
+ import { cn } from 'cn';
4
+ import { Button } from '../ui/button.js';
5
+ import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
6
+ import { Skeleton } from '../ui/skeleton.js';
7
+ import { IconAction } from './icon-action.js';
8
+ import { PillFilter } from './pill-filter.js';
9
+ import { togglePick } from './table-columns.js';
10
+ // The pills on one line that scrolls sideways under 48rem, wrapping wider.
11
+ // The padding keeps the focus ring inside the scroll box.
12
+ export function ViewPills({ views, value, onValueChange, label, }) {
13
+ return (_jsx("div", { "data-slot": "data-table-views", className: "max-md:-mx-1 max-md:overflow-x-auto max-md:p-1", children: _jsx(PillFilter, { label: label, allLabel: null, options: views.map((view) => ({ value: view.id, label: view.label })),
14
+ // No view's id matches '' (filters set by hand), so none is pressed.
15
+ value: value ?? '', onValueChange: onValueChange, className: "max-md:w-max max-md:flex-nowrap" }) }));
16
+ }
17
+ export function ColumnsMenu({ columns, visible, fixed, pick, onPickChange, setByView, label = 'Columns', }) {
18
+ const ids = [...fixed, ...columns.map((column) => column.id)];
19
+ return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { variant: "outline", size: "sm", "data-slot": "data-table-columns-menu" }), children: [_jsx(Columns3Icon, { "aria-hidden": "true" }), label] }), _jsxs(DropdownMenuContent, { align: "end", className: "w-52", children: [_jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: setByView ? 'Set by this view' : 'Show columns' }), columns.map((column) => (_jsx(DropdownMenuCheckboxItem, { checked: visible.includes(column.id), disabled: setByView, onCheckedChange: (checked) => onPickChange(togglePick(ids, visible, column.id, checked, pick)), children: column.label }, column.id)))] }), pick && !setByView ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onClick: () => onPickChange(null), children: "Reset to the list's columns" })] })) : null] })] }));
20
+ }
21
+ export function RowActions({ actions, rowLabel }) {
22
+ if (actions.length === 0)
23
+ return null;
24
+ const only = actions.length === 1 ? actions[0] : undefined;
25
+ if (only) {
26
+ return only.icon ? (_jsx(IconAction, { icon: only.icon, label: only.label, tone: only.tone, size: "sm", variant: "ghost", disabled: only.disabled, onClick: only.onSelect, "data-slot": "data-table-row-action" })) : (_jsx(Button, { variant: "ghost", size: "sm", disabled: only.disabled, onClick: only.onSelect, "data-slot": "data-table-row-action", className: cn(only.tone === 'destructive' && 'text-destructive-text'), children: only.label }));
27
+ }
28
+ return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(IconAction, { icon: EllipsisIcon, label: rowLabel ? `Actions for ${rowLabel}` : 'Actions', size: "sm", variant: "ghost", "data-slot": "data-table-row-actions" }) }), _jsx(DropdownMenuContent, { align: "end", className: "w-44", children: actions.map((action) => {
29
+ const Icon = action.icon;
30
+ return (_jsxs(DropdownMenuItem, { variant: action.tone === 'destructive' ? 'destructive' : 'default', disabled: action.disabled, onClick: action.onSelect, children: [Icon ? _jsx(Icon, { "aria-hidden": "true" }) : null, action.label] }, action.label));
31
+ }) })] }));
32
+ }
33
+ // The whole row is the target, 44px at least, lit as a table row is on hover.
34
+ const PHONE_TARGET_CLASS = 'flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-0.5 px-2 py-2 text-left outline-none ' +
35
+ 'focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset';
36
+ const PHONE_OPENS_CLASS = 'cursor-pointer hover:bg-(--table-hover)';
37
+ export function PhoneRow({ row, phoneRow, actions, highlighted, href, onOpen, }) {
38
+ const facts = (phoneRow.facts?.(row) ?? []).filter((fact) => fact !== null && fact !== undefined && fact !== '' && fact !== false);
39
+ const content = (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex min-w-0 items-baseline justify-between gap-3", children: [_jsx("span", { className: "min-w-0 type-body font-medium break-words text-foreground", children: phoneRow.title(row) }), phoneRow.status ? _jsx("span", { className: "shrink-0", children: phoneRow.status(row) }) : null] }), facts.length > 0 ? (_jsx("span", { className: "flex flex-wrap gap-x-1.5 type-caption text-muted-foreground", children: facts.map((fact, index) => (_jsxs("span", { className: "inline-flex gap-x-1.5", children: [index > 0 ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsx("span", { className: "sr-only", children: ", " })] })) : null, fact] }, index))) })) : null] }));
40
+ return (_jsxs("li", { "data-slot": "data-table-phone-row", "data-highlighted": highlighted || undefined, className: cn('flex items-center gap-1 border-b border-border last:border-b-0', highlighted &&
41
+ '[--muted-foreground:var(--table-highlight-muted-foreground)] bg-(--table-highlight) shadow-[inset_3px_0_0_0_var(--info-text)]'), children: [href !== undefined ? (_jsx("a", { href: href, className: cn(PHONE_TARGET_CLASS, PHONE_OPENS_CLASS), onClick: (event) => {
42
+ if (!onOpen || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
43
+ return;
44
+ event.preventDefault();
45
+ onOpen();
46
+ }, children: content })) : onOpen ? (_jsx("button", { type: "button", className: cn(PHONE_TARGET_CLASS, PHONE_OPENS_CLASS), onClick: onOpen, children: content })) : (_jsx("div", { className: PHONE_TARGET_CLASS, children: content })), actions ? _jsx("div", { className: "shrink-0 pr-1", children: actions }) : null] }));
47
+ }
48
+ export const PHONE_LIST_CLASS = 'flex flex-col overflow-hidden rounded-lg border border-border';
49
+ export function PhoneRowsSkeleton() {
50
+ return (_jsx("ul", { className: PHONE_LIST_CLASS, "data-state": "loading", "aria-hidden": "true", children: Array.from({ length: 6 }, (_, index) => (_jsxs("li", { className: "flex flex-col gap-1.5 border-b border-border px-2 py-2.5 last:border-b-0", children: [_jsx(Skeleton, { className: "h-4 w-3/5" }), _jsx(Skeleton, { className: "h-3 w-2/5" })] }, index))) }));
51
+ }
52
+ export function ViewAllLink({ viewAll, total, navigator }) {
53
+ return (_jsx("a", { "data-slot": "data-table-view-all", href: navigator ? navigator.createHref(viewAll.to) : viewAll.to, className: "self-start rounded-sm type-body font-medium text-link underline-offset-4 outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50", onClick: (event) => {
54
+ if (!navigator || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
55
+ return;
56
+ event.preventDefault();
57
+ void navigator.push(viewAll.to);
58
+ }, children: viewAll.label ?? `View all ${total}` }));
59
+ }
@@ -5,6 +5,7 @@ import type { AppError } from '../../api/contracts.js';
5
5
  import type { ArtworkAspect } from './artwork.js';
6
6
  import type { IconComponent } from './icon-component.js';
7
7
  import { type RowGroup } from './table-groups.js';
8
+ import { type DataTableColumnsMenu, type DataTablePhoneRow, type DataTableRowAction, type DataTableView, type DataTableViewAll } from './data-table-tools.js';
8
9
  export type SortingState = {
9
10
  id: string;
10
11
  desc: boolean;
@@ -24,9 +25,14 @@ declare module '@tanstack/table-core' {
24
25
  * a phone). Without `clip`, the content wraps at it.
25
26
  */
26
27
  maxWidth?: string;
28
+ /**
29
+ * The column's name in DataTable's Columns menu (`columnsMenu`), for a
30
+ * column whose `header` isn't a string.
31
+ */
32
+ label?: string;
27
33
  }
28
34
  }
29
- export type DataTableProps<TData extends Record<string, unknown>> = {
35
+ export type DataTableProps<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView> = {
30
36
  columns: LegacyColumnDef<TData, unknown>[];
31
37
  data: TData[];
32
38
  total: number;
@@ -247,6 +253,58 @@ export type DataTableProps<TData extends Record<string, unknown>> = {
247
253
  label?: string;
248
254
  icon?: IconComponent;
249
255
  };
256
+ /**
257
+ * The list's saved views as pills above the toolbar (the list page
258
+ * standard, L3): useTableUrlState's views, by id, each with a `label`, in
259
+ * their order. One is pressed while it's `activeView`; none once the
260
+ * filters move off every view. Under 48rem they stay on one line that
261
+ * scrolls sideways. A view with `columns` shows those while it's on, over
262
+ * the Columns menu's pick.
263
+ */
264
+ views?: Readonly<Record<string, TView>>;
265
+ /** The view on: useTableUrlState's `activeView`, or null. */
266
+ activeView?: string | null;
267
+ /** A pill pressed: useTableUrlState's `applyView` (it gets the view, then its id). */
268
+ onViewChange?: (view: TView, id: string) => void;
269
+ /** The pills' group name: "Views" unless set. */
270
+ viewsLabel?: string;
271
+ /**
272
+ * A Columns menu at the end of the toolbar (L5): a tick for every column
273
+ * but the first (the name) and the row actions, remembered on this device
274
+ * under `storageKey`. Until something is ticked it starts from
275
+ * `visibleColumns` (or every column). While a view with `columns` is on,
276
+ * the view's columns show and the ticks can't change. A column's name in
277
+ * the menu is its string `header`, or `meta.label`.
278
+ */
279
+ columnsMenu?: DataTableColumnsMenu;
280
+ /**
281
+ * A row's actions (L9), in a column of their own pinned to the right edge,
282
+ * its header for screen readers only. One action is its icon (its label
283
+ * the tooltip and name), two or more a ⋯ menu. A row with none gets an
284
+ * empty cell. A click on them never opens the row.
285
+ */
286
+ rowActions?: (row: TData) => readonly DataTableRowAction[];
287
+ /**
288
+ * Under 48rem, a row list in place of the table (L11): the name, the
289
+ * status at the line's end, and one muted line of the facts that matter.
290
+ * The whole row is the target, 44px at least, and opens as `opens` says
291
+ * (a link to the record, so a long press or a modified click works as
292
+ * links do); rows edited in place (`kind: 'rows'`) open nothing here.
293
+ * Row actions sit at the row's end. Headings, paging and every state hold;
294
+ * `totals` is the table's alone. A card layout, when picked, wins.
295
+ */
296
+ phoneRow?: DataTablePhoneRow<TData>;
297
+ /**
298
+ * At most this many rows, with no pagination bar: a record's list of
299
+ * related records (R8, or RelatedTable). The caller still fetches only
300
+ * that many; `data` past it isn't shown.
301
+ */
302
+ limit?: number;
303
+ /**
304
+ * With `limit`: a View all link under the rows to the whole list, shown
305
+ * when there are more than the rows shown.
306
+ */
307
+ viewAll?: DataTableViewAll;
250
308
  };
251
309
  /** A field DataTable's rows can be grouped by (`groupings`). */
252
310
  export type DataTableGrouping<TData> = {
@@ -322,4 +380,4 @@ export type DataTableTotals = {
322
380
  */
323
381
  cells?: Partial<Record<string, ReactNode>>;
324
382
  };
325
- export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
383
+ export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, views, activeView, onViewChange, viewsLabel, columnsMenu, rowActions, phoneRow, limit, viewAll, }: DataTableProps<TData, TView>): import("react").JSX.Element;
@@ -10,7 +10,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
10
10
  // pagination tree-shakeable and independently swappable, which buys nothing
11
11
  // here: every row model is manual (the server sorts and pages), so this
12
12
  // table never uses TanStack's own sorted/paginated row models at all.
13
- import { useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, } from 'react';
13
+ import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
14
14
  import { UNSAFE_LocationContext as LocationContext, UNSAFE_NavigationContext as NavigationContext, } from 'react-router';
15
15
  import { flexRender } from '@tanstack/react-table';
16
16
  import { cn } from 'cn';
@@ -29,6 +29,10 @@ import { EditInPlaceStore } from './edit-in-place-store.js';
29
29
  import { LeaveGuard } from './editable-value.js';
30
30
  import { recordDialogState } from './record-dialog-context.js';
31
31
  import { groupByValues, groupRuns } from './table-groups.js';
32
+ import { ColumnsMenu, PHONE_LIST_CLASS, PhoneRow, PhoneRowsSkeleton, RowActions, ViewAllLink, ViewPills, } from './data-table-tools.js';
33
+ import { ROW_ACTIONS_COLUMN_ID, visibleFromPick } from './table-columns.js';
34
+ import { useColumnsPick } from '../../hooks/use-columns-pick.js';
35
+ import { useIsPhone } from '../../hooks/use-is-phone.js';
32
36
  import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from '../ui/table.js';
33
37
  // Whether a link is to `to` (its path and query), the record the row opens.
34
38
  function linksTo(link, to) {
@@ -361,7 +365,25 @@ function useStickyHeadings(containerRef, enabled) {
361
365
  }, [containerRef, enabled]);
362
366
  return { scrollsSideways, headHeight };
363
367
  }
364
- export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', }) {
368
+ // `rowActions`: the column DataTable adds for them, pinned last. Its cell
369
+ // reads the app's function through context, so the column stays the same
370
+ // object between renders (a new one would remount every cell, and close a
371
+ // menu that's open).
372
+ const RowActionsContext = createContext(undefined);
373
+ function RowActionsCell({ row }) {
374
+ const getActions = useContext(RowActionsContext);
375
+ return _jsx(RowActions, { actions: getActions?.(row.original) ?? [] });
376
+ }
377
+ const ROW_ACTIONS_COLUMN = {
378
+ id: ROW_ACTIONS_COLUMN_ID,
379
+ enableSorting: false,
380
+ header: () => _jsx("span", { className: "sr-only", children: "Actions" }),
381
+ cell: RowActionsCell,
382
+ meta: { align: 'right' },
383
+ };
384
+ // The cell under the actions' column: as narrow as its button.
385
+ const ROW_ACTIONS_CELL_CLASS = 'w-px py-0';
386
+ export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', views, activeView = null, onViewChange, viewsLabel = 'Views', columnsMenu, rowActions, phoneRow, limit, viewAll, }) {
365
387
  // The switch's own state, for a table that doesn't pass `layout`.
366
388
  const [ownLayout, setOwnLayout] = useState('table');
367
389
  const requestedLayout = layoutProp ?? ownLayout;
@@ -428,18 +450,33 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
428
450
  const [store] = useState(() => new EditInPlaceStore());
429
451
  const editing = useSyncExternalStore(store.subscribe, () => store.editing, () => store.editing);
430
452
  const pageCount = Math.max(1, Math.ceil(total / pageSize));
453
+ // The columns showing: a view's while it's on, else the Columns menu's
454
+ // pick, else the app's `visibleColumns`. The first column always shows.
455
+ const leafIds = leafColumnIds(columns);
456
+ const fixedColumns = leafIds.slice(0, 1);
457
+ const viewColumns = activeView !== null ? views?.[activeView]?.columns : undefined;
458
+ const [columnsPick, setColumnsPick] = useColumnsPick(columnsMenu?.storageKey);
459
+ const shownColumns = viewColumns ?? (columnsMenu && columnsPick ? visibleFromPick(leafIds, columnsPick, fixedColumns) : visibleColumns);
460
+ // `rowActions`: their column, last.
461
+ const hasRowActions = Boolean(rowActions);
462
+ const tableColumns = useMemo(() => (hasRowActions ? [...columns, ROW_ACTIONS_COLUMN] : columns), [columns, hasRowActions]);
463
+ const pinLast = Boolean(pinLastColumn || hasRowActions);
464
+ // `limit`: a capped list shows that many rows and no pagination bar.
465
+ const shownData = limit === undefined ? data : data.slice(0, limit);
466
+ // `phoneRow`: a row list in place of the table under 48rem.
467
+ const isPhone = useIsPhone();
431
468
  // TanStack treats a column missing from this map as visible, so every
432
469
  // column gets an entry once a list is given.
433
470
  // While grouped, the grouped column is hidden: its value is the heading.
434
471
  const columnVisibility = {
435
- ...(visibleColumns
436
- ? Object.fromEntries(leafColumnIds(columns).map((id) => [id, visibleColumns.includes(id)]))
472
+ ...(shownColumns
473
+ ? Object.fromEntries(leafIds.map((id) => [id, fixedColumns.includes(id) || shownColumns.includes(id)]))
437
474
  : {}),
438
475
  ...(activeGrouping ? { [activeGrouping.id]: false } : {}),
439
476
  };
440
477
  const table = useLegacyTable({
441
- data,
442
- columns,
478
+ data: shownData,
479
+ columns: tableColumns,
443
480
  getRowId: getRowId,
444
481
  state: {
445
482
  sorting,
@@ -471,7 +508,8 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
471
508
  // `width="content"`: the width the table last had loaded, kept while it
472
509
  // shows another state.
473
510
  // A card layout's grid takes the whole width whatever `width` says.
474
- const fitsColumns = width === 'content' && !cardLayout;
511
+ const showPhoneRows = Boolean(phoneRow) && isPhone && !cardLayout;
512
+ const fitsColumns = width === 'content' && !cardLayout && !showPhoneRows;
475
513
  const root = useRef(null);
476
514
  const body = useRef(null);
477
515
  const [lastWidth, setLastWidth] = useState(null);
@@ -484,7 +522,7 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
484
522
  return () => observer.disconnect();
485
523
  }, [fitsColumns, isSuccessView]);
486
524
  const containerRef = useRef(null);
487
- const { barRef, isOverflowing, scrollWidth } = useBottomScrollbar(containerRef, Boolean(pinFirstColumn) && isSuccessView && !cardLayout);
525
+ const { barRef, isOverflowing, scrollWidth } = useBottomScrollbar(containerRef, Boolean(pinFirstColumn) && isSuccessView && !cardLayout && !showPhoneRows);
488
526
  const rows = table.getRowModel().rows;
489
527
  const visibleLeafColumns = table.getVisibleLeafColumns();
490
528
  const visibleColumnCount = visibleLeafColumns.length;
@@ -635,22 +673,61 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
635
673
  const value = flexRender(cell.column.columnDef.cell, cell.getContext());
636
674
  const shown = meta?.clip ? (_jsx(ClippedText, { maxWidth: meta.maxWidth ?? DEFAULT_CLIP_WIDTH, children: value })) : meta?.maxWidth ? (_jsx("div", { className: "whitespace-normal break-words", style: { maxWidth: meta.maxWidth }, children: value })) : (value);
637
675
  const isPinnedFirst = pinFirstColumn && index === 0;
638
- const isPinnedLast = pinLastColumn && index === row.getVisibleCells().length - 1;
639
- return (_jsx(TableCell, { className: cn(isPinnedFirst && PINNED_COLUMN_CLASS, isPinnedLast && PINNED_LAST_COLUMN_CLASS, (isPinnedFirst || isPinnedLast) && striped && PINNED_STRIPED_CELL_CLASS, alignClass(meta?.align)), children: isPinnedFirst ? _jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: shown }) : shown }, cell.id));
676
+ const isPinnedLast = pinLast && index === row.getVisibleCells().length - 1;
677
+ return (_jsx(TableCell, { className: cn(isPinnedFirst && PINNED_COLUMN_CLASS, isPinnedLast && PINNED_LAST_COLUMN_CLASS, (isPinnedFirst || isPinnedLast) && striped && PINNED_STRIPED_CELL_CLASS, alignClass(meta?.align), cell.column.id === ROW_ACTIONS_COLUMN_ID && ROW_ACTIONS_CELL_CLASS), children: isPinnedFirst ? _jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: shown }) : shown }, cell.id));
640
678
  }) }, key));
641
679
  };
642
- const content = (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [layouts?.length || groupings?.length ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: toolbar }), groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [activeGrouping && (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold all' : 'Fold all' })), _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layouts?.length ? (_jsx(LayoutSwitch, { options: [
680
+ // `columnsMenu`: every column but the first and the actions, by name.
681
+ const menuColumns = columnsMenu
682
+ ? table
683
+ .getAllLeafColumns()
684
+ .filter((column) => column.id !== ROW_ACTIONS_COLUMN_ID && !fixedColumns.includes(column.id))
685
+ .map((column) => {
686
+ const header = column.columnDef.header;
687
+ return { id: column.id, label: column.columnDef.meta?.label ?? (typeof header === 'string' ? header : column.id) };
688
+ })
689
+ : [];
690
+ // `views`: the pills, in the views' order.
691
+ const viewEntries = views ? Object.entries(views) : [];
692
+ // A record a phone row opens: its address, and what a plain tap does.
693
+ const phoneTarget = (row) => {
694
+ const href = opensTo
695
+ ? navigation
696
+ ? navigation.navigator.createHref(opensTo.to(row.original))
697
+ : opensTo.to(row.original)
698
+ : undefined;
699
+ const onOpen = openRow
700
+ ? () => openRow(row.original)
701
+ : detailPanel
702
+ ? () => setSelection({ key: row.id, rowId: row.id })
703
+ : undefined;
704
+ return { href, onOpen };
705
+ };
706
+ const phoneList = (items) => (_jsx("ul", { role: "list", className: PHONE_LIST_CLASS, children: items.map((row) => (_jsx(PhoneRow, { row: row.original, phoneRow: phoneRow, highlighted: Boolean(highlightRow?.(row.original)), actions: rowActions ? _jsx(RowActions, { actions: rowActions(row.original) }) : undefined, ...phoneTarget(row) }, row.id))) }));
707
+ const viewAllTotal = viewAll?.total ?? total;
708
+ // The row list a phone gets has no columns to pick.
709
+ const showColumnsMenu = Boolean(columnsMenu) && !showPhoneRows;
710
+ const content = (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [viewEntries.length > 0 ? (_jsx(ViewPills, { label: viewsLabel, views: viewEntries.map(([id, view]) => ({ id, label: view.label ?? id })), value: activeView, onValueChange: (id) => {
711
+ const view = views?.[id];
712
+ if (view)
713
+ onViewChange?.(view, id);
714
+ } })) : null, layouts?.length || groupings?.length || showColumnsMenu ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1 basis-72", children: toolbar }), showColumnsMenu ? (_jsx(ColumnsMenu, { label: columnsMenu?.label, columns: menuColumns, visible: shownColumns ?? leafIds, fixed: fixedColumns, pick: columnsPick, onPickChange: setColumnsPick, setByView: viewColumns !== undefined })) : null, groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [activeGrouping && (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold all' : 'Fold all' })), _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layouts?.length ? (_jsx(LayoutSwitch, { options: [
643
715
  { id: 'table', label: tableLayout?.label ?? 'Table', icon: tableLayout?.icon ?? TableIcon },
644
716
  ...layouts,
645
717
  ], value: currentLayout, onValueChange: setLayout })) : null] })) : (toolbar), _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: fitsColumns && !isSuccessView && lastWidth !== null
646
718
  ? { '--data-table-last-width': `${lastWidth}px` }
647
- : undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry })) : isLoading || isPastLastPage ? (cardLayout ? (_jsx(CardsSkeleton, { layout: cardLayout })) : (_jsx(TableSkeleton, { columnCount: table.getVisibleLeafColumns().length }))) : isEmpty ? (_jsxs(Empty, { "data-state": "empty", children: [_jsxs(EmptyHeader, { children: [_jsx(EmptyTitle, { children: emptyTitle }), emptyDescription && _jsx(EmptyDescription, { children: emptyDescription })] }), emptyAction] })) : (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: selectedRow && detailPanel && isWide ? (_jsxs("aside", { "aria-label": detailLabel, "data-slot": "data-table-detail", className: DETAIL_ASIDE_CLASS, onKeyDown: (event) => {
719
+ : undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry })) : isLoading || isPastLastPage ? (cardLayout ? (_jsx(CardsSkeleton, { layout: cardLayout })) : showPhoneRows ? (_jsx(PhoneRowsSkeleton, {})) : (_jsx(TableSkeleton, { columnCount: table.getVisibleLeafColumns().length }))) : isEmpty ? (_jsxs(Empty, { "data-state": "empty", children: [_jsxs(EmptyHeader, { children: [_jsx(EmptyTitle, { children: emptyTitle }), emptyDescription && _jsx(EmptyDescription, { children: emptyDescription })] }), emptyAction] })) : (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: selectedRow && detailPanel && isWide ? (_jsxs("aside", { "aria-label": detailLabel, "data-slot": "data-table-detail", className: DETAIL_ASIDE_CLASS, onKeyDown: (event) => {
648
720
  const target = event.target;
649
721
  if (event.key !== 'Escape' || event.defaultPrevented || target.closest(TYPING_SELECTOR))
650
722
  return;
651
723
  event.preventDefault();
652
724
  closeDetail();
653
- }, children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("h2", { className: "type-label text-muted-foreground", children: detailLabel }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: closeDetail, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }), detailPanel(selectedRow.original)] })) : null, children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons, onCardClick: onCardClick })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined, className: cn(stickyGroups && STICKY_FOCUS_CLASS), containerStyle: stickyGroups
725
+ }, children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("h2", { className: "type-label text-muted-foreground", children: detailLabel }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: closeDetail, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }), detailPanel(selectedRow.original)] })) : null, children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons, onCardClick: onCardClick })) : showPhoneRows ? (_jsx("div", { "data-state": "success", "data-slot": "data-table-phone-rows", className: "flex flex-col gap-4", children: runs
726
+ ? runs.map((run, runIndex) => {
727
+ const isFolded = folded.has(run.key);
728
+ return (_jsxs("section", { "data-slot": "table-group", "data-folded": isFolded || undefined, className: "flex flex-col gap-2", children: [_jsxs("h2", { "data-slot": "table-group-heading", className: "flex items-baseline gap-2 px-1", children: [_jsx(GroupLabel, { run: run, icon: groupIcons?.get(run.key), isFolded: isFolded, onToggle: () => toggleFold(run.key) }), groupSummary && (_jsx("span", { className: "type-caption text-muted-foreground tabular-nums", children: groupSummary(run.rows.map((row) => row.original), { key: run.key, label: run.label }) }))] }), !isFolded && phoneList(run.rows)] }, `${runIndex}:${run.key}`));
729
+ })
730
+ : phoneList(rows) })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined, className: cn(stickyGroups && STICKY_FOCUS_CLASS), containerStyle: stickyGroups
654
731
  ? {
655
732
  '--data-table-head-height': `${headHeight}px`,
656
733
  '--data-table-sticky-top': stickyTop,
@@ -675,7 +752,7 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
675
752
  // The arrow on the label's left, so the label's
676
753
  // right edge lines up with the numbers under it.
677
754
  header.column.columnDef.meta?.align === 'right' && 'ml-auto flex-row-reverse'), onClick: header.column.getToggleSortingHandler(), children: [flexRender(header.column.columnDef.header, header.getContext()), sortDirection === 'asc' ? (_jsx(ArrowUpIcon, { className: "size-3.5 text-muted-foreground" })) : sortDirection === 'desc' ? (_jsx(ArrowDownIcon, { className: "size-3.5 text-muted-foreground" })) : (_jsx(ArrowUpDownIcon, { className: "size-3.5 text-muted-foreground/50" }))] })) : (flexRender(header.column.columnDef.header, header.getContext()));
678
- return (_jsx(TableHead, { className: cn(!showHeader && HIDDEN_HEAD_CLASS, pinFirstColumn && index === 0 && PINNED_COLUMN_CLASS, pinLastColumn &&
755
+ return (_jsx(TableHead, { className: cn(!showHeader && HIDDEN_HEAD_CLASS, pinFirstColumn && index === 0 && PINNED_COLUMN_CLASS, pinLast &&
679
756
  index === headerGroup.headers.length - 1 &&
680
757
  PINNED_LAST_COLUMN_CLASS, stickyGroups && showHeader && STICKY_HEAD_CELL_CLASS, alignClass(header.column.columnDef.meta?.align)), "aria-sort": !canSort
681
758
  ? undefined
@@ -688,13 +765,13 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
688
765
  const isFolded = folded.has(run.key);
689
766
  return (_jsxs(TableBody, { "data-slot": "table-group", "data-folded": isFolded || undefined, className: cn(!striped && UNSTRIPED_BODY_CLASS), children: [_jsx(TableRow, { "data-slot": "table-group-heading", className: cn('hover:bg-transparent has-aria-expanded:bg-transparent', stickyGroups && 'border-b-0'), children: _jsx(TableHead, { scope: "rowgroup", colSpan: visibleColumnCount, className: cn(GROUP_HEADING_CLASS, stickyGroups && STICKY_GROUP_HEADING_CLASS), children: _jsxs("span", { className: "sticky left-(--table-cell-px) inline-flex items-baseline gap-2", children: [_jsx(GroupLabel, { run: run, icon: groupIcons?.get(run.key), isFolded: isFolded, onToggle: () => toggleFold(run.key) }), groupSummary && (_jsx("span", { className: "type-caption text-muted-foreground tabular-nums", children: groupSummary(run.rows.map((row) => row.original), { key: run.key, label: run.label }) }))] }) }) }), _jsx("tr", { hidden: true, "aria-hidden": "true", "data-slot": "table-group-stripe-offset" }), !isFolded && run.rows.map((row) => renderRow(row, placeKey(run.key, row.id)))] }, `${runIndex}:${run.key}`));
690
767
  })) : (_jsx(TableBody, { className: cn(!striped && UNSTRIPED_BODY_CLASS), children: rows.map((row) => renderRow(row)) })), totals && (_jsx(TableFooter, { className: TOTALS_FOOTER_CLASS, children: _jsx(TableRow, { "data-slot": "table-totals", className: "hover:bg-transparent", children: visibleLeafColumns.map((column, index) => {
691
- const className = cn(pinFirstColumn && index === 0 && PINNED_TOTALS_LABEL_CLASS, pinLastColumn && index === visibleColumnCount - 1 && PINNED_LAST_COLUMN_CLASS, alignClass(column.columnDef.meta?.align));
768
+ const className = cn(pinFirstColumn && index === 0 && PINNED_TOTALS_LABEL_CLASS, pinLast && index === visibleColumnCount - 1 && PINNED_LAST_COLUMN_CLASS, alignClass(column.columnDef.meta?.align));
692
769
  return index === 0 ? (_jsx(TableHead, { scope: "row", className: cn(TOTALS_LABEL_CLASS, className), children: pinFirstColumn ? (_jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: totals.label })) : (totals.label) }, column.id)) : (_jsx(TableCell, { className: className, children: totals.cells?.[column.id] }, column.id));
693
- }) }) }))] })), pinFirstColumn && isOverflowing && !cardLayout && (_jsx("div", { ref: barRef, "aria-hidden": "true", tabIndex: -1, "data-slot": "bottom-scrollbar", className: "sticky bottom-0 z-20 h-4 overflow-x-auto border-t border-border bg-background", children: _jsx("div", { style: { width: scrollWidth, height: 1 } }) })), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", "data-slot": "data-table-pagination", children: [_jsxs("p", { className: "type-body text-muted-foreground", children: [total === 0 ? 0 : (page - 1) * pageSize + 1, '–', Math.min(page * pageSize, total), " of ", total] }), _jsxs("div", { className: "flex items-center gap-2", children: [pageSizes && pageSizes.length > 1 && onPageSizeChange ? (_jsx(PageSizeMenu, { pageSizes: pageSizes, value: pageSize, onValueChange: onPageSizeChange })) : null, _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Previous page", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: _jsx(ChevronLeftIcon, {}) }), _jsxs("span", { className: "type-body text-muted-foreground", children: ["Page ", page, " of ", pageCount] }), _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Next page", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: _jsx(ChevronRightIcon, {}) })] })] })] })) })] }));
694
- return (_jsxs(EditInPlaceContext.Provider, { value: store, children: [editing && _jsx(LeaveGuard, { store: store }), width === 'content' ? _jsx("div", { className: "@container/data-table", children: content }) : content, detailPanel && (_jsx(Sheet, { open: Boolean(selectedRow) && !isWide && isSuccessView && !cardLayout, onOpenChange: (open) => {
695
- if (!open)
696
- setSelection(null);
697
- }, children: _jsxs(SheetContent, { side: "bottom", className: "max-h-[85dvh] overflow-y-auto", "data-slot": "data-table-detail-sheet", children: [_jsx(SheetHeader, { className: "pb-0", children: _jsx(SheetTitle, { children: detailLabel }) }), _jsx("div", { className: "px-4 pb-4", children: selectedRow && detailPanel(selectedRow.original) })] }) }))] }));
770
+ }) }) }))] })), pinFirstColumn && isOverflowing && !cardLayout && !showPhoneRows && (_jsx("div", { ref: barRef, "aria-hidden": "true", tabIndex: -1, "data-slot": "bottom-scrollbar", className: "sticky bottom-0 z-20 h-4 overflow-x-auto border-t border-border bg-background", children: _jsx("div", { style: { width: scrollWidth, height: 1 } }) })), viewAll && limit !== undefined && viewAllTotal > rows.length ? (_jsx(ViewAllLink, { viewAll: viewAll, total: viewAllTotal, navigator: navigation?.navigator })) : null, limit === undefined && (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", "data-slot": "data-table-pagination", children: [_jsxs("p", { className: "type-body text-muted-foreground", children: [total === 0 ? 0 : (page - 1) * pageSize + 1, '–', Math.min(page * pageSize, total), " of ", total] }), _jsxs("div", { className: "flex items-center gap-2", children: [pageSizes && pageSizes.length > 1 && onPageSizeChange ? (_jsx(PageSizeMenu, { pageSizes: pageSizes, value: pageSize, onValueChange: onPageSizeChange })) : null, _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Previous page", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: _jsx(ChevronLeftIcon, {}) }), _jsxs("span", { className: "type-body text-muted-foreground", children: ["Page ", page, " of ", pageCount] }), _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Next page", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: _jsx(ChevronRightIcon, {}) })] })] }))] })) })] }));
771
+ return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs(RowActionsContext.Provider, { value: rowActions, children: [editing && _jsx(LeaveGuard, { store: store }), width === 'content' ? _jsx("div", { className: "@container/data-table", children: content }) : content, detailPanel && (_jsx(Sheet, { open: Boolean(selectedRow) && !isWide && isSuccessView && !cardLayout, onOpenChange: (open) => {
772
+ if (!open)
773
+ setSelection(null);
774
+ }, children: _jsxs(SheetContent, { side: "bottom", className: "max-h-[85dvh] overflow-y-auto", "data-slot": "data-table-detail-sheet", children: [_jsx(SheetHeader, { className: "pb-0", children: _jsx(SheetTitle, { children: detailLabel }) }), _jsx("div", { className: "px-4 pb-4", children: selectedRow && detailPanel(selectedRow.original) })] }) }))] }) }));
698
775
  }
699
776
  // The list and, once a row is picked on a wide screen, the detail panel
700
777
  // beside it (`detailPanel`). Without a panel it adds nothing.
@@ -0,0 +1,55 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type ActiveFilter } from './secondary-filters.js';
3
+ export type FilterBarSearch = {
4
+ value: string;
5
+ onChange: (value: string) => void;
6
+ /** What can be searched ("Search names and notes"). */
7
+ placeholder?: string;
8
+ /** The box's accessible name: "Search" unless set. */
9
+ label?: string;
10
+ };
11
+ export type FilterBarProps = {
12
+ search?: FilterBarSearch;
13
+ /** The filters shown in the toolbar (two, usually): FilterSelect, MultiChoice with `label`. */
14
+ primary?: ReactNode;
15
+ /**
16
+ * The primary filters that are on, as chips: shown only below 48rem,
17
+ * where those filters move into the sheet. Wider, each control shows its
18
+ * own value.
19
+ */
20
+ primaryActive?: readonly ActiveFilter[];
21
+ /** The rest, behind the Filters button: SecondaryFilters' children. */
22
+ secondary?: ReactNode;
23
+ /** The secondary filters that are on: SecondaryFilters' `active`. */
24
+ active?: readonly ActiveFilter[];
25
+ /** Takes every secondary filter off, in one update (useTableUrlState's `setFilters`). */
26
+ onClear?: () => void;
27
+ /**
28
+ * Takes every filter in the sheet off below 48rem, primary ones too, in
29
+ * one update. `onClear` unless set.
30
+ */
31
+ onClearAll?: () => void;
32
+ /** The Filters button's text. */
33
+ filtersLabel?: string;
34
+ };
35
+ export declare function FilterBar({ search, primary, primaryActive, secondary, active, onClear, onClearAll, filtersLabel, }: FilterBarProps): import("react").JSX.Element;
36
+ export type FilterSelectOption = {
37
+ value: string;
38
+ label: string;
39
+ };
40
+ export type FilterSelectProps = {
41
+ /** What it filters ("Status"): the prefix of the value it shows ("Status: Active"). */
42
+ label: string;
43
+ options: readonly FilterSelectOption[];
44
+ /** The picked option's value; '' is any. */
45
+ value: string;
46
+ onValueChange: (value: string) => void;
47
+ /** What it says while off: "Any <label in lower case>" unless set ("Any status"). */
48
+ anyLabel?: string;
49
+ className?: string;
50
+ };
51
+ /**
52
+ * A single-choice filter that names itself: "Any status" while off,
53
+ * "Status: Active" with a value, so the toolbar needs no captions.
54
+ */
55
+ export declare function FilterSelect({ label, options, value, onValueChange, anyLabel, className }: FilterSelectProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SearchIcon } from 'lucide-react';
3
+ import { InputGroup, InputGroupAddon, InputGroupInput } from '../ui/input-group.js';
4
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
5
+ import { useIsPhone } from '../../hooks/use-is-phone.js';
6
+ import { SecondaryFilters } from './secondary-filters.js';
7
+ const SEARCH_CLASS = 'w-56 max-w-full';
8
+ export function FilterBar({ search, primary, primaryActive = [], secondary, active = [], onClear, onClearAll, filtersLabel = 'Filters', }) {
9
+ const isMobile = useIsPhone();
10
+ const searchBox = search ? (_jsxs(InputGroup, { className: isMobile ? 'min-w-0 flex-1 basis-40' : SEARCH_CLASS, "data-slot": "filter-bar-search", children: [_jsx(InputGroupAddon, { children: _jsx(SearchIcon, { "aria-hidden": "true" }) }), _jsx(InputGroupInput, { type: "search", value: search.value, onChange: (event) => search.onChange(event.target.value), placeholder: search.placeholder, "aria-label": search.label ?? 'Search' })] })) : null;
11
+ if (isMobile) {
12
+ const hasSheet = Boolean(primary || secondary);
13
+ return (_jsxs("div", { "data-slot": "filter-bar", "data-layout": "phone", className: "flex flex-wrap items-center gap-2", children: [searchBox, hasSheet && (_jsxs(SecondaryFilters, { className: "contents", label: filtersLabel, active: [...primaryActive, ...active], onClear: onClearAll ?? onClear ?? (() => { }), children: [primary, secondary] }))] }));
14
+ }
15
+ return (_jsxs("div", { "data-slot": "filter-bar", className: "flex flex-wrap items-center gap-2", children: [searchBox, primary, secondary && (_jsx(SecondaryFilters, { label: filtersLabel, active: active, onClear: onClear ?? (() => { }), children: secondary }))] }));
16
+ }
17
+ // Base UI's Select needs a value for "any" that isn't empty.
18
+ const ANY = '__any__';
19
+ /**
20
+ * A single-choice filter that names itself: "Any status" while off,
21
+ * "Status: Active" with a value, so the toolbar needs no captions.
22
+ */
23
+ export function FilterSelect({ label, options, value, onValueChange, anyLabel, className }) {
24
+ const any = anyLabel ?? `Any ${label.toLowerCase()}`;
25
+ const picked = options.find((option) => option.value === value);
26
+ const shown = picked ? `${label}: ${picked.label}` : any;
27
+ return (_jsxs(Select, { value: picked ? picked.value : ANY, onValueChange: (next) => onValueChange(next === ANY || next === null ? '' : String(next)), children: [_jsx(SelectTrigger, { "aria-label": shown, "data-slot": "filter-select", "data-active": picked ? true : undefined, className: className, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), options.map((option) => (_jsx(SelectItem, { value: option.value, children: option.label }, option.value)))] })] }));
28
+ }
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- export declare function MultiChoice<T extends string>({ options, value, onValueChange, getLabel, id, placeholder, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }: {
2
+ export declare function MultiChoice<T extends string>({ options, value, onValueChange, getLabel, id, placeholder, label, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }: {
3
3
  /** Every allowed option, in display order. */
4
4
  options: readonly T[];
5
5
  value: T[];
@@ -12,6 +12,14 @@ export declare function MultiChoice<T extends string>({ options, value, onValueC
12
12
  /** Id for the text input, so a <FieldLabel htmlFor> labels it. */
13
13
  id?: string;
14
14
  placeholder?: string;
15
+ /**
16
+ * A toolbar filter that names itself (the list page standard, L4): with
17
+ * picks it shows "<label>: <first> +N" in place of a chip per pick, so
18
+ * it stays one line; with none, the `placeholder` ("Any status"). Picks
19
+ * come off in the list, or with Backspace. Leave it out on a form, where
20
+ * every pick is its own chip.
21
+ */
22
+ label?: string;
15
23
  /** For use without a visible label (e.g. a table toolbar filter). */
16
24
  'aria-label'?: string;
17
25
  'aria-invalid'?: boolean;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  // A multi-choice picker: selected options as removable chips, the rest in a
3
3
  // filterable dropdown. The one control for every "multi choice" field
4
4
  // (conventions/docs/entity-plan-template.md) — on a form (Widget Tags) and as a table
@@ -11,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  // typed-text match all use the label, and the value is what's emitted.
12
12
  import * as React from 'react';
13
13
  import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxValue, useComboboxAnchor, } from '../ui/combobox.js';
14
- export function MultiChoice({ options, value, onValueChange, getLabel = String, id, placeholder, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }) {
14
+ export function MultiChoice({ options, value, onValueChange, getLabel = String, id, placeholder, label, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }) {
15
15
  const anchor = useComboboxAnchor();
16
16
  return (_jsxs(Combobox, { multiple: true, autoHighlight: true, items: options, value: value, onValueChange: (next, details) => {
17
17
  // Base UI empties the value on Escape while the list is closed, so
@@ -25,5 +25,5 @@ export function MultiChoice({ options, value, onValueChange, getLabel = String,
25
25
  return;
26
26
  }
27
27
  onValueChange(next);
28
- }, itemToStringLabel: getLabel, children: [_jsx(ComboboxChips, { ref: anchor, className: className, children: _jsx(ComboboxValue, { children: (selected) => (_jsxs(React.Fragment, { children: [selected.map((option) => (_jsx(ComboboxChip, { children: getLabel(option) }, option))), _jsx(ComboboxChipsInput, { id: id, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, placeholder: selected.length === 0 ? placeholder : undefined })] })) }) }), _jsxs(ComboboxContent, { anchor: anchor, children: [_jsx(ComboboxEmpty, { children: "No options found." }), _jsx(ComboboxList, { children: (option) => (_jsx(ComboboxItem, { value: option, children: getLabel(option) }, option)) })] })] }));
28
+ }, itemToStringLabel: getLabel, children: [_jsx(ComboboxChips, { ref: anchor, className: className, children: _jsx(ComboboxValue, { children: (selected) => (_jsxs(React.Fragment, { children: [label !== undefined && selected.length > 0 ? (_jsxs("span", { "data-slot": "multi-choice-summary", className: "min-w-0 truncate pl-1 type-body text-foreground", children: [label, ": ", getLabel(selected[0]), selected.length > 1 && _jsxs("span", { className: "text-muted-foreground", children: [" +", selected.length - 1] })] })) : null, (label === undefined ? selected : []).map((option) => (_jsx(ComboboxChip, { children: getLabel(option) }, option))), _jsx(ComboboxChipsInput, { id: id, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, placeholder: selected.length === 0 ? placeholder : undefined })] })) }) }), _jsxs(ComboboxContent, { anchor: anchor, children: [_jsx(ComboboxEmpty, { children: "No options found." }), _jsx(ComboboxList, { children: (option) => (_jsx(ComboboxItem, { value: option, children: getLabel(option) }, option)) })] })] }));
29
29
  }
@@ -11,5 +11,7 @@ export type PillFilterProps = {
11
11
  onValueChange: (value: string) => void;
12
12
  /** The first pill, which clears the filter. null leaves it out, for a filter that always has a value. */
13
13
  allLabel?: string | null;
14
+ /** On the group: `flex-nowrap` (with a scrolling parent) keeps the pills on one line. */
15
+ className?: string;
14
16
  };
15
- export declare function PillFilter({ label, options, value, onValueChange, allLabel }: PillFilterProps): import("react").JSX.Element;
17
+ export declare function PillFilter({ label, options, value, onValueChange, allLabel, className }: PillFilterProps): import("react").JSX.Element;
@@ -10,6 +10,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
10
10
  // with `setFilter`. Built on shadcn's ToggleGroup (Base UI): a group named
11
11
  // by `label`, one tab stop, the arrow keys along it, each pill a toggle
12
12
  // button with aria-pressed.
13
+ import { cn } from 'cn';
13
14
  import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
14
15
  // The All pill's value inside the group: Base UI's toggles need one that
15
16
  // isn't empty, and '' is what the app's filter calls All.
@@ -18,10 +19,10 @@ const ALL = '__all__';
18
19
  // (bg-muted) is ~3% off the page, too faint to say which one is on.
19
20
  const PILL_CLASS = 'rounded-full px-3 aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground ' +
20
21
  'aria-pressed:hover:bg-primary/90 aria-pressed:hover:text-primary-foreground';
21
- export function PillFilter({ label, options, value, onValueChange, allLabel = 'All' }) {
22
+ export function PillFilter({ label, options, value, onValueChange, allLabel = 'All', className }) {
22
23
  const pills = allLabel === null ? options : [{ value: ALL, label: allLabel }, ...options];
23
24
  const pressed = value === '' && allLabel !== null ? ALL : value;
24
- return (_jsx(ToggleGroup, { "aria-label": label, variant: "outline", size: "sm", spacing: 1, className: "flex-wrap", value: [pressed], onValueChange: (next) => {
25
+ return (_jsx(ToggleGroup, { "aria-label": label, variant: "outline", size: "sm", spacing: 1, className: cn('flex-wrap', className), value: [pressed], onValueChange: (next) => {
25
26
  // [] is the pressed pill pressed again: it stays on.
26
27
  const chosen = next[0];
27
28
  if (chosen === undefined || chosen === pressed)
@@ -0,0 +1,11 @@
1
+ import { type DataTableOpens, type DataTableProps } from './data-table.js';
2
+ import type { DataTableViewAll } from './data-table-tools.js';
3
+ export type RelatedTableProps<TData extends Record<string, unknown>> = Pick<DataTableProps<TData>, 'columns' | 'data' | 'total' | 'isLoading' | 'error' | 'onRetry' | 'emptyTitle' | 'emptyDescription' | 'emptyAction' | 'getRowId' | 'visibleColumns' | 'highlightRow' | 'rowActions' | 'phoneRow' | 'onRowClick' | 'width'> & {
4
+ /** How a row opens its record, as on every list. */
5
+ opens: DataTableOpens<TData>;
6
+ /** The most rows shown: 10 unless set. */
7
+ limit?: number;
8
+ /** The whole list, filtered to this record: shown when `total` is over `limit`. */
9
+ viewAll?: DataTableViewAll;
10
+ };
11
+ export declare function RelatedTable<TData extends Record<string, unknown>>({ columns, limit, ...props }: RelatedTableProps<TData>): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // A record's list of related records (the record page standard, R8): the
3
+ // ten newest under a section's heading, then View all N to the whole list
4
+ // filtered to this record, so a long care log doesn't push the rest of the
5
+ // record away. A DataTable with `limit` and `viewAll` and nothing to page or
6
+ // sort: the app's query asks for `limit` rows, newest first, and the total.
7
+ //
8
+ // <RelatedTable
9
+ // columns={VISIT_COLUMNS}
10
+ // opens={{ kind: 'dialog', to: (visit) => `/health/visits/${visit.id}` }}
11
+ // data={visits.data?.items ?? []}
12
+ // total={visits.data?.total ?? 0}
13
+ // isLoading={visits.isLoading}
14
+ // error={visits.error}
15
+ // onRetry={() => visits.refetch()}
16
+ // emptyTitle="No visits yet"
17
+ // viewAll={{ to: `/health/visits?provider=${provider.id}` }}
18
+ // />
19
+ import { useMemo } from 'react';
20
+ import { DataTable } from './data-table.js';
21
+ const noop = () => { };
22
+ const NO_SORT = [];
23
+ export function RelatedTable({ columns, limit = 10, ...props }) {
24
+ // The headers aren't sort buttons: the newest come first, and View all
25
+ // has the list's own sorting.
26
+ const unsorted = useMemo(() => columns.map((column) => ({ ...column, enableSorting: false })), [columns]);
27
+ return (_jsx(DataTable, { ...props, columns: unsorted, limit: limit, page: 1, pageSize: limit, onPageChange: noop, sorting: NO_SORT, onSortingChange: noop }));
28
+ }
@@ -14,5 +14,7 @@ export type SecondaryFiltersProps = {
14
14
  onClear: () => void;
15
15
  /** The button's text. */
16
16
  label?: string;
17
+ /** On the wrapper of the button and the chips (`contents`, to put them in a row of the parent's). */
18
+ className?: string;
17
19
  };
18
- export declare function SecondaryFilters({ children, active, onClear, label }: SecondaryFiltersProps): import("react").JSX.Element;
20
+ export declare function SecondaryFilters({ children, active, onClear, label, className }: SecondaryFiltersProps): import("react").JSX.Element;
@@ -18,15 +18,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
18
18
  // their Esc); the next one closes the panel.
19
19
  import { useState } from 'react';
20
20
  import { SlidersHorizontalIcon, XIcon } from 'lucide-react';
21
+ import { cn } from 'cn';
21
22
  import { Button } from '../ui/button.js';
22
23
  import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '../ui/popover.js';
23
24
  import { Sheet, SheetContent, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from '../ui/sheet.js';
24
- import { useIsMobile } from '../../hooks/use-mobile.js';
25
- export function SecondaryFilters({ children, active, onClear, label = 'Filters' }) {
26
- const isMobile = useIsMobile();
25
+ import { useIsPhone } from '../../hooks/use-is-phone.js';
26
+ export function SecondaryFilters({ children, active, onClear, label = 'Filters', className }) {
27
+ const isMobile = useIsPhone();
27
28
  const [open, setOpen] = useState(false);
28
29
  const count = active.length;
29
30
  const trigger = (_jsxs(Button, { variant: "outline", children: [_jsx(SlidersHorizontalIcon, { "aria-hidden": "true" }), _jsxs("span", { children: [label, count > 0 && _jsx("span", { className: "text-[0px]", children: "," })] }), count > 0 && (_jsxs(_Fragment, { children: [_jsx("span", { className: "rounded-full bg-primary px-1.5 type-caption text-primary-foreground tabular-nums", children: count }), _jsx("span", { className: "sr-only", children: " active" })] }))] }));
30
31
  const footer = (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { variant: "ghost", size: "sm", disabled: count === 0, onClick: onClear, children: "Clear filters" }), _jsx(Button, { size: "sm", onClick: () => setOpen(false), children: "Done" })] }));
31
- return (_jsxs("div", { "data-slot": "secondary-filters", className: "flex flex-wrap items-center gap-2", children: [isMobile ? (_jsxs(Sheet, { open: open, onOpenChange: setOpen, children: [_jsx(SheetTrigger, { render: trigger }), _jsxs(SheetContent, { side: "bottom", className: "max-h-[85svh] overflow-y-auto", children: [_jsx(SheetHeader, { children: _jsx(SheetTitle, { children: label }) }), _jsx("div", { className: "flex flex-col gap-3 px-4 [&>*]:w-full", children: children }), _jsx(SheetFooter, { children: footer })] })] })) : (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { render: trigger }), _jsxs(PopoverContent, { align: "start", className: "w-auto min-w-64 gap-3 p-3", children: [_jsx(PopoverTitle, { children: label }), _jsx("div", { className: "flex flex-col gap-3", children: children }), footer] })] })), active.map((filter) => (_jsxs("span", { "data-slot": "secondary-filter-chip", className: "inline-flex h-7 items-center gap-0.5 rounded-md bg-muted pr-0.5 pl-2 type-caption text-foreground", children: [filter.label, _jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Remove filter: ${filter.label}`, onClick: filter.onRemove, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }, filter.id))), count > 1 && (_jsx(Button, { variant: "ghost", size: "sm", onClick: onClear, children: "Clear filters" }))] }));
32
+ return (_jsxs("div", { "data-slot": "secondary-filters", className: cn('flex flex-wrap items-center gap-2', className), children: [isMobile ? (_jsxs(Sheet, { open: open, onOpenChange: setOpen, children: [_jsx(SheetTrigger, { render: trigger }), _jsxs(SheetContent, { side: "bottom", className: "max-h-[85svh] overflow-y-auto", children: [_jsx(SheetHeader, { children: _jsx(SheetTitle, { children: label }) }), _jsx("div", { className: "flex flex-col gap-3 px-4 [&>*]:w-full", children: children }), _jsx(SheetFooter, { children: footer })] })] })) : (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { render: trigger }), _jsxs(PopoverContent, { align: "start", className: "w-auto min-w-64 gap-3 p-3", children: [_jsx(PopoverTitle, { children: label }), _jsx("div", { className: "flex flex-col gap-3", children: children }), footer] })] })), active.map((filter) => (_jsxs("span", { "data-slot": "secondary-filter-chip", className: "inline-flex h-7 items-center gap-0.5 rounded-md bg-muted pr-0.5 pl-2 type-caption text-foreground", children: [filter.label, _jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Remove filter: ${filter.label}`, onClick: filter.onRemove, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }, filter.id))), count > 1 && (_jsx(Button, { variant: "ghost", size: "sm", onClick: onClear, children: "Clear filters" }))] }));
32
33
  }
@@ -0,0 +1,15 @@
1
+ export declare const ROW_ACTIONS_COLUMN_ID = "__row-actions";
2
+ export type ColumnsPick = {
3
+ order: string[];
4
+ hidden: string[];
5
+ };
6
+ /** The stored pick, or null when there's none or it can't be read. */
7
+ export declare function parseColumnsPick(raw: string | null): ColumnsPick | null;
8
+ /** The ids to show under `pick`: every column of `ids` it doesn't hide, in `ids`' order, `fixed` always. */
9
+ export declare function visibleFromPick(ids: readonly string[], pick: ColumnsPick, fixed: readonly string[]): string[];
10
+ /**
11
+ * The pick after `id` is ticked (`shown`) or unticked, starting from what
12
+ * shows now (`visible`): every column in `ids` is in `order`, the ones not
13
+ * showing in `hidden`.
14
+ */
15
+ export declare function togglePick(ids: readonly string[], visible: readonly string[], id: string, shown: boolean, previous: ColumnsPick | null): ColumnsPick;
@@ -0,0 +1,50 @@
1
+ // The Columns menu's pick (DataTable `columnsMenu`), kept free of React so
2
+ // tests/ can unit-test it. It's stored on this device per list as JSON:
3
+ // every column's id in order, and the ones unticked:
4
+ //
5
+ // {"order":["name","status","dose","since"],"hidden":["since"]}
6
+ //
7
+ // `order` is there for reordering, a later addition to the same value; for
8
+ // now it's written and kept, never applied. A column the list gained after
9
+ // the pick was stored isn't in `hidden`, so it shows.
10
+ // The id of the column DataTable adds for `rowActions`, pinned last: never
11
+ // in the Columns menu.
12
+ export const ROW_ACTIONS_COLUMN_ID = '__row-actions';
13
+ /** The stored pick, or null when there's none or it can't be read. */
14
+ export function parseColumnsPick(raw) {
15
+ if (raw === null)
16
+ return null;
17
+ try {
18
+ const value = JSON.parse(raw);
19
+ if (typeof value !== 'object' || value === null)
20
+ return null;
21
+ const { order, hidden } = value;
22
+ const strings = (list) => (Array.isArray(list) ? list.filter((id) => typeof id === 'string') : null);
23
+ const orderIds = strings(order);
24
+ const hiddenIds = strings(hidden);
25
+ return orderIds && hiddenIds ? { order: orderIds, hidden: hiddenIds } : null;
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
31
+ /** The ids to show under `pick`: every column of `ids` it doesn't hide, in `ids`' order, `fixed` always. */
32
+ export function visibleFromPick(ids, pick, fixed) {
33
+ const hidden = new Set(pick.hidden);
34
+ return ids.filter((id) => fixed.includes(id) || !hidden.has(id));
35
+ }
36
+ /**
37
+ * The pick after `id` is ticked (`shown`) or unticked, starting from what
38
+ * shows now (`visible`): every column in `ids` is in `order`, the ones not
39
+ * showing in `hidden`.
40
+ */
41
+ export function togglePick(ids, visible, id, shown, previous) {
42
+ const next = new Set(visible);
43
+ if (shown)
44
+ next.add(id);
45
+ else
46
+ next.delete(id);
47
+ // Keep an order already stored (reordering, later), with new columns after.
48
+ const order = previous ? [...previous.order.filter((each) => ids.includes(each)), ...ids.filter((each) => !previous.order.includes(each))] : [...ids];
49
+ return { order, hidden: ids.filter((each) => !next.has(each)) };
50
+ }
@@ -4,6 +4,8 @@ type Sort = readonly {
4
4
  }[];
5
5
  export type UrlChanges = Record<string, string | string[] | null>;
6
6
  export type TableView<F extends string, M extends string> = {
7
+ /** Its pill's word in DataTable's `views` ("Current"); the view's id unless set. */
8
+ label?: string;
7
9
  filters?: Partial<Record<F, string>>;
8
10
  multiFilters?: Partial<Record<M, string[]>>;
9
11
  sort?: Sort;
@@ -0,0 +1,3 @@
1
+ import { type ColumnsPick } from '../components/app/table-columns.js';
2
+ /** The pick stored under `key`, read and written through the device's store. */
3
+ export declare function useColumnsPick(key: string | undefined): readonly [ColumnsPick | null, (next: ColumnsPick | null) => void];
@@ -0,0 +1,18 @@
1
+ // DataTable's Columns menu pick (`columnsMenu`), remembered on this device
2
+ // under the list's `storageKey` in the same store as a table's layout and
3
+ // grouping (use-table-layout.ts). The format is table-columns.ts's.
4
+ import { useCallback, useSyncExternalStore } from 'react';
5
+ import { parseColumnsPick } from '../components/app/table-columns.js';
6
+ import { browserStore } from './use-table-layout.js';
7
+ /** The pick stored under `key`, read and written through the device's store. */
8
+ export function useColumnsPick(key) {
9
+ const subscribe = useCallback((listener) => (key === undefined ? () => { } : browserStore.subscribe(key, listener)), [key]);
10
+ const raw = useSyncExternalStore(subscribe, () => (key === undefined ? null : browserStore.get(key)), () => null);
11
+ const pick = parseColumnsPick(raw);
12
+ const setPick = (next) => {
13
+ if (key === undefined)
14
+ return;
15
+ browserStore.set(key, next === null ? '' : JSON.stringify(next));
16
+ };
17
+ return [pick, setPick];
18
+ }
@@ -0,0 +1 @@
1
+ export declare function useIsPhone(): boolean;
@@ -0,0 +1,18 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ // Whether the screen is under 48rem (useIsMobile's 768px), read through
3
+ // matchMedia as a store, so rendering on the server or where matchMedia is
4
+ // missing (a test's DOM) gives "not a phone" instead of failing on
5
+ // `window`. DataTable's row list, FilterBar and SecondaryFilters' sheet
6
+ // read it, so they always agree.
7
+ const PHONE_QUERY = '(max-width: 767px)';
8
+ const canMatchMedia = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function';
9
+ function subscribe(listener) {
10
+ if (!canMatchMedia())
11
+ return () => { };
12
+ const query = window.matchMedia(PHONE_QUERY);
13
+ query.addEventListener('change', listener);
14
+ return () => query.removeEventListener('change', listener);
15
+ }
16
+ export function useIsPhone() {
17
+ return useSyncExternalStore(subscribe, () => canMatchMedia() && window.matchMedia(PHONE_QUERY).matches, () => false);
18
+ }
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export { ColorSwatch, type ColorSwatchProps } from './components/app/color-swatc
10
10
  export { storedColor } from './lib/stored-color.js';
11
11
  export { CountLink, type CountLinkProps } from './components/app/count-link.js';
12
12
  export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
13
+ export { type DataTableColumnsMenu, type DataTablePhoneRow, type DataTableRowAction, type DataTableView, type DataTableViewAll, } from './components/app/data-table-tools.js';
14
+ export { RelatedTable, type RelatedTableProps } from './components/app/related-table.js';
13
15
  export { type RowGroup } from './components/app/table-groups.js';
14
16
  export { byDay, type ByDayOptions } from './lib/group-by-day.js';
15
17
  export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
@@ -49,6 +51,7 @@ export { RichTextEditor, type RichTextEditorProps } from './components/app/rich-
49
51
  export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
50
52
  export { PillFilter, type PillFilterOption, type PillFilterProps } from './components/app/pill-filter.js';
51
53
  export { SecondaryFilters, type ActiveFilter, type SecondaryFiltersProps } from './components/app/secondary-filters.js';
54
+ export { FilterBar, FilterSelect, type FilterBarProps, type FilterBarSearch, type FilterSelectOption, type FilterSelectProps, } from './components/app/filter-bar.js';
52
55
  export { SessionStage, SessionView, sessionStageLit, sessionStageMain, sessionStageQuiet, type SessionStageProps, type SessionStageTone, type SessionViewProps, } from './components/app/session-view.js';
53
56
  export { AllowReminders, type AllowRemindersProps } from './components/app/allow-reminders.js';
54
57
  export { StageCircle, type StageCircleProps, type StageCircleStage, type StageCircleTone, } from './components/app/stage-circle.js';
package/dist/index.js CHANGED
@@ -14,6 +14,8 @@ export { ColorSwatch } from './components/app/color-swatch.js';
14
14
  export { storedColor } from './lib/stored-color.js';
15
15
  export { CountLink } from './components/app/count-link.js';
16
16
  export { DataTable, } from './components/app/data-table.js';
17
+ export {} from './components/app/data-table-tools.js';
18
+ export { RelatedTable } from './components/app/related-table.js';
17
19
  export {} from './components/app/table-groups.js';
18
20
  export { byDay } from './lib/group-by-day.js';
19
21
  export { EntityForm } from './components/app/entity-form.js';
@@ -51,6 +53,7 @@ export { RichTextEditor } from './components/app/rich-text-editor.js';
51
53
  export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
52
54
  export { PillFilter } from './components/app/pill-filter.js';
53
55
  export { SecondaryFilters } from './components/app/secondary-filters.js';
56
+ export { FilterBar, FilterSelect, } from './components/app/filter-bar.js';
54
57
  export { SessionStage, SessionView, sessionStageLit, sessionStageMain, sessionStageQuiet, } from './components/app/session-view.js';
55
58
  export { AllowReminders } from './components/app/allow-reminders.js';
56
59
  export { StageCircle, } from './components/app/stage-circle.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.85.0",
3
+ "version": "4.86.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": {