@ac-kit/ui-common 0.1.0 → 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.
Files changed (101) hide show
  1. package/CHANGELOG.md +155 -0
  2. package/README.md +327 -9
  3. package/dist/anchored/anchored.d.ts +19 -0
  4. package/dist/anchored/anchored.d.ts.map +1 -0
  5. package/dist/anchored/anchored.js +2 -0
  6. package/dist/anchored/anchored.js.map +1 -0
  7. package/dist/focus/typeahead.d.ts +112 -0
  8. package/dist/focus/typeahead.d.ts.map +1 -0
  9. package/dist/focus/typeahead.js +178 -0
  10. package/dist/focus/typeahead.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +10 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/menu/menu.d.ts +157 -0
  16. package/dist/menu/menu.d.ts.map +1 -0
  17. package/dist/menu/menu.js +162 -0
  18. package/dist/menu/menu.js.map +1 -0
  19. package/dist/preact/_anchor.d.ts +13 -0
  20. package/dist/preact/_anchor.d.ts.map +1 -0
  21. package/dist/preact/_anchor.js +39 -0
  22. package/dist/preact/_anchor.js.map +1 -0
  23. package/dist/preact/_dom.d.ts +14 -0
  24. package/dist/preact/_dom.d.ts.map +1 -0
  25. package/dist/preact/_dom.js +31 -0
  26. package/dist/preact/_dom.js.map +1 -0
  27. package/dist/preact/_live-announcer.d.ts +26 -0
  28. package/dist/preact/_live-announcer.d.ts.map +1 -0
  29. package/dist/preact/_live-announcer.js +101 -0
  30. package/dist/preact/_live-announcer.js.map +1 -0
  31. package/dist/preact/index.d.ts +7 -0
  32. package/dist/preact/index.d.ts.map +1 -1
  33. package/dist/preact/index.js +7 -0
  34. package/dist/preact/index.js.map +1 -1
  35. package/dist/preact/knob.d.ts.map +1 -1
  36. package/dist/preact/knob.js +5 -13
  37. package/dist/preact/knob.js.map +1 -1
  38. package/dist/preact/menu-button.d.ts +117 -0
  39. package/dist/preact/menu-button.d.ts.map +1 -0
  40. package/dist/preact/menu-button.js +330 -0
  41. package/dist/preact/menu-button.js.map +1 -0
  42. package/dist/preact/progress-ring.d.ts +42 -0
  43. package/dist/preact/progress-ring.d.ts.map +1 -0
  44. package/dist/preact/progress-ring.js +26 -0
  45. package/dist/preact/progress-ring.js.map +1 -0
  46. package/dist/preact/slider.d.ts.map +1 -1
  47. package/dist/preact/slider.js +6 -4
  48. package/dist/preact/slider.js.map +1 -1
  49. package/dist/preact/spin-button.d.ts +67 -0
  50. package/dist/preact/spin-button.d.ts.map +1 -0
  51. package/dist/preact/spin-button.js +132 -0
  52. package/dist/preact/spin-button.js.map +1 -0
  53. package/dist/preact/tabs.d.ts +97 -0
  54. package/dist/preact/tabs.d.ts.map +1 -0
  55. package/dist/preact/tabs.js +264 -0
  56. package/dist/preact/tabs.js.map +1 -0
  57. package/dist/preact/toaster.d.ts +43 -0
  58. package/dist/preact/toaster.d.ts.map +1 -0
  59. package/dist/preact/toaster.js +356 -0
  60. package/dist/preact/toaster.js.map +1 -0
  61. package/dist/preact/toolbar.d.ts.map +1 -1
  62. package/dist/preact/toolbar.js +2 -8
  63. package/dist/preact/toolbar.js.map +1 -1
  64. package/dist/preact/tooltip.d.ts +67 -0
  65. package/dist/preact/tooltip.d.ts.map +1 -0
  66. package/dist/preact/tooltip.js +165 -0
  67. package/dist/preact/tooltip.js.map +1 -0
  68. package/dist/preact/tree.d.ts +93 -0
  69. package/dist/preact/tree.d.ts.map +1 -0
  70. package/dist/preact/tree.js +399 -0
  71. package/dist/preact/tree.js.map +1 -0
  72. package/dist/progress/progress.d.ts +51 -0
  73. package/dist/progress/progress.d.ts.map +1 -0
  74. package/dist/progress/progress.js +43 -0
  75. package/dist/progress/progress.js.map +1 -0
  76. package/dist/spin-button/spin-button.d.ts +110 -0
  77. package/dist/spin-button/spin-button.d.ts.map +1 -0
  78. package/dist/spin-button/spin-button.js +179 -0
  79. package/dist/spin-button/spin-button.js.map +1 -0
  80. package/dist/tabs/tabs.d.ts +157 -0
  81. package/dist/tabs/tabs.d.ts.map +1 -0
  82. package/dist/tabs/tabs.js +120 -0
  83. package/dist/tabs/tabs.js.map +1 -0
  84. package/dist/toast/toast-queue.d.ts +212 -0
  85. package/dist/toast/toast-queue.d.ts.map +1 -0
  86. package/dist/toast/toast-queue.js +290 -0
  87. package/dist/toast/toast-queue.js.map +1 -0
  88. package/dist/toast/toasts-obscure.d.ts +25 -0
  89. package/dist/toast/toasts-obscure.d.ts.map +1 -0
  90. package/dist/toast/toasts-obscure.js +30 -0
  91. package/dist/toast/toasts-obscure.js.map +1 -0
  92. package/dist/tooltip/tooltip.d.ts +183 -0
  93. package/dist/tooltip/tooltip.d.ts.map +1 -0
  94. package/dist/tooltip/tooltip.js +185 -0
  95. package/dist/tooltip/tooltip.js.map +1 -0
  96. package/dist/tree/tree.d.ts +302 -0
  97. package/dist/tree/tree.d.ts.map +1 -0
  98. package/dist/tree/tree.js +439 -0
  99. package/dist/tree/tree.js.map +1 -0
  100. package/package.json +22 -12
  101. package/styles.css +894 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,160 @@
