@mistriwork/ui 1.0.0-rc.58 → 1.0.0-rc.59
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/README.md +46 -12
- package/dist/Avatar.js +3 -3
- package/dist/Button.d.ts +4 -14
- package/dist/Button.js +26 -13
- package/dist/Carousel.d.ts +6 -5
- package/dist/Carousel.js +58 -67
- package/dist/Choices.d.ts +2 -9
- package/dist/Choices.js +127 -64
- package/dist/DateField.d.ts +9 -4
- package/dist/DateField.js +102 -119
- package/dist/Drawer.d.ts +1 -19
- package/dist/Drawer.js +8 -9
- package/dist/DropMenu.d.ts +8 -21
- package/dist/DropMenu.js +84 -30
- package/dist/Dropdown.d.ts +9 -8
- package/dist/Dropdown.js +69 -65
- package/dist/Field.d.ts +2 -1
- package/dist/Field.js +12 -18
- package/dist/FileField.d.ts +3 -10
- package/dist/FileField.js +12 -9
- package/dist/FormParts.d.ts +17 -10
- package/dist/FormParts.js +26 -41
- package/dist/HeroBlocks.d.ts +7 -3
- package/dist/HeroBlocks.js +11 -6
- package/dist/Modal.d.ts +6 -17
- package/dist/Modal.js +90 -21
- package/dist/Pagination.d.ts +1 -12
- package/dist/Pagination.js +17 -3
- package/dist/Popover.d.ts +1 -15
- package/dist/Popover.js +10 -15
- package/dist/Resizable.d.ts +3 -21
- package/dist/Resizable.js +14 -91
- package/dist/ScrollArea.d.ts +4 -2
- package/dist/ScrollArea.js +11 -11
- package/dist/Select.d.ts +1 -6
- package/dist/Select.js +16 -7
- package/dist/SensitiveField.d.ts +1 -8
- package/dist/SensitiveField.js +6 -4
- package/dist/Slider.d.ts +1 -5
- package/dist/Slider.js +13 -5
- package/dist/Switch.d.ts +1 -11
- package/dist/Switch.js +10 -9
- package/dist/Tabs.d.ts +3 -3
- package/dist/Tabs.js +3 -3
- package/dist/TextArea.d.ts +4 -6
- package/dist/TextArea.js +14 -5
- package/dist/TextField.d.ts +5 -9
- package/dist/TextField.js +67 -9
- package/dist/Tooltip.d.ts +1 -21
- package/dist/Tooltip.js +13 -31
- package/dist/Typeahead.d.ts +15 -18
- package/dist/Typeahead.js +151 -86
- package/dist/UiKit.d.ts +63 -4
- package/dist/UiKit.js +46 -5
- package/dist/behaviors/DaysParts.js +28 -0
- package/dist/behaviors/EditableParts.js +21 -0
- package/dist/behaviors/PickParts.js +30 -0
- package/dist/behaviors/ScrubParts.js +21 -0
- package/dist/behaviors/SortableParts.js +32 -0
- package/dist/behaviors/SpansParts.js +12 -0
- package/dist/behaviors/TransferParts.js +37 -0
- package/dist/behaviors/TurnsParts.js +31 -0
- package/dist/behaviors/WidthsParts.js +27 -0
- package/dist/behaviors/days.js +216 -0
- package/dist/behaviors/dress.js +86 -0
- package/dist/behaviors/editable.js +104 -0
- package/dist/behaviors/heard.js +22 -0
- package/dist/behaviors/index.d.ts +310 -0
- package/dist/behaviors/index.js +44 -0
- package/dist/behaviors/pick.js +158 -0
- package/dist/behaviors/scrub.js +152 -0
- package/dist/behaviors/sortable.js +170 -0
- package/dist/behaviors/spans.js +240 -0
- package/dist/behaviors/testing.js +48 -0
- package/dist/behaviors/transfer.js +202 -0
- package/dist/behaviors/turns.js +106 -0
- package/dist/behaviors/widths.js +150 -0
- package/dist/behaviors.css +309 -0
- package/dist/changeDetails.d.ts +4 -8
- package/dist/changeDetails.js +0 -6
- package/dist/conformance.js +107 -1
- package/dist/controls.css +36 -0
- package/dist/fieldFrame.d.ts +2 -15
- package/dist/fieldFrame.js +1 -17
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -5
- package/dist/internal/Frame.d.ts +6 -0
- package/dist/internal/Frame.js +25 -0
- package/dist/internal/HelpTip.d.ts +5 -0
- package/dist/internal/HelpTip.js +37 -0
- package/dist/internal/layers.d.ts +21 -0
- package/dist/internal/layers.js +66 -0
- package/dist/internal/popups.d.ts +12 -10
- package/dist/internal/popups.js +18 -14
- package/dist/internal/told.d.ts +14 -0
- package/dist/internal/told.js +20 -0
- package/dist/internal/uiKitContext.js +6 -4
- package/dist/preferences.css +2 -3
- package/dist/style.css +5 -16
- package/dist/styles/extras.css +461 -0
- package/dist/styles/forms.css +346 -0
- package/dist/styles/guard.css +114 -0
- package/dist/styles/kit-fields.css +181 -0
- package/dist/styles/kit-parts.css +130 -0
- package/dist/styles/kit.css +558 -0
- package/dist/styles/layers.css +4 -0
- package/dist/styles/looks.css +374 -0
- package/dist/styles/m-tokens.css +173 -0
- package/dist/styles/overlays.css +107 -0
- package/dist/styles/parts.css +456 -0
- package/dist/styles/screens.css +76 -0
- package/dist/styles/ui-sdk.css +1635 -0
- package/dist/tokens.css +15 -4
- package/dist/uiKitSlots.d.ts +1 -1
- package/dist/uiKitSlots.js +18 -2
- package/package.json +13 -11
- package/dist/forms.css +0 -225
- package/dist/hero.css +0 -23
- package/dist/internal/anchor.d.ts +0 -19
- package/dist/internal/anchor.js +0 -52
- package/dist/primitives.css +0 -200
- package/dist/standalone.css +0 -478
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
The standalone React primitives both shells, mistri's and tablewalk's, are
|
|
6
6
|
drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and
|
|
7
|
-
DateField over [
|
|
8
|
-
are drawn with, and the zoom-aware ruler
|
|
7
|
+
DateField over [UI SDK](https://ui-sdk.dev), the tokens and stylesheet they
|
|
8
|
+
are drawn with, and the zoom-aware ruler a page measures by.
|
|
9
9
|
|
|
10
10
|
The form controls are built on them (**Preview**: @mistriwork/ui is Preview at 1.0): `TextField`, `TextArea`, `MaskedField`,
|
|
11
11
|
`MoneyField`, `SensitiveField`, `FileField`, `Select`, `MultiSelect`, `YesNo`, `ChoiceCards`, `Checkbox`, `Consent`, `Slider`,
|
|
@@ -13,39 +13,73 @@ The form controls are built on them (**Preview**: @mistriwork/ui is Preview at 1
|
|
|
13
13
|
(`phone`, `date`, `month`, `ssn`, `zip`, `money`). Each takes a value and an `onChange` and draws what it is told. A
|
|
14
14
|
typed MM/DD/YYYY date is `MaskedField` with `masks.date` (and `isoDay` to read it); the calendar field is `DateField`.
|
|
15
15
|
The landing hero's blocks are in the same Preview: `Badge` (a few words and an optional icon in a pill), `PhotoTiles`
|
|
16
|
-
(two to four photos in a mosaic, sized before they arrive) and `IconRows` (up to four rows of an icon and a line)
|
|
17
|
-
|
|
16
|
+
(two to four photos in a mosaic, sized before they arrive) and `IconRows` (up to four rows of an icon and a line);
|
|
17
|
+
the icons, the words and the image addresses are props.
|
|
18
18
|
|
|
19
19
|
A control is a Field, so its label, hint and problem are wired into it, and its problem's line is kept in the flow so
|
|
20
|
-
saying it moves nothing. A theme restyles them all together through `--field-
|
|
21
|
-
`--
|
|
20
|
+
saying it moves nothing. A theme restyles them all together through the palette, the faces, `--field-radius` and
|
|
21
|
+
`--field-edge`, and a field label's weight is the theme's label role.
|
|
22
|
+
|
|
23
|
+
No class names a control. Each part carries a `data-slot` (`button`, `input`, `select-trigger`, `dialog-content`,
|
|
24
|
+
`calendar-day`, …) and says its state in attributes (`data-variant`, `data-size`, `data-checked`, `data-invalid`,
|
|
25
|
+
`data-open`), and that is what a stylesheet and a test select by. A caller's own `className` lands on the part it
|
|
26
|
+
always did and is the caller's to dress.
|
|
27
|
+
|
|
28
|
+
Every component here is also a slot of the control kit seam (`defineUiKit`): an App can draw any of them itself, or
|
|
29
|
+
dress the default with `dress('Button', (Button, props) => …)`.
|
|
22
30
|
|
|
23
31
|
A primitive reads no data, address or message catalog: its words, its icons,
|
|
24
32
|
its answers and its hooks are props, and it renders with no server behind it.
|
|
25
|
-
React, React DOM and
|
|
26
|
-
|
|
33
|
+
React, React DOM and UI SDK (`@ui-sdk/core`, `@ui-sdk/react`, pinned to the
|
|
34
|
+
version this release was tested with) are peers: a project drawing with these
|
|
35
|
+
installs them.
|
|
27
36
|
|
|
28
37
|
```tsx
|
|
29
38
|
import '@mistriwork/ui/style.css';
|
|
30
39
|
import { Button, Modal } from '@mistriwork/ui';
|
|
31
40
|
```
|
|
32
41
|
|
|
33
|
-
`style.css` is the tokens (`tokens.css`), the
|
|
34
|
-
(`
|
|
42
|
+
`style.css` is the tokens (`tokens.css`), what the controls wear
|
|
43
|
+
(`controls.css`) and the answers to the reader's contrast and transparency
|
|
44
|
+
settings (`preferences.css`) in a `mistri-ui` cascade layer, so any rule of the page's
|
|
35
45
|
own wins over them. A page with a layered stylesheet of its own can take the
|
|
36
46
|
files into a layer it names instead (`@import '@mistriwork/ui/tokens.css'
|
|
37
|
-
layer(base);`).
|
|
47
|
+
layer(base);`). `controls.css` nests layers of its own inside whichever layer
|
|
48
|
+
takes it, so every rule beside it in that layer stands over a control's default
|
|
49
|
+
dress. An Icon draws the glyphs registered with `registerIcons`; a
|
|
38
50
|
DateField says the `words` it is given, as do Carousel, Resizable and Pagination (a
|
|
39
51
|
`words` object over English defaults). One rule names the rest: a name no one sees is
|
|
40
52
|
`ariaLabel` (Modal, Tabs, Popover, Carousel, Resizable, ScrollArea, Pagination, Drawer),
|
|
41
53
|
and `label` is only ever text drawn on the page. A Field's `optional` is the word drawn
|
|
42
54
|
beside the label of a field that is not required.
|
|
43
55
|
|
|
56
|
+
## The behaviors
|
|
57
|
+
|
|
58
|
+
`@mistriwork/ui/behaviors/index.js` is what a component of your own is built on
|
|
59
|
+
where a reader moves, walks or edits something in place: a list whose order is
|
|
60
|
+
the reader's (`Sortable`), things carried between lists (`Transfer`), a month a
|
|
61
|
+
keyboard walks (`Days`), stretches along tracks (`Spans`), a position read
|
|
62
|
+
along a line (`Scrub`), one of a list shown beside it (`Pick`), a list worked
|
|
63
|
+
one at a time (`Turns`), column widths (`Widths`) and values edited where they
|
|
64
|
+
stand (`Editable`). Each is a UI SDK primitive with React parts: roles, keys,
|
|
65
|
+
announcements and `data-*` on elements you dress, and nothing drawn. A root's
|
|
66
|
+
change callback hears the value and then the reason, the hand and the event, as
|
|
67
|
+
every control's does, with `cancel()` to refuse the change. The primitives
|
|
68
|
+
themselves (`sortable`, `transfer`, …) and `createParts` are exported beside
|
|
69
|
+
the parts, for parts on elements of your choosing.
|
|
70
|
+
|
|
71
|
+
`behaviors.css` gives the slots only what a behavior needs to work wherever it
|
|
72
|
+
stands, and a plain grip. No control imports a behavior, so a page that draws
|
|
73
|
+
none never loads either file. In an App, a component imports them from
|
|
74
|
+
`@mistriwork/mistri/behaviors`
|
|
75
|
+
([guide](https://mistriwork.dev/docs/behaviors/)).
|
|
76
|
+
|
|
44
77
|
## Exports
|
|
45
78
|
|
|
46
79
|
Its exports are its public API, and nothing else is: `@mistriwork/ui` (every
|
|
47
80
|
primitive), each module by its path (`@mistriwork/ui/Button.js`,
|
|
48
|
-
`@mistriwork/ui/
|
|
81
|
+
`@mistriwork/ui/behaviors/index.js`,
|
|
82
|
+
`@mistriwork/ui/internal/datePickerModel.js`, …), and the five stylesheets.
|
|
49
83
|
|
|
50
84
|
Part of [mistri](https://mistriwork.dev);
|
|
51
85
|
[source](https://github.com/rbaljinder/mistri/tree/main/packages/ui).
|
package/dist/Avatar.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
3
|
* An avatar: a person's picture, or their initials where there is none.
|
|
4
|
-
* Over
|
|
4
|
+
* Over UI SDK's Avatar, which shows the fallback only while the picture
|
|
5
5
|
* loads or fails, so a slow picture never leaves a blank disc. The
|
|
6
6
|
* initials are the first letters of the first two words of the name
|
|
7
7
|
* ("Ada Lovelace" → "AL", "Ada" → "A"); the disc itself is decorative,
|
|
8
8
|
* and a name that matters is said beside it by the caller, never by the
|
|
9
9
|
* disc's title. Sizes are the house ones: `sm` 28px, `md` 36px, `lg` 48px.
|
|
10
10
|
*/
|
|
11
|
-
import { Avatar as
|
|
11
|
+
import { Avatar as Disc, AvatarFallback, AvatarImage } from '@ui-sdk/react/avatar';
|
|
12
12
|
import { slotted } from './internal/uiKitContext.js';
|
|
13
13
|
const graphemes = typeof Intl !== 'undefined' && 'Segmenter' in Intl ? new Intl.Segmenter(undefined, { granularity: 'grapheme' }) : null;
|
|
14
14
|
/* A letter is a grapheme, not a UTF-16 unit: `slice(0, 1)` splits an emoji or an astral letter into a lone surrogate. */
|
|
@@ -25,7 +25,7 @@ export function initialsOf(name) {
|
|
|
25
25
|
return firstLetter(words[0]) + firstLetter(words[1]);
|
|
26
26
|
}
|
|
27
27
|
function DefaultAvatar({ name, src, size = 'md', className }) {
|
|
28
|
-
return (_jsxs(
|
|
28
|
+
return (_jsxs(Disc, { className: className, "data-size": size, children: [src ? _jsx(AvatarImage, { src: src, alt: "" }) : null, _jsx(AvatarFallback, { "aria-hidden": "true", children: name ? initialsOf(name) : '' })] }));
|
|
29
29
|
}
|
|
30
30
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
31
31
|
export const Avatar = slotted('Avatar', DefaultAvatar);
|
package/dist/Button.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one button: an intent, a size, and the states the platform already
|
|
3
|
-
* has. Every look dresses the classes it renders — `primary`, `ghost` and
|
|
4
|
-
* `danger` are what the looks' rules already name, `btn` and its modifiers
|
|
5
|
-
* are the primitive's own — so a form, a dialog and the sign-in card draw the
|
|
6
|
-
* same control instead of each dressing a `<button>` of its own.
|
|
7
|
-
*
|
|
8
|
-
* Busy is not disabled (docs/design.md, Access): a disabled button drops the
|
|
9
|
-
* focus it holds, so a busy one says `aria-disabled` and refuses the press
|
|
10
|
-
* itself — a click, and the implicit submission Enter makes through it.
|
|
11
|
-
*/
|
|
12
1
|
import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode, Ref } from 'react';
|
|
13
2
|
export type ButtonIntent = 'primary' | 'secondary' | 'quiet' | 'danger';
|
|
14
3
|
export type ButtonSize = 'compact' | 'default' | 'large';
|
|
@@ -32,15 +21,16 @@ export declare function buttonClass({ intent, size, block, className, }?: {
|
|
|
32
21
|
block?: boolean;
|
|
33
22
|
className?: string;
|
|
34
23
|
}): string;
|
|
35
|
-
declare function DefaultButton({ intent, size, busy, busyLabel, block, type,
|
|
24
|
+
declare function DefaultButton({ intent, size, busy, busyLabel, block, type, onClick, children, ...rest }: ButtonProps): import("react").JSX.Element;
|
|
36
25
|
export interface ButtonLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
37
26
|
intent?: ButtonIntent;
|
|
38
27
|
size?: ButtonSize;
|
|
39
28
|
block?: boolean;
|
|
40
29
|
ref?: Ref<HTMLAnchorElement>;
|
|
41
30
|
}
|
|
42
|
-
/** A link dressed as a button: it goes somewhere (a download, another page) rather than doing something here
|
|
43
|
-
|
|
31
|
+
/** A link dressed as a button: it goes somewhere (a download, another page) rather than doing something here, so it
|
|
32
|
+
is an anchor and nothing more, wearing the button's part for its look. */
|
|
33
|
+
declare function DefaultButtonLink({ intent, size, block, ...rest }: ButtonLinkProps): import("react").JSX.Element;
|
|
44
34
|
export declare const Button: typeof DefaultButton;
|
|
45
35
|
export declare const ButtonLink: typeof DefaultButtonLink;
|
|
46
36
|
export {};
|
package/dist/Button.js
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The one button: an intent, a size, and the states the platform already
|
|
4
|
+
* has, over UI SDK's Button. An intent and a size are attributes of the one
|
|
5
|
+
* button part (`data-variant`, `data-size`), which the stylesheet and every
|
|
6
|
+
* look dress, so a form, a dialog and the sign-in card draw the same control
|
|
7
|
+
* instead of each dressing a `<button>` of its own.
|
|
8
|
+
*
|
|
9
|
+
* Busy is not disabled (docs/design.md, Access): a disabled button drops the
|
|
10
|
+
* focus it holds, so a busy one says `aria-disabled` and refuses the press
|
|
11
|
+
* itself — a click, and the implicit submission Enter makes through it.
|
|
12
|
+
*/
|
|
13
|
+
import { Button as Behavior } from '@ui-sdk/react/button';
|
|
2
14
|
import { slotted } from './internal/uiKitContext.js';
|
|
3
|
-
/*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
quiet: 'btn-quiet',
|
|
8
|
-
danger: 'danger btn-danger',
|
|
9
|
-
};
|
|
15
|
+
/* What the button part says of each intent and size. The outlined secondary and the default size are the part as
|
|
16
|
+
it stands, so they say nothing. */
|
|
17
|
+
const VARIANT = { primary: 'solid', secondary: undefined, quiet: 'quiet', danger: 'destructive' };
|
|
18
|
+
const SIZE = { compact: 'sm', default: undefined, large: 'lg' };
|
|
10
19
|
/** The classes, for the few controls that must stay another element (a link dressed as a button). */
|
|
11
20
|
export function buttonClass({ intent = 'secondary', size = 'default', block = false, className = '', } = {}) {
|
|
12
|
-
return ['
|
|
21
|
+
return ['ui-button', `ui-button-${intent}`, size === 'default' ? '' : `ui-button-${size}`, block ? 'ui-button-block' : '', className]
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.join(' ');
|
|
13
24
|
}
|
|
14
|
-
function DefaultButton({ intent = 'secondary', size = 'default', busy = false, busyLabel, block = false, type = 'button',
|
|
25
|
+
function DefaultButton({ intent = 'secondary', size = 'default', busy = false, busyLabel, block = false, type = 'button', onClick, children, ...rest }) {
|
|
26
|
+
/* UI SDK types the press by the part, which may be drawn as any element; here it is always the button. */
|
|
15
27
|
const press = (event) => {
|
|
16
28
|
if (busy) {
|
|
17
29
|
event.preventDefault();
|
|
@@ -19,11 +31,12 @@ function DefaultButton({ intent = 'secondary', size = 'default', busy = false, b
|
|
|
19
31
|
}
|
|
20
32
|
onClick?.(event);
|
|
21
33
|
};
|
|
22
|
-
return (_jsx(
|
|
34
|
+
return (_jsx(Behavior, { ...rest, type: type, "data-variant": VARIANT[intent], "data-size": SIZE[size], "data-block": block ? '' : undefined, "data-busy": busy ? '' : undefined, "aria-disabled": busy || rest['aria-disabled'] || undefined, onClick: press, children: busy && busyLabel !== undefined ? busyLabel : children }));
|
|
23
35
|
}
|
|
24
|
-
/** A link dressed as a button: it goes somewhere (a download, another page) rather than doing something here
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
/** A link dressed as a button: it goes somewhere (a download, another page) rather than doing something here, so it
|
|
37
|
+
is an anchor and nothing more, wearing the button's part for its look. */
|
|
38
|
+
function DefaultButtonLink({ intent = 'secondary', size = 'default', block, ...rest }) {
|
|
39
|
+
return _jsx("a", { ...rest, "data-slot": "button", "data-variant": VARIANT[intent], "data-size": SIZE[size], "data-block": block ? '' : undefined });
|
|
27
40
|
}
|
|
28
41
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
29
42
|
export const Button = slotted('Button', DefaultButton);
|
package/dist/Carousel.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A carousel: one slide at a time from a row of them, chosen with Previous
|
|
3
|
-
* and Next or with a dot per slide. Plain React
|
|
4
|
-
*
|
|
3
|
+
* and Next or with a dot per slide. Plain React: one slide, two steps and
|
|
4
|
+
* a dot row is all one is. The slides are the
|
|
5
5
|
* caller's array (the Tabs pattern), not children kept in step by hand.
|
|
6
6
|
* Controlled with `index`/`onIndexChange`, uncontrolled with
|
|
7
7
|
* `defaultIndex`. The ends do not wrap: Previous disables on the first
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* is on the carousel or its own controls, so a widget inside a slide
|
|
13
13
|
* keeps its keys — and
|
|
14
14
|
* the slide's movement is silenced for a reader who asked for reduced
|
|
15
|
-
* motion (the track's transition lives under `no-preference` in
|
|
16
|
-
*
|
|
15
|
+
* motion (the track's transition lives under `no-preference` in the
|
|
16
|
+
* stylesheet). A step button that disables under a focused finger
|
|
17
17
|
* hands focus to the other step, never to nowhere.
|
|
18
18
|
*/
|
|
19
19
|
import { type ReactNode } from 'react';
|
|
@@ -49,5 +49,6 @@ interface CarouselWords {
|
|
|
49
49
|
/** The polite status line read as the slide changes. */
|
|
50
50
|
status: (number: number, total: number, label?: string) => string;
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
declare function DefaultCarousel({ slides, index, defaultIndex, onIndexChange, ariaLabel, words: given, className }: CarouselProps): import("react").JSX.Element | null;
|
|
53
|
+
export declare const Carousel: typeof DefaultCarousel;
|
|
53
54
|
export {};
|
package/dist/Carousel.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
3
|
* A carousel: one slide at a time from a row of them, chosen with Previous
|
|
4
|
-
* and Next or with a dot per slide. Plain React
|
|
5
|
-
*
|
|
4
|
+
* and Next or with a dot per slide. Plain React: one slide, two steps and
|
|
5
|
+
* a dot row is all one is. The slides are the
|
|
6
6
|
* caller's array (the Tabs pattern), not children kept in step by hand.
|
|
7
7
|
* Controlled with `index`/`onIndexChange`, uncontrolled with
|
|
8
8
|
* `defaultIndex`. The ends do not wrap: Previous disables on the first
|
|
@@ -13,12 +13,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
* is on the carousel or its own controls, so a widget inside a slide
|
|
14
14
|
* keeps its keys — and
|
|
15
15
|
* the slide's movement is silenced for a reader who asked for reduced
|
|
16
|
-
* motion (the track's transition lives under `no-preference` in
|
|
17
|
-
*
|
|
16
|
+
* motion (the track's transition lives under `no-preference` in the
|
|
17
|
+
* stylesheet). A step button that disables under a focused finger
|
|
18
18
|
* hands focus to the other step, never to nowhere.
|
|
19
19
|
*/
|
|
20
20
|
import { useEffect, useRef, useState } from 'react';
|
|
21
21
|
import { changeDetails } from './changeDetails.js';
|
|
22
|
+
import { slotted } from './internal/uiKitContext.js';
|
|
22
23
|
const ENGLISH = {
|
|
23
24
|
region: 'Carousel',
|
|
24
25
|
previous: 'Previous slide',
|
|
@@ -28,84 +29,74 @@ const ENGLISH = {
|
|
|
28
29
|
goToSlide: (n, label) => `Go to slide ${n}${label ? `: ${label}` : ''}`,
|
|
29
30
|
status: (n, total, label) => `Slide ${n} of ${total}${label ? `: ${label}` : ''}`,
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
+
/* One slide at a time, the others out of reach: only the slide in view is in the tab order and the tree. Drawn by
|
|
33
|
+
hand on the carousel's parts, which the stylesheet dresses: UI SDK's own carousel is a scroller that keeps its
|
|
34
|
+
neighbours beside the slide and chooses among them with tabs, which is another control with other names. */
|
|
35
|
+
function DefaultCarousel({ slides, index, defaultIndex = 0, onIndexChange, ariaLabel, words: given, className }) {
|
|
32
36
|
const words = { ...ENGLISH, ...given };
|
|
33
|
-
const [
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const go = (next, event) => {
|
|
43
|
-
const clamped = Math.min(Math.max(next, 0), slides.length - 1);
|
|
44
|
-
if (index === undefined)
|
|
45
|
-
setUncontrolled(clamped);
|
|
46
|
-
onIndexChange?.(clamped, changeDetails('navigate', event));
|
|
47
|
-
};
|
|
48
|
-
/* A step that disables under its own focus hands focus on: the other
|
|
49
|
-
step where it is live, the region itself where both ends are shut
|
|
50
|
-
(one slide). Rescue runs only while focus is still on that step or
|
|
51
|
-
has already fallen to the body — a reader who tabbed onward is never
|
|
52
|
-
pulled back, and a caller-driven index change moves nothing. */
|
|
37
|
+
const [own, setOwn] = useState(defaultIndex);
|
|
38
|
+
const region = useRef(null);
|
|
39
|
+
const previous = useRef(null);
|
|
40
|
+
const next = useRef(null);
|
|
41
|
+
/* The step the keyboard was last on, so one that disables under it is rescued even where the browser has
|
|
42
|
+
already dropped the focus to the body. */
|
|
43
|
+
const lastStep = useRef(null);
|
|
44
|
+
const last = slides.length - 1;
|
|
45
|
+
const at = slides.length ? Math.min(Math.max(index ?? own, 0), last) : 0;
|
|
53
46
|
useEffect(() => {
|
|
54
47
|
if (!slides.length)
|
|
55
48
|
return;
|
|
56
49
|
const active = document.activeElement;
|
|
57
50
|
const lost = active === document.body;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
what set the ref (the null-after-focus ordering bug, otherwise). */
|
|
61
|
-
const focusStep = (step) => {
|
|
62
|
-
const other = step === 'prev' ? prevRef.current : nextRef.current;
|
|
51
|
+
const hand = (to) => {
|
|
52
|
+
const other = to === 'previous' ? previous.current : next.current;
|
|
63
53
|
if (other && !other.disabled) {
|
|
64
54
|
other.focus();
|
|
65
|
-
|
|
55
|
+
lastStep.current = to;
|
|
66
56
|
}
|
|
67
57
|
else {
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
// Both ends shut (one slide): the carousel itself takes it.
|
|
59
|
+
region.current?.focus();
|
|
60
|
+
lastStep.current = null;
|
|
70
61
|
}
|
|
71
62
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
// Only while the focus is still on that step or has fallen from it: a reader who moved on is not pulled back.
|
|
64
|
+
if (at === 0 && lastStep.current === 'previous' && (lost || active === previous.current))
|
|
65
|
+
hand('next');
|
|
66
|
+
else if (at === last && lastStep.current === 'next' && (lost || active === next.current))
|
|
67
|
+
hand('previous');
|
|
68
|
+
}, [at, last, slides.length]);
|
|
77
69
|
if (!slides.length)
|
|
78
70
|
return null;
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
const go = (to, event) => {
|
|
72
|
+
const place = Math.min(Math.max(to, 0), last);
|
|
73
|
+
if (place === at)
|
|
74
|
+
return;
|
|
75
|
+
if (index === undefined)
|
|
76
|
+
setOwn(place);
|
|
77
|
+
onIndexChange?.(place, changeDetails('navigate', event));
|
|
78
|
+
};
|
|
79
|
+
/* The keys are the carousel's only while the keyboard is on the carousel itself or on one of its own controls.
|
|
80
|
+
What is inside a slide (a caret, a slider, a tab row) keeps them, and so does what is drawn in a portal: React
|
|
81
|
+
hands a portal's events up through this tree, so the document, not the React tree, says whose they are. */
|
|
82
|
+
const onKeyDown = (event) => {
|
|
83
83
|
const target = event.target;
|
|
84
|
-
|
|
84
|
+
const control = target?.closest?.('[data-part="carousel-control"]');
|
|
85
|
+
if (target !== region.current && !(control && control.closest('[data-slot="carousel"]') === region.current))
|
|
86
|
+
return;
|
|
87
|
+
const to = { ArrowLeft: at - 1, ArrowRight: at + 1, Home: 0, End: last }[event.key];
|
|
88
|
+
if (to === undefined)
|
|
85
89
|
return;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
go(current - 1, event);
|
|
89
|
-
}
|
|
90
|
-
else if (event.key === 'ArrowRight') {
|
|
91
|
-
event.preventDefault();
|
|
92
|
-
go(current + 1, event);
|
|
93
|
-
}
|
|
94
|
-
else if (event.key === 'Home') {
|
|
95
|
-
event.preventDefault();
|
|
96
|
-
go(0, event);
|
|
97
|
-
}
|
|
98
|
-
else if (event.key === 'End') {
|
|
99
|
-
event.preventDefault();
|
|
100
|
-
go(slides.length - 1, event);
|
|
101
|
-
}
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
go(to, event);
|
|
102
92
|
};
|
|
103
|
-
return (_jsxs("section", { ref:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}, onClick: (event) => go(current + 1, event), children: words.next })] }), _jsx("p", { className: "ui-carousel-status", "aria-live": "polite", children: words.status(current + 1, slides.length, slides[current]?.label) })] }));
|
|
93
|
+
return (_jsxs("section", { ref: region, "data-slot": "carousel", className: className || undefined, "aria-roledescription": "carousel", "aria-label": ariaLabel ?? words.region,
|
|
94
|
+
// Reached by the hand-over above and never by Tab.
|
|
95
|
+
tabIndex: -1, onKeyDown: onKeyDown, children: [_jsxs("div", { "data-slot": "carousel-stage", children: [_jsxs("button", { ref: previous, type: "button", "data-slot": "carousel-previous", "data-part": "carousel-control", "data-variant": "quiet", disabled: at === 0, "data-disabled": at === 0 ? '' : undefined, onFocus: () => {
|
|
96
|
+
lastStep.current = 'previous';
|
|
97
|
+
}, onClick: (event) => go(at - 1, event), children: [_jsx("svg", { viewBox: "0 0 16 16", width: "16", height: "16", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M10 3.5 5.5 8l4.5 4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) }), _jsx("span", { "data-slot": "visually-hidden", children: words.previous })] }), _jsx("div", { "data-slot": "carousel-viewport", style: { overflow: 'hidden', minWidth: 0 }, children: _jsx("div", { "data-slot": "carousel-content", style: { display: 'flex', gap: 0, transform: `translateX(-${at * 100}%)` }, children: slides.map((slide, place) => (_jsx("div", { "data-slot": "carousel-item", role: "group", "aria-roledescription": "slide", "aria-label": words.slide(place + 1, slides.length, slide.label), "aria-hidden": place !== at || undefined, inert: place !== at || undefined, "data-active": place === at ? '' : undefined, style: { flex: '0 0 100%', minWidth: 0 }, children: slide.children }, place))) }) }), _jsxs("button", { ref: next, type: "button", "data-slot": "carousel-next", "data-part": "carousel-control", "data-variant": "quiet", disabled: at === last, "data-disabled": at === last ? '' : undefined, onFocus: () => {
|
|
98
|
+
lastStep.current = 'next';
|
|
99
|
+
}, onClick: (event) => go(at + 1, event), children: [_jsx("svg", { viewBox: "0 0 16 16", width: "16", height: "16", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M6 3.5 10.5 8 6 12.5", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) }), _jsx("span", { "data-slot": "visually-hidden", children: words.next })] })] }), _jsx("span", { "data-slot": "carousel-indicator-group", role: "group", "aria-label": words.chooseSlide, children: slides.map((slide, place) => (_jsx("button", { type: "button", "data-slot": "carousel-indicator", "data-part": "carousel-control", "data-selected": place === at ? '' : undefined, "aria-label": words.goToSlide(place + 1, slide.label), "aria-current": place === at || undefined, onClick: (event) => go(place, event) }, place))) }), _jsx("p", { "data-slot": "visually-hidden", "aria-live": "polite", children: words.status(at + 1, slides.length, slides[at]?.label) })] }));
|
|
111
100
|
}
|
|
101
|
+
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
102
|
+
export const Carousel = slotted('Carousel', DefaultCarousel, { onIndexChange: [1, 'navigate'] });
|
package/dist/Choices.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Choices drawn as buttons, cards and checkboxes: Yes/No, icon cards (one or several), a checkbox and a consent. One
|
|
3
|
-
* answer is a native radio dressed, so the arrows, Space and the form's own semantics are the browser's, and the focus
|
|
4
|
-
* ring shows on the face when the keyboard is on the input. Several cards are one group as the radios are (CheckCards):
|
|
5
|
-
* one Tab stop, the arrows move between them, Space turns one on or off, and each says `aria-checked`. Props only.
|
|
6
|
-
* Preview: @mistriwork/ui is Preview at 1.0.
|
|
7
|
-
*/
|
|
8
1
|
import { type AriaAttributes, type ReactNode } from 'react';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import type { FieldFrame } from './fieldFrame.js';
|
|
3
|
+
import type { ChangeDetails } from './changeDetails.js';
|
|
11
4
|
export interface ChoiceOption {
|
|
12
5
|
value: string;
|
|
13
6
|
label: string;
|