@scalewing/react 1.72.0 → 1.73.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scalewing/react
2
2
 
3
+ ## 1.73.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f2143f2: New `MessageCard` (with `MessageCardProps`, `MessageCardAction`, `MessageCardActionVariant`, `MessageCardHeadingElement`, `messageCardActionVariants`, `messageCardHeadingElements`): a centred message on an outlined card where a screen cannot go on or has nothing yet, an optional muted `icon` (the consumer's Lucide glyph at size 24, hidden from assistive technology), a `title` (`h2` by default, or `h1` with `headingAs`), muted `lines` (two or fewer; more is allowed but not advised) and one `action` (`{ label, onPress, variant?: 'neutral' | 'primary', icon? }`). By default (`alert`) the card is `role="alert"` and its action takes the focus; `alert={false}` is a plain statement with no role and nothing focused. Blank words or an unknown `headingAs` or variant throw a `RangeError`. No new classes, tokens or dependencies. Request: `docs/requests/teisoro-message-card.md`.
8
+ - 318499b: New `PersonPicker` (with `PersonPickerProps`, `PersonPickerPerson`, `PersonPickerLabels`): people to choose from as large tiles, a `ListGroup` of `lg` tiles three across from `md` and one a row on a phone, each a button named by the person (or its `aria-label`) with an optional `tag`; `onChoose(id)`. From `searchFrom` people (13 by default) a search field narrows them to names starting with what was typed, ignoring capitals and accents, and the tiles scroll inside a named region four rows at a time; nobody left is a muted `role="status"` line. The first tile takes the focus on mount (`autoFocus`, default true). Every word comes from `labels` (`list`, `find`, `noMatch`). The pure filter is exported as `peopleStartingWith` with `comparableName`. No new classes, tokens or dependencies. Request: `docs/requests/teisoro-person-picker.md`.
9
+ - d226efd: New `PinStep` (with `PinStepProps`, `PinStepAction`, `PinStepHeadingElement`, `pinStepHeadingElements`): the step where someone enters a PIN on a shared screen. An optional ghost `back` Button at the top, an `eyebrow` (such as the person's name) over the `heading` (`h1` by default, or `h2` with `headingAs`), `PinField` with its pad and the focus (`autoFocus`, default true here), while `busy` a decorative `Spinner` and a `role="status"` line, and an optional ghost `secondaryAction` under it. Every other `PinField` prop passes through and the ref reaches the input. Blank words or an unknown `headingAs` throw a `RangeError`. No new classes, tokens or dependencies. Request: `docs/requests/teisoro-pin-step.md`.
10
+
3
11
  ## 1.72.0
4
12
 
5
13
  ### Minor Changes
package/README.md CHANGED
@@ -48,6 +48,7 @@ import {
48
48
  DescriptionList,
49
49
  DescriptionItem,
50
50
  EmptyState,
51
+ MessageCard,
51
52
  FixtureCard,
52
53
  FixtureGroup,
53
54
  FixtureRow,
@@ -55,6 +56,7 @@ import {
55
56
  DateToggleCalendar,
56
57
  ListGroup,
57
58
  ListRow,
59
+ PersonPicker,
58
60
  LiveRegion,
59
61
  MarkdownView,
60
62
  DenominationGrid,
@@ -64,6 +66,7 @@ import {
64
66
  Field,
65
67
  FileField,
66
68
  PinField,
69
+ PinStep,
67
70
  Article,
68
71
  Stepper,
69
72
  Steps,
@@ -316,6 +319,27 @@ The digits are never in the page. The input's own value is a mask, one `•` per
316
319
  />
317
320
  ```
318
321
 
322
+ `PinStep` is the step where someone enters a PIN on a shared screen, around `PinField`: an optional `back` (`{ label, onPress }`, a ghost Button at the top), an `eyebrow` (such as the person's name, label text) over the `heading` (heading size; `headingAs` `"h1"` by default, or `"h2"` under a page heading, `pinStepHeadingElements`), then `PinField` with its pad, focused on mount (`autoFocus`, true by default here), then while `busy` is set a decorative `Spinner` beside its words in a polite status line, a `LiveRegion` always mounted under the field (empty and taking no room while idle, so its words are read when they appear; pass `disabled` with it: busy does not disable the field), and an optional `secondaryAction` (`{ label, onPress }`, a ghost Button under it, such as "Forgot your PIN?"). It takes every other `PinField` prop (`label`, `labelVisuallyHidden`, `value`, `onChange`, `onComplete`, `length`, `disabled`, `description`, `error`, `labels`, `id`) and forwards its ref to the input, so you can put the focus back after a refused code. Spacing is a `Stack` gap 4, the eyebrow and heading gap 1. A blank heading, eyebrow, busy line or action label, or an unknown `headingAs`, throws a `RangeError`.
323
+
324
+ ```tsx
325
+ <PinStep
326
+ ref={field}
327
+ back={{ label: 'Back', onPress: backToNames }}
328
+ eyebrow={person.name}
329
+ heading="Enter your PIN"
330
+ label={`PIN for ${person.name}`}
331
+ labelVisuallyHidden
332
+ value={pin}
333
+ onChange={setPin}
334
+ onComplete={send}
335
+ disabled={checking}
336
+ busy={checking ? 'Checking…' : undefined}
337
+ description="Your four to six digits."
338
+ error={refused ? 'That PIN is not right.' : undefined}
339
+ secondaryAction={{ label: 'Forgot your PIN?', onPress: forgot }}
340
+ />
341
+ ```
342
+
319
343
  `Stepper` is a whole-number count changed with − and + or typed. The count is a native text input with `role="spinbutton"` and `inputmode="numeric"`, named by `label` (visible above it, or `labelVisuallyHidden` where table headers say it) and the one tab stop: ArrowUp and ArrowDown step it by `step` (default 1), Home goes to `min` and End to a finite `max` (a range below zero takes `inputmode="text"`, since a phone's numeric pad has no minus key). The − and + buttons are pointer targets outside the tab order, named by `decrementLabel` and `incrementLabel` (your copy), and a press on one leaves focus where it was; the count and both buttons sit in a `group` named by the label. − is disabled at `min` (default 0) and + at `max` (no upper bound when left out). `value` is a count or `null` for an empty box, which the buttons treat as `min` and `placeholder` can fill. Typed text is refused unless it is digits (with a leading minus when `min` is below zero), so `onChange` only receives a whole number or `null`; a typed count is reported as typed even outside the bounds, so say why in `error` (a polite message, `aria-invalid` and the danger border, as `Field`'s), and the buttons then move it back inside them. `aria-describedby` takes ids of elements that describe the count, such as the value it adds up to, read before an `error`'s message. `changed` takes `Field`'s changed look; `readOnly` keeps the count focusable and hides the buttons in their own room; `disabled` stops all three. `limitAppearance="plain"` (default `"faded"`) keeps − at `min` and + at `max` in their usual look instead of faded, for a count sheet where a faded − reads as broken; they are still disabled, a disabled or read-only Stepper is unchanged, forced colors still grey them, and an unknown value throws a `RangeError`. The count is a few digits wide and keeps that width (`width="fixed"`), or fills its container (`width="full"`, for a table cell). `unit` (opt-in) is a short muted word after the count inside its frame, such as "min" or "players": the frame (`sw-stepper-count`) draws the control surface, focus ring and the invalid, changed and disabled states, a press on the word focuses the count, and the count keeps its few-digit width with its digits against the word, so the frame never follows it. The word (`sw-stepper-unit`) is hidden from assistive technology; the count is read with it (`aria-valuetext` "90 min", none while the box is empty), and a `valueText` you pass wins. The default joins the count and the word as given, so a word that changes with the count ("players") reads "1 players": pass `valueText` in your language's right form ("1 player", "11 players"). A blank `unit` throws a `RangeError`. Bounds that are not whole numbers, `min` above `max`, or a `step` that is not above zero throw a `RangeError`.
320
344
 
321
345
  `Stepper` `onCommit` (opt-in) is the finished count once per entry, for a page that saves as you go: it fires on blur, on Enter (a form round the count still submits), and `commitDelay` ms (default 600) after the last − / + press or step key (ArrowUp, ArrowDown, Home, End), each press restarting the wait; blur or Enter while it waits commits at once. Typed digits never commit by themselves. It gives the count you hold at that moment, `null` or outside the bounds included as `onChange` reports them, so check it before saving. It does not fire when that count is the one last committed, or, before the first commit, the one held before the first edit; a count you set while nothing waits (a server's answer) becomes the new baseline. A commit still waiting when the Stepper unmounts is made then. `onChange` is unchanged. A `commitDelay` that is negative or not finite throws a `RangeError`.
@@ -1051,6 +1075,25 @@ Use `LiveRegion` rather than your own `role="status"` or `aria-live` whenever wo
1051
1075
  />
1052
1076
  ```
1053
1077
 
1078
+ `MessageCard` is a centred message on an outlined card where a screen cannot go on, or has nothing to show yet, such as a paused account, a list that could not load or a device that was removed: an optional `icon` over the `title`, up to two muted `lines`, and one `action`. The card is a `Card` (`variant="outlined"`, padding 6) holding a centred `Stack` (gap 3). `icon` is your Lucide glyph at spacing step 5 (`size={24} strokeWidth={1.75}`), drawn in the muted colour and hidden from assistive technology. `title` is a heading-size heading at `headingAs` (`messageCardHeadingElements`: `"h2"` by default, `"h1"` where the card is the whole page), centred. `lines` are muted centred paragraphs: two or fewer (more is allowed but not advised). An empty `icon` (nothing, `false`, `''`) draws no box. `action` is `{ label, onPress, variant?, icon? }`, a `Button` under them (padded by step 2) of `variant` `"neutral"` (the default, grey) or `"primary"` (where it is the page's one way on, `messageCardActionVariants`), its `icon` (a glyph at step 4) before its words. `alert` (default `true`) makes the card `role="alert"`, read when it appears, and gives its action the focus; `alert={false}` is a plain statement, nothing announced or focused, for a state the person did not cause. Use `EmptyState` for an empty list inside a page and `Notice` for a note in a page's flow. A blank title, line or action label, or an unknown `headingAs` or variant, throws a `RangeError`.
1079
+
1080
+ ```tsx
1081
+ <MessageCard
1082
+ icon={<CirclePause size={24} strokeWidth={1.75} aria-hidden />}
1083
+ title="This list is paused."
1084
+ lines={['Its owner can turn it back on.']}
1085
+ action={{ label: 'Go back', onPress: goBack }}
1086
+ />
1087
+
1088
+ <MessageCard
1089
+ alert={false}
1090
+ icon={<Users size={24} strokeWidth={1.75} aria-hidden />}
1091
+ title="Nobody is set up yet"
1092
+ lines={['Add someone in Settings to use this page.']}
1093
+ action={{ label: 'Open Settings', onPress: openSettings }}
1094
+ />
1095
+ ```
1096
+
1054
1097
  `GlyphTile` is a small rounded square in a categorical colour with the consumer's glyph in white: the mark of a kind beside its name, such as a service in a list. `hue` is one of the `@scalewing/tokens` categorical colours (`green`, `blue`, `orange`, `purple`, `teal`, `rose`, or `neutral`); which kind takes which hue is yours. `size` is `sm` (24), `md` (28, the default) or `lg` (32); the glyph is drawn at spacing step 4 in white, which keeps 3:1 on every fill; pass the SVG (a Lucide component) as the tile's direct child, since only a direct-child SVG is sized. It is always `aria-hidden`, so put the kind's name in visible text beside it. An unknown `hue` or `size` throws a `RangeError`. It may hold up to three letters in place of the glyph, such as initials (`<GlyphTile hue="neutral" size="sm">NSL</GlyphTile>`): words given as its children are drawn in one line at weight 600 and sized from the tile, not the text round it (one letter at half its side, two at 0.42, three at a third), so they fit every size; blank words or more than three letters throw a `RangeError`.
1055
1098
 
1056
1099
  ```tsx
@@ -1408,6 +1451,33 @@ The frame is centred at `SiteHeader`'s bar width with its gutters, so the naviga
1408
1451
 
1409
1452
  Each `ListRow` has a `title` (weight 600, or the body weight with `titleAppearance="plain"`; `tone="danger"` for a row that ends something), an optional muted `detail` line, an optional `value` at its end (weight 600, tabular figures; `valueTone` `success`, `danger`, `muted`, `accent` or `warning`, the warning colour's ink moved halfway to the text colour so it keeps 4.5:1 on the surface in every palette; `valueBadge` draws the value as a `Badge` in that tone instead, such as a status, still read in the row's name, never with `valueTone`; `valueDetail` a muted line under it) and an optional `leading` mark such as a status dot, hidden from assistive technology, so the words say what it means. With `onPress` the whole row is a button, and with `href` a link (`onPress` then takes a plain press for a client router); either adds a chevron, a quiet fill under the pointer and 44 px on a coarse pointer, and the row is named by its title and value and described by its detail lines (`aria-label` replaces the name). `selected` makes a pressable row a choice: a check while true, `aria-pressed` on a button or `aria-current` on a link (on a row with neither `onPress` nor `href` it throws, since nothing could read the state). `accessory="none"` hides the chevron of a row that acts in place; `disabled` blocks presses. A row with neither `onPress` nor `href` only states something. `maxHeight={{ rows }}` bounds the list to that many rows of a title and one detail line, the rest scrolling inside its own named region, which shades an edge with more rows past it; a bounded list must be named. `footer` stays pinned under the rows, outside the scroll, such as a `ListRow` with the count and the total (a row there is not a list item). An empty title or value, an unknown variant, tone or badge tone, a `valueDetail`, `valueTone` or `valueBadge` without a value, a value both toned and a badge, or a bad row count throws a `RangeError`.
1410
1453
 
1454
+ `PersonPicker` is people to choose from as large tiles, such as the names at a shared sign-in screen: a `ListGroup` of `lg` tiles (`tileColumns` 3 from `md`, one a row below it), each a `ListRow` button named by the person's `name` (or its `aria-label`, such as "Ada O., PIN locked", where the name alone is not enough), with an optional `tag` (a `Badge`) before its end and no chevron. `people` is `{ id, name, tag?, 'aria-label'? }[]` in the order to show them; `onChoose(id)` gets the pressed person's id. From `searchFrom` people (13 by default, a whole number from 1) a search `Field` labelled `labels.find` comes first and narrows the tiles to names starting with what was typed, its outer spaces trimmed, compared without capitals or accents (NFD, marks removed); the tiles then scroll inside a region named `labels.list`, four rows at a time (`maxHeight={{ rows: 4 }}`). With nobody to show, a muted `role="status"` line says `labels.noMatch`; while the search is shown that status is mounted from the start, empty and taking no room, so a screen reader reads its words when they appear (an empty `people` shows the line too). The first tile takes the focus when the picker mounts (`autoFocus`, default true; pass `false` where something else should); narrowing leaves the focus in the field. The same filter is exported as `peopleStartingWith(people, typed)`, with `comparableName`. Blank labels or names, a repeated id and a bad `searchFrom` throw a `RangeError`.
1455
+
1456
+ ```tsx
1457
+ <PersonPicker
1458
+ people={people.map((person) => ({
1459
+ id: person.id,
1460
+ name: person.name,
1461
+ ...(person.locked
1462
+ ? {
1463
+ 'aria-label': `${person.name}, PIN locked`,
1464
+ tag: (
1465
+ <Badge tone="warning" size="sm">
1466
+ PIN locked
1467
+ </Badge>
1468
+ ),
1469
+ }
1470
+ : {}),
1471
+ }))}
1472
+ onChoose={choose}
1473
+ labels={{
1474
+ list: 'Who’s working?',
1475
+ find: 'Find your name',
1476
+ noMatch: 'No name starts with that.',
1477
+ }}
1478
+ />
1479
+ ```
1480
+
1411
1481
  `FixtureRow` is one pairing of two sides, such as a game: `home` and `away` (`{ name, mark? }`, the mark a hidden crest beside the name on the centre's side), `center` (a kickoff time, `centerKind="time"`, the default, in a small grey chip, or a score, `"score"`, in bold figures; both tabular), then `meta` (muted, such as the field) and `status` (`{ label, tone }`, a small `Badge`) at the end. The home side ends at the centre and the away side starts from it, mirrored in right-to-left; names wrap. Rows live in a `FixtureGroup` (`{ title, children }`), a caption that names their list (a date and a venue): the list is one grid and each row a subgrid of it, so the centres and ends line up down the run whatever the names (a browser without subgrid, before Chrome 117 or Safari 16, draws each row on its own grid, unaligned). Below `md` the end moves under the sides; `metaHideBelow` (`md` or `lg`) leaves the meta out below it. With `href` the whole row is a link and with `onPress` alone a button (with both, `onPress` takes a plain press on the link for a client router), with a chevron, a hover fill, an inset focus ring and 44 px; `aria-label` names it in your words ("Heron Marsh with Otter Pool, 8:00"), otherwise it is named by what it shows, in order. A blank title, a row outside a group, a side without a name, a blank centre, an unknown `centerKind` or `metaHideBelow`, a bad status, a blank `href`, or an `aria-label` that is blank or on a row with neither `href` nor `onPress` throws a `RangeError`.
1412
1482
 
1413
1483
  ```tsx
@@ -0,0 +1,43 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare const messageCardHeadingElements: readonly ["h1", "h2"];
3
+ /** The title's level: `h2` (the default) in a page, `h1` where the card is the page. */
4
+ export type MessageCardHeadingElement = (typeof messageCardHeadingElements)[number];
5
+ export declare const messageCardActionVariants: readonly ["neutral", "primary"];
6
+ /** The action's look: `neutral` (the default) grey, or `primary` where it is the page's one way on. */
7
+ export type MessageCardActionVariant = (typeof messageCardActionVariants)[number];
8
+ /** The card's one button. */
9
+ export type MessageCardAction = {
10
+ label: string;
11
+ onPress: () => void;
12
+ variant?: MessageCardActionVariant;
13
+ /** A decorative glyph before the words (Lucide in the consumer, at spacing step 4). */
14
+ icon?: ReactNode;
15
+ };
16
+ export type MessageCardProps = {
17
+ /** What happened or what is true, such as "This list is paused." */
18
+ title: string;
19
+ /** `h2` (the default) or `h1`. */
20
+ headingAs?: MessageCardHeadingElement;
21
+ /** Muted lines under the title: two or fewer (more is allowed but not advised). None blank. */
22
+ lines?: readonly string[];
23
+ /**
24
+ * A decorative glyph over the title, drawn in the muted colour (Lucide
25
+ * in the consumer, at spacing step 5: `size={24} strokeWidth={1.75}`,
26
+ * `aria-hidden`).
27
+ */
28
+ icon?: ReactNode;
29
+ action?: MessageCardAction;
30
+ /**
31
+ * `true` (the default): the card is an alert, read when it appears, and
32
+ * its action takes the focus, for a refusal the person ran into.
33
+ * `false`: a plain statement, nothing announced or focused, for a state
34
+ * the person did not cause (such as nothing set up yet).
35
+ */
36
+ alert?: boolean;
37
+ };
38
+ /**
39
+ * A centred message on an outlined card, such as a screen that cannot go
40
+ * on: a muted glyph, a title, a line or two and one button. By default an
41
+ * alert whose button takes the focus.
42
+ */
43
+ export declare function MessageCard(props: MessageCardProps): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isOneOf } from '../is-one-of.js';
3
+ import { hasSlot } from './slot.js';
4
+ import { Box } from './Box.js';
5
+ import { Button } from './Button.js';
6
+ import { Card } from './Card.js';
7
+ import { Stack } from './Stack.js';
8
+ import { Text } from './Text.js';
9
+ export const messageCardHeadingElements = ['h1', 'h2'];
10
+ export const messageCardActionVariants = ['neutral', 'primary'];
11
+ function isBlank(value) {
12
+ return typeof value !== 'string' || value.trim() === '';
13
+ }
14
+ /** Fails closed on blank words or an unknown heading level or variant. */
15
+ function assertMessageCard({ title, headingAs, lines, action, }) {
16
+ if (isBlank(title))
17
+ throw new RangeError('MessageCard title must be nonempty');
18
+ if (headingAs !== undefined &&
19
+ !isOneOf(messageCardHeadingElements, headingAs))
20
+ throw new RangeError(`Unknown MessageCard headingAs: ${String(headingAs)}`);
21
+ if (lines?.some(isBlank))
22
+ throw new RangeError('MessageCard lines must be nonempty');
23
+ if (action === undefined)
24
+ return;
25
+ if (isBlank(action.label))
26
+ throw new RangeError('MessageCard action.label must be nonempty');
27
+ if (action.variant !== undefined &&
28
+ !isOneOf(messageCardActionVariants, action.variant))
29
+ throw new RangeError(`Unknown MessageCard action variant: ${String(action.variant)}`);
30
+ }
31
+ /**
32
+ * A centred message on an outlined card, such as a screen that cannot go
33
+ * on: a muted glyph, a title, a line or two and one button. By default an
34
+ * alert whose button takes the focus.
35
+ */
36
+ export function MessageCard(props) {
37
+ assertMessageCard(props);
38
+ const { title, headingAs = 'h2', lines = [], icon, action, alert = true, } = props;
39
+ return (_jsx(Card, { padding: 6, role: alert ? 'alert' : undefined, variant: "outlined", children: _jsxs(Stack, { align: "center", gap: 3, children: [hasSlot(icon) ? (_jsx(Text, { "aria-hidden": "true", as: "span", color: "muted", children: icon })) : null, _jsx(Text, { align: "center", as: headingAs, variant: "heading", children: title }), lines.map((line, index) => (_jsx(Text, { align: "center", color: "muted", children: line }, index))), action ? (_jsx(Box, { paddingTop: 2, children: _jsxs(Button, { autoFocus: alert, onPress: action.onPress, variant: action.variant ?? 'neutral', children: [action.icon, action.label] }) })) : null] }) }));
40
+ }
@@ -0,0 +1,44 @@
1
+ import { type ReactNode } from 'react';
2
+ /** One person to choose: their id, the name on the tile, and an optional status. */
3
+ export type PersonPickerPerson = {
4
+ id: string;
5
+ /** The name drawn on the tile, and the tile's name unless `aria-label` is given. */
6
+ name: string;
7
+ /** A status before the tile's end, such as a `Badge`, which describes the tile. */
8
+ tag?: ReactNode;
9
+ /** The tile's whole name where the name alone is not enough ("Ada O., locked"). */
10
+ 'aria-label'?: string;
11
+ };
12
+ /** PersonPicker's words, all of them the consumer's. */
13
+ export type PersonPickerLabels = {
14
+ /** Names the list (and, while it scrolls, its scroll region). */
15
+ list: string;
16
+ /** The search field's label. */
17
+ find: string;
18
+ /** Said when nobody's name starts with what was typed. */
19
+ noMatch: string;
20
+ };
21
+ export type PersonPickerProps = {
22
+ /** The people, in the order the tiles show them. Ids are unique, names not blank. */
23
+ people: readonly PersonPickerPerson[];
24
+ /** Called with the chosen person's id. */
25
+ onChoose: (id: string) => void;
26
+ labels: PersonPickerLabels;
27
+ /**
28
+ * From this many people (13 by default) a search field narrows the
29
+ * tiles to names starting with what was typed, and the tiles scroll
30
+ * inside their region, four rows at a time.
31
+ */
32
+ searchFrom?: number;
33
+ /** Focuses the first tile when the picker mounts. Default true. */
34
+ autoFocus?: boolean;
35
+ };
36
+ /**
37
+ * People to choose from as large tiles: three across from `md`, one a row
38
+ * below it, each a button named by the person. From `searchFrom` people a
39
+ * search field narrows them to names starting with what was typed (case
40
+ * and accents ignored) and the tiles scroll inside a named region, four
41
+ * rows at a time; nobody left is a muted status line. The first tile has
42
+ * the focus when the picker mounts.
43
+ */
44
+ export declare function PersonPicker({ people, onChoose, labels, searchFrom, autoFocus, }: PersonPickerProps): import("react").JSX.Element;
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { peopleStartingWith } from '../person-names.js';
5
+ import { Box } from './Box.js';
6
+ import { Field } from './Field.js';
7
+ import { ListGroup } from './ListGroup.js';
8
+ import { ListRow } from './ListRow.js';
9
+ import { Stack } from './Stack.js';
10
+ import { Text } from './Text.js';
11
+ /** The rows of tiles a scrolling picker shows at a time: 12 names three across. */
12
+ const scrollRows = 4;
13
+ const defaultSearchFrom = 13;
14
+ /** Fails closed on blank words, a bad threshold, or a blank or repeated person. */
15
+ function assertPersonPicker({ people, labels, searchFrom, }) {
16
+ for (const key of ['list', 'find', 'noMatch']) {
17
+ if (typeof labels[key] !== 'string' || labels[key].trim() === '')
18
+ throw new RangeError(`PersonPicker labels.${key} must be nonempty`);
19
+ }
20
+ if (!Number.isInteger(searchFrom) || searchFrom < 1)
21
+ throw new RangeError('PersonPicker searchFrom must be a whole number from 1');
22
+ const ids = new Set();
23
+ for (const person of people) {
24
+ if (person.name.trim() === '')
25
+ throw new RangeError('PersonPicker names must be nonempty');
26
+ if (ids.has(person.id))
27
+ throw new RangeError(`PersonPicker ids must be unique: ${person.id}`);
28
+ ids.add(person.id);
29
+ }
30
+ }
31
+ /**
32
+ * People to choose from as large tiles: three across from `md`, one a row
33
+ * below it, each a button named by the person. From `searchFrom` people a
34
+ * search field narrows them to names starting with what was typed (case
35
+ * and accents ignored) and the tiles scroll inside a named region, four
36
+ * rows at a time; nobody left is a muted status line. The first tile has
37
+ * the focus when the picker mounts.
38
+ */
39
+ export function PersonPicker({ people, onChoose, labels, searchFrom = defaultSearchFrom, autoFocus = true, }) {
40
+ assertPersonPicker({ people, labels, searchFrom });
41
+ const [typed, setTyped] = useState('');
42
+ const list = useRef(null);
43
+ const searching = people.length >= searchFrom;
44
+ const shown = searching ? peopleStartingWith(people, typed) : people;
45
+ // Read once: only the mount focuses, so a search narrowing the tiles
46
+ // leaves the focus in the field.
47
+ const focusOnMount = useRef(autoFocus);
48
+ useEffect(() => {
49
+ if (focusOnMount.current)
50
+ list.current?.querySelector('button')?.focus();
51
+ }, []);
52
+ return (_jsxs(Stack, { gap: 3, children: [searching ? (_jsx(Field, { label: labels.find, children: _jsx("input", { autoComplete: "off", onChange: (event) => setTyped(event.target.value), type: "search", value: typed }) })) : null, _jsxs(Box, { ref: list, children: [searching || shown.length === 0 ? (_jsx(Text, { color: "muted", role: "status", children: shown.length === 0 ? labels.noMatch : null })) : null, shown.length === 0 ? null : (_jsx(ListGroup, { "aria-label": labels.list, size: "lg", tileColumns: 3, variant: "tiles", ...(searching ? { maxHeight: { rows: scrollRows } } : {}), children: shown.map((person) => (_jsx(ListRow, { accessory: "none", "aria-label": person['aria-label'], onPress: () => onChoose(person.id), tag: person.tag, title: person.name }, person.id))) }))] })] }));
53
+ }
@@ -0,0 +1,52 @@
1
+ import { type PinFieldProps } from './PinField.js';
2
+ export declare const pinStepHeadingElements: readonly ["h1", "h2"];
3
+ /** The heading's level: `h1` (the default) where the step is the page, `h2` under a page heading. */
4
+ export type PinStepHeadingElement = (typeof pinStepHeadingElements)[number];
5
+ /** A quiet press action of the step: its words and what it does. */
6
+ export type PinStepAction = {
7
+ label: string;
8
+ onPress: () => void;
9
+ };
10
+ export type PinStepProps = Omit<PinFieldProps, 'pad'> & {
11
+ /** What the step asks, such as "Enter your PIN". */
12
+ heading: string;
13
+ /** `h1` (the default) or `h2`. */
14
+ headingAs?: PinStepHeadingElement;
15
+ /** A short line over the heading, such as the person's name. */
16
+ eyebrow?: string;
17
+ /** A ghost button at the top that leaves the step, such as Back. */
18
+ back?: PinStepAction;
19
+ /**
20
+ * While set, a decorative spinner and these words under the field, such
21
+ * as "Checking…", in a polite status that is always mounted (empty and
22
+ * taking no room while idle), so they are read. Pair it with `disabled`.
23
+ */
24
+ busy?: string;
25
+ /** A ghost button under the field, such as "Forgot your PIN?". */
26
+ secondaryAction?: PinStepAction;
27
+ };
28
+ /**
29
+ * The step where someone enters a PIN on a shared screen: an optional
30
+ * ghost Back, a short line over the heading, `PinField` with its pad
31
+ * (focused on mount), a spinner and a status line while the code is
32
+ * checked, and an optional ghost action under it. The ref reaches the
33
+ * field's input, to put the focus back after a refusal.
34
+ */
35
+ export declare const PinStep: import("react").ForwardRefExoticComponent<Omit<PinFieldProps, "pad"> & {
36
+ /** What the step asks, such as "Enter your PIN". */
37
+ heading: string;
38
+ /** `h1` (the default) or `h2`. */
39
+ headingAs?: PinStepHeadingElement;
40
+ /** A short line over the heading, such as the person's name. */
41
+ eyebrow?: string;
42
+ /** A ghost button at the top that leaves the step, such as Back. */
43
+ back?: PinStepAction;
44
+ /**
45
+ * While set, a decorative spinner and these words under the field, such
46
+ * as "Checking…", in a polite status that is always mounted (empty and
47
+ * taking no room while idle), so they are read. Pair it with `disabled`.
48
+ */
49
+ busy?: string;
50
+ /** A ghost button under the field, such as "Forgot your PIN?". */
51
+ secondaryAction?: PinStepAction;
52
+ } & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef } from 'react';
4
+ import { isOneOf } from '../is-one-of.js';
5
+ import { Box } from './Box.js';
6
+ import { Button } from './Button.js';
7
+ import { Inline } from './Inline.js';
8
+ import { LiveRegion } from './LiveRegion.js';
9
+ import { PinField } from './PinField.js';
10
+ import { Spinner } from './Spinner.js';
11
+ import { Stack } from './Stack.js';
12
+ import { Text } from './Text.js';
13
+ export const pinStepHeadingElements = ['h1', 'h2'];
14
+ function isBlank(value) {
15
+ return typeof value !== 'string' || value.trim() === '';
16
+ }
17
+ function assertAction(name, action) {
18
+ if (action !== undefined && isBlank(action.label))
19
+ throw new RangeError(`PinStep ${name}.label must be nonempty`);
20
+ }
21
+ /** Fails closed on blank words or an unknown heading level. */
22
+ function assertPinStep({ heading, headingAs, eyebrow, back, busy, secondaryAction, }) {
23
+ if (isBlank(heading))
24
+ throw new RangeError('PinStep heading must be nonempty');
25
+ if (headingAs !== undefined && !isOneOf(pinStepHeadingElements, headingAs))
26
+ throw new RangeError(`Unknown PinStep headingAs: ${String(headingAs)}`);
27
+ if (eyebrow !== undefined && isBlank(eyebrow))
28
+ throw new RangeError('PinStep eyebrow must be nonempty');
29
+ if (busy !== undefined && isBlank(busy))
30
+ throw new RangeError('PinStep busy must be nonempty');
31
+ assertAction('back', back);
32
+ assertAction('secondaryAction', secondaryAction);
33
+ }
34
+ /**
35
+ * The step where someone enters a PIN on a shared screen: an optional
36
+ * ghost Back, a short line over the heading, `PinField` with its pad
37
+ * (focused on mount), a spinner and a status line while the code is
38
+ * checked, and an optional ghost action under it. The ref reaches the
39
+ * field's input, to put the focus back after a refusal.
40
+ */
41
+ export const PinStep = forwardRef(function PinStep(props, ref) {
42
+ assertPinStep(props);
43
+ const { heading, headingAs = 'h1', eyebrow, back, busy, secondaryAction, autoFocus = true, ...field } = props;
44
+ return (_jsxs(Stack, { gap: 4, children: [back ? (_jsx(Inline, { children: _jsx(Button, { onPress: back.onPress, variant: "ghost", children: back.label }) })) : null, _jsxs(Stack, { gap: 1, children: [eyebrow !== undefined ? (_jsx(Text, { variant: "label", children: eyebrow })) : null, _jsx(Text, { as: headingAs, variant: "heading", children: heading })] }), _jsxs(Box, { children: [_jsx(PinField, { ...field, autoFocus: autoFocus, pad: true, ref: ref }), _jsx(Box, { paddingTop: busy === undefined ? undefined : 4, children: _jsxs(Inline, { align: "center", gap: 2, children: [busy === undefined ? null : _jsx(Spinner, { decorative: true }), _jsx(LiveRegion, { children: busy ?? '' })] }) })] }), secondaryAction ? (_jsx(Inline, { children: _jsx(Button, { onPress: secondaryAction.onPress, variant: "ghost", children: secondaryAction.label }) })) : null] }));
45
+ });
package/dist/index.d.ts CHANGED
@@ -9,8 +9,11 @@ export { DateRangeButton, type DateRangeButtonLabels, type DateRangeButtonProps,
9
9
  export { Article, articleTitleElements, type ArticleCover, type ArticleProps, type ArticleTitleElement, } from './components/Article.js';
10
10
  export { FileField, type FileFieldProps, type FileFieldValue, } from './components/FileField.js';
11
11
  export { defaultPinFieldLabels, PinField, type PinFieldLabels, type PinFieldProps, } from './components/PinField.js';
12
+ export { PinStep, pinStepHeadingElements, type PinStepAction, type PinStepHeadingElement, type PinStepProps, } from './components/PinStep.js';
12
13
  export { DocumentViewer, type DocumentViewerLabels, type DocumentViewerProps, } from './components/DocumentViewer.js';
13
14
  export { ListGroup, type ListGroupProps } from './components/ListGroup.js';
15
+ export { PersonPicker, type PersonPickerLabels, type PersonPickerPerson, type PersonPickerProps, } from './components/PersonPicker.js';
16
+ export { comparableName, peopleStartingWith } from './person-names.js';
14
17
  export { inspectMarkdown, markdownOmissionKinds, MarkdownView, type MarkdownHeading, type MarkdownInspection, type MarkdownImage, type MarkdownImageResolver, type MarkdownOmission, type MarkdownOmissionCounts, type MarkdownOmissionKind, type MarkdownOptions, type MarkdownViewProps, } from './components/MarkdownView.js';
15
18
  export { ListRow, type ListRowProps } from './components/ListRow.js';
16
19
  export { listGroupSizes, listGroupVariants, listRowTitleAppearances, listRowTones, listRowValueTones, type ListGroupMaxHeight, type ListGroupSize, type ListGroupVariant, type ListRowTitleAppearance, type ListRowTone, type ListRowValueTone, } from './list-options.js';
@@ -22,6 +25,7 @@ export { Spinner, type SpinnerProps, type SpinnerSize, } from './components/Spin
22
25
  export { LiveRegion, liveRegionPolitenesses, type LiveRegionPoliteness, type LiveRegionProps, } from './components/LiveRegion.js';
23
26
  export { Skeleton, skeletonVariants, type SkeletonProps, type SkeletonVariant, } from './components/Skeleton.js';
24
27
  export { EmptyState, emptyStateTitleElements, type EmptyStateProps, type EmptyStateTitleElement, } from './components/EmptyState.js';
28
+ export { MessageCard, messageCardActionVariants, messageCardHeadingElements, type MessageCardAction, type MessageCardActionVariant, type MessageCardHeadingElement, type MessageCardProps, } from './components/MessageCard.js';
25
29
  export { GlyphTile, glyphTileSizes, type GlyphTileHue, type GlyphTileProps, type GlyphTileSize, } from './components/GlyphTile.js';
26
30
  export { Notice, noticeTones, noticeVariants, type NoticeProps, type NoticeRole, type NoticeTone, type NoticeVariant, } from './components/Notice.js';
27
31
  export { Progress, progressTones, type ProgressProps, type ProgressTone, } from './components/Progress.js';
package/dist/index.js CHANGED
@@ -8,8 +8,11 @@ export { DateRangeButton, } from './components/DateRangeButton.js';
8
8
  export { Article, articleTitleElements, } from './components/Article.js';
9
9
  export { FileField, } from './components/FileField.js';
10
10
  export { defaultPinFieldLabels, PinField, } from './components/PinField.js';
11
+ export { PinStep, pinStepHeadingElements, } from './components/PinStep.js';
11
12
  export { DocumentViewer, } from './components/DocumentViewer.js';
12
13
  export { ListGroup } from './components/ListGroup.js';
14
+ export { PersonPicker, } from './components/PersonPicker.js';
15
+ export { comparableName, peopleStartingWith } from './person-names.js';
13
16
  export { inspectMarkdown, markdownOmissionKinds, MarkdownView, } from './components/MarkdownView.js';
14
17
  export { ListRow } from './components/ListRow.js';
15
18
  export { listGroupSizes, listGroupVariants, listRowTitleAppearances, listRowTones, listRowValueTones, } from './list-options.js';
@@ -21,6 +24,7 @@ export { Spinner, } from './components/Spinner.js';
21
24
  export { LiveRegion, liveRegionPolitenesses, } from './components/LiveRegion.js';
22
25
  export { Skeleton, skeletonVariants, } from './components/Skeleton.js';
23
26
  export { EmptyState, emptyStateTitleElements, } from './components/EmptyState.js';
27
+ export { MessageCard, messageCardActionVariants, messageCardHeadingElements, } from './components/MessageCard.js';
24
28
  export { GlyphTile, glyphTileSizes, } from './components/GlyphTile.js';
25
29
  export { Notice, noticeTones, noticeVariants, } from './components/Notice.js';
26
30
  export { Progress, progressTones, } from './components/Progress.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A name as PersonPicker compares it: decomposed (NFD), its combining marks
3
+ * removed, in lower case, so "Ángel" and "angel" are the same.
4
+ */
5
+ export declare function comparableName(value: string): string;
6
+ /**
7
+ * The people whose name starts with what was typed, ignoring case and
8
+ * accents and the typed words' outer spaces, in the order given. Nothing
9
+ * typed (or only spaces) keeps everyone.
10
+ */
11
+ export declare function peopleStartingWith<Person extends {
12
+ name: string;
13
+ }>(people: readonly Person[], typed: string): Person[];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A name as PersonPicker compares it: decomposed (NFD), its combining marks
3
+ * removed, in lower case, so "Ángel" and "angel" are the same.
4
+ */
5
+ export function comparableName(value) {
6
+ return value.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase('en');
7
+ }
8
+ /**
9
+ * The people whose name starts with what was typed, ignoring case and
10
+ * accents and the typed words' outer spaces, in the order given. Nothing
11
+ * typed (or only spaces) keeps everyone.
12
+ */
13
+ export function peopleStartingWith(people, typed) {
14
+ const start = comparableName(typed.trim());
15
+ if (start.length === 0)
16
+ return [...people];
17
+ return people.filter((person) => comparableName(person.name).startsWith(start));
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalewing/react",
3
- "version": "1.72.0",
3
+ "version": "1.73.0",
4
4
  "description": "Scalewing DOM components and package-owned CSS utilities.",
5
5
  "type": "module",
6
6
  "license": "MIT",