1
1
  # @ac-kit/ui-common
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0b4fe43: A menu button, a tooltip and toasts, over the Popover API and CSS anchor
8
+ positioning, and a typeahead for lists.
9
+
10
+ - `MenuButton` (`/preact`), with `MenuItem`, `MenuItemCheckbox`,
11
+ `MenuItemRadio`, `MenuGroup` and `MenuSeparator`, follows the WAI-ARIA menu
12
+ button and menu patterns: Enter, Space and the arrows open it on its first
13
+ or last item, the arrows, Home, End and typed names move in it, Enter
14
+ chooses and closes, Space checks a checkbox or radio item and keeps it open,
15
+ Escape, Tab and a press outside close it, and focus returns to the button
16
+ before an item's callback runs. A disabled item stays focusable and is not
17
+ chosen. `onOpenChange` reports the open state; the items' checked states are
18
+ the caller's.
19
+ - `Tooltip` (`/preact`) describes or names its trigger (`relation`), shows on
20
+ a mouse or pen hover after `showDelayMs` and at once on a keyboard focus,
21
+ stays while the trigger or the tooltip is hovered or focused, and hides on
22
+ Escape (without closing a dialog around it) and on a press, per WCAG 2.2
23
+ success criterion 1.4.13. The tooltips of a `TooltipGroup` show one at a
24
+ time, the next without its delay.
25
+ - `Toaster` (`/preact`) shows a `ToastQueue`'s toasts in a named region at an
26
+ edge of the viewport and announces each one through a polite or assertive
27
+ live region; while a modal dialog holds focus, both move into it so they are
28
+ neither inert nor silent. F8 takes focus to the toasts and back, Escape
29
+ dismisses the focused one, and their clocks stop while hovered, focused or
30
+ with the page hidden. A toast with an action stays until dismissed unless
31
+ given a duration; showing a toast again with its id updates it in place.
32
+ Toasts covering part of the focused control fade until hovered (WCAG 2.2
33
+ success criterion 2.4.11).
34
+ - The core gains the framework-free parts every adapter shares:
35
+ `menuButtonAttributes`, `menuAttributes`, `menuItemAttributes`,
36
+ `menuButtonKeyAction`, `menuKeyAction`; `tooltipAttributes`,
37
+ `tooltipTriggerAttributes`, `tooltipStep`, `TOOLTIP_CLOSED`,
38
+ `TooltipGroup`; `ToastQueue`, `toasterAttributes`, `toastAttributes`,
39
+ `toastAnnouncement`, `toastsObscure`; `Typeahead`, `typeaheadIndex` (grapheme- and
40
+ locale-aware, case- and accent-insensitive), `isTypeaheadKey`; and the
41
+ `AnchoredSide` and `AnchoredAlign` placement types.
42
+ - `styles.css` places a menu or tooltip on its `data-side` and `data-align`,
43
+ flipping it when the viewport has no room and shifting it inside, with new
44
+ `--ack-menu-*`, `--ack-tooltip-*`, `--ack-toast-*` and `--ack-toaster-inset`
45
+ properties; their transitions stop under `prefers-reduced-motion: reduce`.
46
+ A browser without anchor positioning needs a polyfill, or shows them in the
47
+ middle of the viewport.
48
+
49
+ The package now depends on `@ac-kit/browser`.
50
+ - 0b4fe43: Tabs, a progress ring, a spin button and a tree view.
51
+
52
+ - `Tabs` (`/preact`), with `TabList`, `Tab` and `TabPanel`, follows the
53
+ WAI-ARIA tabs pattern: one tab stop on the selected tab, the arrows along
54
+ the list moving round (mirrored right to left), Home and End to the ends,
55
+ then the panel or its first control. Activation is `automatic` (a tab shows
56
+ its panel as the arrows reach it) or `manual` (Enter, Space or a click). A
57
+ disabled tab is focusable and never selected. With `onDelete`, Delete closes
58
+ the focused tab, focus moving to the next and the nearest enabled tab
59
+ selected in its place. Hidden panels stay rendered `hidden="until-found"`,
60
+ so they keep their state and find in page selects the tab of a match. The
61
+ selection is the caller's.
62
+ - `ProgressRing` (`/preact`) is a `progressbar` drawn as an arc from twelve
63
+ o'clock, with its value and `valueText`, or turning while indeterminate
64
+ (still under `prefers-reduced-motion: reduce`); it can draw its value text
65
+ inside.
66
+ - `SpinButton` (`/preact`) follows the WAI-ARIA spinbutton pattern: Arrow Up
67
+ and Down, Page Up and Down by ten steps, Home and End to the bounds it has,
68
+ either bound optional. With `parse`, the value is also typed, committed on
69
+ Enter or blur snapped to the steps and bounds, reverted on Escape, and
70
+ marked invalid while it is not a number. Its − and + buttons are named, out
71
+ of the tab order, never take focus, stop at the bounds, and announce the new
72
+ value politely when focus is elsewhere. `onChange` fires once per key,
73
+ press or entry.
74
+ - `Tree` (`/preact`) follows the WAI-ARIA tree view pattern over the caller's
75
+ nodes (`roots`, `childrenOf`, `textValueOf`, `renderItem`): one tab stop,
76
+ the pattern's keys including `*`, typeahead and the multiple-selection keys,
77
+ mirrored right to left; `selectionMode` `single`, `multiple` or `none`,
78
+ `selectionFollowsFocus`, `onActivate` (Enter and a click), disabled nodes
79
+ focusable but never selected or activated, and lazy children shown busy
80
+ until loaded (`isBranch`). Expansion and selection are the caller's. Every
81
+ row states its level, position and set size; a row is drawn again only when
82
+ its own state changes, and focus moves to the nearest row left when the
83
+ focused one goes away.
84
+ - The core gains the framework-free parts: `tabListAttributes`,
85
+ `tabAttributes`, `tabPanelAttributes`, `tabsKeyAction`;
86
+ `progressAttributes`; `SpinButtonRange`, `snapSpinButtonValue`,
87
+ `spinButtonValue`, `spinButtonAttributes`; `TreeSource`, `TreeRows`,
88
+ `visibleTreeRows` (iterative, a node's row in O(1), a node shown twice
89
+ refused), `treeKeyAction`, `nextTreeSelection`, `expandTreeSiblings`,
90
+ `treePath`, `treeTabStop`, `treeAttributes`, `treeItemAttributes`; and
91
+ `typeaheadCharacter` and `Typeahead.find`, which the menu now uses too.
92
+ - `styles.css` draws them with new `--ack-tabs-*`, `--ack-tab-*`,
93
+ `--ack-progress-ring-*`, `--ack-spin-button-*` and `--ack-tree-*`
94
+ properties; a selected tab and a selected row carry a bar besides their
95
+ colour, forced colours draw them in system colours, and every new
96
+ transition and animation stops under `prefers-reduced-motion: reduce`.
97
+
98
+ ### Patch Changes
99
+
100
+ - 0b4fe43: `Knob` and `Slider` fixes. A `Knob` that is disabled drops a tap pending in its
101
+ double-tap window, so enabling it again before the deadline no longer requests
102
+ entry. A `Slider` swallows the click after a press released away from where it
103
+ started, even with no move in between, and lets through the click of a press
104
+ whose moves never left the press point. The arrow keys, Page Up and Page Down,
105
+ Home and End of both step from the value they show: a value of `200` in
106
+ `[0, 100]` shows `100`, and ArrowLeft gives `99`.
107
+ - Updated dependencies [0b4fe43]
108
+ - Updated dependencies [0b4fe43]
109
+ - Updated dependencies [0b4fe43]
110
+ - Updated dependencies [0b4fe43]
111
+ - Updated dependencies [0b4fe43]
112
+ - Updated dependencies [0b4fe43]
113
+ - Updated dependencies [0b4fe43]
114
+ - Updated dependencies [0b4fe43]
115
+ - Updated dependencies [0b4fe43]
116
+ - Updated dependencies [0b4fe43]
117
+ - Updated dependencies [0b4fe43]
118
+ - Updated dependencies [0b4fe43]
119
+ - Updated dependencies [0b4fe43]
120
+ - Updated dependencies [0b4fe43]
121
+ - Updated dependencies [0b4fe43]
122
+ - Updated dependencies [0b4fe43]
123
+ - Updated dependencies [0b4fe43]
124
+ - Updated dependencies [0b4fe43]
125
+ - Updated dependencies [0b4fe43]
126
+ - Updated dependencies [0b4fe43]
127
+ - Updated dependencies [0b4fe43]
128
+ - Updated dependencies [0b4fe43]
129
+ - Updated dependencies [0b4fe43]
130
+ - Updated dependencies [0b4fe43]
131
+ - Updated dependencies [0b4fe43]
132
+ - Updated dependencies [0b4fe43]
133
+ - Updated dependencies [0b4fe43]
134
+ - Updated dependencies [0b4fe43]
135
+ - Updated dependencies [0b4fe43]
136
+ - Updated dependencies [0b4fe43]
137
+ - Updated dependencies [0b4fe43]
138
+ - Updated dependencies [0b4fe43]
139
+ - Updated dependencies [0b4fe43]
140
+ - Updated dependencies [0b4fe43]
141
+ - Updated dependencies [0b4fe43]
142
+ - Updated dependencies [0b4fe43]
143
+ - Updated dependencies [0b4fe43]
144
+ - Updated dependencies [0b4fe43]
145
+ - Updated dependencies [0b4fe43]
146
+ - Updated dependencies [0b4fe43]
147
+ - Updated dependencies [0b4fe43]
148
+ - Updated dependencies [0b4fe43]
149
+ - @ac-kit/algo@0.6.0
150
+ - @ac-kit/browser@0.4.0
151
+ - @ac-kit/core@0.13.0
152
+ - @ac-kit/math-geometry@0.4.0
153
+ - @ac-kit/math-linear@0.4.0
154
+ - @ac-kit/math-scalar@0.4.0
155
+ - @ac-kit/ui-gesture@0.1.1
156
+ - @ac-kit/format-svg@0.1.5
157
+
3
158
  ## 0.1.0
