@arshad-shah/cynosure 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/README.md +3 -3
- package/dist/components/Accordion/Accordion.d.ts +14 -0
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Announcer/Announcer.d.ts +1 -0
- package/dist/components/Announcer/Announcer.js.map +1 -1
- package/dist/components/AppShell/AppShell.d.ts +22 -1
- package/dist/components/AppShell/AppShell.js +95 -83
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/AppShell/index.d.ts +1 -1
- package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
- package/dist/components/AspectRatio/AspectRatio.js +21 -0
- package/dist/components/AspectRatio/AspectRatio.js.map +1 -0
- package/dist/components/AspectRatio/index.d.ts +1 -0
- package/dist/components/Avatar/Avatar.d.ts +96 -0
- package/dist/components/Avatar/Avatar.js +90 -0
- package/dist/components/Avatar/Avatar.js.map +1 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +55 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +85 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -0
- package/dist/components/Breadcrumbs/index.d.ts +1 -0
- package/dist/components/Button/Button.d.ts +13 -2
- package/dist/components/Button/Button.js +28 -26
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.d.ts +65 -7
- package/dist/components/Calendar/Calendar.js +207 -95
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Calendar/dates.d.ts +4 -0
- package/dist/components/Calendar/dates.js +41 -27
- package/dist/components/Calendar/dates.js.map +1 -1
- package/dist/components/Calendar/index.d.ts +1 -1
- package/dist/components/Card/Card.d.ts +27 -0
- package/dist/components/Card/Card.js +48 -36
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Card/index.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.d.ts +8 -1
- package/dist/components/Checkbox/Checkbox.js +7 -6
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Checkbox/ChoiceRow.d.ts +17 -1
- package/dist/components/Checkbox/ChoiceRow.js +19 -18
- package/dist/components/Checkbox/ChoiceRow.js.map +1 -1
- package/dist/components/Checklist/Checklist.d.ts +65 -0
- package/dist/components/Checklist/Checklist.js +163 -0
- package/dist/components/Checklist/Checklist.js.map +1 -0
- package/dist/components/Checklist/index.d.ts +1 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +5 -0
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/ColorField/ColorField.d.ts +12 -0
- package/dist/components/ColorField/ColorField.js +19 -19
- package/dist/components/ColorField/ColorField.js.map +1 -1
- package/dist/components/ColorSwatches/ColorSwatches.d.ts +5 -0
- package/dist/components/ColorSwatches/ColorSwatches.js +6 -6
- package/dist/components/ColorSwatches/ColorSwatches.js.map +1 -1
- package/dist/components/Combobox/Combobox.d.ts +20 -1
- package/dist/components/Combobox/Combobox.js +38 -34
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/CommandPalette/CommandPalette.d.ts +9 -0
- package/dist/components/CommandPalette/CommandPalette.js +10 -10
- package/dist/components/CommandPalette/CommandPalette.js.map +1 -1
- package/dist/components/CompareSlider/CompareSlider.d.ts +4 -0
- package/dist/components/CompareSlider/CompareSlider.js +4 -4
- package/dist/components/CompareSlider/CompareSlider.js.map +1 -1
- package/dist/components/Container/Container.d.ts +44 -0
- package/dist/components/Container/Container.js +24 -0
- package/dist/components/Container/Container.js.map +1 -0
- package/dist/components/Container/index.d.ts +1 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +11 -0
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.d.ts +8 -0
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DateField/DateField.d.ts +17 -0
- package/dist/components/DateField/DateField.js +6 -6
- package/dist/components/DateField/DateField.js.map +1 -1
- package/dist/components/DescriptionList/DescriptionList.d.ts +3 -0
- package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +16 -2
- package/dist/components/Dialog/Dialog.js +82 -70
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/Disclosure/Disclosure.d.ts +7 -0
- package/dist/components/Disclosure/Disclosure.js.map +1 -1
- package/dist/components/Divider/Divider.d.ts +59 -0
- package/dist/components/Divider/Divider.js +32 -0
- package/dist/components/Divider/Divider.js.map +1 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/DocumentViewport/DocumentViewport.d.ts +8 -0
- package/dist/components/DocumentViewport/DocumentViewport.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.d.ts +3 -0
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/Field/Field.d.ts +6 -0
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/FileDrop/FileDrop.d.ts +8 -0
- package/dist/components/FileDrop/FileDrop.js.map +1 -1
- package/dist/components/FloatingToolbar/FloatingToolbar.d.ts +4 -0
- package/dist/components/FloatingToolbar/FloatingToolbar.js +4 -4
- package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
- package/dist/components/Grid/Grid.d.ts +33 -7
- package/dist/components/Grid/Grid.js +46 -25
- package/dist/components/Grid/Grid.js.map +1 -1
- package/dist/components/Grid/index.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +57 -0
- package/dist/components/Heading/Heading.js +33 -0
- package/dist/components/Heading/Heading.js.map +1 -0
- package/dist/components/Heading/index.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/components/IconButton/IconButton.d.ts +1 -0
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/Image/Image.d.ts +62 -0
- package/dist/components/Image/Image.js +75 -0
- package/dist/components/Image/Image.js.map +1 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Inline/Inline.d.ts +7 -3
- package/dist/components/Inline/Inline.js +19 -13
- package/dist/components/Inline/Inline.js.map +1 -1
- package/dist/components/Kbd/Kbd.d.ts +2 -0
- package/dist/components/Kbd/Kbd.js.map +1 -1
- package/dist/components/KeyValueEditor/KeyValueEditor.d.ts +7 -0
- package/dist/components/KeyValueEditor/KeyValueEditor.js +8 -8
- package/dist/components/KeyValueEditor/KeyValueEditor.js.map +1 -1
- package/dist/components/Link/Link.d.ts +7 -0
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/LoadingDots/LoadingDots.d.ts +2 -0
- package/dist/components/LoadingDots/LoadingDots.js.map +1 -1
- package/dist/components/Menu/Menu.d.ts +13 -1
- package/dist/components/Menu/Menu.js +37 -35
- package/dist/components/Menu/Menu.js.map +1 -1
- package/dist/components/Notice/Notice.d.ts +5 -0
- package/dist/components/Notice/Notice.js.map +1 -1
- package/dist/components/NumberField/NumberField.d.ts +17 -0
- package/dist/components/NumberField/NumberField.js +8 -8
- package/dist/components/NumberField/NumberField.js.map +1 -1
- package/dist/components/PageHeader/PageHeader.d.ts +61 -0
- package/dist/components/PageHeader/PageHeader.js +63 -0
- package/dist/components/PageHeader/PageHeader.js.map +1 -0
- package/dist/components/PageHeader/index.d.ts +1 -0
- package/dist/components/Pagination/Pagination.d.ts +77 -0
- package/dist/components/Pagination/Pagination.js +120 -0
- package/dist/components/Pagination/Pagination.js.map +1 -0
- package/dist/components/Pagination/index.d.ts +1 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.d.ts +4 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.js.map +1 -1
- package/dist/components/Popover/Popover.d.ts +10 -0
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +5 -0
- package/dist/components/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/components/ProgressOverlay/ProgressOverlay.d.ts +3 -0
- package/dist/components/ProgressOverlay/ProgressOverlay.js.map +1 -1
- package/dist/components/Prose/Prose.d.ts +1 -0
- package/dist/components/Prose/Prose.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +13 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +9 -0
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.d.ts +18 -1
- package/dist/components/Select/Select.js +97 -88
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/SelectionFrame/SelectionFrame.d.ts +6 -0
- package/dist/components/SelectionFrame/SelectionFrame.js.map +1 -1
- package/dist/components/SideNav/SideNav.d.ts +37 -1
- package/dist/components/SideNav/SideNav.js +100 -73
- package/dist/components/SideNav/SideNav.js.map +1 -1
- package/dist/components/SideNav/index.d.ts +1 -1
- package/dist/components/SignaturePad/SignaturePad.d.ts +3 -0
- package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
- package/dist/components/Skeleton/Skeleton.d.ts +1 -0
- package/dist/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/components/Slider/Slider.d.ts +11 -0
- package/dist/components/Slider/Slider.js +6 -6
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/SortableList/SortableList.d.ts +6 -0
- package/dist/components/SortableList/SortableList.js.map +1 -1
- package/dist/components/SplitPane/SplitPane.d.ts +5 -0
- package/dist/components/SplitPane/SplitPane.js +4 -4
- package/dist/components/SplitPane/SplitPane.js.map +1 -1
- package/dist/components/Stack/Stack.d.ts +7 -3
- package/dist/components/Stack/Stack.js +18 -12
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/index.d.ts +1 -0
- package/dist/components/Stack/space.d.ts +18 -0
- package/dist/components/Stack/space.js +12 -0
- package/dist/components/Stack/space.js.map +1 -0
- package/dist/components/Steps/Steps.d.ts +4 -0
- package/dist/components/Steps/Steps.js.map +1 -1
- package/dist/components/Table/Table.d.ts +12 -0
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +14 -0
- package/dist/components/Tabs/Tabs.js +4 -4
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TagInput/TagInput.d.ts +18 -0
- package/dist/components/TagInput/TagInput.js +5 -5
- package/dist/components/TagInput/TagInput.js.map +1 -1
- package/dist/components/Text/Text.d.ts +72 -0
- package/dist/components/Text/Text.js +30 -0
- package/dist/components/Text/Text.js.map +1 -0
- package/dist/components/Text/index.d.ts +1 -0
- package/dist/components/TextArea/TextArea.d.ts +10 -0
- package/dist/components/TextArea/TextArea.js +4 -4
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +13 -0
- package/dist/components/TextField/TextField.js +4 -4
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/ThemeToggle/ThemeToggle.d.ts +4 -0
- package/dist/components/ThemeToggle/ThemeToggle.js.map +1 -1
- package/dist/components/TimeField/TimeField.d.ts +62 -8
- package/dist/components/TimeField/TimeField.js +308 -72
- package/dist/components/TimeField/TimeField.js.map +1 -1
- package/dist/components/Toast/Toast.d.ts +25 -1
- package/dist/components/Toast/Toast.js +134 -125
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/components/Toast/index.d.ts +1 -1
- package/dist/components/Toolbar/Toolbar.d.ts +3 -0
- package/dist/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tree/Tree.d.ts +8 -0
- package/dist/components/Tree/Tree.js.map +1 -1
- package/dist/components/VirtualList/VirtualList.d.ts +8 -0
- package/dist/components/VirtualList/VirtualList.js +4 -4
- package/dist/components/VirtualList/VirtualList.js.map +1 -1
- package/dist/components/ZoomControls/ZoomControls.d.ts +4 -0
- package/dist/components/ZoomControls/ZoomControls.js.map +1 -1
- package/dist/foundations/ChoiceBase/ChoiceBase.d.ts +1 -0
- package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
- package/dist/foundations/HiddenValue/HiddenValue.d.ts +3 -0
- package/dist/foundations/HiddenValue/HiddenValue.js.map +1 -1
- package/dist/foundations/Icon/Icon.d.ts +3 -0
- package/dist/foundations/Icon/Icon.js.map +1 -1
- package/dist/foundations/image-outcome.d.ts +15 -0
- package/dist/foundations/image-outcome.js +39 -0
- package/dist/foundations/image-outcome.js.map +1 -0
- package/dist/foundations/option-icon.d.ts +26 -0
- package/dist/foundations/option-icon.js +16 -0
- package/dist/foundations/option-icon.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +476 -474
- package/dist/icons/keywords.d.ts +249 -0
- package/dist/icons/keywords.js +1728 -0
- package/dist/icons/keywords.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.js +240 -213
- package/dist/styles/aspect-ratio.css +1 -0
- package/dist/styles/avatar.css +1 -0
- package/dist/styles/breadcrumbs.css +1 -0
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/checklist.css +1 -0
- package/dist/styles/container.css +1 -0
- package/dist/styles/divider.css +1 -0
- package/dist/styles/generated-css.d.ts +1 -1
- package/dist/styles/generated-css.js +1 -1
- package/dist/styles/generated-css.js.map +1 -1
- package/dist/styles/grid.css +1 -1
- package/dist/styles/heading.css +1 -0
- package/dist/styles/image.css +1 -0
- package/dist/styles/menu.css +1 -1
- package/dist/styles/page-header.css +1 -0
- package/dist/styles/pagination.css +1 -0
- package/dist/styles/side-nav.css +1 -1
- package/dist/styles/stack.css +1 -1
- package/dist/styles/text.css +1 -0
- package/dist/styles/time-field.css +1 -1
- package/dist/styles/toast.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme/CynosureTheme.d.ts +4 -0
- package/dist/theme/CynosureTheme.js.map +1 -1
- package/dist/tokens/to-css.js +12 -12
- package/dist/tokens/to-css.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useControllableState as Y } from "../../foundations/controllable.js";
|
|
3
|
+
import { useClientLayoutEffect as Z } from "../../foundations/client-layout-effect.js";
|
|
4
|
+
import { IconButton as k } from "../IconButton/IconButton.js";
|
|
5
|
+
import { Checkbox as O } from "../Checkbox/Checkbox.js";
|
|
6
|
+
import { isComposing as A } from "../../foundations/keys.js";
|
|
7
|
+
import { edit as z } from "../../icons/edit.js";
|
|
8
|
+
import { plus as ee } from "../../icons/plus.js";
|
|
9
|
+
import { trash as te } from "../../icons/trash.js";
|
|
10
|
+
import { Field as ce } from "../Field/Field.js";
|
|
11
|
+
import { SortableList as re } from "../SortableList/SortableList.js";
|
|
12
|
+
import { TextField as L } from "../TextField/TextField.js";
|
|
13
|
+
import { forwardRef as ne, useRef as b, useState as B } from "react";
|
|
14
|
+
import { jsx as r, jsxs as g } from "react/jsx-runtime";
|
|
15
|
+
var le = {
|
|
16
|
+
add: "Add an item",
|
|
17
|
+
addButton: "Add",
|
|
18
|
+
rename: (d) => `Rename ${d}`,
|
|
19
|
+
remove: (d) => `Remove ${d}`
|
|
20
|
+
}, ae = 0, oe = () => typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `item-${Date.now().toString(36)}-${(++ae).toString(36)}`, F = ".cy-choice input", se = ".cy-checklist-rename", U = ".cy-text-field-input", T = `.cy-checklist-add ${U}`, De = ne(function({ label: v, labelHidden: I = !1, items: K, defaultItems: H = [], onChange: j, createId: q = oe, maxItems: u, reorderable: M = !1, disabled: a = !1, readOnly: i = !1, size: l = "md", labels: P, className: C, style: V }, W) {
|
|
21
|
+
const o = {
|
|
22
|
+
...le,
|
|
23
|
+
...P
|
|
24
|
+
}, [n, f] = Y(K, H, j), [D, E] = B(""), [_, N] = B(null), p = b(!1), w = b(null), s = b(null), R = u !== void 0 && n.length >= u;
|
|
25
|
+
Z(() => {
|
|
26
|
+
const e = s.current;
|
|
27
|
+
e !== null && (s.current = null, w.current?.querySelector(e)?.focus());
|
|
28
|
+
});
|
|
29
|
+
const m = (e, t) => `[data-item="${CSS.escape(e)}"] ${t}`, S = (e, t) => f(n.map((c) => c.id === e ? {
|
|
30
|
+
...c,
|
|
31
|
+
...t
|
|
32
|
+
} : c)), $ = () => {
|
|
33
|
+
const e = D.trim();
|
|
34
|
+
if (!e) return;
|
|
35
|
+
const t = {
|
|
36
|
+
id: q(),
|
|
37
|
+
label: e,
|
|
38
|
+
done: !1
|
|
39
|
+
};
|
|
40
|
+
s.current = u !== void 0 && n.length + 1 >= u ? m(t.id, F) : T, f([...n, t]), E("");
|
|
41
|
+
}, G = (e) => {
|
|
42
|
+
const t = n.findIndex((y) => y.id === e), c = n.filter((y) => y.id !== e), h = c[t] ?? c[t - 1];
|
|
43
|
+
s.current = h ? m(h.id, F) : T, f(c);
|
|
44
|
+
}, J = (e) => {
|
|
45
|
+
s.current = m(e, U), N(e);
|
|
46
|
+
}, Q = (e) => (t) => {
|
|
47
|
+
A(t) || t.key !== "Enter" && t.key !== "Escape" || (t.preventDefault(), t.stopPropagation(), p.current = t.key === "Escape", s.current = m(e.id, se), t.currentTarget.blur());
|
|
48
|
+
}, X = (e, t) => {
|
|
49
|
+
const c = t.trim();
|
|
50
|
+
!p.current && c && c !== e.label && S(e.id, { label: c }), p.current = !1, N(null);
|
|
51
|
+
}, x = (e) => {
|
|
52
|
+
const t = _ === e.id;
|
|
53
|
+
return /* @__PURE__ */ g("div", {
|
|
54
|
+
className: "cy-checklist-row cy-reset",
|
|
55
|
+
"data-item": e.id,
|
|
56
|
+
"data-renaming": t ? "" : void 0,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ r(O, {
|
|
59
|
+
strikeWhenChecked: !0,
|
|
60
|
+
label: t ? /* @__PURE__ */ r("span", {
|
|
61
|
+
className: "cy-visually-hidden",
|
|
62
|
+
children: e.label
|
|
63
|
+
}) : e.label,
|
|
64
|
+
checked: e.done,
|
|
65
|
+
disabled: a,
|
|
66
|
+
size: l,
|
|
67
|
+
className: "cy-checklist-check",
|
|
68
|
+
onChange: (c) => {
|
|
69
|
+
i || S(e.id, { done: c });
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
t && /* @__PURE__ */ r(L, {
|
|
73
|
+
label: o.rename(e.label),
|
|
74
|
+
labelHidden: !0,
|
|
75
|
+
defaultValue: e.label,
|
|
76
|
+
size: l,
|
|
77
|
+
className: "cy-checklist-field",
|
|
78
|
+
onFocus: (c) => c.currentTarget.select(),
|
|
79
|
+
onKeyDown: Q(e),
|
|
80
|
+
onBlur: (c) => X(e, c.currentTarget.value)
|
|
81
|
+
}),
|
|
82
|
+
!i && !t && /* @__PURE__ */ r(k, {
|
|
83
|
+
icon: z,
|
|
84
|
+
label: o.rename(e.label),
|
|
85
|
+
variant: "ghost",
|
|
86
|
+
size: l,
|
|
87
|
+
disabled: a,
|
|
88
|
+
className: "cy-checklist-rename",
|
|
89
|
+
onClick: () => J(e.id)
|
|
90
|
+
}),
|
|
91
|
+
!i && /* @__PURE__ */ r(k, {
|
|
92
|
+
icon: te,
|
|
93
|
+
label: o.remove(e.label),
|
|
94
|
+
variant: "ghost",
|
|
95
|
+
size: l,
|
|
96
|
+
disabled: a,
|
|
97
|
+
onClick: () => G(e.id)
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return /* @__PURE__ */ r("div", {
|
|
103
|
+
ref: W,
|
|
104
|
+
className: C ? `cy-checklist ${C}` : "cy-checklist",
|
|
105
|
+
"data-size": l,
|
|
106
|
+
style: V,
|
|
107
|
+
children: /* @__PURE__ */ r(ce, {
|
|
108
|
+
group: !0,
|
|
109
|
+
label: v,
|
|
110
|
+
labelHidden: I,
|
|
111
|
+
size: l,
|
|
112
|
+
children: (e) => /* @__PURE__ */ g("div", {
|
|
113
|
+
ref: w,
|
|
114
|
+
className: "cy-checklist-body cy-reset",
|
|
115
|
+
children: [n.length > 0 && (M && !i ? /* @__PURE__ */ r(re, {
|
|
116
|
+
label: v,
|
|
117
|
+
items: n.map((t) => ({
|
|
118
|
+
id: t.id,
|
|
119
|
+
label: t.label,
|
|
120
|
+
content: x(t)
|
|
121
|
+
})),
|
|
122
|
+
onReorder: (t) => f(t.map((c) => n.find((h) => h.id === c.id))),
|
|
123
|
+
disabled: a,
|
|
124
|
+
size: l
|
|
125
|
+
}) : /* @__PURE__ */ r("ul", {
|
|
126
|
+
className: "cy-checklist-items cy-reset",
|
|
127
|
+
"aria-labelledby": e.labelId,
|
|
128
|
+
children: n.map((t) => /* @__PURE__ */ r("li", {
|
|
129
|
+
className: "cy-checklist-item cy-reset",
|
|
130
|
+
children: x(t)
|
|
131
|
+
}, t.id))
|
|
132
|
+
})), !i && /* @__PURE__ */ g("div", {
|
|
133
|
+
className: "cy-checklist-add cy-reset",
|
|
134
|
+
children: [/* @__PURE__ */ r(L, {
|
|
135
|
+
label: o.add,
|
|
136
|
+
labelHidden: !0,
|
|
137
|
+
placeholder: o.add,
|
|
138
|
+
value: D,
|
|
139
|
+
disabled: a || R,
|
|
140
|
+
size: l,
|
|
141
|
+
className: "cy-checklist-field",
|
|
142
|
+
onChange: E,
|
|
143
|
+
onKeyDown: (t) => {
|
|
144
|
+
t.key !== "Enter" || A(t) || (t.preventDefault(), $());
|
|
145
|
+
}
|
|
146
|
+
}), /* @__PURE__ */ r(k, {
|
|
147
|
+
icon: ee,
|
|
148
|
+
label: o.addButton,
|
|
149
|
+
variant: "ghost",
|
|
150
|
+
size: l,
|
|
151
|
+
disabled: a || R,
|
|
152
|
+
onClick: $
|
|
153
|
+
})]
|
|
154
|
+
})]
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
export {
|
|
160
|
+
De as Checklist
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=Checklist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Checklist.js","names":["useControllableState","useClientLayoutEffect","IconButton","Checkbox","isComposing","edit","plus","trash","Field","SortableList","TextField","forwardRef","useRef","useState","jsx","jsxs","DEFAULT_LABELS","name","made","newId","CHECK","RENAME","FIELD","ADD","Checklist","label","labelHidden","items","defaultItems","onChange","createId","maxItems","reorderable","disabled","readOnly","size","labels","className","style","ref","text","rows","setRows","draft","setDraft","editing","setEditing","cancelled","body","focusNext","full","selector","inRow","id","part","update","patch","r","add","item","remove","at","rest","next","rename","onRenameKey","event","endRename","typed","row","renaming","done","field","moved"],"sources":["../../../src/components/Checklist/Checklist.tsx"],"sourcesContent":["import { type CSSProperties, forwardRef, type KeyboardEvent, useRef, useState } from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { isComposing } from \"../../foundations/keys.js\";\nimport { edit } from \"../../icons/edit.js\";\nimport { plus } from \"../../icons/plus.js\";\nimport { trash } from \"../../icons/trash.js\";\nimport { Checkbox } from \"../Checkbox/Checkbox.js\";\nimport { Field } from \"../Field/Field.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { SortableList } from \"../SortableList/SortableList.js\";\nimport { TextField } from \"../TextField/TextField.js\";\n\nexport interface ChecklistTokens {\n /** Space between rows, and between the rows and the add field. */\n gap: string;\n /** Space between a row's checkbox, name and buttons. */\n rowGap: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n checklist: ChecklistTokens;\n }\n}\n\nexport interface ChecklistItem {\n /** Stable and unique: React keys, focus and reordering follow it. */\n id: string;\n /** The row's name. */\n label: string;\n /** Whether it is ticked. */\n done: boolean;\n}\n\nexport interface ChecklistLabels {\n /** Name and placeholder of the field that adds a row. Default \"Add an item\". */\n add: string;\n /** Name of the button next to that field. Default \"Add\". */\n addButton: string;\n /** Name of a row's rename button, and of the field it opens. Default \"Rename Buy milk\". */\n rename: (name: string) => string;\n /** Name of a row's remove button. Default \"Remove Buy milk\". */\n remove: (name: string) => string;\n}\n\nexport interface ChecklistProps {\n /** What the rows are (\"Subtasks\"). Names the list; shown above it unless `labelHidden`. */\n label: string;\n /** Visually hide the label (it still names the list). Default false. */\n labelHidden?: boolean;\n /** The rows, when you control them: `{ id, label, done }`. */\n items?: ChecklistItem[] | undefined;\n /** Starting rows when uncontrolled. */\n defaultItems?: ChecklistItem[];\n /** Called with the full list after each change: a row added, ticked, renamed, removed or moved. */\n onChange?: ((items: ChecklistItem[]) => void) | undefined;\n /** Makes the id of a new row. Default: `crypto.randomUUID()`, or a time-based id where that is missing. */\n createId?: () => string;\n /** The most rows the list may hold; the add field turns off when it is full. */\n maxItems?: number | undefined;\n /** Rows get a grip to drag, or to move with Space and the arrow keys (SortableList). Default false. */\n reorderable?: boolean;\n /** Turns off every checkbox, field and button. Default false. */\n disabled?: boolean;\n /** Shows the rows as they are: nothing can be ticked, added, renamed, removed or moved. Default false. */\n readOnly?: boolean;\n /** Size of the checkboxes, text, fields and buttons. Default \"md\". */\n size?: \"sm\" | \"md\";\n /** Replace the built-in English text. */\n labels?: Partial<ChecklistLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-checklist-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: ChecklistLabels = {\n add: \"Add an item\",\n addButton: \"Add\",\n rename: (name) => `Rename ${name}`,\n remove: (name) => `Remove ${name}`,\n};\n\nlet made = 0;\nconst newId = () =>\n typeof crypto.randomUUID === \"function\"\n ? crypto.randomUUID()\n : `item-${Date.now().toString(36)}-${(++made).toString(36)}`;\n\nconst CHECK = \".cy-choice input\";\nconst RENAME = \".cy-checklist-rename\";\nconst FIELD = \".cy-text-field-input\";\nconst ADD = `.cy-checklist-add ${FIELD}`;\n\n/**\n * A list of rows people add, tick, rename and remove: a task's subtasks, a packing list, the steps of a recipe.\n * Built from Checkbox, TextField and IconButton; with `reorderable` the rows sit in a SortableList.\n */\nexport const Checklist = forwardRef<HTMLDivElement, ChecklistProps>(function Checklist(\n {\n label,\n labelHidden = false,\n items,\n defaultItems = [],\n onChange,\n createId = newId,\n maxItems,\n reorderable = false,\n disabled = false,\n readOnly = false,\n size = \"md\",\n labels,\n className,\n style,\n },\n ref,\n) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const [rows, setRows] = useControllableState(items, defaultItems, onChange);\n const [draft, setDraft] = useState(\"\");\n /** The id of the row being renamed. */\n const [editing, setEditing] = useState<string | null>(null);\n /** Set by Escape, so the blur that follows throws the typed name away. */\n const cancelled = useRef(false);\n const body = useRef<HTMLDivElement>(null);\n /** Selector (inside the body) of what to focus once the rows have rendered. */\n const focusNext = useRef<string | null>(null);\n const full = maxItems !== undefined && rows.length >= maxItems;\n\n useClientLayoutEffect(() => {\n const selector = focusNext.current;\n if (selector === null) return;\n focusNext.current = null;\n body.current?.querySelector<HTMLElement>(selector)?.focus();\n });\n\n const inRow = (id: string, part: string) => `[data-item=\"${CSS.escape(id)}\"] ${part}`;\n const update = (id: string, patch: Partial<ChecklistItem>) =>\n setRows(rows.map((r) => (r.id === id ? { ...r, ...patch } : r)));\n\n const add = () => {\n const name = draft.trim();\n if (!name) return;\n const item = { id: createId(), label: name, done: false };\n // Focus stays in the add field for the next row; when the list is now full, it goes to the new row.\n focusNext.current = maxItems !== undefined && rows.length + 1 >= maxItems ? inRow(item.id, CHECK) : ADD;\n setRows([...rows, item]);\n setDraft(\"\");\n };\n const remove = (id: string) => {\n const at = rows.findIndex((r) => r.id === id);\n const rest = rows.filter((r) => r.id !== id);\n // Focus the row that took its place (or the one before it), else the add field.\n const next = rest[at] ?? rest[at - 1];\n focusNext.current = next ? inRow(next.id, CHECK) : ADD;\n setRows(rest);\n };\n const rename = (id: string) => {\n focusNext.current = inRow(id, FIELD);\n setEditing(id);\n };\n /** Enter saves and Escape cancels, both by leaving the field: its blur is the one place a rename ends. */\n const onRenameKey = (item: ChecklistItem) => (event: KeyboardEvent<HTMLInputElement>) => {\n if (isComposing(event) || (event.key !== \"Enter\" && event.key !== \"Escape\")) return;\n // Enter must not submit a form around the list, and Escape must not close a dialog around it.\n event.preventDefault();\n event.stopPropagation();\n cancelled.current = event.key === \"Escape\";\n focusNext.current = inRow(item.id, RENAME);\n event.currentTarget.blur();\n };\n const endRename = (item: ChecklistItem, typed: string) => {\n const name = typed.trim();\n // An empty name is not saved: the row keeps the name it had.\n if (!cancelled.current && name && name !== item.label) update(item.id, { label: name });\n cancelled.current = false;\n setEditing(null);\n };\n\n const row = (item: ChecklistItem) => {\n const renaming = editing === item.id;\n return (\n <div\n className=\"cy-checklist-row cy-reset\"\n data-item={item.id}\n data-renaming={renaming ? \"\" : undefined}\n >\n {/* Done rows are struck through and muted by Checkbox itself. */}\n <Checkbox\n strikeWhenChecked\n label={renaming ? <span className=\"cy-visually-hidden\">{item.label}</span> : item.label}\n checked={item.done}\n disabled={disabled}\n size={size}\n className=\"cy-checklist-check\"\n onChange={(done) => {\n if (!readOnly) update(item.id, { done });\n }}\n />\n {renaming && (\n <TextField\n label={text.rename(item.label)}\n labelHidden\n defaultValue={item.label}\n size={size}\n className=\"cy-checklist-field\"\n onFocus={(event) => event.currentTarget.select()}\n onKeyDown={onRenameKey(item)}\n onBlur={(event) => endRename(item, event.currentTarget.value)}\n />\n )}\n {!readOnly && !renaming && (\n <IconButton\n icon={edit}\n label={text.rename(item.label)}\n variant=\"ghost\"\n size={size}\n disabled={disabled}\n className=\"cy-checklist-rename\"\n onClick={() => rename(item.id)}\n />\n )}\n {!readOnly && (\n <IconButton\n icon={trash}\n label={text.remove(item.label)}\n variant=\"ghost\"\n size={size}\n disabled={disabled}\n onClick={() => remove(item.id)}\n />\n )}\n </div>\n );\n };\n\n return (\n <div\n ref={ref}\n className={className ? `cy-checklist ${className}` : \"cy-checklist\"}\n data-size={size}\n style={style}\n >\n <Field group label={label} labelHidden={labelHidden} size={size}>\n {(field) => (\n <div ref={body} className=\"cy-checklist-body cy-reset\">\n {rows.length > 0 &&\n (reorderable && !readOnly ? (\n <SortableList\n label={label}\n items={rows.map((item) => ({ id: item.id, label: item.label, content: row(item) }))}\n onReorder={(next) =>\n setRows(next.map((moved) => rows.find((r) => r.id === moved.id) as ChecklistItem))\n }\n disabled={disabled}\n size={size}\n />\n ) : (\n <ul className=\"cy-checklist-items cy-reset\" aria-labelledby={field.labelId}>\n {rows.map((item) => (\n <li key={item.id} className=\"cy-checklist-item cy-reset\">\n {row(item)}\n </li>\n ))}\n </ul>\n ))}\n {!readOnly && (\n <div className=\"cy-checklist-add cy-reset\">\n <TextField\n label={text.add}\n labelHidden\n placeholder={text.add}\n value={draft}\n disabled={disabled || full}\n size={size}\n className=\"cy-checklist-field\"\n onChange={setDraft}\n onKeyDown={(event) => {\n if (event.key !== \"Enter\" || isComposing(event)) return;\n // Enter adds a row; it must not submit a form around the list.\n event.preventDefault();\n add();\n }}\n />\n <IconButton\n icon={plus}\n label={text.addButton}\n variant=\"ghost\"\n size={size}\n disabled={disabled || full}\n onClick={add}\n />\n </div>\n )}\n </div>\n )}\n </Field>\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;AA6EA,IAAMgB,KAAkC;AAAA,EACtC,KAAK;AAAA,EACL,WAAW;AAAA,EACX,QAAA,CAASC,MAAS,UAAUA,CAAA;AAAA,EAC5B,QAAA,CAASA,MAAS,UAAUA,CAAA;AAC9B,GAEIC,KAAO,GACLC,KAAA,MACJ,OAAO,OAAO,cAAe,aACzB,OAAO,WAAW,IAClB,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,CAAA,KAAM,EAAED,IAAM,SAAS,EAAE,CAAA,IAEvDE,IAAQ,oBACRC,KAAS,wBACTC,IAAQ,wBACRC,IAAM,qBAAqBD,CAAA,IAMpBE,KAAYb,GAA2C,SAClE,EACE,OAAAc,G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AClB,OAAOG;AAAA,YACP,UAAUV,KAAYiB;AAAA,YAChB,MAAAf;AAAA,YACN,WAAU;AAAA,YACV,UAAUS;AAAA,YACV,WAAA,CAAYsB,MAAU;AACpB,cAAIA,EAAM,QAAQ,WAAW9D,EAAY8D,CAAK,MAE9CA,EAAM,eAAe,GACrBR,EAAI;AAAA,YACN;AAAA,UACD,CAAA,GACD,gBAAA5C,EAACZ,GAAD;AAAA,YACE,MAAMI;AAAA,YACN,OAAOkC,EAAK;AAAA,YACZ,SAAQ;AAAA,YACF,MAAAL;AAAA,YACN,UAAUF,KAAYiB;AAAA,YACtB,SAASQ;AAAA,UACV,CAAA,CACE;AAAA,QAEJ,CAAA,CAAA;AAAA,M;A,IAEF,CAAA;AAAA,EACJ,CAAA;AAET,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Checklist, type ChecklistItem, type ChecklistLabels, type ChecklistProps, type ChecklistTokens, } from "./Checklist.js";
|
|
@@ -21,6 +21,7 @@ export interface CodeBlockLabels extends CopyButtonLabels {
|
|
|
21
21
|
active: (lines: readonly number[]) => string;
|
|
22
22
|
}
|
|
23
23
|
export interface CodeBlockProps {
|
|
24
|
+
/** The code to show and copy. One final new line is not shown as an empty last line. */
|
|
24
25
|
code: string;
|
|
25
26
|
/** Shown in the header (when there is no `title`) and passed to `highlight`. */
|
|
26
27
|
language?: string | undefined;
|
|
@@ -31,6 +32,7 @@ export interface CodeBlockProps {
|
|
|
31
32
|
* bundles none. Without it the code is plain text.
|
|
32
33
|
*/
|
|
33
34
|
highlight?: ((code: string, language?: string) => ReactNode) | undefined;
|
|
35
|
+
/** Show line numbers beside the code. Left out when `wrap` is on. */
|
|
34
36
|
lineNumbers?: boolean;
|
|
35
37
|
/** Lines to mark (1-based), such as the line a debugger is on. Marked behind the text and read out. */
|
|
36
38
|
activeLines?: readonly number[] | undefined;
|
|
@@ -40,8 +42,11 @@ export interface CodeBlockProps {
|
|
|
40
42
|
copyable?: boolean;
|
|
41
43
|
/** Passed to the copy button (extensions can copy through their own channel). */
|
|
42
44
|
copy?: ((text: string) => Promise<void> | void) | undefined;
|
|
45
|
+
/** Text size of the code. Default "md". */
|
|
43
46
|
size?: Size;
|
|
47
|
+
/** Replace the built-in English text: the copy button, the code region's name and the marked lines. */
|
|
44
48
|
labels?: Partial<CodeBlockLabels>;
|
|
49
|
+
/** Added to the root element, for layout. */
|
|
45
50
|
className?: string;
|
|
46
51
|
/** Layout only. Restyle through --cy-code-block-* tokens. */
|
|
47
52
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.js","names":["CopyButton","useId","jsx","jsxs","defaultActive","lines","CodeBlock","code","language","title","highlight","lineNumbers","activeLines","wrap","copyable","copy","size","labels","className","style","id","shown","name","heading","numbered","marked","n","body","_","i"],"sources":["../../../src/components/CodeBlock/CodeBlock.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useId } from \"react\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { CopyButton, type CopyButtonLabels } from \"../CopyButton/CopyButton.js\";\n\nexport interface CodeBlockTokens {\n /** Background of the code. */\n background: string;\n /** Corner radius of the block. */\n radius: string;\n /** Tallest the code gets before it scrolls. */\n maxHeight: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n codeBlock: CodeBlockTokens;\n }\n}\n\nexport interface CodeBlockLabels extends CopyButtonLabels {\n /** Name of the scrollable code region when there is no `title` or `language`. Default: \"Code\". */\n region: string;\n /** Read after the code when lines are marked. Default: \"Line 3 highlighted\" / \"Lines 3, 4 highlighted\". */\n active: (lines: readonly number[]) => string;\n}\n\nconst defaultActive = (lines: readonly number[]) =>\n `${lines.length === 1 ? \"Line\" : \"Lines\"} ${lines.join(\", \")} highlighted`;\n\nexport interface CodeBlockProps {\n code: string;\n /** Shown in the header (when there is no `title`) and passed to `highlight`. */\n language?: string | undefined;\n /** A file name or caption for the header, e.g. \"vite.config.ts\". */\n title?: ReactNode;\n /**\n * Your highlighter, e.g. `(code, lang) => <span dangerouslySetInnerHTML={{ __html: shiki(code, lang) }} />`. Cynosure\n * bundles none. Without it the code is plain text.\n */\n highlight?: ((code: string, language?: string) => ReactNode) | undefined;\n lineNumbers?: boolean;\n /** Lines to mark (1-based), such as the line a debugger is on. Marked behind the text and read out. */\n activeLines?: readonly number[] | undefined;\n /** Wrap long lines instead of scrolling sideways (line numbers are then left out, as they would not line up). */\n wrap?: boolean;\n /** Show the copy button. Default true. */\n copyable?: boolean;\n /** Passed to the copy button (extensions can copy through their own channel). */\n copy?: ((text: string) => Promise<void> | void) | undefined;\n size?: Size;\n labels?: Partial<CodeBlockLabels>;\n className?: string;\n /** Layout only. Restyle through --cy-code-block-* tokens. */\n style?: CSSProperties;\n}\n\n/**\n * Code to read and copy: a header with the file name or language and a copy button, then the code with optional line\n * numbers. Bring your own highlighter through `highlight`.\n */\nexport function CodeBlock({\n code,\n language,\n title,\n highlight,\n lineNumbers = false,\n activeLines,\n wrap = false,\n copyable = true,\n copy,\n size = \"md\",\n labels,\n className,\n style,\n}: CodeBlockProps) {\n const id = useId();\n // One final new line is a file ending, not an empty last line.\n const shown = code.replace(/\\n$/, \"\");\n const lines = shown.split(\"\\n\");\n const name = typeof title === \"string\" ? title : (language ?? labels?.region ?? \"Code\");\n const heading = title ?? language;\n const numbered = lineNumbers && !wrap;\n const marked = !wrap && activeLines?.length ? activeLines.filter((n) => n >= 1 && n <= lines.length) : [];\n const body = (\n <code className=\"cy-code-block-code cy-reset\" data-language={language}>\n {highlight ? highlight(shown, language) : shown}\n </code>\n );\n return (\n <figure\n className={className ? `cy-code-block ${className}` : \"cy-code-block\"}\n data-size={size}\n data-wrap={wrap ? \"\" : undefined}\n aria-labelledby={heading ? `${id}-title` : undefined}\n aria-label={heading ? undefined : name}\n style={style}\n >\n {(heading || copyable) && (\n <div className=\"cy-code-block-header cy-reset\">\n <span className=\"cy-code-block-title cy-reset\" id={`${id}-title`}>\n {heading}\n </span>\n {copyable && (\n <CopyButton\n value={code}\n size=\"sm\"\n variant=\"ghost\"\n tooltipPlacement=\"start\"\n {...(copy ? { copy } : {})}\n {...(labels ? { labels } : {})}\n />\n )}\n </div>\n )}\n <div className=\"cy-code-block-body cy-reset\">\n {numbered && (\n <span className=\"cy-code-block-gutter cy-reset\" aria-hidden=\"true\">\n {lines.map((_, i) => (\n <span key={i} className=\"cy-reset\" data-active={marked.includes(i + 1) ? \"\" : undefined}>\n {i + 1}\n </span>\n ))}\n </span>\n )}\n {wrap ? (\n <pre className=\"cy-code-block-pre cy-reset\">{body}</pre>\n ) : (\n // A scrolling region must be reachable by keyboard: it is focusable and named.\n // biome-ignore lint/a11y/noNoninteractiveTabindex lint/a11y/useSemanticElements: the scrolling pre itself is the focusable, named region\n <pre className=\"cy-code-block-pre cy-reset\" tabIndex={0} role=\"region\" aria-label={name}>\n {marked.map((n) => (\n <span\n key={n}\n className=\"cy-code-block-mark cy-reset\"\n style={{ \"--_line\": n - 1 } as CSSProperties}\n aria-hidden=\"true\"\n />\n ))}\n {body}\n </pre>\n )}\n </div>\n {marked.length > 0 && (\n <span className=\"cy-visually-hidden\">{(labels?.active ?? defaultActive)(marked)}</span>\n )}\n </figure>\n );\n}\n"],"mappings":";;;;AA0BA,IAAMI,IAAA,CAAiBC,MACrB,GAAGA,EAAM,WAAW,IAAI,SAAS,OAAA,IAAWA,EAAM,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"CodeBlock.js","names":["CopyButton","useId","jsx","jsxs","defaultActive","lines","CodeBlock","code","language","title","highlight","lineNumbers","activeLines","wrap","copyable","copy","size","labels","className","style","id","shown","name","heading","numbered","marked","n","body","_","i"],"sources":["../../../src/components/CodeBlock/CodeBlock.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useId } from \"react\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { CopyButton, type CopyButtonLabels } from \"../CopyButton/CopyButton.js\";\n\nexport interface CodeBlockTokens {\n /** Background of the code. */\n background: string;\n /** Corner radius of the block. */\n radius: string;\n /** Tallest the code gets before it scrolls. */\n maxHeight: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n codeBlock: CodeBlockTokens;\n }\n}\n\nexport interface CodeBlockLabels extends CopyButtonLabels {\n /** Name of the scrollable code region when there is no `title` or `language`. Default: \"Code\". */\n region: string;\n /** Read after the code when lines are marked. Default: \"Line 3 highlighted\" / \"Lines 3, 4 highlighted\". */\n active: (lines: readonly number[]) => string;\n}\n\nconst defaultActive = (lines: readonly number[]) =>\n `${lines.length === 1 ? \"Line\" : \"Lines\"} ${lines.join(\", \")} highlighted`;\n\nexport interface CodeBlockProps {\n /** The code to show and copy. One final new line is not shown as an empty last line. */\n code: string;\n /** Shown in the header (when there is no `title`) and passed to `highlight`. */\n language?: string | undefined;\n /** A file name or caption for the header, e.g. \"vite.config.ts\". */\n title?: ReactNode;\n /**\n * Your highlighter, e.g. `(code, lang) => <span dangerouslySetInnerHTML={{ __html: shiki(code, lang) }} />`. Cynosure\n * bundles none. Without it the code is plain text.\n */\n highlight?: ((code: string, language?: string) => ReactNode) | undefined;\n /** Show line numbers beside the code. Left out when `wrap` is on. */\n lineNumbers?: boolean;\n /** Lines to mark (1-based), such as the line a debugger is on. Marked behind the text and read out. */\n activeLines?: readonly number[] | undefined;\n /** Wrap long lines instead of scrolling sideways (line numbers are then left out, as they would not line up). */\n wrap?: boolean;\n /** Show the copy button. Default true. */\n copyable?: boolean;\n /** Passed to the copy button (extensions can copy through their own channel). */\n copy?: ((text: string) => Promise<void> | void) | undefined;\n /** Text size of the code. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text: the copy button, the code region's name and the marked lines. */\n labels?: Partial<CodeBlockLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-code-block-* tokens. */\n style?: CSSProperties;\n}\n\n/**\n * Code to read and copy: a header with the file name or language and a copy button, then the code with optional line\n * numbers. Bring your own highlighter through `highlight`.\n */\nexport function CodeBlock({\n code,\n language,\n title,\n highlight,\n lineNumbers = false,\n activeLines,\n wrap = false,\n copyable = true,\n copy,\n size = \"md\",\n labels,\n className,\n style,\n}: CodeBlockProps) {\n const id = useId();\n // One final new line is a file ending, not an empty last line.\n const shown = code.replace(/\\n$/, \"\");\n const lines = shown.split(\"\\n\");\n const name = typeof title === \"string\" ? title : (language ?? labels?.region ?? \"Code\");\n const heading = title ?? language;\n const numbered = lineNumbers && !wrap;\n const marked = !wrap && activeLines?.length ? activeLines.filter((n) => n >= 1 && n <= lines.length) : [];\n const body = (\n <code className=\"cy-code-block-code cy-reset\" data-language={language}>\n {highlight ? highlight(shown, language) : shown}\n </code>\n );\n return (\n <figure\n className={className ? `cy-code-block ${className}` : \"cy-code-block\"}\n data-size={size}\n data-wrap={wrap ? \"\" : undefined}\n aria-labelledby={heading ? `${id}-title` : undefined}\n aria-label={heading ? undefined : name}\n style={style}\n >\n {(heading || copyable) && (\n <div className=\"cy-code-block-header cy-reset\">\n <span className=\"cy-code-block-title cy-reset\" id={`${id}-title`}>\n {heading}\n </span>\n {copyable && (\n <CopyButton\n value={code}\n size=\"sm\"\n variant=\"ghost\"\n tooltipPlacement=\"start\"\n {...(copy ? { copy } : {})}\n {...(labels ? { labels } : {})}\n />\n )}\n </div>\n )}\n <div className=\"cy-code-block-body cy-reset\">\n {numbered && (\n <span className=\"cy-code-block-gutter cy-reset\" aria-hidden=\"true\">\n {lines.map((_, i) => (\n <span key={i} className=\"cy-reset\" data-active={marked.includes(i + 1) ? \"\" : undefined}>\n {i + 1}\n </span>\n ))}\n </span>\n )}\n {wrap ? (\n <pre className=\"cy-code-block-pre cy-reset\">{body}</pre>\n ) : (\n // A scrolling region must be reachable by keyboard: it is focusable and named.\n // biome-ignore lint/a11y/noNoninteractiveTabindex lint/a11y/useSemanticElements: the scrolling pre itself is the focusable, named region\n <pre className=\"cy-code-block-pre cy-reset\" tabIndex={0} role=\"region\" aria-label={name}>\n {marked.map((n) => (\n <span\n key={n}\n className=\"cy-code-block-mark cy-reset\"\n style={{ \"--_line\": n - 1 } as CSSProperties}\n aria-hidden=\"true\"\n />\n ))}\n {body}\n </pre>\n )}\n </div>\n {marked.length > 0 && (\n <span className=\"cy-visually-hidden\">{(labels?.active ?? defaultActive)(marked)}</span>\n )}\n </figure>\n );\n}\n"],"mappings":";;;;AA0BA,IAAMI,IAAA,CAAiBC,MACrB,GAAGA,EAAM,WAAW,IAAI,SAAS,OAAA,IAAWA,EAAM,KAAK,IAAI,CAAA;AAsC7D,SAAgBC,EAAU,EACxB,MAAAC,GACA,UAAAC,GACA,OAAAC,GACA,WAAAC,GACA,aAAAC,IAAc,IACd,aAAAC,GACA,MAAAC,IAAO,IACP,UAAAC,IAAW,IACX,MAAAC,GACA,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACiB;AACjB,QAAMC,IAAKnB,EAAM,GAEXoB,IAAQd,EAAK,QAAQ,OAAO,EAAE,GAC9BF,IAAQgB,EAAM,MAAM;AAAA,CAAI,GACxBC,IAAO,OAAOb,KAAU,WAAWA,IAASD,KAAYS,GAAQ,UAAU,QAC1EM,IAAUd,KAASD,GACnBgB,IAAWb,KAAe,CAACE,GAC3BY,IAAS,CAACZ,KAAQD,GAAa,SAASA,EAAY,OAAA,CAAQc,MAAMA,KAAK,KAAKA,KAAKrB,EAAM,MAAM,IAAI,CAAC,GAClGsB,IACJ,gBAAAzB,EAAC,QAAD;AAAA,IAAM,WAAU;AAAA,IAA8B,iBAAeM;AAAA,IAC1D,UAAAE,IAAYA,EAAUW,GAAOb,CAAQ,IAAIa;AAAA,EACtC,CAAA;AAER,SACE,gBAAAlB,EAAC,UAAD;AAAA,IACE,WAAWe,IAAY,iBAAiBA,CAAA,KAAc;AAAA,IACtD,aAAWF;AAAA,IACX,aAAWH,IAAO,KAAK;AAAA,IACvB,mBAAiBU,IAAU,GAAGH,CAAA,WAAa;AAAA,IAC3C,cAAYG,IAAU,SAAYD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,QAEJ,CAAA,CAAA;AAAA,M;A,MACJF,EAAO,SAAS,KACf,gBAAAvB,EAAC,QAAD;AAAA,QAAM,WAAU;AAAA,QAAuB,WAAAe,GAAQ,UAAUb,GAAeqB,CAAM;AAAA,MAAQ,CAAA;AAAA,IAElF;AAAA,E;AAEZ"}
|
|
@@ -25,13 +25,19 @@ export interface ColorFieldLabels {
|
|
|
25
25
|
invalid: string;
|
|
26
26
|
}
|
|
27
27
|
export interface ColorFieldProps {
|
|
28
|
+
/** The field's label. */
|
|
28
29
|
label: ReactNode;
|
|
30
|
+
/** Visually hide the label (it still names the control). Prefer visible labels. */
|
|
29
31
|
labelHidden?: boolean;
|
|
32
|
+
/** Help text shown below the control and read with it. */
|
|
30
33
|
description?: ReactNode;
|
|
34
|
+
/** Your own error; it replaces the field's own messages. */
|
|
31
35
|
error?: ReactNode;
|
|
32
36
|
/** Any CSS colour; reported back in `format`. */
|
|
33
37
|
value?: string;
|
|
38
|
+
/** The starting colour when uncontrolled, any CSS colour. Default "black". */
|
|
34
39
|
defaultValue?: string;
|
|
40
|
+
/** Called when the colour changes (typed, picked or chosen from a swatch), with the colour written in `format`. */
|
|
35
41
|
onChange?: (value: string) => void;
|
|
36
42
|
/** How values are written: six-digit hex, `rgb(51 102 255)` or `oklch(55% 0.21 264)`. */
|
|
37
43
|
format?: "hex" | "rgb" | "oklch";
|
|
@@ -39,11 +45,17 @@ export interface ColorFieldProps {
|
|
|
39
45
|
alpha?: boolean;
|
|
40
46
|
/** Colours offered in the picker: brand colours, presets, or recent colours you keep. */
|
|
41
47
|
swatches?: (ColorSwatch | string)[] | undefined;
|
|
48
|
+
/** Name the colour is submitted under in a form, written in `format`. */
|
|
42
49
|
name?: string;
|
|
50
|
+
/** Marks the field as required and makes its input required in a form. */
|
|
43
51
|
required?: boolean;
|
|
52
|
+
/** Turns off the input and the picker; the colour is not submitted with a form. */
|
|
44
53
|
disabled?: boolean;
|
|
54
|
+
/** Size of the field. Default "md". */
|
|
45
55
|
size?: Size;
|
|
56
|
+
/** Replace the built-in English text: the picker's controls and the error for text that is not a colour. */
|
|
46
57
|
labels?: Partial<ColorFieldLabels>;
|
|
58
|
+
/** Added to the root element, for layout. */
|
|
47
59
|
className?: string;
|
|
48
60
|
/** Layout only. */
|
|
49
61
|
style?: CSSProperties;
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
import { Button as Z } from "../Button/Button.js";
|
|
3
3
|
import { clamp as j } from "../../foundations/math.js";
|
|
4
4
|
import { IconButton as q } from "../IconButton/IconButton.js";
|
|
5
|
-
import {
|
|
6
|
-
import { HiddenValue as oe } from "../../foundations/HiddenValue/HiddenValue.js";
|
|
7
|
-
import { InputBase as re } from "../../foundations/InputBase/InputBase.js";
|
|
5
|
+
import { Popover as ee } from "../Popover/Popover.js";
|
|
8
6
|
import { stepKey as z } from "../../foundations/keys.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
7
|
+
import { Field as oe } from "../Field/Field.js";
|
|
8
|
+
import { InputBase as re } from "../../foundations/InputBase/InputBase.js";
|
|
9
|
+
import { useDrag as te } from "../../foundations/drag.js";
|
|
10
|
+
import { HiddenValue as ae } from "../../foundations/HiddenValue/HiddenValue.js";
|
|
11
|
+
import { droplet as ne } from "../../icons/droplet.js";
|
|
12
|
+
import { rgbToOklch as ie, toHex as le } from "../../tokens/color.js";
|
|
13
|
+
import { readColor as se } from "./read-color.js";
|
|
14
|
+
import { ColorSwatches as ce } from "../ColorSwatches/ColorSwatches.js";
|
|
15
15
|
import { Slider as K } from "../Slider/Slider.js";
|
|
16
16
|
import { useEffect as ue, useRef as L, useState as C } from "react";
|
|
17
17
|
import { jsx as s, jsxs as A } from "react/jsx-runtime";
|
|
@@ -51,14 +51,14 @@ function O(a, n, i) {
|
|
|
51
51
|
return t < 1 ? `rgb(${u} ${f} ${d} / ${t})` : `rgb(${u} ${f} ${d})`;
|
|
52
52
|
}
|
|
53
53
|
if (n === "oklch") {
|
|
54
|
-
const [u, f, d] =
|
|
54
|
+
const [u, f, d] = ie(c), h = `${x(u * 100, 1)}% ${x(f, 3)} ${x(f < 5e-4 ? 0 : d, 1)}`;
|
|
55
55
|
return t < 1 ? `oklch(${h} / ${t})` : `oklch(${h})`;
|
|
56
56
|
}
|
|
57
|
-
const l =
|
|
57
|
+
const l = le(c);
|
|
58
58
|
return t < 1 ? `${l}${Math.round(t * 255).toString(16).padStart(2, "0")}` : l;
|
|
59
59
|
}
|
|
60
60
|
var y = (a, n = 0) => {
|
|
61
|
-
const i =
|
|
61
|
+
const i = se(a);
|
|
62
62
|
return i ? {
|
|
63
63
|
...me(i.rgb, n),
|
|
64
64
|
a: i.a
|
|
@@ -96,7 +96,7 @@ function Be({ label: a, labelHidden: n, description: i, error: c, value: t, defa
|
|
|
96
96
|
v: 1 - j((o.y - e.top) / e.height)
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
|
-
|
|
99
|
+
te(w, {
|
|
100
100
|
onStart: ({ point: o }) => {
|
|
101
101
|
F.current = r, w.current?.focus(), I(o);
|
|
102
102
|
},
|
|
@@ -135,7 +135,7 @@ function Be({ label: a, labelHidden: n, description: i, error: c, value: t, defa
|
|
|
135
135
|
} catch {
|
|
136
136
|
}
|
|
137
137
|
}, Y = `rgb(${B(r).map((o) => Math.round(o * 255)).join(" ")} / ${d ? r.a : 1})`, k = (o) => Math.round(o * 100);
|
|
138
|
-
return /* @__PURE__ */ s(
|
|
138
|
+
return /* @__PURE__ */ s(oe, {
|
|
139
139
|
label: a,
|
|
140
140
|
labelHidden: n,
|
|
141
141
|
description: i,
|
|
@@ -150,7 +150,7 @@ function Be({ label: a, labelHidden: n, description: i, error: c, value: t, defa
|
|
|
150
150
|
"data-invalid": o.invalid || void 0,
|
|
151
151
|
"data-disabled": b || void 0,
|
|
152
152
|
children: [
|
|
153
|
-
/* @__PURE__ */ s(
|
|
153
|
+
/* @__PURE__ */ s(ee, {
|
|
154
154
|
label: m.pick,
|
|
155
155
|
size: "sm",
|
|
156
156
|
placement: "bottom",
|
|
@@ -213,7 +213,7 @@ function Be({ label: a, labelHidden: n, description: i, error: c, value: t, defa
|
|
|
213
213
|
className: "cy-color-field-alpha",
|
|
214
214
|
style: { "--_c": `rgb(${B(r).map((e) => Math.round(e * 255)).join(" ")})` }
|
|
215
215
|
}),
|
|
216
|
-
h && h.length > 0 && /* @__PURE__ */ s(
|
|
216
|
+
h && h.length > 0 && /* @__PURE__ */ s(ce, {
|
|
217
217
|
label: m.swatches,
|
|
218
218
|
swatches: h,
|
|
219
219
|
size: "sm",
|
|
@@ -245,13 +245,13 @@ function Be({ label: a, labelHidden: n, description: i, error: c, value: t, defa
|
|
|
245
245
|
}
|
|
246
246
|
}),
|
|
247
247
|
Q && !b && /* @__PURE__ */ s(q, {
|
|
248
|
-
icon:
|
|
248
|
+
icon: ne,
|
|
249
249
|
label: m.eyedropper,
|
|
250
250
|
variant: "ghost",
|
|
251
251
|
size: "sm",
|
|
252
252
|
onClick: X
|
|
253
253
|
}),
|
|
254
|
-
/* @__PURE__ */ s(
|
|
254
|
+
/* @__PURE__ */ s(ae, {
|
|
255
255
|
name: P,
|
|
256
256
|
value: g,
|
|
257
257
|
disabled: b,
|
|
@@ -265,7 +265,7 @@ function Be({ label: a, labelHidden: n, description: i, error: c, value: t, defa
|
|
|
265
265
|
}
|
|
266
266
|
export {
|
|
267
267
|
Be as ColorField,
|
|
268
|
-
|
|
268
|
+
se as readColor
|
|
269
269
|
};
|
|
270
270
|
|
|
271
271
|
//# sourceMappingURL=ColorField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorField.js","names":["Button","clamp","IconButton","useDrag","HiddenValue","InputBase","stepKey","droplet","rgbToOklch","toHex","readColor","ColorSwatches","Field","Popover","Slider","useEffect","useRef","useState","jsx","jsxs","DEFAULT_LABELS","round","n","digits","rgbToHsv","r","g","b","hue","max","d","h","hsvToRgb","s","v","f","k","write","c","format","withAlpha","rgb","a","L","C","H","body","hex","fromText","text","read","ColorField","label","labelHidden","description","error","value","defaultValue","onChange","alpha","swatches","name","required","disabled","size","labels","className","style","inner","setInner","color","current","draft","setDraft","invalid","setInvalid","area","dragFrom","dropper","setDropper","set","next","out","commit","fromPoint","point","box","_","cancelled","onAreaKey","event","axis","pickFromScreen","picked","swatch","pct","field","props"],"sources":["../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import { type CSSProperties, type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { HiddenValue } from \"../../foundations/HiddenValue/HiddenValue.js\";\nimport { InputBase } from \"../../foundations/InputBase/InputBase.js\";\nimport { stepKey } from \"../../foundations/keys.js\";\nimport { clamp } from \"../../foundations/math.js\";\nimport { droplet } from \"../../icons/droplet.js\";\nimport { type Rgb, rgbToOklch, toHex } from \"../../tokens/color.js\";\nimport { type ColorSwatch, ColorSwatches } from \"../ColorSwatches/ColorSwatches.js\";\nimport { readColor } from \"./read-color.js\";\n\nexport { readColor };\n\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Button } from \"../Button/Button.js\";\nimport { Field } from \"../Field/Field.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Popover } from \"../Popover/Popover.js\";\nimport { Slider } from \"../Slider/Slider.js\";\n\nexport interface ColorFieldTokens {\n swatchSize: string;\n areaHeight: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n colorField: ColorFieldTokens;\n }\n}\n\nexport interface ColorFieldLabels {\n /** Name of the swatch button and the picker panel. */\n pick: string;\n area: string;\n hue: string;\n alpha: string;\n eyedropper: string;\n /** Name of the swatch group in the picker. Default: \"Swatches\". */\n swatches: string;\n /** Error when the typed text is not a colour. */\n invalid: string;\n}\n\nexport interface ColorFieldProps {\n label: ReactNode;\n labelHidden?: boolean;\n description?: ReactNode;\n error?: ReactNode;\n /** Any CSS colour; reported back in `format`. */\n value?: string;\n defaultValue?: string;\n onChange?: (value: string) => void;\n /** How values are written: six-digit hex, `rgb(51 102 255)` or `oklch(55% 0.21 264)`. */\n format?: \"hex\" | \"rgb\" | \"oklch\";\n /** Let people set opacity (adds an opacity slider and alpha to the value). */\n alpha?: boolean;\n /** Colours offered in the picker: brand colours, presets, or recent colours you keep. */\n swatches?: (ColorSwatch | string)[] | undefined;\n name?: string;\n required?: boolean;\n disabled?: boolean;\n size?: Size;\n labels?: Partial<ColorFieldLabels>;\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: ColorFieldLabels = {\n pick: \"Choose colour\",\n area: \"Saturation and brightness\",\n hue: \"Hue\",\n alpha: \"Opacity\",\n eyedropper: \"Pick a colour from the screen\",\n swatches: \"Swatches\",\n invalid: \"Enter a colour such as rgb(51 102 255), a hex code or a colour name.\",\n};\n\ninterface Hsva {\n h: number;\n s: number;\n v: number;\n a: number;\n}\n\nconst round = (n: number, digits = 0) => Number(n.toFixed(digits));\n\nfunction rgbToHsv([r, g, b]: Rgb, hue = 0): Omit<Hsva, \"a\"> {\n const max = Math.max(r, g, b);\n const d = max - Math.min(r, g, b);\n let h = hue;\n if (d) {\n if (max === r) h = 60 * (((g - b) / d + 6) % 6);\n else if (max === g) h = 60 * ((b - r) / d + 2);\n else h = 60 * ((r - g) / d + 4);\n }\n return { h, s: max ? d / max : 0, v: max };\n}\nfunction hsvToRgb({ h, s, v }: Hsva): Rgb {\n const f = (n: number) => {\n const k = (n + h / 60) % 6;\n return v - v * s * Math.max(0, Math.min(k, 4 - k, 1));\n };\n return [f(5), f(3), f(1)];\n}\n\nfunction write(c: Hsva, format: ColorFieldProps[\"format\"], withAlpha: boolean): string {\n const rgb = hsvToRgb(c);\n const a = withAlpha ? round(c.a, 2) : 1;\n if (format === \"rgb\") {\n const [r, g, b] = rgb.map((n) => Math.round(n * 255));\n return a < 1 ? `rgb(${r} ${g} ${b} / ${a})` : `rgb(${r} ${g} ${b})`;\n }\n if (format === \"oklch\") {\n const [L, C, H] = rgbToOklch(rgb);\n const body = `${round(L * 100, 1)}% ${round(C, 3)} ${round(C < 0.0005 ? 0 : H, 1)}`;\n return a < 1 ? `oklch(${body} / ${a})` : `oklch(${body})`;\n }\n const hex = toHex(rgb);\n return a < 1\n ? `${hex}${Math.round(a * 255)\n .toString(16)\n .padStart(2, \"0\")}`\n : hex;\n}\n\nconst fromText = (text: string, hue = 0): Hsva | null => {\n const read = readColor(text);\n return read ? { ...rgbToHsv(read.rgb, hue), a: read.a } : null;\n};\n\ntype EyeDropperCtor = new () => { open: () => Promise<{ sRGBHex: string }> };\n\n/** A colour input: type any CSS colour, or pick one with a saturation area, hue and opacity sliders, or the screen. */\nexport function ColorField({\n label,\n labelHidden,\n description,\n error,\n value,\n defaultValue = \"black\",\n onChange,\n format = \"hex\",\n alpha = false,\n swatches,\n name,\n required,\n disabled,\n size = \"md\",\n labels,\n className,\n style,\n}: ColorFieldProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const [inner, setInner] = useState(() => fromText(defaultValue) ?? { h: 0, s: 0, v: 0, a: 1 });\n const external = value === undefined ? null : fromText(value, inner.h);\n const color = external ?? inner;\n const current = write(color, format, alpha);\n const [draft, setDraft] = useState<string | null>(null);\n const [invalid, setInvalid] = useState(false);\n const area = useRef<HTMLDivElement>(null);\n const dragFrom = useRef<Hsva | null>(null);\n const [dropper, setDropper] = useState(false);\n useEffect(() => setDropper(typeof window !== \"undefined\" && \"EyeDropper\" in window), []);\n\n const set = (next: Hsva) => {\n const out = write(next, format, alpha);\n if (value === undefined) setInner(next);\n else setInner((c) => ({ ...c, h: next.h }));\n setDraft(null);\n setInvalid(false);\n if (out !== current) onChange?.(out);\n };\n const commit = () => {\n if (draft === null) return;\n const next = fromText(draft, color.h);\n if (next) set(alpha ? next : { ...next, a: 1 });\n else setInvalid(true);\n };\n\n const fromPoint = (point: { x: number; y: number }) => {\n const box = (area.current as HTMLDivElement).getBoundingClientRect();\n set({\n ...color,\n s: clamp((point.x - box.left) / box.width),\n v: 1 - clamp((point.y - box.top) / box.height),\n });\n };\n // Dragging in the area through detent; Escape puts the colour back.\n useDrag(area, {\n onStart: ({ point }) => {\n dragFrom.current = color;\n area.current?.focus();\n fromPoint(point);\n },\n onMove: ({ point }) => fromPoint(point),\n onEnd: (_, cancelled) => {\n if (cancelled) set(dragFrom.current as Hsva);\n },\n });\n const onAreaKey = (event: KeyboardEvent<HTMLDivElement>) => {\n // Saturation along x, brightness along y; Shift for bigger steps.\n const axis = { min: 0, max: 1, step: 0.01, arrowsOnly: true };\n const s = stepKey(event, { ...axis, value: color.s, axis: \"x\" });\n const v = stepKey(event, { ...axis, value: color.v, axis: \"y\" });\n if (s === undefined && v === undefined) return;\n event.preventDefault();\n set({ ...color, s: s ?? color.s, v: v ?? color.v });\n };\n const pickFromScreen = async () => {\n try {\n const picked = await new (window as unknown as { EyeDropper: EyeDropperCtor }).EyeDropper().open();\n const next = fromText(picked.sRGBHex, color.h);\n if (next) set({ ...next, a: color.a });\n } catch {\n // Cancelled (Escape) or refused: nothing to do.\n }\n };\n\n const swatch = `rgb(${hsvToRgb(color)\n .map((n) => Math.round(n * 255))\n .join(\" \")} / ${alpha ? color.a : 1})`;\n const pct = (n: number) => Math.round(n * 100);\n\n return (\n <Field\n label={label}\n labelHidden={labelHidden}\n description={description}\n error={error ?? (invalid ? text.invalid : undefined)}\n required={required}\n size={size}\n className={className ? `cy-color-field ${className}` : \"cy-color-field\"}\n style={style}\n >\n {(field) => (\n <div\n className=\"cy-text-field cy-color-field-control\"\n data-size={size}\n data-invalid={field.invalid || undefined}\n data-disabled={disabled || undefined}\n >\n <Popover\n label={text.pick}\n size=\"sm\"\n placement=\"bottom\"\n trigger={(props) => (\n <Button\n {...props}\n variant=\"ghost\"\n size=\"sm\"\n disabled={disabled}\n aria-label={text.pick}\n className=\"cy-color-field-trigger\"\n >\n <span\n className=\"cy-color-field-swatch cy-reset\"\n style={{ \"--_c\": swatch } as CSSProperties}\n />\n </Button>\n )}\n >\n <div className=\"cy-color-field-picker cy-reset\">\n <div\n ref={area}\n role=\"slider\"\n tabIndex={0}\n aria-label={text.area}\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={pct(color.s)}\n aria-valuetext={`${text.area}: ${pct(color.s)}%, ${pct(color.v)}%`}\n className=\"cy-color-field-area cy-reset\"\n style={\n {\n \"--_hue\": `hsl(${round(color.h)} 100% 50%)`,\n \"--_x\": `${color.s * 100}%`,\n \"--_y\": `${(1 - color.v) * 100}%`,\n } as CSSProperties\n }\n onKeyDown={onAreaKey}\n >\n <span className=\"cy-color-field-area-thumb cy-reset\" />\n </div>\n <Slider\n label={text.hue}\n labelHidden\n min={0}\n max={360}\n value={round(color.h)}\n onChange={(h) => set({ ...color, h: h as number })}\n className=\"cy-color-field-hue\"\n />\n {alpha && (\n <Slider\n label={text.alpha}\n labelHidden\n min={0}\n max={100}\n value={pct(color.a)}\n labels={{ value: (v) => `${v}%` }}\n onChange={(a) => set({ ...color, a: (a as number) / 100 })}\n className=\"cy-color-field-alpha\"\n style={\n {\n \"--_c\": `rgb(${hsvToRgb(color)\n .map((n) => Math.round(n * 255))\n .join(\" \")})`,\n } as CSSProperties\n }\n />\n )}\n {swatches && swatches.length > 0 && (\n <ColorSwatches\n label={text.swatches}\n swatches={swatches}\n size=\"sm\"\n value={current}\n onChange={(v) => {\n const next = fromText(v);\n if (next) set(next);\n }}\n />\n )}\n </div>\n </Popover>\n <InputBase\n id={field.id}\n className=\"cy-text-field-input\"\n aria-describedby={field.describedBy}\n invalid={field.invalid}\n required={required}\n disabled={disabled}\n autoComplete=\"off\"\n spellCheck={false}\n value={draft ?? current}\n onChange={(e) => {\n setDraft(e.currentTarget.value);\n setInvalid(false);\n }}\n onBlur={commit}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") commit();\n }}\n />\n {dropper && !disabled && (\n <IconButton\n icon={droplet}\n label={text.eyedropper}\n variant=\"ghost\"\n size=\"sm\"\n onClick={pickFromScreen}\n />\n )}\n <HiddenValue\n name={name}\n value={current}\n disabled={disabled}\n onReset={() => {\n setInner(fromText(defaultValue) ?? inner);\n setDraft(null);\n setInvalid(false);\n }}\n />\n </div>\n )}\n </Field>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqEA,IAAMoB,KAAmC;AAAA,EACvC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,SAAS;AACX,GASMC,IAAA,CAASC,GAAWC,IAAS,MAAM,OAAOD,EAAE,QAAQC,CAAM,CAAC;AAEjE,SAASC,GAAS,CAACC,GAAGC,GAAGC,CAAA,GAASC,IAAM,GAAoB;AAC1D,QAAMC,IAAM,KAAK,IAAIJ,GAAGC,GAAGC,CAAC,GACtBG,IAAID,IAAM,KAAK,IAAIJ,GAAGC,GAAGC,CAAC;AAChC,MAAII,IAAIH;AACR,SAAIE,MACED,MAAQJ,IAAGM,IAAI,QAAQL,IAAIC,KAAKG,IAAI,KAAK,KACpCD,MAAQH,IAAGK,IAAI,OAAOJ,IAAIF,KAAKK,IAAI,KACvCC,IAAI,OAAON,IAAIC,KAAKI,IAAI,KAExB;AAAA,IAAE,GAAAC;AAAA,IAAG,GAAGF,IAAMC,IAAID,IAAM;AAAA,IAAG,GAAGA;AAAA,EAAI;AAC3C;AACA,SAASG,EAAS,EAAE,GAAAD,GAAG,GAAAE,GAAG,GAAAC,EAAA,GAAgB;AACxC,QAAMC,IAAA,CAAKb,MAAc;AACvB,UAAMc,KAAKd,IAAIS,IAAI,MAAM;AACzB,WAAOG,IAAIA,IAAID,IAAI,KAAK,IAAI,GAAG,KAAK,IAAIG,GAAG,IAAIA,GAAG,CAAC,CAAC;AAAA,EACtD;AACA,SAAO;AAAA,IAACD,EAAE,CAAC;AAAA,IAAGA,EAAE,CAAC;AAAA,IAAGA,EAAE,CAAC;AAAA,EAAC;AAC1B;A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ACQ,MAAAyD;AAAA,UACN,OAAOU;AAAA,UACG,UAAAR;AAAA,UACV,SAAA,MAAe;AACb,YAAAM,EAASrB,EAASS,CAAY,KAAKW,CAAK,GACxCK,EAAS,IAAI,GACbE,EAAW,EAAK;AAAA,UAClB;AAAA,QACD,CAAA;AAAA,MACE;AAAA,I;A,EAEF,CAAA;AAEX"}
|
|
1
|
+
{"version":3,"file":"ColorField.js","names":["Button","clamp","IconButton","Popover","stepKey","Field","InputBase","useDrag","HiddenValue","droplet","rgbToOklch","toHex","readColor","ColorSwatches","Slider","useEffect","useRef","useState","jsx","jsxs","DEFAULT_LABELS","round","n","digits","rgbToHsv","r","g","b","hue","max","d","h","hsvToRgb","s","v","f","k","write","c","format","withAlpha","rgb","a","L","C","H","body","hex","fromText","text","read","ColorField","label","labelHidden","description","error","value","defaultValue","onChange","alpha","swatches","name","required","disabled","size","labels","className","style","inner","setInner","color","current","draft","setDraft","invalid","setInvalid","area","dragFrom","dropper","setDropper","set","next","out","commit","fromPoint","point","box","_","cancelled","onAreaKey","event","axis","pickFromScreen","picked","swatch","pct","field","props"],"sources":["../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import { type CSSProperties, type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { HiddenValue } from \"../../foundations/HiddenValue/HiddenValue.js\";\nimport { InputBase } from \"../../foundations/InputBase/InputBase.js\";\nimport { stepKey } from \"../../foundations/keys.js\";\nimport { clamp } from \"../../foundations/math.js\";\nimport { droplet } from \"../../icons/droplet.js\";\nimport { type Rgb, rgbToOklch, toHex } from \"../../tokens/color.js\";\nimport { type ColorSwatch, ColorSwatches } from \"../ColorSwatches/ColorSwatches.js\";\nimport { readColor } from \"./read-color.js\";\n\nexport { readColor };\n\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Button } from \"../Button/Button.js\";\nimport { Field } from \"../Field/Field.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Popover } from \"../Popover/Popover.js\";\nimport { Slider } from \"../Slider/Slider.js\";\n\nexport interface ColorFieldTokens {\n swatchSize: string;\n areaHeight: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n colorField: ColorFieldTokens;\n }\n}\n\nexport interface ColorFieldLabels {\n /** Name of the swatch button and the picker panel. */\n pick: string;\n area: string;\n hue: string;\n alpha: string;\n eyedropper: string;\n /** Name of the swatch group in the picker. Default: \"Swatches\". */\n swatches: string;\n /** Error when the typed text is not a colour. */\n invalid: string;\n}\n\nexport interface ColorFieldProps {\n /** The field's label. */\n label: ReactNode;\n /** Visually hide the label (it still names the control). Prefer visible labels. */\n labelHidden?: boolean;\n /** Help text shown below the control and read with it. */\n description?: ReactNode;\n /** Your own error; it replaces the field's own messages. */\n error?: ReactNode;\n /** Any CSS colour; reported back in `format`. */\n value?: string;\n /** The starting colour when uncontrolled, any CSS colour. Default \"black\". */\n defaultValue?: string;\n /** Called when the colour changes (typed, picked or chosen from a swatch), with the colour written in `format`. */\n onChange?: (value: string) => void;\n /** How values are written: six-digit hex, `rgb(51 102 255)` or `oklch(55% 0.21 264)`. */\n format?: \"hex\" | \"rgb\" | \"oklch\";\n /** Let people set opacity (adds an opacity slider and alpha to the value). */\n alpha?: boolean;\n /** Colours offered in the picker: brand colours, presets, or recent colours you keep. */\n swatches?: (ColorSwatch | string)[] | undefined;\n /** Name the colour is submitted under in a form, written in `format`. */\n name?: string;\n /** Marks the field as required and makes its input required in a form. */\n required?: boolean;\n /** Turns off the input and the picker; the colour is not submitted with a form. */\n disabled?: boolean;\n /** Size of the field. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text: the picker's controls and the error for text that is not a colour. */\n labels?: Partial<ColorFieldLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: ColorFieldLabels = {\n pick: \"Choose colour\",\n area: \"Saturation and brightness\",\n hue: \"Hue\",\n alpha: \"Opacity\",\n eyedropper: \"Pick a colour from the screen\",\n swatches: \"Swatches\",\n invalid: \"Enter a colour such as rgb(51 102 255), a hex code or a colour name.\",\n};\n\ninterface Hsva {\n h: number;\n s: number;\n v: number;\n a: number;\n}\n\nconst round = (n: number, digits = 0) => Number(n.toFixed(digits));\n\nfunction rgbToHsv([r, g, b]: Rgb, hue = 0): Omit<Hsva, \"a\"> {\n const max = Math.max(r, g, b);\n const d = max - Math.min(r, g, b);\n let h = hue;\n if (d) {\n if (max === r) h = 60 * (((g - b) / d + 6) % 6);\n else if (max === g) h = 60 * ((b - r) / d + 2);\n else h = 60 * ((r - g) / d + 4);\n }\n return { h, s: max ? d / max : 0, v: max };\n}\nfunction hsvToRgb({ h, s, v }: Hsva): Rgb {\n const f = (n: number) => {\n const k = (n + h / 60) % 6;\n return v - v * s * Math.max(0, Math.min(k, 4 - k, 1));\n };\n return [f(5), f(3), f(1)];\n}\n\nfunction write(c: Hsva, format: ColorFieldProps[\"format\"], withAlpha: boolean): string {\n const rgb = hsvToRgb(c);\n const a = withAlpha ? round(c.a, 2) : 1;\n if (format === \"rgb\") {\n const [r, g, b] = rgb.map((n) => Math.round(n * 255));\n return a < 1 ? `rgb(${r} ${g} ${b} / ${a})` : `rgb(${r} ${g} ${b})`;\n }\n if (format === \"oklch\") {\n const [L, C, H] = rgbToOklch(rgb);\n const body = `${round(L * 100, 1)}% ${round(C, 3)} ${round(C < 0.0005 ? 0 : H, 1)}`;\n return a < 1 ? `oklch(${body} / ${a})` : `oklch(${body})`;\n }\n const hex = toHex(rgb);\n return a < 1\n ? `${hex}${Math.round(a * 255)\n .toString(16)\n .padStart(2, \"0\")}`\n : hex;\n}\n\nconst fromText = (text: string, hue = 0): Hsva | null => {\n const read = readColor(text);\n return read ? { ...rgbToHsv(read.rgb, hue), a: read.a } : null;\n};\n\ntype EyeDropperCtor = new () => { open: () => Promise<{ sRGBHex: string }> };\n\n/** A colour input: type any CSS colour, or pick one with a saturation area, hue and opacity sliders, or the screen. */\nexport function ColorField({\n label,\n labelHidden,\n description,\n error,\n value,\n defaultValue = \"black\",\n onChange,\n format = \"hex\",\n alpha = false,\n swatches,\n name,\n required,\n disabled,\n size = \"md\",\n labels,\n className,\n style,\n}: ColorFieldProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const [inner, setInner] = useState(() => fromText(defaultValue) ?? { h: 0, s: 0, v: 0, a: 1 });\n const external = value === undefined ? null : fromText(value, inner.h);\n const color = external ?? inner;\n const current = write(color, format, alpha);\n const [draft, setDraft] = useState<string | null>(null);\n const [invalid, setInvalid] = useState(false);\n const area = useRef<HTMLDivElement>(null);\n const dragFrom = useRef<Hsva | null>(null);\n const [dropper, setDropper] = useState(false);\n useEffect(() => setDropper(typeof window !== \"undefined\" && \"EyeDropper\" in window), []);\n\n const set = (next: Hsva) => {\n const out = write(next, format, alpha);\n if (value === undefined) setInner(next);\n else setInner((c) => ({ ...c, h: next.h }));\n setDraft(null);\n setInvalid(false);\n if (out !== current) onChange?.(out);\n };\n const commit = () => {\n if (draft === null) return;\n const next = fromText(draft, color.h);\n if (next) set(alpha ? next : { ...next, a: 1 });\n else setInvalid(true);\n };\n\n const fromPoint = (point: { x: number; y: number }) => {\n const box = (area.current as HTMLDivElement).getBoundingClientRect();\n set({\n ...color,\n s: clamp((point.x - box.left) / box.width),\n v: 1 - clamp((point.y - box.top) / box.height),\n });\n };\n // Dragging in the area through detent; Escape puts the colour back.\n useDrag(area, {\n onStart: ({ point }) => {\n dragFrom.current = color;\n area.current?.focus();\n fromPoint(point);\n },\n onMove: ({ point }) => fromPoint(point),\n onEnd: (_, cancelled) => {\n if (cancelled) set(dragFrom.current as Hsva);\n },\n });\n const onAreaKey = (event: KeyboardEvent<HTMLDivElement>) => {\n // Saturation along x, brightness along y; Shift for bigger steps.\n const axis = { min: 0, max: 1, step: 0.01, arrowsOnly: true };\n const s = stepKey(event, { ...axis, value: color.s, axis: \"x\" });\n const v = stepKey(event, { ...axis, value: color.v, axis: \"y\" });\n if (s === undefined && v === undefined) return;\n event.preventDefault();\n set({ ...color, s: s ?? color.s, v: v ?? color.v });\n };\n const pickFromScreen = async () => {\n try {\n const picked = await new (window as unknown as { EyeDropper: EyeDropperCtor }).EyeDropper().open();\n const next = fromText(picked.sRGBHex, color.h);\n if (next) set({ ...next, a: color.a });\n } catch {\n // Cancelled (Escape) or refused: nothing to do.\n }\n };\n\n const swatch = `rgb(${hsvToRgb(color)\n .map((n) => Math.round(n * 255))\n .join(\" \")} / ${alpha ? color.a : 1})`;\n const pct = (n: number) => Math.round(n * 100);\n\n return (\n <Field\n label={label}\n labelHidden={labelHidden}\n description={description}\n error={error ?? (invalid ? text.invalid : undefined)}\n required={required}\n size={size}\n className={className ? `cy-color-field ${className}` : \"cy-color-field\"}\n style={style}\n >\n {(field) => (\n <div\n className=\"cy-text-field cy-color-field-control\"\n data-size={size}\n data-invalid={field.invalid || undefined}\n data-disabled={disabled || undefined}\n >\n <Popover\n label={text.pick}\n size=\"sm\"\n placement=\"bottom\"\n trigger={(props) => (\n <Button\n {...props}\n variant=\"ghost\"\n size=\"sm\"\n disabled={disabled}\n aria-label={text.pick}\n className=\"cy-color-field-trigger\"\n >\n <span\n className=\"cy-color-field-swatch cy-reset\"\n style={{ \"--_c\": swatch } as CSSProperties}\n />\n </Button>\n )}\n >\n <div className=\"cy-color-field-picker cy-reset\">\n <div\n ref={area}\n role=\"slider\"\n tabIndex={0}\n aria-label={text.area}\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={pct(color.s)}\n aria-valuetext={`${text.area}: ${pct(color.s)}%, ${pct(color.v)}%`}\n className=\"cy-color-field-area cy-reset\"\n style={\n {\n \"--_hue\": `hsl(${round(color.h)} 100% 50%)`,\n \"--_x\": `${color.s * 100}%`,\n \"--_y\": `${(1 - color.v) * 100}%`,\n } as CSSProperties\n }\n onKeyDown={onAreaKey}\n >\n <span className=\"cy-color-field-area-thumb cy-reset\" />\n </div>\n <Slider\n label={text.hue}\n labelHidden\n min={0}\n max={360}\n value={round(color.h)}\n onChange={(h) => set({ ...color, h: h as number })}\n className=\"cy-color-field-hue\"\n />\n {alpha && (\n <Slider\n label={text.alpha}\n labelHidden\n min={0}\n max={100}\n value={pct(color.a)}\n labels={{ value: (v) => `${v}%` }}\n onChange={(a) => set({ ...color, a: (a as number) / 100 })}\n className=\"cy-color-field-alpha\"\n style={\n {\n \"--_c\": `rgb(${hsvToRgb(color)\n .map((n) => Math.round(n * 255))\n .join(\" \")})`,\n } as CSSProperties\n }\n />\n )}\n {swatches && swatches.length > 0 && (\n <ColorSwatches\n label={text.swatches}\n swatches={swatches}\n size=\"sm\"\n value={current}\n onChange={(v) => {\n const next = fromText(v);\n if (next) set(next);\n }}\n />\n )}\n </div>\n </Popover>\n <InputBase\n id={field.id}\n className=\"cy-text-field-input\"\n aria-describedby={field.describedBy}\n invalid={field.invalid}\n required={required}\n disabled={disabled}\n autoComplete=\"off\"\n spellCheck={false}\n value={draft ?? current}\n onChange={(e) => {\n setDraft(e.currentTarget.value);\n setInvalid(false);\n }}\n onBlur={commit}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") commit();\n }}\n />\n {dropper && !disabled && (\n <IconButton\n icon={droplet}\n label={text.eyedropper}\n variant=\"ghost\"\n size=\"sm\"\n onClick={pickFromScreen}\n />\n )}\n <HiddenValue\n name={name}\n value={current}\n disabled={disabled}\n onReset={() => {\n setInner(fromText(defaultValue) ?? inner);\n setDraft(null);\n setInvalid(false);\n }}\n />\n </div>\n )}\n </Field>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiFA,IAAMoB,KAAmC;AAAA,EACvC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,SAAS;AACX,GASMC,IAAA,CAASC,GAAWC,IAAS,MAAM,OAAOD,EAAE,QAAQC,CAAM,CAAC;AAEjE,SAASC,GAAS,CAACC,GAAGC,GA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,MAAM;AACf,wBAAM+C,IAAOjC,EAASd,CAAC;AACvB,kBAAI+C,KAAMD,EAAIC,CAAI;AAAA,gBACpB;AAAA,cACD,CAAA;AAAA,YAEA;AAAA,U;A,QACE,CAAA;AAAA,QACT,gBAAA/D,EAACZ,IAAD;AAAA,UACE,IAAI0F,EAAM;AAAA,UACV,WAAU;AAAA,UACV,oBAAkBA,EAAM;AAAA,UACxB,SAASA,EAAM;AAAA,UACL,UAAAlC;AAAA,UACA,UAAAC;AAAA,UACV,cAAa;AAAA,UACb,YAAY;AAAA,UACZ,OAAOS,KAASD;AAAA,UAChB,UAAA,CAAW,MAAM;AACf,YAAAE,EAAS,EAAE,cAAc,KAAK,GAC9BE,EAAW,EAAK;AAAA,UAClB;AAAA,UACA,QAAQQ;AAAA,UACR,WAAA,CAAY,MAAM;AAChB,YAAI,EAAE,QAAQ,WAASA,EAAO;AAAA,UAChC;AAAA,QACD,CAAA;AAAA,QACAL,KAAW,CAACf,KACX,gBAAA7C,EAAChB,GAAD;AAAA,UACE,MAAMO;AAAA,UACN,OAAOwC,EAAK;AAAA,UACZ,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,SAAS2C;AAAA,QACV,CAAA;AAAA,QAEH,gBAAA1E,EAACV,IAAD;AAAA,UACQ,MAAAqD;AAAA,UACN,OAAOU;AAAA,UACG,UAAAR;AAAA,UACV,SAAA,MAAe;AACb,YAAAM,EAASrB,EAASS,CAAY,KAAKW,CAAK,GACxCK,EAAS,IAAI,GACbE,EAAW,EAAK;AAAA,UAClB;AAAA,QACD,CAAA;AAAA,MACE;AAAA,I;A,EAEF,CAAA;AAEX"}
|
|
@@ -20,12 +20,17 @@ export interface ColorSwatch {
|
|
|
20
20
|
export interface ColorSwatchesProps {
|
|
21
21
|
/** Accessible name of the group, e.g. "Recent colours". */
|
|
22
22
|
label: string;
|
|
23
|
+
/** The colours to offer: a CSS colour, or `{ value, label }` to give it a spoken name. */
|
|
23
24
|
swatches: (ColorSwatch | string)[];
|
|
24
25
|
/** The chosen colour, matched by colour (so "#FFF" and "white" are the same swatch). */
|
|
25
26
|
value?: string | undefined;
|
|
27
|
+
/** Called when a swatch is chosen (pressed, or reached with the arrow keys), with that swatch's `value`. */
|
|
26
28
|
onChange: (value: string) => void;
|
|
29
|
+
/** No swatch can be chosen. */
|
|
27
30
|
disabled?: boolean;
|
|
31
|
+
/** Size of each swatch. Default "md". */
|
|
28
32
|
size?: Size;
|
|
33
|
+
/** Added to the root element, for layout. */
|
|
29
34
|
className?: string;
|
|
30
35
|
/** Layout only. Restyle through --cy-color-swatches-* tokens. */
|
|
31
36
|
style?: CSSProperties;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { ButtonBase as f } from "../../foundations/ButtonBase/ButtonBase.js";
|
|
3
3
|
import { Icon as g } from "../../foundations/Icon/Icon.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { useRovingFocus as y } from "../../foundations/roving-focus.js";
|
|
5
|
+
import { check as b } from "../../icons/check.js";
|
|
6
|
+
import { luminance as w } from "../../tokens/color.js";
|
|
7
7
|
import { readColor as m } from "../ColorField/read-color.js";
|
|
8
8
|
import { useRef as k } from "react";
|
|
9
9
|
import { jsx as s } from "react/jsx-runtime";
|
|
@@ -12,11 +12,11 @@ var d = (a) => {
|
|
|
12
12
|
return r ? `${r.rgb.map((e) => Math.round(e * 255)).join(",")}/${Math.round(r.a * 100)}` : a;
|
|
13
13
|
}, $ = (a) => {
|
|
14
14
|
const r = m(a);
|
|
15
|
-
return r ?
|
|
15
|
+
return r ? w(r.rgb) : 1;
|
|
16
16
|
};
|
|
17
17
|
function N({ label: a, swatches: r, value: e, onChange: t, disabled: n = !1, size: v = "md", className: i, style: h }) {
|
|
18
18
|
const u = k(null);
|
|
19
|
-
|
|
19
|
+
y(u, {
|
|
20
20
|
orientation: "both",
|
|
21
21
|
selector: '[role="radio"]'
|
|
22
22
|
});
|
|
@@ -43,7 +43,7 @@ function N({ label: a, swatches: r, value: e, onChange: t, disabled: n = !1, siz
|
|
|
43
43
|
onClick: () => t(o.value),
|
|
44
44
|
onFocus: () => c !== void 0 && !l && t(o.value),
|
|
45
45
|
children: l && /* @__PURE__ */ s(g, {
|
|
46
|
-
icon:
|
|
46
|
+
icon: b,
|
|
47
47
|
size: "sm"
|
|
48
48
|
})
|
|
49
49
|
}, o.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorSwatches.js","names":["ButtonBase","Icon","
|
|
1
|
+
{"version":3,"file":"ColorSwatches.js","names":["ButtonBase","Icon","useRovingFocus","check","luminance","readColor","useRef","jsx","key","text","c","n","lightness","ColorSwatches","label","swatches","value","onChange","disabled","size","className","style","group","chosen","items","s","item","on"],"sources":["../../../src/components/ColorSwatches/ColorSwatches.tsx"],"sourcesContent":["import { type CSSProperties, useRef } from \"react\";\nimport { ButtonBase } from \"../../foundations/ButtonBase/ButtonBase.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { useRovingFocus } from \"../../foundations/roving-focus.js\";\nimport { check } from \"../../icons/check.js\";\nimport { luminance } from \"../../tokens/color.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { readColor } from \"../ColorField/read-color.js\";\n\nexport interface ColorSwatchesTokens {\n /** Swatch size at `md`. */\n size: string;\n /** Corner radius of a swatch. */\n radius: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n colorSwatches: ColorSwatchesTokens;\n }\n}\n\nexport interface ColorSwatch {\n /** Any CSS colour. */\n value: string;\n /** Spoken name, e.g. \"Brand red\". Default: the value. */\n label?: string;\n}\n\nexport interface ColorSwatchesProps {\n /** Accessible name of the group, e.g. \"Recent colours\". */\n label: string;\n /** The colours to offer: a CSS colour, or `{ value, label }` to give it a spoken name. */\n swatches: (ColorSwatch | string)[];\n /** The chosen colour, matched by colour (so \"#FFF\" and \"white\" are the same swatch). */\n value?: string | undefined;\n /** Called when a swatch is chosen (pressed, or reached with the arrow keys), with that swatch's `value`. */\n onChange: (value: string) => void;\n /** No swatch can be chosen. */\n disabled?: boolean;\n /** Size of each swatch. Default \"md\". */\n size?: Size;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-color-swatches-* tokens. */\n style?: CSSProperties;\n}\n\n/** A colour's identity for matching: its rgb and alpha rounded, whatever syntax it was written in. */\nconst key = (text: string | undefined) => {\n const c = text ? readColor(text) : null;\n return c ? `${c.rgb.map((n) => Math.round(n * 255)).join(\",\")}/${Math.round(c.a * 100)}` : text;\n};\n/** Relative luminance (sRGB), to pick a tick that shows on the swatch. */\nconst lightness = (text: string) => {\n const c = readColor(text);\n return c ? luminance(c.rgb) : 1;\n};\n\n/**\n * A palette to pick a colour from: brand colours, recent colours, presets. An APG radio group: one tab stop, arrow keys\n * move and choose. Each swatch is named, and the chosen one shows a tick that contrasts with it.\n */\nexport function ColorSwatches({\n label,\n swatches,\n value,\n onChange,\n disabled = false,\n size = \"md\",\n className,\n style,\n}: ColorSwatchesProps) {\n const group = useRef<HTMLDivElement>(null);\n useRovingFocus(group, { orientation: \"both\", selector: '[role=\"radio\"]' });\n const chosen = key(value);\n const items = swatches.map((s) => (typeof s === \"string\" ? { value: s } : s));\n return (\n <div\n ref={group}\n role=\"radiogroup\"\n aria-label={label}\n aria-disabled={disabled || undefined}\n className={className ? `cy-color-swatches ${className}` : \"cy-color-swatches\"}\n data-size={size}\n style={style}\n >\n {items.map((item) => {\n const on = chosen !== undefined && key(item.value) === chosen;\n return (\n <ButtonBase\n key={item.value}\n role=\"radio\"\n aria-checked={on}\n aria-label={item.label ?? item.value}\n disabled={disabled}\n data-roving=\"\"\n className=\"cy-color-swatches-swatch cy-reset\"\n data-light={lightness(item.value) > 0.4 ? \"\" : undefined}\n style={{ \"--_swatch\": item.value } as CSSProperties}\n onClick={() => onChange(item.value)}\n // Arrow keys move focus (roving); in a radio group the focused swatch is chosen too, once one is.\n onFocus={() => chos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