@speles7172/controls 0.6.3 → 0.7.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.
@@ -0,0 +1,262 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
3
+ import { civilFromFixed, fixedFromCivil, fixedFromIso, formatHebrewDate, hebrewFromFixed, isoFromFixed, } from '@speles7172/controls-client/core';
4
+ import { Calendar } from './Calendar.js';
5
+ import { CalendarIcon, CloseIcon, ICON_SIZE } from './icons.js';
6
+ import { useAnchoredPopover } from './useAnchoredPopover.js';
7
+ const DEFAULT_CALENDAR_LABELS = {
8
+ gregorian: 'Gregorian',
9
+ hebrew: 'Hebrew',
10
+ };
11
+ /**
12
+ * The order a locale writes a numeric date in, read off `Intl` rather than
13
+ * kept in a table — so `he`, `en-GB`, `de` and `en-US` each get theirs with no
14
+ * list to maintain.
15
+ */
16
+ export function dateOrder(locale) {
17
+ const parts = new Intl.DateTimeFormat(locale, {
18
+ timeZone: 'UTC',
19
+ day: '2-digit',
20
+ month: '2-digit',
21
+ year: 'numeric',
22
+ }).formatToParts(new Date(Date.UTC(2026, 10, 23, 12)));
23
+ const order = parts
24
+ .map((part) => part.type)
25
+ .filter((type) => type === 'day' || type === 'month' || type === 'year');
26
+ return order.length === 3 ? order : ['day', 'month', 'year'];
27
+ }
28
+ /** The day written in digits in the locale's order, e.g. `24/08/2026`. */
29
+ export function formatDay(iso, locale) {
30
+ const fixed = fixedFromIso(iso);
31
+ if (fixed === null)
32
+ return iso;
33
+ const date = civilFromFixed(fixed);
34
+ const text = {
35
+ day: String(date.day).padStart(2, '0'),
36
+ month: String(date.month).padStart(2, '0'),
37
+ year: String(date.year).padStart(4, '0'),
38
+ };
39
+ return dateOrder(locale)
40
+ .map((part) => text[part])
41
+ .join('/');
42
+ }
43
+ /**
44
+ * What somebody typed, as a day — or null when it is not one.
45
+ *
46
+ * ISO (`2026-08-24`) always reads as ISO. Anything else is three runs of
47
+ * digits in the locale's order, separated by anything: `24/8/2026`,
48
+ * `24.08.2026`, `24-8-26`. A two-digit year is this century. A day that does
49
+ * not exist — 31 April, 29 February in a common year — is not a day.
50
+ */
51
+ export function parseDay(text, locale) {
52
+ const trimmed = text.trim();
53
+ const iso = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(trimmed);
54
+ let year;
55
+ let month;
56
+ let day;
57
+ if (iso !== null) {
58
+ [year, month, day] = [Number(iso[1]), Number(iso[2]), Number(iso[3])];
59
+ }
60
+ else {
61
+ const runs = trimmed.split(/[^0-9]+/).filter((run) => run !== '');
62
+ if (runs.length !== 3)
63
+ return null;
64
+ const read = {};
65
+ dateOrder(locale).forEach((part, index) => {
66
+ read[part] = runs[index] ?? '';
67
+ });
68
+ const yearText = read.year ?? '';
69
+ if (yearText.length !== 2 && yearText.length !== 4)
70
+ return null;
71
+ year = yearText.length === 2 ? 2000 + Number(yearText) : Number(yearText);
72
+ month = Number(read.month);
73
+ day = Number(read.day);
74
+ }
75
+ if (month < 1 || month > 12 || day < 1 || day > 31 || year < 1)
76
+ return null;
77
+ const fixed = fixedFromCivil({ year, month, day });
78
+ const back = civilFromFixed(fixed);
79
+ if (back.year !== year || back.month !== month || back.day !== day)
80
+ return null;
81
+ return isoFromFixed(fixed);
82
+ }
83
+ function fill(template, key, value) {
84
+ return template.replace(`{${key}}`, value);
85
+ }
86
+ /**
87
+ * One date, as one form field.
88
+ *
89
+ * The single-day sibling of `<DateRangeFilter>`, for an expense's date or a
90
+ * payment's — where a bare `<input type="date">` is a native picker nobody can
91
+ * restyle, that writes the day in the *browser's* order rather than the
92
+ * application's, and that knows nothing of the Hebrew calendar.
93
+ *
94
+ * The day is typed or picked. The text box reads the locale's order (or ISO)
95
+ * and only hands a real day inside `min`/`max` to `onChange`; anything else
96
+ * marks the field invalid and leaves the value alone. The button beside it
97
+ * opens the same `<Calendar>` grid the range filter is built from, in either
98
+ * calendar, positioned by `useAnchoredPopover` so a dialog body never clips it.
99
+ *
100
+ * What it holds is a civil day, `YYYY-MM-DD`, and nothing else: which instant
101
+ * that day starts at is a question for the caller's time zone, not this field.
102
+ */
103
+ export function DateField({ value, onChange, label, labels = {}, locale, calendars = ['gregorian'], initialCalendar, hebrewLanguage = 'he', showHebrewDate, min, max, weekStartsOn = 0, today, disabled = false, required = false, id, name, 'aria-label': ariaLabel, placeholder, error, className, theme = 'light', 'data-testid': testId, }) {
104
+ const ids = useId();
105
+ const inputId = id ?? `${ids}-input`;
106
+ const rootRef = useRef(null);
107
+ const boxRef = useRef(null);
108
+ const buttonRef = useRef(null);
109
+ const inputRef = useRef(null);
110
+ const [openState, setOpen] = useState(false);
111
+ // A disabled field offers no calendar: one left open when the host disables
112
+ // the field (during a save, say) must not go on changing the value.
113
+ const open = openState && !disabled;
114
+ if (disabled && openState)
115
+ setOpen(false);
116
+ const popoverRef = useAnchoredPopover(open, boxRef);
117
+ const [calendar, setCalendar] = useState(initialCalendar ?? calendars[0] ?? 'gregorian');
118
+ const shown = value === null ? '' : formatDay(value, locale);
119
+ /**
120
+ * What is in the box. Follows the value whenever the value moves — a pick on
121
+ * the grid, the host resetting the form — and is the person's own text in
122
+ * between, so a half-typed date is not rewritten under the cursor.
123
+ */
124
+ const [text, setText] = useState(shown);
125
+ const [seen, setSeen] = useState({ value, locale });
126
+ const [problem, setProblemState] = useState(null);
127
+ // A new locale rewrites the box too: the text is read back in the locale's
128
+ // order, so `04/08/2026` written for `en-GB` and left in the box would be
129
+ // read as 8 April by `en-US`.
130
+ if (seen.value !== value || seen.locale !== locale) {
131
+ setSeen({ value, locale });
132
+ setText(shown);
133
+ setProblemState(null);
134
+ }
135
+ /**
136
+ * A typed date the field refuses is also refused by the form: the box is
137
+ * marked invalid for the browser's own validation, or submitting would send
138
+ * the previous day through the hidden input. Set at once, not only after the
139
+ * render, because a click on Submit blurs the box and submits in one gesture.
140
+ */
141
+ const setProblem = (next) => {
142
+ setProblemState(next);
143
+ inputRef.current?.setCustomValidity(next ?? '');
144
+ };
145
+ useLayoutEffect(() => {
146
+ inputRef.current?.setCustomValidity(problem ?? '');
147
+ }, [problem]);
148
+ const order = dateOrder(locale);
149
+ const format = order
150
+ .map((part) => part === 'day'
151
+ ? (labels.dayPlaceholder ?? 'DD')
152
+ : part === 'month'
153
+ ? (labels.monthPlaceholder ?? 'MM')
154
+ : (labels.yearPlaceholder ?? 'YYYY'))
155
+ .join('/');
156
+ /** Read the box, and hand the day on only when it is one the field accepts. */
157
+ const commitText = () => {
158
+ if (text.trim() === '') {
159
+ if (required) {
160
+ setProblem(labels.requiredMessage ?? 'Enter a date');
161
+ return;
162
+ }
163
+ setProblem(null);
164
+ if (value !== null)
165
+ onChange(null);
166
+ return;
167
+ }
168
+ const day = parseDay(text, locale);
169
+ if (day === null) {
170
+ setProblem(fill(labels.invalidMessage ?? 'Enter a date as {format}', 'format', format));
171
+ return;
172
+ }
173
+ if (min !== undefined && day < min) {
174
+ setProblem(fill(labels.tooEarlyMessage ?? 'Choose {min} or later', 'min', formatDay(min, locale)));
175
+ return;
176
+ }
177
+ if (max !== undefined && day > max) {
178
+ setProblem(fill(labels.tooLateMessage ?? 'Choose {max} or earlier', 'max', formatDay(max, locale)));
179
+ return;
180
+ }
181
+ setProblem(null);
182
+ // Normalised either way: `24.8.26` becomes `24/08/2026`.
183
+ setText(formatDay(day, locale));
184
+ if (day !== value)
185
+ onChange(day);
186
+ };
187
+ const close = (focusButton) => {
188
+ setOpen(false);
189
+ if (focusButton)
190
+ buttonRef.current?.focus();
191
+ };
192
+ const pick = (iso) => {
193
+ if (disabled)
194
+ return;
195
+ setProblem(null);
196
+ setText(formatDay(iso, locale));
197
+ if (iso !== value)
198
+ onChange(iso);
199
+ close(true);
200
+ };
201
+ const clear = () => {
202
+ setProblem(null);
203
+ setText('');
204
+ if (value !== null)
205
+ onChange(null);
206
+ inputRef.current?.focus();
207
+ };
208
+ /** Close on a click elsewhere, the same way the pickers do. */
209
+ useEffect(() => {
210
+ if (!open)
211
+ return;
212
+ const onPointerDown = (event) => {
213
+ if (rootRef.current !== null && !rootRef.current.contains(event.target)) {
214
+ setOpen(false);
215
+ }
216
+ };
217
+ document.addEventListener('mousedown', onPointerDown);
218
+ return () => document.removeEventListener('mousedown', onPointerDown);
219
+ }, [open]);
220
+ /** Opening puts the keyboard on the chosen day, so the arrows work at once. */
221
+ useEffect(() => {
222
+ if (!open)
223
+ return;
224
+ popoverRef.current
225
+ ?.querySelector('.ctl-cal-day[tabindex="0"]')
226
+ ?.focus();
227
+ }, [open, calendar, popoverRef]);
228
+ const onRootKeyDown = (event) => {
229
+ if (event.key === 'Escape' && open) {
230
+ event.preventDefault();
231
+ event.stopPropagation();
232
+ close(true);
233
+ }
234
+ };
235
+ const onInputKeyDown = (event) => {
236
+ if (event.key === 'Enter') {
237
+ // A typed date is committed, and a form around the field is not
238
+ // submitted with a value it has not seen yet.
239
+ event.preventDefault();
240
+ commitText();
241
+ }
242
+ else if (event.key === 'ArrowDown' && event.altKey) {
243
+ event.preventDefault();
244
+ setOpen(true);
245
+ }
246
+ };
247
+ const message = error ?? problem;
248
+ const hebrew = (showHebrewDate ?? calendars.includes('hebrew')) && value !== null ? hebrewOf(value, hebrewLanguage) : null;
249
+ const describedBy = [message === null || message === undefined ? null : `${ids}-error`, hebrew === null ? null : `${ids}-hebrew`]
250
+ .filter((entry) => entry !== null)
251
+ .join(' ');
252
+ return (_jsxs("div", { ref: rootRef, className: `ctl ctl-datefield${className === undefined ? '' : ` ${className}`}`, "data-ctl-theme": theme, "data-testid": testId, onKeyDown: onRootKeyDown, children: [label !== undefined && (_jsx("label", { className: "ctl-label", htmlFor: inputId, children: label })), _jsxs("div", { ref: boxRef, className: `ctl-datefield-box${disabled ? ' ctl-datefield-box-disabled' : ''}`, "data-ctl-invalid": message === null || message === undefined ? undefined : 'true', children: [_jsx("input", { ref: inputRef, id: inputId, type: "text", inputMode: "numeric", autoComplete: "off", className: "ctl-datefield-input", value: text, placeholder: placeholder ?? format, disabled: disabled, required: required, "aria-required": required || undefined, "aria-label": label === undefined ? ariaLabel : undefined, "aria-invalid": message === null || message === undefined ? undefined : true, "aria-describedby": describedBy === '' ? undefined : describedBy, onChange: (event) => setText(event.target.value), onBlur: commitText, onKeyDown: onInputKeyDown, "data-testid": testId === undefined ? undefined : `${testId}-input` }), _jsxs("span", { className: "ctl-trigger-icons", children: [!required && value !== null && !disabled && (_jsx("button", { type: "button", className: "ctl-icon-button", "aria-label": labels.clearLabel ?? 'Clear', title: labels.clearLabel ?? 'Clear', onClick: clear, "data-testid": testId === undefined ? undefined : `${testId}-clear`, children: _jsx(CloseIcon, { size: ICON_SIZE, "aria-hidden": "true" }) })), _jsx("button", { ref: buttonRef, type: "button", className: "ctl-icon-button", disabled: disabled, "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": labels.openCalendarLabel ?? 'Choose a date', title: labels.openCalendarLabel ?? 'Choose a date', onClick: () => setOpen(!open), "data-testid": testId === undefined ? undefined : `${testId}-trigger`, children: _jsx(CalendarIcon, { size: ICON_SIZE, "aria-hidden": "true" }) })] })] }), hebrew !== null && (_jsx("span", { className: "ctl-datefield-hebrew", id: `${ids}-hebrew`, dir: "auto", children: hebrew })), message !== null && message !== undefined && (_jsx("span", { className: "ctl-datefield-error ctl-error", id: `${ids}-error`, role: "alert", children: message })), open && (_jsxs("div", { className: "ctl-popover ctl-datefield-popover", ref: popoverRef, role: "dialog", "aria-label": labels.calendarLabel ?? label ?? ariaLabel, children: [calendars.length > 1 && (_jsx("div", { className: "ctl-datefield-calendars", role: "group", "aria-label": labels.calendarHeading, children: calendars.map((entry) => (_jsx("button", { type: "button", className: "ctl-daterange-chip", "aria-pressed": entry === calendar, onClick: () => setCalendar(entry), "data-testid": testId === undefined ? undefined : `${testId}-calendar-${entry}`, children: labels.calendars?.[entry] ?? DEFAULT_CALENDAR_LABELS[entry] }, entry))) })), _jsx(Calendar
253
+ // Remounted per calendar, so the month on screen is re-derived from
254
+ // the value in the calendar now drawn.
255
+ , { calendar: calendar, hebrewLanguage: hebrewLanguage, ...(locale === undefined ? {} : { locale }), from: value, to: value, onSelect: pick, ...(min === undefined ? {} : { min }), ...(max === undefined ? {} : { max }), ...(today === undefined ? {} : { today }), weekStartsOn: weekStartsOn, ...(labels.calendarLabel === undefined ? {} : { label: labels.calendarLabel }), ...(labels.previousMonthLabel === undefined ? {} : { previousLabel: labels.previousMonthLabel }), ...(labels.nextMonthLabel === undefined ? {} : { nextLabel: labels.nextMonthLabel }), theme: theme, ...(testId === undefined ? {} : { 'data-testid': `${testId}-calendar` }) }, calendar)] })), name !== undefined && _jsx("input", { type: "hidden", name: name, value: value ?? '' })] }));
256
+ }
257
+ /** That day, written the way the Hebrew calendar writes it. */
258
+ function hebrewOf(iso, language) {
259
+ const fixed = fixedFromIso(iso);
260
+ return fixed === null ? null : formatHebrewDate(hebrewFromFixed(fixed), { language });
261
+ }
262
+ //# sourceMappingURL=DateField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateField.js","sourceRoot":"","sources":["../src/DateField.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAC;AAChG,OAAO,EACL,cAAc,EACd,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,YAAY,GAGb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAyF7D,MAAM,uBAAuB,GAAsC;IACjE,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;CACjB,CAAC;AAIF;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAA0B;IAClD,M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AE,CAAC,CAAC;AACxF,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ReactNode } from 'react';
2
+ /** One fact about a record: what it is called, and what it is. */
3
+ export interface DetailItem {
4
+ label: ReactNode;
5
+ /** `null`, `undefined`, `''` and `false` read as "nothing on file" and show `emptyText`. */
6
+ value: ReactNode;
7
+ /** Take the whole row — for notes, an address, anything that wraps. */
8
+ wide?: boolean;
9
+ /** A stable key, when two labels are not plain strings or could repeat. */
10
+ key?: string;
11
+ }
12
+ export interface DetailListProps {
13
+ items: readonly DetailItem[];
14
+ /**
15
+ * Facts side by side. Default 2. Two collapse to one when the list itself is
16
+ * narrower than about 440px — measured on the list, not the screen, so a
17
+ * record in a narrow side panel reads as one column on a wide monitor too.
18
+ */
19
+ columns?: 1 | 2;
20
+ /** What an empty value shows. Default an em dash — never a blank, which reads as a missing field. */
21
+ emptyText?: ReactNode;
22
+ className?: string;
23
+ }
24
+ /**
25
+ * The read view of a record: label over value, two facts to a row.
26
+ *
27
+ * A `<dl>`, because that is what a list of named values is, and a screen reader
28
+ * announces it as one. Each fact is a `<div>` holding one `<dt>` and one `<dd>`,
29
+ * which HTML allows inside a `<dl>` and which is what lets a fact span the row.
30
+ *
31
+ * An empty value is an em dash rather than nothing, because a blank under a
32
+ * label reads as the page having failed to load it.
33
+ */
34
+ export declare function DetailList({ items, columns, emptyText, className }: DetailListProps): import("react").JSX.Element;
35
+ //# sourceMappingURL=DetailList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DetailList.d.ts","sourceRoot":"","sources":["../src/DetailList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,SAAS,CAAC;IACjB,4FAA4F;IAC5F,KAAK,EAAE,SAAS,CAAC;IACjB,uEAAuE;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2EAA2E;IAC3E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,qGAAqG;IACrG,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAMD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,OAAW,EAAE,SAAe,EAAE,SAAS,EAAE,EAAE,eAAe,+BAkB7F"}
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ function isEmpty(value) {
3
+ return value === null || value === undefined || value === false || value === '';
4
+ }
5
+ /**
6
+ * The read view of a record: label over value, two facts to a row.
7
+ *
8
+ * A `<dl>`, because that is what a list of named values is, and a screen reader
9
+ * announces it as one. Each fact is a `<div>` holding one `<dt>` and one `<dd>`,
10
+ * which HTML allows inside a `<dl>` and which is what lets a fact span the row.
11
+ *
12
+ * An empty value is an em dash rather than nothing, because a blank under a
13
+ * label reads as the page having failed to load it.
14
+ */
15
+ export function DetailList({ items, columns = 2, emptyText = '—', className }) {
16
+ return (_jsx("div", { className: `ctl-details-wrap${className === undefined ? '' : ` ${className}`}`, children: _jsx("dl", { className: `ctl-details ctl-details-cols-${columns}`, children: items.map((item, index) => (_jsxs("div", { className: `ctl-details-item${item.wide === true ? ' ctl-details-item-wide' : ''}`, children: [_jsx("dt", { className: "ctl-details-label", children: item.label }), _jsx("dd", { className: `ctl-details-value${isEmpty(item.value) ? ' ctl-details-empty' : ''}`, children: isEmpty(item.value) ? emptyText : item.value })] }, item.key ?? (typeof item.label === 'string' ? `${item.label}-${index}` : index)))) }) }));
17
+ }
18
+ //# sourceMappingURL=DetailList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DetailList.js","sourceRoot":"","sources":["../src/DetailList.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'react';
2
+ /**
3
+ * What an icon button's colour means once somebody reaches for it.
4
+ *
5
+ * Named for meaning, like a badge's tone: `danger` is a delete, `ok` an
6
+ * approve, `accent` the ordinary "act on this". At rest every tone is the same
7
+ * muted grey — six actions in a row are six quiet glyphs rather than a traffic
8
+ * light — and the colour arrives on hover and focus, as the answer to "what will
9
+ * this do".
10
+ */
11
+ export type IconButtonTone = 'neutral' | 'accent' | 'danger' | 'ok';
12
+ /** 28px for a row action in a dense table, 32px everywhere else. */
13
+ export type IconButtonSize = 'sm' | 'md';
14
+ /** The shape an icon in the controls' set has; any lucide icon fits. */
15
+ export type IconComponent = ComponentType<{
16
+ size?: number | string;
17
+ 'aria-hidden'?: boolean | 'true' | 'false';
18
+ }>;
19
+ export interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'title' | 'aria-label'> {
20
+ /** The glyph — a component from the controls' icon set, e.g. `EditIcon`. */
21
+ icon: IconComponent;
22
+ /**
23
+ * What pressing it does, in the reader's language. Required, and both the
24
+ * accessible name and the tooltip: an icon-only button carries no text, so
25
+ * this string is the whole of what names it — to a screen reader and, through
26
+ * `title`, to anyone hovering it. Name the record where a column of them
27
+ * repeats: `Delete Camps`, not `Delete`.
28
+ */
29
+ label: string;
30
+ tone?: IconButtonTone;
31
+ size?: IconButtonSize;
32
+ }
33
+ /**
34
+ * An icon-only button: the verb a table row repeats, or an action in a dialog's
35
+ * header.
36
+ *
37
+ * The label is not optional, because an unnamed icon button is invisible to a
38
+ * screen reader and a mystery on a touch screen; making it a required prop is
39
+ * what stops one being written. It is rendered as both `aria-label` and
40
+ * `title` from the one string, so the two can never drift apart.
41
+ *
42
+ * Carries no `.ctl` of its own — like `<Badge>`, it is an inline part that takes
43
+ * its tokens from the `.ctl` around it. Putting the class here would redeclare
44
+ * the light palette on every button and override a dark host.
45
+ */
46
+ export declare function IconButton({ icon: Icon, label, tone, size, type, className, ...rest }: IconButtonProps): import("react").JSX.Element;
47
+ //# sourceMappingURL=IconButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IconButton.d.ts","sourceRoot":"","sources":["../src/IconButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEpE,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;AAEzC,wEAAwE;AACxE,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,CAAC;AAElH,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,YAAY,CAAC;IAC1F,4EAA4E;IAC5E,IAAI,EAAE,aAAa,CAAC;IACpB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EACzB,IAAI,EAAE,IAAI,EACV,KAAK,EACL,IAAgB,EAChB,IAAW,EACX,IAAe,EACf,SAAS,EACT,GAAG,IAAI,EACR,EAAE,eAAe,+BAYjB"}
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * An icon-only button: the verb a table row repeats, or an action in a dialog's
4
+ * header.
5
+ *
6
+ * The label is not optional, because an unnamed icon button is invisible to a
7
+ * screen reader and a mystery on a touch screen; making it a required prop is
8
+ * what stops one being written. It is rendered as both `aria-label` and
9
+ * `title` from the one string, so the two can never drift apart.
10
+ *
11
+ * Carries no `.ctl` of its own — like `<Badge>`, it is an inline part that takes
12
+ * its tokens from the `.ctl` around it. Putting the class here would redeclare
13
+ * the light palette on every button and override a dark host.
14
+ */
15
+ export function IconButton({ icon: Icon, label, tone = 'neutral', size = 'md', type = 'button', className, ...rest }) {
16
+ return (_jsx("button", { ...rest, type: type, "aria-label": label, title: label, className: `ctl-icon-btn ctl-icon-btn-${size} ctl-icon-btn-${tone}${className === undefined ? '' : ` ${className}`}`, children: _jsx(Icon, { size: size === 'sm' ? 15 : 16, "aria-hidden": "true" }) }));
17
+ }
18
+ //# sourceMappingURL=IconButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IconButton.js","sourceRoot":"","sources":["../src/IconButton.tsx"],"names":[],"mappings":";AAmCA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,IAAI,EAAE,IAAI,EACV,KAAK,EACL,IAAI,GAAG,SAAS,EAChB,IAAI,GAAG,IAAI,EACX,IAAI,GAAG,QAAQ,EACf,SAAS,EACT,GAAG,IAAI,EACS;IAChB,OAAO,CACL,oBACM,IAAI,EACR,IAAI,EAAE,IAAI,gBACE,KAAK,EACjB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,6BAA6B,IAAI,iBAAiB,IAAI,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,EAAE,YAEpH,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAc,MAAM,GAAG,GACnD,CACV,CAAC;AACJ,CAAC"}
package/dist/Modal.d.ts CHANGED
@@ -22,6 +22,13 @@ export interface ModalProps {
22
22
  children: ReactNode;
23
23
  /** A row of actions pinned below the scrolling body. */
24
24
  footer?: ReactNode;
25
+ /**
26
+ * Actions drawn in the header, before the close button — an edit pencil, a
27
+ * history icon. Usually `<IconButton>`s; anything rendered here can leave the
28
+ * current form through {@link useModalGuard} and get the same unsaved-changes
29
+ * prompt the close button does.
30
+ */
31
+ headerActions?: ReactNode;
25
32
  /** Widen the panel for content that is mostly table, picture or stack trace. */
26
33
  wide?: boolean;
27
34
  /**
@@ -78,6 +85,21 @@ export interface ModalProps {
78
85
  className?: string;
79
86
  theme?: ControlTheme;
80
87
  }
88
+ /**
89
+ * Leave whatever the dialog is showing, asking first when a form in it holds
90
+ * unsaved edits — the same *Save / Discard / Keep editing* prompt the close
91
+ * button raises, but running `action` instead of closing.
92
+ */
93
+ export type ModalGuard = (action: () => void) => void;
94
+ /**
95
+ * The guard of the `<Modal>` around this component.
96
+ *
97
+ * For a control inside a dialog that moves away from a form without closing —
98
+ * a record's "back to the read view" — and must not drop somebody's typing
99
+ * silently on the way. `guard(() => setMode('view'))` switches at once when
100
+ * nothing was edited, and asks when something was.
101
+ */
102
+ export declare function useModalGuard(): ModalGuard;
81
103
  /**
82
104
  * The modal shell.
83
105
  *
@@ -111,5 +133,5 @@ export interface ModalProps {
111
133
  * so a dark console would open a light dialog. `position: fixed` covers the
112
134
  * viewport from wherever the element sits.
113
135
  */
114
- export declare function Modal({ title, onClose, children, footer, wide, closeLabel, dismissible, dirty, onSave, unsavedLabels, labelledBy, className, theme, }: ModalProps): import("react").JSX.Element;
136
+ export declare function Modal({ title, onClose, children, footer, headerActions, wide, closeLabel, dismissible, dirty, onSave, unsavedLabels, labelledBy, className, theme, }: ModalProps): import("react").JSX.Element;
115
137
  //# sourceMappingURL=Modal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../src/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,8FAA8F;AAC9F,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,K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AAC,MAAM,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAKtD;;;;;;;GAOG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AA0DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,aAAa,EACb,IAAY,EACZ,UAAoB,EACpB,WAAkB,EAClB,KAAK,EACL,MAAM,EACN,aAAa,EACb,UAAU,EACV,SAAS,EACT,KAAe,GAChB,EAAE,UAAU,+BAiUZ"}
package/dist/Modal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useId, useRef, useState } from 'react';
2
+ import { createContext, useContext, useEffect, useId, useRef, useState } from 'react';
3
3
  import { CheckIcon, CloseIcon, DeleteIcon } from './icons.js';
4
4
  const UNSAVED_LABELS = {
5
5
  title: 'Unsaved changes',
@@ -29,6 +29,19 @@ const UNSAVED_LABELS = {
29
29
  * right entry.
30
30
  */
31
31
  const openModals = [];
32
+ /** Outside a `<Modal>` there is nothing to guard, and the action runs at once. */
33
+ const ModalGuardContext = createContext((action) => action());
34
+ /**
35
+ * The guard of the `<Modal>` around this component.
36
+ *
37
+ * For a control inside a dialog that moves away from a form without closing —
38
+ * a record's "back to the read view" — and must not drop somebody's typing
39
+ * silently on the way. `guard(() => setMode('view'))` switches at once when
40
+ * nothing was edited, and asks when something was.
41
+ */
42
+ export function useModalGuard() {
43
+ return useContext(ModalGuardContext);
44
+ }
32
45
  /** What `body.style.overflow` was before the first modal took it. */
33
46
  let releasedOverflow = '';
34
47
  /** Everything a `Tab` can land on, in document order. */
@@ -108,7 +121,7 @@ function submitterOf(form) {
108
121
  * so a dark console would open a light dialog. `position: fixed` covers the
109
122
  * viewport from wherever the element sits.
110
123
  */
111
- export function Modal({ title, onClose, children, footer, wide = false, closeLabel = 'Close', dismissible = true, dirty, onSave, unsavedLabels, labelledBy, className, theme = 'light', }) {
124
+ export function Modal({ title, onClose, children, footer, headerActions, wide = false, closeLabel = 'Close', dismissible = true, dirty, onSave, unsavedLabels, labelledBy, className, theme = 'light', }) {
112
125
  const panel = useRef(null);
113
126
  const confirmPanel = useRef(null);
114
127
  const titleId = useId();
@@ -124,6 +137,20 @@ export function Modal({ title, onClose, children, footer, wide = false, closeLab
124
137
  const [confirming, setConfirming] = useState(false);
125
138
  /** The form *Save* submitted, whose leaving means the save went through. */
126
139
  const savedForm = useRef(null);
140
+ /**
141
+ * What finishes once the prompt is answered with Discard, or once a Save has
142
+ * gone through: `null` for closing the dialog, else the action a
143
+ * {@link useModalGuard} caller asked for.
144
+ */
145
+ const pendingAction = useRef(null);
146
+ const finish = () => {
147
+ const action = pendingAction.current;
148
+ pendingAction.current = null;
149
+ if (action === null)
150
+ onClose();
151
+ else
152
+ action();
153
+ };
127
154
  const onReach = (event) => {
128
155
  const form = event.target instanceof Element ? event.target.closest('form') : null;
129
156
  if (form === null || !panel.current?.contains(form))
@@ -144,26 +171,47 @@ export function Modal({ title, onClose, children, footer, wide = false, closeLab
144
171
  const requestClose = () => {
145
172
  if (!dismissible)
146
173
  return;
174
+ pendingAction.current = null;
147
175
  const unsaved = dirty ?? editedForm() !== null;
148
176
  if (unsaved)
149
177
  setConfirming(true);
150
178
  else
151
179
  onClose();
152
180
  };
181
+ /** The same question, for leaving a form without closing — see {@link useModalGuard}. */
182
+ const guard = (action) => {
183
+ // A locked dialog (a save under way) stays where it is, as its close does.
184
+ if (!dismissible)
185
+ return;
186
+ const unsaved = dirty ?? editedForm() !== null;
187
+ if (!unsaved) {
188
+ action();
189
+ return;
190
+ }
191
+ pendingAction.current = action;
192
+ setConfirming(true);
193
+ };
153
194
  const discard = () => {
154
195
  setConfirming(false);
155
- onClose();
196
+ // An earlier Save that was refused is over: its form leaving now is the discard, not that save.
197
+ savedForm.current = null;
198
+ finish();
156
199
  };
157
200
  const save = () => {
158
201
  setConfirming(false);
159
202
  if (onSave !== undefined) {
203
+ // The caller's save decides what happens next; a guarded action does not
204
+ // outlive it.
205
+ pendingAction.current = null;
160
206
  onSave();
161
207
  return;
162
208
  }
163
209
  const form = editedForm();
164
210
  const submitter = form === null ? null : submitterOf(form);
165
- if (form === null || submitter === null)
211
+ if (form === null || submitter === null) {
212
+ pendingAction.current = null;
166
213
  return;
214
+ }
167
215
  savedForm.current = form;
168
216
  form.requestSubmit(submitter);
169
217
  };
@@ -175,7 +223,7 @@ export function Modal({ title, onClose, children, footer, wide = false, closeLab
175
223
  useEffect(() => {
176
224
  if (savedForm.current !== null && !savedForm.current.isConnected) {
177
225
  savedForm.current = null;
178
- onClose();
226
+ finish();
179
227
  }
180
228
  });
181
229
  // Into the prompt when it opens, and back to the panel when it is waved away
@@ -226,8 +274,10 @@ export function Modal({ title, onClose, children, footer, wide = false, closeLab
226
274
  // the key that this dialog refused.
227
275
  event.stopPropagation();
228
276
  // Escape on the prompt is "keep editing" — the gentlest way out of it.
229
- if (confirming)
277
+ if (confirming) {
278
+ pendingAction.current = null;
230
279
  setConfirming(false);
280
+ }
231
281
  else
232
282
  requestClose();
233
283
  return;
@@ -298,13 +348,16 @@ export function Modal({ title, onClose, children, footer, wide = false, closeLab
298
348
  // this may be about to open, or out of the dialog left standing.
299
349
  event.preventDefault();
300
350
  requestClose();
301
- }, children: _jsxs("div", { className: `ctl-modal${wide ? ' ctl-modal-wide' : ''}${className ? ` ${className}` : ''}`, role: "dialog", "aria-modal": "true", "aria-labelledby": labelledBy ?? titleId, tabIndex: -1, ref: panel, onFocusCapture: onReach, onPointerDownCapture: onReach, onMouseDownCapture: onReach, children: [_jsxs("div", { className: "ctl-modal-head", children: [_jsx("h2", { className: "ctl-modal-title", id: titleId, children: title }), _jsx("button", { type: "button", className: "ctl-modal-close", "aria-label": closeLabel,
351
+ }, children: _jsxs("div", { className: `ctl-modal${wide ? ' ctl-modal-wide' : ''}${className ? ` ${className}` : ''}`, role: "dialog", "aria-modal": "true", "aria-labelledby": labelledBy ?? titleId, tabIndex: -1, ref: panel, onFocusCapture: onReach, onPointerDownCapture: onReach, onMouseDownCapture: onReach, children: [_jsxs("div", { className: "ctl-modal-head", children: [_jsx("h2", { className: "ctl-modal-title", id: titleId, children: title }), headerActions !== undefined && (_jsx("div", { className: "ctl-modal-head-actions", children: _jsx(ModalGuardContext.Provider, { value: guard, children: headerActions }) })), _jsx("button", { type: "button", className: "ctl-modal-close", "aria-label": closeLabel,
302
352
  // The same string on `title`: on a touch screen there is no hover,
303
353
  // and on a desktop the tooltip is the only thing that names an
304
354
  // icon-only control to somebody not using a screen reader.
305
- title: closeLabel, disabled: !dismissible, onClick: requestClose, children: _jsx(CloseIcon, { size: 18, "aria-hidden": "true" }) })] }), _jsx("div", { className: "ctl-modal-body", children: children }), footer !== undefined && _jsx("div", { className: "ctl-modal-foot", children: footer }), confirming && (
355
+ title: closeLabel, disabled: !dismissible, onClick: requestClose, children: _jsx(CloseIcon, { size: 18, "aria-hidden": "true" }) })] }), _jsxs(ModalGuardContext.Provider, { value: guard, children: [_jsx("div", { className: "ctl-modal-body", children: children }), footer !== undefined && _jsx("div", { className: "ctl-modal-foot", children: footer })] }), confirming && (
306
356
  // Inside the panel rather than a second modal: it asks about *this*
307
357
  // dialog, covers it, and needs none of the stack bookkeeping above.
308
- _jsx("div", { className: "ctl-modal-confirm-scrim", children: _jsxs("div", { className: "ctl-modal-confirm", role: "alertdialog", "aria-modal": "true", "aria-labelledby": `${confirmId}-title`, "aria-describedby": `${confirmId}-message`, tabIndex: -1, ref: confirmPanel, children: [_jsx("h3", { className: "ctl-modal-confirm-title", id: `${confirmId}-title`, children: words.title }), _jsx("p", { className: "ctl-modal-confirm-message", id: `${confirmId}-message`, children: canSave ? words.message : words.discardMessage }), _jsxs("div", { className: "ctl-modal-confirm-actions", children: [_jsx("button", { type: "button", className: "ctl-btn ctl-btn-ghost", onClick: () => setConfirming(false), children: words.keepEditing }), _jsxs("button", { type: "button", className: "ctl-btn ctl-btn-danger", onClick: discard, children: [_jsx(DeleteIcon, { size: 16, "aria-hidden": "true" }), words.discard] }), canSave && (_jsxs("button", { type: "button", className: "ctl-btn ctl-btn-primary", onClick: save, children: [_jsx(CheckIcon, { size: 16, "aria-hidden": "true" }), words.save] }))] })] }) }))] }) }));
358
+ _jsx("div", { className: "ctl-modal-confirm-scrim", children: _jsxs("div", { className: "ctl-modal-confirm", role: "alertdialog", "aria-modal": "true", "aria-labelledby": `${confirmId}-title`, "aria-describedby": `${confirmId}-message`, tabIndex: -1, ref: confirmPanel, children: [_jsx("h3", { className: "ctl-modal-confirm-title", id: `${confirmId}-title`, children: words.title }), _jsx("p", { className: "ctl-modal-confirm-message", id: `${confirmId}-message`, children: canSave ? words.message : words.discardMessage }), _jsxs("div", { className: "ctl-modal-confirm-actions", children: [_jsx("button", { type: "button", className: "ctl-btn ctl-btn-ghost", onClick: () => {
359
+ pendingAction.current = null;
360
+ setConfirming(false);
361
+ }, children: words.keepEditing }), _jsxs("button", { type: "button", className: "ctl-btn ctl-btn-danger", onClick: discard, children: [_jsx(DeleteIcon, { size: 16, "aria-hidden": "true" }), words.discard] }), canSave && (_jsxs("button", { type: "button", className: "ctl-btn ctl-btn-primary", onClick: save, children: [_jsx(CheckIcon, { size: 16, "aria-hidden": "true" }), words.save] }))] })] }) }))] }) }));
309
362
  }
310
363
  //# sourceMappingURL=Modal.js.map