4
159
 
5
160
  ### Minor Changes
package/README.md CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  Generic controls for the browser, touch first: a knob turned by dragging up
4
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 and a modal
6
- dialog. Each one is a headless core — its state and behaviour as plain
7
- functions and data, with no framework and no DOM — and a component per
8
- framework over it, styled only through CSS custom properties.
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.
9
11
 
10
12
  ```tsx
11
13
  import { Knob } from "@ac-kit/ui-common/preact";
@@ -64,10 +66,65 @@ tests anywhere. Every function is pure and every time is passed in.
64
66
  arrow key, Home or End moves to, skipping disabled ones, wrapping or not,
65
67
  mirrored in a right-to-left direction; `ownsArrowKeys` says whether an
66
68
  element (its tag, input type, role, editable content) uses the arrow keys
67
- itself, so a container leaves them to it.
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.
68
100
  - **Meter.** `meterAttributes` — the `meter` role with its range and a value
69
101
  kept inside it; `meterLitCount` maps a level to the lit segments of a scale
70
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`.
71
128
  - `ControlTone`, the colour role every lit control takes.
72
129
 
73
130
  ```ts
@@ -94,7 +151,7 @@ peer dependency: install the one you use, and nothing else is pulled in.
94
151
 
95
152
  | subpath | framework | components |
96
153
  | -------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------- |
97
- | `@ac-kit/ui-common/preact` | Preact 11 | `Knob`, `Slider`, `ToggleButton`, `Readout`, `Meter`, `Switch`, `RadioGroup`, `Button`, `IconButton`, `Toolbar`, `Dialog` |
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` |
98
155
 
99
156
  Every component is controlled: it shows `value` (or `isOn`) and reports what
100
157
  the person asks for through a callback, typed with `@ac-kit/core`'s
@@ -132,6 +189,159 @@ the person asks for through a callback, typed with `@ac-kit/core`'s
132
189
  `closeIcon`, `actions`. A native modal `<dialog>`, no portal. `onClose` is
133
190
  asked once when Escape, the close button, a backdrop press or a
134
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.
135
345
 
136
346
  A `value` outside `min`–`max` is drawn, formatted and announced as the nearest
137
347
  end. Disabling a `Knob` or a `Slider` mid-gesture drops the gesture: nothing is
@@ -163,9 +373,9 @@ panel, or on one control.
163
373
 
164
374
  Every control root carries `ack-control` beside its own class (`ack-knob`,
165
375
  `ack-slider`, …): the hook for what they share — the tone, the focus ring, the
166
- disabled look, the touch target of the interactive ones (a `Readout` and a
167
- `Meter` are displays and keep their own size) and, on the controls a finger
168
- drags, no text
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
169
379
  selection. The components also render stable part classes (`ack-knob-arc`,
170
380
  `ack-slider-thumb`, …) and state attributes (`data-tone`, `data-state`,
171
381
  `data-indicator`, `data-orientation`, `data-dragging`, `data-lit`,
@@ -239,11 +449,56 @@ Per control:
239
449
  | `--ack-dialog-text` | `CanvasText` | the panel's text |
240
450
  | `--ack-dialog-backdrop` | `rgb(0 0 0 / 0.5)` | what dims the page behind |
241
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 |
242
487
 
243
488
  A dialog stops the page behind from scrolling while it is open
244
489
  (`:root:has(dialog.ack-dialog[open])`), and its entry and exit are transitions
245
490
  that `prefers-reduced-motion: reduce` turns off.
246
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
+
247
502
  Without the stylesheet the components still work, unstyled; only the slider's
248
503
  thumb and the meter's bar depend on it for their position.
249
504
 
@@ -266,9 +521,72 @@ thumb and the meter's bar depend on it for their position.
266
521
  - `Dialog` is a native modal `<dialog>` named by its title and described by its
267
522
  description: the page is inert, Escape closes it when dismissible, focus
268
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).
269
556
  - `Readout` is a group named once by its caption.
270
557
  - `Meter` has the `meter` role with its range and value (and `valueText`), and
271
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.
272
590
  - Pointer input is touch first: pointers are captured for the length of a
273
591
  gesture, `touch-action` keeps the page from scrolling under a knob's drag
274
592
  (a slider lets it scroll across the track, and a scroll that starts cancels
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The side of its anchor a popover sits on, in logical terms: `block-end` is
3
+ * below in a horizontal writing mode, `inline-end` after it in the reading
4
+ * direction (right in a left-to-right page). It moves to the opposite side when
5
+ * the viewport has no room for it.
6
+ */
7
+ export type AnchoredSide = "block-start" | "block-end" | "inline-start" | "inline-end";
8
+ /**
9
+ * How a popover lines up with its anchor along that side: its start edges
10
+ * together, centred, or its end edges together. It shifts into the viewport
11
+ * when it would overflow it.
12
+ */
13
+ export type AnchoredAlign = "start" | "center" | "end";
14
+ /** The attributes the stylesheet places an anchored popover by. */
15
+ export type AnchoredAttributes = {
16
+ "data-side": AnchoredSide;
17
+ "data-align": AnchoredAlign;
18
+ };
19
+ //# sourceMappingURL=anchored.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchored.d.ts","sourceRoot":"","sources":["../../src/anchored/anchored.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACrB,aAAa,GACb,WAAW,GACX,cAAc,GACd,YAAY,CAAC;AAEhB;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEvD,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG;IAChC,WAAW,EAAE,YAAY,CAAC;IAC1B,YAAY,EAAE,aAAa,CAAC;CAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=anchored.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchored.js","sourceRoot":"","sources":["../../src/anchored/anchored.ts"],"names":[],"mappings":""}