@ac-kit/ui-common 0.0.0-stage → 0.1.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 +89 -0
- package/LICENSE +28 -0
- package/README.md +315 -2
- 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/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -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/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/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 +13 -0
- package/dist/preact/index.d.ts.map +1 -0
- package/dist/preact/index.js +13 -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 +152 -0
- package/dist/preact/knob.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/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 +162 -0
- package/dist/preact/slider.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/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 +148 -0
- package/dist/preact/toolbar.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/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/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/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/package.json +100 -3
- package/styles.css +992 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { buttonAttributes, } from "../button/button.js";
|
|
3
|
+
import { joinClasses } from "./join-classes.js";
|
|
4
|
+
/**
|
|
5
|
+
* A push button for an action: `primary` for the one main action of a view,
|
|
6
|
+
* `secondary` for the others, `ghost` for a bare one. A native button, so it
|
|
7
|
+
* takes focus and activates with Space and Enter; `type` defaults to `button`,
|
|
8
|
+
* so inside a form only `type="submit"` submits it.
|
|
9
|
+
*/
|
|
10
|
+
export function Button(props) {
|
|
11
|
+
const { variant, size, tone, icon, children, class: extra, type = "button", ...rest } = props;
|
|
12
|
+
return (_jsxs("button", { ...rest, ...buttonAttributes({ variant, size, tone }), type: type, class: joinClasses("ack-control ack-button", extra), children: [icon !== undefined && (_jsx("span", { class: "ack-button-icon", "aria-hidden": "true", children: icon })), children] }));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A button drawn as an icon alone, named by `label`: transport controls, a
|
|
16
|
+
* close button. Takes the touch target's full size around a small icon.
|
|
17
|
+
*/
|
|
18
|
+
export function IconButton(props) {
|
|
19
|
+
const { label, variant, tone, children, class: extra, type = "button", ...rest } = props;
|
|
20
|
+
return (_jsx("button", { title: label, ...rest, ...buttonAttributes({ variant, tone }), type: type, "aria-label": label, class: joinClasses("ack-control ack-button ack-icon-button", extra), children: _jsx("span", { class: "ack-button-icon", "aria-hidden": "true", children: children }) }));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/preact/button.tsx"],"names":[],"mappings":";AAEA,OAAO,EAGN,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBhD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAkB;IACxC,MAAM,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,IAAI,GAAG,QAAQ,EACf,GAAG,IAAI,EACP,GAAG,KAAK,CAAC;IAEV,OAAO,CACN,qBACK,IAAI,KACJ,gBAAgB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAC7C,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,WAAW,CAAC,wBAAwB,EAAE,KAAK,CAAC,aAElD,IAAI,KAAK,SAAS,IAAI,CACtB,eAAM,KAAK,EAAC,iBAAiB,iBAAa,MAAM,YAC9C,IAAI,GACC,CACP,EACA,QAAQ,IACD,CACT,CAAC;AACH,CAAC;AAiBD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB;IAChD,MAAM,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,IAAI,GAAG,QAAQ,EACf,GAAG,IAAI,EACP,GAAG,KAAK,CAAC;IAEV,OAAO,CACN,iBACC,KAAK,EAAE,KAAK,KACR,IAAI,KACJ,gBAAgB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EACvC,IAAI,EAAE,IAAI,gBACE,KAAK,EACjB,KAAK,EAAE,WAAW,CAAC,wCAAwC,EAAE,KAAK,CAAC,YAEnE,eAAM,KAAK,EAAC,iBAAiB,iBAAa,MAAM,YAC9C,QAAQ,GACH,GACC,CACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CallableNoArgs } from "@ac-kit/core";
|
|
2
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
3
|
+
import { type DialogPlacement } from "../dialog/dialog.js";
|
|
4
|
+
/** Props of {@link Dialog}. */
|
|
5
|
+
export type DialogProps = {
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Asked to close: Escape, the close button, a backdrop click when
|
|
11
|
+
* dismissible, or a `<form method="dialog">` submitted. Called once, after
|
|
12
|
+
* the dialog has closed; set `isOpen` to false in answer.
|
|
13
|
+
*/
|
|
14
|
+
onClose: CallableNoArgs;
|
|
15
|
+
/** Defaults to `center`. */
|
|
16
|
+
placement?: DialogPlacement;
|
|
17
|
+
/** Escape and a backdrop click close it. Defaults to true. */
|
|
18
|
+
isDismissible?: boolean;
|
|
19
|
+
/** The close button's accessible name; without it, no close button is drawn. */
|
|
20
|
+
closeLabel?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The close button's icon. Defaults to a drawn ×, hidden from assistive
|
|
23
|
+
* technology.
|
|
24
|
+
*/
|
|
25
|
+
closeIcon?: ComponentChildren;
|
|
26
|
+
children: ComponentChildren;
|
|
27
|
+
/** A footer row of actions. */
|
|
28
|
+
actions?: ComponentChildren;
|
|
29
|
+
id?: string;
|
|
30
|
+
class?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A modal dialog on a native `<dialog>`: the rest of the page is inert, Escape
|
|
34
|
+
* closes it when dismissible, and focus returns to the opener. Rendered in
|
|
35
|
+
* place, with no portal: the top layer lifts it above the page.
|
|
36
|
+
*
|
|
37
|
+
* A press that starts and ends on the backdrop closes it too, a text selection
|
|
38
|
+
* dragged out of the panel does not.
|
|
39
|
+
*
|
|
40
|
+
* Keep `isOpen` the single source of truth: set it false in `onClose`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function Dialog(props: DialogProps): JSX.Element;
|
|
43
|
+
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/preact/dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAGrD,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,qBAAqB,CAAC;AAI7E,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,8DAA8D;IAC9D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,+BAA+B;IAC/B,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAiJtD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useId, useLayoutEffect, useRef } from "preact/hooks";
|
|
3
|
+
import { dialogAttributes } from "../dialog/dialog.js";
|
|
4
|
+
import { joinClasses } from "./join-classes.js";
|
|
5
|
+
import { useLatest } from "./use-element-binding.js";
|
|
6
|
+
/**
|
|
7
|
+
* A modal dialog on a native `<dialog>`: the rest of the page is inert, Escape
|
|
8
|
+
* closes it when dismissible, and focus returns to the opener. Rendered in
|
|
9
|
+
* place, with no portal: the top layer lifts it above the page.
|
|
10
|
+
*
|
|
11
|
+
* A press that starts and ends on the backdrop closes it too, a text selection
|
|
12
|
+
* dragged out of the panel does not.
|
|
13
|
+
*
|
|
14
|
+
* Keep `isOpen` the single source of truth: set it false in `onClose`.
|
|
15
|
+
*/
|
|
16
|
+
export function Dialog(props) {
|
|
17
|
+
const { title, description, isOpen, onClose, placement, isDismissible = true, closeLabel, closeIcon, children, actions, id, } = props;
|
|
18
|
+
const titleId = useId();
|
|
19
|
+
const descriptionId = useId();
|
|
20
|
+
const dialog = useRef(null);
|
|
21
|
+
const latestOnClose = useLatest(onClose);
|
|
22
|
+
const isPressOnBackdrop = useRef(false);
|
|
23
|
+
// Closes the effect below asked for: each one's close event is its own, even
|
|
24
|
+
// when the browser delivers it after a later reopening.
|
|
25
|
+
const pendingCloses = useRef(0);
|
|
26
|
+
const opener = useRef(undefined);
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
const element = dialog.current;
|
|
29
|
+
if (element === null) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (isOpen && !element.open) {
|
|
33
|
+
opener.current =
|
|
34
|
+
document.activeElement instanceof HTMLElement
|
|
35
|
+
? document.activeElement
|
|
36
|
+
: undefined;
|
|
37
|
+
element.showModal();
|
|
38
|
+
}
|
|
39
|
+
else if (!isOpen && element.open) {
|
|
40
|
+
pendingCloses.current += 1;
|
|
41
|
+
element.close();
|
|
42
|
+
}
|
|
43
|
+
}, [isOpen]);
|
|
44
|
+
// Removed while open, the browser does not return focus: do it. The opener
|
|
45
|
+
// stays inert until the dialog closes, so close it first.
|
|
46
|
+
useLayoutEffect(() => () => {
|
|
47
|
+
const element = dialog.current;
|
|
48
|
+
if (element?.open !== true) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
pendingCloses.current += 1;
|
|
52
|
+
element.close();
|
|
53
|
+
if (opener.current?.isConnected === true) {
|
|
54
|
+
opener.current.focus();
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
return (_jsx("dialog", { ...dialogAttributes({
|
|
58
|
+
titleId,
|
|
59
|
+
descriptionId: description === undefined ? undefined : descriptionId,
|
|
60
|
+
placement,
|
|
61
|
+
}), id: id, ref: dialog, closedby: isDismissible ? "closerequest" : "none", class: joinClasses("ack-dialog", props.class), onCancel: (event) => {
|
|
62
|
+
if (!isDismissible) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
}
|
|
65
|
+
}, onClose: () => {
|
|
66
|
+
if (pendingCloses.current > 0) {
|
|
67
|
+
pendingCloses.current -= 1;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
latestOnClose.current();
|
|
71
|
+
}, onPointerDown: (event) => {
|
|
72
|
+
isPressOnBackdrop.current = event.target === event.currentTarget;
|
|
73
|
+
}, onPointerUp: (event) => {
|
|
74
|
+
// A touch's implicit capture retargets its release to the dialog
|
|
75
|
+
// wherever it ends: hit-test where it ends instead.
|
|
76
|
+
const released = document.elementFromPoint(event.clientX, event.clientY);
|
|
77
|
+
if (event.target !== event.currentTarget ||
|
|
78
|
+
released !== event.currentTarget) {
|
|
79
|
+
isPressOnBackdrop.current = false;
|
|
80
|
+
}
|
|
81
|
+
}, onClick: (event) => {
|
|
82
|
+
const isBackdropClick = isPressOnBackdrop.current && event.target === event.currentTarget;
|
|
83
|
+
isPressOnBackdrop.current = false;
|
|
84
|
+
if (isBackdropClick && isDismissible) {
|
|
85
|
+
event.currentTarget.close();
|
|
86
|
+
}
|
|
87
|
+
}, children: _jsxs("div", { class: "ack-dialog-panel", children: [_jsxs("div", { class: "ack-dialog-header", children: [_jsx("h2", { id: titleId, class: "ack-dialog-title", children: title }), closeLabel !== undefined && (_jsx("button", { type: "button", class: "ack-control ack-dialog-close", "aria-label": closeLabel, title: closeLabel, onClick: () => dialog.current?.close(), children: _jsx("span", { class: "ack-dialog-close-icon", "aria-hidden": "true", children: closeIcon ?? (_jsx("svg", { viewBox: "0 0 16 16", focusable: "false", children: _jsx("path", { d: "M3 3l10 10M13 3L3 13" }) })) }) }))] }), description !== undefined && (_jsx("p", { id: descriptionId, class: "ack-dialog-description", children: description })), _jsx("div", { class: "ack-dialog-body", children: children }), actions !== undefined && (_jsx("div", { class: "ack-dialog-actions", children: actions }))] }) }));
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/preact/dialog.tsx"],"names":[],"mappings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,uBAAuB,iBAAa,MAAM,YACpD,SAAS,IAAI,CACb,cAAK,OAAO,EAAC,WAAW,EAAC,SAAS,EAAC,OAAO,YACzC,eAAM,CAAC,EAAC,sBAAsB,GAAG,GAC5B,CACN,GACK,GACC,CACT,IACI,EACL,WAAW,KAAK,SAAS,IAAI,CAC7B,YAAG,EAAE,EAAE,aAAa,EAAE,KAAK,EAAC,wBAAwB,YAClD,WAAW,GACT,CACJ,EACD,cAAK,KAAK,EAAC,iBAAiB,YAAE,QAAQ,GAAO,EAC5C,OAAO,KAAK,SAAS,IAAI,CACzB,cAAK,KAAK,EAAC,oBAAoB,YAAE,OAAO,GAAO,CAC/C,IACI,GACE,CACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./button.js";
|
|
2
|
+
export * from "./dialog.js";
|
|
3
|
+
export * from "./join-classes.js";
|
|
4
|
+
export * from "./knob.js";
|
|
5
|
+
export * from "./meter.js";
|
|
6
|
+
export * from "./radio-group.js";
|
|
7
|
+
export * from "./readout.js";
|
|
8
|
+
export * from "./slider.js";
|
|
9
|
+
export * from "./switch.js";
|
|
10
|
+
export * from "./toggle-button.js";
|
|
11
|
+
export * from "./toolbar.js";
|
|
12
|
+
export * from "./use-element-binding.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/preact/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./button.js";
|
|
2
|
+
export * from "./dialog.js";
|
|
3
|
+
export * from "./join-classes.js";
|
|
4
|
+
export * from "./knob.js";
|
|
5
|
+
export * from "./meter.js";
|
|
6
|
+
export * from "./radio-group.js";
|
|
7
|
+
export * from "./readout.js";
|
|
8
|
+
export * from "./slider.js";
|
|
9
|
+
export * from "./switch.js";
|
|
10
|
+
export * from "./toggle-button.js";
|
|
11
|
+
export * from "./toolbar.js";
|
|
12
|
+
export * from "./use-element-binding.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/preact/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A control's own classes, then the caller's: for the `class` of a component's
|
|
3
|
+
* root, so a caller's class never replaces the ones the stylesheet needs.
|
|
4
|
+
* `ui-music`'s components and the caller's use it for the same.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* joinClasses("ack-control ack-knob", props.class); // "ack-control ack-knob mine"
|
|
8
|
+
*/
|
|
9
|
+
export declare function joinClasses(base: string, extra: string | undefined): string;
|
|
10
|
+
//# sourceMappingURL=join-classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-classes.d.ts","sourceRoot":"","sources":["../../src/preact/join-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE3E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A control's own classes, then the caller's: for the `class` of a component's
|
|
3
|
+
* root, so a caller's class never replaces the ones the stylesheet needs.
|
|
4
|
+
* `ui-music`'s components and the caller's use it for the same.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* joinClasses("ack-control ack-knob", props.class); // "ack-control ack-knob mine"
|
|
8
|
+
*/
|
|
9
|
+
export function joinClasses(base, extra) {
|
|
10
|
+
return extra === undefined || extra === "" ? base : `${base} ${extra}`;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=join-classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-classes.js","sourceRoot":"","sources":["../../src/preact/join-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAyB;IAClE,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Callable, CallableNoArgs } from "@ac-kit/core";
|
|
2
|
+
import type { JSX } from "preact";
|
|
3
|
+
import type { ControlTone } from "../tone.js";
|
|
4
|
+
/** Props of {@link Knob}. */
|
|
5
|
+
export type KnobProps = {
|
|
6
|
+
/** Its accessible name, also drawn under it. */
|
|
7
|
+
label: string;
|
|
8
|
+
value: number;
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
/** Defaults to 1. */
|
|
12
|
+
step?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The value a double tap goes back to. Without one, a double tap is two taps,
|
|
15
|
+
* and a tap requests entry at once instead of after the double-tap interval.
|
|
16
|
+
*/
|
|
17
|
+
resetValue?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The value the lit arc grows from. Defaults to `min`; a bipolar knob (pan,
|
|
20
|
+
* detune) gives its centre.
|
|
21
|
+
*/
|
|
22
|
+
origin?: number;
|
|
23
|
+
tone?: ControlTone;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** The value as a person reads it, shown and announced. Defaults to `String`. */
|
|
26
|
+
format?: Callable<[value: number], string>;
|
|
27
|
+
/** A new value, once per gesture: at a drag's end, a key, a double tap. */
|
|
28
|
+
onChange: Callable<[value: number]>;
|
|
29
|
+
/** The value following a drag, before it is committed through `onChange`. */
|
|
30
|
+
onInput?: Callable<[value: number]>;
|
|
31
|
+
/**
|
|
32
|
+
* A tap, or Enter or Space while focused: the person wants to type or pick a
|
|
33
|
+
* value. Open your own surface for it — a dialog, a sheet, a large `Slider` —
|
|
34
|
+
* and report its result through `onChange`.
|
|
35
|
+
*/
|
|
36
|
+
onRequestEntry?: CallableNoArgs;
|
|
37
|
+
id?: string;
|
|
38
|
+
class?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A rotary control, as on a synthesizer: drag up or down to turn it (not
|
|
42
|
+
* around, which hides it under a finger), with Shift for fine control; tap it
|
|
43
|
+
* to request value entry; double-tap to reset it. Focused, the arrow keys step
|
|
44
|
+
* it, Page Up and Page Down by ten steps, Home and End to the ends. It reports
|
|
45
|
+
* a value once a gesture ends.
|
|
46
|
+
*
|
|
47
|
+
* For a compact panel of sound or tempo controls; a setting with room to spare
|
|
48
|
+
* reads better as a `Slider`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function Knob(props: KnobProps): JSX.Element;
|
|
51
|
+
//# sourceMappingURL=knob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knob.d.ts","sourceRoot":"","sources":["../../src/preact/kn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from "@ac-kit/ui-gesture/dom";
|
|
3
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
4
|
+
import { KNOB_ARC, knobAngles, knobArcPath, knobDragValue, } from "../knob/knob.js";
|
|
5
|
+
import { clampedSliderValue_ } from "../slider/_clamped-value.js";
|
|
6
|
+
import { sliderAttributes } from "../slider/slider-attributes.js";
|
|
7
|
+
import { snapSliderValue } from "../slider/slider-range.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
|
+
// The dial's drawing, in its 52 × 52 view box.
|
|
12
|
+
const DIAL_ = { centerX: 26, centerY: 26, radius: 22 };
|
|
13
|
+
const CAP_RADIUS_ = 15;
|
|
14
|
+
const POINTER_LENGTH_ = 12;
|
|
15
|
+
// An arc shorter than this, in degrees, would draw as a dot under the round
|
|
16
|
+
// line caps, so none is drawn.
|
|
17
|
+
const MIN_ARC_DEGREES_ = 0.5;
|
|
18
|
+
const TRACK_PATH_ = knobArcPath(DIAL_, KNOB_ARC.startDegrees, KNOB_ARC.startDegrees + KNOB_ARC.sweepDegrees);
|
|
19
|
+
/**
|
|
20
|
+
* A rotary control, as on a synthesizer: drag up or down to turn it (not
|
|
21
|
+
* around, which hides it under a finger), with Shift for fine control; tap it
|
|
22
|
+
* to request value entry; double-tap to reset it. Focused, the arrow keys step
|
|
23
|
+
* it, Page Up and Page Down by ten steps, Home and End to the ends. It reports
|
|
24
|
+
* a value once a gesture ends.
|
|
25
|
+
*
|
|
26
|
+
* For a compact panel of sound or tempo controls; a setting with room to spare
|
|
27
|
+
* reads better as a `Slider`.
|
|
28
|
+
*/
|
|
29
|
+
export function Knob(props) {
|
|
30
|
+
const { label, value, min, max, step = 1, resetValue, origin, tone, disabled = false, format = String, onChange, onInput, onRequestEntry, id, } = props;
|
|
31
|
+
const range = { min, max, step };
|
|
32
|
+
const [dragged, setDragged] = useState(undefined);
|
|
33
|
+
const drag = useRef(undefined);
|
|
34
|
+
const binding = useRef(undefined);
|
|
35
|
+
const latest = useLatest({
|
|
36
|
+
range,
|
|
37
|
+
value,
|
|
38
|
+
resetValue,
|
|
39
|
+
disabled,
|
|
40
|
+
onChange,
|
|
41
|
+
onInput,
|
|
42
|
+
onRequestEntry,
|
|
43
|
+
});
|
|
44
|
+
const shown = clampedSliderValue_(dragged ?? value, range);
|
|
45
|
+
const angles = knobAngles(shown, range, { origin });
|
|
46
|
+
const hasReset = resetValue !== undefined;
|
|
47
|
+
const commit = (next) => {
|
|
48
|
+
const { range, value, onChange } = latest.current;
|
|
49
|
+
const snapped = snapSliderValue(next, range);
|
|
50
|
+
if (snapped !== value) {
|
|
51
|
+
onChange(snapped);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const endDrag = () => {
|
|
55
|
+
drag.current = undefined;
|
|
56
|
+
setDragged(undefined);
|
|
57
|
+
};
|
|
58
|
+
const valueAt = (current, update) => knobDragValue(current.startValue, -update.movementY, latest.current.range, {
|
|
59
|
+
isFine: update.phase === "end" ? current.isFine : update.shiftKey,
|
|
60
|
+
});
|
|
61
|
+
const onDrag = (update) => {
|
|
62
|
+
const current = drag.current;
|
|
63
|
+
if (current === undefined) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (update.phase === "cancel" || latest.current.disabled) {
|
|
67
|
+
endDrag();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const next = valueAt(current, update);
|
|
71
|
+
if (next !== (current.value ?? current.startValue)) {
|
|
72
|
+
latest.current.onInput?.(next);
|
|
73
|
+
}
|
|
74
|
+
if (update.phase === "end") {
|
|
75
|
+
// The release point decides, not the last move.
|
|
76
|
+
endDrag();
|
|
77
|
+
commit(next);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
current.value = next;
|
|
81
|
+
current.isFine = update.shiftKey;
|
|
82
|
+
setDragged(next);
|
|
83
|
+
};
|
|
84
|
+
const root = useElementBinding((element, signal) => {
|
|
85
|
+
const bound = bindPressGesture(element, {
|
|
86
|
+
onPress: () => {
|
|
87
|
+
drag.current = {
|
|
88
|
+
startValue: latest.current.value,
|
|
89
|
+
value: undefined,
|
|
90
|
+
isFine: false,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
onDrag,
|
|
94
|
+
// A tap settles after the double-tap window, which a disabling can
|
|
95
|
+
// fall in.
|
|
96
|
+
onTap: () => {
|
|
97
|
+
if (!latest.current.disabled) {
|
|
98
|
+
latest.current.onRequestEntry?.();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onDoubleTap: () => {
|
|
102
|
+
const { resetValue, disabled } = latest.current;
|
|
103
|
+
if (resetValue !== undefined && !disabled) {
|
|
104
|
+
commit(resetValue);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
}, {
|
|
108
|
+
doubleTap: hasReset,
|
|
109
|
+
touchAction: "none",
|
|
110
|
+
accept: () => !latest.current.disabled,
|
|
111
|
+
signal,
|
|
112
|
+
});
|
|
113
|
+
binding.current = bound;
|
|
114
|
+
// A rebinding mid-drag drops the drag with the old binding.
|
|
115
|
+
return {
|
|
116
|
+
[Symbol.dispose]() {
|
|
117
|
+
bound[Symbol.dispose]();
|
|
118
|
+
binding.current = undefined;
|
|
119
|
+
endDrag();
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}, [hasReset]);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (disabled) {
|
|
125
|
+
binding.current?.cancel();
|
|
126
|
+
endDrag();
|
|
127
|
+
}
|
|
128
|
+
}, [disabled]);
|
|
129
|
+
const onKeyDown = (event) => {
|
|
130
|
+
if (disabled) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const next = steppedValue(value, event.key, range);
|
|
134
|
+
if (next !== undefined) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
commit(next);
|
|
137
|
+
}
|
|
138
|
+
else if ((event.key === "Enter" || event.key === " ") &&
|
|
139
|
+
onRequestEntry !== undefined) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
onRequestEntry();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return (_jsxs("div", { ...sliderAttributes({
|
|
145
|
+
label,
|
|
146
|
+
value: shown,
|
|
147
|
+
range,
|
|
148
|
+
valueText: format(shown),
|
|
149
|
+
disabled,
|
|
150
|
+
}), ref: root, id: id, class: joinClasses("ack-control ack-knob", props.class), "data-tone": tone, "data-dragging": dragged === undefined ? undefined : "", tabIndex: disabled ? -1 : 0, onKeyDown: onKeyDown, children: [_jsxs("svg", { class: "ack-knob-dial", viewBox: "0 0 52 52", "aria-hidden": "true", children: [_jsx("path", { class: "ack-knob-track", d: TRACK_PATH_ }), angles.arcTo - angles.arcFrom > MIN_ARC_DEGREES_ && (_jsx("path", { class: "ack-knob-arc", d: knobArcPath(DIAL_, angles.arcFrom, angles.arcTo) })), _jsx("circle", { class: "ack-knob-cap", cx: DIAL_.centerX, cy: DIAL_.centerY, r: CAP_RADIUS_ }), _jsx("line", { class: "ack-knob-pointer", x1: DIAL_.centerX, y1: DIAL_.centerY, x2: DIAL_.centerX, y2: DIAL_.centerY - POINTER_LENGTH_, transform: `rotate(${angles.pointer} ${DIAL_.centerX} ${DIAL_.centerY})` })] }), _jsx("span", { class: "ack-knob-value", children: format(shown) }), _jsx("span", { class: "ack-knob-label", children: label })] }));
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=knob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knob.js","sourceRoot":"","sources":["../../src/preact/knob.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EACN,QAAQ,EAER,UAAU,EACV,WAAW,EACX,aAAa,GACb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AAE,KAAK,CAAC,OAAO,EACjB,EAAE,EAAE,KAAK,CAAC,OAAO,EACjB,EAAE,EAAE,KAAK,CAAC,OAAO,GAAG,eAAe,EACnC,SAAS,EAAE,UAAU,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,GAAG,GACvE,IACG,EACN,eAAM,KAAK,EAAC,gBAAgB,YAAE,MAAM,CAAC,KAAK,CAAC,GAAQ,EACnD,eAAM,KAAK,EAAC,gBAAgB,YAAE,KAAK,GAAQ,IACtC,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JSX } from "preact";
|
|
2
|
+
import { type MeterSegment } from "../meter/meter.js";
|
|
3
|
+
import type { ControlTone } from "../tone.js";
|
|
4
|
+
/** Props of {@link Meter}. */
|
|
5
|
+
export type MeterProps = {
|
|
6
|
+
/** Its accessible name; it is not drawn. */
|
|
7
|
+
label: string;
|
|
8
|
+
value: number;
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
/**
|
|
12
|
+
* Segments lit from the bottom or the left by `value`, in the units of
|
|
13
|
+
* `value`. Without, a continuous bar.
|
|
14
|
+
*/
|
|
15
|
+
segments?: readonly MeterSegment[];
|
|
16
|
+
/** Defaults to `horizontal`. */
|
|
17
|
+
orientation?: "horizontal" | "vertical";
|
|
18
|
+
/** What a person reads, announced with the value: `"-12 dB"`. */
|
|
19
|
+
valueText?: string;
|
|
20
|
+
/** The colour of a continuous bar; segments carry their own. */
|
|
21
|
+
tone?: ControlTone;
|
|
22
|
+
id?: string;
|
|
23
|
+
class?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A read-only level meter: a continuous bar, or a row of segments that light in
|
|
27
|
+
* their tones as the level rises. The `meter` role, so it is announced with its
|
|
28
|
+
* value and range, not as a control.
|
|
29
|
+
*
|
|
30
|
+
* @throws {RangeError} When `min` or `max` is not finite, or `max` is not above
|
|
31
|
+
* `min`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function Meter(props: MeterProps): JSX.Element;
|
|
34
|
+
//# sourceMappingURL=meter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/preact/meter.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EACN,KAAK,YAAY,EAGjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG;IACxB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IACnC,gCAAgC;IAChC,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACxC,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAAC,OAAO,CAgDpD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { inverseLerp } from "@ac-kit/math-scalar";
|
|
3
|
+
import { meterAttributes, meterLitCount, } from "../meter/meter.js";
|
|
4
|
+
import { joinClasses } from "./join-classes.js";
|
|
5
|
+
/**
|
|
6
|
+
* A read-only level meter: a continuous bar, or a row of segments that light in
|
|
7
|
+
* their tones as the level rises. The `meter` role, so it is announced with its
|
|
8
|
+
* value and range, not as a control.
|
|
9
|
+
*
|
|
10
|
+
* @throws {RangeError} When `min` or `max` is not finite, or `max` is not above
|
|
11
|
+
* `min`.
|
|
12
|
+
*/
|
|
13
|
+
export function Meter(props) {
|
|
14
|
+
const { label, value, min, max, segments, orientation = "horizontal", valueText, tone, id, } = props;
|
|
15
|
+
const attributes = meterAttributes({ label, value, min, max, valueText });
|
|
16
|
+
const litCount = segments === undefined ? 0 : meterLitCount(value, segments);
|
|
17
|
+
return (_jsx("div", { ...attributes, id: id, class: joinClasses("ack-control ack-meter", props.class), "data-orientation": orientation, "data-tone": tone, style: {
|
|
18
|
+
"--ack-meter-fraction": inverseLerp(min, max, attributes["aria-valuenow"]),
|
|
19
|
+
}, children: segments === undefined ? (_jsx("div", { class: "ack-meter-bar", children: _jsx("div", { class: "ack-meter-fill" }) })) : (_jsx("div", { class: "ack-meter-segments", children: segments.map((segment, index) => (_jsx("span", { class: "ack-meter-segment", "data-tone": segment.tone, "data-lit": index < litCount ? "" : undefined }, index))) })) }));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=meter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/preact/meter.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAEN,eAAe,EACf,aAAa,GACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAwBhD;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,KAAiB;IACtC,MAAM,EACL,KAAK,EACL,KAAK,EACL,GAAG,EACH,GAAG,EACH,QAAQ,EACR,WAAW,GAAG,YAAY,EAC1B,SAAS,EACT,IAAI,EACJ,EAAE,GACF,GAAG,KAAK,CAAC;IACV,MAAM,UAAU,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1E,MAAM,QAAQ,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE7E,OAAO,CACN,iBACK,UAAU,EACd,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,WAAW,CAAC,uBAAuB,EAAE,KAAK,CAAC,KAAK,CAAC,sBACtC,WAAW,eAClB,IAAI,EACf,KAAK,EAAE;YACN,sBAAsB,EAAE,WAAW,CAClC,GAAG,EACH,GAAG,EACH,UAAU,CAAC,eAAe,CAAC,CAC3B;SACD,YAEA,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CACzB,cAAK,KAAK,EAAC,eAAe,YACzB,cAAK,KAAK,EAAC,gBAAgB,GAAG,GACzB,CACN,CAAC,CAAC,CAAC,CACH,cAAK,KAAK,EAAC,oBAAoB,YAC7B,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CACjC,eAEC,KAAK,EAAC,mBAAmB,eACd,OAAO,CAAC,IAAI,cACb,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,IAHtC,KAAK,CAIT,CACF,CAAC,GACG,CACN,GACI,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
3
|
+
import type { ControlTone } from "../tone.js";
|
|
4
|
+
/** One choice of a {@link RadioGroup}. */
|
|
5
|
+
export type RadioOption<Value extends string> = {
|
|
6
|
+
value: Value;
|
|
7
|
+
/** Its accessible name, drawn on it. */
|
|
8
|
+
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* A sentence under the label, linked by `aria-describedby`; drawn by the
|
|
11
|
+
* `cards` appearance.
|
|
12
|
+
*/
|
|
13
|
+
description?: string;
|
|
14
|
+
/** Drawn before the label, hidden from assistive technology. */
|
|
15
|
+
icon?: ComponentChildren;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** The colour it lights in while chosen. */
|
|
18
|
+
tone?: ControlTone;
|
|
19
|
+
};
|
|
20
|
+
/** Props of {@link RadioGroup}. */
|
|
21
|
+
export type RadioGroupProps<Value extends string> = {
|
|
22
|
+
/** The `<legend>`; visually hidden unless `isLabelShown`. */
|
|
23
|
+
label: string;
|
|
24
|
+
isLabelShown?: boolean;
|
|
25
|
+
options: readonly RadioOption<Value>[];
|
|
26
|
+
/** The chosen option; `undefined` for none yet. */
|
|
27
|
+
value: Value | undefined;
|
|
28
|
+
/** The option chosen: by a pointer, or an arrow key. */
|
|
29
|
+
onChange: Callable<[value: Value]>;
|
|
30
|
+
/** Side-by-side segments, or cards with descriptions. Defaults to `segmented`. */
|
|
31
|
+
appearance?: "segmented" | "cards";
|
|
32
|
+
/** Defaults to `horizontal`. */
|
|
33
|
+
orientation?: "horizontal" | "vertical";
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
/** The radios' `name`. Defaults to a generated id. */
|
|
36
|
+
name?: string;
|
|
37
|
+
id?: string;
|
|
38
|
+
class?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* One choice among a few, all shown at once: a segmented control, or a list of
|
|
42
|
+
* cards with descriptions. Native radios in a `<fieldset>`, so the browser
|
|
43
|
+
* provides the arrow keys (they move and choose), Tab leaving the group, and
|
|
44
|
+
* form participation.
|
|
45
|
+
*
|
|
46
|
+
* For more than about six options, use a select; for independent settings,
|
|
47
|
+
* switches.
|
|
48
|
+
*/
|
|
49
|
+
export declare function RadioGroup<Value extends string>(props: RadioGroupProps<Value>): JSX.Element;
|
|
50
|
+
//# sourceMappingURL=radio-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group.d.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AEF;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,MAAM,EAC9C,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,GAC3B,GAAG,CAAC,OAAO,CA8Fb"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useId, useRef } from "preact/hooks";
|
|
3
|
+
import { joinClasses } from "./join-classes.js";
|
|
4
|
+
import { useLatest } from "./use-element-binding.js";
|
|
5
|
+
/**
|
|
6
|
+
* One choice among a few, all shown at once: a segmented control, or a list of
|
|
7
|
+
* cards with descriptions. Native radios in a `<fieldset>`, so the browser
|
|
8
|
+
* provides the arrow keys (they move and choose), Tab leaving the group, and
|
|
9
|
+
* form participation.
|
|
10
|
+
*
|
|
11
|
+
* For more than about six options, use a select; for independent settings,
|
|
12
|
+
* switches.
|
|
13
|
+
*/
|
|
14
|
+
export function RadioGroup(props) {
|
|
15
|
+
const { label, isLabelShown = false, options, value, onChange, appearance = "segmented", orientation = "horizontal", disabled = false, id, } = props;
|
|
16
|
+
const generatedName = useId();
|
|
17
|
+
const group = useRef(null);
|
|
18
|
+
const latestValue = useLatest(value);
|
|
19
|
+
// The browser checks a radio before the caller answers; once the render the
|
|
20
|
+
// answer may cause has run, the native state follows `value` again.
|
|
21
|
+
const reconcile = () => {
|
|
22
|
+
queueMicrotask(() => {
|
|
23
|
+
for (const input of group.current?.querySelectorAll("input") ?? []) {
|
|
24
|
+
input.checked = input.value === latestValue.current;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const idPrefix = useId();
|
|
29
|
+
const name = props.name ?? generatedName;
|
|
30
|
+
return (_jsxs("fieldset", { ref: group, id: id, disabled: disabled, "data-appearance": appearance, "data-orientation": orientation, class: joinClasses("ack-control ack-radio-group", props.class), children: [_jsx("legend", { class: isLabelShown
|
|
31
|
+
? "ack-radio-group-legend"
|
|
32
|
+
: "ack-radio-group-legend ack-visually-hidden", children: label }), options.map((option, index) => {
|
|
33
|
+
const labelId = `${idPrefix}-${index}-label`;
|
|
34
|
+
const descriptionId = `${idPrefix}-${index}`;
|
|
35
|
+
const isChosen = option.value === value;
|
|
36
|
+
return (_jsxs("label", { class: "ack-control ack-radio", "data-state": isChosen ? "on" : "off", "data-tone": option.tone, "data-disabled": option.disabled === true ? "" : undefined, children: [_jsx("input", { type: "radio", class: "ack-radio-input", name: name, value: option.value, checked: isChosen, disabled: option.disabled, "aria-labelledby": labelId, "aria-describedby": option.description === undefined ? undefined : descriptionId, onChange: () => {
|
|
37
|
+
onChange(option.value);
|
|
38
|
+
reconcile();
|
|
39
|
+
} }), option.icon !== undefined && (_jsx("span", { class: "ack-radio-icon", "aria-hidden": "true", children: option.icon })), _jsxs("span", { class: "ack-radio-text", children: [_jsx("span", { id: labelId, class: "ack-radio-label", children: option.label }), option.description !== undefined && (_jsx("span", { id: descriptionId, class: "ack-radio-description", children: option.description }))] })] }, option.value));
|
|
40
|
+
})] }));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=radio-group.js.map
|