@tristan2828/ui-foundation 4.145.0 → 4.147.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/conventions/docs/design-language.md +78 -44
- package/dist/components/app/date-choices.d.ts +63 -0
- package/dist/components/app/date-choices.js +62 -0
- package/dist/components/app/date-field.js +8 -16
- package/dist/components/app/widget-card.d.ts +8 -1
- package/dist/components/app/widget-card.js +7 -2
- package/dist/components/ui/calendar.d.ts +1 -1
- package/dist/components/ui/calendar.js +22 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
|
@@ -3,50 +3,51 @@
|
|
|
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
|
|
7
|
-
- [Glow](#glow) · lines
|
|
8
|
-
- [Semantic tones](#semantic-tones) · lines
|
|
9
|
-
- [The three badge styles](#the-three-badge-styles) · lines
|
|
10
|
-
- [Status marks](#status-marks) · lines
|
|
11
|
-
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines
|
|
12
|
-
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines
|
|
13
|
-
- [Logos and brand marks](#logos-and-brand-marks) · lines
|
|
14
|
-
- [Emoji](#emoji) · lines
|
|
15
|
-
- [Categorical colour](#categorical-colour) · lines
|
|
16
|
-
- [Heat scale](#heat-scale) · lines
|
|
17
|
-
- [Depth ramps](#depth-ramps) · lines
|
|
18
|
-
- [A stored colour](#a-stored-colour) · lines
|
|
19
|
-
- [Shapes and sizes](#shapes-and-sizes) · lines
|
|
20
|
-
- [Typography](#typography) · lines
|
|
21
|
-
- [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines
|
|
22
|
-
- [Written text (notes)](#written-text-notes) · lines
|
|
23
|
-
- [Density](#density) · lines
|
|
24
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
25
|
-
- [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines
|
|
26
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
27
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
28
|
-
- [Notices](#notices) · lines
|
|
29
|
-
- [A value over time](#a-value-over-time) · lines
|
|
30
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
31
|
-
- [Parts of a whole over time](#parts-of-a-whole-over-time) · lines
|
|
32
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
33
|
-
- [Order, groups and the header](#order-groups-and-the-header) · lines
|
|
34
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
35
|
-
- [Images full screen](#images-full-screen) · lines
|
|
36
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
37
|
-
- [Parts of the page standards](#parts-of-the-page-standards) · lines
|
|
38
|
-
- [A few equal things](#a-few-equal-things) · lines
|
|
39
|
-
- [An overview page](#an-overview-page) · lines
|
|
40
|
-
- [A record's header and empty values](#a-records-header-and-empty-values) · lines
|
|
41
|
-
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines
|
|
42
|
-
- [Picking at random](#picking-at-random) · lines
|
|
43
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
44
|
-
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines
|
|
45
|
-
- [A quick add line](#a-quick-add-line) · lines
|
|
46
|
-
- [A date field's quick picks](#a-date-fields-quick-picks) · lines
|
|
47
|
-
- [A month
|
|
48
|
-
- [A
|
|
49
|
-
- [
|
|
6
|
+
- [Palettes](#palettes) · lines 60–143
|
|
7
|
+
- [Glow](#glow) · lines 145–164
|
|
8
|
+
- [Semantic tones](#semantic-tones) · lines 166–194
|
|
9
|
+
- [The three badge styles](#the-three-badge-styles) · lines 196–213
|
|
10
|
+
- [Status marks](#status-marks) · lines 215–258
|
|
11
|
+
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 260–289
|
|
12
|
+
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 291–302
|
|
13
|
+
- [Logos and brand marks](#logos-and-brand-marks) · lines 304–344
|
|
14
|
+
- [Emoji](#emoji) · lines 346–386
|
|
15
|
+
- [Categorical colour](#categorical-colour) · lines 388–453
|
|
16
|
+
- [Heat scale](#heat-scale) · lines 455–507
|
|
17
|
+
- [Depth ramps](#depth-ramps) · lines 509–576
|
|
18
|
+
- [A stored colour](#a-stored-colour) · lines 578–625
|
|
19
|
+
- [Shapes and sizes](#shapes-and-sizes) · lines 627–648
|
|
20
|
+
- [Typography](#typography) · lines 650–820
|
|
21
|
+
- [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 684–716
|
|
22
|
+
- [Written text (notes)](#written-text-notes) · lines 718–820
|
|
23
|
+
- [Density](#density) · lines 822–951
|
|
24
|
+
- [Rows on this device](#rows-on-this-device) · lines 895–923
|
|
25
|
+
- [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 925–951
|
|
26
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 953–1070
|
|
27
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1072–1144
|
|
28
|
+
- [Notices](#notices) · lines 1146–1173
|
|
29
|
+
- [A value over time](#a-value-over-time) · lines 1175–1305
|
|
30
|
+
- [Several values over time](#several-values-over-time) · lines 1224–1262
|
|
31
|
+
- [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1264–1305
|
|
32
|
+
- [A list as a board](#a-list-as-a-board) · lines 1307–1417
|
|
33
|
+
- [Order, groups and the header](#order-groups-and-the-header) · lines 1360–1417
|
|
34
|
+
- [A list as cards](#a-list-as-cards) · lines 1419–1466
|
|
35
|
+
- [Images full screen](#images-full-screen) · lines 1468–1514
|
|
36
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1516–1552
|
|
37
|
+
- [Parts of the page standards](#parts-of-the-page-standards) · lines 1554–1590
|
|
38
|
+
- [A few equal things](#a-few-equal-things) · lines 1592–1707
|
|
39
|
+
- [An overview page](#an-overview-page) · lines 1709–1774
|
|
40
|
+
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1776–1839
|
|
41
|
+
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1841–1928
|
|
42
|
+
- [Picking at random](#picking-at-random) · lines 1930–1961
|
|
43
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1963–2030
|
|
44
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2032–2051
|
|
45
|
+
- [A quick add line](#a-quick-add-line) · lines 2053–2081
|
|
46
|
+
- [A date field's quick picks](#a-date-fields-quick-picks) · lines 2083–2107
|
|
47
|
+
- [A few choices, then the month](#a-few-choices-then-the-month) · lines 2109–2135
|
|
48
|
+
- [A month calendar](#a-month-calendar) · lines 2137–2169
|
|
49
|
+
- [A settings page](#a-settings-page) · lines 2171–2228
|
|
50
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2230–2289
|
|
50
51
|
|
|
51
52
|
<!-- /index -->
|
|
52
53
|
|
|
@@ -996,6 +997,11 @@ const { data, isLoading, error, refetch } = useReadyTasksQuery() // one page of
|
|
|
996
997
|
<service>' }}` opens it in a new tab, with the external-link mark and
|
|
997
998
|
"(opens in a new tab)" for a screen reader. Set `skeletonRows` to the number it usually holds, so the card
|
|
998
999
|
keeps its height when the data arrives.
|
|
1000
|
+
- **A row's words:** its text is one line, cut. A small muted `note`
|
|
1001
|
+
("2 h ago", "holds 2") sits beside it, at the row's end; a `line`
|
|
1002
|
+
("Every day · 4 steps", 4.147) sits under it, wraps rather than cuts,
|
|
1003
|
+
and the row keeps room under it. Neither is part of the link's name.
|
|
1004
|
+
Don't reach into the row's spans through `className` to move a note.
|
|
999
1005
|
- **Each widget owns its four states.** Loading is a skeleton of rows,
|
|
1000
1006
|
empty is one quiet line the app writes ("Nothing waiting", not "No
|
|
1001
1007
|
data"), and **an error stays inside the card**: the compact
|
|
@@ -2100,6 +2106,34 @@ days over the calendar, for a due day picked in one press:
|
|
|
2100
2106
|
ahead; a day something happened (finished, bought) has no use for
|
|
2101
2107
|
them.
|
|
2102
2108
|
|
|
2109
|
+
## A few choices, then the month
|
|
2110
|
+
|
|
2111
|
+
A row's "move to" picker (a to-do's ⋯: the parts of the day, Tomorrow,
|
|
2112
|
+
or any day) is the package's `DateChoices`, never a `DropdownMenu` with a
|
|
2113
|
+
calendar in it. A calendar's grid can't sit inside `role="menu"`, and a
|
|
2114
|
+
menu's arrows never reach it.
|
|
2115
|
+
|
|
2116
|
+
- **The look is DateField's popup:** the app's `choices` at the top, under
|
|
2117
|
+
their `choicesLabel` heading ("Move to"), each a ghost button with its
|
|
2118
|
+
label on the left and its `value` muted on the right (a start time, "Thu,
|
|
2119
|
+
Nov 26"), over a `border-border` rule. Then the month, on the day the
|
|
2120
|
+
thing sits on (`value`), with today ringed (`today`, the app's own day,
|
|
2121
|
+
the browser's when left out). A choice that can't be picked now (a block
|
|
2122
|
+
that has ended) is `disabled`: shown, greyed, skipped by Tab.
|
|
2123
|
+
- **It's a dialog named for what it moves** (`label`, "Move Water the
|
|
2124
|
+
plants"), opened from the app's own `trigger`. It opens on the first
|
|
2125
|
+
choice that can be pressed, or on the month's day when there are none.
|
|
2126
|
+
Tab goes through the choices, then the month's buttons and its day,
|
|
2127
|
+
where the arrows move a day or a week. Escape closes, and focus goes
|
|
2128
|
+
back to the trigger.
|
|
2129
|
+
- **A choice runs its own `onSelect`; a day picked runs `onPick`** with
|
|
2130
|
+
its `'YYYY-MM-DD'`. Either closes the popup first, so a row that moves
|
|
2131
|
+
away leaves nothing open behind it. Each choice is named for its label
|
|
2132
|
+
and value ("Tomorrow, Thu, Nov 26"), as the quick picks are.
|
|
2133
|
+
- **DateField's popup shares its parts:** its quick picks are the same
|
|
2134
|
+
rows, its month the same calendar. A field still opens on the day, with
|
|
2135
|
+
its picks before it; a picker opens on its first choice.
|
|
2136
|
+
|
|
2103
2137
|
## A month calendar
|
|
2104
2138
|
|
|
2105
2139
|
A month of days holding the app's dated things (events, visits): the
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import { type PlainDate } from '../../lib/plain-date.js';
|
|
3
|
+
import type { WeekdayCode } from '../../lib/recurrence.js';
|
|
4
|
+
export type DateChoice = {
|
|
5
|
+
/** Its words, on the left: "Morning", "Tomorrow". Title Case. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** What it means, muted on the right: a start time, a day ("Thu, Nov 26"). */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** Shown, greyed and not pressable: a block that has ended. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Pressed: the popup closes, then this runs. */
|
|
12
|
+
onSelect: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type DateChoicesProps = {
|
|
15
|
+
/**
|
|
16
|
+
* The button that opens it, as a Base UI `render` element (`<Button
|
|
17
|
+
* size="icon-sm" variant="ghost" aria-label="Move Water the plants" />`),
|
|
18
|
+
* with `children` inside it.
|
|
19
|
+
*/
|
|
20
|
+
trigger: ReactElement;
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
/** The popup's name, read when it opens: "Move Water the plants". */
|
|
23
|
+
label: string;
|
|
24
|
+
/** The rows' heading, shown over them and naming their group: "Move to". */
|
|
25
|
+
choicesLabel?: string;
|
|
26
|
+
choices?: readonly DateChoice[];
|
|
27
|
+
/** The day it's on now, `'YYYY-MM-DD'`: marked in the calendar, whose month opens on it. */
|
|
28
|
+
value?: PlainDate;
|
|
29
|
+
/**
|
|
30
|
+
* Today as the app counts it (a day that rolls over at 4 AM, say), ringed
|
|
31
|
+
* in the calendar. Defaults to the browser's today.
|
|
32
|
+
*/
|
|
33
|
+
today?: PlainDate;
|
|
34
|
+
/** A day picked in the calendar, `'YYYY-MM-DD'`. The popup closes first. */
|
|
35
|
+
onPick: (day: PlainDate) => void;
|
|
36
|
+
/** The day the calendar's weeks start on (`'MO'` to `'SU'`; Monday when left out). */
|
|
37
|
+
weekStart?: WeekdayCode;
|
|
38
|
+
/** Where it lines up with the trigger. Defaults to `'end'`, as a row's ⋯ menu does. */
|
|
39
|
+
align?: 'start' | 'center' | 'end';
|
|
40
|
+
open?: boolean;
|
|
41
|
+
onOpenChange?: (open: boolean) => void;
|
|
42
|
+
className?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function DateChoices({ trigger, children, label, choicesLabel, choices, value, today, onPick, weekStart, align, open: givenOpen, onOpenChange, className, }: DateChoicesProps): import("react").JSX.Element;
|
|
45
|
+
/**
|
|
46
|
+
* The rows over a date popup's calendar, DateField's quick picks among
|
|
47
|
+
* them: ghost buttons in a named group, each its label on the left and its
|
|
48
|
+
* value muted on the right, named for both ("Tomorrow, Thu, Nov 26").
|
|
49
|
+
*/
|
|
50
|
+
export declare function DateChoiceRows({ label, showLabel, choices, slot, }: {
|
|
51
|
+
label?: string;
|
|
52
|
+
/** The heading over the rows; `false` names the group without showing it (Quick Picks). */
|
|
53
|
+
showLabel?: boolean;
|
|
54
|
+
choices: readonly DateChoice[];
|
|
55
|
+
slot?: string;
|
|
56
|
+
}): import("react").JSX.Element | null;
|
|
57
|
+
/** A date popup's month: the day it's on marked, today ringed, a pick given as `'YYYY-MM-DD'`. */
|
|
58
|
+
export declare function DateChoiceCalendar({ value, today, weekStart, onPick, }: {
|
|
59
|
+
value?: PlainDate;
|
|
60
|
+
today?: PlainDate;
|
|
61
|
+
weekStart?: WeekdayCode;
|
|
62
|
+
onPick: (day: PlainDate) => void;
|
|
63
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A few choices, then the month calendar, opened from any trigger: a
|
|
3
|
+
// "move to" picker in DateField's look. The app gives its rows (a label,
|
|
4
|
+
// its value muted on the right, disabled or not) and the day the thing
|
|
5
|
+
// sits on; a row runs its own `onSelect` and a day picked in the calendar
|
|
6
|
+
// runs `onPick`, and either closes the popup.
|
|
7
|
+
//
|
|
8
|
+
// It is a dialog, never a menu: a calendar's grid can't sit inside a
|
|
9
|
+
// `role="menu"`, whose children are menu items. So the rows are buttons
|
|
10
|
+
// in a named group and the keyboard is DateField's: Tab goes through the
|
|
11
|
+
// rows, then the calendar (its month buttons, then its day, where the
|
|
12
|
+
// arrows move), Escape closes and focus goes back to the trigger. It
|
|
13
|
+
// opens on the first row that can be pressed, or on the calendar's day
|
|
14
|
+
// when there is none.
|
|
15
|
+
//
|
|
16
|
+
// DateField's own popup is built from the same parts: its quick picks are
|
|
17
|
+
// `DateChoiceRows`, and its calendar is `DateChoiceCalendar`.
|
|
18
|
+
import { useId, useRef, useState } from 'react';
|
|
19
|
+
import { cn } from 'cn';
|
|
20
|
+
import { Button } from '../ui/button.js';
|
|
21
|
+
import { Calendar } from '../ui/calendar.js';
|
|
22
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';
|
|
23
|
+
import { localToPlainDate, plainDateToLocal } from '../../lib/plain-date.js';
|
|
24
|
+
export function DateChoices({ trigger, children, label, choicesLabel, choices = [], value, today, onPick, weekStart, align = 'end', open: givenOpen, onOpenChange, className, }) {
|
|
25
|
+
const [ownOpen, setOwnOpen] = useState(false);
|
|
26
|
+
const open = givenOpen ?? ownOpen;
|
|
27
|
+
const popup = useRef(null);
|
|
28
|
+
const changeOpen = (next) => {
|
|
29
|
+
setOwnOpen(next);
|
|
30
|
+
onOpenChange?.(next);
|
|
31
|
+
};
|
|
32
|
+
// Closed first, then the app's own work: a row that moves the thing away
|
|
33
|
+
// (and unmounts the trigger) leaves nothing open behind it.
|
|
34
|
+
const close = (then) => {
|
|
35
|
+
changeOpen(false);
|
|
36
|
+
then();
|
|
37
|
+
};
|
|
38
|
+
return (_jsxs(Popover, { open: open, onOpenChange: changeOpen, children: [_jsx(PopoverTrigger, { render: trigger, children: children }), _jsxs(PopoverContent, { ref: popup, align: align, className: cn('w-auto p-0', className), "data-slot": "date-choices", "aria-label": label, initialFocus: () => popup.current?.querySelector('[data-slot="date-choice"]:not(:disabled)') ??
|
|
39
|
+
popup.current?.querySelector('button[data-day][tabindex="0"]') ??
|
|
40
|
+
true, children: [_jsx(DateChoiceRows, { label: choicesLabel, choices: choices.map((choice) => ({ ...choice, onSelect: () => close(choice.onSelect) })) }), _jsx(DateChoiceCalendar, { value: value, today: today, weekStart: weekStart, onPick: (day) => close(() => onPick(day)) })] })] }));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The rows over a date popup's calendar, DateField's quick picks among
|
|
44
|
+
* them: ghost buttons in a named group, each its label on the left and its
|
|
45
|
+
* value muted on the right, named for both ("Tomorrow, Thu, Nov 26").
|
|
46
|
+
*/
|
|
47
|
+
export function DateChoiceRows({ label, showLabel = true, choices, slot = 'date-choices-rows', }) {
|
|
48
|
+
const headingId = useId();
|
|
49
|
+
if (choices.length === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const shown = label && showLabel;
|
|
52
|
+
return (_jsxs("div", { role: "group", "aria-label": shown ? undefined : label, "aria-labelledby": shown ? headingId : undefined, "data-slot": slot, className: "flex flex-col gap-0.5 border-b border-border p-2", children: [shown && (_jsx("div", { id: headingId, className: "px-3 py-1 text-xs font-medium text-muted-foreground", children: label })), choices.map((choice) => (_jsxs(Button, { type: "button", variant: "ghost", size: "sm", "data-slot": "date-choice", disabled: choice.disabled, className: "w-full justify-between gap-4 font-normal", "aria-label": choice.value ? `${choice.label}, ${choice.value}` : choice.label, onClick: choice.onSelect, children: [_jsx("span", { children: choice.label }), choice.value && ' ', choice.value && _jsx("span", { className: "text-muted-foreground tabular-nums", children: choice.value })] }, choice.label)))] }));
|
|
53
|
+
}
|
|
54
|
+
// Calendar's `weekStartsOn` by code. Left out, it's Calendar's own default (Monday).
|
|
55
|
+
const WEEK_STARTS_ON = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 };
|
|
56
|
+
/** A date popup's month: the day it's on marked, today ringed, a pick given as `'YYYY-MM-DD'`. */
|
|
57
|
+
export function DateChoiceCalendar({ value, today, weekStart, onPick, }) {
|
|
58
|
+
const selected = value ? plainDateToLocal(value) : undefined;
|
|
59
|
+
return (_jsx(Calendar, { mode: "single",
|
|
60
|
+
// Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
|
|
61
|
+
required: true, selected: selected, defaultMonth: selected, today: today ? plainDateToLocal(today) : undefined, weekStartsOn: weekStart && WEEK_STARTS_ON[weekStart], onSelect: (date) => onPick(localToPlainDate(date)) }));
|
|
62
|
+
}
|
|
@@ -24,21 +24,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
24
24
|
// week start), or an app passes its own list. Each is a button named for
|
|
25
25
|
// its words and the day it sets ("Next Week, Mon, Nov 30"); pressing one
|
|
26
26
|
// sets that day and closes, as a day picked in the calendar does. Off
|
|
27
|
-
// unless asked for.
|
|
27
|
+
// unless asked for. The picks and the calendar are DateChoices' parts, the
|
|
28
|
+
// same rows and month an app's own "move to" picker shows.
|
|
28
29
|
import { useId, useRef, useState } from 'react';
|
|
29
30
|
import { CalendarIcon } from 'lucide-react';
|
|
30
31
|
import { cn } from 'cn';
|
|
31
32
|
import { Button } from '../ui/button.js';
|
|
32
|
-
import { Calendar } from '../ui/calendar.js';
|
|
33
33
|
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '../ui/input-group.js';
|
|
34
34
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';
|
|
35
35
|
import { DATE_QUICK_PICKS } from '../../lib/date-quick-picks.js';
|
|
36
|
-
import { formatPlainDate, localToPlainDate, parsePlainDate, plainDateExamples,
|
|
36
|
+
import { formatPlainDate, localToPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, } from '../../lib/plain-date.js';
|
|
37
|
+
import { DateChoiceCalendar, DateChoiceRows } from './date-choices.js';
|
|
37
38
|
export function DateField({ typing = true, onProblem, ...props }) {
|
|
38
39
|
return typing ? _jsx(TypedDate, { ...props, onProblem: onProblem }) : _jsx(DateButton, { ...props });
|
|
39
40
|
}
|
|
40
|
-
// Calendar's `weekStartsOn` by code. Left out, it's Calendar's own default (Monday).
|
|
41
|
-
const WEEK_STARTS_ON = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 };
|
|
42
41
|
// The quick picks over the calendar, each named for its words and its day,
|
|
43
42
|
// counted from the browser's own today when the calendar opens.
|
|
44
43
|
function QuickPicks({ picks, weekStart = 'MO', locale, onPick, }) {
|
|
@@ -46,10 +45,9 @@ function QuickPicks({ picks, weekStart = 'MO', locale, onPick, }) {
|
|
|
46
45
|
if (list.length === 0)
|
|
47
46
|
return null;
|
|
48
47
|
const today = localToPlainDate(new Date());
|
|
49
|
-
return (_jsx(
|
|
48
|
+
return (_jsx(DateChoiceRows, { label: "Quick Picks", showLabel: false, slot: "date-field-quick-picks", choices: list.map((pick) => {
|
|
50
49
|
const day = pick.day(today, weekStart);
|
|
51
|
-
|
|
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));
|
|
50
|
+
return { label: pick.label, value: formatPlainDate(day, { weekday: 'short', month: 'short', day: 'numeric' }, locale), onSelect: () => onPick(day) };
|
|
53
51
|
}) }));
|
|
54
52
|
}
|
|
55
53
|
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 }) {
|
|
@@ -125,20 +123,16 @@ function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, cleara
|
|
|
125
123
|
changeOpen(true);
|
|
126
124
|
}
|
|
127
125
|
};
|
|
128
|
-
const selected = plainDateToLocal(given);
|
|
129
126
|
const showProblem = told && problem !== null;
|
|
130
127
|
return (_jsxs("div", { "data-slot": "date-field", "data-kind": "date", className: cn('flex w-full min-w-0 flex-col gap-1.5', className), children: [_jsxs(InputGroup, { ref: group, children: [_jsx(InputGroupInput, { ref: box, id: id, value: text, onChange: (event) => type(event.target.value), onBlur: settle, onKeyDown: onKeyDown, placeholder: placeholder ?? plainDateExamples(locale), readOnly: readOnly, autoComplete: "off", "aria-invalid": invalid || showProblem || undefined, "aria-describedby": [showProblem ? messageId : null, describedBy].filter(Boolean).join(' ') || undefined, ...aria }), _jsx(InputGroupAddon, { align: "inline-end", children: _jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsx(PopoverTrigger, { render: _jsx(InputGroupButton, { type: "button", size: "icon-xs", variant: "ghost", disabled: readOnly, "aria-label": "Open Calendar" }), children: _jsx(CalendarIcon, { "aria-hidden": "true" }) }), _jsxs(PopoverContent, { ref: popup, anchor: group, align: "start", className: "w-auto p-0", "data-slot": "date-field-calendar", "aria-label": "Calendar",
|
|
131
128
|
// The day the keyboard starts from (the chosen one, else today).
|
|
132
129
|
initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true,
|
|
133
130
|
// Back to the box, where typing goes on.
|
|
134
|
-
finalFocus: box, children: [_jsx(QuickPicks, { picks: quickPicks, weekStart: weekStart, locale: locale, onPick: pick }), _jsx(
|
|
135
|
-
// Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
|
|
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 }))] }));
|
|
131
|
+
finalFocus: box, children: [_jsx(QuickPicks, { picks: quickPicks, weekStart: weekStart, locale: locale, onPick: pick }), _jsx(DateChoiceCalendar, { value: given, weekStart: weekStart, onPick: pick }), 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 }))] }));
|
|
137
132
|
}
|
|
138
133
|
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 }) {
|
|
139
134
|
const [open, setOpen] = useState(defaultOpen && !readOnly);
|
|
140
135
|
const popup = useRef(null);
|
|
141
|
-
const selected = plainDateToLocal(value);
|
|
142
136
|
const shown = formatPlainDate(value, format, locale);
|
|
143
137
|
const changeOpen = (next) => {
|
|
144
138
|
if (next && readOnly)
|
|
@@ -155,7 +149,5 @@ function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date',
|
|
|
155
149
|
// The day the keyboard starts from (the chosen one, else today):
|
|
156
150
|
// the one day react-day-picker makes tabbable. The popup would
|
|
157
151
|
// otherwise take focus itself, past the Calendar's autoFocus.
|
|
158
|
-
initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true, children: [_jsx(QuickPicks, { picks: quickPicks, weekStart: weekStart, locale: locale, onPick: pick }), _jsx(
|
|
159
|
-
// Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
|
|
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" }) }))] })] }));
|
|
152
|
+
initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true, children: [_jsx(QuickPicks, { picks: quickPicks, weekStart: weekStart, locale: locale, onPick: pick }), _jsx(DateChoiceCalendar, { value: value, weekStart: weekStart, onPick: pick }), 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" }) }))] })] }));
|
|
161
153
|
}
|
|
@@ -120,6 +120,13 @@ export interface WidgetListItemProps {
|
|
|
120
120
|
lead?: ReactNode;
|
|
121
121
|
/** A small muted note after the text: "2 h ago", "holds 2". */
|
|
122
122
|
note?: ReactNode;
|
|
123
|
+
/**
|
|
124
|
+
* A muted line under the text: what the row is about in a few words
|
|
125
|
+
* ("Every day · 4 steps"). Unlike the text it isn't cut: on a narrow row
|
|
126
|
+
* it wraps, and the row grows to hold it. Outside the link, so it isn't
|
|
127
|
+
* part of the row's name.
|
|
128
|
+
*/
|
|
129
|
+
line?: ReactNode;
|
|
123
130
|
/**
|
|
124
131
|
* What ends the row: a badge, or a control. A control needs a name: pass
|
|
125
132
|
* a function, and put the id it gets in the control's `aria-labelledby`,
|
|
@@ -128,4 +135,4 @@ export interface WidgetListItemProps {
|
|
|
128
135
|
trailing?: ReactNode | ((rowTextId: string) => ReactNode);
|
|
129
136
|
className?: string;
|
|
130
137
|
}
|
|
131
|
-
export declare function WidgetListItem({ children, to, href, lead, note, trailing, className }: WidgetListItemProps): import("react").JSX.Element;
|
|
138
|
+
export declare function WidgetListItem({ children, to, href, lead, note, line, trailing, className }: WidgetListItemProps): import("react").JSX.Element;
|
|
@@ -142,15 +142,20 @@ function WidgetListSkeleton({ rows }) {
|
|
|
142
142
|
export function WidgetList({ children, className }) {
|
|
143
143
|
return (_jsx("ul", { "data-slot": "widget-list", className: cn('flex flex-col divide-y divide-border', className), children: children }));
|
|
144
144
|
}
|
|
145
|
+
// A row with a line under its text keeps room under the line at every
|
|
146
|
+
// density, so a wrapped line doesn't sit against the divider (a compact
|
|
147
|
+
// phone row has no padding of its own: its link's is the target).
|
|
148
|
+
const ROW_WITH_LINE_CLASS = 'density-compact:py-1.5 max-sm:density-compact:pb-2';
|
|
145
149
|
const ROW_LINK_CLASS = 'min-w-0 truncate rounded-sm font-medium text-foreground underline-offset-4 outline-none ' +
|
|
146
150
|
'hover:underline focus-visible:underline focus-visible:ring-3 focus-visible:ring-ring/50 ' +
|
|
147
151
|
'max-sm:density-compact:py-3';
|
|
148
|
-
export function WidgetListItem({ children, to, href, lead, note, trailing, className }) {
|
|
152
|
+
export function WidgetListItem({ children, to, href, lead, note, line, trailing, className }) {
|
|
149
153
|
const textId = useId();
|
|
150
154
|
const hasLead = lead !== undefined && lead !== null && lead !== false;
|
|
151
155
|
// With a lead the text is its own cut span after it, both on one line.
|
|
152
156
|
const words = hasLead ? (_jsxs(_Fragment, { children: [_jsx("span", { "data-slot": "widget-list-item-lead", "aria-hidden": "true", className: "inline-flex shrink-0", children: lead }), _jsx("span", { className: "min-w-0 truncate", children: children })] })) : (children);
|
|
153
157
|
const leadRow = hasLead && 'flex items-center gap-1.5';
|
|
154
158
|
const text = to !== undefined ? (_jsx(Link, { id: textId, to: to, title: children, className: cn(ROW_LINK_CLASS, leadRow), children: words })) : href !== undefined ? (_jsxs("a", { id: textId, href: href, target: "_blank", rel: "noreferrer", title: children, className: cn(ROW_LINK_CLASS, 'flex items-center gap-1', hasLead && 'gap-1.5'), children: [hasLead ? words : _jsx("span", { className: "truncate", children: children }), _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "size-3 shrink-0 text-muted-foreground" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] })) : (_jsx("span", { id: textId, title: children, className: cn('min-w-0 truncate text-foreground', leadRow), children: words }));
|
|
155
|
-
|
|
159
|
+
const hasLine = line !== undefined && line !== null && line !== false;
|
|
160
|
+
return (_jsxs("li", { "data-slot": "widget-list-item", className: cn(ROW_CLASS, 'type-body', hasLine && ROW_WITH_LINE_CLASS, className), children: [hasLine ? (_jsxs("span", { "data-slot": "widget-list-item-text", className: "flex min-w-0 flex-col gap-0.5", children: [text, _jsx("span", { "data-slot": "widget-list-item-line", className: "type-caption text-muted-foreground", children: line })] })) : (text), (note !== undefined || trailing !== undefined) && (_jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-3", children: [note !== undefined && _jsx("span", { className: "type-caption tabular-nums text-muted-foreground", children: note }), typeof trailing === 'function' ? trailing(textId) : trailing] }))] }));
|
|
156
161
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { DayPicker, type DayButton, type Locale } from "react-day-picker";
|
|
3
3
|
import { Button } from "./button.js";
|
|
4
|
-
declare function Calendar({ className, classNames, showOutsideDays, captionLayout, buttonVariant, weekStartsOn, locale, formatters, components, ...props }: React.ComponentProps<typeof DayPicker> & {
|
|
4
|
+
declare function Calendar({ className, classNames, showOutsideDays, captionLayout, buttonVariant, weekStartsOn, locale, formatters, components, labels, ...props }: React.ComponentProps<typeof DayPicker> & {
|
|
5
5
|
buttonVariant?: React.ComponentProps<typeof Button>["variant"];
|
|
6
6
|
}): React.JSX.Element;
|
|
7
7
|
declare function CalendarDayButton({ className, day, modifiers, locale, ...props }: React.ComponentProps<typeof DayButton> & {
|
|
@@ -9,11 +9,14 @@ function Calendar({ className, classNames, showOutsideDays = true, captionLayout
|
|
|
9
9
|
// Patched (ui-foundation): upstream leaves this to react-day-picker, which
|
|
10
10
|
// starts weeks on Sunday. Monday unless the caller says, the default of
|
|
11
11
|
// MonthCalendar, RecurrenceField and byDay; a `locale` doesn't change it.
|
|
12
|
-
weekStartsOn = 1, locale, formatters, components, ...props }) {
|
|
12
|
+
weekStartsOn = 1, locale, formatters, components, labels, ...props }) {
|
|
13
13
|
const defaultClassNames = getDefaultClassNames();
|
|
14
14
|
return (_jsx(DayPicker, { showOutsideDays: showOutsideDays, className: cn("group/calendar bg-background p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent", String.raw `rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw `rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className), captionLayout: captionLayout, weekStartsOn: weekStartsOn, locale: locale, formatters: {
|
|
15
15
|
formatMonthDropdown: (date) => date.toLocaleString(locale?.code, { month: "short" }),
|
|
16
16
|
...formatters,
|
|
17
|
+
}, labels: {
|
|
18
|
+
labelDayButton: (date, modifiers) => dayButtonLabel(date, modifiers, locale?.code),
|
|
19
|
+
...labels,
|
|
17
20
|
}, classNames: {
|
|
18
21
|
root: cn("w-fit", defaultClassNames.root),
|
|
19
22
|
months: cn("relative flex flex-col gap-4 md:flex-row", defaultClassNames.months),
|
|
@@ -65,6 +68,24 @@ weekStartsOn = 1, locale, formatters, components, ...props }) {
|
|
|
65
68
|
...components,
|
|
66
69
|
}, ...props }));
|
|
67
70
|
}
|
|
71
|
+
// Patched (ui-foundation): react-day-picker names a day "Monday, September
|
|
72
|
+
// 14th, 2026" (date-fns' PPPP), and axe's label-content-name-mismatch doesn't
|
|
73
|
+
// find the "14" the button shows in "14th". The locale's own long date
|
|
74
|
+
// ("Monday, September 14, 2026"), with react-day-picker's "Today, " and
|
|
75
|
+
// ", selected" kept, so the shown number is a word of the name.
|
|
76
|
+
function dayButtonLabel(date, modifiers, localeCode) {
|
|
77
|
+
let label = date.toLocaleDateString(localeCode ?? "en-US", {
|
|
78
|
+
weekday: "long",
|
|
79
|
+
month: "long",
|
|
80
|
+
day: "numeric",
|
|
81
|
+
year: "numeric",
|
|
82
|
+
});
|
|
83
|
+
if (modifiers.today)
|
|
84
|
+
label = `Today, ${label}`;
|
|
85
|
+
if (modifiers.selected)
|
|
86
|
+
label = `${label}, selected`;
|
|
87
|
+
return label;
|
|
88
|
+
}
|
|
68
89
|
function CalendarDayButton({ className, day, modifiers, locale, ...props }) {
|
|
69
90
|
const defaultClassNames = getDefaultClassNames();
|
|
70
91
|
const ref = React.useRef(null);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AppShell, type AppShellProps, type AppShellSearch, type RecentRecord, type SearchRecord, type AppShellVersion, type BottomBarItem, type NavEntry, type NavItem, type NavLook, type NavSection, } from './components/app/app-shell.js';
|
|
2
|
+
export { navItems, navPathname } from './components/app/app-shell-nav.js';
|
|
2
3
|
export type { IconComponent } from './components/app/icon-component.js';
|
|
3
4
|
export { Board, type BoardColumn, type BoardGroup, type BoardMoveTarget, type BoardPlace, type BoardProps } from './components/app/board.js';
|
|
4
5
|
export { SpinWheel, type SpinWheelProps } from './components/app/spin-wheel.js';
|
|
@@ -105,6 +106,7 @@ export { RatingStar, type RatingStarProps, type RatingStarValue } from './compon
|
|
|
105
106
|
export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
|
|
106
107
|
export { RatingInput, type RatingInputProps, type RatingInputSource } from './components/app/rating-input.js';
|
|
107
108
|
export { DateField, type DateFieldProps } from './components/app/date-field.js';
|
|
109
|
+
export { DateChoices, type DateChoice, type DateChoicesProps } from './components/app/date-choices.js';
|
|
108
110
|
export { addPlainDays, comingWeekday, DATE_QUICK_PICKS, NEXT_WEEK_PICK, THIS_WEEKEND_PICK, TODAY_PICK, TOMORROW_PICK, type DateQuickPick, } from './lib/date-quick-picks.js';
|
|
109
111
|
export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
|
|
110
112
|
export { Emoji, EmojiTile, type EmojiProps, type EmojiTileProps } from './components/app/emoji.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// points (`/gateway`, `/mocks`, `/testing`) so each stays behind its boundary.
|
|
5
5
|
// Composites
|
|
6
6
|
export { AppShell, } from './components/app/app-shell.js';
|
|
7
|
+
export { navItems, navPathname } from './components/app/app-shell-nav.js';
|
|
7
8
|
export { Board } from './components/app/board.js';
|
|
8
9
|
export { SpinWheel } from './components/app/spin-wheel.js';
|
|
9
10
|
export { pickSpinWheelIndex } from './components/app/spin-wheel-pick.js';
|
|
@@ -115,6 +116,7 @@ export { RatingStar } from './components/app/rating-star.js';
|
|
|
115
116
|
export { RatingScore } from './components/app/rating-score.js';
|
|
116
117
|
export { RatingInput } from './components/app/rating-input.js';
|
|
117
118
|
export { DateField } from './components/app/date-field.js';
|
|
119
|
+
export { DateChoices } from './components/app/date-choices.js';
|
|
118
120
|
export { addPlainDays, comingWeekday, DATE_QUICK_PICKS, NEXT_WEEK_PICK, THIS_WEEKEND_PICK, TODAY_PICK, TOMORROW_PICK, } from './lib/date-quick-picks.js';
|
|
119
121
|
export { EmojiField } from './components/app/emoji-field.js';
|
|
120
122
|
export { Emoji, EmojiTile } from './components/app/emoji.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.147.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": {
|