@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/dist/UiKit.d.ts
CHANGED
|
@@ -15,21 +15,29 @@
|
|
|
15
15
|
import { type ComponentProps, type ComponentType, type ReactNode } from 'react';
|
|
16
16
|
import type { Avatar } from './Avatar.js';
|
|
17
17
|
import type { Button, ButtonLink } from './Button.js';
|
|
18
|
+
import type { Carousel } from './Carousel.js';
|
|
18
19
|
import type { ChangeDetails } from './changeDetails.js';
|
|
19
20
|
import type { CheckCards, Checkbox, ChoiceCards, Consent, YesNo } from './Choices.js';
|
|
20
21
|
import type { DateField } from './DateField.js';
|
|
21
22
|
import type { Drawer } from './Drawer.js';
|
|
23
|
+
import type { Field } from './Field.js';
|
|
24
|
+
import type { FileField } from './FileField.js';
|
|
25
|
+
import type { ActionBar, Columns, HelpTip, ProgressBar, ReviewList, StepHeader } from './FormParts.js';
|
|
26
|
+
import type { Badge, IconRows, PhotoTiles } from './HeroBlocks.js';
|
|
22
27
|
import type { DropGroup, DropItem, DropMenu, DropSeparator } from './DropMenu.js';
|
|
23
28
|
import type { Dropdown, MultiDropdown } from './Dropdown.js';
|
|
24
29
|
import type { Modal } from './Modal.js';
|
|
25
30
|
import type { Pagination } from './Pagination.js';
|
|
26
31
|
import type { Popover } from './Popover.js';
|
|
32
|
+
import type { Resizable } from './Resizable.js';
|
|
33
|
+
import type { ScrollArea } from './ScrollArea.js';
|
|
27
34
|
import type { MultiSelect, Select } from './Select.js';
|
|
28
35
|
import type { SensitiveField } from './SensitiveField.js';
|
|
29
36
|
import type { Slider } from './Slider.js';
|
|
30
37
|
import type { Switch } from './Switch.js';
|
|
31
38
|
import type { Tabs } from './Tabs.js';
|
|
32
|
-
import type {
|
|
39
|
+
import type { TextArea } from './TextArea.js';
|
|
40
|
+
import type { MaskedField, MoneyField, TextField, ValidMark } from './TextField.js';
|
|
33
41
|
import type { Tooltip } from './Tooltip.js';
|
|
34
42
|
import type { TypeaheadProps } from './Typeahead.js';
|
|
35
43
|
import { installUiKit } from './internal/uiKitContext.js';
|
|
@@ -76,17 +84,68 @@ export interface UiKitSlots {
|
|
|
76
84
|
Tabs: Slot<typeof Tabs>;
|
|
77
85
|
Pagination: Slot<typeof Pagination>;
|
|
78
86
|
Avatar: Slot<typeof Avatar>;
|
|
87
|
+
/** A label over any control, with its hint and its problem: the wiring between them is the slot's to keep. */
|
|
88
|
+
Field: Slot<typeof Field>;
|
|
89
|
+
TextArea: Slot<typeof TextArea>;
|
|
90
|
+
FileField: Slot<typeof FileField>;
|
|
91
|
+
/** The mark at a box's end. */
|
|
92
|
+
ValidMark: Slot<typeof ValidMark>;
|
|
93
|
+
HelpTip: Slot<typeof HelpTip>;
|
|
94
|
+
ProgressBar: Slot<typeof ProgressBar>;
|
|
95
|
+
StepHeader: Slot<typeof StepHeader>;
|
|
96
|
+
ActionBar: Slot<typeof ActionBar>;
|
|
97
|
+
Columns: Slot<typeof Columns>;
|
|
98
|
+
ReviewList: Slot<typeof ReviewList>;
|
|
99
|
+
/** The landing's blocks. */
|
|
100
|
+
Badge: Slot<typeof Badge>;
|
|
101
|
+
PhotoTiles: Slot<typeof PhotoTiles>;
|
|
102
|
+
IconRows: Slot<typeof IconRows>;
|
|
103
|
+
Carousel: Slot<typeof Carousel>;
|
|
104
|
+
Resizable: Slot<typeof Resizable>;
|
|
105
|
+
ScrollArea: Slot<typeof ScrollArea>;
|
|
79
106
|
}
|
|
107
|
+
/** The props a slot is drawn with. */
|
|
108
|
+
export type SlotProps<Name extends SlotName> = UiKitSlots[Name] extends (props: infer Props) => unknown ? Props : UiKitSlots[Name] extends ComponentType<infer Props> ? Props : never;
|
|
80
109
|
/** A kit: any of the slots; the rest draw as they always have. */
|
|
81
110
|
export type UiKit = Readonly<Partial<UiKitSlots>>;
|
|
82
111
|
/** Declares a kit, refusing a slot it does not have in words: `export default defineUiKit({ Button, Modal })`. */
|
|
83
112
|
export declare function defineUiKit(kit: UiKit): UiKit;
|
|
84
113
|
/** The primitives' own drawing, by slot, for a kit that dresses a default rather than replacing it. Filled as the
|
|
85
|
-
page loads each primitive, so read it when drawing, not when the kit is defined. */
|
|
114
|
+
page loads each primitive, so read it when drawing, not when the kit is defined (`dress` does). */
|
|
86
115
|
export declare const defaultUiKit: Readonly<Partial<UiKitSlots>>;
|
|
87
|
-
/**
|
|
88
|
-
|
|
116
|
+
/**
|
|
117
|
+
* A slot that is the platform's own control with something changed, where a kit wants to dress one and not redraw
|
|
118
|
+
* it: `Button: dress('Button', (Button, props) => <Button {...props} size="large" />)`. The function is handed the
|
|
119
|
+
* default and the props the slot was drawn with, typed for that slot, and the default is read at each draw, when the
|
|
120
|
+
* page has loaded it.
|
|
121
|
+
*/
|
|
122
|
+
export declare function dress<Name extends SlotName>(name: Name, draw: (Default: UiKitSlots[Name], props: SlotProps<Name>) => ReactNode): UiKitSlots[Name];
|
|
123
|
+
/** One kit made of several, a later one's slots over an earlier one's: a design system's kit with two slots of the
|
|
124
|
+
App's own, held to the same rules as a kit written out whole. */
|
|
125
|
+
export declare function extendUiKit(kit: UiKit, ...more: UiKit[]): UiKit;
|
|
126
|
+
/**
|
|
127
|
+
* Draws everything inside it with this kit; a page with one kit installs it once instead (`installUiKit`). A slot
|
|
128
|
+
* this kit does not fill is drawn by the kit around it, an outer provider's or the installed one, so a part of a
|
|
129
|
+
* page changes two controls and keeps the rest of the page's. `alone` draws with this kit and nothing else: a slot
|
|
130
|
+
* it does not fill is the platform's own, whatever is around.
|
|
131
|
+
*/
|
|
132
|
+
export declare function UiKitProvider({ kit, alone, children }: {
|
|
89
133
|
kit: UiKit;
|
|
134
|
+
alone?: boolean;
|
|
90
135
|
children?: ReactNode;
|
|
91
136
|
}): import("react").FunctionComponentElement<import("react").ProviderProps<Record<string, (import("react").ComponentClass<any, any> | import("react").FunctionComponent<any>) | undefined>>>;
|
|
137
|
+
/**
|
|
138
|
+
* Where a kit draws a popup opened from this element, for a kit whose own popups are portalled: the dialog the
|
|
139
|
+
* element stands in, so the popup shares its focus trap and its stacking, else the container an embedded shell
|
|
140
|
+
* named for every popup, else nothing, which is the body. The platform's own controls are drawn there.
|
|
141
|
+
*/
|
|
142
|
+
export declare function usePopupHost(trigger: {
|
|
143
|
+
current: Element | null;
|
|
144
|
+
}): HTMLElement | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* The name a layer drawn outside its place in the tree should carry as `data-component`, where there is one: a
|
|
147
|
+
* component's scoped stylesheet reaches what carries its name and nothing else, and a dialog or a popup a kit
|
|
148
|
+
* portals away would otherwise lose the styles of the component that opened it.
|
|
149
|
+
*/
|
|
150
|
+
export declare function useComponentScope(): string | undefined;
|
|
92
151
|
export { installUiKit, SLOT_NAMES, uiKitProblems, type SlotName };
|
package/dist/UiKit.js
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* Nothing here imports a primitive's module, only its types: a kit compiled apart from the page reads this file for
|
|
13
13
|
* `defineUiKit`, and the defaults arrive in `defaultUiKit` as the page loads them.
|
|
14
14
|
*/
|
|
15
|
-
import { createElement } from 'react';
|
|
15
|
+
import { createElement, useContext, useMemo } from 'react';
|
|
16
|
+
import { ComponentStyleScope } from './internal/ComponentStyleScope.js';
|
|
17
|
+
import { popupContainer, useDialogContainer } from './internal/popups.js';
|
|
16
18
|
import { UiKitContext, defaultSlots, installUiKit } from './internal/uiKitContext.js';
|
|
17
19
|
import { SLOT_NAMES, uiKitProblems } from './uiKitSlots.js';
|
|
18
20
|
/** Declares a kit, refusing a slot it does not have in words: `export default defineUiKit({ Button, Modal })`. */
|
|
@@ -23,10 +25,49 @@ export function defineUiKit(kit) {
|
|
|
23
25
|
return Object.freeze({ ...kit });
|
|
24
26
|
}
|
|
25
27
|
/** The primitives' own drawing, by slot, for a kit that dresses a default rather than replacing it. Filled as the
|
|
26
|
-
page loads each primitive, so read it when drawing, not when the kit is defined. */
|
|
28
|
+
page loads each primitive, so read it when drawing, not when the kit is defined (`dress` does). */
|
|
27
29
|
export const defaultUiKit = defaultSlots;
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A slot that is the platform's own control with something changed, where a kit wants to dress one and not redraw
|
|
32
|
+
* it: `Button: dress('Button', (Button, props) => <Button {...props} size="large" />)`. The function is handed the
|
|
33
|
+
* default and the props the slot was drawn with, typed for that slot, and the default is read at each draw, when the
|
|
34
|
+
* page has loaded it.
|
|
35
|
+
*/
|
|
36
|
+
export function dress(name, draw) {
|
|
37
|
+
const Dressed = (props) => draw(defaultSlots[name], props);
|
|
38
|
+
Dressed.displayName = `dress(${name})`;
|
|
39
|
+
return Dressed;
|
|
40
|
+
}
|
|
41
|
+
/** One kit made of several, a later one's slots over an earlier one's: a design system's kit with two slots of the
|
|
42
|
+
App's own, held to the same rules as a kit written out whole. */
|
|
43
|
+
export function extendUiKit(kit, ...more) {
|
|
44
|
+
return defineUiKit(Object.assign({}, kit, ...more));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Draws everything inside it with this kit; a page with one kit installs it once instead (`installUiKit`). A slot
|
|
48
|
+
* this kit does not fill is drawn by the kit around it, an outer provider's or the installed one, so a part of a
|
|
49
|
+
* page changes two controls and keeps the rest of the page's. `alone` draws with this kit and nothing else: a slot
|
|
50
|
+
* it does not fill is the platform's own, whatever is around.
|
|
51
|
+
*/
|
|
52
|
+
export function UiKitProvider({ kit, alone = false, children }) {
|
|
53
|
+
const around = useContext(UiKitContext);
|
|
54
|
+
const layered = useMemo(() => (alone ? kit : { ...around, ...kit }), [alone, around, kit]);
|
|
55
|
+
return createElement(UiKitContext.Provider, { value: layered }, children);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Where a kit draws a popup opened from this element, for a kit whose own popups are portalled: the dialog the
|
|
59
|
+
* element stands in, so the popup shares its focus trap and its stacking, else the container an embedded shell
|
|
60
|
+
* named for every popup, else nothing, which is the body. The platform's own controls are drawn there.
|
|
61
|
+
*/
|
|
62
|
+
export function usePopupHost(trigger) {
|
|
63
|
+
return useDialogContainer(trigger) ?? popupContainer();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The name a layer drawn outside its place in the tree should carry as `data-component`, where there is one: a
|
|
67
|
+
* component's scoped stylesheet reaches what carries its name and nothing else, and a dialog or a popup a kit
|
|
68
|
+
* portals away would otherwise lose the styles of the component that opened it.
|
|
69
|
+
*/
|
|
70
|
+
export function useComponentScope() {
|
|
71
|
+
return useContext(ComponentStyleScope);
|
|
31
72
|
}
|
|
32
73
|
export { installUiKit, SLOT_NAMES, uiKitProblems };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of a grid of days (./days.ts is the primitive). The root hands the month in view, the day the
|
|
3
|
+
keyboard is on and the month's weeks to its children, and what a day is drawn as is the caller's:
|
|
4
|
+
|
|
5
|
+
<Days defaultMonth="2026-11" onPick={(day) => choose(day)} role="grid" aria-label="A day to visit">
|
|
6
|
+
{({ weeks }) =>
|
|
7
|
+
weeks.map((week) => (
|
|
8
|
+
<div role="row" key={week[0]}>
|
|
9
|
+
{week.map((day) => (
|
|
10
|
+
<DaysDay key={day} value={day}>{Number(day.slice(8))}</DaysDay>
|
|
11
|
+
))}
|
|
12
|
+
</div>
|
|
13
|
+
))
|
|
14
|
+
}
|
|
15
|
+
</Days>
|
|
16
|
+
|
|
17
|
+
A day can be another part's element (`render`), so a day that is also a place things are carried to is one
|
|
18
|
+
element with both behaviors: `<DaysDay value={day} render={<TransferList value={day} … />} />`.
|
|
19
|
+
|
|
20
|
+
Slots: `days` (`data-month`) and `days-day` (`data-day`, `data-outside`, `data-today`). */
|
|
21
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
22
|
+
import { days } from './days.js';
|
|
23
|
+
import { heard } from './heard.js';
|
|
24
|
+
const parts = createParts(days, { root: 'div', day: 'div' });
|
|
25
|
+
export function Days({ children, onValueChange, onMonthChange, ...props }) {
|
|
26
|
+
return (_jsx(parts.Root, { ...props, ...heard({ onValueChange, onMonthChange }), children: (state) => children(state) }));
|
|
27
|
+
}
|
|
28
|
+
export const DaysDay = parts.Day;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of values edited in place (./editable.ts is the primitive). The root lays nothing out
|
|
3
|
+
(`display: contents`) and hands down which value is being edited, so the composer draws the box in its place:
|
|
4
|
+
|
|
5
|
+
<Editable text={(id) => texts[id]} onCommit={(id, text) => save(id, text)}>
|
|
6
|
+
{(editing) => (
|
|
7
|
+
<EditableValue value="rent" press tabIndex={0}>
|
|
8
|
+
{editing === 'rent' ? <EditableInput aria-label="Rent" /> : money(rent)}
|
|
9
|
+
</EditableValue>
|
|
10
|
+
)}
|
|
11
|
+
</Editable>
|
|
12
|
+
|
|
13
|
+
Slots: `editable` (`data-editing`), `editable-value` (`data-editing`, `data-locked`) and `editable-input`. */
|
|
14
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
15
|
+
import { editable } from './editable.js';
|
|
16
|
+
const parts = createParts(editable, { root: 'div', value: 'span', input: 'input' });
|
|
17
|
+
export function Editable({ children, ...props }) {
|
|
18
|
+
return _jsx(parts.Root, { ...props, children: (state) => children(state.editing) });
|
|
19
|
+
}
|
|
20
|
+
export const EditableValue = parts.Value;
|
|
21
|
+
export const EditableInput = parts.Input;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of one picked from a list and shown beside it (./pick.ts is the primitive):
|
|
3
|
+
|
|
4
|
+
<Pick keys={ids} value={open} onValueChange={setOpen} follow={wide}>
|
|
5
|
+
<PickList aria-label="Residents">
|
|
6
|
+
{ids.map((id) => (
|
|
7
|
+
<PickOption key={id} value={id}>{name(id)}</PickOption>
|
|
8
|
+
))}
|
|
9
|
+
</PickList>
|
|
10
|
+
<PickPane aria-label={open ? name(open) : 'Residents'}>
|
|
11
|
+
{open ? <Resident id={open} /> : 'Pick one to read it here.'}
|
|
12
|
+
</PickPane>
|
|
13
|
+
</Pick>
|
|
14
|
+
|
|
15
|
+
Which of the list and the pane is drawn is the caller's: where only one is in view, draw the pane once
|
|
16
|
+
something is picked, with a `PickBack` in it, and the list otherwise.
|
|
17
|
+
|
|
18
|
+
Slots: `pick` (`data-picked`), `pick-list`, `pick-option` (`data-key`, `data-picked`), `pick-pane`
|
|
19
|
+
(`data-empty`) and `pick-back`. */
|
|
20
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
21
|
+
import { heard } from './heard.js';
|
|
22
|
+
import { pick } from './pick.js';
|
|
23
|
+
const parts = createParts(pick, { root: 'div', list: 'ul', option: 'li', pane: 'section', back: 'button' });
|
|
24
|
+
export function Pick({ onValueChange, ...props }) {
|
|
25
|
+
return _jsx(parts.Root, { ...props, ...heard({ onValueChange }) });
|
|
26
|
+
}
|
|
27
|
+
export const PickList = parts.List;
|
|
28
|
+
export const PickOption = parts.Option;
|
|
29
|
+
export const PickPane = parts.Pane;
|
|
30
|
+
export const PickBack = parts.Back;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of a scrub (./scrub.ts is the primitive). The root hands the position being read to its
|
|
3
|
+
children, so whatever is drawn for it (a hairline, a readout) is the caller's:
|
|
4
|
+
|
|
5
|
+
<Scrub count={months.length} text={(at) => `${months[at]}: ${said(at)}`}>
|
|
6
|
+
{(at) => (
|
|
7
|
+
<ScrubTrack aria-label="Rent collected">
|
|
8
|
+
<svg>…{at !== null && <line x1={x(at)} x2={x(at)} … />}</svg>
|
|
9
|
+
</ScrubTrack>
|
|
10
|
+
)}
|
|
11
|
+
</Scrub>
|
|
12
|
+
|
|
13
|
+
Slots: `scrub` (`data-scrubbing`) and `scrub-track` (`data-at`). */
|
|
14
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
15
|
+
import { heard } from './heard.js';
|
|
16
|
+
import { scrub } from './scrub.js';
|
|
17
|
+
const parts = createParts(scrub, { root: 'div', track: 'div' });
|
|
18
|
+
export function Scrub({ children, onValueChange, ...props }) {
|
|
19
|
+
return (_jsx(parts.Root, { ...props, ...heard({ onValueChange }), children: (state) => children(state.at, state.last) }));
|
|
20
|
+
}
|
|
21
|
+
export const ScrubTrack = parts.Track;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The sortable list's React parts (./sortable.ts is the primitive). The root draws its items in the order they
|
|
3
|
+
stand in now, which while one is being moved is the order it would leave them in, so a caller says how one item
|
|
4
|
+
is drawn and never keeps a second copy of the order:
|
|
5
|
+
|
|
6
|
+
<Sortable value={order} onValueChange={setOrder} aria-label="Columns">
|
|
7
|
+
{(key) => <SortableItem value={key}>{names[key]}</SortableItem>}
|
|
8
|
+
</Sortable>
|
|
9
|
+
|
|
10
|
+
An item with controls of its own is picked up by a handle instead (`by="handle"`):
|
|
11
|
+
|
|
12
|
+
<Sortable by="handle" …>
|
|
13
|
+
{(key) => (
|
|
14
|
+
<SortableItem value={key}>
|
|
15
|
+
<SortableHandle aria-label={`Move ${names[key]}`} />
|
|
16
|
+
<Checkbox … /> {names[key]}
|
|
17
|
+
</SortableItem>
|
|
18
|
+
)}
|
|
19
|
+
</Sortable>
|
|
20
|
+
|
|
21
|
+
Each part takes `render`, `className` and `style` as UI SDK's own parts do, and carries `data-slot="sortable"`,
|
|
22
|
+
`"sortable-item"` or `"sortable-handle"` with `data-sorting`, `data-grabbed`, `data-dragging` and
|
|
23
|
+
`data-disabled` for a stylesheet. */
|
|
24
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
25
|
+
import { heard } from './heard.js';
|
|
26
|
+
import { sortable } from './sortable.js';
|
|
27
|
+
const parts = createParts(sortable, { root: 'div', item: 'div', handle: 'button' });
|
|
28
|
+
export function Sortable({ children, onValueChange, ...props }) {
|
|
29
|
+
return (_jsx(parts.Root, { ...props, ...heard({ onValueChange }), children: ({ order }) => order.map((key, at) => children(key, at)) }));
|
|
30
|
+
}
|
|
31
|
+
export const SortableItem = parts.Item;
|
|
32
|
+
export const SortableHandle = parts.Handle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
3
|
+
import { heard } from './heard.js';
|
|
4
|
+
import { spans } from './spans.js';
|
|
5
|
+
const parts = createParts(spans, { root: 'div', track: 'div', span: 'div' });
|
|
6
|
+
export function Spans({ onValueChange, ...props }) {
|
|
7
|
+
return _jsx(parts.Root, { ...props, ...heard({ onValueChange }) });
|
|
8
|
+
}
|
|
9
|
+
export function SpansTrack({ children, ...props }) {
|
|
10
|
+
return _jsx(parts.Track, { ...props, children: (state) => children(state.spans) });
|
|
11
|
+
}
|
|
12
|
+
export const SpansSpan = parts.Span;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of things moved between lists (./transfer.ts is the primitive):
|
|
3
|
+
|
|
4
|
+
<Transfer value={lists} onValueChange={setLists} accepts={(key, list) => …}>
|
|
5
|
+
<TransferList value="todo" aria-label="To do">
|
|
6
|
+
{(key) => (
|
|
7
|
+
<TransferItem value={key}>
|
|
8
|
+
<TransferHandle aria-label={`Carry ${names[key]}`} />
|
|
9
|
+
{names[key]}
|
|
10
|
+
</TransferItem>
|
|
11
|
+
)}
|
|
12
|
+
</TransferList>
|
|
13
|
+
…
|
|
14
|
+
</Transfer>
|
|
15
|
+
|
|
16
|
+
A list draws its items as they stand now, the carried one where it would land, so a caller says how one item is
|
|
17
|
+
drawn. `around` is for a list with more in it than its items: it is handed the items and what the list knows
|
|
18
|
+
while something is carried (`over`, `takes`, `refuses`, the carried key), to say so in a heading or an empty
|
|
19
|
+
place.
|
|
20
|
+
|
|
21
|
+
Slots: `transfer`, `transfer-list` (`data-list`, `data-takes`, `data-refuses`, `data-over`), `transfer-item`
|
|
22
|
+
(`data-carried`, `data-dragging`) and `transfer-handle` (`data-carried`). */
|
|
23
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
24
|
+
import { heard } from './heard.js';
|
|
25
|
+
import { transfer } from './transfer.js';
|
|
26
|
+
const parts = createParts(transfer, { root: 'div', list: 'ul', item: 'li', handle: 'button' });
|
|
27
|
+
export function Transfer({ onValueChange, ...props }) {
|
|
28
|
+
return _jsx(parts.Root, { ...props, ...heard({ onValueChange }) });
|
|
29
|
+
}
|
|
30
|
+
export function TransferList({ children, around, ...props }) {
|
|
31
|
+
return (_jsx(parts.List, { ...props, children: (state) => {
|
|
32
|
+
const items = state.keys.map((key, at) => children(key, at));
|
|
33
|
+
return around ? around(items, state) : items;
|
|
34
|
+
} }));
|
|
35
|
+
}
|
|
36
|
+
export const TransferItem = parts.Item;
|
|
37
|
+
export const TransferHandle = parts.Handle;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of a list worked one at a time (./turns.ts is the primitive). The root hands what is in hand
|
|
3
|
+
and how far along the reader is to its children:
|
|
4
|
+
|
|
5
|
+
<Turns keys={ids} value={answered} onValueChange={setAnswered}>
|
|
6
|
+
{({ current, handled, total }) =>
|
|
7
|
+
current ? (
|
|
8
|
+
<>
|
|
9
|
+
<p>{handled.length + 1} of {total}</p>
|
|
10
|
+
<TurnsName>{name(current)}</TurnsName>
|
|
11
|
+
<TurnsSkip>Skip</TurnsSkip>
|
|
12
|
+
</>
|
|
13
|
+
) : (
|
|
14
|
+
<TurnsName>All done</TurnsName>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
</Turns>
|
|
18
|
+
|
|
19
|
+
To finish the one in hand from a component of your own, make the instance with `usePrimitive(turns, …)` from
|
|
20
|
+
`@ui-sdk/react/primitive` and call its `api.finish()`: the library's `Queue` does, once a verb has settled.
|
|
21
|
+
|
|
22
|
+
Slots: `turns` (`data-done`), `turns-name` and `turns-skip`. */
|
|
23
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
24
|
+
import { heard } from './heard.js';
|
|
25
|
+
import { turns } from './turns.js';
|
|
26
|
+
const parts = createParts(turns, { root: 'div', name: 'h2', skip: 'button' });
|
|
27
|
+
export function Turns({ onValueChange, ...props }) {
|
|
28
|
+
return _jsx(parts.Root, { ...props, ...heard({ onValueChange }) });
|
|
29
|
+
}
|
|
30
|
+
export const TurnsName = parts.Name;
|
|
31
|
+
export const TurnsSkip = parts.Skip;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* The React parts of column widths (./widths.ts is the primitive). The root is a box that lays nothing out
|
|
3
|
+
(`display: contents`, in the parts' sheet): it shares the widths with the columns inside it and hands them to
|
|
4
|
+
its children, so the cells under a header can be held to the header's width.
|
|
5
|
+
|
|
6
|
+
<Widths value={widths} onValueChange={setWidths}>
|
|
7
|
+
{(set) => (
|
|
8
|
+
<table>
|
|
9
|
+
<thead><tr>
|
|
10
|
+
<WidthsColumn value="rent" label="Asking rent">Asking rent <WidthsHandle /></WidthsColumn>
|
|
11
|
+
</tr></thead>
|
|
12
|
+
<tbody>… <td style={cell(set.rent)}>…</td> …</tbody>
|
|
13
|
+
</table>
|
|
14
|
+
)}
|
|
15
|
+
</Widths>
|
|
16
|
+
|
|
17
|
+
Slots: `widths-column` (`data-sized`, `data-sizing`, and its width as a style) and `widths-handle`
|
|
18
|
+
(`data-sizing`). */
|
|
19
|
+
import { createParts } from '@ui-sdk/react/primitive';
|
|
20
|
+
import { heard } from './heard.js';
|
|
21
|
+
import { widths } from './widths.js';
|
|
22
|
+
const parts = createParts(widths, { root: 'div', column: 'th', handle: 'span' });
|
|
23
|
+
export function Widths({ children, onValueChange, ...props }) {
|
|
24
|
+
return (_jsx(parts.Root, { ...props, ...heard({ onValueChange }), children: (state) => children(state.widths, state.sizing) }));
|
|
25
|
+
}
|
|
26
|
+
export const WidthsColumn = parts.Column;
|
|
27
|
+
export const WidthsHandle = parts.Handle;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/* A month of days as a grid a keyboard walks: the behavior under a month calendar, a day picker and anything else
|
|
2
|
+
laid out a week a row. As a UI SDK primitive the day the keyboard is on and the month in view are values with
|
|
3
|
+
changes, so a page can hold either (a calendar and a list reading the same month) or leave them alone.
|
|
4
|
+
|
|
5
|
+
The grid is one stop in the Tab order, the day last visited. Arrows go by day and by week, Home and End to the
|
|
6
|
+
week's edges, Page Up and Down by month; a day past the month's edge brings its month into view and the
|
|
7
|
+
keyboard follows it there. Enter or Space picks the day, which is the caller's to mean: a picker takes it as
|
|
8
|
+
its value, a calendar goes into what the day holds.
|
|
9
|
+
|
|
10
|
+
A day is said as `2026-11-14` and a month as `2026-11`, in no zone: a calendar's day is a date, not a moment. */
|
|
11
|
+
import { createChange, definePrimitive } from '@ui-sdk/core';
|
|
12
|
+
const DAY = 86_400_000;
|
|
13
|
+
export const dayAt = (day) => new Date(`${day}T00:00:00Z`);
|
|
14
|
+
const iso = (date) => date.toISOString().slice(0, 10);
|
|
15
|
+
export const addDays = (day, by) => iso(new Date(dayAt(day).getTime() + by * DAY));
|
|
16
|
+
export const monthOf = (day) => day.slice(0, 7);
|
|
17
|
+
export const addMonths = (month, by) => {
|
|
18
|
+
const date = dayAt(`${month}-01`);
|
|
19
|
+
date.setUTCMonth(date.getUTCMonth() + by);
|
|
20
|
+
return iso(date).slice(0, 7);
|
|
21
|
+
};
|
|
22
|
+
/* The same day of another month, or that month's last where it is shorter. */
|
|
23
|
+
export const inMonth = (day, month) => {
|
|
24
|
+
const last = dayAt(`${addMonths(month, 1)}-01`).getTime() - DAY;
|
|
25
|
+
const wanted = dayAt(`${month}-${day.slice(8)}`);
|
|
26
|
+
return Number.isNaN(wanted.getTime()) || monthOf(iso(wanted)) !== month ? iso(new Date(last)) : iso(wanted);
|
|
27
|
+
};
|
|
28
|
+
export const localToday = () => {
|
|
29
|
+
const now = new Date();
|
|
30
|
+
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
|
|
31
|
+
};
|
|
32
|
+
/* Whole weeks, from the week a month starts in to the week it ends in. */
|
|
33
|
+
export const weeksOf = (month, weekStart) => {
|
|
34
|
+
const first = `${month}-01`;
|
|
35
|
+
const lead = (dayAt(first).getUTCDay() - weekStart + 7) % 7;
|
|
36
|
+
const start = addDays(first, -lead);
|
|
37
|
+
const days = (dayAt(`${addMonths(month, 1)}-01`).getTime() - dayAt(first).getTime()) / DAY;
|
|
38
|
+
const count = Math.ceil((lead + days) / 7);
|
|
39
|
+
return Array.from({ length: count }, (_, week) => Array.from({ length: 7 }, (_, day) => addDays(start, week * 7 + day)));
|
|
40
|
+
};
|
|
41
|
+
export const days = definePrimitive({
|
|
42
|
+
name: 'days',
|
|
43
|
+
options: {
|
|
44
|
+
value: 'string',
|
|
45
|
+
defaultValue: 'string',
|
|
46
|
+
onValueChange: 'callback',
|
|
47
|
+
month: 'string',
|
|
48
|
+
defaultMonth: 'string',
|
|
49
|
+
onMonthChange: 'callback',
|
|
50
|
+
weekStart: 'number',
|
|
51
|
+
today: 'string',
|
|
52
|
+
min: 'string',
|
|
53
|
+
max: 'string',
|
|
54
|
+
unavailable: 'action',
|
|
55
|
+
onPick: 'callback',
|
|
56
|
+
press: 'boolean',
|
|
57
|
+
},
|
|
58
|
+
controlled: ['value', 'month'],
|
|
59
|
+
state: (options) => {
|
|
60
|
+
const today = options.today ?? localToday();
|
|
61
|
+
const month = options.month ?? options.defaultMonth ?? monthOf(options.value ?? options.defaultValue ?? today);
|
|
62
|
+
return {
|
|
63
|
+
month,
|
|
64
|
+
// The keyboard starts on the day it was given, else on today where the month holds it, else on the month's first.
|
|
65
|
+
value: options.value ?? options.defaultValue ?? (monthOf(today) === month ? today : `${month}-01`),
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
sync: (options) => ({
|
|
69
|
+
...(options.value === undefined ? {} : { value: options.value }),
|
|
70
|
+
...(options.month === undefined ? {} : { month: options.month }),
|
|
71
|
+
}),
|
|
72
|
+
api: (context) => {
|
|
73
|
+
const change = createChange(context);
|
|
74
|
+
const weekStart = () => context.options().weekStart ?? 1;
|
|
75
|
+
const today = () => context.options().today ?? localToday();
|
|
76
|
+
const held = (day) => {
|
|
77
|
+
const { min, max } = context.options();
|
|
78
|
+
if (min && day < min)
|
|
79
|
+
return min;
|
|
80
|
+
if (max && day > max)
|
|
81
|
+
return max;
|
|
82
|
+
return day;
|
|
83
|
+
};
|
|
84
|
+
/* The keyboard goes with the day: once the grid is drawn again (a new month's cells are not there until it
|
|
85
|
+
is), the day's cell is found and takes the focus. A few frames are allowed for the drawing. */
|
|
86
|
+
const follow = (from, day) => {
|
|
87
|
+
const root = from?.closest('[data-slot="days"]');
|
|
88
|
+
if (!root || typeof requestAnimationFrame === 'undefined')
|
|
89
|
+
return;
|
|
90
|
+
let tries = 0;
|
|
91
|
+
const land = () => {
|
|
92
|
+
const cell = root.querySelector(`[role="gridcell"][data-day="${day}"]`);
|
|
93
|
+
if (cell)
|
|
94
|
+
cell.focus();
|
|
95
|
+
else if (++tries < 12)
|
|
96
|
+
requestAnimationFrame(land);
|
|
97
|
+
};
|
|
98
|
+
land();
|
|
99
|
+
};
|
|
100
|
+
const visit = (to, reason, event, from) => {
|
|
101
|
+
const day = held(to);
|
|
102
|
+
const now = context.store.get();
|
|
103
|
+
if (day === now.value && monthOf(day) === now.month)
|
|
104
|
+
return false;
|
|
105
|
+
if (day !== now.value && !change('value', day, { reason, event }))
|
|
106
|
+
return false;
|
|
107
|
+
if (monthOf(day) !== context.store.get().month)
|
|
108
|
+
change('month', monthOf(day), { reason, event });
|
|
109
|
+
if (from)
|
|
110
|
+
follow(from, day);
|
|
111
|
+
return true;
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
weekStart,
|
|
115
|
+
today,
|
|
116
|
+
now: () => context.store.get(),
|
|
117
|
+
weeks: () => weeksOf(context.store.get().month, weekStart()),
|
|
118
|
+
visit,
|
|
119
|
+
/* Another month into view, with the keyboard's day kept to the same date in it. */
|
|
120
|
+
show(month, event) {
|
|
121
|
+
const now = context.store.get();
|
|
122
|
+
if (month === now.month)
|
|
123
|
+
return false;
|
|
124
|
+
if (!change('month', month, { reason: 'imperative', event }))
|
|
125
|
+
return false;
|
|
126
|
+
change('value', held(inMonth(now.value, month)), { reason: 'imperative', event });
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
/* Where a key takes the keyboard from a day, or nowhere. */
|
|
130
|
+
step(day, key) {
|
|
131
|
+
const inWeek = (dayAt(day).getUTCDay() - weekStart() + 7) % 7;
|
|
132
|
+
switch (key) {
|
|
133
|
+
case 'ArrowLeft':
|
|
134
|
+
return addDays(day, -1);
|
|
135
|
+
case 'ArrowRight':
|
|
136
|
+
return addDays(day, 1);
|
|
137
|
+
case 'ArrowUp':
|
|
138
|
+
return addDays(day, -7);
|
|
139
|
+
case 'ArrowDown':
|
|
140
|
+
return addDays(day, 7);
|
|
141
|
+
case 'Home':
|
|
142
|
+
return addDays(day, -inWeek);
|
|
143
|
+
case 'End':
|
|
144
|
+
return addDays(day, 6 - inWeek);
|
|
145
|
+
case 'PageUp':
|
|
146
|
+
return inMonth(day, addMonths(monthOf(day), -1));
|
|
147
|
+
case 'PageDown':
|
|
148
|
+
return inMonth(day, addMonths(monthOf(day), 1));
|
|
149
|
+
default:
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
open(day) {
|
|
154
|
+
const { min, max, unavailable } = context.options();
|
|
155
|
+
return !(min && day < min) && !(max && day > max) && !unavailable?.(day);
|
|
156
|
+
},
|
|
157
|
+
/* The day that is the grid's one stop in the Tab order: the keyboard's, or the month's first where a page
|
|
158
|
+
that holds the month has turned it away from that day. */
|
|
159
|
+
stop() {
|
|
160
|
+
const now = context.store.get();
|
|
161
|
+
return monthOf(now.value) === now.month ? now.value : `${now.month}-01`;
|
|
162
|
+
},
|
|
163
|
+
pick(day, event) {
|
|
164
|
+
context.options().onPick?.(day, event);
|
|
165
|
+
},
|
|
166
|
+
presses: () => Boolean(context.options().press),
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
slots: (slot) => ({
|
|
170
|
+
root: slot({
|
|
171
|
+
state: (state, part) => ({ month: state.month, day: state.value, weeks: part.api.weeks() }),
|
|
172
|
+
attrs: (state) => ({ 'data-month': state.month }),
|
|
173
|
+
}),
|
|
174
|
+
day: slot({
|
|
175
|
+
props: { value: 'string' },
|
|
176
|
+
attrs: (state, part) => {
|
|
177
|
+
const day = part.props.value;
|
|
178
|
+
return {
|
|
179
|
+
role: 'gridcell',
|
|
180
|
+
tabindex: day === part.api.stop() ? '0' : '-1',
|
|
181
|
+
'data-day': day,
|
|
182
|
+
'data-outside': monthOf(day) === state.month ? undefined : '',
|
|
183
|
+
'data-today': day === part.api.today() ? '' : undefined,
|
|
184
|
+
'aria-current': day === part.api.today() ? 'date' : undefined,
|
|
185
|
+
'aria-disabled': part.api.open(day) ? undefined : 'true',
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
on: {
|
|
189
|
+
keydown: (event, { api, el, props }) => {
|
|
190
|
+
// A key on something the day holds is that thing's.
|
|
191
|
+
if (event.target !== el)
|
|
192
|
+
return;
|
|
193
|
+
const to = api.step(props.value, event.key);
|
|
194
|
+
if (to) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
api.visit(to, 'move-key', event, el);
|
|
197
|
+
}
|
|
198
|
+
else if ((event.key === 'Enter' || event.key === ' ') && api.open(props.value)) {
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
api.pick(props.value, event);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
focus: (event, { api, el, props }) => {
|
|
204
|
+
if (event.target === el)
|
|
205
|
+
api.visit(props.value, 'focus-in', event);
|
|
206
|
+
},
|
|
207
|
+
click: (event, { api, el, props }) => {
|
|
208
|
+
if (api.presses() && api.open(props.value) && (event.target === el || !event.target.closest('a, button'))) {
|
|
209
|
+
api.visit(props.value, 'focus-in', event);
|
|
210
|
+
api.pick(props.value, event);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
}),
|
|
216
|
+
});
|