@ac-kit/ui-common 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +244 -0
- package/LICENSE +28 -0
- package/README.md +633 -2
- package/dist/anchored/anchored.d.ts +19 -0
- package/dist/anchored/anchored.d.ts.map +1 -0
- package/dist/anchored/anchored.js +2 -0
- package/dist/anchored/anchored.js.map +1 -0
- package/dist/button/button.d.ts +35 -0
- package/dist/button/button.d.ts.map +1 -0
- package/dist/button/button.js +22 -0
- package/dist/button/button.js.map +1 -0
- package/dist/dialog/dialog.d.ts +33 -0
- package/dist/dialog/dialog.d.ts.map +1 -0
- package/dist/dialog/dialog.js +23 -0
- package/dist/dialog/dialog.js.map +1 -0
- package/dist/focus/owns-arrow-keys.d.ts +31 -0
- package/dist/focus/owns-arrow-keys.d.ts.map +1 -0
- package/dist/focus/owns-arrow-keys.js +64 -0
- package/dist/focus/owns-arrow-keys.js.map +1 -0
- package/dist/focus/roving-focus.d.ts +34 -0
- package/dist/focus/roving-focus.d.ts.map +1 -0
- package/dist/focus/roving-focus.js +72 -0
- package/dist/focus/roving-focus.js.map +1 -0
- package/dist/focus/typeahead.d.ts +112 -0
- package/dist/focus/typeahead.d.ts.map +1 -0
- package/dist/focus/typeahead.js +178 -0
- package/dist/focus/typeahead.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/knob/knob.d.ts +106 -0
- package/dist/knob/knob.d.ts.map +1 -0
- package/dist/knob/knob.js +116 -0
- package/dist/knob/knob.js.map +1 -0
- package/dist/menu/menu.d.ts +157 -0
- package/dist/menu/menu.d.ts.map +1 -0
- package/dist/menu/menu.js +162 -0
- package/dist/menu/menu.js.map +1 -0
- package/dist/meter/meter.d.ts +63 -0
- package/dist/meter/meter.d.ts.map +1 -0
- package/dist/meter/meter.js +57 -0
- package/dist/meter/meter.js.map +1 -0
- package/dist/preact/_anchor.d.ts +13 -0
- package/dist/preact/_anchor.d.ts.map +1 -0
- package/dist/preact/_anchor.js +39 -0
- package/dist/preact/_anchor.js.map +1 -0
- package/dist/preact/_dom.d.ts +14 -0
- package/dist/preact/_dom.d.ts.map +1 -0
- package/dist/preact/_dom.js +31 -0
- package/dist/preact/_dom.js.map +1 -0
- package/dist/preact/_live-announcer.d.ts +26 -0
- package/dist/preact/_live-announcer.d.ts.map +1 -0
- package/dist/preact/_live-announcer.js +101 -0
- package/dist/preact/_live-announcer.js.map +1 -0
- package/dist/preact/button.d.ts +40 -0
- package/dist/preact/button.d.ts.map +1 -0
- package/dist/preact/button.js +22 -0
- package/dist/preact/button.js.map +1 -0
- package/dist/preact/dialog.d.ts +43 -0
- package/dist/preact/dialog.d.ts.map +1 -0
- package/dist/preact/dialog.js +89 -0
- package/dist/preact/dialog.js.map +1 -0
- package/dist/preact/index.d.ts +20 -0
- package/dist/preact/index.d.ts.map +1 -0
- package/dist/preact/index.js +20 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/preact/join-classes.d.ts +10 -0
- package/dist/preact/join-classes.d.ts.map +1 -0
- package/dist/preact/join-classes.js +12 -0
- package/dist/preact/join-classes.js.map +1 -0
- package/dist/preact/knob.d.ts +51 -0
- package/dist/preact/knob.d.ts.map +1 -0
- package/dist/preact/knob.js +144 -0
- package/dist/preact/knob.js.map +1 -0
- package/dist/preact/menu-button.d.ts +117 -0
- package/dist/preact/menu-button.d.ts.map +1 -0
- package/dist/preact/menu-button.js +330 -0
- package/dist/preact/menu-button.js.map +1 -0
- package/dist/preact/meter.d.ts +34 -0
- package/dist/preact/meter.d.ts.map +1 -0
- package/dist/preact/meter.js +21 -0
- package/dist/preact/meter.js.map +1 -0
- package/dist/preact/progress-ring.d.ts +42 -0
- package/dist/preact/progress-ring.d.ts.map +1 -0
- package/dist/preact/progress-ring.js +26 -0
- package/dist/preact/progress-ring.js.map +1 -0
- package/dist/preact/radio-group.d.ts +50 -0
- package/dist/preact/radio-group.d.ts.map +1 -0
- package/dist/preact/radio-group.js +42 -0
- package/dist/preact/radio-group.js.map +1 -0
- package/dist/preact/readout.d.ts +22 -0
- package/dist/preact/readout.d.ts.map +1 -0
- package/dist/preact/readout.js +13 -0
- package/dist/preact/readout.js.map +1 -0
- package/dist/preact/slider.d.ts +40 -0
- package/dist/preact/slider.d.ts.map +1 -0
- package/dist/preact/slider.js +164 -0
- package/dist/preact/slider.js.map +1 -0
- package/dist/preact/spin-button.d.ts +67 -0
- package/dist/preact/spin-button.d.ts.map +1 -0
- package/dist/preact/spin-button.js +132 -0
- package/dist/preact/spin-button.js.map +1 -0
- package/dist/preact/switch.d.ts +25 -0
- package/dist/preact/switch.d.ts.map +1 -0
- package/dist/preact/switch.js +19 -0
- package/dist/preact/switch.js.map +1 -0
- package/dist/preact/tabs.d.ts +97 -0
- package/dist/preact/tabs.d.ts.map +1 -0
- package/dist/preact/tabs.js +264 -0
- package/dist/preact/tabs.js.map +1 -0
- package/dist/preact/toaster.d.ts +43 -0
- package/dist/preact/toaster.d.ts.map +1 -0
- package/dist/preact/toaster.js +356 -0
- package/dist/preact/toaster.js.map +1 -0
- package/dist/preact/toggle-button.d.ts +26 -0
- package/dist/preact/toggle-button.d.ts.map +1 -0
- package/dist/preact/toggle-button.js +16 -0
- package/dist/preact/toggle-button.js.map +1 -0
- package/dist/preact/toolbar.d.ts +24 -0
- package/dist/preact/toolbar.d.ts.map +1 -0
- package/dist/preact/toolbar.js +142 -0
- package/dist/preact/toolbar.js.map +1 -0
- package/dist/preact/tooltip.d.ts +67 -0
- package/dist/preact/tooltip.d.ts.map +1 -0
- package/dist/preact/tooltip.js +165 -0
- package/dist/preact/tooltip.js.map +1 -0
- package/dist/preact/tree.d.ts +93 -0
- package/dist/preact/tree.d.ts.map +1 -0
- package/dist/preact/tree.js +399 -0
- package/dist/preact/tree.js.map +1 -0
- package/dist/preact/use-element-binding.d.ts +32 -0
- package/dist/preact/use-element-binding.d.ts.map +1 -0
- package/dist/preact/use-element-binding.js +51 -0
- package/dist/preact/use-element-binding.js.map +1 -0
- package/dist/progress/progress.d.ts +51 -0
- package/dist/progress/progress.d.ts.map +1 -0
- package/dist/progress/progress.js +43 -0
- package/dist/progress/progress.js.map +1 -0
- package/dist/readout/readout.d.ts +41 -0
- package/dist/readout/readout.d.ts.map +1 -0
- package/dist/readout/readout.js +26 -0
- package/dist/readout/readout.js.map +1 -0
- package/dist/slider/_clamped-value.d.ts +7 -0
- package/dist/slider/_clamped-value.d.ts.map +1 -0
- package/dist/slider/_clamped-value.js +9 -0
- package/dist/slider/_clamped-value.js.map +1 -0
- package/dist/slider/slider-attributes.d.ts +50 -0
- package/dist/slider/slider-attributes.d.ts.map +1 -0
- package/dist/slider/slider-attributes.js +38 -0
- package/dist/slider/slider-attributes.js.map +1 -0
- package/dist/slider/slider-range.d.ts +59 -0
- package/dist/slider/slider-range.d.ts.map +1 -0
- package/dist/slider/slider-range.js +73 -0
- package/dist/slider/slider-range.js.map +1 -0
- package/dist/slider/slider-track.d.ts +37 -0
- package/dist/slider/slider-track.d.ts.map +1 -0
- package/dist/slider/slider-track.js +35 -0
- package/dist/slider/slider-track.js.map +1 -0
- package/dist/slider/stepped-value.d.ts +31 -0
- package/dist/slider/stepped-value.d.ts.map +1 -0
- package/dist/slider/stepped-value.js +55 -0
- package/dist/slider/stepped-value.js.map +1 -0
- package/dist/spin-button/spin-button.d.ts +110 -0
- package/dist/spin-button/spin-button.d.ts.map +1 -0
- package/dist/spin-button/spin-button.js +179 -0
- package/dist/spin-button/spin-button.js.map +1 -0
- package/dist/switch/switch.d.ts +30 -0
- package/dist/switch/switch.d.ts.map +1 -0
- package/dist/switch/switch.js +26 -0
- package/dist/switch/switch.js.map +1 -0
- package/dist/tabs/tabs.d.ts +157 -0
- package/dist/tabs/tabs.d.ts.map +1 -0
- package/dist/tabs/tabs.js +120 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/toast/toast-queue.d.ts +212 -0
- package/dist/toast/toast-queue.d.ts.map +1 -0
- package/dist/toast/toast-queue.js +290 -0
- package/dist/toast/toast-queue.js.map +1 -0
- package/dist/toast/toasts-obscure.d.ts +25 -0
- package/dist/toast/toasts-obscure.d.ts.map +1 -0
- package/dist/toast/toasts-obscure.js +30 -0
- package/dist/toast/toasts-obscure.js.map +1 -0
- package/dist/toggle-button/toggle-button.d.ts +44 -0
- package/dist/toggle-button/toggle-button.d.ts.map +1 -0
- package/dist/toggle-button/toggle-button.js +31 -0
- package/dist/toggle-button/toggle-button.js.map +1 -0
- package/dist/tone.d.ts +8 -0
- package/dist/tone.d.ts.map +1 -0
- package/dist/tone.js +2 -0
- package/dist/tone.js.map +1 -0
- package/dist/toolbar/toolbar.d.ts +35 -0
- package/dist/toolbar/toolbar.d.ts.map +1 -0
- package/dist/toolbar/toolbar.js +23 -0
- package/dist/toolbar/toolbar.js.map +1 -0
- package/dist/tooltip/tooltip.d.ts +183 -0
- package/dist/tooltip/tooltip.d.ts.map +1 -0
- package/dist/tooltip/tooltip.js +185 -0
- package/dist/tooltip/tooltip.js.map +1 -0
- package/dist/tree/tree.d.ts +302 -0
- package/dist/tree/tree.d.ts.map +1 -0
- package/dist/tree/tree.js +439 -0
- package/dist/tree/tree.js.map +1 -0
- package/package.json +110 -3
- package/styles.css +1883 -0
package/README.md
CHANGED
|
@@ -1,3 +1,634 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/ui-common
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generic controls for the browser, touch first: a knob turned by dragging up
|
|
4
|
+
and down, a slider, a toggle button, a hardware-style readout, a level meter,
|
|
5
|
+
a switch, a radio group, buttons, a toolbar with roving focus, a modal
|
|
6
|
+
dialog, a menu button, a tooltip, toasts, tabs, a progress ring, a spin
|
|
7
|
+
button and a tree view. Each one is a headless core — its
|
|
8
|
+
state and behaviour as plain functions and data, with no framework and no
|
|
9
|
+
DOM — and a component per framework over it, styled only through CSS custom
|
|
10
|
+
properties.
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { Knob } from "@ac-kit/ui-common/preact";
|
|
14
|
+
import "@ac-kit/ui-common/styles.css";
|
|
15
|
+
|
|
16
|
+
<Knob
|
|
17
|
+
label="Tempo"
|
|
18
|
+
value={tempo}
|
|
19
|
+
min={50}
|
|
20
|
+
max={100}
|
|
21
|
+
resetValue={100}
|
|
22
|
+
format={(value) => `${value} %`}
|
|
23
|
+
onChange={setTempo}
|
|
24
|
+
onRequestEntry={openTempoDialog}
|
|
25
|
+
/>;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## What it is for
|
|
29
|
+
|
|
30
|
+
A panel of settings, a practice tool or a mixer needs controls that behave as
|
|
31
|
+
people expect and that work under a finger: a knob that does not have to be
|
|
32
|
+
turned around itself, a value that commits once the gesture ends rather than
|
|
33
|
+
on every pixel, a slider the page can still scroll across. The behaviour is
|
|
34
|
+
the hard part and is the same whatever draws it, so it lives in a core you can
|
|
35
|
+
test and reuse; the components only connect it to pointer and keyboard events.
|
|
36
|
+
Pointer gestures go through [`@ac-kit/ui-gesture/dom`](../ui-gesture), so
|
|
37
|
+
capture, cancellation and the browser's default actions are written once for
|
|
38
|
+
every framework.
|
|
39
|
+
|
|
40
|
+
## The core
|
|
41
|
+
|
|
42
|
+
`@ac-kit/ui-common` imports no framework and touches no DOM, so it runs and
|
|
43
|
+
tests anywhere. Every function is pure and every time is passed in.
|
|
44
|
+
|
|
45
|
+
- **Sliders.** `SliderRange` (`min`, `max`, `step`, as WAI-ARIA states them),
|
|
46
|
+
`snapSliderValue`, `sliderFraction`, `sliderValueAt`; `steppedValue` maps the
|
|
47
|
+
slider keys (arrows, Page Up/Down by ten steps, Home, End) to a value;
|
|
48
|
+
`sliderAttributes` gives the `slider` role and its `aria-value*` attributes;
|
|
49
|
+
`sliderTrackValueAt` reads the value under a pointer on a horizontal or
|
|
50
|
+
vertical track, the thumb kept inside it. The arithmetic is
|
|
51
|
+
`@ac-kit/math-scalar`'s (`quantize`, `lerp`, `inverseLerp`).
|
|
52
|
+
- **Knob.** `knobAngles` gives the pointer angle and the lit arc on a 270°
|
|
53
|
+
sweep (`KNOB_ARC`), lit from `min` or from a bipolar `origin`; `knobArcPath`
|
|
54
|
+
draws an arc of a `KnobDial` (`centerX`, `centerY`, `radius`) as SVG path
|
|
55
|
+
data, through `@ac-kit/math-geometry` and `@ac-kit/format-svg`;
|
|
56
|
+
`knobDragValue` turns a vertical drag into a value, with a fine mode.
|
|
57
|
+
- **Toggle button.** `toggleButtonAttributes` — a latching toggle,
|
|
58
|
+
`aria-pressed`, state, indicator and tone.
|
|
59
|
+
- **Readout.** `readoutAttributes` — a group named by its caption, optionally
|
|
60
|
+
announced as it changes.
|
|
61
|
+
- **Switch, button, toolbar, dialog.** `switchAttributes` (the `switch` role
|
|
62
|
+
and its state), `buttonAttributes` (variant, size, tone), `toolbarAttributes`
|
|
63
|
+
(the `toolbar` role, named, `aria-orientation` when vertical),
|
|
64
|
+
`dialogAttributes` (title and description ids, placement).
|
|
65
|
+
- **Focus.** `rovingFocusIndex(current, key, count, options)` gives the item an
|
|
66
|
+
arrow key, Home or End moves to, skipping disabled ones, wrapping or not,
|
|
67
|
+
mirrored in a right-to-left direction; `ownsArrowKeys` says whether an
|
|
68
|
+
element (its tag, input type, role, editable content) uses the arrow keys
|
|
69
|
+
itself, so a container leaves them to it. `Typeahead` gathers the characters
|
|
70
|
+
typed within 500 ms of each other, and `typeaheadIndex(labels, current,
|
|
71
|
+
query)` gives the item they reach: the next one starting with a character
|
|
72
|
+
typed alone or repeated, else the first from the current one starting with
|
|
73
|
+
the query, compared grapheme by grapheme as the locale's collation does,
|
|
74
|
+
ignoring case and accents; `isTypeaheadKey` tells a typed character from a
|
|
75
|
+
named key or a shortcut, and `typeaheadCharacter` the character a key adds
|
|
76
|
+
to a query (Space only while one is in progress); `Typeahead.find` types a
|
|
77
|
+
character and returns the item reached, in one call.
|
|
78
|
+
- **Menu.** `menuButtonAttributes` (`aria-haspopup`, `aria-expanded`,
|
|
79
|
+
`aria-controls`), `menuAttributes` (the `menu` role, named by its button,
|
|
80
|
+
with its side and alignment), `menuItemAttributes` (`menuitem`,
|
|
81
|
+
`menuitemcheckbox` or `menuitemradio`, checked, disabled but focusable);
|
|
82
|
+
`menuButtonKeyAction` (the item Enter, Space or an arrow opens the menu on)
|
|
83
|
+
and `menuKeyAction` (what a key does in an open menu: focus an item,
|
|
84
|
+
activate it, closing or not, close, leave with Tab, or type ahead).
|
|
85
|
+
- **Tooltip.** `tooltipAttributes`, `tooltipTriggerAttributes` (described or
|
|
86
|
+
named by the tooltip); `tooltipStep(state, input, time)`, the reducer of a
|
|
87
|
+
tooltip's visibility from hover, keyboard focus, presses, Escape and time,
|
|
88
|
+
with its show and hide delays and WCAG 1.4.13's rules; `TooltipGroup`, the
|
|
89
|
+
tooltips that show one at a time, the next without its delay.
|
|
90
|
+
- **Toasts.** `ToastQueue`: toasts shown a few at a time (`limit`), each until
|
|
91
|
+
its duration has run on a clock that only visible toasts run and pause
|
|
92
|
+
reasons stop, updated in place by id, a toast with an action kept until
|
|
93
|
+
dismissed; `toasterAttributes` (a named region), `toastAttributes`,
|
|
94
|
+
`toastAnnouncement` (the lines a screen reader hears); `toastsObscure`
|
|
95
|
+
(whether toasts cover part of the focused control, from its box and
|
|
96
|
+
theirs).
|
|
97
|
+
- **Anchored popovers.** `AnchoredSide` (`block-start`, `block-end`,
|
|
98
|
+
`inline-start`, `inline-end`) and `AnchoredAlign` (`start`, `center`,
|
|
99
|
+
`end`), the logical placement of a menu or tooltip against its trigger.
|
|
100
|
+
- **Meter.** `meterAttributes` — the `meter` role with its range and a value
|
|
101
|
+
kept inside it; `meterLitCount` maps a level to the lit segments of a scale
|
|
102
|
+
of `MeterSegment`s (a threshold and a tone each), in O(log n).
|
|
103
|
+
- **Tabs.** `tabListAttributes` (the `tablist` role, named,
|
|
104
|
+
`aria-orientation` when vertical), `tabAttributes` (`aria-selected`,
|
|
105
|
+
`aria-controls`, one tab stop, disabled but focusable),
|
|
106
|
+
`tabPanelAttributes` (named by its tab, a tab stop only when nothing inside
|
|
107
|
+
it is); `tabsKeyAction` (what a key does on a tab: focus another, going
|
|
108
|
+
round and mirrored right to left, selecting it when activation is
|
|
109
|
+
`automatic`; select on Enter or Space when `manual`; delete on Delete).
|
|
110
|
+
- **Progress.** `progressAttributes` — the `progressbar` role, from 0 to 100
|
|
111
|
+
by default, its value clamped, absent while indeterminate.
|
|
112
|
+
- **Spin button.** `SpinButtonRange` (`step`, and `min` and `max` when it has
|
|
113
|
+
them), `snapSpinButtonValue` (the nearest step, kept within the bounds;
|
|
114
|
+
`snapSliderValue` with both), `spinButtonValue` (the spin button keys:
|
|
115
|
+
Arrow Up and Down, Page Up and Down by ten steps, Home and End to the bounds
|
|
116
|
+
it has; `steppedValue` with both, Arrow Left and Right left to the caret),
|
|
117
|
+
`spinButtonAttributes` (the `spinbutton` role with the bounds it has).
|
|
118
|
+
- **Tree view.** `TreeSource` (roots, `childrenOf`, `isBranch` for lazy
|
|
119
|
+
children), `visibleTreeRows(source, isExpanded)` — the rows shown, with
|
|
120
|
+
each one's level, position, set size, parent, expansion and loading, a
|
|
121
|
+
node's row found in O(1), walked without recursion by `@ac-kit/algo`'s
|
|
122
|
+
`walkTree`; `treeKeyAction` (the WAI-ARIA tree view keys: move, expand,
|
|
123
|
+
collapse, `*`, Enter, Space, the multiple-selection keys, typeahead, mirrored
|
|
124
|
+
right to left), `nextTreeSelection` (replace, flip, a range, all or none,
|
|
125
|
+
never a disabled node), `expandTreeSiblings`, `treePath` and `treeTabStop`
|
|
126
|
+
(the focused row, else its nearest ancestor shown, else the first selected,
|
|
127
|
+
else the first), `treeAttributes` and `treeItemAttributes`.
|
|
128
|
+
- `ControlTone`, the colour role every lit control takes.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { knobAngles, meterLitCount, steppedValue } from "@ac-kit/ui-common";
|
|
132
|
+
|
|
133
|
+
const tempo = { min: 50, max: 100, step: 1 };
|
|
134
|
+
|
|
135
|
+
steppedValue(80, "PageUp", tempo); // 90
|
|
136
|
+
knobAngles(75, tempo); // { pointer: 0, arcFrom: -135, arcTo: 0 }
|
|
137
|
+
|
|
138
|
+
const scale = [
|
|
139
|
+
{ threshold: -60, tone: "positive" },
|
|
140
|
+
{ threshold: -6, tone: "warning" },
|
|
141
|
+
{ threshold: 0, tone: "negative" },
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
meterLitCount(-10, scale); // 1
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Framework adapters
|
|
148
|
+
|
|
149
|
+
Each framework has its own subpath export, and the framework is an optional
|
|
150
|
+
peer dependency: install the one you use, and nothing else is pulled in.
|
|
151
|
+
|
|
152
|
+
| subpath | framework | components |
|
|
153
|
+
| -------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
154
|
+
| `@ac-kit/ui-common/preact` | Preact 11 | `Knob`, `Slider`, `ToggleButton`, `Readout`, `Meter`, `Switch`, `RadioGroup`, `Button`, `IconButton`, `Toolbar`, `Dialog`, `MenuButton` (with `MenuItem`, `MenuItemCheckbox`, `MenuItemRadio`, `MenuGroup`, `MenuSeparator`), `Tooltip`, `Toaster`, `Tabs` (with `TabList`, `Tab`, `TabPanel`), `ProgressRing`, `SpinButton`, `Tree` |
|
|
155
|
+
|
|
156
|
+
Every component is controlled: it shows `value` (or `isOn`) and reports what
|
|
157
|
+
the person asks for through a callback, typed with `@ac-kit/core`'s
|
|
158
|
+
`Callable`.
|
|
159
|
+
|
|
160
|
+
- `Knob` — `onChange` once per gesture, `onInput` while dragging, and
|
|
161
|
+
`onRequestEntry` when the person taps it or presses Enter: open your own
|
|
162
|
+
dialog, sheet or large `Slider` to type or pick a value. No surface is
|
|
163
|
+
bundled. A double tap goes back to `resetValue`.
|
|
164
|
+
- `Slider` — `orientation` `horizontal` or `vertical`; `onChange` once per
|
|
165
|
+
gesture, `onInput` while dragging; a drag never ends in a click.
|
|
166
|
+
- `ToggleButton` — `isOn`, `onToggle(nextIsOn)`, `indicator="light"` for the
|
|
167
|
+
hardware look; other `<button>` attributes pass through.
|
|
168
|
+
- `Readout` — `label` and the value as children; `live="polite"` announces
|
|
169
|
+
changes.
|
|
170
|
+
- `Meter` — `value`, `min`, `max` (finite), a `label`, optional `segments` and
|
|
171
|
+
`valueText`; read-only.
|
|
172
|
+
- `Switch` — `label`, optional `description`, `isOn`, `onToggle(nextIsOn)`: a
|
|
173
|
+
setting that applies as it is flipped.
|
|
174
|
+
- `RadioGroup` — `label` (the legend, visually hidden unless `isLabelShown`),
|
|
175
|
+
`options` (`value`, `label`, optional `description`, `icon`, `tone`,
|
|
176
|
+
`disabled`), `value`, `onChange(value)`; `appearance` `segmented` or
|
|
177
|
+
`cards`, `orientation`, `name`. Native radios in a `<fieldset>`: the browser
|
|
178
|
+
gives the arrow keys and form participation.
|
|
179
|
+
- `Button` — `variant` (`primary`, `secondary`, `ghost`), `size` (`regular`,
|
|
180
|
+
`large`), `tone`, `icon`; `type` defaults to `button`. `IconButton` — the
|
|
181
|
+
same with a required `label` naming and titling it, the icon as children.
|
|
182
|
+
- `Toolbar` — `label`, `orientation`; one tab stop over its children. Arrows,
|
|
183
|
+
Home and End move between them (Up and Down when vertical); a child that
|
|
184
|
+
owns the arrow keys — a radio group, a `Knob` or `Slider`, a text field —
|
|
185
|
+
keeps them, and only Tab leaves it. A radio group counts as one stop, its
|
|
186
|
+
checked radio.
|
|
187
|
+
- `Dialog` — `title`, `description`, `isOpen`, `onClose`, `placement`
|
|
188
|
+
(`center`, `bottom`, `side`, `sheet`), `isDismissible`, `closeLabel`,
|
|
189
|
+
`closeIcon`, `actions`. A native modal `<dialog>`, no portal. `onClose` is
|
|
190
|
+
asked once when Escape, the close button, a backdrop press or a
|
|
191
|
+
`<form method="dialog">` closes it; set `isOpen` to false in answer.
|
|
192
|
+
- `MenuButton` — `label` (the button's text and the menu's name;
|
|
193
|
+
`isLabelHidden` draws the `icon` alone), `variant`, `size`, `tone`, `side`,
|
|
194
|
+
`align`, `onOpenChange`; its children are the items: `MenuItem`
|
|
195
|
+
(`onSelect`), `MenuItemCheckbox` (`isChecked`, `onCheckedChange`),
|
|
196
|
+
`MenuItemRadio` (`isChecked`, `onSelect`, called only when it was not the
|
|
197
|
+
checked one), each with `icon`, `disabled` and `textValue` (the name
|
|
198
|
+
typeahead matches when the label is not plain text), grouped by `MenuGroup`
|
|
199
|
+
(`label`) and divided by `MenuSeparator`. The menu is a popover the browser
|
|
200
|
+
opens and closes (a press outside it or Escape closes it), so its open
|
|
201
|
+
state is its own and `onOpenChange` reports it. It closes before an item's
|
|
202
|
+
callback runs, focus back on the button, so an item that opens a `Dialog`
|
|
203
|
+
has the button as its opener. Other `<button>` attributes and a `ref` reach
|
|
204
|
+
the button.
|
|
205
|
+
- `Tooltip` — `content`, `relation` (`description`, the default, or `label`
|
|
206
|
+
for an icon-only trigger), `side`, `align`, `showDelayMs` (500),
|
|
207
|
+
`hideDelayMs` (200), `group`; its child is a function rendering the trigger
|
|
208
|
+
with the props it is given (a `ref` and the `aria-describedby` or
|
|
209
|
+
`aria-labelledby` linking it), which works with `Button`, `IconButton`,
|
|
210
|
+
`MenuButton` or any element. Give the trigger no `title`.
|
|
211
|
+
- `Toaster` — `queue` (your `ToastQueue`), `label` (the region's name, which
|
|
212
|
+
may name its shortcut), `closeLabel`, `position` (`top-start` …
|
|
213
|
+
`bottom-end`, default `bottom-end`), `hotkeys` (default `["F8"]`),
|
|
214
|
+
`closeIcon`. Render one per page, outside any dialog, and show toasts from
|
|
215
|
+
anywhere with `queue.show(content, performance.now(), options)`.
|
|
216
|
+
- `Tabs` — `selected` (a tab's `value`), `onSelectedChange(value)`,
|
|
217
|
+
`activation` (`automatic`, the default: a tab shows its panel as the arrows
|
|
218
|
+
reach it; `manual`: on Enter, Space or a click), `orientation`, and
|
|
219
|
+
`onDelete(value)` to let Delete close the focused tab (remove it in answer;
|
|
220
|
+
focus moves to the next tab, and the nearest enabled one is selected when
|
|
221
|
+
it was the selected tab). Its children are a `TabList` (`label` or
|
|
222
|
+
`labelledBy`) of `Tab`s (`value`, `icon`, `disabled`) and a `TabPanel`
|
|
223
|
+
(`value`) per tab. Every panel stays rendered, the hidden ones
|
|
224
|
+
`hidden="until-found"`, so they keep their state and the browser's find in
|
|
225
|
+
page selects the tab of a match.
|
|
226
|
+
- `ProgressRing` — `label` (not drawn) or `labelledBy`, `value` (`undefined`
|
|
227
|
+
while it cannot be told), `min` (0), `max` (100), `valueText`,
|
|
228
|
+
`isValueShown` to draw `valueText` inside, `tone`.
|
|
229
|
+
- `SpinButton` — `label` (`isLabelHidden`), `value`, `min` and `max` (either
|
|
230
|
+
may be omitted), `step` (1), `largeStep`, `format`, `onChange` once per key,
|
|
231
|
+
button press or entry, `decrementLabel` and `incrementLabel` (the buttons'
|
|
232
|
+
names), `decrementIcon`, `incrementIcon`, `disabled`, `tone`. With `parse`
|
|
233
|
+
(text to a number, or `undefined`), the value is also typed: Enter or
|
|
234
|
+
leaving the field commits it snapped, Escape goes back, text that is not a
|
|
235
|
+
number is marked invalid; `inputMode` picks the phone keyboard. For the
|
|
236
|
+
knob sheet's −, + and reset: a `SpinButton` and a `Button`.
|
|
237
|
+
- `Tree` — `label` or `labelledBy`, `roots`, `childrenOf` (a branch's
|
|
238
|
+
children; `undefined` for a leaf or for children not loaded yet),
|
|
239
|
+
`isBranch` (for lazy children), `textValueOf` (the name typeahead matches,
|
|
240
|
+
drawn without `renderItem`), `renderItem(node, state)`, `expanded` and
|
|
241
|
+
`onExpandedChange`, `selectionMode` (`single`, `multiple` or `none`),
|
|
242
|
+
`selected` and `onSelectedChange`, `selectionFollowsFocus`,
|
|
243
|
+
`onActivate(node)` (Enter and a click), `isDisabled`. Nodes are compared by
|
|
244
|
+
identity. Keep `childrenOf`, `isBranch`, `textValueOf` and `renderItem`
|
|
245
|
+
stable (module functions or `useCallback`): the rows are recomputed when
|
|
246
|
+
`roots`, `expanded`, `childrenOf` or `isBranch` change, and a row is drawn
|
|
247
|
+
again only when its own state changes, so a key costs one to two
|
|
248
|
+
milliseconds on 2 000 rows in current browsers. A click on a row's mark, or
|
|
249
|
+
a double click on a branch, expands or collapses it.
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
import { ToastQueue } from "@ac-kit/ui-common";
|
|
253
|
+
import {
|
|
254
|
+
IconButton,
|
|
255
|
+
MenuButton,
|
|
256
|
+
MenuItem,
|
|
257
|
+
MenuItemCheckbox,
|
|
258
|
+
Toaster,
|
|
259
|
+
Tooltip,
|
|
260
|
+
} from "@ac-kit/ui-common/preact";
|
|
261
|
+
|
|
262
|
+
const toasts = new ToastQueue();
|
|
263
|
+
|
|
264
|
+
<>
|
|
265
|
+
<MenuButton label="Score">
|
|
266
|
+
<MenuItem onSelect={openRenameDialog}>Rename…</MenuItem>
|
|
267
|
+
<MenuItemCheckbox isChecked={isLooping} onCheckedChange={setIsLooping}>
|
|
268
|
+
Loop
|
|
269
|
+
</MenuItemCheckbox>
|
|
270
|
+
</MenuButton>
|
|
271
|
+
<Tooltip content="Back to the start" relation="label">
|
|
272
|
+
{(trigger) => (
|
|
273
|
+
<IconButton {...trigger} label="Back to the start" title={undefined}>
|
|
274
|
+
<RewindIcon />
|
|
275
|
+
</IconButton>
|
|
276
|
+
)}
|
|
277
|
+
</Tooltip>
|
|
278
|
+
<Toaster queue={toasts} label="Notifications (F8)" closeLabel="Dismiss" />
|
|
279
|
+
</>;
|
|
280
|
+
|
|
281
|
+
toasts.show(
|
|
282
|
+
{
|
|
283
|
+
title: "Score deleted",
|
|
284
|
+
action: { label: "Undo", onAction: restoreScore },
|
|
285
|
+
},
|
|
286
|
+
performance.now(),
|
|
287
|
+
);
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
import {
|
|
292
|
+
SpinButton,
|
|
293
|
+
Tab,
|
|
294
|
+
TabList,
|
|
295
|
+
TabPanel,
|
|
296
|
+
Tabs,
|
|
297
|
+
Tree,
|
|
298
|
+
} from "@ac-kit/ui-common/preact";
|
|
299
|
+
|
|
300
|
+
// Module functions: stable, so the tree recomputes its rows only when
|
|
301
|
+
// `roots` or `expanded` change.
|
|
302
|
+
const childrenOf = (node: Asn1Node) => node.children;
|
|
303
|
+
const textValueOf = (node: Asn1Node) => describeNode(node);
|
|
304
|
+
|
|
305
|
+
<>
|
|
306
|
+
<Tabs selected={tab} onSelectedChange={setTab}>
|
|
307
|
+
<TabList label="Settings">
|
|
308
|
+
<Tab value="sound">Sound</Tab>
|
|
309
|
+
<Tab value="display">Display</Tab>
|
|
310
|
+
</TabList>
|
|
311
|
+
<TabPanel value="sound">
|
|
312
|
+
<SpinButton
|
|
313
|
+
label="Count-in bars"
|
|
314
|
+
value={bars}
|
|
315
|
+
min={0}
|
|
316
|
+
max={4}
|
|
317
|
+
onChange={setBars}
|
|
318
|
+
decrementLabel="Fewer bars"
|
|
319
|
+
incrementLabel="More bars"
|
|
320
|
+
/>
|
|
321
|
+
</TabPanel>
|
|
322
|
+
<TabPanel value="display">…</TabPanel>
|
|
323
|
+
</Tabs>
|
|
324
|
+
<Tree
|
|
325
|
+
labelledBy="structure-title"
|
|
326
|
+
roots={roots}
|
|
327
|
+
childrenOf={childrenOf}
|
|
328
|
+
textValueOf={textValueOf}
|
|
329
|
+
expanded={expanded}
|
|
330
|
+
onExpandedChange={setExpanded}
|
|
331
|
+
selected={selected}
|
|
332
|
+
onSelectedChange={setSelected}
|
|
333
|
+
selectionFollowsFocus
|
|
334
|
+
/>
|
|
335
|
+
</>;
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Menus and tooltips are placed by CSS anchor positioning, which every current
|
|
339
|
+
browser has (Chromium 125, Firefox 147, Safari 26), over the Popover API
|
|
340
|
+
(Chromium 114, Firefox 125, Safari 17): no script measures anything. For an
|
|
341
|
+
older browser, load a polyfill such as
|
|
342
|
+
[`@oddbird/css-anchor-positioning`](https://github.com/oddbird/css-anchor-positioning);
|
|
343
|
+
without one, a menu or tooltip shows in the middle of the viewport, still
|
|
344
|
+
usable.
|
|
345
|
+
|
|
346
|
+
A `value` outside `min`–`max` is drawn, formatted and announced as the nearest
|
|
347
|
+
end. Disabling a `Knob` or a `Slider` mid-gesture drops the gesture: nothing is
|
|
348
|
+
committed. Only the primary button drives them, and a `Slider` follows one
|
|
349
|
+
pointer at a time.
|
|
350
|
+
|
|
351
|
+
`useElementBinding(bind, deps)`, `useLatest(value)` and `joinClasses(base, extra)`
|
|
352
|
+
are exported for your own components: the first returns the callback ref to put on your element, runs
|
|
353
|
+
a `@ac-kit/ui-gesture/dom` binding on it once mounted and disposes it, aborting
|
|
354
|
+
its signal, at unmount, when the element is replaced or before a re-run for
|
|
355
|
+
changed `deps`; the second gives handlers the latest props without rebinding;
|
|
356
|
+
the third puts a caller's `class` after a root's own classes.
|
|
357
|
+
|
|
358
|
+
Every component takes `class`, added after its own, and `tone` (`accent`,
|
|
359
|
+
`positive`, `warning`, `negative`, or a name of your own) where it has a lit
|
|
360
|
+
colour.
|
|
361
|
+
|
|
362
|
+
## Styling
|
|
363
|
+
|
|
364
|
+
Import `@ac-kit/ui-common/styles.css` once for the default look. Its rules sit
|
|
365
|
+
in the `ack.common` cascade layer, so any rule of yours wins without raising
|
|
366
|
+
specificity. The file opens with the order statement `@layer ack.common,
|
|
367
|
+
ack.music;` that every `ui-*` stylesheet shares, so `@ac-kit/ui-music`'s rules
|
|
368
|
+
follow these whichever file your bundler emits first; keep both names in any
|
|
369
|
+
order statement of your own. Every colour, size and font is a custom property
|
|
370
|
+
with a neutral default: surfaces and lines are mixed from the current text
|
|
371
|
+
colour, so the controls fit a light or a dark page. Set them on `:root`, on a
|
|
372
|
+
panel, or on one control.
|
|
373
|
+
|
|
374
|
+
Every control root carries `ack-control` beside its own class (`ack-knob`,
|
|
375
|
+
`ack-slider`, …): the hook for what they share — the tone, the focus ring, the
|
|
376
|
+
disabled look, the touch target of the interactive ones (a `Readout`, a
|
|
377
|
+
`Meter` and a `ProgressRing` are displays and keep their own size) and, on the
|
|
378
|
+
controls a finger drags, no text
|
|
379
|
+
selection. The components also render stable part classes (`ack-knob-arc`,
|
|
380
|
+
`ack-slider-thumb`, …) and state attributes (`data-tone`, `data-state`,
|
|
381
|
+
`data-indicator`, `data-orientation`, `data-dragging`, `data-lit`,
|
|
382
|
+
`aria-pressed`, `aria-disabled`), which you may select on; the custom
|
|
383
|
+
properties are the supported way to theme them.
|
|
384
|
+
|
|
385
|
+
Shared by every control:
|
|
386
|
+
|
|
387
|
+
| property | default | what it sets |
|
|
388
|
+
| ---------------------- | ----------------------- | ------------------------------------------------------------ |
|
|
389
|
+
| `--ack-accent` | `#2563c9` | the lit colour of the default tone |
|
|
390
|
+
| `--ack-tone-positive` | `#1f7a45` | the lit colour of `tone="positive"` |
|
|
391
|
+
| `--ack-tone-warning` | `#e08a12` | the lit colour of `tone="warning"` |
|
|
392
|
+
| `--ack-tone-negative` | `#c4372e` | the lit colour of `tone="negative"` |
|
|
393
|
+
| `--ack-lit` | from the tone | the lit colour of one control; set it for a tone of your own |
|
|
394
|
+
| `--ack-lit-ink` | `#ffffff`, `#1a1300` on warning | text on a lit control, 4.5:1 on the default tones; set it with `--ack-lit` for a tone of your own |
|
|
395
|
+
| `--ack-surface` | text colour at 10 % | a control's body |
|
|
396
|
+
| `--ack-surface-raised` | text colour at 18 % | tracks and thumbs |
|
|
397
|
+
| `--ack-line` | text colour at 28 % | borders |
|
|
398
|
+
| `--ack-muted` | text colour at 65 % | captions and an off button's text |
|
|
399
|
+
| `--ack-focus-ring` | `--ack-lit` | the focus outline |
|
|
400
|
+
| `--ack-radius` | `6px` | corner radius |
|
|
401
|
+
| `--ack-radius-small` | `4px` | a readout's and a meter bar's corner radius |
|
|
402
|
+
| `--ack-target` | `44px` | the smallest touch target of an interactive control |
|
|
403
|
+
| `--ack-font-mono` | `ui-monospace, monospace` | values |
|
|
404
|
+
| `--ack-motion` | `120ms ease-out` | transitions |
|
|
405
|
+
|
|
406
|
+
A tone of your own: `.ack-knob[data-tone="left-hand"] { --ack-lit: #ff8c0d; }`.
|
|
407
|
+
|
|
408
|
+
Per control:
|
|
409
|
+
|
|
410
|
+
| property | default | what it sets |
|
|
411
|
+
| ------------------------------ | ------------------------ | --------------------------------------------------------- |
|
|
412
|
+
| `--ack-knob-size` | `52px` | the dial's width and height |
|
|
413
|
+
| `--ack-knob-stroke` | `4` | the track and arc width, in dial units of 52 |
|
|
414
|
+
| `--ack-knob-track` | `--ack-surface-raised` | the unlit track |
|
|
415
|
+
| `--ack-knob-cap` | `--ack-surface` | the knob's cap |
|
|
416
|
+
| `--ack-knob-pointer` | `currentColor` | the pointer line |
|
|
417
|
+
| `--ack-slider-length` | `160px` | a horizontal slider's least width, a vertical one's height |
|
|
418
|
+
| `--ack-slider-track` | `--ack-surface-raised` | the unlit track |
|
|
419
|
+
| `--ack-slider-track-thickness` | `6px` | the track's thickness |
|
|
420
|
+
| `--ack-slider-thumb` | `--ack-surface-raised` | the thumb |
|
|
421
|
+
| `--ack-slider-thumb-length` | `20px` | the thumb along the track |
|
|
422
|
+
| `--ack-slider-thumb-thickness` | `34px` | the thumb across the track |
|
|
423
|
+
| `--ack-slider-fraction` | set by the component | the value from 0 to 1; read it, do not set it |
|
|
424
|
+
| `--ack-toggle-button-light-off` | text colour at 30 % | a toggle button's light while off |
|
|
425
|
+
| `--ack-toggle-button-ink` | `--ack-lit-ink` | a toggle button's text and light while on |
|
|
426
|
+
| `--ack-readout-background` | `#0d0f12` | a readout's display |
|
|
427
|
+
| `--ack-readout-text` | `--ack-lit` tinted white | a readout's value |
|
|
428
|
+
| `--ack-readout-glow` | `--ack-lit` at 55 % | the value's glow |
|
|
429
|
+
| `--ack-readout-label` | text colour at 60 % | the caption |
|
|
430
|
+
| `--ack-readout-min-width` | `92px` | a readout's least width |
|
|
431
|
+
| `--ack-meter-length` | `160px` | a meter's length |
|
|
432
|
+
| `--ack-meter-thickness` | `10px` | a meter's thickness |
|
|
433
|
+
| `--ack-meter-gap` | `2px` | the space between segments |
|
|
434
|
+
| `--ack-meter-track` | `--ack-surface-raised` | an unlit bar or segment |
|
|
435
|
+
| `--ack-meter-fraction` | set by the component | the value from 0 to 1; read it, do not set it |
|
|
436
|
+
| `--ack-button-background` | `--ack-surface` | a button's body |
|
|
437
|
+
| `--ack-button-ink` | `--ack-lit-ink` | a primary button's text |
|
|
438
|
+
| `--ack-button-icon-size` | `20px` | the icon of a button, an icon button or a radio |
|
|
439
|
+
| `--ack-switch-width` | `44px` | a switch's track width |
|
|
440
|
+
| `--ack-switch-height` | `24px` | a switch's track height; the thumb fills it |
|
|
441
|
+
| `--ack-switch-track` | `--ack-surface-raised` | an off switch's track |
|
|
442
|
+
| `--ack-switch-thumb` | `#fff` | the thumb |
|
|
443
|
+
| `--ack-radio-background` | `--ack-surface` | an unchosen option |
|
|
444
|
+
| `--ack-radio-ink` | `--ack-lit-ink` | the chosen option's text |
|
|
445
|
+
| `--ack-radio-gap` | `0`, `8px` for cards | the space between options |
|
|
446
|
+
| `--ack-toolbar-gap` | `8px` | the space between a toolbar's controls |
|
|
447
|
+
| `--ack-dialog-width` | `32rem` | a dialog's widest width; a sheet's when wide |
|
|
448
|
+
| `--ack-dialog-background` | `Canvas` | the panel |
|
|
449
|
+
| `--ack-dialog-text` | `CanvasText` | the panel's text |
|
|
450
|
+
| `--ack-dialog-backdrop` | `rgb(0 0 0 / 0.5)` | what dims the page behind |
|
|
451
|
+
| `--ack-dialog-padding` | `20px` | inside the panel |
|
|
452
|
+
| `--ack-menu-offset` | `4px` | the gap between a menu and its button |
|
|
453
|
+
| `--ack-menu-min-width` | `10rem` | a menu's least width; never narrower than its button |
|
|
454
|
+
| `--ack-menu-max-height` | `24rem` | a menu's greatest height before it scrolls |
|
|
455
|
+
| `--ack-menu-background` | `Canvas` | the menu |
|
|
456
|
+
| `--ack-menu-text` | `CanvasText` | the menu's text |
|
|
457
|
+
| `--ack-menu-shadow` | a soft drop shadow | the menu's shadow |
|
|
458
|
+
| `--ack-menu-item-focus` | text colour at 12 % | the focused item, also the one a mouse is over |
|
|
459
|
+
| `--ack-tooltip-offset` | `6px` | the gap between a tooltip and its trigger |
|
|
460
|
+
| `--ack-tooltip-max-width` | `18rem` | a tooltip's widest width before its text wraps |
|
|
461
|
+
| `--ack-tooltip-background` | `CanvasText` | the tooltip: the page's colours inverted |
|
|
462
|
+
| `--ack-tooltip-text` | `Canvas` | the tooltip's text |
|
|
463
|
+
| `--ack-toast-width` | `24rem` | the toaster's width, never wider than the viewport |
|
|
464
|
+
| `--ack-toaster-inset` | `16px` | the toaster's distance from the viewport's edges |
|
|
465
|
+
| `--ack-toast-gap` | `8px` | the space between toasts |
|
|
466
|
+
| `--ack-toast-background` | `Canvas` | a toast |
|
|
467
|
+
| `--ack-toast-text` | `CanvasText` | a toast's text |
|
|
468
|
+
| `--ack-toast-shadow` | a soft drop shadow | a toast's shadow |
|
|
469
|
+
| `--ack-toast-accent` | from the tone | a toast's leading edge; set it for a tone of your own |
|
|
470
|
+
| `--ack-toast-obscuring-opacity` | `0.2` | a toast's opacity while it covers the focused control |
|
|
471
|
+
| `--ack-tabs-gap` | `12px` | the space between a tab list and its panel |
|
|
472
|
+
| `--ack-tab-indicator` | `--ack-lit` | the bar under (or beside) the selected tab |
|
|
473
|
+
| `--ack-tab-indicator-thickness` | `3px` | that bar's thickness |
|
|
474
|
+
| `--ack-progress-ring-size` | `48px` | a progress ring's width and height |
|
|
475
|
+
| `--ack-progress-ring-thickness` | `4` | its track and arc width, in ring units of 48 |
|
|
476
|
+
| `--ack-progress-ring-track` | `--ack-surface-raised` | the unfilled track |
|
|
477
|
+
| `--ack-progress-ring-value-size` | `12px` | the value text drawn inside |
|
|
478
|
+
| `--ack-progress-fraction` | set by the component | the value from 0 to 1; read it, do not set it |
|
|
479
|
+
| `--ack-spin-button-background` | `--ack-surface` | a spin button's body |
|
|
480
|
+
| `--ack-spin-button-field-width` | `5em` | the value's width between the buttons |
|
|
481
|
+
| `--ack-tree-indent` | `1.25rem` | a tree row's indent per level |
|
|
482
|
+
| `--ack-tree-item-height` | `--ack-target` | a tree row's least height; keep it 24px or more (WCAG 2.5.8) |
|
|
483
|
+
| `--ack-tree-toggle-size` | `24px` | a branch's expand mark, a pointer target of its own |
|
|
484
|
+
| `--ack-tree-item-hover` | text colour at 6 % | the row under the pointer |
|
|
485
|
+
| `--ack-tree-item-selected` | `--ack-lit` at 16 % | a selected row, which also carries a bar in `--ack-lit` |
|
|
486
|
+
| `--ack-tree-level` | set by the component | the row's level from 1; read it, do not set it |
|
|
487
|
+
|
|
488
|
+
A dialog stops the page behind from scrolling while it is open
|
|
489
|
+
(`:root:has(dialog.ack-dialog[open])`), and its entry and exit are transitions
|
|
490
|
+
that `prefers-reduced-motion: reduce` turns off.
|
|
491
|
+
|
|
492
|
+
A menu and a tooltip take `data-side` and `data-align` from their props: the
|
|
493
|
+
stylesheet turns them into a `position-area` against the trigger, with
|
|
494
|
+
`position-try-fallbacks` flipping them to the other side when the viewport has
|
|
495
|
+
no room; along the trigger they shift to stay inside it. A menu is at least
|
|
496
|
+
as wide as its button. The toaster sits at the edge `data-position` names,
|
|
497
|
+
clear of the safe-area insets, and toasts take a leading edge in their tone
|
|
498
|
+
(`data-tone`) and a `data-state` of `open` or `closing` while they leave.
|
|
499
|
+
Their entries and exits, like the menu's and the tooltip's, are transitions
|
|
500
|
+
that `prefers-reduced-motion: reduce` turns off.
|
|
501
|
+
|
|
502
|
+
Without the stylesheet the components still work, unstyled; only the slider's
|
|
503
|
+
thumb and the meter's bar depend on it for their position.
|
|
504
|
+
|
|
505
|
+
## Accessibility
|
|
506
|
+
|
|
507
|
+
- `Knob` and `Slider` are WAI-ARIA sliders: named by their label, announcing
|
|
508
|
+
the formatted value, stepped by the arrow keys, Page Up and Page Down by ten
|
|
509
|
+
steps, Home and End to the ends. A knob's value entry is reached with Enter
|
|
510
|
+
or Space as well as by a tap. A disabled one leaves the tab order and
|
|
511
|
+
announces `aria-disabled`.
|
|
512
|
+
- `ToggleButton` is a native button announced as a toggle, pressed or not.
|
|
513
|
+
- `Button` and `IconButton` are native buttons; an `IconButton` is named by its
|
|
514
|
+
`label`.
|
|
515
|
+
- `Switch` is a button with the `switch` role and `aria-checked`, flipped with
|
|
516
|
+
Space or Enter, its description linked by `aria-describedby`.
|
|
517
|
+
- `RadioGroup` is a native radio group in a `<fieldset>` and `<legend>`: arrows
|
|
518
|
+
move and choose, Tab leaves.
|
|
519
|
+
- `Toolbar` is the `toolbar` role with one tab stop and arrow-key movement,
|
|
520
|
+
leaving the arrows to the controls that own them.
|
|
521
|
+
- `Dialog` is a native modal `<dialog>` named by its title and described by its
|
|
522
|
+
description: the page is inert, Escape closes it when dismissible, focus
|
|
523
|
+
returns to the opener.
|
|
524
|
+
- `MenuButton` follows the WAI-ARIA menu button and menu patterns: a button
|
|
525
|
+
with `aria-haspopup="menu"` and `aria-expanded`, a `menu` named by it, items
|
|
526
|
+
of the `menuitem`, `menuitemcheckbox` and `menuitemradio` roles with
|
|
527
|
+
`aria-checked`, in named `group`s and between `separator`s. Enter, Space and
|
|
528
|
+
Arrow Down open it on its first item, Arrow Up on its last; the arrows move
|
|
529
|
+
round, Home and End go to the ends, typing a name moves to it, Enter
|
|
530
|
+
chooses and closes, Space checks a checkbox or radio item and keeps it open,
|
|
531
|
+
Escape and a press outside close it, Tab closes it and moves on. Focus
|
|
532
|
+
returns to the button. A disabled item stays focusable and is announced as
|
|
533
|
+
disabled, as the practices advise, and is not chosen. Items are at least
|
|
534
|
+
`--ack-target` high.
|
|
535
|
+
- `Tooltip` follows the WAI-ARIA tooltip pattern and WCAG 2.2 success
|
|
536
|
+
criterion 1.4.13: the `tooltip` role, describing or naming its trigger
|
|
537
|
+
whether shown or not, shown on a mouse or pen hover after its delay and at
|
|
538
|
+
once on a keyboard focus (not on the focus a click gives); Escape hides it
|
|
539
|
+
without moving focus or the pointer (and does not close a dialog around
|
|
540
|
+
it), the pointer can move onto it, and it stays while hovered or focused. A
|
|
541
|
+
press of the trigger hides it. Touch does not hover: what a tooltip says
|
|
542
|
+
must be reachable another way on a touch screen, or be the name of an icon
|
|
543
|
+
that assistive technology reads.
|
|
544
|
+
- `Toaster` is a landmark region named by its `label`. Each toast is
|
|
545
|
+
announced as it shows by a visually hidden live region, `status` (polite)
|
|
546
|
+
or `alert` for an `assertive` toast, placed in the modal dialog holding
|
|
547
|
+
focus when one is open — which would otherwise leave the announcement, and
|
|
548
|
+
the toasts, inert; the toasts move into that dialog too, so they stay
|
|
549
|
+
operable. Toasts never take focus: F8 does, and F8 again goes back; Escape
|
|
550
|
+
dismisses the focused toast, focus moving to the next one. Their clocks stop
|
|
551
|
+
while the pointer is over them, focus is among them or the page is hidden,
|
|
552
|
+
and a toast with an action stays until dismissed (WCAG 2.2.1): give people a
|
|
553
|
+
setting for the queue's `durationMs` too. While toasts cover part of the
|
|
554
|
+
focused control, the toaster takes `data-obscuring` and they fade until
|
|
555
|
+
hovered or focused, so focus is never hidden behind them (WCAG 2.4.11).
|
|
556
|
+
- `Readout` is a group named once by its caption.
|
|
557
|
+
- `Meter` has the `meter` role with its range and value (and `valueText`), and
|
|
558
|
+
no keyboard.
|
|
559
|
+
- `Tabs` follow the WAI-ARIA tabs pattern: a named `tablist` of `tab`s with
|
|
560
|
+
`aria-selected` and `aria-controls`, each `tabpanel` named by its tab. The
|
|
561
|
+
tab list is one tab stop, on the selected tab; the arrows along it move
|
|
562
|
+
round (mirrored right to left), Home and End go to the ends, and the panel,
|
|
563
|
+
or its first control, is the next tab stop. A disabled tab is focusable and
|
|
564
|
+
announced, never selected. A tab list wider than its box scrolls without a
|
|
565
|
+
tab stop of its own. The selected tab carries a bar besides its colour, in
|
|
566
|
+
forced colours too.
|
|
567
|
+
- `ProgressRing` has the `progressbar` role, its value and `valueText`, no
|
|
568
|
+
value while indeterminate; its turning arc stands still under
|
|
569
|
+
`prefers-reduced-motion: reduce`, and forced colours draw it in system
|
|
570
|
+
colours.
|
|
571
|
+
- `SpinButton` follows the WAI-ARIA spinbutton pattern: the `spinbutton`
|
|
572
|
+
role with the bounds it has and its formatted value, Arrow Up and Down, Page
|
|
573
|
+
Up and Down, Home and End. Its − and + buttons are named, out of the tab
|
|
574
|
+
order, and never take focus, so a phone keyboard stays closed; pressed
|
|
575
|
+
while focus is elsewhere (a screen reader's virtual cursor), they announce
|
|
576
|
+
the new value through a polite live region. An entry that is not a number
|
|
577
|
+
is `aria-invalid`, shown by an outline and a wavy underline, not by colour
|
|
578
|
+
alone.
|
|
579
|
+
- `Tree` follows the WAI-ARIA tree view pattern: a named `tree`
|
|
580
|
+
(`aria-multiselectable` in multiple selection) of `treeitem`s, each stating
|
|
581
|
+
`aria-level`, `aria-posinset`, `aria-setsize` and, for a branch,
|
|
582
|
+
`aria-expanded` (`aria-busy` while its children load), so the flat list
|
|
583
|
+
reads as nested. Selection is stated on every item in multiple selection,
|
|
584
|
+
on the selected one only otherwise. One tab stop; the keys are the
|
|
585
|
+
pattern's, typeahead included, mirrored right to left. When the focused
|
|
586
|
+
row goes away, focus moves to its nearest row still shown rather than to
|
|
587
|
+
the page. A selected row carries a bar besides its background, in forced
|
|
588
|
+
colours too; rows are at least `--ack-target` high and a branch's mark is a
|
|
589
|
+
24px target of its own.
|
|
590
|
+
- Pointer input is touch first: pointers are captured for the length of a
|
|
591
|
+
gesture, `touch-action` keeps the page from scrolling under a knob's drag
|
|
592
|
+
(a slider lets it scroll across the track, and a scroll that starts cancels
|
|
593
|
+
the press), and interactive controls' touch targets are at least
|
|
594
|
+
`--ack-target` wide and high (a readout and a meter are displays, exempt).
|
|
595
|
+
|
|
596
|
+
## Coming from `@ac-kit/ui-controls`
|
|
597
|
+
|
|
598
|
+
`@ac-kit/ui-controls` is replaced by this package, `@ac-kit/ui-music` (the
|
|
599
|
+
keyboard and the dBFS meter scale) and `@ac-kit/ui-gesture` (`TapGesture`).
|
|
600
|
+
What moved here:
|
|
601
|
+
|
|
602
|
+
| `@ac-kit/ui-controls` | here | change |
|
|
603
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------- |
|
|
604
|
+
| `FaderOrientation`, `FaderTrack`, `faderValueAt` | `SliderOrientation`, `SliderTrack`, `sliderTrackValueAt` | renamed |
|
|
605
|
+
| `KnobArc`, `KNOB_ARC`, `KnobAngles`, `KnobAnglesOptions`, `knobAngles`, `KnobDragOptions`, `knobDragValue` | same names | none |
|
|
606
|
+
| `knobArcPath` | `knobArcPath` | `dial` is a `KnobDial` (`centerX`, `centerY`, `radius`), not a `Circle2` |
|
|
607
|
+
| `LedButtonAttributes`, `LedButtonAttributesInput`, `ledButtonAttributes` | `ToggleButtonAttributes`, `ToggleButtonAttributesInput`, `toggleButtonAttributes` | renamed; `indicator` in, `data-indicator` out |
|
|
608
|
+
| `MeterZone` | — | removed: segments carry a `ControlTone` |
|
|
609
|
+
| `MeterSegment` | `MeterSegment` | `zone` → `tone` |
|
|
610
|
+
| `METER_SEGMENTS` | `@ac-kit/ui-music`'s `PEAK_METER_SEGMENTS` | moved and renamed; zones → tones |
|
|
611
|
+
| `meterLitCount` | `meterLitCount` | none |
|
|
612
|
+
| `ReadoutLive`, `ReadoutAttributes`, `ReadoutAttributesInput`, `readoutAttributes`, `ControlTone` | same names | none |
|
|
613
|
+
| `SliderAttributes`, `SliderAttributesInput`, `sliderAttributes`, `SliderRange`, `snapSliderValue`, `sliderFraction`, `sliderValueAt`, `SteppedValueOptions`, `steppedValue` | same names | none |
|
|
614
|
+
| `/preact`: `Fader`, `FaderProps` | `Slider`, `SliderProps` | renamed; pointer input through `ui-gesture/dom`; only the primary button drives it, a drag never ends in a click |
|
|
615
|
+
| `/preact`: `Knob`, `KnobProps` | same names | props unchanged; pointer input through `ui-gesture/dom`; only the primary button drives it |
|
|
616
|
+
| `/preact`: `LedButton`, `LedButtonProps` | `ToggleButton`, `ToggleButtonProps` | renamed; pass `indicator="light"` for the light |
|
|
617
|
+
| `/preact`: `Readout`, `ReadoutProps` | same names | none |
|
|
618
|
+
| `/styles.css` | `@ac-kit/ui-common/styles.css`, then `@ac-kit/ui-music/styles.css` | layer and class renames below |
|
|
619
|
+
|
|
620
|
+
The stylesheet's contract changed with the names:
|
|
621
|
+
|
|
622
|
+
| `@ac-kit/ui-controls` | here |
|
|
623
|
+
| ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
624
|
+
| layer `ack-controls` | `ack.common` (and `ack.music`), after the order statement `@layer ack.common, ack.music;` |
|
|
625
|
+
| — | `ack-control` on every root |
|
|
626
|
+
| `.ack-fader`, `.ack-fader-header`, `-label`, `-value`, `-control`, `-track`, `-range`, `-thumb` | `.ack-slider`, `.ack-slider-header`, `-label`, `-value`, `-control`, `-track`, `-range`, `-thumb` |
|
|
627
|
+
| `--ack-fader-length`, `-track`, `-track-thickness`, `-thumb`, `-thumb-length`, `-thumb-thickness`, `-fraction` | `--ack-slider-length`, `-track`, `-track-thickness`, `-thumb`, `-thumb-length`, `-thumb-thickness`, `-fraction` |
|
|
628
|
+
| `.ack-led-button`, `.ack-led-button-light` | `.ack-toggle-button`, `.ack-toggle-button-light` (drawn only with `indicator="light"`) |
|
|
629
|
+
| `--ack-led-off`, `--ack-led-ink` | `--ack-toggle-button-light-off`, `--ack-toggle-button-ink` |
|
|
630
|
+
| knob and readout classes and properties, shared tokens, `data-*` attributes | unchanged |
|
|
631
|
+
|
|
632
|
+
See the
|
|
633
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/ui-common/)
|
|
634
|
+
for the full reference.
|