@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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { assertFinite, assertPositive, clamp, describeValue, } from "@ac-kit/core";
|
|
2
|
+
import { quantize } from "@ac-kit/math-scalar";
|
|
3
|
+
import { snapSliderValue } from "../slider/slider-range.js";
|
|
4
|
+
import { steppedValue } from "../slider/stepped-value.js";
|
|
5
|
+
/** @throws {RangeError} When the range has no step or inverted bounds. */
|
|
6
|
+
function assertSpinButtonRange_(range) {
|
|
7
|
+
const { min, max, step } = range;
|
|
8
|
+
assertPositive(step, "step");
|
|
9
|
+
if (min !== undefined) {
|
|
10
|
+
assertFinite(min, "min");
|
|
11
|
+
}
|
|
12
|
+
if (max !== undefined) {
|
|
13
|
+
assertFinite(max, "max");
|
|
14
|
+
}
|
|
15
|
+
if (min !== undefined && max !== undefined && !(max > min)) {
|
|
16
|
+
throw new RangeError(`A spin button range needs max > min, got [${describeValue(min)}, ${describeValue(max)}].`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function sliderRangeOf_(range) {
|
|
20
|
+
const { min, max, step } = range;
|
|
21
|
+
return min === undefined || max === undefined
|
|
22
|
+
? undefined
|
|
23
|
+
: { min, max, step };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The value a spin button settles on for `value`, typed or stepped to: the
|
|
27
|
+
* nearest step, kept within the bounds it has. A value at or past a bound gives
|
|
28
|
+
* that bound, so a bound off the grid of steps stays reachable. With both
|
|
29
|
+
* bounds, this is {@link snapSliderValue}.
|
|
30
|
+
*
|
|
31
|
+
* `NaN` gives the origin of the steps (`min`, else `max`, else 0).
|
|
32
|
+
*
|
|
33
|
+
* Time complexity: O(1). Memory: O(1).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* snapSpinButtonValue(7.4, { min: 0, step: 0.5 }); // 7.5
|
|
37
|
+
* snapSpinButtonValue(-3, { min: 0, step: 1 }); // 0
|
|
38
|
+
* snapSpinButtonValue(1e6, { min: 0, step: 1 }); // 1000000: no maximum
|
|
39
|
+
*
|
|
40
|
+
* @throws {RangeError} When `step` is not above zero, a bound is not finite,
|
|
41
|
+
* `max` is not above `min`, or `value` is infinite towards a side with no
|
|
42
|
+
* bound.
|
|
43
|
+
*/
|
|
44
|
+
export function snapSpinButtonValue(value, range) {
|
|
45
|
+
assertSpinButtonRange_(range);
|
|
46
|
+
const bounded = sliderRangeOf_(range);
|
|
47
|
+
if (bounded !== undefined) {
|
|
48
|
+
return snapSliderValue(value, bounded);
|
|
49
|
+
}
|
|
50
|
+
const { min, max, step } = range;
|
|
51
|
+
const origin = min ?? max ?? 0;
|
|
52
|
+
if (Number.isNaN(value)) {
|
|
53
|
+
return origin;
|
|
54
|
+
}
|
|
55
|
+
if (min !== undefined && value <= min) {
|
|
56
|
+
return min;
|
|
57
|
+
}
|
|
58
|
+
if (max !== undefined && value >= max) {
|
|
59
|
+
return max;
|
|
60
|
+
}
|
|
61
|
+
assertFinite(value, "value");
|
|
62
|
+
const snapped = quantize(value, step, origin);
|
|
63
|
+
// The nearest step may lie past the largest finite number: take the one
|
|
64
|
+
// before it, towards the origin.
|
|
65
|
+
const finite = Number.isFinite(snapped)
|
|
66
|
+
? snapped
|
|
67
|
+
: quantize(value - Math.sign(value - origin) * step, step, origin);
|
|
68
|
+
return clamp(finite, min ?? Number.NEGATIVE_INFINITY, max ?? Number.POSITIVE_INFINITY);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The value a key moves a spin button to (WAI-ARIA spinbutton pattern): Arrow
|
|
72
|
+
* Up one step up, Arrow Down one down, Page Up and Page Down a large step, Home
|
|
73
|
+
* to `min` and End to `max` when the range has them. The result is snapped
|
|
74
|
+
* ({@link snapSpinButtonValue}), so stepping past a bound gives that bound;
|
|
75
|
+
* with both bounds, this is {@link steppedValue}'s, without Arrow Left and Arrow
|
|
76
|
+
* Right, which move the caret in an editable field.
|
|
77
|
+
*
|
|
78
|
+
* `undefined` for any other key, Home without `min` and End without `max`:
|
|
79
|
+
* leave those to the browser. A result equal to `value` means the key was a
|
|
80
|
+
* step key but the value cannot move that way (at a bound, or a step that would
|
|
81
|
+
* overflow): consume the key, report no change.
|
|
82
|
+
*
|
|
83
|
+
* Time complexity: O(1). Memory: O(1).
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* spinButtonValue(4, "ArrowUp", { min: 1, step: 1 }); // 5
|
|
87
|
+
* spinButtonValue(4, "PageDown", { min: 1, step: 1 }); // 1
|
|
88
|
+
* spinButtonValue(4, "End", { min: 1, step: 1 }); // undefined: no maximum
|
|
89
|
+
*
|
|
90
|
+
* @throws {RangeError} When the range is invalid ({@link snapSpinButtonValue})
|
|
91
|
+
* or `largeStep` is not above zero.
|
|
92
|
+
*/
|
|
93
|
+
export function spinButtonValue(value, key, range, options = {}) {
|
|
94
|
+
assertSpinButtonRange_(range);
|
|
95
|
+
const { min, max, step } = range;
|
|
96
|
+
const { largeStep = Math.min(step * 10, Number.MAX_VALUE) } = options;
|
|
97
|
+
assertPositive(largeStep, "largeStep");
|
|
98
|
+
let next;
|
|
99
|
+
switch (key) {
|
|
100
|
+
case "ArrowUp":
|
|
101
|
+
next = value + step;
|
|
102
|
+
break;
|
|
103
|
+
case "ArrowDown":
|
|
104
|
+
next = value - step;
|
|
105
|
+
break;
|
|
106
|
+
case "PageUp":
|
|
107
|
+
next = value + largeStep;
|
|
108
|
+
break;
|
|
109
|
+
case "PageDown":
|
|
110
|
+
next = value - largeStep;
|
|
111
|
+
break;
|
|
112
|
+
case "Home":
|
|
113
|
+
if (min === undefined) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
next = min;
|
|
117
|
+
break;
|
|
118
|
+
case "End":
|
|
119
|
+
if (max === undefined) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
next = max;
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const bounded = sliderRangeOf_(range);
|
|
128
|
+
if (bounded !== undefined) {
|
|
129
|
+
return steppedValue(value, key, bounded, { largeStep });
|
|
130
|
+
}
|
|
131
|
+
if (!Number.isFinite(next) && Number.isFinite(value)) {
|
|
132
|
+
return snapSpinButtonValue(value, range);
|
|
133
|
+
}
|
|
134
|
+
return snapSpinButtonValue(next, range);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The `spinbutton` role and its value attributes: what assistive technology
|
|
138
|
+
* announces, and what every adapter renders the same way.
|
|
139
|
+
*
|
|
140
|
+
* Time complexity: O(1). Memory: O(1).
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* spinButtonAttributes({
|
|
144
|
+
* label: "Copies",
|
|
145
|
+
* value: 4,
|
|
146
|
+
* range: { min: 1, step: 1 },
|
|
147
|
+
* valueText: "4",
|
|
148
|
+
* });
|
|
149
|
+
* // { role: "spinbutton", "aria-label": "Copies", "aria-valuemin": 1,
|
|
150
|
+
* // "aria-valuenow": 4, "aria-valuetext": "4" }
|
|
151
|
+
*
|
|
152
|
+
* @throws {RangeError} When the range is invalid ({@link snapSpinButtonValue}).
|
|
153
|
+
*/
|
|
154
|
+
export function spinButtonAttributes(input) {
|
|
155
|
+
const { label, value, range, valueText, disabled } = input;
|
|
156
|
+
assertSpinButtonRange_(range);
|
|
157
|
+
const { min, max } = range;
|
|
158
|
+
const attributes = {
|
|
159
|
+
role: "spinbutton",
|
|
160
|
+
"aria-valuenow": Number.isNaN(value)
|
|
161
|
+
? (min ?? max ?? 0)
|
|
162
|
+
: clamp(value, min ?? Number.NEGATIVE_INFINITY, max ?? Number.POSITIVE_INFINITY),
|
|
163
|
+
"aria-valuetext": valueText,
|
|
164
|
+
};
|
|
165
|
+
if (label !== undefined) {
|
|
166
|
+
attributes["aria-label"] = label;
|
|
167
|
+
}
|
|
168
|
+
if (min !== undefined) {
|
|
169
|
+
attributes["aria-valuemin"] = min;
|
|
170
|
+
}
|
|
171
|
+
if (max !== undefined) {
|
|
172
|
+
attributes["aria-valuemax"] = max;
|
|
173
|
+
}
|
|
174
|
+
if (disabled === true) {
|
|
175
|
+
attributes["aria-disabled"] = "true";
|
|
176
|
+
}
|
|
177
|
+
return attributes;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=spin-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spin-button.js","sourceRoot":"","sources":["../../src/spin-button/spin-button.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,cAAc,EACd,KAAK,EACL,aAAa,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;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,CAAC;AACzC,CAAC;AAgCD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,oBAAoB,CACnC,KAAgC;IAEhC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3D,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAC3B,MAAM,UAAU,GAAyB;QACxC,IAAI,EAAE,YAAY;QAClB,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YACnC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;YACnB,CAAC,CAAC,KAAK,CACL,KAAK,EACL,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAC/B,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAC/B;QACH,gBAAgB,EAAE,SAAS;KAC3B,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,GAAG,CAAC;IACnC,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,GAAG,CAAC;IACnC,CAAC;IACD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;IACtC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes of a switch, keyed by their HTML attribute names: a `button`
|
|
3
|
+
* announced as a switch, on or off, and the state the stylesheet draws it by.
|
|
4
|
+
*/
|
|
5
|
+
export type SwitchAttributes = {
|
|
6
|
+
role: "switch";
|
|
7
|
+
"aria-checked": "true" | "false";
|
|
8
|
+
"aria-disabled"?: "true";
|
|
9
|
+
"data-state": "on" | "off";
|
|
10
|
+
};
|
|
11
|
+
/** Input of {@link switchAttributes}. */
|
|
12
|
+
export type SwitchAttributesInput = {
|
|
13
|
+
isOn: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The attributes of a switch (WAI-ARIA switch pattern): a setting that takes
|
|
18
|
+
* effect as soon as it is flipped, unlike a checkbox in a form that is
|
|
19
|
+
* submitted later. Render it on a native `<button type="button">`, whose Space
|
|
20
|
+
* and Enter activation it relies on; activating it reports `!isOn` and leaves
|
|
21
|
+
* the caller to pass the new state back.
|
|
22
|
+
*
|
|
23
|
+
* Time complexity: O(1). Memory: O(1).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* switchAttributes({ isOn: true });
|
|
27
|
+
* // { role: "switch", "aria-checked": "true", "data-state": "on" }
|
|
28
|
+
*/
|
|
29
|
+
export declare function switchAttributes(input: SwitchAttributesInput): SwitchAttributes;
|
|
30
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,IAAI,GAAG,KAAK,CAAC;CAC3B,CAAC;AAEF,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,qBAAqB,GAC1B,gBAAgB,CAYlB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes of a switch (WAI-ARIA switch pattern): a setting that takes
|
|
3
|
+
* effect as soon as it is flipped, unlike a checkbox in a form that is
|
|
4
|
+
* submitted later. Render it on a native `<button type="button">`, whose Space
|
|
5
|
+
* and Enter activation it relies on; activating it reports `!isOn` and leaves
|
|
6
|
+
* the caller to pass the new state back.
|
|
7
|
+
*
|
|
8
|
+
* Time complexity: O(1). Memory: O(1).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* switchAttributes({ isOn: true });
|
|
12
|
+
* // { role: "switch", "aria-checked": "true", "data-state": "on" }
|
|
13
|
+
*/
|
|
14
|
+
export function switchAttributes(input) {
|
|
15
|
+
const { isOn, disabled = false } = input;
|
|
16
|
+
const attributes = {
|
|
17
|
+
role: "switch",
|
|
18
|
+
"aria-checked": isOn ? "true" : "false",
|
|
19
|
+
"data-state": isOn ? "on" : "off",
|
|
20
|
+
};
|
|
21
|
+
if (disabled) {
|
|
22
|
+
attributes["aria-disabled"] = "true";
|
|
23
|
+
}
|
|
24
|
+
return attributes;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAA4B;IAE5B,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;IACzC,MAAM,UAAU,GAAqB;QACpC,IAAI,EAAE,QAAQ;QACd,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QACvC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;KACjC,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACd,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;IACtC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type Predicate } from "@ac-kit/core";
|
|
2
|
+
import type { KeyInput } from "@ac-kit/ui-gesture";
|
|
3
|
+
/** Which way a tab list lays out its tabs, and so which arrows move along it. */
|
|
4
|
+
export type TabsOrientation = "horizontal" | "vertical";
|
|
5
|
+
/**
|
|
6
|
+
* When a tab shows its panel: as soon as it takes focus (`automatic`, for
|
|
7
|
+
* panels that show at once), or only once Enter, Space or a click chooses it
|
|
8
|
+
* (`manual`, for panels slow to show).
|
|
9
|
+
*/
|
|
10
|
+
export type TabsActivation = "automatic" | "manual";
|
|
11
|
+
/**
|
|
12
|
+
* The attributes of a tab list, keyed by their HTML attribute names.
|
|
13
|
+
* `aria-orientation` is present for `vertical` only, the role's default being
|
|
14
|
+
* horizontal.
|
|
15
|
+
*/
|
|
16
|
+
export type TabListAttributes = {
|
|
17
|
+
role: "tablist";
|
|
18
|
+
"aria-label"?: string;
|
|
19
|
+
"aria-labelledby"?: string;
|
|
20
|
+
"aria-orientation"?: "vertical";
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Input of {@link tabListAttributes}: its accessible name, given as text or as
|
|
24
|
+
* the id of the element naming it.
|
|
25
|
+
*/
|
|
26
|
+
export type TabListAttributesInput = ({
|
|
27
|
+
label: string;
|
|
28
|
+
labelledBy?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
label?: undefined;
|
|
31
|
+
labelledBy: string;
|
|
32
|
+
}) & {
|
|
33
|
+
/** Defaults to `horizontal`. */
|
|
34
|
+
orientation?: TabsOrientation;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The attributes of a tab list (WAI-ARIA tabs pattern): a named row or column
|
|
38
|
+
* of tabs with one tab stop.
|
|
39
|
+
*
|
|
40
|
+
* Time complexity: O(1). Memory: O(1).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* tabListAttributes({ label: "Settings" });
|
|
44
|
+
* // { role: "tablist", "aria-label": "Settings" }
|
|
45
|
+
*/
|
|
46
|
+
export declare function tabListAttributes(input: TabListAttributesInput): TabListAttributes;
|
|
47
|
+
/** The attributes of a tab, keyed by their HTML attribute names. */
|
|
48
|
+
export type TabAttributes = {
|
|
49
|
+
role: "tab";
|
|
50
|
+
"aria-selected": "true" | "false";
|
|
51
|
+
"aria-controls": string;
|
|
52
|
+
tabindex: 0 | -1;
|
|
53
|
+
"aria-disabled"?: "true";
|
|
54
|
+
};
|
|
55
|
+
/** Input of {@link tabAttributes}. */
|
|
56
|
+
export type TabAttributesInput = {
|
|
57
|
+
/** The id of the panel it shows. */
|
|
58
|
+
panelId: string;
|
|
59
|
+
isSelected: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether Tab reaches it: the selected tab, or the first enabled one while
|
|
62
|
+
* none is selected.
|
|
63
|
+
*/
|
|
64
|
+
isTabStop: boolean;
|
|
65
|
+
isDisabled?: boolean;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The attributes of a tab: selected or not, the panel it controls, and in the
|
|
69
|
+
* tab order only as the tab list's single stop. A disabled tab stays focusable,
|
|
70
|
+
* as the WAI-ARIA practices advise for the items of a composite widget, so it
|
|
71
|
+
* can be found and read; it is never selected.
|
|
72
|
+
*
|
|
73
|
+
* Time complexity: O(1). Memory: O(1).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* tabAttributes({ panelId: "p", isSelected: true, isTabStop: true });
|
|
77
|
+
* // { role: "tab", "aria-selected": "true", "aria-controls": "p",
|
|
78
|
+
* // tabindex: 0 }
|
|
79
|
+
*/
|
|
80
|
+
export declare function tabAttributes(input: TabAttributesInput): TabAttributes;
|
|
81
|
+
/** The attributes of a tab panel, keyed by their HTML attribute names. */
|
|
82
|
+
export type TabPanelAttributes = {
|
|
83
|
+
role: "tabpanel";
|
|
84
|
+
"aria-labelledby": string;
|
|
85
|
+
tabindex?: 0;
|
|
86
|
+
};
|
|
87
|
+
/** Input of {@link tabPanelAttributes}. */
|
|
88
|
+
export type TabPanelAttributesInput = {
|
|
89
|
+
/** The id of the tab naming it. */
|
|
90
|
+
tabId: string;
|
|
91
|
+
/**
|
|
92
|
+
* Whether Tab must reach the panel itself: when nothing inside it takes
|
|
93
|
+
* focus, so its content is reached from its tab.
|
|
94
|
+
*/
|
|
95
|
+
isFocusable: boolean;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The attributes of a tab panel: named by its tab, and in the tab order itself
|
|
99
|
+
* when nothing inside it is.
|
|
100
|
+
*
|
|
101
|
+
* Time complexity: O(1). Memory: O(1).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* tabPanelAttributes({ tabId: "t", isFocusable: true });
|
|
105
|
+
* // { role: "tabpanel", "aria-labelledby": "t", tabindex: 0 }
|
|
106
|
+
*/
|
|
107
|
+
export declare function tabPanelAttributes(input: TabPanelAttributesInput): TabPanelAttributes;
|
|
108
|
+
/** Input of {@link tabsKeyAction}: the key and the tab list around focus. */
|
|
109
|
+
export type TabsKeyInput = KeyInput & {
|
|
110
|
+
/** The focused tab's index. */
|
|
111
|
+
current: number;
|
|
112
|
+
/** How many tabs the list has. */
|
|
113
|
+
count: number;
|
|
114
|
+
/** Defaults to `horizontal`. */
|
|
115
|
+
orientation?: TabsOrientation;
|
|
116
|
+
/** `rtl` swaps Left and Right. Defaults to `ltr`. */
|
|
117
|
+
direction?: "ltr" | "rtl";
|
|
118
|
+
/** Defaults to `automatic`. */
|
|
119
|
+
activation?: TabsActivation;
|
|
120
|
+
/** Tabs that take focus but are never selected. Defaults to none. */
|
|
121
|
+
isDisabled?: Predicate<[index: number]>;
|
|
122
|
+
/** Whether Delete closes a tab. Defaults to false. */
|
|
123
|
+
isDeletable?: boolean;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* What a key does in a tab list (WAI-ARIA tabs pattern):
|
|
127
|
+
*
|
|
128
|
+
* - `focus` a tab: the arrows along the list to the previous or next tab, going
|
|
129
|
+
* round, Home and End to the first and last; `selects` when activation is
|
|
130
|
+
* automatic and the tab is enabled;
|
|
131
|
+
* - `select` the focused tab: Enter or Space, when activation is manual;
|
|
132
|
+
* - `delete` the focused tab: Delete, when tabs are deletable.
|
|
133
|
+
*/
|
|
134
|
+
export type TabsKeyAction = {
|
|
135
|
+
readonly kind: "focus";
|
|
136
|
+
readonly index: number;
|
|
137
|
+
readonly selects: boolean;
|
|
138
|
+
} | {
|
|
139
|
+
readonly kind: "select";
|
|
140
|
+
} | {
|
|
141
|
+
readonly kind: "delete";
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* The action of a key on a focused tab, {@link TabsKeyAction}. `undefined` for a
|
|
145
|
+
* key the list does not use, or with Ctrl, Alt or Meta held (a shortcut).
|
|
146
|
+
*
|
|
147
|
+
* Time complexity: O(count) at worst. Memory: O(1).
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* tabsKeyAction({ key: "ArrowRight", current: 2, count: 3 });
|
|
151
|
+
* // { kind: "focus", index: 0, selects: true }
|
|
152
|
+
*
|
|
153
|
+
* @throws {RangeError} When `count` is not a positive safe integer or `current`
|
|
154
|
+
* is outside [0, count).
|
|
155
|
+
*/
|
|
156
|
+
export declare function tabsKeyAction(input: TabsKeyInput): TabsKeyAction | undefined;
|
|
157
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/tabs/tabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAInD,iFAAiF;AACjF,MAA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,EAAE,YAAY,GAAG,aAAa,GAAG,SAAS,CAkD5E"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describeValue, isIntegerInRange } from "@ac-kit/core";
|
|
2
|
+
import { rovingFocusIndex } from "../focus/roving-focus.js";
|
|
3
|
+
/**
|
|
4
|
+
* The attributes of a tab list (WAI-ARIA tabs pattern): a named row or column
|
|
5
|
+
* of tabs with one tab stop.
|
|
6
|
+
*
|
|
7
|
+
* Time complexity: O(1). Memory: O(1).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* tabListAttributes({ label: "Settings" });
|
|
11
|
+
* // { role: "tablist", "aria-label": "Settings" }
|
|
12
|
+
*/
|
|
13
|
+
export function tabListAttributes(input) {
|
|
14
|
+
const { label, labelledBy, orientation = "horizontal" } = input;
|
|
15
|
+
const attributes = { role: "tablist" };
|
|
16
|
+
if (label !== undefined) {
|
|
17
|
+
attributes["aria-label"] = label;
|
|
18
|
+
}
|
|
19
|
+
if (labelledBy !== undefined) {
|
|
20
|
+
attributes["aria-labelledby"] = labelledBy;
|
|
21
|
+
}
|
|
22
|
+
if (orientation === "vertical") {
|
|
23
|
+
attributes["aria-orientation"] = "vertical";
|
|
24
|
+
}
|
|
25
|
+
return attributes;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The attributes of a tab: selected or not, the panel it controls, and in the
|
|
29
|
+
* tab order only as the tab list's single stop. A disabled tab stays focusable,
|
|
30
|
+
* as the WAI-ARIA practices advise for the items of a composite widget, so it
|
|
31
|
+
* can be found and read; it is never selected.
|
|
32
|
+
*
|
|
33
|
+
* Time complexity: O(1). Memory: O(1).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* tabAttributes({ panelId: "p", isSelected: true, isTabStop: true });
|
|
37
|
+
* // { role: "tab", "aria-selected": "true", "aria-controls": "p",
|
|
38
|
+
* // tabindex: 0 }
|
|
39
|
+
*/
|
|
40
|
+
export function tabAttributes(input) {
|
|
41
|
+
const attributes = {
|
|
42
|
+
role: "tab",
|
|
43
|
+
"aria-selected": input.isSelected ? "true" : "false",
|
|
44
|
+
"aria-controls": input.panelId,
|
|
45
|
+
tabindex: input.isTabStop ? 0 : -1,
|
|
46
|
+
};
|
|
47
|
+
if (input.isDisabled === true) {
|
|
48
|
+
attributes["aria-disabled"] = "true";
|
|
49
|
+
}
|
|
50
|
+
return attributes;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The attributes of a tab panel: named by its tab, and in the tab order itself
|
|
54
|
+
* when nothing inside it is.
|
|
55
|
+
*
|
|
56
|
+
* Time complexity: O(1). Memory: O(1).
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* tabPanelAttributes({ tabId: "t", isFocusable: true });
|
|
60
|
+
* // { role: "tabpanel", "aria-labelledby": "t", tabindex: 0 }
|
|
61
|
+
*/
|
|
62
|
+
export function tabPanelAttributes(input) {
|
|
63
|
+
const attributes = {
|
|
64
|
+
role: "tabpanel",
|
|
65
|
+
"aria-labelledby": input.tabId,
|
|
66
|
+
};
|
|
67
|
+
if (input.isFocusable) {
|
|
68
|
+
attributes.tabindex = 0;
|
|
69
|
+
}
|
|
70
|
+
return attributes;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The action of a key on a focused tab, {@link TabsKeyAction}. `undefined` for a
|
|
74
|
+
* key the list does not use, or with Ctrl, Alt or Meta held (a shortcut).
|
|
75
|
+
*
|
|
76
|
+
* Time complexity: O(count) at worst. Memory: O(1).
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* tabsKeyAction({ key: "ArrowRight", current: 2, count: 3 });
|
|
80
|
+
* // { kind: "focus", index: 0, selects: true }
|
|
81
|
+
*
|
|
82
|
+
* @throws {RangeError} When `count` is not a positive safe integer or `current`
|
|
83
|
+
* is outside [0, count).
|
|
84
|
+
*/
|
|
85
|
+
export function tabsKeyAction(input) {
|
|
86
|
+
const { key, current, count, orientation = "horizontal", direction = "ltr", activation = "automatic", isDisabled, isDeletable = false, } = input;
|
|
87
|
+
if (!isIntegerInRange(count, 1, Number.MAX_SAFE_INTEGER + 1)) {
|
|
88
|
+
throw new RangeError(`count must be a positive safe integer, got ${describeValue(count)}`);
|
|
89
|
+
}
|
|
90
|
+
if (!isIntegerInRange(current, 0, count)) {
|
|
91
|
+
throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
|
|
92
|
+
}
|
|
93
|
+
if (input.ctrlKey === true ||
|
|
94
|
+
input.altKey === true ||
|
|
95
|
+
input.metaKey === true) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
switch (key) {
|
|
99
|
+
case "Enter":
|
|
100
|
+
case " ":
|
|
101
|
+
return activation === "manual" ? { kind: "select" } : undefined;
|
|
102
|
+
case "Delete":
|
|
103
|
+
return isDeletable ? { kind: "delete" } : undefined;
|
|
104
|
+
default: {
|
|
105
|
+
const index = rovingFocusIndex(current, key, count, {
|
|
106
|
+
orientation,
|
|
107
|
+
direction,
|
|
108
|
+
});
|
|
109
|
+
if (index === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
kind: "focus",
|
|
114
|
+
index,
|
|
115
|
+
selects: activation === "automatic" && isDisabled?.(index) !== true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/tabs/tabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAkB,MAAM,cAAc,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAoC5D;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA6B;IAE7B,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WA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