@ac-kit/ui-common 0.2.0 → 0.3.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 +55 -0
- package/README.md +59 -3
- package/dist/adapter/_anchor.d.ts.map +1 -0
- package/dist/adapter/_anchor.js.map +1 -0
- package/dist/adapter/_dom.d.ts.map +1 -0
- package/dist/adapter/_dom.js.map +1 -0
- package/dist/{preact → adapter}/_live-announcer.d.ts +1 -1
- package/dist/adapter/_live-announcer.d.ts.map +1 -0
- package/dist/{preact → adapter}/_live-announcer.js +1 -1
- package/dist/adapter/_live-announcer.js.map +1 -0
- package/dist/adapter/join-classes.d.ts.map +1 -0
- package/dist/adapter/join-classes.js.map +1 -0
- package/dist/bit-grid/bit-grid.d.ts +151 -0
- package/dist/bit-grid/bit-grid.d.ts.map +1 -0
- package/dist/bit-grid/bit-grid.js +201 -0
- package/dist/bit-grid/bit-grid.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/preact/bit-grid.d.ts +39 -0
- package/dist/preact/bit-grid.d.ts.map +1 -0
- package/dist/preact/bit-grid.js +72 -0
- package/dist/preact/bit-grid.js.map +1 -0
- package/dist/preact/button.d.ts.map +1 -1
- package/dist/preact/button.js +1 -1
- package/dist/preact/button.js.map +1 -1
- package/dist/preact/dialog.d.ts.map +1 -1
- package/dist/preact/dialog.js +1 -1
- package/dist/preact/dialog.js.map +1 -1
- package/dist/preact/index.d.ts +3 -1
- package/dist/preact/index.d.ts.map +1 -1
- package/dist/preact/index.js +3 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/knob.d.ts.map +1 -1
- package/dist/preact/knob.js +1 -1
- package/dist/preact/knob.js.map +1 -1
- package/dist/preact/menu-button.d.ts.map +1 -1
- package/dist/preact/menu-button.js +3 -3
- package/dist/preact/menu-button.js.map +1 -1
- package/dist/preact/meter.d.ts.map +1 -1
- package/dist/preact/meter.js +1 -1
- package/dist/preact/meter.js.map +1 -1
- package/dist/preact/progress-ring.d.ts.map +1 -1
- package/dist/preact/progress-ring.js +1 -1
- package/dist/preact/progress-ring.js.map +1 -1
- package/dist/preact/radio-group.d.ts.map +1 -1
- package/dist/preact/radio-group.js +1 -1
- package/dist/preact/radio-group.js.map +1 -1
- package/dist/preact/readout.d.ts.map +1 -1
- package/dist/preact/readout.js +1 -1
- package/dist/preact/readout.js.map +1 -1
- package/dist/preact/slider.d.ts.map +1 -1
- package/dist/preact/slider.js +1 -1
- package/dist/preact/slider.js.map +1 -1
- package/dist/preact/spin-button.d.ts.map +1 -1
- package/dist/preact/spin-button.js +2 -2
- package/dist/preact/spin-button.js.map +1 -1
- package/dist/preact/swatch-strip.d.ts +30 -0
- package/dist/preact/swatch-strip.d.ts.map +1 -0
- package/dist/preact/swatch-strip.js +17 -0
- package/dist/preact/swatch-strip.js.map +1 -0
- package/dist/preact/switch.js +1 -1
- package/dist/preact/switch.js.map +1 -1
- package/dist/preact/tabs.d.ts.map +1 -1
- package/dist/preact/tabs.js +2 -2
- package/dist/preact/tabs.js.map +1 -1
- package/dist/preact/toaster.d.ts.map +1 -1
- package/dist/preact/toaster.js +2 -2
- package/dist/preact/toaster.js.map +1 -1
- package/dist/preact/toggle-button.d.ts.map +1 -1
- package/dist/preact/toggle-button.js +1 -1
- package/dist/preact/toggle-button.js.map +1 -1
- package/dist/preact/toolbar.d.ts.map +1 -1
- package/dist/preact/toolbar.js +2 -2
- package/dist/preact/toolbar.js.map +1 -1
- package/dist/preact/tooltip.d.ts.map +1 -1
- package/dist/preact/tooltip.js +2 -2
- package/dist/preact/tooltip.js.map +1 -1
- package/dist/preact/tree.d.ts.map +1 -1
- package/dist/preact/tree.js +2 -2
- package/dist/preact/tree.js.map +1 -1
- package/dist/react/_props.d.ts +22 -0
- package/dist/react/_props.d.ts.map +1 -0
- package/dist/react/_props.js +14 -0
- package/dist/react/_props.js.map +1 -0
- package/dist/react/bit-grid.d.ts +40 -0
- package/dist/react/bit-grid.d.ts.map +1 -0
- package/dist/react/bit-grid.js +71 -0
- package/dist/react/bit-grid.js.map +1 -0
- package/dist/react/button.d.ts +60 -0
- package/dist/react/button.d.ts.map +1 -0
- package/dist/react/button.js +34 -0
- package/dist/react/button.js.map +1 -0
- package/dist/react/dialog.d.ts +44 -0
- package/dist/react/dialog.d.ts.map +1 -0
- package/dist/react/dialog.js +91 -0
- package/dist/react/dialog.js.map +1 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +22 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/knob.d.ts +55 -0
- package/dist/react/knob.d.ts.map +1 -0
- package/dist/react/knob.js +144 -0
- package/dist/react/knob.js.map +1 -0
- package/dist/react/menu-button.d.ts +147 -0
- package/dist/react/menu-button.d.ts.map +1 -0
- package/dist/react/menu-button.js +342 -0
- package/dist/react/menu-button.js.map +1 -0
- package/dist/react/meter.d.ts +34 -0
- package/dist/react/meter.d.ts.map +1 -0
- package/dist/react/meter.js +23 -0
- package/dist/react/meter.js.map +1 -0
- package/dist/react/progress-ring.d.ts +42 -0
- package/dist/react/progress-ring.d.ts.map +1 -0
- package/dist/react/progress-ring.js +28 -0
- package/dist/react/progress-ring.js.map +1 -0
- package/dist/react/radio-group.d.ts +52 -0
- package/dist/react/radio-group.d.ts.map +1 -0
- package/dist/react/radio-group.js +30 -0
- package/dist/react/radio-group.js.map +1 -0
- package/dist/react/readout.d.ts +23 -0
- package/dist/react/readout.d.ts.map +1 -0
- package/dist/react/readout.js +13 -0
- package/dist/react/readout.js.map +1 -0
- package/dist/react/slider.d.ts +44 -0
- package/dist/react/slider.d.ts.map +1 -0
- package/dist/react/slider.js +167 -0
- package/dist/react/slider.js.map +1 -0
- package/dist/react/spin-button.d.ts +71 -0
- package/dist/react/spin-button.d.ts.map +1 -0
- package/dist/react/spin-button.js +132 -0
- package/dist/react/spin-button.js.map +1 -0
- package/dist/react/swatch-strip.d.ts +31 -0
- package/dist/react/swatch-strip.d.ts.map +1 -0
- package/dist/react/swatch-strip.js +17 -0
- package/dist/react/swatch-strip.js.map +1 -0
- package/dist/react/switch.d.ts +26 -0
- package/dist/react/switch.d.ts.map +1 -0
- package/dist/react/switch.js +19 -0
- package/dist/react/switch.js.map +1 -0
- package/dist/react/tabs.d.ts +95 -0
- package/dist/react/tabs.d.ts.map +1 -0
- package/dist/react/tabs.js +274 -0
- package/dist/react/tabs.js.map +1 -0
- package/dist/react/toaster.d.ts +43 -0
- package/dist/react/toaster.d.ts.map +1 -0
- package/dist/react/toaster.js +368 -0
- package/dist/react/toaster.js.map +1 -0
- package/dist/react/toggle-button.d.ts +37 -0
- package/dist/react/toggle-button.d.ts.map +1 -0
- package/dist/react/toggle-button.js +22 -0
- package/dist/react/toggle-button.js.map +1 -0
- package/dist/react/toolbar.d.ts +25 -0
- package/dist/react/toolbar.d.ts.map +1 -0
- package/dist/react/toolbar.js +143 -0
- package/dist/react/toolbar.js.map +1 -0
- package/dist/react/tooltip.d.ts +68 -0
- package/dist/react/tooltip.d.ts.map +1 -0
- package/dist/react/tooltip.js +165 -0
- package/dist/react/tooltip.js.map +1 -0
- package/dist/react/tree.d.ts +94 -0
- package/dist/react/tree.d.ts.map +1 -0
- package/dist/react/tree.js +422 -0
- package/dist/react/tree.js.map +1 -0
- package/dist/react/use-element-binding.d.ts +35 -0
- package/dist/react/use-element-binding.d.ts.map +1 -0
- package/dist/react/use-element-binding.js +51 -0
- package/dist/react/use-element-binding.js.map +1 -0
- package/dist/swatch-strip/swatch-strip.d.ts +60 -0
- package/dist/swatch-strip/swatch-strip.d.ts.map +1 -0
- package/dist/swatch-strip/swatch-strip.js +60 -0
- package/dist/swatch-strip/swatch-strip.js.map +1 -0
- package/package.json +38 -15
- package/styles.css +191 -1
- package/dist/preact/_anchor.d.ts.map +0 -1
- package/dist/preact/_anchor.js.map +0 -1
- package/dist/preact/_dom.d.ts.map +0 -1
- package/dist/preact/_dom.js.map +0 -1
- package/dist/preact/_live-announcer.d.ts.map +0 -1
- package/dist/preact/_live-announcer.js.map +0 -1
- package/dist/preact/join-classes.d.ts.map +0 -1
- package/dist/preact/join-classes.js.map +0 -1
- /package/dist/{preact → adapter}/_anchor.d.ts +0 -0
- /package/dist/{preact → adapter}/_anchor.js +0 -0
- /package/dist/{preact → adapter}/_dom.d.ts +0 -0
- /package/dist/{preact → adapter}/_dom.js +0 -0
- /package/dist/{preact → adapter}/join-classes.d.ts +0 -0
- /package/dist/{preact → adapter}/join-classes.js +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { BIT_GRID_FIELD_TONES, bitGridAttributes, bitGridCellLabel, bitGridCells, bitGridKeyIndex, } from "../bit-grid/bit-grid.js";
|
|
4
|
+
import { classOf_ } from "./_props.js";
|
|
5
|
+
import { useLatest } from "./use-element-binding.js";
|
|
6
|
+
/**
|
|
7
|
+
* Bytes as a grid of bits or hex digits, with the cells that differ from a
|
|
8
|
+
* reference marked and named fields coloured. A WAI-ARIA `grid`: one tab stop,
|
|
9
|
+
* the arrows, Home and End move among the cells, and Enter or Space activates
|
|
10
|
+
* one when `onActivate` is given.
|
|
11
|
+
*
|
|
12
|
+
* @throws {RangeError} When a field is not a range of whole bytes inside
|
|
13
|
+
* `bytes`, two fields overlap, or `columns` is not a positive integer.
|
|
14
|
+
*/
|
|
15
|
+
export function BitGrid(props) {
|
|
16
|
+
const { label, bytes, unit = "bit", bitOrder, reference, fields = [], selectedIndex, onActivate, id, } = props;
|
|
17
|
+
const columns = props.columns ?? (unit === "bit" ? 32 : 16);
|
|
18
|
+
const cells = bitGridCells({ bytes, unit, bitOrder, reference, fields });
|
|
19
|
+
const attributes = bitGridAttributes({
|
|
20
|
+
label,
|
|
21
|
+
count: cells.length,
|
|
22
|
+
columns,
|
|
23
|
+
isActivatable: onActivate !== undefined,
|
|
24
|
+
});
|
|
25
|
+
const [focused, setFocused] = useState(undefined);
|
|
26
|
+
const grid = useRef(null);
|
|
27
|
+
const activate = useLatest(onActivate);
|
|
28
|
+
const tabStop = Math.min(focused ?? selectedIndex ?? 0, Math.max(cells.length - 1, 0));
|
|
29
|
+
const rows = [];
|
|
30
|
+
for (let start = 0; start < cells.length; start += columns) {
|
|
31
|
+
rows.push(cells.slice(start, start + columns));
|
|
32
|
+
}
|
|
33
|
+
const style = { "--ack-bit-grid-columns": columns };
|
|
34
|
+
return (_jsxs("div", { id: id, className: classOf_("ack-control ack-bit-grid", props), "data-unit": unit, style: style, children: [_jsx("div", { ...attributes, ref: grid, dir: "ltr", className: "ack-bit-grid-cells", onKeyDown: (event) => {
|
|
35
|
+
const index = Number(event.target.dataset["index"] ?? Number.NaN);
|
|
36
|
+
if (!Number.isSafeInteger(index)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
40
|
+
if (activate.current !== undefined) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
activate.current(index);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const next = bitGridKeyIndex(index, event.key, cells.length, columns, { ctrlKey: event.ctrlKey || event.metaKey });
|
|
47
|
+
if (next === undefined) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
setFocused(next);
|
|
52
|
+
grid.current
|
|
53
|
+
?.querySelector(`[data-index="${next}"]`)
|
|
54
|
+
?.focus();
|
|
55
|
+
}, onClick: (event) => {
|
|
56
|
+
const cell = event.target.closest("[data-index]");
|
|
57
|
+
const index = Number(cell?.dataset["index"] ?? Number.NaN);
|
|
58
|
+
if (!Number.isSafeInteger(index)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setFocused(index);
|
|
62
|
+
activate.current?.(index);
|
|
63
|
+
}, children: rows.map((row, rowIndex) => (_jsx("div", { role: "row", className: "ack-bit-grid-row", "aria-rowindex": rowIndex + 1, children: row.map((cell) => (_jsx("div", { role: "gridcell", className: "ack-bit-grid-cell", "aria-label": bitGridCellLabel(cell, fields), "aria-colindex": (cell.index % columns) + 1, "aria-selected": onActivate === undefined
|
|
64
|
+
? undefined
|
|
65
|
+
: cell.index === selectedIndex, tabIndex: cell.index === tabStop ? 0 : -1, "data-index": cell.index, "data-value": cell.value, "data-changed": cell.changed ? "" : undefined, "data-field-tone": cell.fieldTone, "data-byte-start": cell.bit === undefined || cell.index % 8 === 0
|
|
66
|
+
? ""
|
|
67
|
+
: undefined, onFocus: () => {
|
|
68
|
+
setFocused(cell.index);
|
|
69
|
+
}, children: cell.text }, cell.index))) }, rowIndex))) }), fields.length > 0 && (_jsx("ul", { className: "ack-bit-grid-legend", "aria-label": `${label}: fields`, children: fields.map((field, index) => (_jsx("li", { className: "ack-bit-grid-field", "data-field-tone": index % BIT_GRID_FIELD_TONES, children: field.label }, index))) }))] }));
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=bit-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bit-grid.js","sourceRoot":"","sources":["../../src/react/bit-grid.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAY,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EACN,oBAAoB,EAIpB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,eAAe,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAoB,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AA2BrD;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,KAAmB;IAC1C,MAAM,EACL,KAAK,EACL,KAAK,EACL,IAAI,GAAG,KAAK,EACZ,QAAQ,EACR,SAAS,EACT,MAAM,G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AC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACxB,CAAC,YAEA,IAAI,CAAC,IAAI,IAxBL,IAAI,CAAC,KAAK,CAyBV,CACN,CAAC,IAjCG,QAAQ,CAkCR,CACN,CAAC,GACG,EACL,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CACrB,aAAI,SAAS,EAAC,qBAAqB,gBAAa,GAAG,KAAK,UAAU,YAChE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAC7B,aAEC,SAAS,EAAC,oBAAoB,qBACb,KAAK,GAAG,oBAAoB,YAE5C,KAAK,CAAC,KAAK,IAJP,KAAK,CAKN,CACL,CAAC,GACE,CACL,IACI,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** @jsxImportSource react */
|
|
2
|
+
import { type ButtonHTMLAttributes, type ReactNode } from "react";
|
|
3
|
+
import { type ButtonSize, type ButtonVariant } from "../button/button.js";
|
|
4
|
+
import type { ControlTone } from "../tone.js";
|
|
5
|
+
import { type ClassProps_ } from "./_props.js";
|
|
6
|
+
/** Props of {@link Button}: its own, then any other `<button>` attribute. */
|
|
7
|
+
export type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "className"> & ClassProps_ & {
|
|
8
|
+
/** Defaults to `secondary`. */
|
|
9
|
+
variant?: ButtonVariant;
|
|
10
|
+
/** Defaults to `regular`. */
|
|
11
|
+
size?: ButtonSize;
|
|
12
|
+
tone?: ControlTone;
|
|
13
|
+
/** Drawn before the text, hidden from assistive technology. */
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
/** Its label. */
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A push button for an action: `primary` for the one main action of a view,
|
|
20
|
+
* `secondary` for the others, `ghost` for a bare one. A native button, so it
|
|
21
|
+
* takes focus and activates with Space and Enter; `type` defaults to `button`,
|
|
22
|
+
* so inside a form only `type="submit"` submits it. Its `ref` reaches the
|
|
23
|
+
* button.
|
|
24
|
+
*/
|
|
25
|
+
export declare const Button: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "className"> & ClassProps_ & {
|
|
26
|
+
/** Defaults to `secondary`. */
|
|
27
|
+
variant?: ButtonVariant;
|
|
28
|
+
/** Defaults to `regular`. */
|
|
29
|
+
size?: ButtonSize;
|
|
30
|
+
tone?: ControlTone;
|
|
31
|
+
/** Drawn before the text, hidden from assistive technology. */
|
|
32
|
+
icon?: ReactNode;
|
|
33
|
+
/** Its label. */
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
36
|
+
/** Props of {@link IconButton}: its own, then any other `<button>` attribute. */
|
|
37
|
+
export type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "className" | "aria-label" | "children"> & ClassProps_ & {
|
|
38
|
+
/** Its accessible name, also its tooltip. */
|
|
39
|
+
label: string;
|
|
40
|
+
/** Defaults to `secondary`. */
|
|
41
|
+
variant?: ButtonVariant;
|
|
42
|
+
tone?: ControlTone;
|
|
43
|
+
/** The icon, hidden from assistive technology: `label` names the button. */
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A button drawn as an icon alone, named by `label`: transport controls, a
|
|
48
|
+
* close button. Takes the touch target's full size around a small icon. Its
|
|
49
|
+
* `ref` reaches the button.
|
|
50
|
+
*/
|
|
51
|
+
export declare const IconButton: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "aria-label" | "children" | "className"> & ClassProps_ & {
|
|
52
|
+
/** Its accessible name, also its tooltip. */
|
|
53
|
+
label: string;
|
|
54
|
+
/** Defaults to `secondary`. */
|
|
55
|
+
variant?: ButtonVariant;
|
|
56
|
+
tone?: ControlTone;
|
|
57
|
+
/** The icon, hidden from assistive technology: `label` names the button. */
|
|
58
|
+
children: ReactNode;
|
|
59
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
60
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/react/button.tsx"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EACN,KAAK,oBAAoB,EAGzB,KAAK,SAAS,EAEd,MAAM,OAAO,CAAC;AAEf,OAAO,EACN,KAAK,UAAU,EACf,KAAK,aAAa,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,aAAa,CAAC;AAEzD,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,IAAI,CAC7B,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,WAAW,CACX,GACA,WAAW,GAAG;IACb,+BAA+B;IAC/B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,iBAAiB;IACjB,QAAQ,EAAE,SAAS,CAAC;CACpB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;IAlBjB,+BAA+B;cACrB,aAAa;IACvB,6BAA6B;WACtB,UAAU;WACV,WAAW;IAClB,+DAA+D;WACxD,SAAS;IAChB,iBAAiB;cACP,SAAS;qDAUoD,CAAC;AAoC1E,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,WAAW,GAAG,YAAY,GAAG,UAAU,CACvC,GACA,WAAW,GAAG;IACb,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,4EAA4E;IAC5E,QAAQ,EAAE,SAAS,CAAC;CACpB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU;IAdrB,6CAA6C;WACtC,MAAM;IACb,+BAA+B;cACrB,aAAa;WAChB,WAAW;IAClB,4EAA4E;cAClE,SAAS;qDAUpB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** @jsxImportSource react */
|
|
3
|
+
import { forwardRef, } from "react";
|
|
4
|
+
import { buttonAttributes, } from "../button/button.js";
|
|
5
|
+
import { classOf_ } from "./_props.js";
|
|
6
|
+
/**
|
|
7
|
+
* A push button for an action: `primary` for the one main action of a view,
|
|
8
|
+
* `secondary` for the others, `ghost` for a bare one. A native button, so it
|
|
9
|
+
* takes focus and activates with Space and Enter; `type` defaults to `button`,
|
|
10
|
+
* so inside a form only `type="submit"` submits it. Its `ref` reaches the
|
|
11
|
+
* button.
|
|
12
|
+
*/
|
|
13
|
+
export const Button = forwardRef(Button_);
|
|
14
|
+
function Button_(props, ref) {
|
|
15
|
+
const { variant, size, tone, icon, children, class: extra, className, type = "button", ...rest } = props;
|
|
16
|
+
return (_jsxs("button", { ...rest, ...buttonAttributes({ variant, size, tone }), ref: ref, type: type, className: classOf_("ack-control ack-button", {
|
|
17
|
+
class: extra,
|
|
18
|
+
className,
|
|
19
|
+
}), children: [icon !== undefined && (_jsx("span", { className: "ack-button-icon", "aria-hidden": "true", children: icon })), children] }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A button drawn as an icon alone, named by `label`: transport controls, a
|
|
23
|
+
* close button. Takes the touch target's full size around a small icon. Its
|
|
24
|
+
* `ref` reaches the button.
|
|
25
|
+
*/
|
|
26
|
+
export const IconButton = forwardRef(IconButton_);
|
|
27
|
+
function IconButton_(props, ref) {
|
|
28
|
+
const { label, variant, tone, children, class: extra, className, type = "button", ...rest } = props;
|
|
29
|
+
return (_jsx("button", { title: label, ...rest, ...buttonAttributes({ variant, tone }), ref: ref, type: type, "aria-label": label, className: classOf_("ack-control ack-button ack-icon-button", {
|
|
30
|
+
class: extra,
|
|
31
|
+
className,
|
|
32
|
+
}), children: _jsx("span", { className: "ack-button-icon", "aria-hidden": "true", children: children }) }));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/react/button.tsx"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,OAAO,EAEN,UAAU,GAIV,MAAM,OAAO,CAAC;AAEf,OAAO,EAGN,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAoB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAmBzD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAiC,OAAO,CAAC,CAAC;AAE1E,SAAS,OAAO,CAAC,KAAkB,EAAE,GAA2B;IAC/D,MAAM,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,SAAS,EACT,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,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,QAAQ,CAAC,wBAAwB,EAAE;YAC7C,KAAK,EAAE,KAAK;YACZ,SAAS;SACT,CAAC,aAED,IAAI,KAAK,SAAS,IAAI,CACtB,eAAM,SAAS,EAAC,iBAAiB,iBAAa,MAAM,YAClD,IAAI,GACC,CACP,EACA,QAAQ,IACD,CACT,CAAC;AACH,CAAC;AAiBD;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CACnC,WAAW,CACX,CAAC;AAEF,SAAS,WAAW,CACnB,KAAsB,EACtB,GAA2B;IAE3B,MAAM,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,SAAS,EACT,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,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,gBACE,KAAK,EACjB,SAAS,EAAE,QAAQ,CAAC,wCAAwC,EAAE;YAC7D,KAAK,EAAE,KAAK;YACZ,SAAS;SACT,CAAC,YAEF,eAAM,SAAS,EAAC,iBAAiB,iBAAa,MAAM,YAClD,QAAQ,GACH,GACC,CACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** @jsxImportSource react */
|
|
2
|
+
import type { CallableNoArgs } from "@ac-kit/core";
|
|
3
|
+
import { type JSX, type ReactNode } from "react";
|
|
4
|
+
import { type DialogPlacement } from "../dialog/dialog.js";
|
|
5
|
+
import { type ClassProps_ } from "./_props.js";
|
|
6
|
+
/** Props of {@link Dialog}. */
|
|
7
|
+
export type DialogProps = ClassProps_ & {
|
|
8
|
+
title: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Asked to close: Escape, the close button, a backdrop click when
|
|
13
|
+
* dismissible, or a `<form method="dialog">` submitted. Called once, after
|
|
14
|
+
* the dialog has closed; set `isOpen` to false in answer.
|
|
15
|
+
*/
|
|
16
|
+
onClose: CallableNoArgs;
|
|
17
|
+
/** Defaults to `center`. */
|
|
18
|
+
placement?: DialogPlacement;
|
|
19
|
+
/** Escape and a backdrop click close it. Defaults to true. */
|
|
20
|
+
isDismissible?: boolean;
|
|
21
|
+
/** The close button's accessible name; without it, no close button is drawn. */
|
|
22
|
+
closeLabel?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The close button's icon. Defaults to a drawn ×, hidden from assistive
|
|
25
|
+
* technology.
|
|
26
|
+
*/
|
|
27
|
+
closeIcon?: ReactNode;
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
/** A footer row of actions. */
|
|
30
|
+
actions?: ReactNode;
|
|
31
|
+
id?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A modal dialog on a native `<dialog>`: the rest of the page is inert, Escape
|
|
35
|
+
* closes it when dismissible, and focus returns to the opener. Rendered in
|
|
36
|
+
* place, with no portal: the top layer lifts it above the page.
|
|
37
|
+
*
|
|
38
|
+
* A press that starts and ends on the backdrop closes it too, a text selection
|
|
39
|
+
* dragged out of the panel does not.
|
|
40
|
+
*
|
|
41
|
+
* Keep `isOpen` the single source of truth: set it false in `onClose`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function Dialog(props: DialogProps): JSX.Element;
|
|
44
|
+
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/react/dialog.tsx"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACN,KAAK,GAAG,EACR,KAAK,SAAS,EAId,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,aAAa,CAAC;AAGzD,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACvC,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,SAAS,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAiJtD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useLayoutEffect, useRef, } from "react";
|
|
3
|
+
import { dialogAttributes } from "../dialog/dialog.js";
|
|
4
|
+
import { classOf_ } from "./_props.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
|
+
return () => {
|
|
49
|
+
if (element?.open !== true) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
pendingCloses.current += 1;
|
|
53
|
+
element.close();
|
|
54
|
+
if (opener.current?.isConnected === true) {
|
|
55
|
+
opener.current.focus();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}, []);
|
|
59
|
+
return (_jsx("dialog", { ...dialogAttributes({
|
|
60
|
+
titleId,
|
|
61
|
+
descriptionId: description === undefined ? undefined : descriptionId,
|
|
62
|
+
placement,
|
|
63
|
+
}), id: id, ref: dialog, closedby: isDismissible ? "closerequest" : "none", className: classOf_("ack-dialog", props), onCancel: (event) => {
|
|
64
|
+
if (!isDismissible) {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
}
|
|
67
|
+
}, onClose: () => {
|
|
68
|
+
if (pendingCloses.current > 0) {
|
|
69
|
+
pendingCloses.current -= 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
latestOnClose.current();
|
|
73
|
+
}, onPointerDown: (event) => {
|
|
74
|
+
isPressOnBackdrop.current = event.target === event.currentTarget;
|
|
75
|
+
}, onPointerUp: (event) => {
|
|
76
|
+
// A touch's implicit capture retargets its release to the dialog
|
|
77
|
+
// wherever it ends: hit-test where it ends instead.
|
|
78
|
+
const released = document.elementFromPoint(event.clientX, event.clientY);
|
|
79
|
+
if (event.target !== event.currentTarget ||
|
|
80
|
+
released !== event.currentTarget) {
|
|
81
|
+
isPressOnBackdrop.current = false;
|
|
82
|
+
}
|
|
83
|
+
}, onClick: (event) => {
|
|
84
|
+
const isBackdropClick = isPressOnBackdrop.current && event.target === event.currentTarget;
|
|
85
|
+
isPressOnBackdrop.current = false;
|
|
86
|
+
if (isBackdropClick && isDismissible) {
|
|
87
|
+
event.currentTarget.close();
|
|
88
|
+
}
|
|
89
|
+
}, children: _jsxs("div", { className: "ack-dialog-panel", children: [_jsxs("div", { className: "ack-dialog-header", children: [_jsx("h2", { id: titleId, className: "ack-dialog-title", children: title }), closeLabel !== undefined && (_jsx("button", { type: "button", className: "ack-control ack-dialog-close", "aria-label": closeLabel, title: closeLabel, onClick: () => dialog.current?.close(), children: _jsx("span", { className: "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, className: "ack-dialog-description", children: description })), _jsx("div", { className: "ack-dialog-body", children: children }), actions !== undefined && (_jsx("div", { className: "ack-dialog-actions", children: actions }))] }) }));
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/react/dialog.tsx"],"names":[],"mappings":";AAEA,OAAO,EAG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uB,iBAAa,MAAM,YACxD,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,SAAS,EAAC,wBAAwB,YACtD,WAAW,GACT,CACJ,EACD,cAAK,SAAS,EAAC,iBAAiB,YAAE,QAAQ,GAAO,EAChD,OAAO,KAAK,SAAS,IAAI,CACzB,cAAK,SAAS,EAAC,oBAAoB,YAAE,OAAO,GAAO,CACnD,IACI,GACE,CACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "../adapter/join-classes.js";
|
|
2
|
+
export * from "./bit-grid.js";
|
|
3
|
+
export * from "./button.js";
|
|
4
|
+
export * from "./dialog.js";
|
|
5
|
+
export * from "./knob.js";
|
|
6
|
+
export * from "./menu-button.js";
|
|
7
|
+
export * from "./meter.js";
|
|
8
|
+
export * from "./progress-ring.js";
|
|
9
|
+
export * from "./radio-group.js";
|
|
10
|
+
export * from "./readout.js";
|
|
11
|
+
export * from "./slider.js";
|
|
12
|
+
export * from "./spin-button.js";
|
|
13
|
+
export * from "./swatch-strip.js";
|
|
14
|
+
export * from "./switch.js";
|
|
15
|
+
export * from "./tabs.js";
|
|
16
|
+
export * from "./toaster.js";
|
|
17
|
+
export * from "./toggle-button.js";
|
|
18
|
+
export * from "./toolbar.js";
|
|
19
|
+
export * from "./tooltip.js";
|
|
20
|
+
export * from "./tree.js";
|
|
21
|
+
export * from "./use-element-binding.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "../adapter/join-classes.js";
|
|
2
|
+
export * from "./bit-grid.js";
|
|
3
|
+
export * from "./button.js";
|
|
4
|
+
export * from "./dialog.js";
|
|
5
|
+
export * from "./knob.js";
|
|
6
|
+
export * from "./menu-button.js";
|
|
7
|
+
export * from "./meter.js";
|
|
8
|
+
export * from "./progress-ring.js";
|
|
9
|
+
export * from "./radio-group.js";
|
|
10
|
+
export * from "./readout.js";
|
|
11
|
+
export * from "./slider.js";
|
|
12
|
+
export * from "./spin-button.js";
|
|
13
|
+
export * from "./swatch-strip.js";
|
|
14
|
+
export * from "./switch.js";
|
|
15
|
+
export * from "./tabs.js";
|
|
16
|
+
export * from "./toaster.js";
|
|
17
|
+
export * from "./toggle-button.js";
|
|
18
|
+
export * from "./toolbar.js";
|
|
19
|
+
export * from "./tooltip.js";
|
|
20
|
+
export * from "./tree.js";
|
|
21
|
+
export * from "./use-element-binding.js";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** @jsxImportSource react */
|
|
2
|
+
import type { Callable, CallableNoArgs } from "@ac-kit/core";
|
|
3
|
+
import { type JSX } from "react";
|
|
4
|
+
import type { ControlTone } from "../tone.js";
|
|
5
|
+
import { type ClassProps_ } from "./_props.js";
|
|
6
|
+
/** Props of {@link Knob}. */
|
|
7
|
+
export type KnobProps = ClassProps_ & {
|
|
8
|
+
/** Its accessible name, also drawn under it. */
|
|
9
|
+
label: string;
|
|
10
|
+
value: number;
|
|
11
|
+
min: number;
|
|
12
|
+
max: number;
|
|
13
|
+
/** Defaults to 1. */
|
|
14
|
+
step?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The value a double tap goes back to. Without one, a double tap is two taps,
|
|
17
|
+
* and a tap requests entry at once instead of after the double-tap interval.
|
|
18
|
+
*/
|
|
19
|
+
resetValue?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The value the lit arc grows from. Defaults to `min`; a bipolar knob (pan,
|
|
22
|
+
* detune) gives its centre.
|
|
23
|
+
*/
|
|
24
|
+
origin?: number;
|
|
25
|
+
tone?: ControlTone;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/** The value as a person reads it, shown and announced. Defaults to `String`. */
|
|
28
|
+
format?: Callable<[value: number], string>;
|
|
29
|
+
/**
|
|
30
|
+
* A new value, once per gesture: at a drag's end, a key, a double tap. Not
|
|
31
|
+
* React's `onChange` of a form field, which fires at every input.
|
|
32
|
+
*/
|
|
33
|
+
onChange: Callable<[value: number]>;
|
|
34
|
+
/** The value following a drag, before it is committed through `onChange`. */
|
|
35
|
+
onInput?: Callable<[value: number]>;
|
|
36
|
+
/**
|
|
37
|
+
* A tap, or Enter or Space while focused: the person wants to type or pick a
|
|
38
|
+
* value. Open your own surface for it — a dialog, a sheet, a large `Slider` —
|
|
39
|
+
* and report its result through `onChange`.
|
|
40
|
+
*/
|
|
41
|
+
onRequestEntry?: CallableNoArgs;
|
|
42
|
+
id?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A rotary control, as on a synthesizer: drag up or down to turn it (not
|
|
46
|
+
* around, which hides it under a finger), with Shift for fine control; tap it
|
|
47
|
+
* to request value entry; double-tap to reset it. Focused, the arrow keys step
|
|
48
|
+
* it, Page Up and Page Down by ten steps, Home and End to the ends. It reports
|
|
49
|
+
* a value once a gesture ends.
|
|
50
|
+
*
|
|
51
|
+
* For a compact panel of sound or tempo controls; a setting with room to spare
|
|
52
|
+
* reads better as a `Slider`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function Knob(props: KnobProps): JSX.Element;
|
|
55
|
+
//# sourceMappingURL=knob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knob.d.ts","sourceRoot":"","sources":["../../src/react/knob.tsx"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG7D,OAAO,EAAE,KAAK,GAAG,EAAwC,MAAM,OAAO,CAAC;AAavE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,aAAa,CAAC;AAGzD,6BAA6B;AAC7B,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IACrC,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;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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;;;OAGG;IACH,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;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC;AAsBF;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAAC,OAAO,CA0LlD"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { bindPressGesture } from "@ac-kit/ui-gesture/dom";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
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 { classOf_ } from "./_props.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 latest = useLatest({
|
|
35
|
+
range,
|
|
36
|
+
value,
|
|
37
|
+
resetValue,
|
|
38
|
+
disabled,
|
|
39
|
+
onChange,
|
|
40
|
+
onInput,
|
|
41
|
+
onRequestEntry,
|
|
42
|
+
});
|
|
43
|
+
const shown = clampedSliderValue_(dragged ?? value, range);
|
|
44
|
+
const angles = knobAngles(shown, range, { origin });
|
|
45
|
+
const hasReset = resetValue !== undefined;
|
|
46
|
+
const commit = (next) => {
|
|
47
|
+
const { range, value, onChange } = latest.current;
|
|
48
|
+
const snapped = snapSliderValue(next, range);
|
|
49
|
+
if (snapped !== value) {
|
|
50
|
+
onChange(snapped);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const endDrag = () => {
|
|
54
|
+
drag.current = undefined;
|
|
55
|
+
setDragged(undefined);
|
|
56
|
+
};
|
|
57
|
+
const valueAt = (current, update) => knobDragValue(current.startValue, -update.movementY, latest.current.range, {
|
|
58
|
+
isFine: update.phase === "end" ? current.isFine : update.shiftKey,
|
|
59
|
+
});
|
|
60
|
+
const onDrag = (update) => {
|
|
61
|
+
const current = drag.current;
|
|
62
|
+
if (current === undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (update.phase === "cancel" || latest.current.disabled) {
|
|
66
|
+
endDrag();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const next = valueAt(current, update);
|
|
70
|
+
if (next !== (current.value ?? current.startValue)) {
|
|
71
|
+
latest.current.onInput?.(next);
|
|
72
|
+
}
|
|
73
|
+
if (update.phase === "end") {
|
|
74
|
+
// The release point decides, not the last move.
|
|
75
|
+
endDrag();
|
|
76
|
+
commit(next);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
current.value = next;
|
|
80
|
+
current.isFine = update.shiftKey;
|
|
81
|
+
setDragged(next);
|
|
82
|
+
};
|
|
83
|
+
const root = useElementBinding((element, signal) => {
|
|
84
|
+
const bound = bindPressGesture(element, {
|
|
85
|
+
onPress: () => {
|
|
86
|
+
drag.current = {
|
|
87
|
+
startValue: latest.current.value,
|
|
88
|
+
value: undefined,
|
|
89
|
+
isFine: false,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
onDrag,
|
|
93
|
+
// A tap settles after the double-tap window, which a disabling can
|
|
94
|
+
// fall in.
|
|
95
|
+
onTap: () => {
|
|
96
|
+
if (!latest.current.disabled) {
|
|
97
|
+
latest.current.onRequestEntry?.();
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
onDoubleTap: () => {
|
|
101
|
+
const { resetValue, disabled } = latest.current;
|
|
102
|
+
if (resetValue !== undefined && !disabled) {
|
|
103
|
+
commit(resetValue);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
}, {
|
|
107
|
+
doubleTap: hasReset,
|
|
108
|
+
touchAction: "none",
|
|
109
|
+
accept: () => !latest.current.disabled,
|
|
110
|
+
signal,
|
|
111
|
+
});
|
|
112
|
+
// A rebinding mid-drag drops the drag with the old binding, and one that
|
|
113
|
+
// disabling causes also drops a tap pending in the double-tap window.
|
|
114
|
+
return {
|
|
115
|
+
[Symbol.dispose]() {
|
|
116
|
+
bound[Symbol.dispose]();
|
|
117
|
+
endDrag();
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}, [hasReset, disabled]);
|
|
121
|
+
const onKeyDown = (event) => {
|
|
122
|
+
if (disabled) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const next = steppedValue(clampedSliderValue_(value, range), event.key, range);
|
|
126
|
+
if (next !== undefined) {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
commit(next);
|
|
129
|
+
}
|
|
130
|
+
else if ((event.key === "Enter" || event.key === " ") &&
|
|
131
|
+
onRequestEntry !== undefined) {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
onRequestEntry();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return (_jsxs("div", { ...sliderAttributes({
|
|
137
|
+
label,
|
|
138
|
+
value: shown,
|
|
139
|
+
range,
|
|
140
|
+
valueText: format(shown),
|
|
141
|
+
disabled,
|
|
142
|
+
}), ref: root, id: id, className: classOf_("ack-control ack-knob", props), "data-tone": tone, "data-dragging": dragged === undefined ? undefined : "", tabIndex: disabled ? -1 : 0, onKeyDown: onKeyDown, children: [_jsxs("svg", { className: "ack-knob-dial", viewBox: "0 0 52 52", "aria-hidden": "true", children: [_jsx("path", { className: "ack-knob-track", d: TRACK_PATH_ }), angles.arcTo - angles.arcFrom > MIN_ARC_DEGREES_ && (_jsx("path", { className: "ack-knob-arc", d: knobArcPath(DIAL_, angles.arcFrom, angles.arcTo) })), _jsx("circle", { className: "ack-knob-cap", cx: DIAL_.centerX, cy: DIAL_.centerY, r: CAP_RADIUS_ }), _jsx("line", { className: "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", { className: "ack-knob-value", children: format(shown) }), _jsx("span", { className: "ack-knob-label", children: label })] }));
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=knob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knob.js","sourceRoot":"","sources":["../../src/react/knob.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAgC,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEvE,OAAO,EACN,QAAQ,EAER,UAAU,EACV,WAAW,EACX,aAAa,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAoB,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAoB,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,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