@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,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { readoutAttributes } from "../readout/readout.js";
|
|
3
|
+
import { joinClasses } from "./join-classes.js";
|
|
4
|
+
/**
|
|
5
|
+
* A lit value under a small caption, like a hardware display's: a tempo, a bar
|
|
6
|
+
* number, a program. Read-only; for a value the person sets, use a `Knob` or a
|
|
7
|
+
* `Slider`.
|
|
8
|
+
*/
|
|
9
|
+
export function Readout(props) {
|
|
10
|
+
const { label, tone, live, children, id } = props;
|
|
11
|
+
return (_jsxs("div", { ...readoutAttributes({ label, tone, live }), id: id, class: joinClasses("ack-control ack-readout", props.class), children: [_jsx("span", { class: "ack-readout-label", "aria-hidden": "true", children: label }), _jsx("span", { class: "ack-readout-value", children: children })] }));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=readout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readout.js","sourceRoot":"","sources":["../../src/preact/readout.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAoB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAehD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAmB;IAC1C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAElD,OAAO,CACN,kBACK,iBAAiB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAC5C,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,WAAW,CAAC,yBAAyB,EAAE,KAAK,CAAC,KAAK,CAAC,aAE1D,eAAM,KAAK,EAAC,mBAAmB,iBAAa,MAAM,YAChD,KAAK,GACA,EACP,eAAM,KAAK,EAAC,mBAAmB,YAAE,QAAQ,GAAQ,IAC5C,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { JSX } from "preact";
|
|
3
|
+
import { type SliderOrientation } from "../slider/slider-track.js";
|
|
4
|
+
import type { ControlTone } from "../tone.js";
|
|
5
|
+
/** Props of {@link Slider}. */
|
|
6
|
+
export type SliderProps = {
|
|
7
|
+
/** Its accessible name, also drawn above it. */
|
|
8
|
+
label: string;
|
|
9
|
+
value: number;
|
|
10
|
+
min: number;
|
|
11
|
+
max: number;
|
|
12
|
+
/** Defaults to 1. */
|
|
13
|
+
step?: number;
|
|
14
|
+
/** Defaults to `horizontal`. */
|
|
15
|
+
orientation?: SliderOrientation;
|
|
16
|
+
tone?: ControlTone;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** The value as a person reads it, shown and announced. Defaults to `String`. */
|
|
19
|
+
format?: Callable<[value: number], string>;
|
|
20
|
+
/** A new value, once per gesture: at a drag's end, or a key. */
|
|
21
|
+
onChange: Callable<[value: number]>;
|
|
22
|
+
/** The value following a drag, before it is committed through `onChange`. */
|
|
23
|
+
onInput?: Callable<[value: number]>;
|
|
24
|
+
id?: string;
|
|
25
|
+
class?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A linear slider, horizontal or vertical as on a mixing desk, its value shown
|
|
29
|
+
* beside its label. Pressing anywhere on the track jumps the thumb there; it
|
|
30
|
+
* follows the pointer and reports a value once let go, at the point it was let
|
|
31
|
+
* go. A drag never ends in a click. Focused, the arrow keys step it, Page Up
|
|
32
|
+
* and Page Down by ten steps, Home and End to the ends. The page still scrolls
|
|
33
|
+
* across it: a press that turns into a scroll is cancelled and reports
|
|
34
|
+
* nothing.
|
|
35
|
+
*
|
|
36
|
+
* For a setting with room to spare, or the large entry surface a `Knob` opens;
|
|
37
|
+
* where space is short, prefer a `Knob`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function Slider(props: SliderProps): JSX.Element;
|
|
40
|
+
//# sourceMappingURL=slider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../src/preact/slider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAMlC,OAAO,EACN,KAAK,iBAAiB,EAGtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG;IACzB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iFAAiF;IACjF,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3C,gEAAgE;IAChE,QAAQ,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAUF;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAqNtD"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { bindPointers } from "@ac-kit/ui-gesture/dom";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "preact/hooks";
|
|
4
|
+
import { clampedSliderValue_ } from "../slider/_clamped-value.js";
|
|
5
|
+
import { sliderAttributes } from "../slider/slider-attributes.js";
|
|
6
|
+
import { sliderFraction } from "../slider/slider-range.js";
|
|
7
|
+
import { sliderTrackValueAt, } from "../slider/slider-track.js";
|
|
8
|
+
import { steppedValue } from "../slider/stepped-value.js";
|
|
9
|
+
import { joinClasses } from "./join-classes.js";
|
|
10
|
+
import { useElementBinding, useLatest } from "./use-element-binding.js";
|
|
11
|
+
/**
|
|
12
|
+
* A linear slider, horizontal or vertical as on a mixing desk, its value shown
|
|
13
|
+
* beside its label. Pressing anywhere on the track jumps the thumb there; it
|
|
14
|
+
* follows the pointer and reports a value once let go, at the point it was let
|
|
15
|
+
* go. A drag never ends in a click. Focused, the arrow keys step it, Page Up
|
|
16
|
+
* and Page Down by ten steps, Home and End to the ends. The page still scrolls
|
|
17
|
+
* across it: a press that turns into a scroll is cancelled and reports
|
|
18
|
+
* nothing.
|
|
19
|
+
*
|
|
20
|
+
* For a setting with room to spare, or the large entry surface a `Knob` opens;
|
|
21
|
+
* where space is short, prefer a `Knob`.
|
|
22
|
+
*/
|
|
23
|
+
export function Slider(props) {
|
|
24
|
+
const { label, value, min, max, step = 1, orientation = "horizontal", tone, disabled = false, format = String, onChange, onInput, id, } = props;
|
|
25
|
+
const range = { min, max, step };
|
|
26
|
+
const labelId = useId();
|
|
27
|
+
const [dragged, setDragged] = useState(undefined);
|
|
28
|
+
const drag = useRef(undefined);
|
|
29
|
+
const binding = useRef(undefined);
|
|
30
|
+
const isClickSuppressed = useRef(false);
|
|
31
|
+
const thumb = useRef(null);
|
|
32
|
+
const latest = useLatest({ range, value, disabled, onChange, onInput });
|
|
33
|
+
const shown = clampedSliderValue_(dragged ?? value, range);
|
|
34
|
+
const isVertical = orientation === "vertical";
|
|
35
|
+
const endDrag = () => {
|
|
36
|
+
drag.current = undefined;
|
|
37
|
+
setDragged(undefined);
|
|
38
|
+
};
|
|
39
|
+
const control = useElementBinding((element, signal) => {
|
|
40
|
+
const valueAt = (current, point) => sliderTrackValueAt(isVertical ? point.y : point.x, current.track, latest.current.range, orientation);
|
|
41
|
+
const follow = (current, next) => {
|
|
42
|
+
if (next !== current.value) {
|
|
43
|
+
latest.current.onInput?.(next);
|
|
44
|
+
}
|
|
45
|
+
current.value = next;
|
|
46
|
+
setDragged(next);
|
|
47
|
+
};
|
|
48
|
+
const bound = bindPointers(element, {
|
|
49
|
+
onDown: (down) => {
|
|
50
|
+
const box = bound.box ?? element.getBoundingClientRect();
|
|
51
|
+
const thumbBox = thumb.current?.getBoundingClientRect();
|
|
52
|
+
// The pointer's coordinates are the control's own, so the track
|
|
53
|
+
// starts at 0.
|
|
54
|
+
const track = isVertical
|
|
55
|
+
? {
|
|
56
|
+
start: 0,
|
|
57
|
+
length: box.height,
|
|
58
|
+
thumbLength: thumbBox?.height ?? 0,
|
|
59
|
+
}
|
|
60
|
+
: {
|
|
61
|
+
start: 0,
|
|
62
|
+
length: box.width,
|
|
63
|
+
thumbLength: thumbBox?.width ?? 0,
|
|
64
|
+
};
|
|
65
|
+
const current = {
|
|
66
|
+
pointerId: down.pointerId,
|
|
67
|
+
track,
|
|
68
|
+
value: latest.current.value,
|
|
69
|
+
pressX: down.x,
|
|
70
|
+
pressY: down.y,
|
|
71
|
+
};
|
|
72
|
+
drag.current = current;
|
|
73
|
+
isClickSuppressed.current = false;
|
|
74
|
+
thumb.current?.focus();
|
|
75
|
+
follow(current, valueAt(current, down));
|
|
76
|
+
},
|
|
77
|
+
onMove: (sample) => {
|
|
78
|
+
const current = drag.current;
|
|
79
|
+
if (current?.pointerId === sample.pointerId) {
|
|
80
|
+
follow(current, valueAt(current, sample));
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
onUp: (sample) => {
|
|
84
|
+
const current = drag.current;
|
|
85
|
+
if (current?.pointerId !== sample.pointerId) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
endDrag();
|
|
89
|
+
if (latest.current.disabled) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// The release point decides, not the last move.
|
|
93
|
+
const next = valueAt(current, sample);
|
|
94
|
+
if (next !== current.value) {
|
|
95
|
+
latest.current.onInput?.(next);
|
|
96
|
+
}
|
|
97
|
+
// A drag is a release away from the press, whatever moves came between.
|
|
98
|
+
isClickSuppressed.current =
|
|
99
|
+
sample.x !== current.pressX || sample.y !== current.pressY;
|
|
100
|
+
if (next !== latest.current.value) {
|
|
101
|
+
latest.current.onChange(next);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
onCancel: (pointerId) => {
|
|
105
|
+
if (drag.current?.pointerId === pointerId) {
|
|
106
|
+
endDrag();
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
}, {
|
|
110
|
+
// One pointer at a time: a second one is never tracked, so it cannot
|
|
111
|
+
// keep the first's box for the next drag.
|
|
112
|
+
accept: (event) => event.button === 0 &&
|
|
113
|
+
!latest.current.disabled &&
|
|
114
|
+
drag.current === undefined,
|
|
115
|
+
// The page still scrolls across the slider; the browser's take-over
|
|
116
|
+
// cancels the press.
|
|
117
|
+
touchAction: isVertical ? "pan-x pinch-zoom" : "pan-y pinch-zoom",
|
|
118
|
+
signal,
|
|
119
|
+
});
|
|
120
|
+
binding.current = bound;
|
|
121
|
+
// The click that follows a drag is not a press of anything under it.
|
|
122
|
+
element.addEventListener("click", (event) => {
|
|
123
|
+
if (isClickSuppressed.current && event.detail !== 0) {
|
|
124
|
+
isClickSuppressed.current = false;
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
event.stopImmediatePropagation();
|
|
127
|
+
}
|
|
128
|
+
}, { capture: true, signal });
|
|
129
|
+
return {
|
|
130
|
+
[Symbol.dispose]() {
|
|
131
|
+
bound[Symbol.dispose]();
|
|
132
|
+
binding.current = undefined;
|
|
133
|
+
endDrag();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}, [isVertical]);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (disabled) {
|
|
139
|
+
binding.current?.cancel();
|
|
140
|
+
endDrag();
|
|
141
|
+
}
|
|
142
|
+
}, [disabled]);
|
|
143
|
+
const onKeyDown = (event) => {
|
|
144
|
+
if (disabled) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const next = steppedValue(clampedSliderValue_(value, range), event.key, range);
|
|
148
|
+
if (next === undefined) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
if (next !== value) {
|
|
153
|
+
onChange(next);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return (_jsxs("div", { id: id, class: joinClasses("ack-control ack-slider", props.class), "data-orientation": orientation, "data-tone": tone, "data-dragging": dragged === undefined ? undefined : "", "data-disabled": disabled ? "" : undefined, style: { "--ack-slider-fraction": sliderFraction(shown, range) }, children: [_jsxs("div", { class: "ack-slider-header", children: [_jsx("span", { class: "ack-slider-label", id: labelId, children: label }), _jsx("span", { class: "ack-slider-value", "aria-hidden": "true", children: format(shown) })] }), _jsxs("div", { ref: control, class: "ack-slider-control", children: [_jsx("div", { class: "ack-slider-track", children: _jsx("div", { class: "ack-slider-range" }) }), _jsx("div", { ...sliderAttributes({
|
|
157
|
+
value: shown,
|
|
158
|
+
range,
|
|
159
|
+
valueText: format(shown),
|
|
160
|
+
orientation,
|
|
161
|
+
disabled,
|
|
162
|
+
}), ref: thumb, class: "ack-slider-thumb", "aria-labelledby": labelId, tabIndex: disabled ? -1 : 0, onKeyDown: onKeyDown })] })] }));
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=slider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.js","sourceRoot":"","sources":["../../src/preact/slider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAuB,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAoB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAGN,kBAAkB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B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a,MAAM,YAC/C,MAAM,CAAC,KAAK,CAAC,GACR,IACF,EACN,eAAK,GAAG,EAAE,OAAO,EAAE,KAAK,EAAC,oBAAoB,aAC5C,cAAK,KAAK,EAAC,kBAAkB,YAC5B,cAAK,KAAK,EAAC,kBAAkB,GAAG,GAC3B,EACN,iBACK,gBAAgB,CAAC;4BACpB,KAAK,EAAE,KAAK;4BACZ,KAAK;4BACL,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC;4BACxB,WAAW;4BACX,QAAQ;yBACR,CAAC,EACF,GAAG,EAAE,KAAK,EACV,KAAK,EAAC,kBAAkB,qBACP,OAAO,EACxB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC3B,SAAS,EAAE,SAAS,GACnB,IACG,IACD,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
3
|
+
import type { ControlTone } from "../tone.js";
|
|
4
|
+
/** Props of {@link SpinButton}. */
|
|
5
|
+
export type SpinButtonProps = {
|
|
6
|
+
/** Its accessible name, drawn above it unless `isLabelHidden`. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Name it without drawing `label`. Defaults to false. */
|
|
9
|
+
isLabelHidden?: boolean;
|
|
10
|
+
value: number;
|
|
11
|
+
/** Omit for no minimum. */
|
|
12
|
+
min?: number;
|
|
13
|
+
/** Omit for no maximum. */
|
|
14
|
+
max?: number;
|
|
15
|
+
/** Defaults to 1. */
|
|
16
|
+
step?: number;
|
|
17
|
+
/** What Page Up and Page Down move by. Defaults to ten steps. */
|
|
18
|
+
largeStep?: number;
|
|
19
|
+
/** The value as a person reads it, shown and announced. Defaults to `String`. */
|
|
20
|
+
format?: Callable<[value: number], string>;
|
|
21
|
+
/**
|
|
22
|
+
* Reads what a person typed: a number, or `undefined` when the text is not
|
|
23
|
+
* one. Giving it makes the value editable as text; without it, only the keys
|
|
24
|
+
* and the buttons change the value.
|
|
25
|
+
*/
|
|
26
|
+
parse?: Callable<[text: string], number | undefined>;
|
|
27
|
+
/** A new value, once per key, button press or entry typed. */
|
|
28
|
+
onChange: Callable<[value: number]>;
|
|
29
|
+
/** The decrement button's accessible name: `"Decrease"`. */
|
|
30
|
+
decrementLabel: string;
|
|
31
|
+
/** The increment button's accessible name: `"Increase"`. */
|
|
32
|
+
incrementLabel: string;
|
|
33
|
+
/** Defaults to a minus sign. */
|
|
34
|
+
decrementIcon?: ComponentChildren;
|
|
35
|
+
/** Defaults to a plus sign. */
|
|
36
|
+
incrementIcon?: ComponentChildren;
|
|
37
|
+
/**
|
|
38
|
+
* The virtual keyboard of an editable one. Defaults to `numeric` for whole
|
|
39
|
+
* steps from a minimum of zero or more, `decimal` for other steps from such a
|
|
40
|
+
* minimum, and `text` when the value may be negative, which the numeric and
|
|
41
|
+
* decimal keyboards of some phones cannot type.
|
|
42
|
+
*/
|
|
43
|
+
inputMode?: "numeric" | "decimal" | "text";
|
|
44
|
+
tone?: ControlTone;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
id?: string;
|
|
47
|
+
class?: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A number stepped by keys and buttons (WAI-ARIA spinbutton pattern): Arrow Up
|
|
51
|
+
* and Down step it, Page Up and Down by ten steps, Home and End go to its
|
|
52
|
+
* minimum and maximum when it has them. With `parse`, the value is also typed:
|
|
53
|
+
* Enter or leaving the field commits it, snapped to the steps and the bounds,
|
|
54
|
+
* and Escape goes back to the value; text that is not a number is marked
|
|
55
|
+
* invalid and reverts. The − and + buttons are out of the tab order and never
|
|
56
|
+
* take focus (the field keeps it, and no phone keyboard opens), stop at the
|
|
57
|
+
* bounds, and announce the new value politely when focus is elsewhere, so a
|
|
58
|
+
* screen reader user pressing them hears it.
|
|
59
|
+
*
|
|
60
|
+
* For a count, a duration, a number of beats: a value whose steps people count.
|
|
61
|
+
* For a continuous setting, a `Slider` or a `Knob`.
|
|
62
|
+
*
|
|
63
|
+
* @throws {RangeError} When `step` or `largeStep` is not above zero, a bound is
|
|
64
|
+
* not finite, or `max` is not above `min`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function SpinButton(props: SpinButtonProps): JSX.Element;
|
|
67
|
+
//# sourceMappingURL=spin-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spin-button.d.ts","sourceRoot":"","sources":["../../src/preact/spin-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AASrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,mCAAmC;AACnC,MAAM,MAAM,eAAe,GAAG;IAC7B,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3C;;;;OAIG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACrD,8DAA8D;IAC9D,QAAQ,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,+BAA+B;IAC/B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;IAC3C,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA+BF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,GAAG,CAAC,OAAO,CAmN9D"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useId, useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
3
|
+
import { snapSpinButtonValue, spinButtonAttributes, spinButtonValue, } from "../spin-button/spin-button.js";
|
|
4
|
+
import { LiveAnnouncer_ } from "./_live-announcer.js";
|
|
5
|
+
import { joinClasses } from "./join-classes.js";
|
|
6
|
+
function defaultInputMode_(range) {
|
|
7
|
+
const { min, step } = range;
|
|
8
|
+
if (min === undefined || min < 0) {
|
|
9
|
+
return "text";
|
|
10
|
+
}
|
|
11
|
+
return Number.isInteger(step) && Number.isInteger(min)
|
|
12
|
+
? "numeric"
|
|
13
|
+
: "decimal";
|
|
14
|
+
}
|
|
15
|
+
function minusIcon_() {
|
|
16
|
+
return (_jsx("svg", { viewBox: "0 0 16 16", focusable: "false", children: _jsx("path", { d: "M3 8h10" }) }));
|
|
17
|
+
}
|
|
18
|
+
function plusIcon_() {
|
|
19
|
+
return (_jsx("svg", { viewBox: "0 0 16 16", focusable: "false", children: _jsx("path", { d: "M3 8h10M8 3v10" }) }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A number stepped by keys and buttons (WAI-ARIA spinbutton pattern): Arrow Up
|
|
23
|
+
* and Down step it, Page Up and Down by ten steps, Home and End go to its
|
|
24
|
+
* minimum and maximum when it has them. With `parse`, the value is also typed:
|
|
25
|
+
* Enter or leaving the field commits it, snapped to the steps and the bounds,
|
|
26
|
+
* and Escape goes back to the value; text that is not a number is marked
|
|
27
|
+
* invalid and reverts. The − and + buttons are out of the tab order and never
|
|
28
|
+
* take focus (the field keeps it, and no phone keyboard opens), stop at the
|
|
29
|
+
* bounds, and announce the new value politely when focus is elsewhere, so a
|
|
30
|
+
* screen reader user pressing them hears it.
|
|
31
|
+
*
|
|
32
|
+
* For a count, a duration, a number of beats: a value whose steps people count.
|
|
33
|
+
* For a continuous setting, a `Slider` or a `Knob`.
|
|
34
|
+
*
|
|
35
|
+
* @throws {RangeError} When `step` or `largeStep` is not above zero, a bound is
|
|
36
|
+
* not finite, or `max` is not above `min`.
|
|
37
|
+
*/
|
|
38
|
+
export function SpinButton(props) {
|
|
39
|
+
const { label, isLabelHidden = false, value, min, max, step = 1, largeStep, format = String, parse, onChange, decrementLabel, incrementLabel, decrementIcon, incrementIcon, inputMode, tone, disabled = false, id, } = props;
|
|
40
|
+
const range = { min, max, step };
|
|
41
|
+
const labelId = useId();
|
|
42
|
+
const fieldId = useId();
|
|
43
|
+
const [draft, setDraft] = useState(undefined);
|
|
44
|
+
const field = useRef(null);
|
|
45
|
+
const announcer = useRef(undefined);
|
|
46
|
+
const pendingAnnouncement = useRef(undefined);
|
|
47
|
+
const base = spinButtonAttributes({
|
|
48
|
+
value,
|
|
49
|
+
range,
|
|
50
|
+
valueText: "",
|
|
51
|
+
disabled,
|
|
52
|
+
});
|
|
53
|
+
const shown = base["aria-valuenow"];
|
|
54
|
+
const attributes = { ...base, "aria-valuetext": format(shown) };
|
|
55
|
+
const parsed = draft === undefined ? undefined : parse?.(draft);
|
|
56
|
+
const isDraftValid = parsed !== undefined && Number.isFinite(parsed);
|
|
57
|
+
// Keys and buttons step from what was typed, when it is a number.
|
|
58
|
+
const from = isDraftValid ? snapSpinButtonValue(parsed, range) : shown;
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
const pending = pendingAnnouncement.current;
|
|
61
|
+
pendingAnnouncement.current = undefined;
|
|
62
|
+
if (pending !== undefined && pending === value) {
|
|
63
|
+
announcer.current ??= new LiveAnnouncer_(document);
|
|
64
|
+
announcer.current.announce([format(value)], "polite");
|
|
65
|
+
}
|
|
66
|
+
}, [value]);
|
|
67
|
+
useLayoutEffect(() => () => {
|
|
68
|
+
announcer.current?.[Symbol.dispose]();
|
|
69
|
+
announcer.current = undefined;
|
|
70
|
+
}, []);
|
|
71
|
+
const commitValue = (next) => {
|
|
72
|
+
if (next !== value) {
|
|
73
|
+
onChange(next);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const commitDraft = () => {
|
|
77
|
+
if (draft === undefined) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
setDraft(undefined);
|
|
81
|
+
if (isDraftValid) {
|
|
82
|
+
commitValue(from);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const onKeyDown = (event) => {
|
|
86
|
+
if (disabled || event.altKey || event.ctrlKey || event.metaKey) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (event.key === "Enter") {
|
|
90
|
+
commitDraft();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (event.key === "Escape") {
|
|
94
|
+
if (draft !== undefined) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
setDraft(undefined);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const next = spinButtonValue(from, event.key, range, { largeStep });
|
|
101
|
+
if (next === undefined) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
setDraft(undefined);
|
|
106
|
+
commitValue(next);
|
|
107
|
+
};
|
|
108
|
+
const name = isLabelHidden
|
|
109
|
+
? { "aria-label": label }
|
|
110
|
+
: { "aria-labelledby": labelId };
|
|
111
|
+
const text = draft ?? attributes["aria-valuetext"];
|
|
112
|
+
const stepButton = (key, buttonLabel, icon, isAtBound) => (_jsx("button", { type: "button", class: `ack-spin-button-step ack-spin-button-${key === "ArrowUp" ? "increment" : "decrement"}`, tabIndex: -1, "aria-label": buttonLabel, "aria-controls": fieldId, disabled: disabled || isAtBound, onMouseDown: (event) => {
|
|
113
|
+
// The field keeps focus, and a phone opens no keyboard.
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
}, onClick: () => {
|
|
116
|
+
const next = spinButtonValue(from, key, range, { largeStep }) ?? from;
|
|
117
|
+
setDraft(undefined);
|
|
118
|
+
if (next !== value && field.current !== document.activeElement) {
|
|
119
|
+
pendingAnnouncement.current = next;
|
|
120
|
+
}
|
|
121
|
+
commitValue(next);
|
|
122
|
+
}, children: _jsx("span", { class: "ack-spin-button-icon", "aria-hidden": "true", children: icon }) }));
|
|
123
|
+
return (_jsxs("div", { id: id, class: joinClasses("ack-control ack-spin-button", props.class), "data-tone": tone, "data-disabled": disabled ? "" : undefined, children: [!isLabelHidden &&
|
|
124
|
+
(parse === undefined ? (_jsx("span", { class: "ack-spin-button-label", id: labelId, children: label })) : (_jsx("label", { class: "ack-spin-button-label", id: labelId, for: fieldId, children: label }))), _jsxs("div", { class: "ack-spin-button-body", children: [stepButton("ArrowDown", decrementLabel, decrementIcon ?? minusIcon_(), min !== undefined && shown <= min), parse === undefined ? (_jsx("div", { ...attributes, ...name, id: fieldId, ref: (node) => {
|
|
125
|
+
field.current = node;
|
|
126
|
+
}, class: "ack-spin-button-field", tabIndex: disabled ? -1 : 0, onKeyDown: onKeyDown, children: text })) : (_jsx("input", { ...attributes, ...name, id: fieldId, ref: (node) => {
|
|
127
|
+
field.current = node;
|
|
128
|
+
}, class: "ack-spin-button-field", type: "text", inputMode: inputMode ?? defaultInputMode_(range), autoComplete: "off", spellcheck: false, readOnly: disabled, tabIndex: disabled ? -1 : 0, "aria-invalid": draft !== undefined && !isDraftValid ? "true" : undefined, value: text, onInput: (event) => {
|
|
129
|
+
setDraft(event.currentTarget.value);
|
|
130
|
+
}, onBlur: commitDraft, onKeyDown: onKeyDown })), stepButton("ArrowUp", incrementLabel, incrementIcon ?? plusIcon_(), max !== undefined && shown >= max)] })] }));
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=spin-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spin-button.js","sourceRoot":"","sources":["../../src/preact/spin-button.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EAEN,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,GACf,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgDhD,SAAS,iBAAiB,CACzB,KAAsB;IAEtB,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAC5B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC;IACf,CAAC;IAED,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;QACrD,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED,SAAS,UAAU;IAClB,OAAO,CACN,cAAK,OAAO,EAAC,WAAW,EAAC,SAAS,EAAC,OAAO,YACzC,eAAM,CAAC,EAAC,SAAS,GAAG,GACf,CACN,CAAC;AACH,CAAC;AAED,SAAS,SAAS;IACjB,OAAO,CACN,c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ACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { JSX } from "preact";
|
|
3
|
+
/** Props of {@link Switch}. */
|
|
4
|
+
export type SwitchProps = {
|
|
5
|
+
/** Its accessible name, drawn beside it. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** A sentence under the label, linked by `aria-describedby`. */
|
|
8
|
+
description?: string;
|
|
9
|
+
isOn: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Activated: the state it asks for, `!isOn`. Pass it back as `isOn`. */
|
|
12
|
+
onToggle: Callable<[isOn: boolean]>;
|
|
13
|
+
id?: string;
|
|
14
|
+
class?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* An on/off setting that takes effect as soon as it is flipped, like a phone's
|
|
18
|
+
* airplane-mode switch. A native button announced as a switch, so it takes
|
|
19
|
+
* focus and flips with Space and Enter.
|
|
20
|
+
*
|
|
21
|
+
* For a choice confirmed later with a form, use a checkbox; for a state shown
|
|
22
|
+
* on a hardware-style button, a `ToggleButton`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function Switch(props: SwitchProps): JSX.Element;
|
|
25
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/preact/switch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAMlC,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG;IACzB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yEAAyE;IACzE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACpC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CA+BtD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useId } from "preact/hooks";
|
|
3
|
+
import { switchAttributes } from "../switch/switch.js";
|
|
4
|
+
import { joinClasses } from "./join-classes.js";
|
|
5
|
+
/**
|
|
6
|
+
* An on/off setting that takes effect as soon as it is flipped, like a phone's
|
|
7
|
+
* airplane-mode switch. A native button announced as a switch, so it takes
|
|
8
|
+
* focus and flips with Space and Enter.
|
|
9
|
+
*
|
|
10
|
+
* For a choice confirmed later with a form, use a checkbox; for a state shown
|
|
11
|
+
* on a hardware-style button, a `ToggleButton`.
|
|
12
|
+
*/
|
|
13
|
+
export function Switch(props) {
|
|
14
|
+
const { label, description, isOn, disabled = false, onToggle, id } = props;
|
|
15
|
+
const labelId = useId();
|
|
16
|
+
const descriptionId = useId();
|
|
17
|
+
return (_jsxs("button", { ...switchAttributes({ isOn, disabled }), type: "button", id: id, disabled: disabled, "aria-labelledby": labelId, "aria-describedby": description === undefined ? undefined : descriptionId, class: joinClasses("ack-control ack-switch", props.class), onClick: () => onToggle(!isOn), children: [_jsxs("span", { class: "ack-switch-text", children: [_jsx("span", { id: labelId, class: "ack-switch-label", children: label }), description !== undefined && (_jsx("span", { id: descriptionId, class: "ack-switch-description", children: description }))] }), _jsx("span", { class: "ack-switch-track", "aria-hidden": "true", children: _jsx("span", { class: "ack-switch-thumb" }) })] }));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import { type ComponentChildren, type JSX } from "preact";
|
|
3
|
+
import { type TabsActivation, type TabsOrientation } from "../tabs/tabs.js";
|
|
4
|
+
/** Props of {@link Tabs}. */
|
|
5
|
+
export type TabsProps = {
|
|
6
|
+
/** The `value` of the tab whose panel shows. */
|
|
7
|
+
selected: string;
|
|
8
|
+
/** Called with the `value` of the tab the person chooses. */
|
|
9
|
+
onSelectedChange: Callable<[value: string]>;
|
|
10
|
+
/**
|
|
11
|
+
* `automatic` (the default) shows a tab's panel as soon as the arrow keys
|
|
12
|
+
* reach it; `manual` waits for Enter, Space or a click, for panels slow to
|
|
13
|
+
* show.
|
|
14
|
+
*/
|
|
15
|
+
activation?: TabsActivation;
|
|
16
|
+
/** Defaults to `horizontal`. */
|
|
17
|
+
orientation?: TabsOrientation;
|
|
18
|
+
/**
|
|
19
|
+
* Lets Delete close the focused tab: called with its `value`; remove the tab
|
|
20
|
+
* and its panel in answer. Focus moves to the tab after it (else before);
|
|
21
|
+
* when it was the selected one, the nearest enabled tab after it (else
|
|
22
|
+
* before) is selected in its place. A disabled tab is not deleted.
|
|
23
|
+
*/
|
|
24
|
+
onDelete?: Callable<[value: string]>;
|
|
25
|
+
/** A {@link TabList} and the {@link TabPanel}s. */
|
|
26
|
+
children: ComponentChildren;
|
|
27
|
+
id?: string;
|
|
28
|
+
class?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Panels of content of which one shows at a time, chosen by a row (or column)
|
|
32
|
+
* of tabs (WAI-ARIA tabs pattern). The tab list is one tab stop, on the
|
|
33
|
+
* selected tab; the arrow keys along it move between tabs, going round, Home
|
|
34
|
+
* and End to the ends, mirrored right to left. Tab then reaches the panel, or
|
|
35
|
+
* the first control inside it. A disabled tab takes focus, so it can be found
|
|
36
|
+
* and read, and is never selected.
|
|
37
|
+
*
|
|
38
|
+
* Every panel stays rendered, the others `hidden="until-found"`: their state is
|
|
39
|
+
* kept, and the browser's find in page reveals a match in one by selecting its
|
|
40
|
+
* tab. The selection is the caller's: `selected` and `onSelectedChange`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* <Tabs selected={tab} onSelectedChange={setTab}>
|
|
44
|
+
* <TabList label="Settings">
|
|
45
|
+
* <Tab value="sound">Sound</Tab>
|
|
46
|
+
* <Tab value="display">Display</Tab>
|
|
47
|
+
* </TabList>
|
|
48
|
+
* <TabPanel value="sound">…</TabPanel>
|
|
49
|
+
* <TabPanel value="display">…</TabPanel>
|
|
50
|
+
* </Tabs>;
|
|
51
|
+
*/
|
|
52
|
+
export declare function Tabs(props: TabsProps): JSX.Element;
|
|
53
|
+
/** Props of {@link TabList}: its accessible name, as text or by reference. */
|
|
54
|
+
export type TabListProps = ({
|
|
55
|
+
label: string;
|
|
56
|
+
labelledBy?: undefined;
|
|
57
|
+
} | {
|
|
58
|
+
label?: undefined;
|
|
59
|
+
labelledBy: string;
|
|
60
|
+
}) & {
|
|
61
|
+
/** The {@link Tab}s. */
|
|
62
|
+
children: ComponentChildren;
|
|
63
|
+
class?: string;
|
|
64
|
+
};
|
|
65
|
+
/** The row, or column, of {@link Tab}s of a {@link Tabs}: the `tablist` role. */
|
|
66
|
+
export declare function TabList(props: TabListProps): JSX.Element;
|
|
67
|
+
/** Props of {@link Tab}. */
|
|
68
|
+
export type TabProps = {
|
|
69
|
+
/** Which {@link TabPanel} it shows; unique among the tabs. */
|
|
70
|
+
value: string;
|
|
71
|
+
/** Its label. */
|
|
72
|
+
children: ComponentChildren;
|
|
73
|
+
/** Drawn before the label, hidden from assistive technology. */
|
|
74
|
+
icon?: ComponentChildren;
|
|
75
|
+
/** Announced and focusable, but never selected. Defaults to false. */
|
|
76
|
+
disabled?: boolean;
|
|
77
|
+
class?: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* A tab of a {@link TabList}: a `<button>` with the `tab` role, selected by a
|
|
81
|
+
* click or by the keys {@link Tabs} describes.
|
|
82
|
+
*/
|
|
83
|
+
export declare function Tab(props: TabProps): JSX.Element;
|
|
84
|
+
/** Props of {@link TabPanel}. */
|
|
85
|
+
export type TabPanelProps = {
|
|
86
|
+
/** The `value` of the {@link Tab} that shows it. */
|
|
87
|
+
value: string;
|
|
88
|
+
children: ComponentChildren;
|
|
89
|
+
class?: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* The content a {@link Tab} shows: the `tabpanel` role, named by its tab. In the
|
|
93
|
+
* tab order itself only when nothing inside it is, so Tab from the tab list
|
|
94
|
+
* reaches its content either way.
|
|
95
|
+
*/
|
|
96
|
+
export declare function TabPanel(props: TabPanelProps): JSX.Element;
|
|
97
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/preact/tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,iBAAiB,EAAiB,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AASzE,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EAKpB,MAAM,iBAAiB,CAAC;AAKzB,6BAA6B;AAC7B,MAAM,MAAM,SAAS,GAAG;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,gBAAgB,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C;;;;OAIG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,gCAAgC;IAChC,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACrC,mDAAmD;IACnD,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,EAAE,CAAC,EAAE,MA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