@arshad-shah/cynosure 0.3.0 → 0.4.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/adapters/astro/index.d.ts +52 -0
- package/dist/adapters/astro/index.js +27 -0
- package/dist/adapters/astro/index.js.map +1 -0
- package/dist/adapters/vite/index.d.ts +11 -0
- package/dist/adapters/vite/index.js +33 -12
- package/dist/adapters/vite/index.js.map +1 -1
- package/dist/brands/googleplay.d.ts +2 -0
- package/dist/brands/googleplay.js +17 -0
- package/dist/brands/googleplay.js.map +1 -0
- package/dist/brands/index.d.ts +1 -0
- package/dist/brands/index.js +132 -130
- package/dist/components/Announcer/Announcer.js +5 -5
- package/dist/components/Announcer/Announcer.js.map +1 -1
- package/dist/components/AppShell/AppShell.js +50 -53
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/Avatar/Avatar.js +20 -20
- package/dist/components/Avatar/Avatar.js.map +1 -1
- package/dist/components/Button/Button.d.ts +17 -3
- package/dist/components/Button/Button.js +51 -44
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.js +69 -69
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Card/Card.d.ts +8 -1
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.d.ts +4 -4
- package/dist/components/Checkbox/Checkbox.js +33 -8
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Checklist/Checklist.js +21 -21
- package/dist/components/Checklist/Checklist.js.map +1 -1
- package/dist/components/Choice/Choice.d.ts +73 -0
- package/dist/components/Choice/Choice.js +41 -0
- package/dist/components/Choice/Choice.js.map +1 -0
- package/dist/components/Choice/index.d.ts +1 -0
- package/dist/components/ColorField/ColorField.js +198 -207
- package/dist/components/ColorField/ColorField.js.map +1 -1
- package/dist/components/Combobox/Combobox.js +86 -115
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/Container/Container.d.ts +2 -2
- package/dist/components/Container/Container.js +17 -13
- package/dist/components/Container/Container.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.js +29 -28
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DeviceFrame/DeviceFrame.d.ts +63 -0
- package/dist/components/DeviceFrame/DeviceFrame.js +54 -0
- package/dist/components/DeviceFrame/DeviceFrame.js.map +1 -0
- package/dist/components/DeviceFrame/index.d.ts +1 -0
- package/dist/components/Dialog/Dialog.d.ts +10 -1
- package/dist/components/Dialog/Dialog.js +82 -77
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.d.ts +5 -2
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/Field/Field.js +31 -33
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/FileDrop/FileDrop.js +14 -14
- package/dist/components/FileDrop/FileDrop.js.map +1 -1
- package/dist/components/FloatingToolbar/FloatingToolbar.js +7 -6
- package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
- package/dist/components/Grid/Grid.d.ts +32 -11
- package/dist/components/Grid/Grid.js +68 -46
- 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 +4 -2
- package/dist/components/Heading/Heading.js.map +1 -1
- package/dist/components/IconButton/IconButton.d.ts +16 -1
- package/dist/components/IconButton/IconButton.js +14 -10
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/IconTile/IconTile.d.ts +45 -0
- package/dist/components/IconTile/IconTile.js +25 -0
- package/dist/components/IconTile/IconTile.js.map +1 -0
- package/dist/components/IconTile/index.d.ts +1 -0
- package/dist/components/Image/Image.js.map +1 -1
- package/dist/components/Inline/Inline.d.ts +3 -3
- package/dist/components/Inline/Inline.js +12 -22
- package/dist/components/Inline/Inline.js.map +1 -1
- package/dist/components/KeyValueEditor/KeyValueEditor.js +37 -36
- package/dist/components/KeyValueEditor/KeyValueEditor.js.map +1 -1
- package/dist/components/Link/Link.d.ts +9 -1
- package/dist/components/Link/Link.js +20 -18
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/List/List.d.ts +73 -0
- package/dist/components/List/List.js +64 -0
- package/dist/components/List/List.js.map +1 -0
- package/dist/components/List/index.d.ts +1 -0
- package/dist/components/Notice/Notice.js +12 -11
- package/dist/components/Notice/Notice.js.map +1 -1
- package/dist/components/OptionList/OptionList.d.ts +69 -0
- package/dist/components/OptionList/OptionList.js +75 -0
- package/dist/components/OptionList/OptionList.js.map +1 -0
- package/dist/components/OptionList/index.d.ts +1 -0
- package/dist/components/PageHeader/PageHeader.d.ts +6 -0
- package/dist/components/PageHeader/PageHeader.js +27 -27
- package/dist/components/PageHeader/PageHeader.js.map +1 -1
- package/dist/components/Pagination/Pagination.js +31 -30
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/QRCode/QRCode.d.ts +56 -0
- package/dist/components/QRCode/QRCode.js +48 -0
- package/dist/components/QRCode/QRCode.js.map +1 -0
- package/dist/components/QRCode/index.d.ts +1 -0
- package/dist/components/RadioGroup/RadioGroup.js +32 -24
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/Section/Section.d.ts +57 -0
- package/dist/components/Section/Section.js +27 -0
- package/dist/components/Section/Section.js.map +1 -0
- package/dist/components/Section/index.d.ts +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +12 -12
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.js +106 -133
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Sheet/Sheet.js +12 -7
- package/dist/components/Sheet/Sheet.js.map +1 -1
- package/dist/components/SideNav/SideNav.js +55 -53
- package/dist/components/SideNav/SideNav.js.map +1 -1
- package/dist/components/SiteFooter/SiteFooter.d.ts +66 -0
- package/dist/components/SiteFooter/SiteFooter.js +80 -0
- package/dist/components/SiteFooter/SiteFooter.js.map +1 -0
- package/dist/components/SiteFooter/index.d.ts +1 -0
- package/dist/components/SiteHeader/SiteHeader.d.ts +78 -0
- package/dist/components/SiteHeader/SiteHeader.js +114 -0
- package/dist/components/SiteHeader/SiteHeader.js.map +1 -0
- package/dist/components/SiteHeader/index.d.ts +1 -0
- package/dist/components/SkipLink/SkipLink.d.ts +42 -0
- package/dist/components/SkipLink/SkipLink.js +43 -0
- package/dist/components/SkipLink/SkipLink.js.map +1 -0
- package/dist/components/SkipLink/index.d.ts +1 -0
- package/dist/components/SortableList/SortableList.js +13 -13
- package/dist/components/SortableList/SortableList.js.map +1 -1
- package/dist/components/Stack/Stack.d.ts +16 -7
- package/dist/components/Stack/Stack.js +25 -18
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/index.d.ts +1 -1
- package/dist/components/Stack/space.d.ts +29 -0
- package/dist/components/Stack/space.js +16 -5
- package/dist/components/Stack/space.js.map +1 -1
- package/dist/components/Stat/Stat.d.ts +88 -0
- package/dist/components/Stat/Stat.js +105 -0
- package/dist/components/Stat/Stat.js.map +1 -0
- package/dist/components/Stat/index.d.ts +1 -0
- package/dist/components/Steps/Steps.d.ts +10 -4
- package/dist/components/Steps/Steps.js +31 -30
- package/dist/components/Steps/Steps.js.map +1 -1
- package/dist/components/Switch/Switch.d.ts +4 -4
- package/dist/components/Switch/Switch.js +18 -7
- package/dist/components/Switch/Switch.js.map +1 -1
- package/dist/components/Table/Table.js +11 -12
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +4 -1
- package/dist/components/Tabs/Tabs.js +71 -70
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TagInput/TagInput.js +76 -97
- package/dist/components/TagInput/TagInput.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +4 -0
- package/dist/components/TextField/TextField.js +30 -29
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/ThemeToggle/ThemeToggle.d.ts +7 -1
- package/dist/components/ThemeToggle/ThemeToggle.js +33 -30
- package/dist/components/ThemeToggle/ThemeToggle.js.map +1 -1
- package/dist/components/Toast/Toast.js +22 -20
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +6 -1
- package/dist/components/Tooltip/Tooltip.js +19 -19
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.js +17 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.js.map +1 -0
- package/dist/components/VisuallyHidden/index.d.ts +1 -0
- package/dist/foundations/ChoiceBase/ChoiceBase.js +8 -8
- package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
- package/dist/foundations/HiddenValue/HiddenValue.js +5 -5
- package/dist/foundations/HiddenValue/HiddenValue.js.map +1 -1
- package/dist/foundations/Icon/Icon.d.ts +6 -1
- package/dist/foundations/Icon/Icon.js +15 -14
- package/dist/foundations/Icon/Icon.js.map +1 -1
- package/dist/foundations/image-outcome.d.ts +8 -3
- package/dist/foundations/image-outcome.js +12 -8
- package/dist/foundations/image-outcome.js.map +1 -1
- package/dist/foundations/printing.d.ts +6 -0
- package/dist/foundations/printing.js +17 -0
- package/dist/foundations/printing.js.map +1 -0
- package/dist/foundations/qr.d.ts +42 -0
- package/dist/foundations/qr.js +246 -0
- package/dist/foundations/qr.js.map +1 -0
- package/dist/icons/book-marked.d.ts +2 -0
- package/dist/icons/book-marked.js +14 -0
- package/dist/icons/book-marked.js.map +1 -0
- package/dist/icons/calendar-days.d.ts +2 -0
- package/dist/icons/calendar-days.js +24 -0
- package/dist/icons/calendar-days.js.map +1 -0
- package/dist/icons/check-square.d.ts +2 -0
- package/dist/icons/check-square.js +14 -0
- package/dist/icons/check-square.js.map +1 -0
- package/dist/icons/crescent.d.ts +2 -0
- package/dist/icons/crescent.js +14 -0
- package/dist/icons/crescent.js.map +1 -0
- package/dist/icons/index.d.ts +10 -0
- package/dist/icons/index.js +436 -416
- package/dist/icons/kaaba.d.ts +2 -0
- package/dist/icons/kaaba.js +14 -0
- package/dist/icons/kaaba.js.map +1 -0
- package/dist/icons/keywords.d.ts +11 -1
- package/dist/icons/keywords.js +89 -1
- package/dist/icons/keywords.js.map +1 -1
- package/dist/icons/list-tree.d.ts +2 -0
- package/dist/icons/list-tree.js +14 -0
- package/dist/icons/list-tree.js.map +1 -0
- package/dist/icons/mosque.d.ts +2 -0
- package/dist/icons/mosque.js +14 -0
- package/dist/icons/mosque.js.map +1 -0
- package/dist/icons/prayer-beads.d.ts +2 -0
- package/dist/icons/prayer-beads.js +67 -0
- package/dist/icons/prayer-beads.js.map +1 -0
- package/dist/icons/qr-code.d.ts +2 -0
- package/dist/icons/qr-code.js +38 -0
- package/dist/icons/qr-code.js.map +1 -0
- package/dist/icons/refresh-cw.d.ts +2 -0
- package/dist/icons/refresh-cw.js +14 -0
- package/dist/icons/refresh-cw.js.map +1 -0
- package/dist/icons/types.d.ts +1 -1
- package/dist/icons/types.js +2 -1
- package/dist/icons/types.js.map +1 -1
- package/dist/index.d.ts +16 -2
- package/dist/index.js +274 -241
- package/dist/styles/announcer.css +1 -1
- package/dist/styles/app-shell.css +1 -1
- package/dist/styles/avatar.css +1 -1
- package/dist/styles/base.css +1 -1
- package/dist/styles/button.css +1 -1
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/choice-base.css +1 -0
- package/dist/styles/choice.css +1 -1
- package/dist/styles/color-field.css +1 -1
- package/dist/styles/combobox.css +1 -1
- package/dist/styles/copy-button.css +1 -1
- package/dist/styles/date-field.css +1 -1
- package/dist/styles/device-frame.css +1 -0
- package/dist/styles/dialog.css +1 -1
- package/dist/styles/disclosure.css +1 -1
- package/dist/styles/field.css +1 -1
- package/dist/styles/file-drop.css +1 -1
- package/dist/styles/floating-toolbar.css +1 -1
- 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 -1
- package/dist/styles/icon-tile.css +1 -0
- package/dist/styles/icon.css +1 -1
- package/dist/styles/inline.css +1 -0
- package/dist/styles/key-value-editor.css +1 -1
- package/dist/styles/link.css +1 -1
- package/dist/styles/list.css +1 -0
- package/dist/styles/manifest.json +715 -0
- package/dist/styles/notice.css +1 -1
- package/dist/styles/number-field.css +1 -1
- package/dist/styles/option-list.css +1 -0
- package/dist/styles/pagination.css +1 -1
- package/dist/styles/qr-code.css +1 -0
- package/dist/styles/radio-group.css +1 -1
- package/dist/styles/section.css +1 -0
- package/dist/styles/segmented-control.css +1 -1
- package/dist/styles/select.css +1 -1
- package/dist/styles/sheet.css +1 -1
- package/dist/styles/side-nav.css +1 -1
- package/dist/styles/site-footer.css +1 -0
- package/dist/styles/site-header.css +1 -0
- package/dist/styles/skip-link.css +1 -0
- package/dist/styles/sortable-list.css +1 -1
- package/dist/styles/stack.css +1 -1
- package/dist/styles/stat.css +1 -0
- package/dist/styles/steps.css +1 -1
- package/dist/styles/switch.css +1 -0
- package/dist/styles/table.css +1 -1
- package/dist/styles/tabs.css +1 -1
- package/dist/styles/tag-input.css +1 -1
- package/dist/styles/text-field.css +1 -1
- package/dist/styles/time-field.css +1 -1
- package/dist/styles/toast.css +1 -1
- package/dist/styles/visually-hidden.css +1 -0
- package/dist/styles.css +1 -1
- package/dist/tokens/create-theme.js +137 -108
- package/dist/tokens/create-theme.js.map +1 -1
- package/package.json +6 -1
- package/dist/components/Checkbox/ChoiceRow.d.ts +0 -39
- package/dist/components/Checkbox/ChoiceRow.js +0 -58
- package/dist/components/Checkbox/ChoiceRow.js.map +0 -1
- package/dist/styles/hidden-value.css +0 -1
- package/dist/styles/iconbutton.css +0 -1
- package/dist/styles/search-field.css +0 -1
|
@@ -6,7 +6,7 @@ import { FileInputBase as J, setInputFiles as K } from "../../foundations/FileIn
|
|
|
6
6
|
import { upload as W } from "../../icons/upload.js";
|
|
7
7
|
import { useEffect as M, useId as Q, useRef as N, useState as C } from "react";
|
|
8
8
|
import { jsx as o, jsxs as k } from "react/jsx-runtime";
|
|
9
|
-
var X = (t, n,
|
|
9
|
+
var X = (t, n, f) => `${t} ${t === 1 ? n : f}`, Z = {
|
|
10
10
|
prompt: "Drop files here, or",
|
|
11
11
|
choose: "Choose files",
|
|
12
12
|
chooseOne: "Choose a file",
|
|
@@ -16,16 +16,16 @@ var X = (t, n, d) => `${t} ${t === 1 ? n : d}`, Z = {
|
|
|
16
16
|
};
|
|
17
17
|
function ee(t, n) {
|
|
18
18
|
if (!n) return !0;
|
|
19
|
-
const
|
|
20
|
-
return n.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean).some((s) => s.startsWith(".") ?
|
|
19
|
+
const f = t.name.toLowerCase(), p = t.type.toLowerCase();
|
|
20
|
+
return n.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean).some((s) => s.startsWith(".") ? f.endsWith(s) : s.endsWith("/*") ? p.startsWith(s.slice(0, -1)) : p === s);
|
|
21
21
|
}
|
|
22
|
-
function ce({ onFiles: t, onReject: n, accept:
|
|
22
|
+
function ce({ onFiles: t, onReject: n, accept: f, multiple: p = !1, maxSize: s, maxFiles: P, hint: w, target: S = "zone", name: A, form: _, required: b, disabled: a = !1, size: I = "md", labels: R, className: j, style: U }) {
|
|
23
23
|
const l = {
|
|
24
24
|
...Z,
|
|
25
25
|
...R
|
|
26
|
-
}, T = Q(), y = N(null),
|
|
26
|
+
}, T = Q(), y = N(null), d = N(0), [E, L] = C(!1), [V, Y] = C(""), [$, q] = C([]), g = (r, x) => {
|
|
27
27
|
const i = [], c = [], D = p ? P ?? Number.POSITIVE_INFINITY : 1;
|
|
28
|
-
for (const e of r) ee(e,
|
|
28
|
+
for (const e of r) ee(e, f) ? s !== void 0 && e.size > s ? c.push({
|
|
29
29
|
file: e,
|
|
30
30
|
reason: "size"
|
|
31
31
|
}) : i.length >= D ? c.push({
|
|
@@ -37,7 +37,7 @@ function ce({ onFiles: t, onReject: n, accept: d, multiple: p = !1, maxSize: s,
|
|
|
37
37
|
});
|
|
38
38
|
y.current && (x || c.length) && K(y.current, i), q(c.map(l.rejected)), Y(i.length ? l.added(i.length) : ""), i.length && t?.(i), c.length && n?.(c);
|
|
39
39
|
}, u = (r) => [...r.dataTransfer?.types ?? []].includes("Files"), m = () => {
|
|
40
|
-
|
|
40
|
+
d.current = 0, L(!1);
|
|
41
41
|
}, z = N(g);
|
|
42
42
|
z.current = g;
|
|
43
43
|
const h = S === "window", O = N(null);
|
|
@@ -45,13 +45,13 @@ function ce({ onFiles: t, onReject: n, accept: d, multiple: p = !1, maxSize: s,
|
|
|
45
45
|
if (!h || a) return;
|
|
46
46
|
const D = [
|
|
47
47
|
["dragenter", (e) => {
|
|
48
|
-
u(e) && (e.preventDefault(),
|
|
48
|
+
u(e) && (e.preventDefault(), d.current += 1, L(!0));
|
|
49
49
|
}],
|
|
50
50
|
["dragover", (e) => {
|
|
51
51
|
!u(e) || !e.dataTransfer || (e.preventDefault(), e.dataTransfer.dropEffect = "copy");
|
|
52
52
|
}],
|
|
53
53
|
["dragleave", () => {
|
|
54
|
-
|
|
54
|
+
d.current -= 1, d.current <= 0 && m();
|
|
55
55
|
}],
|
|
56
56
|
["drop", (e) => {
|
|
57
57
|
!u(e) || !e.dataTransfer || (e.preventDefault(), m(), z.current([...e.dataTransfer.files], !0));
|
|
@@ -72,13 +72,13 @@ function ce({ onFiles: t, onReject: n, accept: d, multiple: p = !1, maxSize: s,
|
|
|
72
72
|
"data-invalid": $.length ? "" : void 0,
|
|
73
73
|
style: U,
|
|
74
74
|
onDragEnter: (r) => {
|
|
75
|
-
!v || a || !u(r) || (r.preventDefault(),
|
|
75
|
+
!v || a || !u(r) || (r.preventDefault(), d.current += 1, L(!0));
|
|
76
76
|
},
|
|
77
77
|
onDragOver: (r) => {
|
|
78
78
|
!v || a || !u(r) || (r.preventDefault(), r.dataTransfer.dropEffect = "copy");
|
|
79
79
|
},
|
|
80
80
|
onDragLeave: () => {
|
|
81
|
-
v && (
|
|
81
|
+
v && (d.current -= 1, d.current <= 0 && m());
|
|
82
82
|
},
|
|
83
83
|
onDrop: (r) => {
|
|
84
84
|
!v || a || (r.preventDefault(), m(), g([...r.dataTransfer.files], !0));
|
|
@@ -120,7 +120,7 @@ function ce({ onFiles: t, onReject: n, accept: d, multiple: p = !1, maxSize: s,
|
|
|
120
120
|
})
|
|
121
121
|
}),
|
|
122
122
|
/* @__PURE__ */ o("span", {
|
|
123
|
-
className: "cy-file-drop-status cy-reset",
|
|
123
|
+
className: "cy-file-drop-status cy-reset cy-visually-hidden",
|
|
124
124
|
role: "status",
|
|
125
125
|
children: V
|
|
126
126
|
}),
|
|
@@ -140,10 +140,10 @@ function ce({ onFiles: t, onReject: n, accept: d, multiple: p = !1, maxSize: s,
|
|
|
140
140
|
}),
|
|
141
141
|
/* @__PURE__ */ o(J, {
|
|
142
142
|
ref: y,
|
|
143
|
-
className: "cy-file-drop-input",
|
|
143
|
+
className: "cy-file-drop-input cy-visually-hidden",
|
|
144
144
|
tabIndex: -1,
|
|
145
145
|
"aria-hidden": "true",
|
|
146
|
-
accept:
|
|
146
|
+
accept: f,
|
|
147
147
|
multiple: p,
|
|
148
148
|
name: A,
|
|
149
149
|
form: _,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDrop.js","names":["Icon","Button","usePopover","FileInputBase","setInputFiles","upload","useEffect","useId","useRef","useState","jsx","jsxs","plural","n","one","many","DEFAULT_LABELS","file","reason","acceptsFile","accept","name","type","a","FileDrop","onFiles","onReject","multiple","maxSize","maxFiles","hint","target","form","required","disabled","size","labels","className","style","text","id","input","depth","over","setOver","status","setStatus","problems","setProblems","take","files","fromDrop","accepted","rejected","limit","dragging","event","reset","latest","whole","overlay","all","fn","local","p"],"sources":["../../../src/components/FileDrop/FileDrop.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport { FileInputBase, setInputFiles } from \"../../foundations/FileInputBase/FileInputBase.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { upload } from \"../../icons/upload.js\";\nimport { usePopover } from \"../../overlay/floating.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Button } from \"../Button/Button.js\";\n\nexport interface FileDropTokens {\n /** Corner radius of the drop zone. */\n radius: string;\n /** Background while files are dragged over it. */\n activeBackground: string;\n /** Behind the whole-window overlay (`target=\"window\"`). */\n overlayBackground: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n fileDrop: FileDropTokens;\n }\n}\n\nexport type FileRejection = { file: File; reason: \"type\" | \"size\" | \"count\" };\n\nexport interface FileDropLabels {\n /** Text in the zone. Default: \"Drop files here, or\". */\n prompt: string;\n /** The button. Defaults: \"Choose files\" / \"Choose a file\". */\n choose: string;\n chooseOne: string;\n /** Text while files are over the zone. Default: \"Drop to add\". */\n dragging: string;\n /** Announced after files are added. Default: \"2 files added\". */\n added: (count: number) => string;\n /** Why a file was turned away. */\n rejected: (rejection: FileRejection) => string;\n}\n\nexport interface FileDropProps {\n /** Called with the files that passed the checks. */\n onFiles?: (files: File[]) => void;\n /** Called with the files that did not, and why (they are also listed in the zone). */\n onReject?: (rejections: FileRejection[]) => void;\n /** File types, as for `<input accept>`: \".pdf,image/*\". */\n accept?: string | undefined;\n /** Take more than one file at a time. */\n multiple?: boolean;\n /** Largest file in bytes. */\n maxSize?: number | undefined;\n /** Most files in one go (with `multiple`). */\n maxFiles?: number | undefined;\n /**\n * `zone` (default): files are dropped on the zone. `window`: files dropped anywhere in the window are taken, and an\n * overlay covers the page while they are dragged in (for an app whose whole page is a drop target).\n */\n target?: \"zone\" | \"window\";\n /** Shown under the prompt, e.g. \"PNG or JPG, up to 5 MB\". */\n hint?: ReactNode;\n /** Name the accepted files are submitted under in a form. */\n name?: string | undefined;\n /** Id of the form it belongs to, when it is not inside that form. */\n form?: string | undefined;\n /** Marks the file input as required for form validation. */\n required?: boolean | undefined;\n /** Turns off dropping and the button. */\n disabled?: boolean | undefined;\n /** Size of the zone and its button. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text. */\n labels?: Partial<FileDropLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-file-drop-* tokens. */\n style?: CSSProperties;\n}\n\nconst plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;\nconst DEFAULT_LABELS: FileDropLabels = {\n prompt: \"Drop files here, or\",\n choose: \"Choose files\",\n chooseOne: \"Choose a file\",\n dragging: \"Drop to add\",\n added: (n) => `${plural(n, \"file\", \"files\")} added`,\n rejected: ({ file, reason }) =>\n `${file.name}: ${reason === \"type\" ? \"this type of file is not accepted\" : reason === \"size\" ? \"too large\" : \"too many files\"}`,\n};\n\n/** Whether `file` matches an `accept` list (extensions, exact MIME types and `type/*` wildcards), as browsers do. */\nexport function acceptsFile(file: File, accept: string | undefined): boolean {\n if (!accept) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return accept\n .split(\",\")\n .map((a) => a.trim().toLowerCase())\n .filter(Boolean)\n .some((a) =>\n a.startsWith(\".\") ? name.endsWith(a) : a.endsWith(\"/*\") ? type.startsWith(a.slice(0, -1)) : type === a,\n );\n}\n\n/**\n * A place to add files: drop them on it, or press its button to pick them. Checks type, size and count, explains\n * what it turned away, and puts the accepted files into a native file input so forms submit them.\n */\nexport function FileDrop({\n onFiles,\n onReject,\n accept,\n multiple = false,\n maxSize,\n maxFiles,\n hint,\n target = \"zone\",\n name,\n form,\n required,\n disabled = false,\n size = \"md\",\n labels,\n className,\n style,\n}: FileDropProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const input = useRef<HTMLInputElement>(null);\n const depth = useRef(0);\n const [over, setOver] = useState(false);\n const [status, setStatus] = useState(\"\");\n const [problems, setProblems] = useState<string[]>([]);\n\n const take = (files: File[], fromDrop: boolean) => {\n const accepted: File[] = [];\n const rejected: FileRejection[] = [];\n const limit = multiple ? (maxFiles ?? Number.POSITIVE_INFINITY) : 1;\n for (const file of files) {\n if (!acceptsFile(file, accept)) rejected.push({ file, reason: \"type\" });\n else if (maxSize !== undefined && file.size > maxSize) rejected.push({ file, reason: \"size\" });\n else if (accepted.length >= limit) rejected.push({ file, reason: \"count\" });\n else accepted.push(file);\n }\n // Keep the native input in step with what was accepted, so the form submits exactly that.\n if (input.current && (fromDrop || rejected.length)) setInputFiles(input.current, accepted);\n setProblems(rejected.map(text.rejected));\n setStatus(accepted.length ? text.added(accepted.length) : \"\");\n if (accepted.length) onFiles?.(accepted);\n if (rejected.length) onReject?.(rejected);\n };\n\n const dragging = (event: { dataTransfer: DataTransfer | null }) =>\n [...(event.dataTransfer?.types ?? [])].includes(\"Files\");\n const reset = () => {\n depth.current = 0;\n setOver(false);\n };\n const latest = useRef(take);\n latest.current = take;\n const whole = target === \"window\";\n const overlay = useRef<HTMLDivElement>(null);\n usePopover(overlay, whole && over);\n\n // A whole-window target listens on the window: the page under the files is not ours, so nothing is attached to it.\n useEffect(() => {\n if (!whole || disabled) return;\n const enter = (event: globalThis.DragEvent) => {\n if (!dragging(event)) return;\n event.preventDefault();\n depth.current += 1;\n setOver(true);\n };\n const move = (event: globalThis.DragEvent) => {\n if (!dragging(event) || !event.dataTransfer) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"copy\";\n };\n const leave = () => {\n depth.current -= 1;\n if (depth.current <= 0) reset();\n };\n const drop = (event: globalThis.DragEvent) => {\n if (!dragging(event) || !event.dataTransfer) return;\n event.preventDefault();\n reset();\n latest.current([...event.dataTransfer.files], true);\n };\n const all = [\n [\"dragenter\", enter],\n [\"dragover\", move],\n [\"dragleave\", leave],\n [\"drop\", drop],\n ] as const;\n for (const [type, fn] of all) window.addEventListener(type, fn);\n return () => {\n for (const [type, fn] of all) window.removeEventListener(type, fn);\n reset();\n };\n }, [whole, disabled]);\n const local = !whole;\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: drag and drop target; the button inside is the accessible way in\n <div\n className={className ? `cy-file-drop ${className}` : \"cy-file-drop\"}\n data-size={size}\n data-over={over ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n data-invalid={problems.length ? \"\" : undefined}\n style={style}\n onDragEnter={(event) => {\n if (!local || disabled || !dragging(event)) return;\n event.preventDefault();\n depth.current += 1;\n setOver(true);\n }}\n onDragOver={(event) => {\n if (!local || disabled || !dragging(event)) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"copy\";\n }}\n onDragLeave={() => {\n if (!local) return;\n depth.current -= 1;\n if (depth.current <= 0) reset();\n }}\n onDrop={(event) => {\n if (!local || disabled) return;\n event.preventDefault();\n reset();\n take([...event.dataTransfer.files], true);\n }}\n >\n <Icon icon={upload} size=\"lg\" className=\"cy-file-drop-icon\" />\n <span className=\"cy-file-drop-prompt cy-reset\" id={`${id}-prompt`}>\n {over ? text.dragging : text.prompt}\n </span>\n <Button\n variant=\"outline\"\n tone=\"neutral\"\n size={size}\n disabled={disabled}\n aria-describedby={hint ? `${id}-hint` : undefined}\n onClick={() => input.current?.click()}\n >\n {multiple ? text.choose : text.chooseOne}\n </Button>\n {hint && (\n <span className=\"cy-file-drop-hint cy-reset\" id={`${id}-hint`}>\n {hint}\n </span>\n )}\n <div className=\"cy-file-drop-alert cy-reset\" role=\"alert\">\n {problems.length > 0 && (\n <ul className=\"cy-file-drop-problems cy-reset\">\n {problems.map((p) => (\n <li key={p} className=\"cy-reset\">\n {p}\n </li>\n ))}\n </ul>\n )}\n </div>\n <span className=\"cy-file-drop-status cy-reset\" role=\"status\">\n {status}\n </span>\n {whole && (\n <div\n ref={overlay}\n className=\"cy-file-drop-overlay cy-reset\"\n aria-hidden=\"true\"\n data-size={size}\n {...{ popover: \"manual\" }}\n >\n <Icon icon={upload} size=\"lg\" />\n <span className=\"cy-reset\">{text.dragging}</span>\n </div>\n )}\n <FileInputBase\n ref={input}\n className=\"cy-file-drop-input\"\n tabIndex={-1}\n aria-hidden=\"true\"\n accept={accept}\n multiple={multiple}\n name={name}\n form={form}\n required={required}\n disabled={disabled}\n onFiles={(files) => take(files, false)}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AA6EA,IAAMY,IAAA,CAAUC,GAAWC,GAAaC,MAAiB,GAAGF,CAAA,IAAKA,MAAM,IAAIC,IAAMC,CAAA,IAC3EC,IAAiC;AAAA,EACrC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,OAAA,CAAQH,MAAM,GAAGD,EAAOC,GAAG,QAAQ,OAAO,CAAA;AAAA,EAC1C,UAAA,CAAW,EAAE,MAAAI,GAAM,QAAAC,EAAA,MACjB,GAAGD,EAAK,IAAA,KAASC,MAAW,SAAS,sCAAsCA,MAAW,SAAS,cAAc,gBAAA;AACjH;AAGA,SAAgBC,GAAYF,GAAYG,GAAqC;AAC3E,MAAI,CAACA,EAAQ,QAAO;AACpB,QAAMC,IAAOJ,EAAK,KAAK,YAAY,GAC7BK,IAAOL,EAAK,KAAK,YAAY;AACnC,SAAOG,EACJ,MAAM,GAAG,EACT,IAAA,CAAKG,MAAMA,EAAE,KAAK,EAAE,YAAY,CAAC,EACjC,OAAO,OAAO,EACd,KAAA,CAAMA,MACLA,EAAE,WAAW,GAAG,IAAIF,EAAK,SAASE,CAAC,IAAIA,EAAE,SAAS,IAAI,IAAID,EAAK,WAAWC,EAAE,MAAM,GAAG,EAAE,CAAC,IAAID,MAASC,CACvG;AACJ;AAMA,SAAgBC,GAAS,EACvB,SAAAC,GACA,UAAAC,GACA,QAAAN,GACA,UAAAO,IAAW,IACX,SAAAC,GACA,UAAAC,GACA,MAAAC,GACA,QAAAC,IAAS,QACT,MAAAV,GACA,MAAAW,GACA,UAAAC,GACA,UAAAC,IAAW,IACX,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACgB;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setInputFiles","upload","useEffect","useId","useRef","useState","jsx","jsxs","plural","n","one","many","DEFAULT_LABELS","file","reason","acceptsFile","accept","name","type","a","FileDrop","onFiles","onReject","multiple","maxSize","maxFiles","hint","target","form","required","disabled","size","labels","className","style","text","id","input","depth","over","setOver","status","setStatus","problems","setProblems","take","files","fromDrop","accepted","rejected","limit","dragging","event","reset","latest","whole","overlay","all","fn","local","p"],"sources":["../../../src/components/FileDrop/FileDrop.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport { FileInputBase, setInputFiles } from \"../../foundations/FileInputBase/FileInputBase.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { upload } from \"../../icons/upload.js\";\nimport { usePopover } from \"../../overlay/floating.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Button } from \"../Button/Button.js\";\n\nexport interface FileDropTokens {\n /** Corner radius of the drop zone. */\n radius: string;\n /** Background while files are dragged over it. */\n activeBackground: string;\n /** Behind the whole-window overlay (`target=\"window\"`). */\n overlayBackground: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n fileDrop: FileDropTokens;\n }\n}\n\nexport type FileRejection = { file: File; reason: \"type\" | \"size\" | \"count\" };\n\nexport interface FileDropLabels {\n /** Text in the zone. Default: \"Drop files here, or\". */\n prompt: string;\n /** The button. Defaults: \"Choose files\" / \"Choose a file\". */\n choose: string;\n chooseOne: string;\n /** Text while files are over the zone. Default: \"Drop to add\". */\n dragging: string;\n /** Announced after files are added. Default: \"2 files added\". */\n added: (count: number) => string;\n /** Why a file was turned away. */\n rejected: (rejection: FileRejection) => string;\n}\n\nexport interface FileDropProps {\n /** Called with the files that passed the checks. */\n onFiles?: (files: File[]) => void;\n /** Called with the files that did not, and why (they are also listed in the zone). */\n onReject?: (rejections: FileRejection[]) => void;\n /** File types, as for `<input accept>`: \".pdf,image/*\". */\n accept?: string | undefined;\n /** Take more than one file at a time. */\n multiple?: boolean;\n /** Largest file in bytes. */\n maxSize?: number | undefined;\n /** Most files in one go (with `multiple`). */\n maxFiles?: number | undefined;\n /**\n * `zone` (default): files are dropped on the zone. `window`: files dropped anywhere in the window are taken, and an\n * overlay covers the page while they are dragged in (for an app whose whole page is a drop target).\n */\n target?: \"zone\" | \"window\";\n /** Shown under the prompt, e.g. \"PNG or JPG, up to 5 MB\". */\n hint?: ReactNode;\n /** Name the accepted files are submitted under in a form. */\n name?: string | undefined;\n /** Id of the form it belongs to, when it is not inside that form. */\n form?: string | undefined;\n /** Marks the file input as required for form validation. */\n required?: boolean | undefined;\n /** Turns off dropping and the button. */\n disabled?: boolean | undefined;\n /** Size of the zone and its button. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text. */\n labels?: Partial<FileDropLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-file-drop-* tokens. */\n style?: CSSProperties;\n}\n\nconst plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;\nconst DEFAULT_LABELS: FileDropLabels = {\n prompt: \"Drop files here, or\",\n choose: \"Choose files\",\n chooseOne: \"Choose a file\",\n dragging: \"Drop to add\",\n added: (n) => `${plural(n, \"file\", \"files\")} added`,\n rejected: ({ file, reason }) =>\n `${file.name}: ${reason === \"type\" ? \"this type of file is not accepted\" : reason === \"size\" ? \"too large\" : \"too many files\"}`,\n};\n\n/** Whether `file` matches an `accept` list (extensions, exact MIME types and `type/*` wildcards), as browsers do. */\nexport function acceptsFile(file: File, accept: string | undefined): boolean {\n if (!accept) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return accept\n .split(\",\")\n .map((a) => a.trim().toLowerCase())\n .filter(Boolean)\n .some((a) =>\n a.startsWith(\".\") ? name.endsWith(a) : a.endsWith(\"/*\") ? type.startsWith(a.slice(0, -1)) : type === a,\n );\n}\n\n/**\n * A place to add files: drop them on it, or press its button to pick them. Checks type, size and count, explains\n * what it turned away, and puts the accepted files into a native file input so forms submit them.\n */\nexport function FileDrop({\n onFiles,\n onReject,\n accept,\n multiple = false,\n maxSize,\n maxFiles,\n hint,\n target = \"zone\",\n name,\n form,\n required,\n disabled = false,\n size = \"md\",\n labels,\n className,\n style,\n}: FileDropProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const input = useRef<HTMLInputElement>(null);\n const depth = useRef(0);\n const [over, setOver] = useState(false);\n const [status, setStatus] = useState(\"\");\n const [problems, setProblems] = useState<string[]>([]);\n\n const take = (files: File[], fromDrop: boolean) => {\n const accepted: File[] = [];\n const rejected: FileRejection[] = [];\n const limit = multiple ? (maxFiles ?? Number.POSITIVE_INFINITY) : 1;\n for (const file of files) {\n if (!acceptsFile(file, accept)) rejected.push({ file, reason: \"type\" });\n else if (maxSize !== undefined && file.size > maxSize) rejected.push({ file, reason: \"size\" });\n else if (accepted.length >= limit) rejected.push({ file, reason: \"count\" });\n else accepted.push(file);\n }\n // Keep the native input in step with what was accepted, so the form submits exactly that.\n if (input.current && (fromDrop || rejected.length)) setInputFiles(input.current, accepted);\n setProblems(rejected.map(text.rejected));\n setStatus(accepted.length ? text.added(accepted.length) : \"\");\n if (accepted.length) onFiles?.(accepted);\n if (rejected.length) onReject?.(rejected);\n };\n\n const dragging = (event: { dataTransfer: DataTransfer | null }) =>\n [...(event.dataTransfer?.types ?? [])].includes(\"Files\");\n const reset = () => {\n depth.current = 0;\n setOver(false);\n };\n const latest = useRef(take);\n latest.current = take;\n const whole = target === \"window\";\n const overlay = useRef<HTMLDivElement>(null);\n usePopover(overlay, whole && over);\n\n // A whole-window target listens on the window: the page under the files is not ours, so nothing is attached to it.\n useEffect(() => {\n if (!whole || disabled) return;\n const enter = (event: globalThis.DragEvent) => {\n if (!dragging(event)) return;\n event.preventDefault();\n depth.current += 1;\n setOver(true);\n };\n const move = (event: globalThis.DragEvent) => {\n if (!dragging(event) || !event.dataTransfer) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"copy\";\n };\n const leave = () => {\n depth.current -= 1;\n if (depth.current <= 0) reset();\n };\n const drop = (event: globalThis.DragEvent) => {\n if (!dragging(event) || !event.dataTransfer) return;\n event.preventDefault();\n reset();\n latest.current([...event.dataTransfer.files], true);\n };\n const all = [\n [\"dragenter\", enter],\n [\"dragover\", move],\n [\"dragleave\", leave],\n [\"drop\", drop],\n ] as const;\n for (const [type, fn] of all) window.addEventListener(type, fn);\n return () => {\n for (const [type, fn] of all) window.removeEventListener(type, fn);\n reset();\n };\n }, [whole, disabled]);\n const local = !whole;\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: drag and drop target; the button inside is the accessible way in\n <div\n className={className ? `cy-file-drop ${className}` : \"cy-file-drop\"}\n data-size={size}\n data-over={over ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n data-invalid={problems.length ? \"\" : undefined}\n style={style}\n onDragEnter={(event) => {\n if (!local || disabled || !dragging(event)) return;\n event.preventDefault();\n depth.current += 1;\n setOver(true);\n }}\n onDragOver={(event) => {\n if (!local || disabled || !dragging(event)) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"copy\";\n }}\n onDragLeave={() => {\n if (!local) return;\n depth.current -= 1;\n if (depth.current <= 0) reset();\n }}\n onDrop={(event) => {\n if (!local || disabled) return;\n event.preventDefault();\n reset();\n take([...event.dataTransfer.files], true);\n }}\n >\n <Icon icon={upload} size=\"lg\" className=\"cy-file-drop-icon\" />\n <span className=\"cy-file-drop-prompt cy-reset\" id={`${id}-prompt`}>\n {over ? text.dragging : text.prompt}\n </span>\n <Button\n variant=\"outline\"\n tone=\"neutral\"\n size={size}\n disabled={disabled}\n aria-describedby={hint ? `${id}-hint` : undefined}\n onClick={() => input.current?.click()}\n >\n {multiple ? text.choose : text.chooseOne}\n </Button>\n {hint && (\n <span className=\"cy-file-drop-hint cy-reset\" id={`${id}-hint`}>\n {hint}\n </span>\n )}\n <div className=\"cy-file-drop-alert cy-reset\" role=\"alert\">\n {problems.length > 0 && (\n <ul className=\"cy-file-drop-problems cy-reset\">\n {problems.map((p) => (\n <li key={p} className=\"cy-reset\">\n {p}\n </li>\n ))}\n </ul>\n )}\n </div>\n <span className=\"cy-file-drop-status cy-reset cy-visually-hidden\" role=\"status\">\n {status}\n </span>\n {whole && (\n <div\n ref={overlay}\n className=\"cy-file-drop-overlay cy-reset\"\n aria-hidden=\"true\"\n data-size={size}\n {...{ popover: \"manual\" }}\n >\n <Icon icon={upload} size=\"lg\" />\n <span className=\"cy-reset\">{text.dragging}</span>\n </div>\n )}\n <FileInputBase\n ref={input}\n className=\"cy-file-drop-input cy-visually-hidden\"\n tabIndex={-1}\n aria-hidden=\"true\"\n accept={accept}\n multiple={multiple}\n name={name}\n form={form}\n required={required}\n disabled={disabled}\n onFiles={(files) => take(files, false)}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AA6EA,IAAMY,IAAA,CAAUC,GAAWC,GAAaC,MAAiB,GAAGF,CAAA,IAAKA,MAAM,IAAIC,IAAMC,CAAA,IAC3EC,IAAiC;AAAA,EACrC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,OAAA,CAAQH,MAAM,GAAGD,EAAOC,GAAG,QAAQ,OAAO,CAAA;AAAA,EAC1C,UAAA,CAAW,EAAE,MAAAI,GAAM,QAAAC,EAAA,MACjB,GAAGD,EAAK,IAAA,KAASC,MAAW,SAAS,sCAAsCA,MAAW,SAAS,cAAc,gBAAA;AACjH;AAGA,SAAgBC,GAAYF,GAAYG,GAAqC;AAC3E,MAAI,CAACA,EAAQ,QAAO;AACpB,QAAMC,IAAOJ,EAAK,KAAK,YAAY,GAC7BK,IAAOL,EAAK,KAAK,YAAY;AACnC,SAAOG,EACJ,MAAM,GAAG,EACT,IAAA,CAAKG,MAAMA,EAAE,KAAK,EAAE,YAAY,CAAC,EACjC,OAAO,OAAO,EACd,KAAA,CAAMA,MACLA,EAAE,WAAW,GAAG,IAAIF,EAAK,SAASE,CAAC,IAAIA,EAAE,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AAA,QACE,KAAKsC;AAAA,QACL,WAAU;AAAA,QACV,UAAU;AAAA,QACV,eAAY;AAAA,QACJ,QAAArB;AAAA,QACE,UAAAO;AAAA,QACJ,MAAAN;AAAA,QACA,MAAAW;AAAA,QACI,UAAAC;AAAA,QACA,UAAAC;AAAA,QACV,SAAA,CAAUgB,MAAUD,EAAKC,GAAO,EAAK;AAAA,MACtC,CAAA;AAAA,IACE;AAAA,E;AAET"}
|
|
@@ -4,10 +4,10 @@ import { useFloatingAnchor as j, useFloatingOffset as q, usePopover as E } from
|
|
|
4
4
|
import { isRtl as O } from "../../foundations/dir.js";
|
|
5
5
|
import { useAnchoredPosition as V } from "../../overlay/use-anchored-position.js";
|
|
6
6
|
import { IconButton as W } from "../IconButton/IconButton.js";
|
|
7
|
-
import { useHotkey as
|
|
7
|
+
import { useHotkey as N } from "../../foundations/hotkey.js";
|
|
8
8
|
import { grip as G } from "../../icons/grip.js";
|
|
9
9
|
import { useDrag as J } from "../../foundations/drag.js";
|
|
10
|
-
import { Toolbar as
|
|
10
|
+
import { Toolbar as z } from "../Toolbar/Toolbar.js";
|
|
11
11
|
import { useEffect as R, useRef as h, useState as w } from "react";
|
|
12
12
|
import { Fragment as Q, jsx as p, jsxs as B } from "react/jsx-runtime";
|
|
13
13
|
function P(r) {
|
|
@@ -30,7 +30,7 @@ function at({ label: r, anchor: n, open: t, side: o = "top", onEscape: i, hotkey
|
|
|
30
30
|
const l = h(null), g = j(n), d = (t ?? !0) && g.present;
|
|
31
31
|
E(l, d);
|
|
32
32
|
const k = q(l);
|
|
33
|
-
V(g.ref, l, d, o, k, "start"),
|
|
33
|
+
V(g.ref, l, d, o, k, "start"), N(d && f, () => M(l.current));
|
|
34
34
|
const b = P(i);
|
|
35
35
|
return /* @__PURE__ */ p("div", {
|
|
36
36
|
ref: l,
|
|
@@ -39,8 +39,9 @@ function at({ label: r, anchor: n, open: t, side: o = "top", onEscape: i, hotkey
|
|
|
39
39
|
style: x,
|
|
40
40
|
onFocus: b.onFocus,
|
|
41
41
|
onKeyDown: b.onKeyDown,
|
|
42
|
-
children: /* @__PURE__ */ p(
|
|
42
|
+
children: /* @__PURE__ */ p(z, {
|
|
43
43
|
label: r,
|
|
44
|
+
className: "cy-floating-toolbar-row",
|
|
44
45
|
children: c
|
|
45
46
|
})
|
|
46
47
|
});
|
|
@@ -63,7 +64,7 @@ function lt({ label: r, open: n = !0, onEscape: t, keepVisible: o, trailing: i,
|
|
|
63
64
|
}, m = h(null), D = h(null), u = c !== "bottom";
|
|
64
65
|
E(m, n);
|
|
65
66
|
const F = U();
|
|
66
|
-
|
|
67
|
+
N(n && f, () => M(m.current));
|
|
67
68
|
const [L, _] = w(0);
|
|
68
69
|
I(() => {
|
|
69
70
|
const e = n && !u ? m.current.offsetHeight + F : 0;
|
|
@@ -138,7 +139,7 @@ function lt({ label: r, open: n = !0, onEscape: t, keepVisible: o, trailing: i,
|
|
|
138
139
|
tooltipPlacement: c === "start" ? "end" : "start",
|
|
139
140
|
onClick: K
|
|
140
141
|
}),
|
|
141
|
-
/* @__PURE__ */ p(
|
|
142
|
+
/* @__PURE__ */ p(z, {
|
|
142
143
|
label: r,
|
|
143
144
|
orientation: u ? "vertical" : "horizontal",
|
|
144
145
|
className: "cy-docked-toolbar-row",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingToolbar.js","names":["grip","_Fragment","gripIcon","useClientLayoutEffect","useFloatingAnchor","useFloatingOffset","usePopover","isRtl","useAnchoredPosition","IconButton","useHotkey","grip","useDrag","Toolbar","useEffect","useRef","useState","Fragment$1","jsx","jsxs","useReturnFocus","onEscape","from","event","prev","back","enter","bar","FloatingToolbar","label","anchor","open","side","hotkey","children","className","style","target","shown","offset","focus","useKeyboardInset","inset","setInset","vv","update","DockedToolbar","keepVisible","trailing","edge","onEdgeChange","floating","labels","text","grip$1","room","setRoom","next","r","edgeAt","left","flip","shift","setShift","delta","point","cancelled","to","onKeyDown","el","frame","covered","gap","useSelectionAnchor","container","setAnchor","selection","root","range"],"sources":["../../../src/components/FloatingToolbar/FloatingToolbar.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { useHotkey } from \"../../foundations/hotkey.js\";\nimport { grip as gripIcon } from \"../../icons/grip.js\";\nimport {\n type FloatingAnchor,\n type PopoverEl,\n useFloatingAnchor,\n useFloatingOffset,\n usePopover,\n} from \"../../overlay/floating.js\";\nimport { useAnchoredPosition, type VirtualAnchor } from \"../../overlay/use-anchored-position.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Toolbar } from \"../Toolbar/Toolbar.js\";\n\nexport interface FloatingToolbarTokens {\n /** Background of the bar. */\n background: string;\n /** Corner radius of the floating bar. */\n radius: string;\n /** Gap between the bar and the box it works on. */\n offset: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n floatingToolbar: FloatingToolbarTokens;\n }\n}\n\n/** What a floating toolbar sits beside. */\nexport type ToolbarAnchor = FloatingAnchor;\n\n/**\n * Remembers where focus came from when it enters the bar; Escape inside the bar calls `onEscape` and returns focus\n * there, so an editor keeps its caret and selection.\n */\nfunction useReturnFocus(onEscape: (() => void) | undefined) {\n const from = useRef<HTMLElement | null>(null);\n return {\n onFocus: (event: FocusEvent<HTMLElement>) => {\n const prev = event.relatedTarget as HTMLElement | null;\n if (prev && !event.currentTarget.contains(prev)) from.current = prev;\n },\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => {\n if (event.key !== \"Escape\" || event.defaultPrevented) return;\n event.preventDefault();\n const back = from.current;\n onEscape?.();\n if (back?.isConnected) back.focus();\n },\n };\n}\n\n/** Moves focus to the toolbar's current item (its one tab stop). */\nconst enter = (bar: HTMLElement | null) =>\n bar\n ?.querySelector<HTMLElement>('[role=\"toolbar\"] [tabindex=\"0\"], [role=\"toolbar\"] button:not([disabled])')\n ?.focus();\n\nexport interface FloatingToolbarProps {\n /** Accessible name of the toolbar. */\n label: string;\n /** What it works on: a ref to an element, or a virtual anchor such as `useSelectionAnchor()`. */\n anchor: ToolbarAnchor;\n /** Show the bar. Default: whenever there is an anchor. */\n open?: boolean;\n /** Preferred side; it flips when there is no room. Default `top`. */\n side?: \"top\" | \"bottom\";\n /** Escape inside the bar. Focus then returns to where it came from. */\n onEscape?: (() => void) | undefined;\n /** Keyboard shortcut that moves focus into the bar while it is open. Default \"alt+f10\"; `false` for none. */\n hotkey?: string | false;\n /** Buttons, IconButtons, SegmentedControls. */\n children?: ReactNode;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-floating-toolbar-* tokens. */\n style?: CSSProperties;\n}\n\n/**\n * A compact toolbar that floats beside the box or text it works on, like the mini toolbars of document editors. It\n * flips below when there is no room above and slides to stay on screen. Non-modal: it never takes focus by itself;\n * Alt+F10 moves into it, arrow keys move inside it (APG toolbar), Escape returns.\n */\nexport function FloatingToolbar({\n label,\n anchor,\n open,\n side = \"top\",\n onEscape,\n hotkey = \"alt+f10\",\n children,\n className,\n style,\n}: FloatingToolbarProps) {\n const bar = useRef<PopoverEl>(null);\n const target = useFloatingAnchor(anchor);\n const shown = (open ?? true) && target.present;\n usePopover(bar, shown);\n const offset = useFloatingOffset(bar);\n useAnchoredPosition(target.ref, bar, shown, side, offset, \"start\");\n useHotkey(shown && hotkey, () => enter(bar.current));\n const focus = useReturnFocus(onEscape);\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: delegated Escape and focus tracking for the toolbar inside\n <div\n ref={bar}\n className={className ? `cy-floating-toolbar ${className}` : \"cy-floating-toolbar\"}\n {...{ popover: \"manual\" }}\n style={style}\n onFocus={focus.onFocus}\n onKeyDown={focus.onKeyDown}\n >\n <Toolbar label={label}>{children}</Toolbar>\n </div>\n );\n}\n\nexport interface DockedToolbarProps {\n /** Accessible name of the toolbar. */\n label: string;\n /** Show the bar. Default true. */\n open?: boolean;\n /** Escape inside the bar. Focus then returns to where it came from. */\n onEscape?: (() => void) | undefined;\n /** Kept in view above the bar (and the on-screen keyboard) by scrolling the page, never covered. */\n keepVisible?: RefObject<Element | null> | undefined;\n /** Pinned after the scrolling row, always in reach (e.g. Done). */\n trailing?: ReactNode;\n /** Keyboard shortcut that moves focus into the bar while it is open. Default \"alt+f10\"; `false` for none. */\n hotkey?: string | false;\n /**\n * Where it docks: across the `bottom` of the visible viewport (the phone bar, default), or as a vertical palette on\n * the `start` or `end` edge (the tools of a focused editor).\n */\n edge?: DockEdge;\n /**\n * Lets people move a side palette to the other edge: shows a grip (click or tap to flip, drag to the other half to\n * snap there) and Alt+Left/Right inside the bar.\n */\n onEdgeChange?: ((edge: \"start\" | \"end\") => void) | undefined;\n /** At the bottom: a centred pill above the edge instead of a full-width bar (a mode switcher). */\n floating?: boolean;\n /** Replace the built-in English text: the grip that moves a side palette. */\n labels?: Partial<DockedToolbarLabels>;\n /** Buttons, IconButtons, SegmentedControls. */\n children?: ReactNode;\n /** Added to the bar, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-floating-toolbar-* tokens. */\n style?: CSSProperties;\n}\n\nexport type DockEdge = \"bottom\" | \"start\" | \"end\";\n\nexport interface DockedToolbarLabels {\n /** The grip that moves a side palette. Default \"Move to the other side\". */\n move: string;\n}\n\n/** Height of the part of the layout viewport the on-screen keyboard (or browser chrome) covers at the bottom. */\nfunction useKeyboardInset() {\n const [inset, setInset] = useState(0);\n useEffect(() => {\n const vv = globalThis.visualViewport;\n if (!vv) return;\n const update = () => setInset(Math.max(0, window.innerHeight - (vv.offsetTop + vv.height)));\n update();\n vv.addEventListener(\"resize\", update);\n vv.addEventListener(\"scroll\", update);\n return () => {\n vv.removeEventListener(\"resize\", update);\n vv.removeEventListener(\"scroll\", update);\n };\n }, []);\n return inset;\n}\n\n/**\n * A toolbar docked to an edge of the visible viewport. At the bottom it is the phone form of a contextual toolbar: one\n * row that rides just above the on-screen keyboard, scrolls sideways instead of wrapping, and keeps the box being\n * worked on in view above itself. `floating` makes it a centred pill (a mode switcher). On the `start` or `end` edge it\n * is a vertical palette that people can move to the other side.\n */\nexport function DockedToolbar({\n label,\n open = true,\n onEscape,\n keepVisible,\n trailing,\n hotkey = \"alt+f10\",\n edge = \"bottom\",\n onEdgeChange,\n floating = false,\n labels,\n children,\n className,\n style,\n}: DockedToolbarProps) {\n const text = { move: \"Move to the other side\", ...labels };\n const bar = useRef<PopoverEl>(null);\n const grip = useRef<HTMLButtonElement>(null);\n const side = edge !== \"bottom\";\n usePopover(bar, open);\n const inset = useKeyboardInset();\n useHotkey(open && hotkey, () => enter(bar.current));\n // Room at the end of the page for a bottom bar and the keyboard, so the last content can scroll above them.\n const [room, setRoom] = useState(0);\n useClientLayoutEffect(() => {\n const next = open && !side ? (bar.current as PopoverEl).offsetHeight + inset : 0;\n setRoom((r) => (r === next ? r : next));\n });\n const focus = useReturnFocus(onEscape);\n\n // Moving a side palette: the edge a physical side of the screen is, in this reading direction.\n const edgeAt = (left: boolean) => (left !== isRtl(bar.current as PopoverEl) ? \"start\" : \"end\");\n const flip = () => onEdgeChange?.(edge === \"start\" ? \"end\" : \"start\");\n const [shift, setShift] = useState<{ x: number; y: number } | null>(null);\n useDrag(grip, {\n distance: 4,\n onMove: ({ delta }) => setShift(delta),\n onEnd: ({ point, delta }, cancelled) => {\n setShift(null);\n if (cancelled) return;\n // A finger's tap starts a drag at once (and swallows the click): treat a tap as the click.\n if (Math.hypot(delta.x, delta.y) < 4) return flip();\n const to = edgeAt(point.x < window.innerWidth / 2);\n if (to !== edge) onEdgeChange?.(to);\n },\n });\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (side && onEdgeChange && event.altKey && (event.key === \"ArrowLeft\" || event.key === \"ArrowRight\")) {\n // Alt+Left would otherwise go back in the browser's history.\n event.preventDefault();\n const to = edgeAt(event.key === \"ArrowLeft\");\n if (to !== edge) onEdgeChange(to);\n return;\n }\n focus.onKeyDown(event);\n };\n\n useEffect(() => {\n const target = keepVisible?.current;\n const el = bar.current;\n if (!open || side || !target || !el) return;\n // Measured on the next frame, once the bar and the page have their final layout.\n const frame = requestAnimationFrame(() => {\n const covered = target.getBoundingClientRect().bottom - el.getBoundingClientRect().top;\n const gap = Number.parseFloat(getComputedStyle(el).getPropertyValue(\"--_offset\"));\n if (covered > -gap) window.scrollBy({ top: covered + gap, behavior: \"instant\" });\n });\n return () => cancelAnimationFrame(frame);\n }, [open, side, inset, room, keepVisible]);\n\n return (\n <>\n <div className=\"cy-docked-toolbar-room\" aria-hidden=\"true\" style={{ blockSize: `${room}px` }} />\n {/* biome-ignore lint/a11y/noStaticElementInteractions: delegated Escape and focus tracking for the toolbar inside */}\n <div\n ref={bar}\n className={className ? `cy-docked-toolbar ${className}` : \"cy-docked-toolbar\"}\n data-edge={edge}\n data-floating={floating && !side ? \"\" : undefined}\n data-moving={shift ? \"\" : undefined}\n {...{ popover: \"manual\" }}\n style={\n {\n \"--_inset\": `${inset}px`,\n ...(shift ? { \"--_dx\": `${shift.x}px`, \"--_dy\": `${shift.y}px` } : {}),\n ...style,\n } as CSSProperties\n }\n onFocus={focus.onFocus}\n onKeyDown={onKeyDown}\n >\n {side && onEdgeChange && (\n <IconButton\n ref={grip}\n icon={gripIcon}\n label={text.move}\n variant=\"ghost\"\n size=\"sm\"\n className=\"cy-docked-toolbar-grip\"\n tooltipPlacement={edge === \"start\" ? \"end\" : \"start\"}\n onClick={flip}\n />\n )}\n <Toolbar\n label={label}\n orientation={side ? \"vertical\" : \"horizontal\"}\n className=\"cy-docked-toolbar-row\"\n >\n {children}\n </Toolbar>\n {trailing != null && <div className=\"cy-docked-toolbar-trailing cy-reset\">{trailing}</div>}\n </div>\n </>\n );\n}\n\n/**\n * The current text selection inside `container`, as an anchor for a FloatingToolbar (a formatting bubble). `null`\n * when nothing is selected there. Follows the selection as it changes.\n */\nexport function useSelectionAnchor(container: RefObject<HTMLElement | null>): VirtualAnchor | null {\n const [anchor, setAnchor] = useState<VirtualAnchor | null>(null);\n useEffect(() => {\n const update = () => {\n const selection = document.getSelection();\n const root = container.current;\n if (!selection || selection.isCollapsed || selection.rangeCount === 0 || !root) return setAnchor(null);\n const range = selection.getRangeAt(0);\n if (!root.contains(range.commonAncestorContainer)) return setAnchor(null);\n setAnchor({ getBoundingClientRect: () => range.getBoundingClientRect() });\n };\n document.addEventListener(\"selectionchange\", update);\n return () => document.removeEventListener(\"selectionchange\", update);\n }, [container]);\n return anchor;\n}\n"],"mappings":";;;;;;;;;;;;AAgDA,SAASoB,EAAeC,GAAoC;AAC1D,QAAMC,IAAOP,EAA2B,IAAI;AAC5C,SAAO;AAAA,IACL,SAAA,CAAUQ,MAAmC;AAC3C,YAAMC,IAAOD,EAAM;AACnB,MAAIC,KAAQ,CAACD,EAAM,cAAc,SAASC,CAAI,MAAGF,EAAK,UAAUE;AAAA,IAClE;AAAA,IACA,WAAA,CAAYD,MAAsC;AAChD,UAAIA,EAAM,QAAQ,YAAYA,EAAM,iBAAkB;AACtD,MAAAA,EAAM,eAAe;AACrB,YAAME,IAAOH,EAAK;AAClB,MAAAD,IAAW,GACPI,GAAM,eAAaA,EAAK,MAAM;AAAA,IACpC;AAAA,EACF;AACF;AAGA,IAAMC,IAAA,CAASC,MACbA,GACI,cAA2B,0EAA0E,GACrG,MAAM;AA4BZ,SAAgBC,GAAgB,EAC9B,OAAAC,GACA,QAAAC,GACA,MAAAC,GACA,MAAAC,IAAO,OACP,UAAAX,GACA,QAAAY,IAAS,WACT,UAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACuB;AACvB,QAAMT,IAAMZ,EAAkB,IAAI,GAC5BsB,IAASjC,EAAkB0B,CAAM,GACjCQ,KAASP,KAAQ,OAASM,EAAO;AACvC,EAAA/B,EAAWqB,GAAKW,CAAK;AACrB,QAAMC,IAASlC,EA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M;AAAA,EACrE,GAAG,CAAC6B,CAAS,CAAC,GACP5C;AACT"}
|
|
1
|
+
{"version":3,"file":"FloatingToolbar.js","names":["grip","_Fragment","gripIcon","useClientLayoutEffect","useFloatingAnchor","useFloatingOffset","usePopover","isRtl","useAnchoredPosition","IconButton","useHotkey","grip","useDrag","Toolbar","useEffect","useRef","useState","Fragment$1","jsx","jsxs","useReturnFocus","onEscape","from","event","prev","back","enter","bar","FloatingToolbar","label","anchor","open","side","hotkey","children","className","style","target","shown","offset","focus","useKeyboardInset","inset","setInset","vv","update","DockedToolbar","keepVisible","trailing","edge","onEdgeChange","floating","labels","text","grip$1","room","setRoom","next","r","edgeAt","left","flip","shift","setShift","delta","point","cancelled","to","onKeyDown","el","frame","covered","gap","useSelectionAnchor","container","setAnchor","selection","root","range"],"sources":["../../../src/components/FloatingToolbar/FloatingToolbar.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { useHotkey } from \"../../foundations/hotkey.js\";\nimport { grip as gripIcon } from \"../../icons/grip.js\";\nimport {\n type FloatingAnchor,\n type PopoverEl,\n useFloatingAnchor,\n useFloatingOffset,\n usePopover,\n} from \"../../overlay/floating.js\";\nimport { useAnchoredPosition, type VirtualAnchor } from \"../../overlay/use-anchored-position.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Toolbar } from \"../Toolbar/Toolbar.js\";\n\nexport interface FloatingToolbarTokens {\n /** Background of the bar. */\n background: string;\n /** Corner radius of the floating bar. */\n radius: string;\n /** Gap between the bar and the box it works on. */\n offset: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n floatingToolbar: FloatingToolbarTokens;\n }\n}\n\n/** What a floating toolbar sits beside. */\nexport type ToolbarAnchor = FloatingAnchor;\n\n/**\n * Remembers where focus came from when it enters the bar; Escape inside the bar calls `onEscape` and returns focus\n * there, so an editor keeps its caret and selection.\n */\nfunction useReturnFocus(onEscape: (() => void) | undefined) {\n const from = useRef<HTMLElement | null>(null);\n return {\n onFocus: (event: FocusEvent<HTMLElement>) => {\n const prev = event.relatedTarget as HTMLElement | null;\n if (prev && !event.currentTarget.contains(prev)) from.current = prev;\n },\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => {\n if (event.key !== \"Escape\" || event.defaultPrevented) return;\n event.preventDefault();\n const back = from.current;\n onEscape?.();\n if (back?.isConnected) back.focus();\n },\n };\n}\n\n/** Moves focus to the toolbar's current item (its one tab stop). */\nconst enter = (bar: HTMLElement | null) =>\n bar\n ?.querySelector<HTMLElement>('[role=\"toolbar\"] [tabindex=\"0\"], [role=\"toolbar\"] button:not([disabled])')\n ?.focus();\n\nexport interface FloatingToolbarProps {\n /** Accessible name of the toolbar. */\n label: string;\n /** What it works on: a ref to an element, or a virtual anchor such as `useSelectionAnchor()`. */\n anchor: ToolbarAnchor;\n /** Show the bar. Default: whenever there is an anchor. */\n open?: boolean;\n /** Preferred side; it flips when there is no room. Default `top`. */\n side?: \"top\" | \"bottom\";\n /** Escape inside the bar. Focus then returns to where it came from. */\n onEscape?: (() => void) | undefined;\n /** Keyboard shortcut that moves focus into the bar while it is open. Default \"alt+f10\"; `false` for none. */\n hotkey?: string | false;\n /** Buttons, IconButtons, SegmentedControls. */\n children?: ReactNode;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-floating-toolbar-* tokens. */\n style?: CSSProperties;\n}\n\n/**\n * A compact toolbar that floats beside the box or text it works on, like the mini toolbars of document editors. It\n * flips below when there is no room above and slides to stay on screen. Non-modal: it never takes focus by itself;\n * Alt+F10 moves into it, arrow keys move inside it (APG toolbar), Escape returns.\n */\nexport function FloatingToolbar({\n label,\n anchor,\n open,\n side = \"top\",\n onEscape,\n hotkey = \"alt+f10\",\n children,\n className,\n style,\n}: FloatingToolbarProps) {\n const bar = useRef<PopoverEl>(null);\n const target = useFloatingAnchor(anchor);\n const shown = (open ?? true) && target.present;\n usePopover(bar, shown);\n const offset = useFloatingOffset(bar);\n useAnchoredPosition(target.ref, bar, shown, side, offset, \"start\");\n useHotkey(shown && hotkey, () => enter(bar.current));\n const focus = useReturnFocus(onEscape);\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: delegated Escape and focus tracking for the toolbar inside\n <div\n ref={bar}\n className={className ? `cy-floating-toolbar ${className}` : \"cy-floating-toolbar\"}\n {...{ popover: \"manual\" }}\n style={style}\n onFocus={focus.onFocus}\n onKeyDown={focus.onKeyDown}\n >\n <Toolbar label={label} className=\"cy-floating-toolbar-row\">\n {children}\n </Toolbar>\n </div>\n );\n}\n\nexport interface DockedToolbarProps {\n /** Accessible name of the toolbar. */\n label: string;\n /** Show the bar. Default true. */\n open?: boolean;\n /** Escape inside the bar. Focus then returns to where it came from. */\n onEscape?: (() => void) | undefined;\n /** Kept in view above the bar (and the on-screen keyboard) by scrolling the page, never covered. */\n keepVisible?: RefObject<Element | null> | undefined;\n /** Pinned after the scrolling row, always in reach (e.g. Done). */\n trailing?: ReactNode;\n /** Keyboard shortcut that moves focus into the bar while it is open. Default \"alt+f10\"; `false` for none. */\n hotkey?: string | false;\n /**\n * Where it docks: across the `bottom` of the visible viewport (the phone bar, default), or as a vertical palette on\n * the `start` or `end` edge (the tools of a focused editor).\n */\n edge?: DockEdge;\n /**\n * Lets people move a side palette to the other edge: shows a grip (click or tap to flip, drag to the other half to\n * snap there) and Alt+Left/Right inside the bar.\n */\n onEdgeChange?: ((edge: \"start\" | \"end\") => void) | undefined;\n /** At the bottom: a centred pill above the edge instead of a full-width bar (a mode switcher). */\n floating?: boolean;\n /** Replace the built-in English text: the grip that moves a side palette. */\n labels?: Partial<DockedToolbarLabels>;\n /** Buttons, IconButtons, SegmentedControls. */\n children?: ReactNode;\n /** Added to the bar, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-floating-toolbar-* tokens. */\n style?: CSSProperties;\n}\n\nexport type DockEdge = \"bottom\" | \"start\" | \"end\";\n\nexport interface DockedToolbarLabels {\n /** The grip that moves a side palette. Default \"Move to the other side\". */\n move: string;\n}\n\n/** Height of the part of the layout viewport the on-screen keyboard (or browser chrome) covers at the bottom. */\nfunction useKeyboardInset() {\n const [inset, setInset] = useState(0);\n useEffect(() => {\n const vv = globalThis.visualViewport;\n if (!vv) return;\n const update = () => setInset(Math.max(0, window.innerHeight - (vv.offsetTop + vv.height)));\n update();\n vv.addEventListener(\"resize\", update);\n vv.addEventListener(\"scroll\", update);\n return () => {\n vv.removeEventListener(\"resize\", update);\n vv.removeEventListener(\"scroll\", update);\n };\n }, []);\n return inset;\n}\n\n/**\n * A toolbar docked to an edge of the visible viewport. At the bottom it is the phone form of a contextual toolbar: one\n * row that rides just above the on-screen keyboard, scrolls sideways instead of wrapping, and keeps the box being\n * worked on in view above itself. `floating` makes it a centred pill (a mode switcher). On the `start` or `end` edge it\n * is a vertical palette that people can move to the other side.\n */\nexport function DockedToolbar({\n label,\n open = true,\n onEscape,\n keepVisible,\n trailing,\n hotkey = \"alt+f10\",\n edge = \"bottom\",\n onEdgeChange,\n floating = false,\n labels,\n children,\n className,\n style,\n}: DockedToolbarProps) {\n const text = { move: \"Move to the other side\", ...labels };\n const bar = useRef<PopoverEl>(null);\n const grip = useRef<HTMLButtonElement>(null);\n const side = edge !== \"bottom\";\n usePopover(bar, open);\n const inset = useKeyboardInset();\n useHotkey(open && hotkey, () => enter(bar.current));\n // Room at the end of the page for a bottom bar and the keyboard, so the last content can scroll above them.\n const [room, setRoom] = useState(0);\n useClientLayoutEffect(() => {\n const next = open && !side ? (bar.current as PopoverEl).offsetHeight + inset : 0;\n setRoom((r) => (r === next ? r : next));\n });\n const focus = useReturnFocus(onEscape);\n\n // Moving a side palette: the edge a physical side of the screen is, in this reading direction.\n const edgeAt = (left: boolean) => (left !== isRtl(bar.current as PopoverEl) ? \"start\" : \"end\");\n const flip = () => onEdgeChange?.(edge === \"start\" ? \"end\" : \"start\");\n const [shift, setShift] = useState<{ x: number; y: number } | null>(null);\n useDrag(grip, {\n distance: 4,\n onMove: ({ delta }) => setShift(delta),\n onEnd: ({ point, delta }, cancelled) => {\n setShift(null);\n if (cancelled) return;\n // A finger's tap starts a drag at once (and swallows the click): treat a tap as the click.\n if (Math.hypot(delta.x, delta.y) < 4) return flip();\n const to = edgeAt(point.x < window.innerWidth / 2);\n if (to !== edge) onEdgeChange?.(to);\n },\n });\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (side && onEdgeChange && event.altKey && (event.key === \"ArrowLeft\" || event.key === \"ArrowRight\")) {\n // Alt+Left would otherwise go back in the browser's history.\n event.preventDefault();\n const to = edgeAt(event.key === \"ArrowLeft\");\n if (to !== edge) onEdgeChange(to);\n return;\n }\n focus.onKeyDown(event);\n };\n\n useEffect(() => {\n const target = keepVisible?.current;\n const el = bar.current;\n if (!open || side || !target || !el) return;\n // Measured on the next frame, once the bar and the page have their final layout.\n const frame = requestAnimationFrame(() => {\n const covered = target.getBoundingClientRect().bottom - el.getBoundingClientRect().top;\n const gap = Number.parseFloat(getComputedStyle(el).getPropertyValue(\"--_offset\"));\n if (covered > -gap) window.scrollBy({ top: covered + gap, behavior: \"instant\" });\n });\n return () => cancelAnimationFrame(frame);\n }, [open, side, inset, room, keepVisible]);\n\n return (\n <>\n <div className=\"cy-docked-toolbar-room\" aria-hidden=\"true\" style={{ blockSize: `${room}px` }} />\n {/* biome-ignore lint/a11y/noStaticElementInteractions: delegated Escape and focus tracking for the toolbar inside */}\n <div\n ref={bar}\n className={className ? `cy-docked-toolbar ${className}` : \"cy-docked-toolbar\"}\n data-edge={edge}\n data-floating={floating && !side ? \"\" : undefined}\n data-moving={shift ? \"\" : undefined}\n {...{ popover: \"manual\" }}\n style={\n {\n \"--_inset\": `${inset}px`,\n ...(shift ? { \"--_dx\": `${shift.x}px`, \"--_dy\": `${shift.y}px` } : {}),\n ...style,\n } as CSSProperties\n }\n onFocus={focus.onFocus}\n onKeyDown={onKeyDown}\n >\n {side && onEdgeChange && (\n <IconButton\n ref={grip}\n icon={gripIcon}\n label={text.move}\n variant=\"ghost\"\n size=\"sm\"\n className=\"cy-docked-toolbar-grip\"\n tooltipPlacement={edge === \"start\" ? \"end\" : \"start\"}\n onClick={flip}\n />\n )}\n <Toolbar\n label={label}\n orientation={side ? \"vertical\" : \"horizontal\"}\n className=\"cy-docked-toolbar-row\"\n >\n {children}\n </Toolbar>\n {trailing != null && <div className=\"cy-docked-toolbar-trailing cy-reset\">{trailing}</div>}\n </div>\n </>\n );\n}\n\n/**\n * The current text selection inside `container`, as an anchor for a FloatingToolbar (a formatting bubble). `null`\n * when nothing is selected there. Follows the selection as it changes.\n */\nexport function useSelectionAnchor(container: RefObject<HTMLElement | null>): VirtualAnchor | null {\n const [anchor, setAnchor] = useState<VirtualAnchor | null>(null);\n useEffect(() => {\n const update = () => {\n const selection = document.getSelection();\n const root = container.current;\n if (!selection || selection.isCollapsed || selection.rangeCount === 0 || !root) return setAnchor(null);\n const range = selection.getRangeAt(0);\n if (!root.contains(range.commonAncestorContainer)) return setAnchor(null);\n setAnchor({ getBoundingClientRect: () => range.getBoundingClientRect() });\n };\n document.addEventListener(\"selectionchange\", update);\n return () => document.removeEventListener(\"selectionchange\", update);\n }, [container]);\n return anchor;\n}\n"],"mappings":";;;;;;;;;;;;AAgDA,SAASoB,EAAeC,GAAoC;AAC1D,QAAMC,IAAOP,EAA2B,IAAI;AAC5C,SAAO;AAAA,IACL,SAAA,CAAUQ,MAAmC;AAC3C,YAAMC,IAAOD,EAAM;AACnB,MAAIC,KAAQ,CAACD,EAAM,cAAc,SAASC,CAAI,MAAGF,EAAK,UAAUE;AAAA,IAClE;AAAA,IACA,WAAA,CAAYD,MAAsC;AAChD,UAAIA,EAAM,QAAQ,YAAYA,EAAM,iBAAkB;AACtD,MAA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ACjG,QAAM,CAAC5C,GAAQ6C,CAAA,IAAa3D,EAA+B,IAAI;AAC/D,SAAAF,EAAA,MAAgB;AACd,UAAM+B,IAAA,MAAe;AACnB,YAAM+B,IAAY,SAAS,aAAa,GAClCC,IAAOH,EAAU;AACvB,UAAI,CAACE,KAAaA,EAAU,eAAeA,EAAU,eAAe,KAAK,CAACC,EAAM,QAAOF,EAAU,IAAI;AACrG,YAAMG,IAAQF,EAAU,WAAW,CAAC;AACpC,UAAI,CAACC,EAAK,SAASC,EAAM,uBAAuB,EAAG,QAAOH,EAAU,IAAI;AACxE,MAAAA,EAAU,EAAE,uBAAA,MAA6BG,EAAM,sBAAsB,EAAE,CAAC;AAAA,IAC1E;AACA,oBAAS,iBAAiB,mBAAmBjC,CAAM,GACnD,MAAa,SAAS,oBAAoB,mBAAmBA,CAAM;AAAA,EACrE,GAAG,CAAC6B,CAAS,CAAC,GACP5C;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
-
import { type PaddingProps, type Space } from "../Stack/space.js";
|
|
2
|
+
import { type LayoutAttributes, type PaddingProps, type Space, type VisibilityProps } from "../Stack/space.js";
|
|
3
3
|
/**
|
|
4
4
|
* The widths at which a Grid with `columns` per breakpoint changes its column count. They are widths of the Grid's
|
|
5
5
|
* own content box (inside its padding), not of the window. A breakpoint applies from its width upwards; `base`
|
|
@@ -13,19 +13,23 @@ export declare const GRID_BREAKPOINTS: {
|
|
|
13
13
|
};
|
|
14
14
|
/** A named width of the Grid breakpoint scale. */
|
|
15
15
|
export type GridBreakpoint = keyof typeof GRID_BREAKPOINTS;
|
|
16
|
-
/** A
|
|
17
|
-
export type
|
|
18
|
-
base?:
|
|
16
|
+
/** A value for each width of the grid: `base` below `sm`, then each breakpoint from its width upwards. */
|
|
17
|
+
export type GridResponsive<T> = {
|
|
18
|
+
base?: T | undefined;
|
|
19
19
|
} & {
|
|
20
|
-
[K in GridBreakpoint]?:
|
|
20
|
+
[K in GridBreakpoint]?: T | undefined;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
/** A column count for each width: `base` below `sm`, then each breakpoint from its width upwards. */
|
|
23
|
+
export type GridColumns = GridResponsive<number>;
|
|
24
|
+
export interface GridProps extends PaddingProps, VisibilityProps, LayoutAttributes {
|
|
23
25
|
/**
|
|
24
26
|
* Number of equal columns, or a number per width of the grid itself: `{ base: 1, sm: 2, lg: 4 }`. A breakpoint that
|
|
25
27
|
* is left out keeps the count of the one below it. With `minItemWidth` it is the most columns there can be.
|
|
28
|
+
* A string is a CSS track list for columns of different widths at every width (`"2fr 1fr"`, `"16rem 1fr"`); for
|
|
29
|
+
* unequal columns that change with the width, use equal columns per breakpoint and GridItem `span` per breakpoint.
|
|
26
30
|
* Default 1.
|
|
27
31
|
*/
|
|
28
|
-
columns?: number | GridColumns | undefined;
|
|
32
|
+
columns?: number | GridColumns | string | undefined;
|
|
29
33
|
/** Any CSS length. Columns are at least this wide: as many fit as the width allows, then items wrap. */
|
|
30
34
|
minItemWidth?: string | undefined;
|
|
31
35
|
/** Space token between items. */
|
|
@@ -45,9 +49,26 @@ export interface GridProps extends PaddingProps {
|
|
|
45
49
|
/** Set on the root element, for tests. */
|
|
46
50
|
"data-testid"?: string;
|
|
47
51
|
}
|
|
48
|
-
export interface GridItemProps {
|
|
49
|
-
/**
|
|
50
|
-
|
|
52
|
+
export interface GridItemProps extends VisibilityProps, LayoutAttributes {
|
|
53
|
+
/**
|
|
54
|
+
* Columns the item spans, or `full` for the whole row. Clamped to the columns the grid has at its current width.
|
|
55
|
+
* In a grid with `columns` per breakpoint it can be one per breakpoint too (`{ base: "full", md: 2 }`), measured on
|
|
56
|
+
* the grid's width; a breakpoint that is left out keeps the span of the one below it.
|
|
57
|
+
*/
|
|
58
|
+
span?: number | "full" | GridResponsive<number | "full">;
|
|
59
|
+
/**
|
|
60
|
+
* Visual position among its siblings (CSS `order`; lower comes first), or one per breakpoint in a grid with
|
|
61
|
+
* `columns` per breakpoint (`{ base: 2, md: 1 }` puts it first from `md` up). The reading and tab order stay the
|
|
62
|
+
* source order, so only move things whose order does not matter to understanding them. Default 0.
|
|
63
|
+
*/
|
|
64
|
+
order?: number | GridResponsive<number>;
|
|
65
|
+
/**
|
|
66
|
+
* Stay in view while the page scrolls past it (`position: sticky`), within its row: a sidebar beside a long
|
|
67
|
+
* column. The item keeps its own height instead of stretching to the row's.
|
|
68
|
+
*/
|
|
69
|
+
sticky?: boolean | undefined;
|
|
70
|
+
/** With `sticky`: any CSS length between the top of the scrolling area and the item, e.g. a header's height. Default 0. */
|
|
71
|
+
stickyOffset?: string | undefined;
|
|
51
72
|
/** Rows the item spans. */
|
|
52
73
|
rowSpan?: number;
|
|
53
74
|
/** Neutral layout element to render (never an interactive one). Default "div". */
|
|
@@ -63,5 +84,5 @@ export interface GridItemProps {
|
|
|
63
84
|
}
|
|
64
85
|
/** Two-dimensional layout: a fixed number of columns, or as many as fit at a minimum width. */
|
|
65
86
|
export declare const Grid: import("react").ForwardRefExoticComponent<GridProps & import("react").RefAttributes<HTMLElement>>;
|
|
66
|
-
/** A Grid child that spans several columns or rows. Plain children need no wrapper. */
|
|
87
|
+
/** A Grid child that spans several columns or rows, moves, or sticks. Plain children need no wrapper. */
|
|
67
88
|
export declare const GridItem: import("react").ForwardRefExoticComponent<GridItemProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -1,62 +1,84 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { paddingVars as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { jsx as
|
|
5
|
-
var x = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
xl: "75rem"
|
|
10
|
-
}, O = Object.keys(x), d = (r) => r && r >= 1 ? Math.floor(r) : void 0, E = u(function({ columns: i, minItemWidth: t, gap: o = "4", rowGap: e, padding: l, paddingInline: n, paddingBlock: s, align: c, as: f = "div", className: a, style: I, children: R, ...T }, b) {
|
|
11
|
-
const j = f, v = typeof i == "object" && i !== null, g = {};
|
|
12
|
-
let m = d(v ? i.base : i);
|
|
13
|
-
if (v) {
|
|
2
|
+
import { BREAKPOINTS as O, paddingVars as E, space as T, visibilityAttrs as k } from "../Stack/space.js";
|
|
3
|
+
import { forwardRef as A } from "react";
|
|
4
|
+
import { jsx as B } from "react/jsx-runtime";
|
|
5
|
+
var K = O, G = Object.keys(K), f = (r) => r && r >= 1 ? Math.floor(r) : void 0, x = A(function({ columns: t, minItemWidth: a, gap: i = "4", rowGap: e, padding: o, paddingInline: s, paddingBlock: n, align: u, hideBelow: p, hideAbove: y, as: b = "div", className: l, style: _, children: g, ...c }, v) {
|
|
6
|
+
const $ = b, d = typeof t == "object" && t !== null, N = typeof t == "string" && t.trim() ? t : void 0, R = {};
|
|
7
|
+
let m = f(d ? t.base : typeof t == "number" ? t : void 0);
|
|
8
|
+
if (d) {
|
|
14
9
|
m ??= 1;
|
|
15
|
-
let
|
|
16
|
-
for (const
|
|
17
|
-
|
|
10
|
+
let I = m;
|
|
11
|
+
for (const S of G)
|
|
12
|
+
I = f(t[S]) ?? I, R[`--_cols-${S}`] = I;
|
|
18
13
|
}
|
|
19
|
-
return /* @__PURE__ */
|
|
20
|
-
ref:
|
|
21
|
-
...
|
|
22
|
-
className:
|
|
23
|
-
"data-fit":
|
|
24
|
-
"data-responsive":
|
|
25
|
-
"data-
|
|
14
|
+
return /* @__PURE__ */ B($, {
|
|
15
|
+
ref: v,
|
|
16
|
+
...c,
|
|
17
|
+
className: l ? `cy-grid ${l}` : "cy-grid",
|
|
18
|
+
"data-fit": a ? "" : void 0,
|
|
19
|
+
"data-responsive": d ? "" : void 0,
|
|
20
|
+
"data-tracks": N ? "" : void 0,
|
|
21
|
+
"data-align": u,
|
|
22
|
+
...k({
|
|
23
|
+
hideBelow: p,
|
|
24
|
+
hideAbove: y
|
|
25
|
+
}),
|
|
26
26
|
style: {
|
|
27
|
-
"--_gap":
|
|
28
|
-
"--_row-gap":
|
|
27
|
+
"--_gap": T(i),
|
|
28
|
+
"--_row-gap": T(e ?? i),
|
|
29
29
|
"--_cols": m ?? "initial",
|
|
30
|
-
"--
|
|
31
|
-
|
|
32
|
-
...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
"--_tracks": N ?? "initial",
|
|
31
|
+
"--_min": a ?? "initial",
|
|
32
|
+
...R,
|
|
33
|
+
...E({
|
|
34
|
+
padding: o,
|
|
35
|
+
paddingInline: s,
|
|
36
|
+
paddingBlock: n
|
|
36
37
|
}),
|
|
37
|
-
...
|
|
38
|
+
..._
|
|
38
39
|
},
|
|
39
|
-
children:
|
|
40
|
+
children: g
|
|
40
41
|
});
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
});
|
|
43
|
+
function j(r, t, a, i) {
|
|
44
|
+
const e = {};
|
|
45
|
+
let o = i(t.base ?? a) ?? 0;
|
|
46
|
+
e[`--_${r}-base`] = o;
|
|
47
|
+
for (const s of G) {
|
|
48
|
+
const n = t[s];
|
|
49
|
+
n !== void 0 && (o = i(n) ?? o), e[`--_${r}-${s}`] = o;
|
|
50
|
+
}
|
|
51
|
+
return e;
|
|
52
|
+
}
|
|
53
|
+
var P = (r) => r === "full" ? 1e3 : f(r), F = A(function({ span: t, rowSpan: a, order: i, sticky: e, stickyOffset: o, hideBelow: s, hideAbove: n, as: u = "div", className: p, style: y, children: b, ...l }, _) {
|
|
54
|
+
const g = u, c = typeof t == "object" && t !== null, v = typeof i == "object" && i !== null, $ = t === "full" || c ? void 0 : f(t);
|
|
55
|
+
return /* @__PURE__ */ B(g, {
|
|
56
|
+
ref: _,
|
|
57
|
+
...l,
|
|
58
|
+
className: p ? `cy-grid-item ${p}` : "cy-grid-item",
|
|
59
|
+
"data-full": t === "full" ? "" : void 0,
|
|
60
|
+
"data-span-steps": c ? "" : void 0,
|
|
61
|
+
"data-order-steps": v ? "" : void 0,
|
|
62
|
+
"data-sticky": e ? "" : void 0,
|
|
63
|
+
...k({
|
|
64
|
+
hideBelow: s,
|
|
65
|
+
hideAbove: n
|
|
66
|
+
}),
|
|
48
67
|
style: {
|
|
49
|
-
"--_span":
|
|
50
|
-
"--_row-span":
|
|
51
|
-
...
|
|
68
|
+
"--_span": $ ?? "initial",
|
|
69
|
+
"--_row-span": f(a) ?? "initial",
|
|
70
|
+
...c ? j("span", t, 1, P) : {},
|
|
71
|
+
...v ? j("order", i, 0, (d) => Number.isFinite(d) ? Math.trunc(d) : void 0) : typeof i == "number" && Number.isFinite(i) ? { order: Math.trunc(i) } : {},
|
|
72
|
+
...e && o ? { "--_sticky-top": o } : {},
|
|
73
|
+
...y
|
|
52
74
|
},
|
|
53
|
-
children:
|
|
75
|
+
children: b
|
|
54
76
|
});
|
|
55
77
|
});
|
|
56
78
|
export {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
K as GRID_BREAKPOINTS,
|
|
80
|
+
x as Grid,
|
|
81
|
+
F as GridItem
|
|
60
82
|
};
|
|
61
83
|
|
|
62
84
|
//# sourceMappingURL=Grid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.js","names":["paddingVars","space","forwardRef","jsx","GRID_BREAKPOINTS","BREAKPOINTS","count","n","Grid","columns","minItemWidth","gap","rowGap","padding","paddingInline","paddingBlock","align","as","className","style","children","rest","ref","Tag","responsive","perWidth","cols","current","name","GridItem","span","rowSpan"],"sources":["../../../src/components/Grid/Grid.tsx"],"sourcesContent":["import { type CSSProperties, type ElementType, forwardRef, type ReactNode } from \"react\";\nimport { type PaddingProps, paddingVars, type Space, space } from \"../Stack/space.js\";\n\n/**\n * The widths at which a Grid with `columns` per breakpoint changes its column count. They are widths of the Grid's\n * own content box (inside its padding), not of the window. A breakpoint applies from its width upwards; `base`\n * applies below `sm`. `grid.css` repeats these values (CSS cannot read them from here): change both together.\n */\nexport const GRID_BREAKPOINTS = { sm: \"30rem\", md: \"45rem\", lg: \"60rem\", xl: \"75rem\" } as const;\n\n/** A named width of the Grid breakpoint scale. */\nexport type GridBreakpoint = keyof typeof GRID_BREAKPOINTS;\n\n/** A column count for each width: `base` below `sm`, then each breakpoint from its width upwards. */\nexport type GridColumns = { base?: number | undefined } & { [K in GridBreakpoint]?: number | undefined };\n\nconst BREAKPOINTS = Object.keys(GRID_BREAKPOINTS) as GridBreakpoint[];\n\nexport interface GridProps extends PaddingProps {\n /**\n * Number of equal columns, or a number per width of the grid itself: `{ base: 1, sm: 2, lg: 4 }`. A breakpoint that\n * is left out keeps the count of the one below it. With `minItemWidth` it is the most columns there can be.\n * Default 1.\n */\n columns?: number | GridColumns | undefined;\n /** Any CSS length. Columns are at least this wide: as many fit as the width allows, then items wrap. */\n minItemWidth?: string | undefined;\n /** Space token between items. */\n gap?: Space;\n /** Space token between rows. Default: `gap`. */\n rowGap?: Space;\n /** Block-axis alignment of items in their row. Default: stretch to the row's height. */\n align?: \"start\" | \"center\" | \"end\" | \"stretch\";\n /** Neutral layout element to render (never an interactive one). Use `ul` or `ol` with `GridItem as=\"li\"`. */\n as?: \"div\" | \"section\" | \"ul\" | \"ol\" | \"nav\" | \"aside\" | \"header\" | \"footer\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** The items: any elements, or `GridItem` for ones that span columns or rows. */\n children?: ReactNode;\n /** Set on the root element, for tests. */\n \"data-testid\"?: string;\n}\n\nexport interface GridItemProps {\n /** Columns the item spans, or `full` for the whole row. Clamped to the columns the grid has at its current width. */\n span?: number | \"full\";\n /** Rows the item spans. */\n rowSpan?: number;\n /** Neutral layout element to render (never an interactive one). Default \"div\". */\n as?: \"div\" | \"li\" | \"section\" | \"article\" | \"aside\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** The item's content. */\n children?: ReactNode;\n /** Set on the root element, for tests. */\n \"data-testid\"?: string;\n}\n\nconst count = (n: number | undefined) => (n && n >= 1 ? Math.floor(n) : undefined);\n\n// Custom properties inherit: unset ones are reset to `initial` so a nested Grid never picks up its parent's values.\n\n/** Two-dimensional layout: a fixed number of columns, or as many as fit at a minimum width. */\nexport const Grid = forwardRef<HTMLElement, GridProps>(function Grid(\n {\n columns,\n minItemWidth,\n gap = \"4\",\n rowGap,\n padding,\n paddingInline,\n paddingBlock,\n align,\n as = \"div\",\n className,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const Tag = as as ElementType;\n const responsive = typeof columns === \"object\" && columns !== null;\n const perWidth: Record<string, number> = {};\n let cols = count(responsive ? columns.base : columns);\n if (responsive) {\n // One count per breakpoint, each falling back to the one below, so the CSS never has to chain fallbacks.\n cols ??= 1;\n let current = cols;\n for (const name of BREAKPOINTS) {\n current = count(columns[name]) ?? current;\n perWidth[`--_cols-${name}`] = current;\n }\n }\n return (\n <Tag\n ref={ref}\n {...rest}\n className={className ? `cy-grid ${className}` : \"cy-grid\"}\n data-fit={minItemWidth ? \"\" : undefined}\n data-responsive={responsive ? \"\" : undefined}\n data-align={align}\n style={\n {\n \"--_gap\": space(gap),\n \"--_row-gap\": space(rowGap ?? gap),\n \"--_cols\": cols ?? \"initial\",\n \"--_min\": minItemWidth ?? \"initial\",\n ...perWidth,\n ...paddingVars({ padding, paddingInline, paddingBlock }),\n ...style,\n } as CSSProperties\n }\n >\n {children}\n </Tag>\n );\n});\n\n/** A Grid child that spans several columns or rows. Plain children need no wrapper. */\nexport const GridItem = forwardRef<HTMLElement, GridItemProps>(function GridItem(\n { span, rowSpan, as = \"div\", className, style, children, ...rest },\n ref,\n) {\n const Tag = as as ElementType;\n const cols = span === \"full\" ? undefined : count(span);\n return (\n <Tag\n ref={ref}\n {...rest}\n className={className ? `cy-grid-item ${className}` : \"cy-grid-item\"}\n data-full={span === \"full\" ? \"\" : undefined}\n style={\n {\n \"--_span\": cols ?? \"initial\",\n \"--_row-span\": count(rowSpan) ?? \"initial\",\n ...style,\n } as CSSProperties\n }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;AAAA,MAAa,CAAC;AAAA,MACvD,GAAGI;AAAA,IACL;AAAA,IAGD,UAAAC;AAAA,EACE,CAAA;AAET,CAAC,GAGYS,IAAW3B,EAAuC,SAC7D,EAAE,MAAA4B,GAAM,SAAAC,GAAS,IAAAd,IAAK,OAAO,WAAAC,GAAW,OAAAC,GAAO,UAAAC,GAAU,GAAGC,EAAA,GAC5DC,GACA;AACA,QAAMC,IAAMN,GACNS,IAAOI,MAAS,SAAS,SAAYxB,EAAMwB,CAAI;AACrD,SACE,gBAAA3B,EAACoB,GAAD;AAAA,IACO,KAAAD;AAAA,IACL,GAAID;AAAA,IACJ,WAAWH,IAAY,gBAAgBA,CAAA,KAAc;AAAA,IACrD,aAAWY,MAAS,SAAS,KAAK;AAAA,IAClC,OACE;AAAA,MACE,WAAWJ,KAAQ;AAAA,MACnB,eAAepB,EAAMyB,CAAO,KAAK;AAAA,MACjC,GAAGZ;AAAA,IACL;AAAA,IAGD,UAAAC;AAAA,EACE,CAAA;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"Grid.js","names":["LAYOUT_BREAKPOINTS","BREAKPOINTS$1","paddingVars","space","visibilityAttrs","forwardRef","jsx","GRID_BREAKPOINTS","BREAKPOINTS","count","n","Grid","columns","minItemWidth","gap","rowGap","padding","paddingInline","paddingBlock","align","hideBelow","hideAbove","as","className","style","children","rest","ref","Tag","responsive","tracks","perWidth","cols","current","name","perBreakpoint","value","base","cast","vars","bp","v","spanOf","GridItem","span","rowSpan","order","sticky","stickyOffset","spanSteps","orderSteps"],"sources":["../../../src/components/Grid/Grid.tsx"],"sourcesContent":["import { type CSSProperties, type ElementType, forwardRef, type ReactNode } from \"react\";\nimport {\n BREAKPOINTS as LAYOUT_BREAKPOINTS,\n type LayoutAttributes,\n type PaddingProps,\n paddingVars,\n type Space,\n space,\n type VisibilityProps,\n visibilityAttrs,\n} from \"../Stack/space.js\";\n\n/**\n * The widths at which a Grid with `columns` per breakpoint changes its column count. They are widths of the Grid's\n * own content box (inside its padding), not of the window. A breakpoint applies from its width upwards; `base`\n * applies below `sm`. `grid.css` repeats these values (CSS cannot read them from here): change both together.\n */\nexport const GRID_BREAKPOINTS = LAYOUT_BREAKPOINTS;\n\n/** A named width of the Grid breakpoint scale. */\nexport type GridBreakpoint = keyof typeof GRID_BREAKPOINTS;\n\n/** A value for each width of the grid: `base` below `sm`, then each breakpoint from its width upwards. */\nexport type GridResponsive<T> = { base?: T | undefined } & { [K in GridBreakpoint]?: T | undefined };\n\n/** A column count for each width: `base` below `sm`, then each breakpoint from its width upwards. */\nexport type GridColumns = GridResponsive<number>;\n\nconst BREAKPOINTS = Object.keys(GRID_BREAKPOINTS) as GridBreakpoint[];\n\nexport interface GridProps extends PaddingProps, VisibilityProps, LayoutAttributes {\n /**\n * Number of equal columns, or a number per width of the grid itself: `{ base: 1, sm: 2, lg: 4 }`. A breakpoint that\n * is left out keeps the count of the one below it. With `minItemWidth` it is the most columns there can be.\n * A string is a CSS track list for columns of different widths at every width (`\"2fr 1fr\"`, `\"16rem 1fr\"`); for\n * unequal columns that change with the width, use equal columns per breakpoint and GridItem `span` per breakpoint.\n * Default 1.\n */\n columns?: number | GridColumns | string | undefined;\n /** Any CSS length. Columns are at least this wide: as many fit as the width allows, then items wrap. */\n minItemWidth?: string | undefined;\n /** Space token between items. */\n gap?: Space;\n /** Space token between rows. Default: `gap`. */\n rowGap?: Space;\n /** Block-axis alignment of items in their row. Default: stretch to the row's height. */\n align?: \"start\" | \"center\" | \"end\" | \"stretch\";\n /** Neutral layout element to render (never an interactive one). Use `ul` or `ol` with `GridItem as=\"li\"`. */\n as?: \"div\" | \"section\" | \"ul\" | \"ol\" | \"nav\" | \"aside\" | \"header\" | \"footer\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** The items: any elements, or `GridItem` for ones that span columns or rows. */\n children?: ReactNode;\n /** Set on the root element, for tests. */\n \"data-testid\"?: string;\n}\n\nexport interface GridItemProps extends VisibilityProps, LayoutAttributes {\n /**\n * Columns the item spans, or `full` for the whole row. Clamped to the columns the grid has at its current width.\n * In a grid with `columns` per breakpoint it can be one per breakpoint too (`{ base: \"full\", md: 2 }`), measured on\n * the grid's width; a breakpoint that is left out keeps the span of the one below it.\n */\n span?: number | \"full\" | GridResponsive<number | \"full\">;\n /**\n * Visual position among its siblings (CSS `order`; lower comes first), or one per breakpoint in a grid with\n * `columns` per breakpoint (`{ base: 2, md: 1 }` puts it first from `md` up). The reading and tab order stay the\n * source order, so only move things whose order does not matter to understanding them. Default 0.\n */\n order?: number | GridResponsive<number>;\n /**\n * Stay in view while the page scrolls past it (`position: sticky`), within its row: a sidebar beside a long\n * column. The item keeps its own height instead of stretching to the row's.\n */\n sticky?: boolean | undefined;\n /** With `sticky`: any CSS length between the top of the scrolling area and the item, e.g. a header's height. Default 0. */\n stickyOffset?: string | undefined;\n /** Rows the item spans. */\n rowSpan?: number;\n /** Neutral layout element to render (never an interactive one). Default \"div\". */\n as?: \"div\" | \"li\" | \"section\" | \"article\" | \"aside\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** The item's content. */\n children?: ReactNode;\n /** Set on the root element, for tests. */\n \"data-testid\"?: string;\n}\n\nconst count = (n: number | undefined) => (n && n >= 1 ? Math.floor(n) : undefined);\n\n// Custom properties inherit: unset ones are reset to `initial` so a nested Grid never picks up its parent's values.\n\n/** Two-dimensional layout: a fixed number of columns, or as many as fit at a minimum width. */\nexport const Grid = forwardRef<HTMLElement, GridProps>(function Grid(\n {\n columns,\n minItemWidth,\n gap = \"4\",\n rowGap,\n padding,\n paddingInline,\n paddingBlock,\n align,\n hideBelow,\n hideAbove,\n as = \"div\",\n className,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const Tag = as as ElementType;\n const responsive = typeof columns === \"object\" && columns !== null;\n const tracks = typeof columns === \"string\" && columns.trim() ? columns : undefined;\n const perWidth: Record<string, number> = {};\n let cols = count(responsive ? columns.base : typeof columns === \"number\" ? columns : undefined);\n if (responsive) {\n // One count per breakpoint, each falling back to the one below, so the CSS never has to chain fallbacks.\n cols ??= 1;\n let current = cols;\n for (const name of BREAKPOINTS) {\n current = count(columns[name]) ?? current;\n perWidth[`--_cols-${name}`] = current;\n }\n }\n return (\n <Tag\n ref={ref}\n {...rest}\n className={className ? `cy-grid ${className}` : \"cy-grid\"}\n data-fit={minItemWidth ? \"\" : undefined}\n data-responsive={responsive ? \"\" : undefined}\n data-tracks={tracks ? \"\" : undefined}\n data-align={align}\n {...visibilityAttrs({ hideBelow, hideAbove })}\n style={\n {\n \"--_gap\": space(gap),\n \"--_row-gap\": space(rowGap ?? gap),\n \"--_cols\": cols ?? \"initial\",\n \"--_tracks\": tracks ?? \"initial\",\n \"--_min\": minItemWidth ?? \"initial\",\n ...perWidth,\n ...paddingVars({ padding, paddingInline, paddingBlock }),\n ...style,\n } as CSSProperties\n }\n >\n {children}\n </Tag>\n );\n});\n\n/** A breakpoint value for each width, each falling back to the one below, as `--_<name>-<breakpoint>` properties. */\nfunction perBreakpoint<T>(\n name: string,\n value: GridResponsive<T>,\n base: T,\n cast: (v: T) => number | undefined,\n) {\n const vars: Record<string, number> = {};\n let current = cast(value.base ?? base) ?? 0;\n vars[`--_${name}-base`] = current;\n for (const bp of BREAKPOINTS) {\n const v = value[bp];\n if (v !== undefined) current = cast(v) ?? current;\n vars[`--_${name}-${bp}`] = current;\n }\n return vars;\n}\n\n/** \"full\" per breakpoint: more columns than any grid has, clamped by the grid to the whole row. */\nconst spanOf = (v: number | \"full\") => (v === \"full\" ? 1000 : count(v));\n\n/** A Grid child that spans several columns or rows, moves, or sticks. Plain children need no wrapper. */\nexport const GridItem = forwardRef<HTMLElement, GridItemProps>(function GridItem(\n {\n span,\n rowSpan,\n order,\n sticky,\n stickyOffset,\n hideBelow,\n hideAbove,\n as = \"div\",\n className,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const Tag = as as ElementType;\n const spanSteps = typeof span === \"object\" && span !== null;\n const orderSteps = typeof order === \"object\" && order !== null;\n const cols = span === \"full\" || spanSteps ? undefined : count(span);\n return (\n <Tag\n ref={ref}\n {...rest}\n className={className ? `cy-grid-item ${className}` : \"cy-grid-item\"}\n data-full={span === \"full\" ? \"\" : undefined}\n data-span-steps={spanSteps ? \"\" : undefined}\n data-order-steps={orderSteps ? \"\" : undefined}\n data-sticky={sticky ? \"\" : undefined}\n {...visibilityAttrs({ hideBelow, hideAbove })}\n style={\n {\n \"--_span\": cols ?? \"initial\",\n \"--_row-span\": count(rowSpan) ?? \"initial\",\n ...(spanSteps ? perBreakpoint(\"span\", span, 1, spanOf) : {}),\n ...(orderSteps\n ? perBreakpoint(\"order\", order, 0, (v) => (Number.isFinite(v) ? Math.trunc(v) : undefined))\n : typeof order === \"number\" && Number.isFinite(order)\n ? { order: Math.trunc(order) }\n : {}),\n ...(sticky && stickyOffset ? { \"--_sticky-top\": stickyOffset } : {}),\n ...style,\n } as CSSProperties\n }\n >\n {children}\n </Tag>\n );\n});\n"],"mappings":";;;;AAiBA,IAAaO,IAAmBP,GAW1BQ,IAAc,OAAO,KAAKD,CAAgB,GAiE1CE,IAAA,CAASC,MAA2BA,KAAKA,KAAK,IAAI,KAAK,MAAMA,CAAC,IAAI,QAK3DC,IAAON,EAAmC,SACrD,EACE,SAAAO,GACA,cAAAC,GACA,KAAAC,IAAM,KACN,QAAAC,GACA,SAAAC,GACA,eAAAC,GACA,cAAAC,GACA,OAAAC,GACA,WAAAC,GACA,WAAAC,GACA,IAAAC,IAAK,OACL,WAAAC,GACA,OAAAC,GACA,UAAAC,GACA,GAAGC,EAAA,GAELC,GACA;AACA,QAAMC,IAAMN,GACNO,IAAa,OAAOjB,KAAY,YAAYA,MAAY,MACxDkB,IAAS,OAAOlB,KAAY,YAAYA,EAAQ,KAAK,IAAIA,IAAU,QACnEmB,IAAmC,CAAC;AAC1C,MAAIC,IAAOvB,EAAMoB,IAAajB,EAAQ,OAAO,OAAOA,KAAY,WAAWA,IAAU,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E,GAAGxB;AAAA,IACL;AAAA,IAGD,UAAAC;AAAA,EACE,CAAA;AAET,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { GRID_BREAKPOINTS, Grid, type GridBreakpoint, type GridColumns, GridItem, type GridItemProps, type GridProps, } from "./Grid.js";
|
|
1
|
+
export { GRID_BREAKPOINTS, Grid, type GridBreakpoint, type GridColumns, GridItem, type GridItemProps, type GridProps, type GridResponsive, } from "./Grid.js";
|