@tristan2828/ui-foundation 4.142.0 → 4.143.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.
@@ -16,7 +16,7 @@
16
16
  - Step 8: Add Playwright specs for all three screens · lines 255–335
17
17
  - Step 9: Register the nav entry and route names · lines 336–349
18
18
  - Step 10: `npm run verify`. · lines 350–351
19
- - [Step 6 in detail](#step-6-in-detail) · lines 353–933
19
+ - [Step 6 in detail](#step-6-in-detail) · lines 353–935
20
20
  - [A `reference`](#a-reference) · lines 358–360
21
21
  - [A `single choice`](#a-single-choice) · lines 362–368
22
22
  - [A `date-time`](#a-date-time) · lines 370–373
@@ -25,32 +25,32 @@
25
25
  - [A `multi reference`](#a-multi-reference) · lines 393–405
26
26
  - [Sub-records](#sub-records) · lines 407–423
27
27
  - [A `computed` field](#a-computed-field) · lines 425–434
28
- - [A `date`](#a-date) · lines 436–457
29
- - [A `month-day`](#a-month-day) · lines 459–479
30
- - [A `recurrence`](#a-recurrence) · lines 481–502
31
- - [An image on a record](#an-image-on-a-record) · lines 504–532
32
- - [A `reference` inside a sub-record item](#a-reference-inside-a-sub-record-item) · lines 534–593
33
- - [A `yes/no` marked `toggle`](#a-yesno-marked-toggle) · lines 595–610
34
- - [Keep column definitions stable](#keep-column-definitions-stable) · lines 612–620
35
- - [The view](#the-view) · lines 622–740
36
- - [The view: long text and notes](#the-view-long-text-and-notes) · lines 742–796
37
- - [The view: quick actions and editing in place](#the-view-quick-actions-and-editing-in-place) · lines 798–856
38
- - [The table opens the view, and the form returns to it](#the-table-opens-the-view-and-the-form-returns-to-it) · lines 858–869
39
- - [`<SelectValue>` shows the value, not the label](#selectvalue-shows-the-value-not-the-label) · lines 871–917
40
- - [Choosing how each column looks](#choosing-how-each-column-looks) · lines 919–933
41
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 935–1439
42
- - [The record view](#the-record-view) · lines 1078–1258
43
- - [Forms](#forms) · lines 1260–1343
44
- - [Dialogs](#dialogs) · lines 1345–1378
45
- - [Toasts and feedback](#toasts-and-feedback) · lines 1380–1439
46
- - [What not to copy](#what-not-to-copy) · lines 1441–1468
47
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1470–1487
48
- - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1489–1549
49
- - [Deleting](#deleting) · lines 1551–1581
50
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1583–1602
51
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1604–1613
52
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1616–1658
53
- - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1660–1693
28
+ - [A `date`](#a-date) · lines 436–459
29
+ - [A `month-day`](#a-month-day) · lines 461–481
30
+ - [A `recurrence`](#a-recurrence) · lines 483–504
31
+ - [An image on a record](#an-image-on-a-record) · lines 506–534
32
+ - [A `reference` inside a sub-record item](#a-reference-inside-a-sub-record-item) · lines 536–595
33
+ - [A `yes/no` marked `toggle`](#a-yesno-marked-toggle) · lines 597–612
34
+ - [Keep column definitions stable](#keep-column-definitions-stable) · lines 614–622
35
+ - [The view](#the-view) · lines 624–742
36
+ - [The view: long text and notes](#the-view-long-text-and-notes) · lines 744–798
37
+ - [The view: quick actions and editing in place](#the-view-quick-actions-and-editing-in-place) · lines 800–858
38
+ - [The table opens the view, and the form returns to it](#the-table-opens-the-view-and-the-form-returns-to-it) · lines 860–871
39
+ - [`<SelectValue>` shows the value, not the label](#selectvalue-shows-the-value-not-the-label) · lines 873–919
40
+ - [Choosing how each column looks](#choosing-how-each-column-looks) · lines 921–935
41
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 937–1441
42
+ - [The record view](#the-record-view) · lines 1080–1260
43
+ - [Forms](#forms) · lines 1262–1345
44
+ - [Dialogs](#dialogs) · lines 1347–1380
45
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1382–1441
46
+ - [What not to copy](#what-not-to-copy) · lines 1443–1470
47
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1472–1489
48
+ - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1491–1551
49
+ - [Deleting](#deleting) · lines 1553–1583
50
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1585–1604
51
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1606–1615
52
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1618–1660
53
+ - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1662–1695
54
54
 
55
55
  <!-- /index -->
56
56
 
@@ -453,7 +453,9 @@ button alone; in place then `editInPlace({ kind: 'choice', ... })` with
453
453
  start on Monday. An app whose weeks start on Sunday gives `DateField`,
454
454
  `inPlace.date`, `FilterDate` and `FillInField` `weekStart="SU"`, the
455
455
  `weekStart` it gives `MonthCalendar` and `RecurrenceField` (a `Calendar`
456
- of its own takes react-day-picker's `weekStartsOn={0}`). The backend column
456
+ of its own takes react-day-picker's `weekStartsOn={0}`). A due or start
457
+ day can add `quickPicks` (Today, Tomorrow, This Weekend, Next Week over
458
+ the calendar; design-language.md "A date field's quick picks"). The backend column
457
459
  is a SQL `date` (`datetime.date` in the model).
458
460
 
459
461
  ### A `month-day`
@@ -3,48 +3,49 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [Palettes](#palettes) · lines 57–140
7
- - [Glow](#glow) · lines 142–161
8
- - [Semantic tones](#semantic-tones) · lines 163–191
9
- - [The three badge styles](#the-three-badge-styles) · lines 193–210
10
- - [Status marks](#status-marks) · lines 212–255
11
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 257–286
12
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 288–299
13
- - [Logos and brand marks](#logos-and-brand-marks) · lines 301–341
14
- - [Categorical colour](#categorical-colour) · lines 343–408
15
- - [Heat scale](#heat-scale) · lines 410–462
16
- - [Depth ramps](#depth-ramps) · lines 464–531
17
- - [A stored colour](#a-stored-colour) · lines 533–580
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 582–603
19
- - [Typography](#typography) · lines 605–775
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 639–671
21
- - [Written text (notes)](#written-text-notes) · lines 673–775
22
- - [Density](#density) · lines 777–899
23
- - [Rows on this device](#rows-on-this-device) · lines 844–872
24
- - [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 874–899
25
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 901–1011
26
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1013–1085
27
- - [Notices](#notices) · lines 1087–1114
28
- - [A value over time](#a-value-over-time) · lines 1116–1246
29
- - [Several values over time](#several-values-over-time) · lines 1165–1203
30
- - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1205–1246
31
- - [A list as a board](#a-list-as-a-board) · lines 1248–1358
32
- - [Order, groups and the header](#order-groups-and-the-header) · lines 1301–1358
33
- - [A list as cards](#a-list-as-cards) · lines 1360–1407
34
- - [Images full screen](#images-full-screen) · lines 1409–1455
35
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1457–1493
36
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1495–1531
37
- - [A few equal things](#a-few-equal-things) · lines 1533–1648
38
- - [An overview page](#an-overview-page) · lines 1650–1715
39
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1717–1780
40
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1782–1869
41
- - [Picking at random](#picking-at-random) · lines 1871–1902
42
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1904–1971
43
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1973–1992
44
- - [A quick add line](#a-quick-add-line) · lines 1994–2022
45
- - [A month calendar](#a-month-calendar) · lines 2024–2054
46
- - [A settings page](#a-settings-page) · lines 2056–2113
47
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2115–2174
6
+ - [Palettes](#palettes) · lines 58–141
7
+ - [Glow](#glow) · lines 143–162
8
+ - [Semantic tones](#semantic-tones) · lines 164–192
9
+ - [The three badge styles](#the-three-badge-styles) · lines 194–211
10
+ - [Status marks](#status-marks) · lines 213–256
11
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 258–287
12
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 289–300
13
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 302–342
14
+ - [Categorical colour](#categorical-colour) · lines 344–409
15
+ - [Heat scale](#heat-scale) · lines 411–463
16
+ - [Depth ramps](#depth-ramps) · lines 465–532
17
+ - [A stored colour](#a-stored-colour) · lines 534–581
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 583–604
19
+ - [Typography](#typography) · lines 606–776
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 640–672
21
+ - [Written text (notes)](#written-text-notes) · lines 674–776
22
+ - [Density](#density) · lines 778–900
23
+ - [Rows on this device](#rows-on-this-device) · lines 845–873
24
+ - [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 875–900
25
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 902–1012
26
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1014–1086
27
+ - [Notices](#notices) · lines 1088–1115
28
+ - [A value over time](#a-value-over-time) · lines 1117–1247
29
+ - [Several values over time](#several-values-over-time) · lines 1166–1204
30
+ - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1206–1247
31
+ - [A list as a board](#a-list-as-a-board) · lines 1249–1359
32
+ - [Order, groups and the header](#order-groups-and-the-header) · lines 1302–1359
33
+ - [A list as cards](#a-list-as-cards) · lines 1361–1408
34
+ - [Images full screen](#images-full-screen) · lines 1410–1456
35
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1458–1494
36
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1496–1532
37
+ - [A few equal things](#a-few-equal-things) · lines 1534–1649
38
+ - [An overview page](#an-overview-page) · lines 1651–1716
39
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1718–1781
40
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1783–1870
41
+ - [Picking at random](#picking-at-random) · lines 1872–1903
42
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1905–1972
43
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1974–1993
44
+ - [A quick add line](#a-quick-add-line) · lines 1995–2023
45
+ - [A date field's quick picks](#a-date-fields-quick-picks) · lines 2025–2049
46
+ - [A month calendar](#a-month-calendar) · lines 2051–2081
47
+ - [A settings page](#a-settings-page) · lines 2083–2140
48
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2142–2201
48
49
 
49
50
  <!-- /index -->
50
51
 
@@ -2021,6 +2022,32 @@ day and a repeat with no day come out, is in its source's header
2021
2022
  own day (`todayIn`). A repeat is a `Recurrence`, read by
2022
2023
  `parseRecurrencePhrase` (`every!` repeats from completion).
2023
2024
 
2025
+ ## A date field's quick picks
2026
+
2027
+ `DateField` (and `inPlace.date`) with `quickPicks` puts a short list of
2028
+ days over the calendar, for a due day picked in one press:
2029
+
2030
+ - **The four:** `quickPicks` (`true`) is Today, Tomorrow, This Weekend
2031
+ and Next Week (`DATE_QUICK_PICKS`). This Weekend is the coming
2032
+ Saturday, today when it's Saturday; Next Week is the coming week start
2033
+ (`weekStart`, Monday when left out), a week on when today is one. An
2034
+ app passes its own list instead: `{ label, day: (today, weekStart) =>
2035
+ day }`, its words in Title Case.
2036
+ - **The look:** a column of ghost buttons at the popover's top, over a
2037
+ `border-border` rule, each its words on the left and the day it sets
2038
+ on the right in `text-muted-foreground` ("Sat, Nov 28", the locale's
2039
+ short weekday, month and day), so nobody has to work out which day
2040
+ "Next Week" is.
2041
+ - **Behaviour:** a pick sets its day and closes, as a day picked in the
2042
+ calendar does (editing in place, it saves). Each is a button named for
2043
+ its words and its day ("This Weekend, Sat, Nov 28") in a group named
2044
+ Quick Picks; the keyboard still opens on the calendar's day, with the
2045
+ picks before it (Shift+Tab).
2046
+ - **Off unless asked for:** a field without `quickPicks` is the calendar
2047
+ alone. Give them to a due day or a start day, the dates people set
2048
+ ahead; a day something happened (finished, bought) has no use for
2049
+ them.
2050
+
2024
2051
  ## A month calendar
2025
2052
 
2026
2053
  A month of days holding the app's dated things (events, visits): the
@@ -1,3 +1,4 @@
1
+ import { type DateQuickPick } from '../../lib/date-quick-picks.js';
1
2
  import { type PlainDate } from '../../lib/plain-date.js';
2
3
  import type { WeekdayCode } from '../../lib/recurrence.js';
3
4
  export type DateFieldProps = {
@@ -44,6 +45,12 @@ export type DateFieldProps = {
44
45
  format?: Intl.DateTimeFormatOptions;
45
46
  /** The day the calendar's weeks start on (`'MO'` to `'SU'`; Monday when left out). */
46
47
  weekStart?: WeekdayCode;
48
+ /**
49
+ * Days to pick in one press, over the calendar: `true` for Today,
50
+ * Tomorrow, This Weekend and Next Week (`DATE_QUICK_PICKS`), or the
51
+ * app's own list. Each sets its day and closes. None when left out.
52
+ */
53
+ quickPicks?: boolean | readonly DateQuickPick[];
47
54
  locale?: string;
48
55
  className?: string;
49
56
  'aria-label'?: string;
@@ -18,6 +18,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
18
  // The calendar's weeks start on Monday, MonthCalendar's and
19
19
  // RecurrenceField's default; `weekStart="SU"` for an app whose weeks start
20
20
  // on Sunday.
21
+ //
22
+ // `quickPicks` puts a short list of days over the calendar: `true` is Today,
23
+ // Tomorrow, This Weekend (the coming Saturday) and Next Week (the coming
24
+ // week start), or an app passes its own list. Each is a button named for
25
+ // its words and the day it sets ("Next Week, Mon, Nov 30"); pressing one
26
+ // sets that day and closes, as a day picked in the calendar does. Off
27
+ // unless asked for.
21
28
  import { useId, useRef, useState } from 'react';
22
29
  import { CalendarIcon } from 'lucide-react';
23
30
  import { cn } from 'cn';
@@ -25,13 +32,27 @@ import { Button } from '../ui/button.js';
25
32
  import { Calendar } from '../ui/calendar.js';
26
33
  import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '../ui/input-group.js';
27
34
  import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';
35
+ import { DATE_QUICK_PICKS } from '../../lib/date-quick-picks.js';
28
36
  import { formatPlainDate, localToPlainDate, parsePlainDate, plainDateExamples, plainDateToLocal, unreadableDateMessage, } from '../../lib/plain-date.js';
29
37
  export function DateField({ typing = true, onProblem, ...props }) {
30
38
  return typing ? _jsx(TypedDate, { ...props, onProblem: onProblem }) : _jsx(DateButton, { ...props });
31
39
  }
32
40
  // Calendar's `weekStartsOn` by code. Left out, it's Calendar's own default (Monday).
33
41
  const WEEK_STARTS_ON = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 };
34
- function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, weekStart, locale, className, 'aria-describedby': describedBy, ...aria }) {
42
+ // The quick picks over the calendar, each named for its words and its day,
43
+ // counted from the browser's own today when the calendar opens.
44
+ function QuickPicks({ picks, weekStart = 'MO', locale, onPick, }) {
45
+ const list = picks === true ? DATE_QUICK_PICKS : picks || [];
46
+ if (list.length === 0)
47
+ return null;
48
+ const today = localToPlainDate(new Date());
49
+ return (_jsx("div", { role: "group", "aria-label": "Quick Picks", "data-slot": "date-field-quick-picks", className: "flex flex-col gap-0.5 border-b border-border p-2", children: list.map((pick) => {
50
+ const day = pick.day(today, weekStart);
51
+ const shown = formatPlainDate(day, { weekday: 'short', month: 'short', day: 'numeric' }, locale);
52
+ return (_jsxs(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full justify-between gap-4 font-normal", "aria-label": `${pick.label}, ${shown}`, onClick: () => onPick(day), children: [_jsx("span", { children: pick.label }), _jsx("span", { className: "text-muted-foreground", children: shown })] }, pick.label));
53
+ }) }));
54
+ }
55
+ function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, weekStart, quickPicks, locale, className, 'aria-describedby': describedBy, ...aria }) {
35
56
  const messageId = useId();
36
57
  const [open, setOpen] = useState(defaultOpen && !readOnly);
37
58
  const box = useRef(null);
@@ -110,11 +131,11 @@ function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, cleara
110
131
  // The day the keyboard starts from (the chosen one, else today).
111
132
  initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true,
112
133
  // Back to the box, where typing goes on.
113
- finalFocus: box, children: [_jsx(Calendar, { mode: "single",
134
+ finalFocus: box, children: [_jsx(QuickPicks, { picks: quickPicks, weekStart: weekStart, locale: locale, onPick: pick }), _jsx(Calendar, { mode: "single",
114
135
  // Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
115
136
  required: true, selected: selected, defaultMonth: selected, weekStartsOn: weekStart && WEEK_STARTS_ON[weekStart], onSelect: (date) => pick(localToPlainDate(date)) }), clearable && given && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }) })] }), showProblem && (_jsx("p", { id: messageId, "data-slot": "date-field-problem", className: "type-caption text-destructive-text", children: problem }))] }));
116
137
  }
117
- function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date', clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, weekStart, locale, className, ...aria }) {
138
+ function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date', clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, weekStart, quickPicks, locale, className, ...aria }) {
118
139
  const [open, setOpen] = useState(defaultOpen && !readOnly);
119
140
  const popup = useRef(null);
120
141
  const selected = plainDateToLocal(value);
@@ -134,7 +155,7 @@ function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date',
134
155
  // The day the keyboard starts from (the chosen one, else today):
135
156
  // the one day react-day-picker makes tabbable. The popup would
136
157
  // otherwise take focus itself, past the Calendar's autoFocus.
137
- initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true, children: [_jsx(Calendar, { mode: "single",
158
+ initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true, children: [_jsx(QuickPicks, { picks: quickPicks, weekStart: weekStart, locale: locale, onPick: pick }), _jsx(Calendar, { mode: "single",
138
159
  // Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
139
160
  required: true, selected: selected, defaultMonth: selected, weekStartsOn: weekStart && WEEK_STARTS_ON[weekStart], onSelect: (date) => pick(localToPlainDate(date)) }), clearable && value && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }));
140
161
  }
@@ -1,4 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
+ import type { DateQuickPick } from '../../lib/date-quick-picks.js';
2
3
  import { type MonthDay } from '../../lib/month-day.js';
3
4
  import { type PlainDate } from '../../lib/plain-date.js';
4
5
  import { type Recurrence, type WeekdayCode } from '../../lib/recurrence.js';
@@ -68,6 +69,8 @@ export type InPlaceDateConfig<TRequired extends boolean = boolean> = {
68
69
  format?: Intl.DateTimeFormatOptions;
69
70
  /** DateField's `weekStart`: `'SU'` for an app whose weeks start on Sunday. */
70
71
  weekStart?: WeekdayCode;
72
+ /** DateField's `quickPicks`: `true` for Today, Tomorrow, This Weekend and Next Week over the calendar, or the app's own. */
73
+ quickPicks?: boolean | readonly DateQuickPick[];
71
74
  locale?: string;
72
75
  placeholder?: string;
73
76
  };
@@ -135,7 +135,7 @@ function dateKind(config) {
135
135
  control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value,
136
136
  // Alone, a pick saves and the calendar opens with the field; closing
137
137
  // it with nothing picked gives up (a pick has already saved by then).
138
- onChange: alone ? (day) => props.commit(day) : props.onChange, clearable: !config.required, placeholder: config.placeholder, format: config.format, weekStart: config.weekStart, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, defaultOpen: alone, modal: alone ? false : undefined, onOpenChange: alone
138
+ onChange: alone ? (day) => props.commit(day) : props.onChange, clearable: !config.required, placeholder: config.placeholder, format: config.format, weekStart: config.weekStart, quickPicks: config.quickPicks, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, defaultOpen: alone, modal: alone ? false : undefined, onOpenChange: alone
139
139
  ? (open) => {
140
140
  if (!open)
141
141
  props.cancel();
@@ -156,7 +156,7 @@ function typedDateKind(config) {
156
156
  return formatPlainDate(draft) === '' ? { ok: false, message: unreadableDateMessage(config.locale) } : { ok: true, value: draft };
157
157
  },
158
158
  show: (value) => (value ? formatPlainDate(value, config.format, config.locale) || value : null),
159
- control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value, onChange: props.onChange, onPick: alone ? (day) => props.commit(day) : props.onChange, onProblem: props.onProblem, clearable: !config.required, placeholder: config.placeholder, format: config.format, weekStart: config.weekStart, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, modal: false, "aria-label": props.label, "aria-describedby": props.describedBy })),
159
+ control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value, onChange: props.onChange, onPick: alone ? (day) => props.commit(day) : props.onChange, onProblem: props.onProblem, clearable: !config.required, placeholder: config.placeholder, format: config.format, weekStart: config.weekStart, quickPicks: config.quickPicks, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, modal: false, "aria-label": props.label, "aria-describedby": props.describedBy })),
160
160
  };
161
161
  }
162
162
  function monthDayKind(config) {
package/dist/index.d.ts CHANGED
@@ -105,6 +105,7 @@ export { RatingStar, type RatingStarProps, type RatingStarValue } from './compon
105
105
  export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
106
106
  export { RatingInput, type RatingInputProps, type RatingInputSource } from './components/app/rating-input.js';
107
107
  export { DateField, type DateFieldProps } from './components/app/date-field.js';
108
+ export { addPlainDays, comingWeekday, DATE_QUICK_PICKS, NEXT_WEEK_PICK, THIS_WEEKEND_PICK, TODAY_PICK, TOMORROW_PICK, type DateQuickPick, } from './lib/date-quick-picks.js';
108
109
  export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
109
110
  export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
110
111
  export { ImageField, type ImageFieldProps } from './components/app/image-field.js';
package/dist/index.js CHANGED
@@ -115,6 +115,7 @@ export { RatingStar } from './components/app/rating-star.js';
115
115
  export { RatingScore } from './components/app/rating-score.js';
116
116
  export { RatingInput } from './components/app/rating-input.js';
117
117
  export { DateField } from './components/app/date-field.js';
118
+ export { addPlainDays, comingWeekday, DATE_QUICK_PICKS, NEXT_WEEK_PICK, THIS_WEEKEND_PICK, TODAY_PICK, TOMORROW_PICK, } from './lib/date-quick-picks.js';
118
119
  export { EmojiField } from './components/app/emoji-field.js';
119
120
  export { MonthDayField } from './components/app/month-day-field.js';
120
121
  export { ImageField } from './components/app/image-field.js';
@@ -0,0 +1,28 @@
1
+ import { type PlainDate } from './plain-date.js';
2
+ import type { WeekdayCode } from './recurrence.js';
3
+ /** One quick pick: its button's words, and the day it sets from today's. */
4
+ export type DateQuickPick = {
5
+ /** The button's words, in Title Case ("This Weekend"). */
6
+ label: string;
7
+ /** The day it sets, from today (`'YYYY-MM-DD'`) and the calendar's week start. */
8
+ day: (today: PlainDate, weekStart: WeekdayCode) => PlainDate;
9
+ };
10
+ /** The day `days` after a plain day (before it, for a negative count). */
11
+ export declare function addPlainDays(day: PlainDate, days: number): PlainDate;
12
+ /**
13
+ * The next `weekday` on or after a plain day (`sameDay: true`, the
14
+ * default), or strictly after it (`sameDay: false`).
15
+ */
16
+ export declare function comingWeekday(day: PlainDate, weekday: WeekdayCode, { sameDay }?: {
17
+ sameDay?: boolean;
18
+ }): PlainDate;
19
+ /** Today. */
20
+ export declare const TODAY_PICK: DateQuickPick;
21
+ /** The day after today. */
22
+ export declare const TOMORROW_PICK: DateQuickPick;
23
+ /** The coming Saturday: today when it's Saturday, the next one from Sunday on. */
24
+ export declare const THIS_WEEKEND_PICK: DateQuickPick;
25
+ /** The first day of next week: the coming week start, a week on when today is one. */
26
+ export declare const NEXT_WEEK_PICK: DateQuickPick;
27
+ /** DateField's `quickPicks` when it's given `true`: Today, Tomorrow, This Weekend and Next Week. */
28
+ export declare const DATE_QUICK_PICKS: readonly DateQuickPick[];
@@ -0,0 +1,41 @@
1
+ // The days DateField's quick picks set: Today, Tomorrow, This Weekend and
2
+ // Next Week, counted from today's plain day and the calendar's week start.
3
+ // Plain days in, plain days out: the sums run on a local Date at midnight
4
+ // (`new Date(y, m, d + n)` rolls over months and years and never lands
5
+ // on another day across a clock change), so no time zone moves the day.
6
+ import { localToPlainDate, plainDateToLocal } from './plain-date.js';
7
+ // Date's getDay() by weekday code: Sunday is 0.
8
+ const DAY_NUMBER = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 };
9
+ /** The day `days` after a plain day (before it, for a negative count). */
10
+ export function addPlainDays(day, days) {
11
+ const local = plainDateToLocal(day);
12
+ if (!local)
13
+ return '';
14
+ return localToPlainDate(new Date(local.getFullYear(), local.getMonth(), local.getDate() + days));
15
+ }
16
+ /**
17
+ * The next `weekday` on or after a plain day (`sameDay: true`, the
18
+ * default), or strictly after it (`sameDay: false`).
19
+ */
20
+ export function comingWeekday(day, weekday, { sameDay = true } = {}) {
21
+ const local = plainDateToLocal(day);
22
+ if (!local)
23
+ return '';
24
+ let ahead = (DAY_NUMBER[weekday] - local.getDay() + 7) % 7;
25
+ if (ahead === 0 && !sameDay)
26
+ ahead = 7;
27
+ return addPlainDays(day, ahead);
28
+ }
29
+ /** Today. */
30
+ export const TODAY_PICK = { label: 'Today', day: (today) => today };
31
+ /** The day after today. */
32
+ export const TOMORROW_PICK = { label: 'Tomorrow', day: (today) => addPlainDays(today, 1) };
33
+ /** The coming Saturday: today when it's Saturday, the next one from Sunday on. */
34
+ export const THIS_WEEKEND_PICK = { label: 'This Weekend', day: (today) => comingWeekday(today, 'SA') };
35
+ /** The first day of next week: the coming week start, a week on when today is one. */
36
+ export const NEXT_WEEK_PICK = {
37
+ label: 'Next Week',
38
+ day: (today, weekStart) => comingWeekday(today, weekStart, { sameDay: false }),
39
+ };
40
+ /** DateField's `quickPicks` when it's given `true`: Today, Tomorrow, This Weekend and Next Week. */
41
+ export const DATE_QUICK_PICKS = [TODAY_PICK, TOMORROW_PICK, THIS_WEEKEND_PICK, NEXT_WEEK_PICK];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.142.0",
3
+ "version": "4.143.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": {