@tristan2828/ui-foundation 4.123.0 → 4.124.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,29 +4,29 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 45–67
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 69–855
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 69–859
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 111–118
9
9
  - Step 2: `npm run gen:api` · lines 119–120
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 121–132
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 133–142
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 143–149
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 150–743
14
- - Step 7: Register routes · lines 744–759
15
- - Step 8: Add Playwright specs for all three screens · lines 760–837
16
- - Step 9: Register the nav entry and route names · lines 838–852
17
- - Step 10: `npm run verify`. · lines 853–855
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 857–1326
19
- - [The record view](#the-record-view) · lines 1010–1167
20
- - [Forms](#forms) · lines 1169–1240
21
- - [Dialogs](#dialogs) · lines 1242–1273
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1275–1326
23
- - [What not to copy](#what-not-to-copy) · lines 1328–1361
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1363–1380
25
- - [Deleting](#deleting) · lines 1382–1413
26
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1415–1436
27
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1438–1447
28
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1450–1492
29
- - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1494–1530
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 150–747
14
+ - Step 7: Register routes · lines 748–763
15
+ - Step 8: Add Playwright specs for all three screens · lines 764–841
16
+ - Step 9: Register the nav entry and route names · lines 842–856
17
+ - Step 10: `npm run verify`. · lines 857–859
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 861–1330
19
+ - [The record view](#the-record-view) · lines 1014–1171
20
+ - [Forms](#forms) · lines 1173–1244
21
+ - [Dialogs](#dialogs) · lines 1246–1277
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1279–1330
23
+ - [What not to copy](#what-not-to-copy) · lines 1332–1365
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1367–1384
25
+ - [Deleting](#deleting) · lines 1386–1417
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1419–1440
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1442–1451
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1454–1496
29
+ - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1498–1534
30
30
 
31
31
  <!-- /index -->
32
32
 
@@ -606,7 +606,11 @@ is a filled-in example while the Widgets demo is still here).
606
606
  renames its tooltip and name) that prints the marked sections alone, under the title
607
607
  and subtitle: no rail, no shell, no buttons, light paper in either
608
608
  theme, headings and bullets as written, nothing folded, tables
609
- ruled with room in their empty cells. `print: { answerSpace: true }`
609
+ ruled with room in their empty cells. On a phone, whose print()
610
+ returns at once and fires `afterprint` before its preview exists, the
611
+ copy stays until the person next touches the page or presses a key
612
+ (4.124.1), so the preview prints the notes; the browser's own print
613
+ (Ctrl+P) in that gap prints them too. `print: { answerSpace: true }`
610
614
  also leaves space under each item of the section's numbered lists,
611
615
  for questions answered by hand. A section's own content that should
612
616
  print differently (a list of sub-items as plain text) reads
@@ -3,47 +3,48 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 75–98
7
- - [1. Plain text](#1-plain-text) · lines 100–155
8
- - [2. Icon + label](#2-icon--label) · lines 157–180
9
- - [3. Icon in a badge](#3-icon-in-a-badge) · lines 182–195
10
- - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 197–274
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 222–274
12
- - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 276–296
13
- - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 298–310
14
- - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 312–333
15
- - [8. Date, relative](#8-date-relative) · lines 335–372
16
- - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 374–433
17
- - [Three variants the package draws: a step bar, a star and a score](#three-variants-the-package-draws-a-step-bar-a-star-and-a-score) · lines 392–433
18
- - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 435–485
19
- - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 453–485
20
- - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 487–527
21
- - [12. Boolean](#12-boolean) · lines 529–559
22
- - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 561–597
23
- - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 581–597
24
- - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 599–616
25
- - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 618–727
26
- - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 644–727
27
- - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 729–775
28
- - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 777–850
29
- - [18. Editable value](#18-editable-value) · lines 852–1555
30
- - [Presets: one line per field](#presets-one-line-per-field) · lines 1187–1255
31
- - [Several fields edited as one](#several-fields-edited-as-one) · lines 1257–1293
32
- - [A link and its label](#a-link-and-its-label) · lines 1295–1319
33
- - [A list of sub-items](#a-list-of-sub-items) · lines 1321–1454
34
- - [In a table's rows](#in-a-tables-rows) · lines 1456–1541
35
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1543–1555
36
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1557–1623
37
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1625–1689
38
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1691–1789
39
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1791–1820
40
- - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1822–1860
41
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1862–1938
42
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1940–1963
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 1965–2190
44
- - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2119–2190
45
- - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2192–2228
46
- - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2230–2279
6
+ - [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 76–99
7
+ - [1. Plain text](#1-plain-text) · lines 101–156
8
+ - [2. Icon + label](#2-icon--label) · lines 158–181
9
+ - [3. Icon in a badge](#3-icon-in-a-badge) · lines 183–196
10
+ - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 198–275
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 223–275
12
+ - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 277–297
13
+ - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 299–311
14
+ - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 313–334
15
+ - [8. Date, relative](#8-date-relative) · lines 336–373
16
+ - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 375–434
17
+ - [Three variants the package draws: a step bar, a star and a score](#three-variants-the-package-draws-a-step-bar-a-star-and-a-score) · lines 393–434
18
+ - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 436–486
19
+ - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 454–486
20
+ - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 488–528
21
+ - [12. Boolean](#12-boolean) · lines 530–560
22
+ - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 562–598
23
+ - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 582–598
24
+ - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 600–617
25
+ - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 619–728
26
+ - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 645–728
27
+ - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 730–776
28
+ - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 778–851
29
+ - [18. Editable value](#18-editable-value) · lines 853–1556
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1188–1256
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1258–1294
32
+ - [A link and its label](#a-link-and-its-label) · lines 1296–1320
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1322–1455
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1457–1542
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1544–1556
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1558–1624
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1626–1690
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1692–1790
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1792–1821
40
+ - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1823–1861
41
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1863–1939
42
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1941–2027
43
+ - [Picking one on a form: `ColorField`](#picking-one-on-a-form-colorfield) · lines 1966–2027
44
+ - [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 2029–2254
45
+ - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2183–2254
46
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2256–2292
47
+ - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2294–2343
47
48
 
48
49
  <!-- /index -->
49
50
 
@@ -1962,6 +1963,69 @@ import { ColorSwatch } from '@tristan2828/ui-foundation'
1962
1963
  The package's fixture `app/ColorSwatch` "In a table" renders it; its
1963
1964
  checks measure the ring at 3:1 in both themes and every palette.
1964
1965
 
1966
+ ### Picking one on a form: `ColorField`
1967
+
1968
+ The same colour on the record's form (4.124): a grid of named swatches
1969
+ and **Custom**, which opens the browser's own colour picker. One control
1970
+ for a react-hook-form `Controller`, like `DateField`.
1971
+
1972
+ ```tsx
1973
+ import { ColorField, storedColor } from '@tristan2828/ui-foundation'
1974
+
1975
+ <Field data-invalid={!!errors.color || undefined}>
1976
+ <FieldLabel id="label-color-label" htmlFor="label-color">Colour</FieldLabel>
1977
+ <Controller
1978
+ control={form.control}
1979
+ name="color"
1980
+ rules={{ validate: (value) => !value || !!storedColor(value) || 'Pick a colour' }}
1981
+ render={({ field, fieldState }) => (
1982
+ <ColorField
1983
+ id="label-color"
1984
+ aria-labelledby="label-color-label"
1985
+ value={field.value}
1986
+ onChange={field.onChange}
1987
+ onBlur={field.onBlur}
1988
+ invalid={fieldState.invalid}
1989
+ />
1990
+ )}
1991
+ />
1992
+ <FieldError errors={[errors.color]} />
1993
+ </Field>
1994
+ ```
1995
+
1996
+ - **It's one radio group.** One tab stop; the arrow keys move and pick;
1997
+ Tab goes on to Custom's picker, then out. Each swatch's name is its
1998
+ radio's label, written beside it (the word carries it, as above). The
1999
+ picked one shows its radio's dot and a primary border, not only its
2000
+ colour.
2001
+ - **Name the group with `aria-labelledby`** (the `FieldLabel`'s `id`): a
2002
+ label's `htmlFor` can't name a group. Still pass `id` and `htmlFor`, so
2003
+ `<FieldLabel required>` marks the group `aria-required`.
2004
+ - **The value out is always `storedColor`'s form** (`#c0392b`). A value in
2005
+ is compared in full, so `C0392B` or `#FFF` still shows as its named
2006
+ colour. One that's none of the named colours (a hex typed in the old
2007
+ text box) shows **Custom** picked, its hex beside it, and stays as it
2008
+ is until someone picks. A value that isn't a colour shows nothing
2009
+ picked.
2010
+ - **Custom by pointer opens the picker; by keyboard it only picks**, and
2011
+ the picker is the next tab stop. Picking Custom keeps the current
2012
+ colour until a colour is chosen in the picker.
2013
+ - **The default set** is `COLOR_CHOICES`: twelve named hues at a middle
2014
+ lightness that read on a card in light, dark and every palette (3:1,
2015
+ 2.3:1 on Palm LCD's mid panel). An app with its own names passes
2016
+ `colors={[{ name: 'Hale Navy', color: '#434c56' }, ...]}`; each name is
2017
+ shown, so make them words a person would say.
2018
+ - **Replacing a text box and a swatch preview**: the stored values don't
2019
+ change. Swap the `Input` for `ColorField` in the same `Controller`;
2020
+ values already stored that aren't in the set show as Custom.
2021
+
2022
+ The package's fixture `app/ColorField` renders it on a card (a named
2023
+ colour, a Custom hex, a required one left empty, an app's own list, a
2024
+ refused value); its checks run axe, the token check, each swatch's ring
2025
+ and the picker's edge at 3:1, and each default fill against the card, in
2026
+ both themes and every palette. `e2e/color-field.spec.ts` drives the
2027
+ pointer, the keyboard and Custom.
2028
+
1965
2029
  ## 25. A list's tools: views, filters, columns, row actions, a phone's rows
1966
2030
 
1967
2031
  The rest of the list page standard (4.86): what sits above a list's rows,
@@ -14,30 +14,30 @@
14
14
  - [Categorical colour](#categorical-colour) · lines 370–440
15
15
  - [Heat scale](#heat-scale) · lines 442–503
16
16
  - [Depth ramps](#depth-ramps) · lines 505–590
17
- - [A stored colour](#a-stored-colour) · lines 592–640
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 642–663
19
- - [Typography](#typography) · lines 665–836
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 699–732
21
- - [Written text (notes)](#written-text-notes) · lines 734–836
22
- - [Density](#density) · lines 838–931
23
- - [Rows on this device](#rows-on-this-device) · lines 904–931
24
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 933–1047
25
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1049–1126
26
- - [Notices](#notices) · lines 1128–1156
27
- - [A value over time](#a-value-over-time) · lines 1158–1244
28
- - [Several values over time](#several-values-over-time) · lines 1207–1244
29
- - [A list as a board](#a-list-as-a-board) · lines 1246–1297
30
- - [A list as cards](#a-list-as-cards) · lines 1299–1345
31
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1347–1383
32
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1385–1455
33
- - [A few equal things](#a-few-equal-things) · lines 1457–1541
34
- - [An overview page](#an-overview-page) · lines 1543–1614
35
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1615–1678
36
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1680–1804
37
- - [Picking at random](#picking-at-random) · lines 1806–1837
38
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1839–1906
39
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1908–1933
40
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1935–2031
17
+ - [A stored colour](#a-stored-colour) · lines 592–649
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 651–672
19
+ - [Typography](#typography) · lines 674–845
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 708–741
21
+ - [Written text (notes)](#written-text-notes) · lines 743–845
22
+ - [Density](#density) · lines 847–940
23
+ - [Rows on this device](#rows-on-this-device) · lines 913–940
24
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 942–1056
25
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1058–1135
26
+ - [Notices](#notices) · lines 1137–1165
27
+ - [A value over time](#a-value-over-time) · lines 1167–1253
28
+ - [Several values over time](#several-values-over-time) · lines 1216–1253
29
+ - [A list as a board](#a-list-as-a-board) · lines 1255–1306
30
+ - [A list as cards](#a-list-as-cards) · lines 1308–1354
31
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1356–1392
32
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1394–1464
33
+ - [A few equal things](#a-few-equal-things) · lines 1466–1550
34
+ - [An overview page](#an-overview-page) · lines 1552–1623
35
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1624–1690
36
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1692–1816
37
+ - [Picking at random](#picking-at-random) · lines 1818–1849
38
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1851–1918
39
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1920–1945
40
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1947–2043
41
41
 
42
42
  <!-- /index -->
43
43
 
@@ -639,6 +639,15 @@ palette side by side), with axe, the token check and the ring's ratio
639
639
  measured in light, dark and every palette. Cell pattern 24 is it in a
640
640
  column.
641
641
 
642
+ **Picking one on a form is `ColorField`** (4.124): the same swatches,
643
+ each beside its name, as one radio group, and Custom for the browser's
644
+ own picker. Its default twelve (`COLOR_CHOICES`) sit at a middle
645
+ lightness, so each fill clears 3:1 against a card in light, dark and the
646
+ dark palettes, and 2.3:1 on Palm LCD, whose mid-light panel no middle
647
+ colour clears 3:1 on (the ring shows the edge there). The picked one is
648
+ marked by its radio's dot and a primary border, never by its colour
649
+ alone. Cell pattern 24 has its markup.
650
+
642
651
  ## Shapes and sizes
643
652
 
644
653
  The shared style guide's, the same in every app with or without a
@@ -1652,6 +1661,9 @@ data on each its own.
1652
1661
  the universal actions only (Delete, Print Notes, Copy link, Pin, Open
1653
1662
  site, Restore, Open Full Page, Close, More); everything else keeps its
1654
1663
  word. `printLook="words"` keeps Print Notes as a button with its words.
1664
+ Print Notes prints a hidden copy of the notes: a desktop browser takes it
1665
+ away when its dialog closes, a phone's (print() returns at once) when the
1666
+ person next touches the page (4.124.1).
1655
1667
  - **An empty value** reads as a dash (`emptyText`, default `'—'`), in the
1656
1668
  muted text tone, read by a screen reader as "Not set": the same on
1657
1669
  every field, the presets' included. A field's own `emptyLabel` still
@@ -0,0 +1,22 @@
1
+ import { type ColorChoice } from '../../lib/color-choices.js';
2
+ export type ColorFieldProps = {
3
+ /** The radio group's id, for the field's `<FieldLabel htmlFor>` (its `required` marks the group). */
4
+ id?: string;
5
+ /** The stored colour: a hex, with or without `#`, in 3, 4, 6 or 8 digits. Missing or invalid picks nothing. */
6
+ value: string | null | undefined;
7
+ /** Called with the picked colour in `storedColor`'s form (`#c0392b`). */
8
+ onChange: (value: string) => void;
9
+ /** Called when focus leaves the whole field (react-hook-form's `onBlur`). */
10
+ onBlur?: () => void;
11
+ /** The named colours offered, in order. Defaults to `COLOR_CHOICES`, twelve that read on a card everywhere. */
12
+ colors?: readonly ColorChoice[];
13
+ /** The value was refused: `aria-invalid` on the group and a destructive outline. */
14
+ invalid?: boolean;
15
+ disabled?: boolean;
16
+ className?: string;
17
+ /** Name the group: the FieldLabel's id (a label's `htmlFor` can't name a group). */
18
+ 'aria-labelledby'?: string;
19
+ 'aria-label'?: string;
20
+ 'aria-describedby'?: string;
21
+ };
22
+ export declare function ColorField({ id, value, onChange, onBlur, colors, invalid, disabled, className, ...aria }: ColorFieldProps): import("react").JSX.Element;
@@ -0,0 +1,84 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A stored colour on a form (a label's colour, a calendar's): a grid of
3
+ // named swatches and Custom, one radio group, for a react-hook-form
4
+ // `Controller` like DateField. The value is a hex string, always
5
+ // `storedColor`'s form (`#c0392b`), and the design language's "A stored
6
+ // colour" is the why of the swatches themselves (ColorSwatch).
7
+ //
8
+ // - One radio group (shadcn's RadioGroup on Base UI): one tab stop, the
9
+ // arrow keys move and pick, Space picks. Each choice is a radio with its
10
+ // ColorSwatch, and the swatch's name is the radio's label, written out:
11
+ // the colour is never the only way to tell. The picked one shows its
12
+ // radio's dot and a primary border, so it's marked by more than its
13
+ // colour; the focused one wears the focus ring.
14
+ // - Custom is the last choice. Clicking it opens the browser's own colour
15
+ // picker (`<input type="color">`, beside it, which is also a button of
16
+ // its own); reaching it by the keyboard only picks it, and Tab goes on to
17
+ // the picker. The chosen hex is written beside it.
18
+ // - A value that's none of the named colours (a hex typed elsewhere,
19
+ // uppercase or 3-digit included) shows Custom picked, with its hex.
20
+ // Colours compare in full (`#FFF` is `#ffffff`), so a named colour stored
21
+ // another way still shows as its name. A value that isn't a colour
22
+ // (missing, empty, a typo) shows nothing picked.
23
+ // - The swatch fills are data (ColorSwatch's inline style); everything
24
+ // around them is semantic tokens.
25
+ import { useRef, useState } from 'react';
26
+ import { cn } from 'cn';
27
+ import { RadioGroup, RadioGroupItem } from '../ui/radio-group.js';
28
+ import { choiceIndex, COLOR_CHOICES, pickerHex } from '../../lib/color-choices.js';
29
+ import { storedColor } from '../../lib/stored-color.js';
30
+ import { ColorSwatch } from './color-swatch.js';
31
+ const CUSTOM = 'custom';
32
+ // A choice's box: the radio and its swatch, a primary border when picked
33
+ // (the dot says it too), the focus ring on the one the keyboard is on.
34
+ const CHOICE = cn('flex h-(--control-height,--spacing(8)) min-w-0 cursor-pointer items-center gap-2 rounded-md border border-transparent px-2 type-body text-foreground', 'hover:bg-muted has-data-checked:border-primary has-data-checked:bg-primary/12', 'has-[:focus-visible]:border-ring has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/50', 'has-data-disabled:cursor-not-allowed has-data-disabled:opacity-50');
35
+ export function ColorField({ id, value, onChange, onBlur, colors = COLOR_CHOICES, invalid = false, disabled = false, className, ...aria }) {
36
+ const picker = useRef(null);
37
+ // Custom picked by the person while the value is still a named colour:
38
+ // it stays picked until they pick a named one.
39
+ const [customPicked, setCustomPicked] = useState(false);
40
+ const index = choiceIndex(value, colors);
41
+ const hex = storedColor(value);
42
+ const picked = customPicked || (index === -1 && hex) ? CUSTOM : index === -1 ? null : String(index);
43
+ const choose = (next) => {
44
+ if (next === CUSTOM) {
45
+ setCustomPicked(true);
46
+ return;
47
+ }
48
+ const choice = colors[Number(next)];
49
+ const color = storedColor(choice?.color);
50
+ if (!color)
51
+ return;
52
+ setCustomPicked(false);
53
+ if (color !== hex)
54
+ onChange(color);
55
+ };
56
+ // A pointer's click on Custom (its radio or its word) opens the picker;
57
+ // a label's forwarded click and the keyboard's (`detail` 0) don't.
58
+ const openPicker = (event) => {
59
+ if (disabled || event.detail === 0)
60
+ return;
61
+ const input = picker.current;
62
+ if (!input)
63
+ return;
64
+ try {
65
+ input.showPicker();
66
+ }
67
+ catch {
68
+ input.click();
69
+ }
70
+ };
71
+ const leave = (event) => {
72
+ if (!event.currentTarget.contains(event.relatedTarget))
73
+ onBlur?.();
74
+ };
75
+ return (_jsx("div", { "data-slot": "color-field", className: cn('min-w-0', className), onBlur: leave, children: _jsxs(RadioGroup, { id: id, value: picked, onValueChange: choose, disabled: disabled, "aria-invalid": invalid || undefined, className: cn('grid grid-cols-[repeat(auto-fill,minmax(7.5rem,1fr))] gap-1 rounded-md', invalid && 'ring-3 ring-destructive/20 dark:ring-destructive/40'), ...aria, children: [colors.map((choice, at) => (_jsxs("label", { "data-slot": "color-field-choice", className: CHOICE, children: [_jsx(RadioGroupItem, { value: String(at), "aria-invalid": invalid || undefined }), _jsx(ColorSwatch, { color: choice.color, label: choice.name })] }, `${choice.name}-${at}`))), _jsxs("div", { "data-slot": "color-field-custom", className: "col-span-full flex min-w-0 flex-wrap items-center gap-2", children: [_jsxs("label", { className: cn(CHOICE, 'w-fit'), onClick: openPicker, children: [_jsx(RadioGroupItem, { value: CUSTOM, "aria-invalid": invalid || undefined }), "Custom"] }), _jsx("input", { ref: picker, type: "color", "data-slot": "color-field-picker", "aria-label": "Custom colour", value: pickerHex(value), disabled: disabled, onChange: (event) => {
76
+ const color = storedColor(event.target.value);
77
+ if (!color)
78
+ return;
79
+ setCustomPicked(true);
80
+ onChange(color);
81
+ },
82
+ // The radio group's arrow keys are for its radios, not this button.
83
+ onKeyDown: (event) => event.stopPropagation(), className: cn('box-border size-(--control-height,--spacing(8)) shrink-0 cursor-pointer rounded-md border border-muted-foreground bg-transparent p-0.5 outline-none', 'focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50', '[&::-webkit-color-swatch-wrapper]:p-0 [&::-webkit-color-swatch]:rounded-sm [&::-webkit-color-swatch]:border-0 [&::-moz-color-swatch]:rounded-sm [&::-moz-color-swatch]:border-0') }), picked === CUSTOM && hex && (_jsx("span", { "data-slot": "color-field-hex", className: "type-body text-muted-foreground tabular-nums", children: hex }))] })] }) }));
84
+ }
@@ -13,8 +13,11 @@ export type EntityViewPrintSection = {
13
13
  };
14
14
  /**
15
15
  * The header's Print notes button and, while it prints, the printed copy.
16
- * The copy mounts, then the browser's print dialog opens on it; it goes
17
- * when the dialog closes (`afterprint`).
16
+ * The copy mounts, then the browser's print dialog opens on it. Where
17
+ * print() blocks (a desktop browser) it goes when the dialog closes
18
+ * (`afterprint`). Where print() returns at once (a phone) `afterprint`
19
+ * comes too early to mean anything, so the copy goes on the person's next
20
+ * pointerdown or key instead.
18
21
  */
19
22
  export declare function PrintNotes({ label, look, title, subtitle, sections, }: {
20
23
  label: string;
@@ -13,7 +13,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
13
13
  // write. A section marked `print: { answerSpace: true }` leaves space
14
14
  // under each item of its numbered lists, for questions answered by hand.
15
15
  //
16
- // The browser's own print (Ctrl+P) still prints the page as it is; only
16
+ // How long the copy stays depends on the browser. A desktop browser blocks
17
+ // in window.print() until the dialog closes, so `afterprint` ends it. A
18
+ // phone (Android Chrome, iOS Safari) returns from print() at once and
19
+ // fires `afterprint` before its preview is built, and a copy that went then
20
+ // would leave the preview to print the whole app page. So when print()
21
+ // returns in under a second, that early `afterprint` is ignored and the copy
22
+ // stays until the person next touches the page (a pointerdown or a key).
23
+ // Hidden on screen, it costs nothing to keep. The one visible side effect:
24
+ // the browser's own print (Ctrl+P) made before that touch prints the notes
25
+ // copy rather than the page. Otherwise Ctrl+P prints the page as it is; only
17
26
  // the button prints the notes alone.
18
27
  import { useEffect, useState } from 'react';
19
28
  import { createPortal } from 'react-dom';
@@ -30,23 +39,53 @@ function PrintedSection({ section }) {
30
39
  function PrintedNotes({ title, subtitle, sections }) {
31
40
  return createPortal(_jsx(PrintingContext.Provider, { value: true, children: _jsxs("article", { "data-print-notes": "", "data-slot": "entity-view-print", className: "hidden flex-col gap-6 bg-background text-foreground print:flex", children: [_jsxs("header", { className: "flex flex-col gap-1", children: [_jsx("h1", { className: "type-heading-1 break-words", children: title }), subtitle && _jsx("div", { className: "type-body break-words text-muted-foreground", children: subtitle })] }), sections.map((section) => (_jsx(PrintedSection, { section: section }, section.title)))] }) }), document.body);
32
41
  }
42
+ /** A print() that returns sooner than this didn't wait for the dialog: a phone's. */
43
+ const BLOCKING_PRINT_MS = 1000;
33
44
  /**
34
45
  * The header's Print notes button and, while it prints, the printed copy.
35
- * The copy mounts, then the browser's print dialog opens on it; it goes
36
- * when the dialog closes (`afterprint`).
46
+ * The copy mounts, then the browser's print dialog opens on it. Where
47
+ * print() blocks (a desktop browser) it goes when the dialog closes
48
+ * (`afterprint`). Where print() returns at once (a phone) `afterprint`
49
+ * comes too early to mean anything, so the copy goes on the person's next
50
+ * pointerdown or key instead.
37
51
  */
38
52
  export function PrintNotes({ label, look = 'icon', title, subtitle, sections, }) {
39
53
  // How many times it's been pressed since the copy last went: a press
40
- // while one is up (a browser that never said the dialog closed) prints
41
- // it again rather than doing nothing.
54
+ // while one is up (a browser that never said the dialog closed, or a phone
55
+ // still holding the copy) prints it again rather than doing nothing.
42
56
  const [printing, setPrinting] = useState(0);
43
57
  useEffect(() => {
44
58
  if (printing === 0)
45
59
  return;
46
- const done = () => setPrinting(0);
47
- window.addEventListener('afterprint', done);
60
+ const release = () => setPrinting(0);
61
+ // Whether print() waited for the dialog; unknown until it returns, and an
62
+ // `afterprint` inside the call is kept until then.
63
+ let blocked = undefined;
64
+ let endedInside = false;
65
+ const onAfterPrint = () => {
66
+ if (blocked === undefined)
67
+ endedInside = true;
68
+ else if (blocked)
69
+ release();
70
+ };
71
+ window.addEventListener('afterprint', onAfterPrint);
72
+ const started = performance.now();
48
73
  window.print();
49
- return () => window.removeEventListener('afterprint', done);
74
+ blocked = performance.now() - started >= BLOCKING_PRINT_MS;
75
+ if (blocked) {
76
+ if (endedInside)
77
+ release();
78
+ }
79
+ else {
80
+ // A phone: the copy waits for the person to come back to the page.
81
+ window.addEventListener('pointerdown', release);
82
+ window.addEventListener('keydown', release);
83
+ }
84
+ return () => {
85
+ window.removeEventListener('afterprint', onAfterPrint);
86
+ window.removeEventListener('pointerdown', release);
87
+ window.removeEventListener('keydown', release);
88
+ };
50
89
  }, [printing]);
51
90
  return (_jsxs(_Fragment, { children: [look === 'icon' ? (_jsx(IconAction, { icon: PrinterIcon, label: label, onClick: () => setPrinting((count) => count + 1) })) : (_jsxs(Button, { variant: "outline", onClick: () => setPrinting((count) => count + 1), children: [_jsx(PrinterIcon, {}), label] })), printing > 0 && _jsx(PrintedNotes, { title: title, subtitle: subtitle, sections: sections })] }));
52
91
  }
@@ -0,0 +1,5 @@
1
+ import { Radio as RadioPrimitive } from "@base-ui/react/radio";
2
+ import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group";
3
+ declare function RadioGroup({ className, ...props }: RadioGroupPrimitive.Props): import("react").JSX.Element;
4
+ declare function RadioGroupItem({ className, ...props }: RadioPrimitive.Root.Props): import("react").JSX.Element;
5
+ export { RadioGroup, RadioGroupItem };
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Radio as RadioPrimitive } from "@base-ui/react/radio";
3
+ import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group";
4
+ import { cn } from "cn";
5
+ function RadioGroup({ className, ...props }) {
6
+ return (_jsx(RadioGroupPrimitive, { "data-slot": "radio-group", className: cn("grid w-full gap-2", className), ...props }));
7
+ }
8
+ function RadioGroupItem({ className, ...props }) {
9
+ return (_jsx(RadioPrimitive.Root, { "data-slot": "radio-group-item", className: cn("group/radio-group-item peer relative flex aspect-square size-4 shrink-0 rounded-full border border-input outline-none group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary", className), ...props, children: _jsx(RadioPrimitive.Indicator, { "data-slot": "radio-group-indicator", className: "flex size-4 items-center justify-center", children: _jsx("span", { className: "absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-foreground" }) }) }));
10
+ }
11
+ export { RadioGroup, RadioGroupItem };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export { FillInField, FillInInput, FillInSelect, type FillInFieldKind, type Fill
8
8
  export { Artwork, ArtworkTag, ArtworkToggle, type ArtworkAspect, type ArtworkProps, type ArtworkToggleProps, } from './components/app/artwork.js';
9
9
  export { ColorSwatch, type ColorSwatchProps } from './components/app/color-swatch.js';
10
10
  export { storedColor } from './lib/stored-color.js';
11
+ export { ColorField, type ColorFieldProps } from './components/app/color-field.js';
12
+ export { COLOR_CHOICES, type ColorChoice } from './lib/color-choices.js';
11
13
  export { CountLink, type CountLinkProps } from './components/app/count-link.js';
12
14
  export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableLook, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
13
15
  export { type DataTableColumnsMenu, type DataTablePhoneRow, type DataTableRowAction, type DataTableView, type DataTableViewAll, } from './components/app/data-table-tools.js';
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ export { FillInField, FillInInput, FillInSelect, } from './components/app/fill-i
12
12
  export { Artwork, ArtworkTag, ArtworkToggle, } from './components/app/artwork.js';
13
13
  export { ColorSwatch } from './components/app/color-swatch.js';
14
14
  export { storedColor } from './lib/stored-color.js';
15
+ export { ColorField } from './components/app/color-field.js';
16
+ export { COLOR_CHOICES } from './lib/color-choices.js';
15
17
  export { CountLink } from './components/app/count-link.js';
16
18
  export { DataTable, } from './components/app/data-table.js';
17
19
  export {} from './components/app/data-table-tools.js';
@@ -0,0 +1,31 @@
1
+ /** One named colour a ColorField offers: its name is shown and is its accessible label. */
2
+ export type ColorChoice = {
3
+ name: string;
4
+ color: string;
5
+ };
6
+ /**
7
+ * ColorField's default set: twelve hues at a middle lightness, so each fill
8
+ * clears 3:1 against `card` in light, dark and every dark palette, and 2.3:1
9
+ * on Palm LCD's mid-light panel (measured in e2e/fixtures-visual.spec.ts).
10
+ * The swatch's ring shows its edge on any surface either way. An app with
11
+ * its own names or colours passes its own `colors`.
12
+ */
13
+ export declare const COLOR_CHOICES: readonly ColorChoice[];
14
+ /**
15
+ * A stored colour in full: `storedColor`'s form with a 3- or 4-digit hex
16
+ * spelt out (`#fff` → `#ffffff`, `#fff8` → `#ffffff88`), so two spellings of
17
+ * one colour compare equal. `null` when it isn't a colour.
18
+ */
19
+ export declare function fullHex(value: string | null | undefined): string | null;
20
+ /**
21
+ * The index of the choice a stored value is, or `-1` when it's none of them
22
+ * (Custom), compared in full so `#FFF`, `fff` and `#ffffff` are one colour.
23
+ * A value that isn't a colour (missing, empty, a typo) is `-1` too.
24
+ */
25
+ export declare function choiceIndex(value: string | null | undefined, colors: readonly ColorChoice[]): number;
26
+ /**
27
+ * What `<input type="color">` can show for a stored value: `#rrggbb` only,
28
+ * so a short hex is spelt out and an alpha dropped. Black when there's no
29
+ * colour, the input's own default.
30
+ */
31
+ export declare function pickerHex(value: string | null | undefined): string;
@@ -0,0 +1,57 @@
1
+ // The value handling behind ColorField: which of a set of named colours a
2
+ // stored value is, and what the browser's own colour picker can show. Its
3
+ // own file so it's tested without a browser (tests/color-field.test.tsx).
4
+ import { storedColor } from './stored-color.js';
5
+ /**
6
+ * ColorField's default set: twelve hues at a middle lightness, so each fill
7
+ * clears 3:1 against `card` in light, dark and every dark palette, and 2.3:1
8
+ * on Palm LCD's mid-light panel (measured in e2e/fixtures-visual.spec.ts).
9
+ * The swatch's ring shows its edge on any surface either way. An app with
10
+ * its own names or colours passes its own `colors`.
11
+ */
12
+ export const COLOR_CHOICES = [
13
+ { name: 'Red', color: '#dc2626' },
14
+ { name: 'Orange', color: '#dd5208' },
15
+ { name: 'Amber', color: '#c27006' },
16
+ { name: 'Olive', color: '#5f8a12' },
17
+ { name: 'Green', color: '#16883f' },
18
+ { name: 'Teal', color: '#0d8a80' },
19
+ { name: 'Cyan', color: '#0b86a8' },
20
+ { name: 'Blue', color: '#2563eb' },
21
+ { name: 'Indigo', color: '#5b5ee8' },
22
+ { name: 'Purple', color: '#9b3fec' },
23
+ { name: 'Pink', color: '#d62a74' },
24
+ { name: 'Grey', color: '#737373' },
25
+ ];
26
+ /**
27
+ * A stored colour in full: `storedColor`'s form with a 3- or 4-digit hex
28
+ * spelt out (`#fff` → `#ffffff`, `#fff8` → `#ffffff88`), so two spellings of
29
+ * one colour compare equal. `null` when it isn't a colour.
30
+ */
31
+ export function fullHex(value) {
32
+ const hex = storedColor(value);
33
+ if (!hex)
34
+ return null;
35
+ if (hex.length > 5)
36
+ return hex;
37
+ return `#${[...hex.slice(1)].map((digit) => digit + digit).join('')}`;
38
+ }
39
+ /**
40
+ * The index of the choice a stored value is, or `-1` when it's none of them
41
+ * (Custom), compared in full so `#FFF`, `fff` and `#ffffff` are one colour.
42
+ * A value that isn't a colour (missing, empty, a typo) is `-1` too.
43
+ */
44
+ export function choiceIndex(value, colors) {
45
+ const hex = fullHex(value);
46
+ if (!hex)
47
+ return -1;
48
+ return colors.findIndex((choice) => fullHex(choice.color) === hex);
49
+ }
50
+ /**
51
+ * What `<input type="color">` can show for a stored value: `#rrggbb` only,
52
+ * so a short hex is spelt out and an alpha dropped. Black when there's no
53
+ * colour, the input's own default.
54
+ */
55
+ export function pickerHex(value) {
56
+ return fullHex(value)?.slice(0, 7) ?? '#000000';
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.123.0",
3
+ "version": "4.124.1",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {