@mistriwork/ui 1.0.0-rc.62 → 1.0.0-rc.64

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.
@@ -11,14 +11,15 @@ import { type AriaAttributes, type KeyboardEvent, type ReactNode, type Ref } fro
11
11
  import { type ChangeDetails } from './changeDetails.js';
12
12
  /** What a date field says. A `format` is the locale's numeric date pattern ("MM/DD/YYYY"). */
13
13
  export interface DateFieldWords {
14
- /** The placeholder and the format a date and a time are typed in. */
15
- dateTimePattern: string;
16
- /** The box's complaint at a date and time it cannot take. */
17
- enterDateAndTime: string;
14
+ /** How a wall-clock time is written in the box ("HH:MM"). A date and a time are typed as the locale's date, then this:
15
+ the one format the box shows, the placeholder says and the hint reads. */
16
+ timePattern: string;
17
+ /** The box's complaint at a date and time it cannot take, given the format it takes. */
18
+ enterDateAndTime: (format: string) => string;
18
19
  /** The box's complaint at a date it cannot take. */
19
20
  enterDate: (format: string) => string;
20
21
  /** The hint read with the box: its format, for a date and a time. */
21
- dateAndTimeFormat: string;
22
+ dateAndTimeFormat: (format: string) => string;
22
23
  /** The hint read with the box: its format, for a date. */
23
24
  dateFormat: (format: string) => string;
24
25
  /** The hint's second sentence: the key that opens the calendar. */
package/dist/DateField.js CHANGED
@@ -45,6 +45,25 @@ function localeText(iso, mask) {
45
45
  return mask.order.map((type) => of[type]).join(mask.sep);
46
46
  }
47
47
  const isoDate = (text) => isPickerDate(text);
48
+ /** A date and a time as the box shows them: the locale's date, then the time as it is stored. */
49
+ function localeDateTime(iso, mask) {
50
+ const parts = splitDateTime(iso);
51
+ return parts ? `${localeText(parts.date, mask)} ${parts.time}` : iso;
52
+ }
53
+ /** What was typed as a date and a time, read in the locale's order (or ISO) as `YYYY-MM-DD HH:MM`, else undefined: a draft
54
+ stays text. */
55
+ function readDateTime(text, mask) {
56
+ const typed = text.trim();
57
+ if (isPickerDateTime(text))
58
+ return text;
59
+ const split = typed.match(/^(\S+)[ T](\d{1,2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?)$/);
60
+ if (!split)
61
+ return undefined;
62
+ const date = readDate(split[1], mask);
63
+ const time = /^\d:/.test(split[2]) ? `0${split[2]}` : split[2];
64
+ const iso = date && `${date} ${time}`;
65
+ return iso && isPickerDateTime(iso) ? iso : undefined;
66
+ }
48
67
  /** What was typed, read as a whole date in the locale's order (or ISO), else undefined: a draft stays text. */
49
68
  function readDate(text, mask) {
50
69
  if (isoDate(text))
@@ -117,9 +136,13 @@ function DefaultDateField({ id, words, calendarIcon, value, onChange, onBlur, on
117
136
  field is left, so a half-typed date is never rewritten under the caret. A date with a time stays ISO text. */
118
137
  const mask = useMemo(() => dateMask(locale), [locale]);
119
138
  const [draft, setDraft] = useState(null);
120
- const shown = withTime ? value : (draft ?? (isPickerDate(value) ? localeText(value, mask) : value));
139
+ const read = (text) => (withTime ? readDateTime(text, mask) : readDate(text, mask));
140
+ const shown = draft ??
141
+ (withTime ? (isPickerDateTime(value) ? localeDateTime(value, mask) : value) : isPickerDate(value) ? localeText(value, mask) : value);
142
+ /* One format, the locale's, for the box, its placeholder and the hint a screen reader hears. */
143
+ const pattern = withTime ? `${mask.hint} ${words.timePattern}` : mask.hint;
121
144
  useEffect(() => {
122
- if (draft !== null && value !== (readDate(draft, mask) ?? draft))
145
+ if (draft !== null && value !== (read(draft) ?? draft))
123
146
  setDraft(null);
124
147
  }, [value]); // eslint-disable-line react-hooks/exhaustive-deps
125
148
  const bad = !configuredBounds ||
@@ -128,8 +151,8 @@ function DefaultDateField({ id, words, calendarIcon, value, onChange, onBlur, on
128
151
  ? !isPickerDateTime(value) || !dateWithinBounds(datePart, bounds) || !dateTimeWithinBounds(value, min, max)
129
152
  : !dateWithinBounds(value, bounds)));
130
153
  useEffect(() => {
131
- input.current?.setCustomValidity(!bad ? '' : withTime ? words.enterDateAndTime : words.enterDate(mask.hint));
132
- }, [bad, withTime, mask]); // eslint-disable-line react-hooks/exhaustive-deps
154
+ input.current?.setCustomValidity(!bad ? '' : withTime ? words.enterDateAndTime(pattern) : words.enterDate(pattern));
155
+ }, [bad, withTime, pattern]); // eslint-disable-line react-hooks/exhaustive-deps
133
156
  /* While the calendar is open and what bounds it moves under it, the month in view goes to where a day can still
134
157
  be chosen, and the keyboard goes with it where it was on a day. */
135
158
  useLayoutEffect(() => {
@@ -194,17 +217,15 @@ function DefaultDateField({ id, words, calendarIcon, value, onChange, onBlur, on
194
217
  // The caller's class is a box's, and the box here is the text and its button together.
195
218
  className: className, onFocus: () => {
196
219
  ownedFocus.current = true;
197
- }, onBlur: leave, children: [_jsx(Input, { id: id, ref: input, name: name, type: "text", value: shown, placeholder: placeholder ?? (withTime ? words.dateTimePattern : mask.hint), disabled: disabled, required: required, autoComplete: "off", spellCheck: false, "aria-required": required, "aria-label": label, "aria-invalid": invalid || bad || undefined, "aria-describedby": [describedBy, hint].filter(Boolean).join(' '),
220
+ }, onBlur: leave, children: [_jsx(Input, { id: id, ref: input, name: name, type: "text", value: shown, placeholder: placeholder ?? pattern, disabled: disabled, required: required, autoComplete: "off", spellCheck: false, "aria-required": required, "aria-label": label, "aria-invalid": invalid || bad || undefined, "aria-describedby": [describedBy, hint].filter(Boolean).join(' '),
198
221
  /* React's own change, not UI SDK's `onValueChange`: that one hears the `input` event alone, and a value
199
222
  put in the box without one (a browser's autofill, a script that sets it and says `change`) would be
200
223
  shown and never reported. */
201
224
  onChange: (event) => {
202
225
  const text = event.target.value;
203
226
  const said = changeDetails('input-change', event);
204
- if (withTime)
205
- return onChange(text, said);
206
227
  setDraft(text);
207
- onChange(readDate(text, mask) ?? text, said);
228
+ onChange(read(text) ?? text, said);
208
229
  }, onKeyDown: (event) => {
209
230
  if (event.altKey && event.key === 'ArrowDown') {
210
231
  event.preventDefault();
@@ -220,7 +241,7 @@ function DefaultDateField({ id, words, calendarIcon, value, onChange, onBlur, on
220
241
  return;
221
242
  const day = isPickerDate(datePart) ? datePart : today;
222
243
  onChange(`${day} ${clock}`, changeDetails('input-change', event));
223
- } })), _jsxs("span", { id: hint, "data-slot": "date-field-hint", "data-kind": "visually-hidden", children: [withTime ? words.dateAndTimeFormat : words.dateFormat(mask.hint), " ", words.openWithKeys] }), _jsxs(Popover, { open: open && !shut, onOpenChange: (next, details) => {
244
+ } })), _jsxs("span", { id: hint, "data-slot": "date-field-hint", "data-kind": "visually-hidden", children: [withTime ? words.dateAndTimeFormat(pattern) : words.dateFormat(pattern), " ", words.openWithKeys] }), _jsxs(Popover, { open: open && !shut, onOpenChange: (next, details) => {
224
245
  // Escape hands the keyboard back to the button; a press elsewhere leaves it where the press put it.
225
246
  if (!next && details.reason === 'escape-key')
226
247
  returnToTrigger();
@@ -222,10 +222,10 @@ function heardDetails(callback, at, what) {
222
222
  }
223
223
  }
224
224
  const DATE_WORDS = {
225
- dateTimePattern: 'YYYY-MM-DD HH:MM',
226
- enterDateAndTime: 'Enter a date and time.',
225
+ timePattern: 'HH:MM',
226
+ enterDateAndTime: () => 'Enter a date and time.',
227
227
  enterDate: (format) => `Enter a date as ${format}.`,
228
- dateAndTimeFormat: 'Date and time format.',
228
+ dateAndTimeFormat: () => 'Date and time format.',
229
229
  dateFormat: (format) => `Date format: ${format}.`,
230
230
  openWithKeys: 'Alt and Down arrow opens the calendar.',
231
231
  chooseDate: (label) => `Pick a day for ${label ?? 'it'}`,
@@ -35,3 +35,5 @@ export declare function viewportSize(): {
35
35
  width: number;
36
36
  height: number;
37
37
  };
38
+ export declare const PHONE_QUERY = "(max-width: 760px)";
39
+ export declare const TABLET_QUERY = "(min-width: 761px) and (max-width: 1100px)";
@@ -53,3 +53,14 @@ export function viewportSize() {
53
53
  const z = viewportScale();
54
54
  return { width: window.innerWidth / z, height: window.innerHeight / z };
55
55
  }
56
+ /*
57
+ * The window's three bands, named once (docs/design.md, Mobile). A phone is up to 760px: one column, the
58
+ * navigation in a drawer, a list drawn as cards. A tablet is 761–1100px: the navigation folded to its icon rail, a
59
+ * record keeping its side column at 280px, a dashboard two-up. A desk is 1101px and wider. A media query measures
60
+ * the window in CSS pixels before the root's zoom, so these are read with matchMedia, not against the ruler above;
61
+ * the stylesheets say the same numbers in their @media rules, which cannot import them.
62
+ */
63
+ const PHONE_MAX = 760;
64
+ const DESK_MIN = 1101;
65
+ export const PHONE_QUERY = `(max-width: ${PHONE_MAX}px)`;
66
+ export const TABLET_QUERY = `(min-width: ${PHONE_MAX + 1}px) and (max-width: ${DESK_MIN - 1}px)`;
@@ -53,6 +53,28 @@
53
53
  flex-direction: column;
54
54
  gap: var(--m-space-1);
55
55
  }
56
+
57
+ /* The box, its words and their mark share one line. The rule above makes any other child of a check a column,
58
+ which stood the box over its label; the words are the box's target, and the box sits level with their first
59
+ line however many lines they run to. */
60
+ & > [data-slot='field-check-row'] {
61
+ flex-direction: row;
62
+ align-items: flex-start;
63
+ gap: var(--m-space-3h);
64
+ min-width: 0;
65
+ }
66
+
67
+ & > [data-slot='field-check-row'] > [data-slot='field-label'] {
68
+ flex: 1 1 auto;
69
+ min-width: 0;
70
+ cursor: pointer;
71
+ line-height: var(--m-leading);
72
+ }
73
+
74
+ & > [data-slot='field-check-row'] > :not([data-slot='field-label'], [data-slot='field-required'], [data-slot='field-optional']) {
75
+ flex: none;
76
+ margin-block-start: 0.2em;
77
+ }
56
78
  }
57
79
 
58
80
  /* One of a few: each choice is a card, and the chosen one wears the accent's edge and wash. The radio covers
package/dist/tokens.css CHANGED
@@ -52,6 +52,11 @@
52
52
  --status-warning: #9a4b12;
53
53
  --status-critical: #a12d2d;
54
54
  --status-info: #7a5cc0;
55
+ /* What an AI made (a generated draft's badge, a suggestion's edge, the
56
+ assistant's mark): a fuchsia, a hue no status colour and no look's info
57
+ wears, so a mark that says "a model wrote this" is never taken for good
58
+ news or a note. 3:1 as a mark on every ground; a theme's `ai` role replaces it. */
59
+ --ai: #a62a9c;
55
60
  /* Success, independent of --accent: an app may theme its accent indigo,
56
61
  and "good" must stay green there. */
57
62
  --status-good: #1f7a46;
@@ -88,6 +93,12 @@
88
93
  /* The one space under a room's head, to its first control or part: a list's filter bar and a free-form page's first
89
94
  part stand this far below the head's rule, so no kind of page starts further down than another. */
90
95
  --page-head-gap: var(--space-3);
96
+ /* The space from the top bar to a page's first heading, on every page that begins with one (a list, a settings room,
97
+ a dashboard, a record's name when no trail stands over it): one step, said once, because each head used to say its
98
+ own (14px, 20px, 16px) and the rooms stood at three heights. A step of the layout's, so a theme's rhythm moves it; a
99
+ phone takes the one below (the pane's gutter is 4px there, and 24px of air over a title is a third of a short
100
+ screen). Under a trail the title keeps the 16px the trail leaves (page.css). */
101
+ --page-top: var(--space-6);
91
102
  /* The space scale (docs/design.md, Space and text): every padding, margin
92
103
  and gap is a step of it or a semantic token over it. The steps from 16px
93
104
  up are the layout's and move with a theme's rhythm (themeFamilies.css);
@@ -187,6 +198,9 @@
187
198
  @media (pointer: coarse) {
188
199
  :root, :root[data-density] { --row-h: calc(44px / var(--density-zoom, 1)); }
189
200
  }
201
+ @media (max-width: 760px) {
202
+ :root { --page-top: var(--space-5); }
203
+ }
190
204
 
191
205
  /* The browser draws its own controls — a checkbox, a radio, a date's
192
206
  calendar, the window's scroll bar — in the scheme it is told. Untold, they
@@ -217,6 +231,7 @@
217
231
  --status-warning: #e0a05c;
218
232
  --status-critical: #e8756f;
219
233
  --status-info: #b39ae8;
234
+ --ai: #e58bdc;
220
235
  --status-good: #57b884;
221
236
  --shadow-pop: 0 6px 20px rgb(0 0 0 / 0.5);
222
237
  --shadow-panel: 0 10px 34px rgb(0 0 0 / 0.55);
@@ -244,6 +259,7 @@
244
259
  --status-warning: #e0a05c;
245
260
  --status-critical: #e8756f;
246
261
  --status-info: #b39ae8;
262
+ --ai: #e58bdc;
247
263
  --status-good: #57b884;
248
264
  --shadow-pop: 0 6px 20px rgb(0 0 0 / 0.5);
249
265
  --shadow-panel: 0 10px 34px rgb(0 0 0 / 0.55);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/ui",
3
- "version": "1.0.0-rc.62",
3
+ "version": "1.0.0-rc.64",
4
4
  "description": "The standalone React primitives both shells are drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and DateField over UI SDK, Switch, Tabs, Drawer, Popover, Avatar, Pagination, Carousel, Resizable, ScrollArea and Tooltip, the form controls built on them (text, masked, money and sensitive boxes, listboxes, choices, slider, progress and action bar; Preview), the landing hero's blocks (badge, photo tiles, icon rows; Preview), their tokens and stylesheet, and the zoom-aware ruler their popups are placed by.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {