@tristan2828/ui-foundation 4.84.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 +1 -1
- package/conventions/docs/add-an-entity.md +72 -24
- package/conventions/docs/cell-patterns.md +165 -37
- package/conventions/docs/design-language.md +24 -17
- package/dist/components/app/data-table-tools.d.ts +98 -0
- package/dist/components/app/data-table-tools.js +59 -0
- package/dist/components/app/data-table.d.ts +60 -2
- package/dist/components/app/data-table.js +97 -20
- package/dist/components/app/entity-form.d.ts +27 -3
- package/dist/components/app/entity-form.js +124 -3
- package/dist/components/app/filter-bar.d.ts +55 -0
- package/dist/components/app/filter-bar.js +28 -0
- package/dist/components/app/form-dialog.js +16 -4
- package/dist/components/app/form-leave-guard.d.ts +4 -0
- package/dist/components/app/form-leave-guard.js +42 -0
- package/dist/components/app/form-section.d.ts +9 -0
- package/dist/components/app/form-section.js +15 -0
- package/dist/components/app/multi-choice.d.ts +9 -1
- package/dist/components/app/multi-choice.js +3 -3
- package/dist/components/app/option-select.d.ts +30 -0
- package/dist/components/app/option-select.js +21 -0
- package/dist/components/app/pill-filter.d.ts +3 -1
- package/dist/components/app/pill-filter.js +3 -2
- package/dist/components/app/related-table.d.ts +11 -0
- package/dist/components/app/related-table.js +28 -0
- package/dist/components/app/secondary-filters.d.ts +3 -1
- package/dist/components/app/secondary-filters.js +5 -4
- package/dist/components/app/table-columns.d.ts +15 -0
- package/dist/components/app/table-columns.js +50 -0
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/combobox.js +1 -1
- package/dist/components/ui/field.d.ts +28 -3
- package/dist/components/ui/field.js +116 -8
- package/dist/components/ui/input-group.js +1 -1
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/select.js +1 -1
- package/dist/hooks/table-url-changes.d.ts +2 -0
- package/dist/hooks/use-columns-pick.d.ts +3 -0
- package/dist/hooks/use-columns-pick.js +18 -0
- package/dist/hooks/use-is-phone.d.ts +1 -0
- package/dist/hooks/use-is-phone.js +18 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/lib/field-rows.d.ts +18 -0
- package/dist/lib/field-rows.js +53 -0
- package/dist/lib/form-errors.d.ts +6 -0
- package/dist/lib/form-errors.js +19 -0
- package/package.json +1 -1
- package/styles/index.css +60 -0
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`. 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` |
|
|
@@ -3,27 +3,28 @@
|
|
|
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 reference files](#the-reference-files) · lines
|
|
7
|
-
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines
|
|
8
|
-
- Step 1: Add `<Entity>` to `openapi.yaml` · lines
|
|
9
|
-
- Step 2: `npm run gen:api` · lines
|
|
10
|
-
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines
|
|
11
|
-
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines
|
|
12
|
-
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines
|
|
13
|
-
- Step 6: Copy the reference files, one for one, not just the two screens · lines
|
|
14
|
-
- Step 7: Register routes · lines
|
|
15
|
-
- Step 8: Add Playwright specs for all three screens · lines
|
|
16
|
-
- Step 9: Register the nav entry and route names · lines
|
|
17
|
-
- Step 10: `npm run verify`. · lines
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines
|
|
19
|
-
- [The record view](#the-record-view) · lines
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
6
|
+
- [The reference files](#the-reference-files) · lines 43–65
|
|
7
|
+
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 67–812
|
|
8
|
+
- Step 1: Add `<Entity>` to `openapi.yaml` · lines 109–116
|
|
9
|
+
- Step 2: `npm run gen:api` · lines 117–118
|
|
10
|
+
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 119–130
|
|
11
|
+
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 131–140
|
|
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–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
|
|
27
28
|
|
|
28
29
|
<!-- /index -->
|
|
29
30
|
|
|
@@ -376,7 +377,10 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
376
377
|
`<SecondaryFilters>`, as the template does with Extra Categories,
|
|
377
378
|
Progress and In Stock. Pass it each filter that's on as an
|
|
378
379
|
`ActiveFilter` (its chip text and how to take it off) and an
|
|
379
|
-
`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).
|
|
380
384
|
- `src/routes/widgets/widget-view.tsx` →
|
|
381
385
|
`src/routes/<entity>/<entity>-view.tsx` — thin consumer of the
|
|
382
386
|
foundation's `<EntityView>`. Swap the title, badges and sections for
|
|
@@ -403,8 +407,9 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
403
407
|
- `src/routes/widgets/widget-form.tsx` →
|
|
404
408
|
`src/routes/<entity>/<entity>-form.tsx` — thin consumer of the
|
|
405
409
|
foundation's `<EntityForm>` (its `danger` slot takes an edit-only
|
|
406
|
-
delete). Swap the zod schema and fields
|
|
407
|
-
|
|
410
|
+
delete). Swap the zod schema and fields, each `Field` with its
|
|
411
|
+
`size` and the required ones' `<FieldLabel required>` ("Forms"
|
|
412
|
+
below). Every way out lands on a view (below).
|
|
408
413
|
|
|
409
414
|
**The view** is the read-only page for one record, at `/<entity>/:id`
|
|
410
415
|
(apart from the plan's quick actions and fields edited in place, if it
|
|
@@ -996,6 +1001,49 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
996
1001
|
Edit and its form page stay only for a field the view can't edit in
|
|
997
1002
|
place yet; the plan says which, and the gap is raised for the package.
|
|
998
1003
|
|
|
1004
|
+
### Forms
|
|
1005
|
+
|
|
1006
|
+
Every create and edit form is an `EntityForm` (a page) or a `FormDialog`
|
|
1007
|
+
(up to about eight fields, over its list), and every one has the same
|
|
1008
|
+
shape (4.85):
|
|
1009
|
+
|
|
1010
|
+
- **One column, short fields sharing a row.** Give each `Field` its
|
|
1011
|
+
`size` and the form lays the rows out itself, from the order: `s` a
|
|
1012
|
+
number or a short code, `m` a date, a status, a choice of two to four
|
|
1013
|
+
or a rating, `l` a name or a pick of a record, and no `size` (`full`)
|
|
1014
|
+
for long text, a list or anything that needs the row. Consecutive short
|
|
1015
|
+
fields share a row, up to three, as wide as their sizes; a long one
|
|
1016
|
+
takes one short partner (Series and Number). `<Field solo>` keeps a
|
|
1017
|
+
short one alone where a pairing would read wrong. Under 48rem every
|
|
1018
|
+
field takes its own row but two dates or two numbers (a date picker of
|
|
1019
|
+
your own says so with `kind="date"`). Never a hand-made
|
|
1020
|
+
`sm:grid-cols-2` row.
|
|
1021
|
+
- **Order:** required first, the status next, long text last.
|
|
1022
|
+
- **Required:** `<FieldLabel required>` (an asterisk, and `aria-required`
|
|
1023
|
+
on the control it names). Nothing on an optional field: never
|
|
1024
|
+
"(optional)".
|
|
1025
|
+
- **Labels** above the box, sentence case ("My rating"). Help text
|
|
1026
|
+
(`FieldDescription`) only where the label can't say it, one short line.
|
|
1027
|
+
A placeholder only for a format the box needs (`https://`), never an
|
|
1028
|
+
example that looks like a value.
|
|
1029
|
+
- **Messages say what to do**, in the app's voice: "Give it a title",
|
|
1030
|
+
"Enter a full address, starting https://", never "Title is required".
|
|
1031
|
+
- **A status** is an `OptionSelect` with the same `render` (its badge) as
|
|
1032
|
+
its cell and the record: `inPlace.select`'s `{ value, label }` options.
|
|
1033
|
+
- **Cards** (`<FormSection title>`) only on a form of eight fields or
|
|
1034
|
+
more, never in a dialog; a short form is one run of fields. Sub-record
|
|
1035
|
+
editors (`ListEditor`) sit in a card of their own.
|
|
1036
|
+
- **Pass `dirty={formState.isDirty}` and `errors={formState.errors}`.**
|
|
1037
|
+
With `dirty`, leaving (a link, Back, the sidebar, Cancel) asks "Discard
|
|
1038
|
+
your changes?" first and a reload asks the browser; navigating while
|
|
1039
|
+
`isSubmitting` (the save's own move to the record) doesn't. With
|
|
1040
|
+
`errors`, a refused Add moves to the first problem and the bar says
|
|
1041
|
+
"2 to fix". Both come free; the form draws a failed save as a `Notice`
|
|
1042
|
+
with Try again in its bar, which sticks to the window's bottom on a long
|
|
1043
|
+
form.
|
|
1044
|
+
- **The words:** "New book", "Add book" (the word Add on every create
|
|
1045
|
+
form), and the toast after it "Added The Long Walk".
|
|
1046
|
+
|
|
999
1047
|
### Dialogs
|
|
1000
1048
|
|
|
1001
1049
|
Every dialog is one of three widths, `DialogContent`'s `size` (4.82):
|
|
@@ -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
|
|
7
|
-
- [1. Plain text](#1-plain-text) · lines
|
|
8
|
-
- [2. Icon + label](#2-icon--label) · lines
|
|
9
|
-
- [3. Icon in a badge](#3-icon-in-a-badge) · lines
|
|
10
|
-
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines
|
|
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
|
|
12
|
-
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines
|
|
13
|
-
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines
|
|
14
|
-
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines
|
|
15
|
-
- [8. Date, relative](#8-date-relative) · lines
|
|
16
|
-
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines
|
|
17
|
-
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines
|
|
18
|
-
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines
|
|
19
|
-
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines
|
|
20
|
-
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines
|
|
21
|
-
- [12. Boolean](#12-boolean) · lines
|
|
22
|
-
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines
|
|
23
|
-
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines
|
|
24
|
-
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines
|
|
25
|
-
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines
|
|
26
|
-
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines
|
|
27
|
-
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines
|
|
28
|
-
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines
|
|
30
|
-
- [Presets: one line per field](#presets-one-line-per-field) · lines
|
|
31
|
-
- [Several fields edited as one](#several-fields-edited-as-one) · lines
|
|
32
|
-
- [A link and its label](#a-link-and-its-label) · lines
|
|
33
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
34
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
35
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
36
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
37
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
38
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
39
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
40
|
-
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines
|
|
41
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
42
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
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.
|
|
@@ -17,23 +17,23 @@
|
|
|
17
17
|
- [Shapes and sizes](#shapes-and-sizes) · lines 541–562
|
|
18
18
|
- [Typography](#typography) · lines 564–684
|
|
19
19
|
- [Written text (notes)](#written-text-notes) · lines 598–684
|
|
20
|
-
- [Density](#density) · lines 686–
|
|
21
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
22
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
23
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
24
|
-
- [Notices](#notices) · lines
|
|
25
|
-
- [A value over time](#a-value-over-time) · lines
|
|
26
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
27
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
28
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
29
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
30
|
-
- [Parts of the page standards](#parts-of-the-page-standards) · lines
|
|
31
|
-
- [A record's header and empty values](#a-records-header-and-empty-values) · lines
|
|
32
|
-
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines
|
|
33
|
-
- [Picking at random](#picking-at-random) · lines
|
|
34
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
35
|
-
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines
|
|
36
|
-
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines
|
|
20
|
+
- [Density](#density) · lines 686–779
|
|
21
|
+
- [Rows on this device](#rows-on-this-device) · lines 752–779
|
|
22
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 781–895
|
|
23
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 897–974
|
|
24
|
+
- [Notices](#notices) · lines 976–1004
|
|
25
|
+
- [A value over time](#a-value-over-time) · lines 1006–1092
|
|
26
|
+
- [Several values over time](#several-values-over-time) · lines 1055–1092
|
|
27
|
+
- [A list as a board](#a-list-as-a-board) · lines 1094–1145
|
|
28
|
+
- [A list as cards](#a-list-as-cards) · lines 1147–1193
|
|
29
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1195–1224
|
|
30
|
+
- [Parts of the page standards](#parts-of-the-page-standards) · lines 1226–1269
|
|
31
|
+
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1270–1308
|
|
32
|
+
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1310–1355
|
|
33
|
+
- [Picking at random](#picking-at-random) · lines 1357–1388
|
|
34
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1390–1457
|
|
35
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1459–1484
|
|
36
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1486–1532
|
|
37
37
|
|
|
38
38
|
<!-- /index -->
|
|
39
39
|
|
|
@@ -704,6 +704,13 @@ set, not a `DataTable` prop:
|
|
|
704
704
|
|
|
705
705
|
- `compact` and `comfortable` change padding only. Text keeps
|
|
706
706
|
`type-body`, so compact never drops below a readable size.
|
|
707
|
+
- **Forms are compact at every density but `large`** (4.85): inside a
|
|
708
|
+
`FieldGroup` (every `EntityForm`, `FormDialog` and `FormSection`) the
|
|
709
|
+
inputs, selects, combobox boxes and default buttons are 32px, the
|
|
710
|
+
compact table's row, with 14px between fields; under 48rem or on a
|
|
711
|
+
touch screen 40px, for the finger. They read `--control-height`, which
|
|
712
|
+
`FieldGroup` and the forms' bars set from `--spacing`, so `large` grows
|
|
713
|
+
them as it grows everything. Outside a form a control keeps its 36px.
|
|
707
714
|
- On a hub, `compact` takes a `WidgetCard`'s padding from 16px to 12px,
|
|
708
715
|
a `WidgetList` row from 36px to 32px (6px around its line) and a
|
|
709
716
|
`ModuleCard`'s band and body by 4px each. On a phone a compact row is
|
|
@@ -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
|
+
}
|