@mistriwork/ui 1.0.0-rc.57 → 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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/* How wide each of a set of columns is, as a UI SDK primitive: the widths are a value with a change, a bar at a
|
|
2
|
+
column's far edge is dragged to set one, and the keyboard sets it from the column's own header (Alt with Left
|
|
3
|
+
and Right, Alt with Backspace to give the width back), so the bars add no stops to the Tab order of a table
|
|
4
|
+
that already has a header button a column. A width that was never set is the column's own: the value only
|
|
5
|
+
holds what the reader changed, and taking a key out of it is how a column is given back.
|
|
6
|
+
|
|
7
|
+
While a bar is dragged the width is a draft, so nothing is told until the pointer lifts, and Escape puts the
|
|
8
|
+
column back. Every state is an attribute: `data-sized` on a column that has a width, `data-sizing` on the one
|
|
9
|
+
being dragged and on the root. */
|
|
10
|
+
import { announce, bindDrag, createChange, definePrimitive } from '@ui-sdk/core';
|
|
11
|
+
import { zoomOf } from './dress.js';
|
|
12
|
+
export const widths = definePrimitive({
|
|
13
|
+
name: 'widths',
|
|
14
|
+
options: {
|
|
15
|
+
value: 'value',
|
|
16
|
+
defaultValue: 'value',
|
|
17
|
+
onValueChange: 'callback',
|
|
18
|
+
min: 'number',
|
|
19
|
+
max: 'number',
|
|
20
|
+
step: 'number',
|
|
21
|
+
say: 'action',
|
|
22
|
+
},
|
|
23
|
+
controlled: ['value'],
|
|
24
|
+
state: (options) => ({
|
|
25
|
+
value: options.value ?? options.defaultValue ?? {},
|
|
26
|
+
sizing: null,
|
|
27
|
+
}),
|
|
28
|
+
sync: (options) => (options.value === undefined ? {} : { value: options.value }),
|
|
29
|
+
api: (context) => {
|
|
30
|
+
const change = createChange(context);
|
|
31
|
+
const said = (label, width) => context.options().say?.(label, width) ?? (width === undefined ? `${label}, its own width` : `${label}, ${width} pixels wide`);
|
|
32
|
+
const held = (width) => Math.round(Math.min(Math.max(width, context.options().min ?? 64), context.options().max ?? 640));
|
|
33
|
+
/* The width a column has now: the draft's while its bar is dragged, else what the reader set, else none. */
|
|
34
|
+
const of = (state, key) => state.sizing?.key === key ? state.sizing.width : state.value[key];
|
|
35
|
+
const set = (key, width, reason, event) => {
|
|
36
|
+
const next = { ...context.store.get().value };
|
|
37
|
+
const to = width === undefined ? undefined : held(width);
|
|
38
|
+
// An edge already at its limit, or a column with nothing to give back: nothing changed, so nothing is told.
|
|
39
|
+
if (next[key] === to)
|
|
40
|
+
return false;
|
|
41
|
+
if (to === undefined)
|
|
42
|
+
delete next[key];
|
|
43
|
+
else
|
|
44
|
+
next[key] = to;
|
|
45
|
+
return change('value', next, { reason, event, key });
|
|
46
|
+
};
|
|
47
|
+
let stop;
|
|
48
|
+
context.onDestroy(() => stop?.());
|
|
49
|
+
return {
|
|
50
|
+
of,
|
|
51
|
+
/* Follows the pointer that pressed a bar. The column is measured as it stands, so a column that was never
|
|
52
|
+
sized starts from the width its words gave it. */
|
|
53
|
+
drag(event, bar, key, column) {
|
|
54
|
+
if (event.button !== 0)
|
|
55
|
+
return;
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
// Under a zoomed page a width is in the stylesheet's pixels and the pointer moves in the screen's.
|
|
58
|
+
const zoom = zoomOf(column);
|
|
59
|
+
const from = column.getBoundingClientRect().width / zoom;
|
|
60
|
+
const start = event.clientX;
|
|
61
|
+
const towardEnd = getComputedStyle(column).direction === 'rtl' ? -1 : 1;
|
|
62
|
+
stop?.();
|
|
63
|
+
stop = bindDrag(bar, event, {
|
|
64
|
+
cancelOnEscape: true,
|
|
65
|
+
onMove: ({ x }) => context.store.set({ sizing: { key, width: held(from + ((x - start) / zoom) * towardEnd) } }),
|
|
66
|
+
onEnd: (up, canceled) => {
|
|
67
|
+
const draft = context.store.get().sizing;
|
|
68
|
+
context.store.set({ sizing: null });
|
|
69
|
+
stop = undefined;
|
|
70
|
+
if (!canceled && draft && draft.width !== Math.round(from))
|
|
71
|
+
set(key, draft.width, 'drag', up);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
/* The keyboard's way, from the column's header. Returns whether the key was one of its own. */
|
|
76
|
+
keydown(event, key, column, label) {
|
|
77
|
+
if (!event.altKey)
|
|
78
|
+
return false;
|
|
79
|
+
const step = (context.options().step ?? 16) * (event.shiftKey ? 5 : 1);
|
|
80
|
+
const now = of(context.store.get(), key) ?? column.getBoundingClientRect().width / zoomOf(column);
|
|
81
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
const next = held(now + (event.key === 'ArrowRight' ? step : -step));
|
|
84
|
+
if (set(key, next, 'move-key', event))
|
|
85
|
+
announce(said(label, next));
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (event.key === 'Backspace' || event.key === 'Delete') {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
if (set(key, undefined, 'clear-press', event))
|
|
91
|
+
announce(said(label, undefined));
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
},
|
|
96
|
+
reset: (key, event) => set(key, undefined, 'clear-press', event),
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
slots: (slot) => ({
|
|
100
|
+
root: slot({
|
|
101
|
+
state: (state) => ({
|
|
102
|
+
widths: state.sizing ? { ...state.value, [state.sizing.key]: state.sizing.width } : state.value,
|
|
103
|
+
sizing: state.sizing?.key ?? null,
|
|
104
|
+
}),
|
|
105
|
+
attrs: (state) => ({ 'data-sizing': state.sizing ? '' : undefined }),
|
|
106
|
+
}),
|
|
107
|
+
/* The column itself: a table's header cell. It wears its width, and hears the keyboard for it. */
|
|
108
|
+
column: slot({
|
|
109
|
+
props: { value: 'string', label: 'string' },
|
|
110
|
+
attrs: (state, part) => {
|
|
111
|
+
const width = part.api.of(state, part.key);
|
|
112
|
+
return {
|
|
113
|
+
'data-sized': width === undefined ? undefined : '',
|
|
114
|
+
'data-sizing': state.sizing?.key === part.key ? '' : undefined,
|
|
115
|
+
style: width === undefined ? undefined : `width:${width}px;min-width:${width}px;max-width:${width}px`,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
on: {
|
|
119
|
+
keydown: (event, { api, key, el, props }) => {
|
|
120
|
+
if (el)
|
|
121
|
+
api.keydown(event, key, el, props.label ?? key);
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
/* The bar at the column's far edge. A pointer's only: the keyboard has the header. */
|
|
126
|
+
handle: slot({
|
|
127
|
+
props: { value: { kind: 'string', from: 'column', required: true } },
|
|
128
|
+
attrs: (state, part) => ({
|
|
129
|
+
role: 'separator',
|
|
130
|
+
'aria-orientation': 'vertical',
|
|
131
|
+
'aria-hidden': 'true',
|
|
132
|
+
'data-sizing': state.sizing?.key === part.key ? '' : undefined,
|
|
133
|
+
}),
|
|
134
|
+
on: {
|
|
135
|
+
pointerdown: (event, { api, key, el }) => {
|
|
136
|
+
const column = el?.closest('[data-slot="widths-column"]');
|
|
137
|
+
if (el && column)
|
|
138
|
+
api.drag(event, el, key, column);
|
|
139
|
+
event.stopPropagation();
|
|
140
|
+
},
|
|
141
|
+
dblclick: (event, { api, key }) => {
|
|
142
|
+
api.reset(key, event);
|
|
143
|
+
event.stopPropagation();
|
|
144
|
+
},
|
|
145
|
+
// A press on the bar is not a press on the header under it (which would sort the column).
|
|
146
|
+
click: (event) => event.stopPropagation(),
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/* What the behaviors wear (./behaviors/index.ts): only what each needs to work wherever it stands, and a plain default for the
|
|
2
|
+
two parts a reader has to find (a grip, a value that can be edited). A dragged item follows the pointer, a carried
|
|
3
|
+
thing is not selected as text by the press that carries it, a finger on a track still scrolls the page. What a
|
|
4
|
+
component built on a behavior looks like is said of that component, by its own sheet, never of the slot.
|
|
5
|
+
|
|
6
|
+
It is not one of the controls' sheets (./controls.css): no control uses a behavior, so this arrives with the
|
|
7
|
+
behaviors and a page that draws none of them never fetches it. Its rules are in the controls' own layer for a
|
|
8
|
+
part's dress, so whoever takes this file puts it where they put the controls, under their own rules, and a
|
|
9
|
+
caller's class wins. The colours, the ring and the pace are the ones the controls read (./styles/m-tokens.css). */
|
|
10
|
+
@layer m-parts {
|
|
11
|
+
/* A grip is the button an item is picked up by with the keyboard or a finger: bare, and it alone takes a finger's
|
|
12
|
+
drag, so the rest of the item still scrolls the page. Empty, it draws six dots; a caller's own icon replaces
|
|
13
|
+
them. */
|
|
14
|
+
:is([data-slot='sortable-handle'], [data-slot='transfer-handle']) {
|
|
15
|
+
display: inline-grid;
|
|
16
|
+
flex: none;
|
|
17
|
+
place-items: center;
|
|
18
|
+
width: 1rem;
|
|
19
|
+
height: 1.5rem;
|
|
20
|
+
min-height: 0;
|
|
21
|
+
padding: 0;
|
|
22
|
+
border: 0;
|
|
23
|
+
border-radius: max(0px, calc(var(--m-radius) - 3px));
|
|
24
|
+
background: transparent;
|
|
25
|
+
box-shadow: none;
|
|
26
|
+
color: var(--m-ink-subtle);
|
|
27
|
+
cursor: grab;
|
|
28
|
+
touch-action: none;
|
|
29
|
+
|
|
30
|
+
&:empty::before {
|
|
31
|
+
width: 0.375rem;
|
|
32
|
+
height: 0.625rem;
|
|
33
|
+
background: radial-gradient(circle, currentColor 0.0625rem, transparent 0.078125rem) 0 0 / 0.1875rem 0.21875rem;
|
|
34
|
+
content: '';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
& svg {
|
|
38
|
+
width: 0.875rem;
|
|
39
|
+
height: 0.875rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@media (hover: hover) {
|
|
43
|
+
&:hover {
|
|
44
|
+
color: var(--m-ink);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&:focus-visible,
|
|
49
|
+
&:is([data-grabbed], [data-carried]) {
|
|
50
|
+
color: var(--m-accent-ink);
|
|
51
|
+
outline: 2px solid var(--ui-ring-border);
|
|
52
|
+
outline-offset: 1px;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* An item of a sortable list follows the pointer that drags it, over its neighbours; picked up with the keys it
|
|
57
|
+
stands where it would land, marked. */
|
|
58
|
+
[data-slot='sortable-item'] {
|
|
59
|
+
user-select: none;
|
|
60
|
+
|
|
61
|
+
&[data-dragging] {
|
|
62
|
+
position: relative;
|
|
63
|
+
z-index: 1;
|
|
64
|
+
/* Where UI SDK says, with the pointer's part put right for a zoomed page (./behaviors/sortable.ts). */
|
|
65
|
+
translate: calc(var(--drag-x, 0px) + var(--drag-dx, 0px) * var(--drag-ease, 0))
|
|
66
|
+
calc(var(--drag-y, 0px) + var(--drag-dy, 0px) * var(--drag-ease, 0));
|
|
67
|
+
box-shadow: var(--m-shadow-pop);
|
|
68
|
+
cursor: grabbing;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&[data-grabbed]:not([data-dragging]) {
|
|
72
|
+
box-shadow: 0 0 0 2px var(--ui-ring-border);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&:focus-visible {
|
|
76
|
+
outline: 2px solid var(--ui-ring-border);
|
|
77
|
+
outline-offset: 1px;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* A thing that is carried is not also selected as text by the press that carries it; the one the keys hold is
|
|
82
|
+
marked, and a list that would take it says so. */
|
|
83
|
+
[data-slot='transfer-item'],
|
|
84
|
+
[data-slot='transfer'][data-carrying] {
|
|
85
|
+
user-select: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[data-slot='transfer-item'] {
|
|
89
|
+
&[data-carried]:not([data-dragging]) {
|
|
90
|
+
box-shadow: 0 0 0 2px var(--ui-ring-border);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&:focus-visible {
|
|
94
|
+
outline: 2px solid var(--ui-ring-border);
|
|
95
|
+
outline-offset: 1px;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
[data-slot='transfer-list'][data-over] {
|
|
100
|
+
outline: 2px solid var(--ui-ring-border);
|
|
101
|
+
outline-offset: -2px;
|
|
102
|
+
|
|
103
|
+
&[data-refuses] {
|
|
104
|
+
outline-color: var(--m-line-strong);
|
|
105
|
+
outline-style: dashed;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* The copy under the pointer lifts off the page, and squares up with an edge in the accent over a place that would
|
|
110
|
+
take it. It is drawn on the page's top layer, outside whatever it was lifted from. */
|
|
111
|
+
[data-drag-preview] {
|
|
112
|
+
/* A copy of a list's item is outside its list, and would grow the marker its list had taken off. */
|
|
113
|
+
list-style: none;
|
|
114
|
+
box-shadow: var(--m-shadow-pop);
|
|
115
|
+
cursor: grabbing;
|
|
116
|
+
outline: 2px solid transparent;
|
|
117
|
+
|
|
118
|
+
&[data-over] {
|
|
119
|
+
outline-color: var(--ui-ring-border);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* Column widths. The root lays nothing out. A column's bar is a strip over its far edge, wider than the line it
|
|
124
|
+
draws; the line shows when the column is pointed at, and turns to the accent under the pointer and while it is
|
|
125
|
+
dragged. */
|
|
126
|
+
[data-slot='widths'] {
|
|
127
|
+
display: contents;
|
|
128
|
+
|
|
129
|
+
&[data-sizing] {
|
|
130
|
+
cursor: col-resize;
|
|
131
|
+
user-select: none;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
[data-slot='widths-column'] {
|
|
136
|
+
position: relative;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[data-slot='widths-handle'] {
|
|
140
|
+
position: absolute;
|
|
141
|
+
inset-block: 0;
|
|
142
|
+
inset-inline-end: -0.3125rem;
|
|
143
|
+
z-index: 1;
|
|
144
|
+
width: 0.625rem;
|
|
145
|
+
cursor: col-resize;
|
|
146
|
+
touch-action: none;
|
|
147
|
+
|
|
148
|
+
&::after {
|
|
149
|
+
position: absolute;
|
|
150
|
+
inset-block: 28%;
|
|
151
|
+
inset-inline-start: calc(50% - 0.5px);
|
|
152
|
+
width: 1px;
|
|
153
|
+
background: var(--m-line-strong);
|
|
154
|
+
content: '';
|
|
155
|
+
opacity: 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@media (hover: hover) {
|
|
159
|
+
[data-slot='widths-column']:hover > &::after {
|
|
160
|
+
opacity: 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&[data-sizing]::after {
|
|
165
|
+
inset-block: 0;
|
|
166
|
+
width: 2px;
|
|
167
|
+
background: var(--m-accent);
|
|
168
|
+
opacity: 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* Under a pointer that can hover, the handle shows as it will while it is dragged. */
|
|
172
|
+
@media (hover: hover) {
|
|
173
|
+
&:hover::after {
|
|
174
|
+
inset-block: 0;
|
|
175
|
+
width: 2px;
|
|
176
|
+
background: var(--m-accent);
|
|
177
|
+
opacity: 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Values edited where they stand. The root lays nothing out. That a value can be changed is said by its edge on
|
|
183
|
+
the way to it; nothing is drawn on a value at rest. */
|
|
184
|
+
[data-slot='editable'] {
|
|
185
|
+
display: contents;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
[data-slot='editable-value'] {
|
|
189
|
+
position: relative;
|
|
190
|
+
display: inline-flex;
|
|
191
|
+
align-items: center;
|
|
192
|
+
max-width: 100%;
|
|
193
|
+
min-height: 1.5rem;
|
|
194
|
+
border-radius: max(0px, calc(var(--m-radius) - 3px));
|
|
195
|
+
cursor: text;
|
|
196
|
+
|
|
197
|
+
&[data-locked] {
|
|
198
|
+
cursor: default;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@media (hover: hover) {
|
|
202
|
+
&:not([data-editing], [data-locked]):hover {
|
|
203
|
+
box-shadow: inset 0 0 0 1px var(--m-line-control);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
&:focus-visible {
|
|
208
|
+
outline: 2px solid var(--ui-ring-border);
|
|
209
|
+
outline-offset: 1px;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* The box is laid over the value, not in its place, so nothing around it is laid out again. */
|
|
214
|
+
[data-slot='editable-input'] {
|
|
215
|
+
position: absolute;
|
|
216
|
+
inset-block-start: 0;
|
|
217
|
+
inset-inline-start: 0;
|
|
218
|
+
z-index: 1;
|
|
219
|
+
box-sizing: border-box;
|
|
220
|
+
width: 100%;
|
|
221
|
+
min-width: 6rem;
|
|
222
|
+
height: 100%;
|
|
223
|
+
margin: 0;
|
|
224
|
+
padding: 0 var(--m-space-2h);
|
|
225
|
+
border: 0;
|
|
226
|
+
border-radius: max(0px, calc(var(--m-radius) - 3px));
|
|
227
|
+
background: var(--m-surface);
|
|
228
|
+
box-shadow: inset 0 0 0 1px var(--ui-ring-border);
|
|
229
|
+
color: var(--m-ink);
|
|
230
|
+
font: inherit;
|
|
231
|
+
text-align: inherit;
|
|
232
|
+
outline: 2px solid var(--ui-ring);
|
|
233
|
+
outline-offset: 1px;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/* A finger moving along a track reads it; moving down the page still scrolls. */
|
|
237
|
+
[data-slot='scrub-track'] {
|
|
238
|
+
touch-action: pan-y;
|
|
239
|
+
|
|
240
|
+
&:focus-visible {
|
|
241
|
+
outline: 2px solid var(--ui-ring-border);
|
|
242
|
+
outline-offset: 2px;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/* Stretches are placed by their track, which is the caller's to lay out; the root is only a box to find them in. */
|
|
247
|
+
[data-slot='spans'] {
|
|
248
|
+
display: block;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
[data-slot='spans-span']:focus-visible,
|
|
252
|
+
[data-slot='days-day']:focus-visible,
|
|
253
|
+
[data-slot='pick-option']:focus-visible,
|
|
254
|
+
[data-slot='turns-name']:focus-visible {
|
|
255
|
+
outline: 2px solid var(--ui-ring-border);
|
|
256
|
+
outline-offset: 1px;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/* Hover and the lift are 120ms of colour and edge and nothing else, and none of it where the reader asked for
|
|
260
|
+
less motion (docs/design.md, Motion). */
|
|
261
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
262
|
+
:is([data-slot='sortable-handle'], [data-slot='transfer-handle']) {
|
|
263
|
+
transition: color var(--m-fast);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
[data-drag-preview] {
|
|
267
|
+
rotate: 1.5deg;
|
|
268
|
+
transition:
|
|
269
|
+
rotate var(--m-fast),
|
|
270
|
+
outline-color var(--m-fast);
|
|
271
|
+
|
|
272
|
+
&[data-over] {
|
|
273
|
+
rotate: 0deg;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
[data-slot='widths-handle']::after {
|
|
278
|
+
transition:
|
|
279
|
+
opacity var(--m-fast),
|
|
280
|
+
background-color var(--m-fast);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/* Under a finger a grip is as large a target as any button without being drawn any larger: the area round it
|
|
285
|
+
answers for it. */
|
|
286
|
+
@media (pointer: coarse) {
|
|
287
|
+
:is([data-slot='sortable-handle'], [data-slot='transfer-handle']) {
|
|
288
|
+
position: relative;
|
|
289
|
+
|
|
290
|
+
&::after {
|
|
291
|
+
position: absolute;
|
|
292
|
+
inset: 50% auto auto 50%;
|
|
293
|
+
width: 2.75rem;
|
|
294
|
+
height: 2.75rem;
|
|
295
|
+
translate: -50% -50%;
|
|
296
|
+
content: '';
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/* Where the system draws in its own few colours a shadow is not drawn, so what is held or carried is marked by an
|
|
302
|
+
outline in the system's own highlight. */
|
|
303
|
+
@media (forced-colors: active) {
|
|
304
|
+
:is([data-slot='sortable-item'], [data-slot='transfer-item']):is([data-grabbed], [data-carried], [data-dragging]),
|
|
305
|
+
[data-drag-preview] {
|
|
306
|
+
outline: 2px solid Highlight;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
package/dist/changeDetails.d.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* value ignores it; one that must tell a person's choice from its own (a filter that should not save when the page set
|
|
4
4
|
* it, a dialog closed by Escape rather than by Save) reads it instead of keeping a flag beside the control.
|
|
5
5
|
*
|
|
6
|
-
* `reason` is
|
|
7
|
-
*
|
|
6
|
+
* `reason` is one short word per cause (`trigger-press`, `outside-press`, `escape-key`, `item-press`, `focus-out` …);
|
|
7
|
+
* each callback's type lists the words it can hear. The words are this package's, not the library's the primitives
|
|
8
|
+
* are drawn over: they were Base UI's first, callers read them, and they stayed when the drawing moved to UI SDK
|
|
9
|
+
* (internal/told.ts puts UI SDK's details under them).
|
|
8
10
|
* `source` is the hand that did it. `event` is the DOM event behind it, absent when the page made the change.
|
|
9
11
|
*/
|
|
10
12
|
export type ChangeSource = 'pointer' | 'keyboard' | 'program';
|
|
@@ -20,9 +22,3 @@ export declare function changeDetails<Reason extends string>(reason: Reason, eve
|
|
|
20
22
|
nativeEvent: Event;
|
|
21
23
|
}): ChangeDetails<Reason>;
|
|
22
24
|
export declare function keptDetails<Reason extends string>(reason: Reason): ChangeDetails<Reason>;
|
|
23
|
-
/** Base UI's details in this shape, its reason kept, or this primitive's own word where Base UI says only `none`: a raw
|
|
24
|
-
`none` never reaches a caller, who could not tell which of Base UI's unnamed changes it heard. */
|
|
25
|
-
export declare function fromBaseUi<Reason extends string, Own extends string>(details: {
|
|
26
|
-
reason: Reason;
|
|
27
|
-
event: Event;
|
|
28
|
-
}, own: Own): ChangeDetails<Exclude<Reason, 'none'> | Own>;
|
package/dist/changeDetails.js
CHANGED
|
@@ -46,9 +46,3 @@ export function changeDetails(reason, event) {
|
|
|
46
46
|
export function keptDetails(reason) {
|
|
47
47
|
return { reason, source: lastKnownHand() };
|
|
48
48
|
}
|
|
49
|
-
export function fromBaseUi(details, own) {
|
|
50
|
-
const reason = details.reason === 'none' ? own : details.reason;
|
|
51
|
-
// Base UI stands an Event named `base-ui` in for the one it did not have: the page made that change.
|
|
52
|
-
const event = details.event?.type === 'base-ui' ? undefined : details.event;
|
|
53
|
-
return event ? { reason, source: changeSource(event), event } : { reason, source: 'program' };
|
|
54
|
-
}
|
package/dist/conformance.js
CHANGED
|
@@ -20,20 +20,28 @@ import { act, createRef, useState } from 'react';
|
|
|
20
20
|
import { createRoot } from 'react-dom/client';
|
|
21
21
|
import { Avatar } from './Avatar.js';
|
|
22
22
|
import { Button, ButtonLink } from './Button.js';
|
|
23
|
+
import { Carousel } from './Carousel.js';
|
|
23
24
|
import { CheckCards, Checkbox, ChoiceCards, Consent, YesNo } from './Choices.js';
|
|
24
25
|
import { DateField } from './DateField.js';
|
|
25
26
|
import { Drawer } from './Drawer.js';
|
|
27
|
+
import { Field } from './Field.js';
|
|
28
|
+
import { FileField } from './FileField.js';
|
|
29
|
+
import { ActionBar, Columns, HelpTip, ProgressBar, ReviewList, StepHeader } from './FormParts.js';
|
|
30
|
+
import { Badge, IconRows, PhotoTiles } from './HeroBlocks.js';
|
|
26
31
|
import { DropGroup, DropItem, DropMenu, DropSeparator } from './DropMenu.js';
|
|
27
32
|
import { Dropdown, MultiDropdown } from './Dropdown.js';
|
|
28
33
|
import { Modal } from './Modal.js';
|
|
29
34
|
import { Pagination } from './Pagination.js';
|
|
30
35
|
import { Popover } from './Popover.js';
|
|
36
|
+
import { Resizable } from './Resizable.js';
|
|
37
|
+
import { ScrollArea } from './ScrollArea.js';
|
|
31
38
|
import { MultiSelect, Select } from './Select.js';
|
|
32
39
|
import { SensitiveField } from './SensitiveField.js';
|
|
33
40
|
import { Slider } from './Slider.js';
|
|
34
41
|
import { Switch } from './Switch.js';
|
|
35
42
|
import { Tabs } from './Tabs.js';
|
|
36
|
-
import {
|
|
43
|
+
import { TextArea } from './TextArea.js';
|
|
44
|
+
import { MaskedField, MoneyField, TextField, ValidMark } from './TextField.js';
|
|
37
45
|
import { Tooltip } from './Tooltip.js';
|
|
38
46
|
import { Typeahead } from './Typeahead.js';
|
|
39
47
|
import { UiKitProvider } from './UiKit.js';
|
|
@@ -545,4 +553,102 @@ export function uiKitConformance(kit, test) {
|
|
|
545
553
|
await until(() => find('dialog', 'Filters'), 'Drawer: no dialog named by its title is drawn while open');
|
|
546
554
|
await patterns('Drawer');
|
|
547
555
|
});
|
|
556
|
+
/* The parts a page draws with that are not controls of one value: a kit that fills one keeps what the platform's
|
|
557
|
+
screens read from it, which is a name, a role and the words it was handed. */
|
|
558
|
+
it('Field names any control by its label, and describes it by its hint and the problem it holds', async (mount) => {
|
|
559
|
+
await mount(_jsx(Field, { label: "Company", hint: "As it is registered", problem: "Say which company", required: true, children: (control) => _jsx("input", { ...control }) }));
|
|
560
|
+
const box = get('textbox', 'Company', 'Field');
|
|
561
|
+
const described = (box.getAttribute('aria-describedby') ?? '')
|
|
562
|
+
.split(/\s+/)
|
|
563
|
+
.map((id) => document.getElementById(id)?.textContent ?? '')
|
|
564
|
+
.join(' ');
|
|
565
|
+
check(described.includes('As it is registered'), 'Field: the control is not described by the hint');
|
|
566
|
+
check(described.includes('Say which company'), 'Field: the control is not described by the problem it holds');
|
|
567
|
+
check(box.getAttribute('aria-invalid') === 'true', 'Field: a control that holds a problem is not marked invalid');
|
|
568
|
+
check(box.getAttribute('aria-required') === 'true', 'Field: a required control does not say so');
|
|
569
|
+
});
|
|
570
|
+
it('TextArea is named by its label, shows its value and reports what is typed', async (mount) => {
|
|
571
|
+
const changed = heard();
|
|
572
|
+
await mount(_jsx(TextArea, { label: "Notes", value: "First line", onChange: changed }));
|
|
573
|
+
const box = get('textbox', 'Notes', 'TextArea');
|
|
574
|
+
check(box.value === 'First line', `TextArea: the box shows "${box.value}", not its value`);
|
|
575
|
+
await type(box, 'First line and more');
|
|
576
|
+
check(changed.calls.at(-1)?.[0] === 'First line and more', 'TextArea: onChange was not told the typed text');
|
|
577
|
+
heardDetails(changed, 1, 'TextArea: onChange');
|
|
578
|
+
});
|
|
579
|
+
it('FileField is a file input named by its label that takes the accept list, and says the words it is given', async (mount) => {
|
|
580
|
+
await mount(_jsx(FileField, { label: "Contacts", accept: ".csv", value: null, onChange: () => { }, chooseLabel: "Pick a file", noneLabel: "Nothing picked" }));
|
|
581
|
+
const input = [...document.querySelectorAll('input[type="file"]')].find((one) => nameOf(one) === 'Contacts');
|
|
582
|
+
check(input, 'FileField: no file input named by its label is drawn');
|
|
583
|
+
check(input.accept === '.csv', 'FileField: the input does not take the accept list');
|
|
584
|
+
showsText('Pick a file', 'FileField');
|
|
585
|
+
showsText('Nothing picked', 'FileField');
|
|
586
|
+
});
|
|
587
|
+
it('HelpTip is a button in the caller’s word that shows its text once pressed', async (mount) => {
|
|
588
|
+
await mount(_jsx(HelpTip, { label: "About visits", text: "We text the morning of the visit" }));
|
|
589
|
+
await click(get('button', 'About visits', 'HelpTip'));
|
|
590
|
+
await until(() => document.body.textContent?.includes('We text the morning of the visit'), 'HelpTip: its text is not shown after a press');
|
|
591
|
+
});
|
|
592
|
+
it('ProgressBar says how far along it is, under the name it is given', async (mount) => {
|
|
593
|
+
await mount(_jsx(ProgressBar, { value: 3, min: 1, max: 12, label: "Step 3 of 12" }));
|
|
594
|
+
const bar = get('progressbar', 'Step 3 of 12', 'ProgressBar');
|
|
595
|
+
check(bar.getAttribute('aria-valuenow') === '3', 'ProgressBar: it does not say its value');
|
|
596
|
+
check(bar.getAttribute('aria-valuemin') === '1' && bar.getAttribute('aria-valuemax') === '12', 'ProgressBar: it does not say its range');
|
|
597
|
+
});
|
|
598
|
+
it('StepHeader is a heading at the level it is told, and ActionBar runs what its two buttons are for', async (mount) => {
|
|
599
|
+
const back = heard();
|
|
600
|
+
const go = heard();
|
|
601
|
+
await mount(_jsxs(_Fragment, { children: [_jsx(StepHeader, { level: 2, title: "When can we visit?", lead: "A technician needs an hour" }), _jsx(ActionBar, { back: { label: 'Back', onClick: back }, primary: { label: 'Continue', onClick: go } })] }));
|
|
602
|
+
const heading = [...document.querySelectorAll('h1, h2, h3, [role="heading"]')].find((one) => one.textContent?.includes('When can we visit?'));
|
|
603
|
+
check(heading, 'StepHeader: no heading with its title is drawn');
|
|
604
|
+
check(heading.tagName === 'H2' || heading.getAttribute('aria-level') === '2', 'StepHeader: the heading is not at the level it was told');
|
|
605
|
+
showsText('A technician needs an hour', 'StepHeader');
|
|
606
|
+
await click(get('button', 'Back', 'ActionBar'));
|
|
607
|
+
await click(get('button', 'Continue', 'ActionBar'));
|
|
608
|
+
check(back.calls.length === 1 && go.calls.length === 1, 'ActionBar: a press did not run its button’s onClick');
|
|
609
|
+
});
|
|
610
|
+
it('Columns, ReviewList and ValidMark draw what they are handed', async (mount) => {
|
|
611
|
+
await mount(_jsxs(_Fragment, { children: [_jsx(Columns, { cols: "1fr 1fr", children: _jsx("p", { children: "Left of two" }) }), _jsx(ReviewList, { label: "What you told us", children: _jsx("p", { children: "Home: AC-204" }) }), _jsx(ValidMark, { icon: _jsx("i", { "data-mark": "" }) })] }));
|
|
612
|
+
showsText('Left of two', 'Columns');
|
|
613
|
+
const review = get('group', 'What you told us', 'ReviewList');
|
|
614
|
+
check(review.textContent?.includes('Home: AC-204'), 'ReviewList: what it lists is not inside the group it names');
|
|
615
|
+
const mark = document.querySelector('[data-mark]');
|
|
616
|
+
check(mark, 'ValidMark: the icon it was handed is not drawn');
|
|
617
|
+
check(mark.closest('[aria-hidden="true"]'), 'ValidMark: the mark is not hidden from assistive technology');
|
|
618
|
+
});
|
|
619
|
+
it('Badge, PhotoTiles and IconRows draw their words, their pictures with their descriptions, and their lines', async (mount) => {
|
|
620
|
+
await mount(_jsxs(_Fragment, { children: [_jsx(Badge, { children: "Now letting" }), _jsx(PhotoTiles, { tiles: [
|
|
621
|
+
{ src: '/a.jpg', alt: 'The front of the house' },
|
|
622
|
+
{ src: '/b.jpg', alt: 'A kitchen' },
|
|
623
|
+
] }), _jsx(IconRows, { rows: [{ icon: _jsx("i", {}), text: 'Repairs answered within a day' }] })] }));
|
|
624
|
+
showsText('Now letting', 'Badge');
|
|
625
|
+
for (const alt of ['The front of the house', 'A kitchen'])
|
|
626
|
+
check(document.querySelector(`img[alt="${alt}"]`), `PhotoTiles: no picture described as "${alt}" is drawn`);
|
|
627
|
+
showsText('Repairs answered within a day', 'IconRows');
|
|
628
|
+
});
|
|
629
|
+
it('Carousel is a named region that shows one slide and steps to the next', async (mount) => {
|
|
630
|
+
const moved = heard();
|
|
631
|
+
await mount(_jsx(Carousel, { ariaLabel: "Homes to let", onIndexChange: moved, words: { next: 'Onward' }, slides: [
|
|
632
|
+
{ label: 'Studio', children: _jsx("p", { children: "A studio flat" }) },
|
|
633
|
+
{ label: 'One bedroom', children: _jsx("p", { children: "A one bedroom flat" }) },
|
|
634
|
+
] }));
|
|
635
|
+
check([...document.querySelectorAll('section, [role="region"]')].some((one) => nameOf(one) === 'Homes to let'), 'Carousel: no region under its name is drawn');
|
|
636
|
+
showsText('A studio flat', 'Carousel');
|
|
637
|
+
await click(get('button', 'Onward', 'Carousel'));
|
|
638
|
+
check(moved.calls.at(-1)?.[0] === 1, 'Carousel: onIndexChange was not told the slide it moved to');
|
|
639
|
+
heardDetails(moved, 1, 'Carousel: onIndexChange');
|
|
640
|
+
});
|
|
641
|
+
it('Resizable parts its panes with a handle that says its place, and ScrollArea is a region under its name', async (mount) => {
|
|
642
|
+
await mount(_jsxs(_Fragment, { children: [_jsx(Resizable, { ariaLabel: "Record and detail", panels: [
|
|
643
|
+
{ label: 'Record', defaultSize: 60, children: _jsx("p", { children: "The record" }) },
|
|
644
|
+
{ label: 'Detail', defaultSize: 40, children: _jsx("p", { children: "The detail" }) },
|
|
645
|
+
] }), _jsx(ScrollArea, { ariaLabel: "Recent payments", children: _jsx("p", { children: "Payment one" }) })] }));
|
|
646
|
+
showsText('The record', 'Resizable');
|
|
647
|
+
showsText('The detail', 'Resizable');
|
|
648
|
+
const handle = await until(() => all('separator').find((one) => one.getAttribute('aria-valuenow') !== null), 'Resizable: no handle that says its place is drawn');
|
|
649
|
+
check(Number(handle.getAttribute('aria-valuenow')) === 60, 'Resizable: the handle does not say the first pane’s share');
|
|
650
|
+
const scroller = all('region').find((one) => nameOf(one) === 'Recent payments') ?? all('group').find((one) => nameOf(one) === 'Recent payments');
|
|
651
|
+
check(scroller, 'ScrollArea: nothing under its name is drawn');
|
|
652
|
+
check(scroller.textContent?.includes('Payment one'), 'ScrollArea: what it holds is not inside it');
|
|
653
|
+
});
|
|
548
654
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* What the controls wear. A Button, a text box, a listbox, a dialog and the rest are drawn over UI SDK, and a part is
|
|
2
|
+
dressed by the `data-slot` it carries, never by a class:
|
|
3
|
+
|
|
4
|
+
styles/ui-sdk.css UI SDK's own sheet, without its rules for bare elements (scripts/ui-sdk-css.mjs)
|
|
5
|
+
styles/m-tokens.css the scales the parts are set on, and this package's tokens under the names they read
|
|
6
|
+
styles/parts.css the dress for UI SDK's parts
|
|
7
|
+
styles/forms.css a field, its frame and a form's parts
|
|
8
|
+
styles/overlays.css a dialog, a drawer, a popover
|
|
9
|
+
styles/extras.css the carousel, the split panes, the scroller, the landing's blocks
|
|
10
|
+
styles/kit*.css what the controls add to the parts they are built from
|
|
11
|
+
styles/screens.css what a control owes a screen: an answer's width, a finger's target, a phone's text
|
|
12
|
+
styles/guard.css what is said a second time against a look's rules for bare elements
|
|
13
|
+
styles/looks.css a theme's recipes, part by part
|
|
14
|
+
|
|
15
|
+
They are layers of their own (styles/layers.css) inside whichever layer takes this file, in that order whatever the
|
|
16
|
+
order they load in. One file, and not split by what a first paint draws: two of these sheets in one layer win by
|
|
17
|
+
the order they arrive in, and one that arrived late would take over rules it is meant to stand under.
|
|
18
|
+
It is the package's one stylesheet for what it draws, beside its tokens (tokens.css) and its answer to the
|
|
19
|
+
reader's settings on those tokens (preferences.css). No class names a control: a caller's own `className` is the
|
|
20
|
+
caller's to dress, and it wins, because whoever takes this file puts it under their own rules. */
|
|
21
|
+
@import './styles/layers.css';
|
|
22
|
+
@import './styles/ui-sdk.css';
|
|
23
|
+
@import './styles/m-tokens.css';
|
|
24
|
+
@import './styles/parts.css';
|
|
25
|
+
@import './styles/forms.css';
|
|
26
|
+
@import './styles/overlays.css';
|
|
27
|
+
@import './styles/extras.css';
|
|
28
|
+
@import './styles/kit.css';
|
|
29
|
+
@import './styles/kit-fields.css';
|
|
30
|
+
@import './styles/kit-parts.css';
|
|
31
|
+
@import './styles/screens.css';
|
|
32
|
+
@import './styles/guard.css';
|
|
33
|
+
@import './styles/looks.css';
|
|
34
|
+
|
|
35
|
+
/* The Icon primitive (Icon.tsx): a glyph that sits on the line beside its words and is never squeezed by them. */
|
|
36
|
+
.mistri-icon { display: inline-block; flex: none; vertical-align: middle; }
|