@scalewing/react 1.64.0 → 1.66.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 +34 -0
- package/README.md +24 -1
- package/dist/components/Checkbox.d.ts +13 -1
- package/dist/components/Checkbox.js +6 -2
- package/dist/components/Field.js +1 -0
- package/dist/components/RadioGroup.d.ts +12 -1
- package/dist/components/RadioGroup.js +6 -2
- package/dist/components/SiteHeader.d.ts +8 -4
- package/dist/components/SiteHeader.js +10 -5
- package/dist/components/TaskList.d.ts +21 -2
- package/dist/components/TaskList.js +11 -6
- package/dist/components/checkbox/checkbox-appearance.d.ts +12 -0
- package/dist/components/checkbox/checkbox-appearance.js +16 -0
- package/dist/components/field/field-checks.d.ts +1 -1
- package/dist/components/field/field-checks.js +18 -1
- package/dist/components/field/field-props.d.ts +8 -0
- package/dist/components/radio-group/radio-group-description-layout.d.ts +9 -0
- package/dist/components/radio-group/radio-group-description-layout.js +11 -0
- package/dist/components/site-header/SiteHeaderSearch.d.ts +16 -0
- package/dist/components/site-header/SiteHeaderSearch.js +19 -0
- package/dist/components/site-header/types.d.ts +24 -0
- package/dist/components/site-header/validate.d.ts +1 -1
- package/dist/components/site-header/validate.js +22 -1
- package/dist/components/task-list/assert-task-list.d.ts +3 -0
- package/dist/components/task-list/assert-task-list.js +7 -0
- package/dist/css/css-checkbox-tile.d.ts +2 -0
- package/dist/css/css-checkbox-tile.js +67 -0
- package/dist/css/css-checkbox.js +4 -0
- package/dist/css/css-field-read-only.d.ts +2 -0
- package/dist/css/css-field-read-only.js +26 -0
- package/dist/css/css-field.js +4 -0
- package/dist/css/css-radio-group.js +5 -1
- package/dist/css/css-site-header-search.d.ts +2 -0
- package/dist/css/css-site-header-search.js +336 -0
- package/dist/css/css-site-header.js +6 -1
- package/dist/css/css-task-list-layout.d.ts +6 -0
- package/dist/css/css-task-list-layout.js +67 -0
- package/dist/css/css-task-list.js +5 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/styles.css +378 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @scalewing/react
|
|
2
2
|
|
|
3
|
+
## 1.66.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ce2cb82: Four opt-in options for a form's choices and a setup checklist (Teisoro F-001, request `docs/requests/teisoro-choice-layouts.md`). Every default is unchanged.
|
|
8
|
+
|
|
9
|
+
- `Checkbox appearance="tile"` (`checkboxAppearances`): the box, label and description in a bordered tile as wide as its column, the whole tile one press target, with the accent edge while chosen and the danger edge while invalid. New classes `sw-checkbox-tile`, `sw-checkbox-tile-checked`, `sw-checkbox-tile-invalid`.
|
|
10
|
+
- `RadioGroup descriptionLayout="stacked"` (`radioGroupDescriptionLayouts`): every option's description on its own line under its label at every width. New class `sw-radio-group-stacked`.
|
|
11
|
+
- `Field variant="read-only"`: a value shown, not typed, on the subtle fill with no edge; needs one `readOnly` native input or textarea. New class `sw-field-read-only`.
|
|
12
|
+
- `TaskList numbered` and `actionBelow="md"`: open tasks show their place in their ring, and below md each action takes a full-width line under the words. New classes `sw-task-list-numbered`, `sw-task-list-action-below-md`.
|
|
13
|
+
|
|
14
|
+
No new tokens or dependencies.
|
|
15
|
+
|
|
16
|
+
## 1.65.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- 3cfbc90: `SiteHeader search`: the site's search in the header, rendered on the server
|
|
21
|
+
with no script. `search` (`SiteHeaderSearchOptions`: `{ action, name?, label,
|
|
22
|
+
placeholder, labels: { open, close }, icon }`) is one GET form drawn once:
|
|
23
|
+
from `lg` an sm search field in the bar after the destinations, pushed to the
|
|
24
|
+
end with the actions; below `lg` a 44 px search button before the compact
|
|
25
|
+
actions that opens the same form over the whole window as a native popover
|
|
26
|
+
(the field at the body size so an iPhone does not zoom in, a close button
|
|
27
|
+
drawn with `closeIcon`, the results under it). Opening, Escape, closing and
|
|
28
|
+
submitting need no script (the consumer's script focuses the field on
|
|
29
|
+
`toggle`), and the form submits to `action` as `name` (default `q`). An
|
|
30
|
+
empty `hidden` results panel with a polite status, a list and a row
|
|
31
|
+
`template` is the consumer's script to fill: from `lg` it drops down under
|
|
32
|
+
the field as a raised panel, below `lg` it fills the window. New classes
|
|
33
|
+
`sw-site-header-search*`; blank words, a `name` that is not a plain
|
|
34
|
+
parameter name, or no `icon` throw a `RangeError`. No new tokens or
|
|
35
|
+
dependencies. Request: `docs/requests/futmas-site-header-search.md`.
|
|
36
|
+
|
|
3
37
|
## 1.64.0
|
|
4
38
|
|
|
5
39
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -140,6 +140,8 @@ Import the CSS once at the application entry. Do not copy it into your source tr
|
|
|
140
140
|
|
|
141
141
|
`TaskList` is a setup checklist: an `ol` (with `role="list"`, which Safari drops from a list without bullets) named by `label` holding one row per item of `items`, in order, a hairline between rows. Each item is `{ id, title, detail?, status, action? }` (`TaskListItem`): `status` (`taskListStatuses`: `'done' | 'next' | 'todo' | 'waiting'`, type `TaskListStatus`) draws a 24 px marker hidden from assistive technology, a different shape for each so colour is never the only cue: `done` a check on the success fill, `next` an accent ring round an accent dot, `todo` the grey hairline ring of a step ahead, and `waiting` a lock in the muted colour (waiting is not work that needs the person, so it is grey, not the warning amber). Then the `title` (label type, a waiting task's muted at the body weight), a muted caption `detail` under it, and `action` at the row's end, such as a small `Button`; the marker and the action sit on the row's middle, and on a narrow column an action that would leave the words less than half the row wraps to a line of its own at the row's end. Each title is read with its status word after a comma, as one visually hidden line ("Season, Done"; the drawn title is `aria-hidden`, as in a folded `Step`), then the detail, then the action. The words are English by default (`defaultTaskListLabels`: Done, Next step, To do, Waiting); `labels` (`Partial<TaskListLabels>`) takes yours, any you leave out or pass as `undefined` staying English. A row's text content holds the title twice (drawn, then spoken), so find a task in tests by its spoken line or by role. `action` may be a function given `{ titleId }`, the id of the drawn title, for the action's `aria-describedby` (or its `aria-labelledby` with its own id), so two "Change" buttons are told apart by their tasks out of the list. Scalewing holds no order rules and adds no `aria-current`: you set every status, and which action is the page's primary (the next task's, by convention) and which are `neutral`. On a coarse pointer the row's Buttons are 44 px like every Button, so rows grow. Forced colours draw every ring as a `CanvasText` border (the next one `Highlight`) and keep the check, dot and lock, which are borders. A blank `label`, status word, id, title or `detail`, a repeated id, or an unknown status throws a `RangeError`; an empty `items` draws an empty list. Other `ol` attributes (`className`, `id`, `data-*`, `aria-describedby`) pass through.
|
|
142
142
|
|
|
143
|
+
`TaskList` `numbered` (opt-in) draws each open task's place in the list (1, 2, …) inside its marker, so a step can be pointed at: a `todo` task's number in the muted colour on its grey ring, the `next` task's in the accent on the accent ring with its dot dropped (`CanvasText` in forced colours); `done` and `waiting` keep the check and the lock. The numbers are drawn only, as the list's own order says them. `actionBelow` (a layout breakpoint, `md`) moves each action, below that width, to a line of its own under the task's words, from where they start to the row's end, its control stretched to fill it: one full-width button per task on a phone. An unknown breakpoint throws a `RangeError`. New classes `sw-task-list-numbered`, `sw-task-list-action-below-md`.
|
|
144
|
+
|
|
143
145
|
```tsx
|
|
144
146
|
<TaskList
|
|
145
147
|
label="Get the spring survey ready"
|
|
@@ -242,6 +244,8 @@ A disabled native text control (`<input>`, `<select>` or `<textarea>` on the can
|
|
|
242
244
|
|
|
243
245
|
`Field` `variant="search"` (default `"outlined"`; `fieldVariants`) is a search box over one native `<input>` child with a `value`: the `label` is not drawn but still names the input, which becomes `type="search"` (a `searchbox`); `leading` is your glyph at the frame's start, such as a magnifier, hidden from assistive technology; and while the input holds text and is enabled and not read-only, a clear button named `clearLabel` ("Clear search") ends the frame, puts focus back in the input and calls `onClear` (set the value to `''`); Escape with text calls `onClear` too. The browser's own clear button is hidden, so there is one. The input gets `enterKeyHint="search"` unless you pass one. The frame is the adorned field's, so focus, `error`, `description`, `invalid` and the disabled look work as on any field; a press on the glyph focuses the input; the clear button is the 44 px target on a coarse pointer. A search field without a nonempty `clearLabel` or `onClear`, with `prefix` or `suffix`, or with a child that is not an `<input>` with a `value` throws; `leading`, `clearLabel` and `onClear` on an outlined field, or an unknown `variant`, throw too.
|
|
244
246
|
|
|
247
|
+
`Field` `variant="read-only"` is a value shown in a form that the person cannot change there, such as the email an invitation went to: the label stays above, and the control keeps its size but drops its edge for the subtle fill, in the text colour with a plain cursor, so it reads as given rather than as a field to type in, and apart from a disabled field's dashed edge. The native control stays focusable, selectable and sent with the form; `description` works as on any field. Forced colours keep a dotted `CanvasText` edge. It needs one native `<input>` or `<textarea>` child with `readOnly`, and takes no `prefix`, `suffix`, `error`, `invalid` or `changed` (a `TypeError` otherwise): a value the person cannot change is never marked invalid or changed. New class `sw-field-read-only`.
|
|
248
|
+
|
|
245
249
|
```tsx
|
|
246
250
|
<Field label="Drop amount" prefix="$">
|
|
247
251
|
<input inputMode="decimal" name="drop" />
|
|
@@ -597,8 +601,12 @@ A toast can also be a corner card that confirms a save: `placement="top-end"` pu
|
|
|
597
601
|
|
|
598
602
|
`Checkbox` `labelVisuallyHidden` (opt-in) keeps `label` as the checkbox's name but does not draw it, for a box that stands alone, such as a table's select column ("Select Mallard"); the box is then its own target, its drawn size (24 px) on a fine pointer and at least 44 × 44 px on a coarse one. `indeterminate` (opt-in) is the mixed state, such as "Select all" while only some rows are chosen: a dash on the accent fill (Highlight in forced colours), the native `indeterminate` property and `aria-checked="mixed"`, so Playwright's `toBeChecked({ indeterminate: true })` and `getByRole('checkbox', { checked: 'mixed' })` find it (Testing Library's `checked` query ignores the mixed state of a native checkbox; assert `aria-checked="mixed"` or the `indeterminate` property there). It wins over `checked` in the drawing and the state read out. A press reports `!checked` (with `checked` false: `true`, choose all); the box stays mixed until the props change.
|
|
599
603
|
|
|
604
|
+
`Checkbox` `appearance="tile"` (default `"plain"`; `checkboxAppearances`, `CheckboxAppearance`) draws the box, the label and the description inside a bordered tile (the md radius, a hairline in the border colour) as wide as its column, at least 52 px tall, for a set of choices laid out in a `Grid`, such as a store's services. The label's `::after` covers the whole tile, so a press anywhere on it, the description included, toggles the box; the name and description are unchanged. A chosen or mixed tile takes the accent edge and an invalid one the danger edge (which wins), each twice the hairline through an inset shadow so nothing moves; a disabled tile keeps its edge with its words faded. Forced colours draw the edges in `CanvasText`, `Highlight` and `Mark`. A tile with `labelVisuallyHidden`, or an unknown appearance, throws a `RangeError`. New classes `sw-checkbox-tile`, `sw-checkbox-tile-checked`, `sw-checkbox-tile-invalid`.
|
|
605
|
+
|
|
600
606
|
`RadioGroup` is a controlled fieldset of native radio choices. Supply a unique nonempty `value` for each option, one selected `value` or an empty value for no selection, a `legend`, and `onChange`. Long labels wrap in a vertical group. The consumer provides localized option labels and validation `error`; `required` keeps native form semantics. An option's optional `icon` (a `ReactNode`, such as a Lucide glyph) sits between the radio and the label, in the text color and the option's gap; it is `aria-hidden`, so the radio's accessible name stays the `label` text, and a press on it chooses the option as the label does.
|
|
601
607
|
|
|
608
|
+
`RadioGroup` `descriptionLayout="stacked"` (default `"auto"`; `radioGroupDescriptionLayouts`, `RadioGroupDescriptionLayout`) puts every option's description on a second line under its label at every width, starting under the label's words, for long descriptions (what a role may do) that would otherwise sit far from their radio at the row's end on a wide screen. An unknown layout throws a `RangeError`. New class `sw-radio-group-stacked`.
|
|
609
|
+
|
|
602
610
|
```tsx
|
|
603
611
|
<RadioGroup
|
|
604
612
|
legend="Check type"
|
|
@@ -1148,7 +1156,7 @@ const { headings, omissions } = inspectMarkdown(page.body, {
|
|
|
1148
1156
|
</Band>
|
|
1149
1157
|
```
|
|
1150
1158
|
|
|
1151
|
-
`SiteHeader` is a public site's header. Supply `brand` (such as a logo linked to the home page), `navLabel` and `items` (`{ id, label, href, current? }`, `current` as SectionNav's: `page`, `location` or `true` sets `aria-current`), `labels` (`openMenu`, `closeMenu`) and the decorative `menuIcon` and `closeIcon` glyphs. From `lg` the bar shows the brand, the destinations as a row of links (the current one at label weight over a bar in the words' colour, a thick underline in forced colours) and `actions` at its end, such as a language switch, Sign in (`Box as="a" link="quiet"`) and a `ButtonLink`. Below `lg` it shows the brand, `compactActions` and a menu button that opens, under the bar over the rest of the window, the destinations as large rows (the current one in the accent) and `menuActions` at the panel's foot, such as full-width `ButtonLink`s. The menu is a native `details`, so it opens and closes by touch, click and keyboard with no script, as a page rendered on the server needs; its `summary` is the button, named `openMenu` or `closeMenu` by its state. Script adds Escape (focus back on the button), and closes it when a link in it is chosen, focus leaves it, a press lands outside it, or the window widens to `lg`; nothing traps focus. A page rendered on the server has the no-script menu until it hydrates; a site that never hydrates keeps it, which still opens and closes. While the menu is open the bar's `compactActions` step aside (the menu holds its own `menuActions`), so the bar shows only the brand and the close button. The bar is 56 px tall below `lg` and 72 px from it, on the solid surface with a hairline under it; `sticky` (default `true`) keeps it at the window's top. While a sticky header is on the page the document's `scroll-padding-top` clears the bar, its hairline and a small gap, so a `#fragment` link, `:target` and `scrollIntoView` land below the bar instead of under it; a header with `sticky={false}` leaves the scroll padding alone. An optional `skipLink` (`{ label, href }`, such as `{ label: 'Skip to content', href: '#main' }`) is the header's first focusable element: visually hidden until it has focus, then a pill on the surface with the focus ring over the bar's start. Give the target (usually `main`) the matching `id`, and `tabIndex={-1}` so every browser moves focus there with the jump. No items, blank or repeated ids, blank labels or hrefs, a blank `navLabel` or menu label, or a skip link with a blank label or an `href` that is not a `#fragment` throw a `RangeError`.
|
|
1159
|
+
`SiteHeader` is a public site's header. Supply `brand` (such as a logo linked to the home page), `navLabel` and `items` (`{ id, label, href, current? }`, `current` as SectionNav's: `page`, `location` or `true` sets `aria-current`), `labels` (`openMenu`, `closeMenu`) and the decorative `menuIcon` and `closeIcon` glyphs. From `lg` the bar shows the brand, the destinations as a row of links (the current one at label weight over a bar in the words' colour, a thick underline in forced colours) and `actions` at its end, such as a language switch, Sign in (`Box as="a" link="quiet"`) and a `ButtonLink`. Below `lg` it shows the brand, `compactActions` and a menu button that opens, under the bar over the rest of the window, the destinations as large rows (the current one in the accent) and `menuActions` at the panel's foot, such as full-width `ButtonLink`s. The menu is a native `details`, so it opens and closes by touch, click and keyboard with no script, as a page rendered on the server needs; its `summary` is the button, named `openMenu` or `closeMenu` by its state. Script adds Escape (focus back on the button), and closes it when a link in it is chosen, focus leaves it, a press lands outside it, or the window widens to `lg`; nothing traps focus. A page rendered on the server has the no-script menu until it hydrates; a site that never hydrates keeps it, which still opens and closes. While the menu is open the bar's `compactActions` step aside (the menu holds its own `menuActions`), as does a `search` button, so the bar shows only the brand and the close button. The bar is 56 px tall below `lg` and 72 px from it, on the solid surface with a hairline under it; `sticky` (default `true`) keeps it at the window's top. While a sticky header is on the page the document's `scroll-padding-top` clears the bar, its hairline and a small gap, so a `#fragment` link, `:target` and `scrollIntoView` land below the bar instead of under it; a header with `sticky={false}` leaves the scroll padding alone. An optional `skipLink` (`{ label, href }`, such as `{ label: 'Skip to content', href: '#main' }`) is the header's first focusable element: visually hidden until it has focus, then a pill on the surface with the focus ring over the bar's start. Give the target (usually `main`) the matching `id`, and `tabIndex={-1}` so every browser moves focus there with the jump. No items, blank or repeated ids, blank labels or hrefs, a blank `navLabel` or menu label, or a skip link with a blank label or an `href` that is not a `#fragment` throw a `RangeError`.
|
|
1152
1160
|
|
|
1153
1161
|
```tsx
|
|
1154
1162
|
<SiteHeader
|
|
@@ -1173,6 +1181,21 @@ const { headings, omissions } = inspectMarkdown(page.body, {
|
|
|
1173
1181
|
/>
|
|
1174
1182
|
```
|
|
1175
1183
|
|
|
1184
|
+
An optional `search` (`SiteHeaderSearchOptions`: `{ action, name?, label, placeholder, labels: { open, close }, icon }`) adds the site's search. It is one GET form drawn once: from `lg` a search field in the bar (an sm pill with a hairline and the decorative `icon`, named `label`, showing `placeholder`), after the destinations and pushed to the bar's end with the `actions`; below `lg` a round search button (named `labels.open`, 44 px on touch) before the compact actions that opens the same form over the whole window as a native popover on the top layer, with the filled field at the top (the body size, so an iPhone does not zoom in), a close button beside it (named `labels.close`, drawn with `closeIcon`) and the results under it. Opening, closing (Escape or the close button) and submitting need no script: the form sends the query to `action` as `name` (default `q`), the site's results page. The popover is not modal and the browser moves no focus into it, so the site's script should focus the field on the popover's `toggle` event; with no script the reader taps the field. It needs Popover support (Safari 17, Firefox 125, Chrome 114); without it only the field from `lg` is drawn. An open search stays a full-window overlay if the window widens past `lg` until it is closed. The results are the consumer's: Scalewing draws an empty, `hidden` panel (`.sw-site-header-search-results`, which the field's `aria-controls` names) holding a polite status line (`.sw-site-header-search-status`), a list (`.sw-site-header-search-list`) and a row `template` (`.sw-site-header-search-row`: an `li` holding an `a.sw-site-header-search-result` with a `-title` and a `-text` span); a site's script fills them as the reader types and un-hides the panel. The status is a polite live region inside the panel, so write its final words after un-hiding it, in a later task (after the search resolves), or the first announcement may be missed. From `lg` the panel drops down under the field's end as a raised panel over the page, each result a row that takes the quiet fill on hover; below `lg` the results fill the window under the field, each a row with a hairline. A server render puts the row in the template's `content`; a client render leaves it as the template's child. A blank `action`, `label`, `placeholder` or button name, a `name` that is not a plain parameter name, or no `icon` throws a `RangeError`.
|
|
1185
|
+
|
|
1186
|
+
```tsx
|
|
1187
|
+
<SiteHeader
|
|
1188
|
+
…
|
|
1189
|
+
search={{
|
|
1190
|
+
action: '/docs/search/',
|
|
1191
|
+
label: 'Search the docs',
|
|
1192
|
+
placeholder: 'Search the docs',
|
|
1193
|
+
labels: { open: 'Search', close: 'Close search' },
|
|
1194
|
+
icon: <SearchIcon />,
|
|
1195
|
+
}}
|
|
1196
|
+
/>
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1176
1199
|
`Hero` is a public page's opening, a `section` named by its title: an optional `eyebrow` (muted label words), the `title` (the page's one `h1`, in the `hero` size), an optional `lead` (the `lead` size) and `actions` (links or buttons in a wrapping row, stacked to the full width below `md`), with an optional `media` picture. From `md` the picture keeps its own width at the row's end and the words take the rest; below `md` it sits centred under the words. With no picture the words keep the reading width (`--sw-reading-max`). Put it in the page's column (`sw-container`); it sets no gutter or fill of its own. The title always names the section (`aria-labelledby` is not a prop). Leave out `actions` or `media` rather than passing an empty fragment, which keeps its row or column. A blank `title` throws a `RangeError`.
|
|
1177
1200
|
|
|
1178
1201
|
```tsx
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type CheckboxAppearance } from './checkbox/checkbox-appearance.js';
|
|
2
|
+
export { checkboxAppearances, type CheckboxAppearance, } from './checkbox/checkbox-appearance.js';
|
|
1
3
|
export type CheckboxProps = {
|
|
2
4
|
label: string;
|
|
3
5
|
checked: boolean;
|
|
@@ -23,5 +25,15 @@ export type CheckboxProps = {
|
|
|
23
25
|
* stays mixed.
|
|
24
26
|
*/
|
|
25
27
|
indeterminate?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* `plain` (default) draws the box beside its words. `tile` draws the box,
|
|
30
|
+
* the label and the description inside a bordered tile as wide as its
|
|
31
|
+
* column, the whole tile one press target, so a set of tiles in a `Grid`
|
|
32
|
+
* reads as a set of choices (a store's services, say). A chosen (or
|
|
33
|
+
* mixed) tile takes the accent edge, an invalid one the danger edge. A
|
|
34
|
+
* tile needs its label drawn: with `labelVisuallyHidden`, or with an
|
|
35
|
+
* unknown appearance, it throws a `RangeError`.
|
|
36
|
+
*/
|
|
37
|
+
appearance?: CheckboxAppearance;
|
|
26
38
|
};
|
|
27
|
-
export declare function Checkbox({ label, checked, onCheckedChange, disabled, required, description, error, labelVisuallyHidden, indeterminate, }: CheckboxProps): import("react").JSX.Element;
|
|
39
|
+
export declare function Checkbox({ label, checked, onCheckedChange, disabled, required, description, error, labelVisuallyHidden, indeterminate, appearance, }: CheckboxProps): import("react").JSX.Element;
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId, useLayoutEffect, useRef } from 'react';
|
|
4
4
|
import { cx } from '../class-names.js';
|
|
5
|
+
import { assertCheckboxAppearance, } from './checkbox/checkbox-appearance.js';
|
|
5
6
|
import { CheckboxControl } from './checkbox/CheckboxControl.js';
|
|
6
7
|
import { FieldErrorRegion } from './FieldErrorRegion.js';
|
|
7
|
-
export
|
|
8
|
+
export { checkboxAppearances, } from './checkbox/checkbox-appearance.js';
|
|
9
|
+
export function Checkbox({ label, checked, onCheckedChange, disabled = false, required = false, description, error, labelVisuallyHidden = false, indeterminate = false, appearance = 'plain', }) {
|
|
10
|
+
assertCheckboxAppearance(appearance, labelVisuallyHidden);
|
|
11
|
+
const tile = appearance === 'tile';
|
|
8
12
|
const descriptionId = useId();
|
|
9
13
|
const errorId = useId();
|
|
10
14
|
const inputRef = useRef(null);
|
|
@@ -19,7 +23,7 @@ export function Checkbox({ label, checked, onCheckedChange, disabled = false, re
|
|
|
19
23
|
if (inputRef.current)
|
|
20
24
|
inputRef.current.indeterminate = indeterminate;
|
|
21
25
|
});
|
|
22
|
-
return (_jsxs("div", { className:
|
|
26
|
+
return (_jsxs("div", { className: cx('sw-checkbox', tile && 'sw-checkbox-tile', tile && (checked || indeterminate) && 'sw-checkbox-tile-checked', tile && Boolean(error) && 'sw-checkbox-tile-invalid'), children: [_jsxs("label", { className: cx('sw-checkbox-label', labelVisuallyHidden && 'sw-checkbox-label-hidden'), children: [_jsx(CheckboxControl, { ref: inputRef, "aria-checked": indeterminate ? 'mixed' : undefined, "aria-describedby": describedBy || undefined, "aria-invalid": Boolean(error), checked: checked, disabled: disabled, onChange: (event) => {
|
|
23
27
|
const input = event.currentTarget;
|
|
24
28
|
// The press cleared the mixed state; keep it until the props say.
|
|
25
29
|
input.indeterminate = indeterminate;
|
package/dist/components/Field.js
CHANGED
|
@@ -36,6 +36,7 @@ export function Field(props) {
|
|
|
36
36
|
size === 'xs' && 'sw-field-xs',
|
|
37
37
|
marksInvalid && 'sw-field-invalid',
|
|
38
38
|
search && 'sw-field-search-field',
|
|
39
|
+
variant === 'read-only' && 'sw-field-read-only',
|
|
39
40
|
changed && !marksInvalid && 'sw-field-changed',
|
|
40
41
|
width && 'sw-field-sized',
|
|
41
42
|
width && fieldWidthClass(width),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type RadioGroupOption } from './radio-group/RadioGroupOptionLabel.js';
|
|
2
|
+
import { type RadioGroupDescriptionLayout } from './radio-group/radio-group-description-layout.js';
|
|
2
3
|
export type { RadioGroupOption };
|
|
4
|
+
export { radioGroupDescriptionLayouts, type RadioGroupDescriptionLayout, } from './radio-group/radio-group-description-layout.js';
|
|
3
5
|
export type RadioGroupProps = {
|
|
4
6
|
legend: string;
|
|
5
7
|
value: string;
|
|
@@ -9,5 +11,14 @@ export type RadioGroupProps = {
|
|
|
9
11
|
disabled?: boolean;
|
|
10
12
|
description?: string;
|
|
11
13
|
error?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Where an option's description goes. `auto` (default): at the row's
|
|
16
|
+
* inline end while it fits beside the label, on a second line under the
|
|
17
|
+
* label when it does not or below md. `stacked`: always on a second line,
|
|
18
|
+
* starting under the label's words, so a long description (what a role
|
|
19
|
+
* may do, say) stays beside its radio on a wide screen. An unknown
|
|
20
|
+
* layout throws a `RangeError`.
|
|
21
|
+
*/
|
|
22
|
+
descriptionLayout?: RadioGroupDescriptionLayout;
|
|
12
23
|
};
|
|
13
|
-
export declare function RadioGroup({ legend, value, onChange, options, required, disabled, description, error, }: RadioGroupProps): import("react").JSX.Element;
|
|
24
|
+
export declare function RadioGroup({ legend, value, onChange, options, required, disabled, description, error, descriptionLayout, }: RadioGroupProps): import("react").JSX.Element;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId } from 'react';
|
|
4
|
+
import { cx } from '../class-names.js';
|
|
4
5
|
import { FieldErrorRegion } from './FieldErrorRegion.js';
|
|
5
6
|
import { RadioGroupOptionLabel, } from './radio-group/RadioGroupOptionLabel.js';
|
|
7
|
+
import { assertRadioGroupDescriptionLayout, } from './radio-group/radio-group-description-layout.js';
|
|
6
8
|
import { radioTabStopValue } from '../tab-stop.js';
|
|
7
|
-
export
|
|
9
|
+
export { radioGroupDescriptionLayouts, } from './radio-group/radio-group-description-layout.js';
|
|
10
|
+
export function RadioGroup({ legend, value, onChange, options, required = false, disabled = false, description, error, descriptionLayout = 'auto', }) {
|
|
11
|
+
assertRadioGroupDescriptionLayout(descriptionLayout);
|
|
8
12
|
const name = useId();
|
|
9
13
|
const descriptionId = useId();
|
|
10
14
|
const errorId = useId();
|
|
@@ -22,7 +26,7 @@ export function RadioGroup({ legend, value, onChange, options, required = false,
|
|
|
22
26
|
if (value !== '' && !values.includes(value))
|
|
23
27
|
throw new RangeError('value must match an option or be empty');
|
|
24
28
|
const entry = radioTabStopValue(options, value);
|
|
25
|
-
return (_jsxs("fieldset", { "aria-describedby": describedBy || undefined, "aria-invalid": Boolean(error), className:
|
|
29
|
+
return (_jsxs("fieldset", { "aria-describedby": describedBy || undefined, "aria-invalid": Boolean(error), className: cx('sw-radio-group', descriptionLayout === 'stacked' && 'sw-radio-group-stacked'), disabled: disabled, children: [_jsx("legend", { className: "sw-radio-group-legend", children: legend }), description ? (_jsx("span", { className: "sw-radio-group-description", id: descriptionId, children: description })) : null, _jsx("span", { className: "sw-radio-group-options", children: options.map((option) => (_jsx(RadioGroupOptionLabel, { checked: value === option.value, name: name, onSelect: () => {
|
|
26
30
|
if (!disabled && !option.disabled)
|
|
27
31
|
onChange(option.value);
|
|
28
32
|
}, option: option, required: required, isTabStop: option.value === entry }, option.value))) }), _jsx(FieldErrorRegion, { className: "sw-radio-group-error", id: errorId, message: error })] }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SiteHeaderProps } from './site-header/types.js';
|
|
2
|
-
export type { SiteHeaderItem, SiteHeaderLabels, SiteHeaderProps, SiteHeaderSkipLink, } from './site-header/types.js';
|
|
2
|
+
export type { SiteHeaderItem, SiteHeaderLabels, SiteHeaderProps, SiteHeaderSearchOptions, SiteHeaderSkipLink, } from './site-header/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* A public site's header: the brand at the start; from `lg` the main
|
|
5
5
|
* destinations as a row of links (the current one marked by weight and a
|
|
@@ -10,8 +10,12 @@ export type { SiteHeaderItem, SiteHeaderLabels, SiteHeaderProps, SiteHeaderSkipL
|
|
|
10
10
|
* page rendered on the server needs; script adds Escape (focus back on the
|
|
11
11
|
* button) and closes it when a link is chosen or focus leaves it. It traps
|
|
12
12
|
* no focus. While the menu is open the compact actions step aside, so the
|
|
13
|
-
* bar shows only the brand and the close button
|
|
14
|
-
*
|
|
13
|
+
* bar shows only the brand and the close button (the search button
|
|
14
|
+
* steps aside too). An optional skip link
|
|
15
|
+
* comes first, hidden until it has focus. An optional `search` is a field
|
|
16
|
+
* in the bar from `lg` and a search button below it that opens the same
|
|
17
|
+
* form over the window as a native popover (no script); its results panel
|
|
18
|
+
* is the consumer script's to fill. Invalid items or words throw a
|
|
15
19
|
* `RangeError`.
|
|
16
20
|
*/
|
|
17
|
-
export declare function SiteHeader({ actions, brand, closeIcon, compactActions, items, labels, menuActions, menuIcon, navLabel, skipLink, sticky, }: SiteHeaderProps): import("react").JSX.Element;
|
|
21
|
+
export declare function SiteHeader({ actions, brand, closeIcon, compactActions, items, labels, menuActions, menuIcon, navLabel, search, skipLink, sticky, }: SiteHeaderProps): import("react").JSX.Element;
|
|
@@ -4,6 +4,7 @@ import { useRef } from 'react';
|
|
|
4
4
|
import { cx } from '../class-names.js';
|
|
5
5
|
import { tabStop } from '../tab-stop.js';
|
|
6
6
|
import { SiteHeaderLinks } from './site-header/SiteHeaderLinks.js';
|
|
7
|
+
import { SiteHeaderSearch } from './site-header/SiteHeaderSearch.js';
|
|
7
8
|
import { useMenuDismiss } from './site-header/use-menu-dismiss.js';
|
|
8
9
|
import { assertSiteHeaderProps } from './site-header/validate.js';
|
|
9
10
|
/**
|
|
@@ -16,13 +17,17 @@ import { assertSiteHeaderProps } from './site-header/validate.js';
|
|
|
16
17
|
* page rendered on the server needs; script adds Escape (focus back on the
|
|
17
18
|
* button) and closes it when a link is chosen or focus leaves it. It traps
|
|
18
19
|
* no focus. While the menu is open the compact actions step aside, so the
|
|
19
|
-
* bar shows only the brand and the close button
|
|
20
|
-
*
|
|
20
|
+
* bar shows only the brand and the close button (the search button
|
|
21
|
+
* steps aside too). An optional skip link
|
|
22
|
+
* comes first, hidden until it has focus. An optional `search` is a field
|
|
23
|
+
* in the bar from `lg` and a search button below it that opens the same
|
|
24
|
+
* form over the window as a native popover (no script); its results panel
|
|
25
|
+
* is the consumer script's to fill. Invalid items or words throw a
|
|
21
26
|
* `RangeError`.
|
|
22
27
|
*/
|
|
23
|
-
export function SiteHeader({ actions, brand, closeIcon, compactActions, items, labels, menuActions, menuIcon, navLabel, skipLink, sticky = true, }) {
|
|
24
|
-
assertSiteHeaderProps({ items, labels, navLabel, skipLink });
|
|
28
|
+
export function SiteHeader({ actions, brand, closeIcon, compactActions, items, labels, menuActions, menuIcon, navLabel, search, skipLink, sticky = true, }) {
|
|
29
|
+
assertSiteHeaderProps({ items, labels, navLabel, search, skipLink });
|
|
25
30
|
const menuRef = useRef(null);
|
|
26
31
|
useMenuDismiss(menuRef);
|
|
27
|
-
return (_jsxs("header", { className: cx('sw-site-header', sticky && 'sw-site-header-sticky'), children: [skipLink ? (_jsx("a", { className: "sw-site-header-skip-link", href: skipLink.href, tabIndex: tabStop, children: skipLink.label })) : null, _jsxs("div", { className: "sw-site-header-bar", children: [_jsx("div", { className: "sw-site-header-brand", children: brand }), _jsx(SiteHeaderLinks, { className: "sw-site-header-nav", items: items, navLabel: navLabel }), actions ? (_jsx("div", { className: "sw-site-header-actions", children: actions })) : null, _jsxs("div", { className: "sw-site-header-compact", children: [compactActions ? (_jsx("div", { className: "sw-site-header-compact-actions", children: compactActions })) : null, _jsxs("details", { className: "sw-site-header-menu", ref: menuRef, children: [_jsxs("summary", { className: "sw-site-header-menu-button", children: [_jsxs("span", { className: "sw-site-header-menu-open", children: [_jsx("span", { "aria-hidden": "true", className: "sw-site-header-glyph", children: menuIcon }), _jsx("span", { className: "sw-sr-only", children: labels.openMenu })] }), _jsxs("span", { className: "sw-site-header-menu-close", children: [_jsx("span", { "aria-hidden": "true", className: "sw-site-header-glyph", children: closeIcon }), _jsx("span", { className: "sw-sr-only", children: labels.closeMenu })] })] }), _jsxs("div", { className: "sw-site-header-panel", children: [_jsx(SiteHeaderLinks, { className: "sw-site-header-menu-nav", items: items, navLabel: navLabel }), menuActions ? (_jsx("div", { className: "sw-site-header-menu-actions", children: menuActions })) : null] })] })] })] })] }));
|
|
32
|
+
return (_jsxs("header", { className: cx('sw-site-header', sticky && 'sw-site-header-sticky'), children: [skipLink ? (_jsx("a", { className: "sw-site-header-skip-link", href: skipLink.href, tabIndex: tabStop, children: skipLink.label })) : null, _jsxs("div", { className: "sw-site-header-bar", children: [_jsx("div", { className: "sw-site-header-brand", children: brand }), _jsx(SiteHeaderLinks, { className: "sw-site-header-nav", items: items, navLabel: navLabel }), search ? (_jsx(SiteHeaderSearch, { closeIcon: closeIcon, search: search })) : null, actions ? (_jsx("div", { className: "sw-site-header-actions", children: actions })) : null, _jsxs("div", { className: "sw-site-header-compact", children: [compactActions ? (_jsx("div", { className: "sw-site-header-compact-actions", children: compactActions })) : null, _jsxs("details", { className: "sw-site-header-menu", ref: menuRef, children: [_jsxs("summary", { className: "sw-site-header-menu-button", children: [_jsxs("span", { className: "sw-site-header-menu-open", children: [_jsx("span", { "aria-hidden": "true", className: "sw-site-header-glyph", children: menuIcon }), _jsx("span", { className: "sw-sr-only", children: labels.openMenu })] }), _jsxs("span", { className: "sw-site-header-menu-close", children: [_jsx("span", { "aria-hidden": "true", className: "sw-site-header-glyph", children: closeIcon }), _jsx("span", { className: "sw-sr-only", children: labels.closeMenu })] })] }), _jsxs("div", { className: "sw-site-header-panel", children: [_jsx(SiteHeaderLinks, { className: "sw-site-header-menu-nav", items: items, navLabel: navLabel }), menuActions ? (_jsx("div", { className: "sw-site-header-menu-actions", children: menuActions })) : null] })] })] })] })] }));
|
|
28
33
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type HTMLAttributes } from 'react';
|
|
2
|
+
import { type Breakpoint } from '../css/breakpoints.js';
|
|
2
3
|
import type { TaskListItem } from './task-list/task-list-item.js';
|
|
3
4
|
import { type TaskListLabels } from './task-list/task-list-status.js';
|
|
4
5
|
export type { TaskListActionContext, TaskListItem, } from './task-list/task-list-item.js';
|
|
@@ -10,13 +11,31 @@ export type TaskListProps = Omit<HTMLAttributes<HTMLOListElement>, 'aria-label'
|
|
|
10
11
|
items: readonly TaskListItem[];
|
|
11
12
|
/** The status words heard after each title. English by default. */
|
|
12
13
|
labels?: Partial<TaskListLabels>;
|
|
14
|
+
/**
|
|
15
|
+
* Numbers the open tasks: a `todo` or `next` task's marker shows its
|
|
16
|
+
* place in the list (1, 2, …) inside its ring, in place of the empty ring
|
|
17
|
+
* and the dot, so "step 3" can be pointed at. Done and waiting markers
|
|
18
|
+
* keep their check and lock. The number is drawn only; the list's own
|
|
19
|
+
* order says it to assistive technology. Default `false`.
|
|
20
|
+
*/
|
|
21
|
+
numbered?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Below this breakpoint each action leaves the row's end for a line of its
|
|
24
|
+
* own under the task's words, as wide as them, its control stretched to
|
|
25
|
+
* fill it, so a phone shows one full-width button per task. Left out, an
|
|
26
|
+
* action stays at the row's end (wrapping only when it would squeeze the
|
|
27
|
+
* words). An unknown breakpoint throws a `RangeError`.
|
|
28
|
+
*/
|
|
29
|
+
actionBelow?: Breakpoint;
|
|
13
30
|
};
|
|
14
31
|
/**
|
|
15
32
|
* A setup checklist: an ordered list of tasks, each with a status marker
|
|
16
33
|
* (done: a check on the success fill; next: an accent ring round a dot;
|
|
17
34
|
* todo: a grey ring; waiting: a muted lock), its title, a muted detail
|
|
18
|
-
* line and an optional action at the row's end
|
|
35
|
+
* line and an optional action at the row's end (or, with `actionBelow`,
|
|
36
|
+
* under the words on a narrow screen), the open tasks optionally numbered
|
|
37
|
+
* (`numbered`). Each title is followed by
|
|
19
38
|
* its status word for assistive technology. Scalewing holds no order
|
|
20
39
|
* rules: the consumer sets every task's status and action.
|
|
21
40
|
*/
|
|
22
|
-
export declare function TaskList({ label, items, labels, className, ...rest }: TaskListProps): import("react").JSX.Element;
|
|
41
|
+
export declare function TaskList({ label, items, labels, numbered, actionBelow, className, ...rest }: TaskListProps): import("react").JSX.Element;
|
|
@@ -2,26 +2,31 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId } from 'react';
|
|
4
4
|
import { cx } from '../class-names.js';
|
|
5
|
-
import {
|
|
5
|
+
import { taskListActionBelowClass } from '../css/css-task-list-layout.js';
|
|
6
|
+
import { assertActionBelow, assertTaskList, } from './task-list/assert-task-list.js';
|
|
6
7
|
import { taskListWords, taskSpokenTitle, } from './task-list/task-list-status.js';
|
|
7
8
|
export { defaultTaskListLabels, taskListStatuses, } from './task-list/task-list-status.js';
|
|
8
|
-
function TaskRow({ item, labels, titleId, }) {
|
|
9
|
+
function TaskRow({ item, labels, titleId, number, }) {
|
|
9
10
|
const action = typeof item.action === 'function' ? item.action({ titleId }) : item.action;
|
|
10
11
|
const hasAction = action !== undefined && action !== null && action !== false;
|
|
11
|
-
|
|
12
|
+
const open = item.status === 'todo' || item.status === 'next';
|
|
13
|
+
return (_jsxs("li", { className: cx('sw-task-list-item', `sw-task-list-item-${item.status}`), children: [_jsx("span", { "aria-hidden": "true", className: "sw-task-list-marker", children: number !== null && open ? number : null }), _jsxs("span", { className: "sw-task-list-body", children: [_jsxs("span", { className: "sw-task-list-title", children: [_jsx("span", { "aria-hidden": "true", id: titleId, children: item.title }), _jsx("span", { className: "sw-sr-only", children: taskSpokenTitle(item.title, item.status, labels) })] }), item.detail !== undefined ? (_jsx("span", { className: "sw-task-list-detail", children: item.detail })) : null] }), hasAction ? _jsx("span", { className: "sw-task-list-action", children: action }) : null] }));
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* A setup checklist: an ordered list of tasks, each with a status marker
|
|
15
17
|
* (done: a check on the success fill; next: an accent ring round a dot;
|
|
16
18
|
* todo: a grey ring; waiting: a muted lock), its title, a muted detail
|
|
17
|
-
* line and an optional action at the row's end
|
|
19
|
+
* line and an optional action at the row's end (or, with `actionBelow`,
|
|
20
|
+
* under the words on a narrow screen), the open tasks optionally numbered
|
|
21
|
+
* (`numbered`). Each title is followed by
|
|
18
22
|
* its status word for assistive technology. Scalewing holds no order
|
|
19
23
|
* rules: the consumer sets every task's status and action.
|
|
20
24
|
*/
|
|
21
|
-
export function TaskList({ label, items, labels, className, ...rest }) {
|
|
25
|
+
export function TaskList({ label, items, labels, numbered = false, actionBelow, className, ...rest }) {
|
|
22
26
|
const words = taskListWords(labels);
|
|
23
27
|
assertTaskList(label, items, words);
|
|
28
|
+
assertActionBelow(actionBelow);
|
|
24
29
|
const baseId = useId();
|
|
25
30
|
// role="list" keeps the list a list where list-style: none drops it (Safari).
|
|
26
|
-
return (_jsx("ol", { "aria-label": label, className: cx('sw-task-list', className), role: "list", ...rest, children: items.map((item, index) => (_jsx(TaskRow, { item: item, labels: words, titleId: `${baseId}-${index}` }, item.id))) }));
|
|
31
|
+
return (_jsx("ol", { "aria-label": label, className: cx('sw-task-list', numbered && 'sw-task-list-numbered', actionBelow && taskListActionBelowClass(actionBelow), className), role: "list", ...rest, children: items.map((item, index) => (_jsx(TaskRow, { item: item, labels: words, number: numbered ? index + 1 : null, titleId: `${baseId}-${index}` }, item.id))) }));
|
|
27
32
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a Checkbox is drawn: `plain` (the box beside its words) or `tile`
|
|
3
|
+
* (the box and its words inside a bordered tile that is one press target).
|
|
4
|
+
*/
|
|
5
|
+
export declare const checkboxAppearances: readonly ["plain", "tile"];
|
|
6
|
+
export type CheckboxAppearance = (typeof checkboxAppearances)[number];
|
|
7
|
+
/**
|
|
8
|
+
* Fails closed on a Checkbox it cannot draw: an unknown appearance, or a
|
|
9
|
+
* tile whose words are hidden (a tile is a press target named by the words
|
|
10
|
+
* it draws).
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertCheckboxAppearance(appearance: CheckboxAppearance, labelVisuallyHidden: boolean): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a Checkbox is drawn: `plain` (the box beside its words) or `tile`
|
|
3
|
+
* (the box and its words inside a bordered tile that is one press target).
|
|
4
|
+
*/
|
|
5
|
+
export const checkboxAppearances = ['plain', 'tile'];
|
|
6
|
+
/**
|
|
7
|
+
* Fails closed on a Checkbox it cannot draw: an unknown appearance, or a
|
|
8
|
+
* tile whose words are hidden (a tile is a press target named by the words
|
|
9
|
+
* it draws).
|
|
10
|
+
*/
|
|
11
|
+
export function assertCheckboxAppearance(appearance, labelVisuallyHidden) {
|
|
12
|
+
if (!checkboxAppearances.includes(appearance))
|
|
13
|
+
throw new RangeError(`Unknown Checkbox appearance: ${String(appearance)}`);
|
|
14
|
+
if (appearance === 'tile' && labelVisuallyHidden)
|
|
15
|
+
throw new RangeError('A tile Checkbox draws its label');
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type KeyboardEvent } from 'react';
|
|
2
2
|
import type { FieldProps } from './field-props.js';
|
|
3
|
-
export declare const fieldVariants: readonly ["outlined", "search"];
|
|
3
|
+
export declare const fieldVariants: readonly ["outlined", "search", "read-only"];
|
|
4
4
|
export type FieldVariant = (typeof fieldVariants)[number];
|
|
5
5
|
/** The props Field reads from, and sets on, its native control child. */
|
|
6
6
|
export type FieldControlProps = {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { isValidElement } from 'react';
|
|
2
2
|
import { assertFieldWidth } from '../../css/css-field-width.js';
|
|
3
3
|
import { assertFieldDescriptionTone } from './FieldDescription.js';
|
|
4
|
-
export const fieldVariants = ['outlined', 'search'];
|
|
4
|
+
export const fieldVariants = ['outlined', 'search', 'read-only'];
|
|
5
|
+
/** A read-only field draws one native input or textarea that is `readOnly`. */
|
|
6
|
+
function assertReadOnlyChild(child) {
|
|
7
|
+
if (!isValidElement(child) ||
|
|
8
|
+
(child.type !== 'input' && child.type !== 'textarea') ||
|
|
9
|
+
child.props.readOnly !== true)
|
|
10
|
+
throw new TypeError('A read-only Field needs one native input or textarea child with readOnly');
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* Fails closed on a Field it cannot draw: an unknown variant, width or
|
|
7
14
|
* description tone, search props on an outlined field, and a search field
|
|
@@ -13,6 +20,16 @@ export function assertFieldProps(props, child) {
|
|
|
13
20
|
assertFieldDescriptionTone(descriptionTone);
|
|
14
21
|
if (!fieldVariants.includes(variant))
|
|
15
22
|
throw new RangeError(`Unknown Field variant: ${String(variant)}`);
|
|
23
|
+
if (variant === 'read-only') {
|
|
24
|
+
assertReadOnlyChild(child);
|
|
25
|
+
if (props.prefix || props.suffix)
|
|
26
|
+
throw new TypeError('A read-only Field takes no prefix or suffix');
|
|
27
|
+
// A value the person cannot change cannot be invalid or changed here.
|
|
28
|
+
if (props.error !== undefined ||
|
|
29
|
+
props.invalid !== undefined ||
|
|
30
|
+
props.changed !== undefined)
|
|
31
|
+
throw new TypeError('A read-only Field takes no error, invalid or changed');
|
|
32
|
+
}
|
|
16
33
|
if (variant !== 'search') {
|
|
17
34
|
if (props.leading !== undefined ||
|
|
18
35
|
props.clearLabel !== undefined ||
|
|
@@ -61,6 +61,14 @@ export type FieldProps = {
|
|
|
61
61
|
* clear button named `clearLabel` shows while the input holds text and
|
|
62
62
|
* is enabled; it calls `onClear` (set the value to `''`) and puts focus
|
|
63
63
|
* back in the input. Needs one native `input` child with a `value`.
|
|
64
|
+
* `read-only` is a value shown in a form that the person cannot change
|
|
65
|
+
* there, such as the email an invitation was sent to: the label above a
|
|
66
|
+
* borderless box on the subtle fill, in the text colour, so it reads as
|
|
67
|
+
* given rather than as a field to type in (and apart from a disabled
|
|
68
|
+
* field's dashed edge). It keeps the native control, so the value is
|
|
69
|
+
* still focusable, selectable and sent with the form. Needs one native
|
|
70
|
+
* `input` or `textarea` child with `readOnly` and takes no prefix,
|
|
71
|
+
* suffix, `error`, `invalid` or `changed` (a `TypeError` otherwise).
|
|
64
72
|
*/
|
|
65
73
|
variant?: FieldVariant;
|
|
66
74
|
/** A search field's glyph at its start, such as a magnifier; hidden from assistive technology. */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a RadioGroup option's description goes: `auto` (at the row's end
|
|
3
|
+
* while it fits, under the label otherwise and below md) or `stacked`
|
|
4
|
+
* (always under the label).
|
|
5
|
+
*/
|
|
6
|
+
export declare const radioGroupDescriptionLayouts: readonly ["auto", "stacked"];
|
|
7
|
+
export type RadioGroupDescriptionLayout = (typeof radioGroupDescriptionLayouts)[number];
|
|
8
|
+
/** Fails closed on a description layout RadioGroup does not have. */
|
|
9
|
+
export declare function assertRadioGroupDescriptionLayout(layout: RadioGroupDescriptionLayout): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a RadioGroup option's description goes: `auto` (at the row's end
|
|
3
|
+
* while it fits, under the label otherwise and below md) or `stacked`
|
|
4
|
+
* (always under the label).
|
|
5
|
+
*/
|
|
6
|
+
export const radioGroupDescriptionLayouts = ['auto', 'stacked'];
|
|
7
|
+
/** Fails closed on a description layout RadioGroup does not have. */
|
|
8
|
+
export function assertRadioGroupDescriptionLayout(layout) {
|
|
9
|
+
if (!radioGroupDescriptionLayouts.includes(layout))
|
|
10
|
+
throw new RangeError(`Unknown RadioGroup descriptionLayout: ${String(layout)}`);
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type SiteHeaderSearchOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The header's search: one form drawn once. From `lg` it sits in the bar as
|
|
5
|
+
* a search field; below `lg` it is a native popover that the search button
|
|
6
|
+
* opens over the whole window, with the field at the top, a close button
|
|
7
|
+
* beside it and the results under it, so it opens, closes on Escape and
|
|
8
|
+
* closes from its button with no script. Submitting sends the query to
|
|
9
|
+
* `action` as `name` (a results page). The results panel and its row
|
|
10
|
+
* template are empty until the consumer's script fills them; with no
|
|
11
|
+
* script the form still works.
|
|
12
|
+
*/
|
|
13
|
+
export declare function SiteHeaderSearch({ search, closeIcon, }: {
|
|
14
|
+
search: SiteHeaderSearchOptions;
|
|
15
|
+
closeIcon: ReactNode;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { tabStop } from '../../tab-stop.js';
|
|
4
|
+
/**
|
|
5
|
+
* The header's search: one form drawn once. From `lg` it sits in the bar as
|
|
6
|
+
* a search field; below `lg` it is a native popover that the search button
|
|
7
|
+
* opens over the whole window, with the field at the top, a close button
|
|
8
|
+
* beside it and the results under it, so it opens, closes on Escape and
|
|
9
|
+
* closes from its button with no script. Submitting sends the query to
|
|
10
|
+
* `action` as `name` (a results page). The results panel and its row
|
|
11
|
+
* template are empty until the consumer's script fills them; with no
|
|
12
|
+
* script the form still works.
|
|
13
|
+
*/
|
|
14
|
+
export function SiteHeaderSearch({ search, closeIcon, }) {
|
|
15
|
+
const id = useId();
|
|
16
|
+
const panelId = `${id}search`;
|
|
17
|
+
const resultsId = `${id}results`;
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { "aria-label": search.labels.open, className: "sw-site-header-search-button", popoverTarget: panelId, popoverTargetAction: "show", tabIndex: tabStop, type: "button", children: _jsx("span", { "aria-hidden": "true", className: "sw-site-header-glyph", children: search.icon }) }), _jsxs("div", { className: "sw-site-header-search", id: panelId, popover: "auto", children: [_jsxs("form", { action: search.action, className: "sw-site-header-search-form", method: "get", role: "search", children: [_jsxs("div", { className: "sw-site-header-search-field", children: [_jsx("span", { "aria-hidden": "true", className: "sw-site-header-search-icon", children: search.icon }), _jsx("input", { "aria-controls": resultsId, "aria-label": search.label, autoComplete: "off", className: "sw-site-header-search-input", enterKeyHint: "search", name: search.name ?? 'q', placeholder: search.placeholder, tabIndex: tabStop, type: "search" })] }), _jsx("button", { "aria-label": search.labels.close, className: "sw-site-header-search-close", popoverTarget: panelId, popoverTargetAction: "hide", tabIndex: tabStop, type: "button", children: _jsx("span", { "aria-hidden": "true", className: "sw-site-header-glyph", children: closeIcon }) })] }), _jsxs("div", { className: "sw-site-header-search-results", hidden: true, id: resultsId, children: [_jsx("p", { "aria-live": "polite", className: "sw-site-header-search-status" }), _jsx("ul", { className: "sw-site-header-search-list" }), _jsx("template", { className: "sw-site-header-search-row", children: _jsx("li", { children: _jsxs("a", { className: "sw-site-header-search-result", href: "/", children: [_jsx("span", { className: "sw-site-header-search-result-title" }), _jsx("span", { className: "sw-site-header-search-result-text" })] }) }) })] })] })] }));
|
|
19
|
+
}
|
|
@@ -25,6 +25,28 @@ export type SiteHeaderSkipLink = {
|
|
|
25
25
|
/** The main content's fragment, such as `#main`. */
|
|
26
26
|
href: string;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* The header's search form: a field in the bar from `lg`, a search button
|
|
30
|
+
* opening a full-window search below it. Submitting goes to `action` (the
|
|
31
|
+
* site's results page) with the query as `name`.
|
|
32
|
+
*/
|
|
33
|
+
export type SiteHeaderSearchOptions = {
|
|
34
|
+
/** The results page the form submits to with GET, such as `/docs/search/`. */
|
|
35
|
+
action: string;
|
|
36
|
+
/** The query's parameter name (default `q`). */
|
|
37
|
+
name?: string;
|
|
38
|
+
/** The field's accessible name, such as "Search the docs". */
|
|
39
|
+
label: string;
|
|
40
|
+
/** The empty field's hint, such as "Search the docs". */
|
|
41
|
+
placeholder: string;
|
|
42
|
+
/** The button names: `open` below `lg` ("Search"), `close` in the open search ("Close search"). */
|
|
43
|
+
labels: {
|
|
44
|
+
open: string;
|
|
45
|
+
close: string;
|
|
46
|
+
};
|
|
47
|
+
/** The magnifier glyph, decorative, in the button and the field. */
|
|
48
|
+
icon: ReactNode;
|
|
49
|
+
};
|
|
28
50
|
export type SiteHeaderProps = {
|
|
29
51
|
/** The site's mark at the start, such as a logo linked to the home page. */
|
|
30
52
|
brand: ReactNode;
|
|
@@ -50,4 +72,6 @@ export type SiteHeaderProps = {
|
|
|
50
72
|
sticky?: boolean;
|
|
51
73
|
/** A "skip to content" link before everything else in the header. */
|
|
52
74
|
skipLink?: SiteHeaderSkipLink;
|
|
75
|
+
/** A search field in the bar from `lg`; a search button below it. */
|
|
76
|
+
search?: SiteHeaderSearchOptions;
|
|
53
77
|
};
|
|
@@ -5,4 +5,4 @@ import { type SiteHeaderProps } from './types.js';
|
|
|
5
5
|
* button name, and a skip link with blank words or an address that is not
|
|
6
6
|
* a fragment on the page.
|
|
7
7
|
*/
|
|
8
|
-
export declare function assertSiteHeaderProps({ items, labels, navLabel, skipLink, }: Pick<SiteHeaderProps, 'items' | 'labels' | 'navLabel' | 'skipLink'>): void;
|
|
8
|
+
export declare function assertSiteHeaderProps({ items, labels, navLabel, search, skipLink, }: Pick<SiteHeaderProps, 'items' | 'labels' | 'navLabel' | 'search' | 'skipLink'>): void;
|