@box-kite/react 1.0.0 → 2.0.1
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/.claude/rules/box-kite-rules.md +23 -1
- package/.claude/skills/box-kite/SKILL.md +134 -427
- package/.claude/skills/box-kite/references/components.md +235 -0
- package/.claude/skills/box-kite/references/extending.md +42 -0
- package/.claude/skills/box-kite/references/patterns.md +27 -0
- package/.claude/skills/box-kite/references/styling.md +222 -0
- package/.cursor/rules/box-kite.mdc +73 -0
- package/AGENTS.md +102 -0
- package/BOX_AI_CONTEXT.md +1124 -153
- package/BOX_KITE_AI_CONTEXT.md +1124 -153
- package/README.md +36 -2
- package/a11y.cjs +1 -1
- package/a11y.d.ts +1 -1
- package/a11y.mjs +3 -2
- package/anchor.cjs +1 -0
- package/anchor.d.ts +14 -0
- package/anchor.mjs +3 -0
- package/behavior.cjs +1 -1
- package/behavior.mjs +118 -136
- package/box.cjs +1 -1
- package/box.mjs +1 -1
- package/client.cjs +1 -1
- package/client.mjs +15 -14
- package/components/accordion.cjs +1 -0
- package/components/accordion.d.ts +114 -0
- package/components/accordion.mjs +251 -0
- package/components/button.cjs +1 -1
- package/components/button.d.ts +3 -0
- package/components/button.mjs +1 -1
- package/components/chart.cjs +1 -1
- package/components/chart.d.ts +2 -1
- package/components/chart.mjs +159 -184
- package/components/checkbox.cjs +1 -1
- package/components/checkbox.d.ts +8 -0
- package/components/checkbox.mjs +1 -1
- package/components/combobox/comboboxChips.d.ts +21 -0
- package/components/combobox/comboboxListbox.d.ts +47 -0
- package/components/combobox.cjs +1 -0
- package/components/combobox.d.ts +121 -0
- package/components/combobox.mjs +563 -0
- package/components/dataGrid/components/dataGridAggregateValue.d.ts +10 -0
- package/components/dataGrid/components/dataGridCell.d.ts +2 -1
- package/components/dataGrid/components/dataGridCellEditor.d.ts +15 -0
- package/components/dataGrid/components/dataGridCellPlaceholder.d.ts +14 -0
- package/components/dataGrid/components/dataGridCellTree.d.ts +16 -0
- package/components/dataGrid/components/dataGridDataSourceError.d.ts +12 -0
- package/components/dataGrid/components/dataGridExport.d.ts +10 -0
- package/components/dataGrid/components/dataGridFooter.d.ts +11 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +474 -16
- package/components/dataGrid/export/gridExport.d.ts +10 -0
- package/components/dataGrid/gridNavigationContext.d.ts +9 -1
- package/components/dataGrid/models/aggregateCellModel.d.ts +34 -0
- package/components/dataGrid/models/aggregationModel.d.ts +32 -0
- package/components/dataGrid/models/cellKeys.d.ts +11 -0
- package/components/dataGrid/models/cellModel.d.ts +27 -1
- package/components/dataGrid/models/columnModel.d.ts +12 -2
- package/components/dataGrid/models/dataSourceModel.d.ts +177 -0
- package/components/dataGrid/models/editModel.d.ts +77 -0
- package/components/dataGrid/models/exportModel.d.ts +51 -0
- package/components/dataGrid/models/gridModel.d.ts +108 -21
- package/components/dataGrid/models/groupRowCellModel.d.ts +11 -3
- package/components/dataGrid/models/groupRowModel.d.ts +22 -2
- package/components/dataGrid/models/rowModel.d.ts +13 -1
- package/components/dataGrid/models/sourceGroupRowModel.d.ts +45 -0
- package/components/dataGrid/models/sourceLevel.d.ts +71 -0
- package/components/dataGrid/models/sourceRowModel.d.ts +29 -0
- package/components/dataGrid/models/sourceTreeRowModel.d.ts +23 -0
- package/components/dataGrid/models/treeModel.d.ts +94 -0
- package/components/dataGrid/models/treeRow.d.ts +22 -0
- package/components/dataGrid/models/treeRowModel.d.ts +50 -0
- package/components/dataGrid.cjs +1 -1
- package/components/dataGrid.d.ts +4 -2
- package/components/dataGrid.mjs +4484 -2755
- package/components/dialog.cjs +1 -0
- package/components/dialog.d.ts +151 -0
- package/components/dialog.mjs +223 -0
- package/components/dropdown.cjs +1 -1
- package/components/dropdown.d.ts +30 -0
- package/components/dropdown.mjs +256 -244
- package/components/icon.cjs +1 -1
- package/components/icon.d.ts +2 -1
- package/components/icon.mjs +3 -3
- package/components/menu.cjs +1 -0
- package/components/menu.d.ts +234 -0
- package/components/menu.mjs +422 -0
- package/components/overlay.cjs +1 -1
- package/components/overlay.d.ts +30 -26
- package/components/overlay.mjs +45 -75
- package/components/popover.cjs +1 -0
- package/components/popover.d.ts +100 -0
- package/components/popover.mjs +69 -0
- package/components/presence.d.ts +6 -0
- package/components/progress.cjs +1 -0
- package/components/progress.d.ts +47 -0
- package/components/progress.mjs +28 -0
- package/components/radioButton.cjs +1 -1
- package/components/radioButton.d.ts +8 -0
- package/components/radioButton.mjs +1 -1
- package/components/radioGroup.cjs +1 -1
- package/components/radioGroup.d.ts +15 -2
- package/components/radioGroup.mjs +34 -30
- package/components/select.d.ts +9 -0
- package/components/semantics.cjs +1 -1
- package/components/semantics.d.ts +33 -28
- package/components/semantics.mjs +3 -3
- package/components/slider.cjs +1 -0
- package/components/slider.d.ts +98 -0
- package/components/slider.mjs +250 -0
- package/components/svg.cjs +1 -1
- package/components/svg.d.ts +25 -23
- package/components/svg.mjs +3 -3
- package/components/switch.cjs +1 -1
- package/components/switch.d.ts +9 -0
- package/components/switch.mjs +1 -1
- package/components/tabs.cjs +1 -0
- package/components/tabs.d.ts +87 -0
- package/components/tabs.mjs +324 -0
- package/components/textarea.cjs +1 -1
- package/components/textarea.d.ts +14 -0
- package/components/textarea.mjs +1 -1
- package/components/textbox.cjs +1 -1
- package/components/textbox.d.ts +12 -0
- package/components/textbox.mjs +1 -1
- package/components/toaster.cjs +1 -0
- package/components/toaster.d.ts +106 -0
- package/components/toaster.mjs +295 -0
- package/components/tooltip.cjs +1 -1
- package/components/tooltip.d.ts +39 -4
- package/components/tooltip.mjs +56 -54
- package/docs/a11y.md +199 -0
- package/docs/anchor.md +139 -0
- package/docs/components.md +48 -0
- package/docs/index.md +11 -0
- package/docs/props.md +1777 -0
- package/effects.cjs +1 -1
- package/effects.mjs +1 -1
- package/gridExport.cjs +2 -0
- package/gridExport.mjs +244 -0
- package/identity.cjs +1 -0
- package/identity.mjs +12 -0
- package/keyboard.cjs +1 -0
- package/keyboard.mjs +30 -0
- package/layer.cjs +1 -0
- package/layer.mjs +127 -0
- package/motion.cjs +1 -1
- package/motion.mjs +1 -1
- package/package.json +134 -10
- package/placement.cjs +1 -0
- package/placement.mjs +180 -0
- package/platform.cjs +1 -1
- package/platform.mjs +18 -5
- package/react/anchor/useAnchorPosition.d.ts +79 -0
- package/react/dialog/useScrollLock.d.ts +12 -0
- package/react/hooks/usePortalContainer.d.ts +6 -1
- package/react/hooks/useVirtualization.d.ts +24 -35
- package/react/popover/usePopoverLayer.d.ts +87 -0
- package/react-shared.cjs +1 -1
- package/react-shared.mjs +19 -2
- package/rsc.cjs +1 -1
- package/rsc.mjs +1 -1
- package/utils/accordion/accordionUtils.d.ts +48 -0
- package/utils/anchor/anchorUtils.d.ts +79 -0
- package/utils/array/lazyList.d.ts +10 -0
- package/utils/chart/chartPalette.d.ts +15 -0
- package/utils/chart/chartUtils.d.ts +2 -8
- package/utils/combobox/comboboxUtils.d.ts +89 -0
- package/utils/dom/domUtils.d.ts +6 -0
- package/utils/environment/environmentUtils.d.ts +10 -0
- package/utils/export/csvUtils.d.ts +23 -0
- package/utils/export/downloadUtils.d.ts +12 -0
- package/utils/export/xlsxUtils.d.ts +56 -0
- package/utils/export/zipUtils.d.ts +26 -0
- package/utils/keyboard/typeaheadUtils.d.ts +31 -0
- package/utils/menu/menuUtils.d.ts +25 -0
- package/utils/slider/sliderUtils.d.ts +67 -0
- package/utils/tabs/tabsUtils.d.ts +75 -0
- package/utils/toast/toastStore.d.ts +73 -0
- package/utils/virtual/virtualUtils.d.ts +47 -0
- /package/react/{a11y → identity}/useIdentifier.d.ts +0 -0
package/components/chart.mjs
CHANGED
|
@@ -1,261 +1,236 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import
|
|
1
|
+
import { n as e, r as t, t as n } from "../react-shared.mjs";
|
|
2
|
+
import { Circle as r, Path as i, Svg as a } from "./svg.mjs";
|
|
3
|
+
import { forwardRef as o } from "react";
|
|
4
|
+
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
5
|
+
import u from "@box-kite/react";
|
|
6
6
|
//#region src/utils/chart/chartUtils.ts
|
|
7
|
-
var
|
|
8
|
-
(function(
|
|
9
|
-
let
|
|
10
|
-
function
|
|
7
|
+
var d;
|
|
8
|
+
(function(r) {
|
|
9
|
+
let i = r.VIEW = 100, a = r.CENTRE = i / 2, o = r.FRACTION_STEP = .005;
|
|
10
|
+
function s(e) {
|
|
11
11
|
return Math.round(e * 100) / 100;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
return Math.round(Math.min(Math.max(e, 0), 1) /
|
|
13
|
+
function c(e) {
|
|
14
|
+
return Math.round(Math.min(Math.max(e, 0), 1) / o) * o;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
function
|
|
16
|
+
r.fraction = c;
|
|
17
|
+
function l(e, t = {}) {
|
|
18
18
|
if (e.length === 0) return [];
|
|
19
|
-
let
|
|
19
|
+
let n = t.min ?? Math.min(...e), r = (t.max ?? Math.max(...e)) - n, o = (e) => s(r === 0 ? a : i - (e - n) / r * i);
|
|
20
20
|
if (e.length === 1) return [{
|
|
21
21
|
x: 0,
|
|
22
|
-
y:
|
|
22
|
+
y: o(e[0])
|
|
23
23
|
}, {
|
|
24
|
-
x:
|
|
25
|
-
y:
|
|
24
|
+
x: i,
|
|
25
|
+
y: o(e[0])
|
|
26
26
|
}];
|
|
27
|
-
let c =
|
|
27
|
+
let c = i / (e.length - 1);
|
|
28
28
|
return e.map((e, t) => ({
|
|
29
|
-
x:
|
|
30
|
-
y:
|
|
29
|
+
x: s(t * c),
|
|
30
|
+
y: o(e)
|
|
31
31
|
}));
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
function
|
|
33
|
+
r.points = l;
|
|
34
|
+
function u(e) {
|
|
35
35
|
return e.length === 0 ? "" : e.map((e, t) => `${t === 0 ? "M" : "L"}${e.x} ${e.y}`).join("");
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
function
|
|
37
|
+
r.linePath = u;
|
|
38
|
+
function d(e) {
|
|
39
39
|
if (e.length === 0) return "";
|
|
40
|
-
let
|
|
41
|
-
return `${
|
|
40
|
+
let t = e[e.length - 1];
|
|
41
|
+
return `${u(e)}L${t.x} ${i}L${e[0].x} ${i}Z`;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
function
|
|
43
|
+
r.areaPath = d;
|
|
44
|
+
function f(e, t = {}, n = .25) {
|
|
45
45
|
if (e.length === 0) return "";
|
|
46
|
-
let
|
|
47
|
-
return
|
|
48
|
-
let
|
|
49
|
-
return `M${
|
|
46
|
+
let r = i / e.length, a = s(r * (1 - n)), o = s((r - a) / 2);
|
|
47
|
+
return l(e, t).map((e, t) => {
|
|
48
|
+
let n = Math.min(e.y, i - 1);
|
|
49
|
+
return `M${s(t * r + o)} ${n}h${a}v${s(i - n)}h${-a}Z`;
|
|
50
50
|
}).join("");
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
function
|
|
54
|
-
return
|
|
52
|
+
r.barsPath = f;
|
|
53
|
+
function p(e) {
|
|
54
|
+
return s(a - e / 2);
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
function
|
|
58
|
-
return
|
|
56
|
+
r.radius = p;
|
|
57
|
+
function m(e) {
|
|
58
|
+
return s(2 * Math.PI * e);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
function
|
|
60
|
+
r.circumference = m;
|
|
61
|
+
function h(e, t) {
|
|
62
62
|
return {
|
|
63
|
-
strokeDasharray:
|
|
64
|
-
strokeDashoffset:
|
|
63
|
+
strokeDasharray: s(e),
|
|
64
|
+
strokeDashoffset: s(e * (1 - c(t)))
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
function
|
|
69
|
-
let
|
|
67
|
+
r.dash = h;
|
|
68
|
+
function g(e, t) {
|
|
69
|
+
let n = (t - 90) * Math.PI / 180;
|
|
70
70
|
return {
|
|
71
|
-
x:
|
|
72
|
-
y:
|
|
71
|
+
x: s(a + e * Math.cos(n)),
|
|
72
|
+
y: s(a + e * Math.sin(n))
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
75
|
+
function _(e, t) {
|
|
76
|
+
return s(m(e) * (Math.min(Math.abs(t), 360) / 360));
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
function
|
|
78
|
+
r.arcLength = _;
|
|
79
|
+
function v(e, t, n) {
|
|
80
80
|
if (Math.abs(n) >= 360) {
|
|
81
|
-
let n =
|
|
81
|
+
let n = g(e, t), r = g(e, t + 180);
|
|
82
82
|
return `M${n.x} ${n.y}A${e} ${e} 0 0 1 ${r.x} ${r.y}A${e} ${e} 0 0 1 ${n.x} ${n.y}`;
|
|
83
83
|
}
|
|
84
|
-
let r =
|
|
84
|
+
let r = g(e, t), i = g(e, t + n), a = +(Math.abs(n) > 180), o = n < 0 ? 0 : 1;
|
|
85
85
|
return `M${r.x} ${r.y}A${e} ${e} 0 ${a} ${o} ${i.x} ${i.y}`;
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
function
|
|
87
|
+
r.arcPath = v;
|
|
88
|
+
function y(e, t) {
|
|
89
89
|
let n = e.reduce((e, t) => e + Math.max(t, 0), 0);
|
|
90
90
|
if (n <= 0) return [];
|
|
91
91
|
let r = 0;
|
|
92
|
-
return e.map((e,
|
|
93
|
-
let
|
|
94
|
-
return r +=
|
|
95
|
-
strokeDasharray: `${
|
|
92
|
+
return e.map((e, i) => {
|
|
93
|
+
let a = c(Math.max(e, 0) / n), o = s(t * a), l = s(r * 360);
|
|
94
|
+
return r += a, {
|
|
95
|
+
strokeDasharray: `${o} ${s(t - o)}`,
|
|
96
96
|
rotate: l,
|
|
97
97
|
value: e,
|
|
98
|
-
index:
|
|
98
|
+
index: i
|
|
99
99
|
};
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
let
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"amber-500",
|
|
107
|
-
"violet-500",
|
|
108
|
-
"rose-500",
|
|
109
|
-
"cyan-500"
|
|
110
|
-
];
|
|
111
|
-
e.DARK_PALETTE = [
|
|
112
|
-
"sky-400",
|
|
113
|
-
"emerald-400",
|
|
114
|
-
"amber-400",
|
|
115
|
-
"violet-400",
|
|
116
|
-
"rose-400",
|
|
117
|
-
"cyan-400"
|
|
118
|
-
];
|
|
119
|
-
function v(e) {
|
|
120
|
-
return e.reduce((e, t, n) => (e[`chart-${n + 1}`] = t, e), {});
|
|
121
|
-
}
|
|
122
|
-
e.paletteVariables = v;
|
|
123
|
-
function y(e, t = _.length) {
|
|
102
|
+
r.donutSegments = y;
|
|
103
|
+
let b = r.PALETTE = e;
|
|
104
|
+
r.DARK_PALETTE = n, r.paletteVariables = t;
|
|
105
|
+
function x(e, t = b.length) {
|
|
124
106
|
return (Array.isArray(e) ? e.map((e, n) => [e, `var(--chart-${n % t + 1})`]) : Object.entries(e)).reduce((e, [t, n]) => (e[`color-${t}`] = n, e), {});
|
|
125
107
|
}
|
|
126
|
-
|
|
127
|
-
})(
|
|
128
|
-
var
|
|
129
|
-
function
|
|
130
|
-
let { data:
|
|
131
|
-
min:
|
|
132
|
-
max:
|
|
133
|
-
}, g =
|
|
134
|
-
return /* @__PURE__ */
|
|
135
|
-
viewBox:
|
|
108
|
+
r.seriesVariables = x;
|
|
109
|
+
})(d ||= {});
|
|
110
|
+
var f = d, p = `0 0 ${f.VIEW} ${f.VIEW}`, m = f.PALETTE;
|
|
111
|
+
function h(e, t) {
|
|
112
|
+
let { data: n, variant: r = "line", min: o, max: u, children: d, ...m } = e, h = {
|
|
113
|
+
min: o,
|
|
114
|
+
max: u
|
|
115
|
+
}, g = f.points(n, h);
|
|
116
|
+
return /* @__PURE__ */ l(a, {
|
|
117
|
+
viewBox: p,
|
|
118
|
+
component: "sparkline",
|
|
136
119
|
preserveAspectRatio: "none",
|
|
137
|
-
vectorEffect: "non-scaling-stroke",
|
|
138
120
|
width: "100%",
|
|
139
121
|
height: "1.5rem",
|
|
140
|
-
|
|
141
|
-
stroke: "currentColor",
|
|
142
|
-
fill: "currentColor",
|
|
143
|
-
strokeWidth: 1.5,
|
|
144
|
-
strokeLinecap: "round",
|
|
145
|
-
strokeLinejoin: "round",
|
|
146
|
-
ref: r,
|
|
122
|
+
ref: t,
|
|
147
123
|
...m,
|
|
148
|
-
children: [
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}) : /* @__PURE__ */ s
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
d:
|
|
157
|
-
|
|
158
|
-
})] }), p]
|
|
124
|
+
children: [r === "bar" ? /* @__PURE__ */ c(i, {
|
|
125
|
+
component: "sparkline.bar",
|
|
126
|
+
d: f.barsPath(n, h)
|
|
127
|
+
}) : /* @__PURE__ */ l(s, { children: [r === "area" && /* @__PURE__ */ c(i, {
|
|
128
|
+
component: "sparkline.area",
|
|
129
|
+
d: f.areaPath(g)
|
|
130
|
+
}), /* @__PURE__ */ c(i, {
|
|
131
|
+
component: "sparkline.line",
|
|
132
|
+
d: f.linePath(g)
|
|
133
|
+
})] }), d]
|
|
159
134
|
});
|
|
160
135
|
}
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
function
|
|
164
|
-
let { value:
|
|
165
|
-
return /* @__PURE__ */
|
|
166
|
-
viewBox:
|
|
136
|
+
var g = /* @__PURE__ */ o(h);
|
|
137
|
+
g.displayName = "Sparkline";
|
|
138
|
+
function _(e, t) {
|
|
139
|
+
let { value: n, thickness: i = 10, trackOpacity: o, children: s, ...u } = e, d = f.radius(i), m = f.circumference(d);
|
|
140
|
+
return /* @__PURE__ */ l(a, {
|
|
141
|
+
viewBox: p,
|
|
142
|
+
component: "progressRing",
|
|
167
143
|
width: "3rem",
|
|
168
144
|
height: "3rem",
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
strokeLinecap: "round",
|
|
173
|
-
ref: r,
|
|
174
|
-
...f,
|
|
145
|
+
strokeWidth: i,
|
|
146
|
+
ref: t,
|
|
147
|
+
...u,
|
|
175
148
|
children: [
|
|
176
|
-
/* @__PURE__ */
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
149
|
+
/* @__PURE__ */ c(r, {
|
|
150
|
+
component: "progressRing.track",
|
|
151
|
+
cx: f.CENTRE,
|
|
152
|
+
cy: f.CENTRE,
|
|
153
|
+
r: d,
|
|
154
|
+
strokeOpacity: o
|
|
181
155
|
}),
|
|
182
|
-
/* @__PURE__ */
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
156
|
+
/* @__PURE__ */ c(r, {
|
|
157
|
+
component: "progressRing.arc",
|
|
158
|
+
cx: f.CENTRE,
|
|
159
|
+
cy: f.CENTRE,
|
|
160
|
+
r: d,
|
|
161
|
+
transform: `rotate(-90 ${f.CENTRE} ${f.CENTRE})`,
|
|
162
|
+
...f.dash(m, n)
|
|
188
163
|
}),
|
|
189
|
-
|
|
164
|
+
s
|
|
190
165
|
]
|
|
191
166
|
});
|
|
192
167
|
}
|
|
193
|
-
var
|
|
194
|
-
|
|
195
|
-
function
|
|
196
|
-
let { value:
|
|
197
|
-
return /* @__PURE__ */
|
|
198
|
-
viewBox:
|
|
168
|
+
var v = /* @__PURE__ */ o(_);
|
|
169
|
+
v.displayName = "ProgressRing";
|
|
170
|
+
function y(e, t) {
|
|
171
|
+
let { value: n, thickness: r = 10, trackOpacity: o, sweep: s = 270, start: u = 225, children: d, ...m } = e, h = f.radius(r), g = f.arcLength(h, s), _ = f.arcPath(h, u, s);
|
|
172
|
+
return /* @__PURE__ */ l(a, {
|
|
173
|
+
viewBox: p,
|
|
174
|
+
component: "gauge",
|
|
199
175
|
width: "4rem",
|
|
200
176
|
height: "4rem",
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
strokeWidth: a,
|
|
204
|
-
strokeLinecap: "round",
|
|
205
|
-
ref: r,
|
|
177
|
+
strokeWidth: r,
|
|
178
|
+
ref: t,
|
|
206
179
|
...m,
|
|
207
180
|
children: [
|
|
208
|
-
/* @__PURE__ */
|
|
181
|
+
/* @__PURE__ */ c(i, {
|
|
182
|
+
component: "gauge.track",
|
|
209
183
|
d: _,
|
|
210
|
-
strokeOpacity:
|
|
184
|
+
strokeOpacity: o
|
|
211
185
|
}),
|
|
212
|
-
/* @__PURE__ */
|
|
186
|
+
/* @__PURE__ */ c(i, {
|
|
187
|
+
component: "gauge.arc",
|
|
213
188
|
d: _,
|
|
214
|
-
...
|
|
189
|
+
...f.dash(g, n)
|
|
215
190
|
}),
|
|
216
|
-
|
|
191
|
+
d
|
|
217
192
|
]
|
|
218
193
|
});
|
|
219
194
|
}
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
function
|
|
223
|
-
let { data:
|
|
224
|
-
return /* @__PURE__ */
|
|
225
|
-
viewBox:
|
|
195
|
+
var b = /* @__PURE__ */ o(y);
|
|
196
|
+
b.displayName = "Gauge";
|
|
197
|
+
function x(e, t) {
|
|
198
|
+
let { data: n, colors: i = m, thickness: o = 20, children: s, ...u } = e, d = f.radius(o), h = f.circumference(d);
|
|
199
|
+
return /* @__PURE__ */ l(a, {
|
|
200
|
+
viewBox: p,
|
|
201
|
+
component: "miniDonut",
|
|
226
202
|
width: "3rem",
|
|
227
203
|
height: "3rem",
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
cx:
|
|
234
|
-
cy:
|
|
235
|
-
r:
|
|
236
|
-
stroke:
|
|
237
|
-
strokeDasharray:
|
|
238
|
-
transform: `rotate(${
|
|
239
|
-
},
|
|
204
|
+
strokeWidth: o,
|
|
205
|
+
ref: t,
|
|
206
|
+
...u,
|
|
207
|
+
children: [f.donutSegments(n, h).map((e) => /* @__PURE__ */ c(r, {
|
|
208
|
+
component: "miniDonut.segment",
|
|
209
|
+
cx: f.CENTRE,
|
|
210
|
+
cy: f.CENTRE,
|
|
211
|
+
r: d,
|
|
212
|
+
stroke: i[e.index % i.length],
|
|
213
|
+
strokeDasharray: e.strokeDasharray,
|
|
214
|
+
transform: `rotate(${e.rotate - 90} ${f.CENTRE} ${f.CENTRE})`
|
|
215
|
+
}, e.index)), s]
|
|
240
216
|
});
|
|
241
217
|
}
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
function
|
|
245
|
-
let { series: n, vars: r,
|
|
246
|
-
...
|
|
247
|
-
...n ? u.seriesVariables(n) : {},
|
|
218
|
+
var S = /* @__PURE__ */ o(x);
|
|
219
|
+
S.displayName = "MiniDonut";
|
|
220
|
+
function C(e, t) {
|
|
221
|
+
let { series: n, vars: r, ...i } = e, a = {
|
|
222
|
+
...n ? f.seriesVariables(n) : {},
|
|
248
223
|
...r
|
|
249
|
-
}
|
|
250
|
-
return /* @__PURE__ */
|
|
224
|
+
};
|
|
225
|
+
return /* @__PURE__ */ c(u, {
|
|
251
226
|
ref: t,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
...
|
|
227
|
+
component: "chartContainer",
|
|
228
|
+
vars: a,
|
|
229
|
+
...i
|
|
255
230
|
});
|
|
256
231
|
}
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
var
|
|
232
|
+
var w = o(C);
|
|
233
|
+
w.displayName = "ChartContainer";
|
|
234
|
+
var T = w;
|
|
260
235
|
//#endregion
|
|
261
|
-
export {
|
|
236
|
+
export { T as ChartContainer, b as Gauge, S as MiniDonut, v as ProgressRing, g as Sparkline };
|
package/components/checkbox.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../react-shared.cjs"),t=require("../box.cjs"),n=require("../forms.cjs");let r=require("react"),i=require("react/jsx-runtime");var a=[`name`,`onInput`,`onChange`,`autoFocus`,`readOnly`,`value`,`defaultChecked`];function o(o,s){let{label:c,labelProps:l,...u}=o,d=Array.isArray(o.indeterminate)?o.indeterminate[0]:o.indeterminate,f=typeof d==`boolean`&&d,p=e.
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../react-shared.cjs"),t=require("../box.cjs"),n=require("../forms.cjs");let r=require("react"),i=require("react/jsx-runtime");var a=[`name`,`onInput`,`onChange`,`autoFocus`,`readOnly`,`value`,`defaultChecked`];function o(o,s){let{label:c,labelProps:l,...u}=o,d=Array.isArray(o.indeterminate)?o.indeterminate[0]:o.indeterminate,f=typeof d==`boolean`&&d,p=e.i.buildProps(u,a,{type:`checkbox`,...f?{"aria-checked":`mixed`}:{}}),m=(0,r.useRef)(null);return(0,r.useImperativeHandle)(s,()=>m.current),(0,r.useEffect)(()=>{m.current&&(m.current.indeterminate=f)},[m,f]),(0,i.jsx)(n.n,{label:c,labelProps:l,children:(0,i.jsx)(t.default,{tag:`input`,ref:m,component:`checkbox`,...p})})}var s=(0,r.forwardRef)(o);s.displayName=`Checkbox`,exports.default=s;
|
package/components/checkbox.d.ts
CHANGED
|
@@ -7,13 +7,21 @@ type TagPropsType = (typeof tagProps)[number];
|
|
|
7
7
|
type CheckboxProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'input', TKey>, 'tag' | 'props'>;
|
|
8
8
|
type CheckboxTagProps = OmitTagProps<BoxTagProps<'input'>, TagPropsType | 'type'>;
|
|
9
9
|
interface Props<TKey extends keyof ComponentsAndVariants> extends CheckboxProps<TKey> {
|
|
10
|
+
/** What the checkbox submits under. Needed for a form; a controlled checkbox can do without one. */
|
|
10
11
|
name?: string;
|
|
12
|
+
/** Attributes for the `<input>` itself — `type` is the component's, and so is `aria-checked`. */
|
|
11
13
|
props?: CheckboxTagProps;
|
|
14
|
+
/** Fires on every click or keystroke. On a checkbox this is the same moment as `onChange`. */
|
|
12
15
|
onInput?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
16
|
+
/** Fires when the box is ticked or cleared. `e.target.checked` is the new state. */
|
|
13
17
|
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
+
/** The value the form submits when it is checked. Defaults to `"on"`, as HTML does. */
|
|
14
19
|
value?: string | number;
|
|
20
|
+
/** Focus it on mount. One per page at most — a stolen focus is a lost place in the document. */
|
|
15
21
|
autoFocus?: boolean;
|
|
22
|
+
/** Rendered and read, but not toggleable. Unlike `disabled` it stays in the tab order and submits. */
|
|
16
23
|
readOnly?: boolean;
|
|
24
|
+
/** The state it starts in when the checkbox is uncontrolled. Pass `checked` instead to control it. */
|
|
17
25
|
defaultChecked?: boolean;
|
|
18
26
|
/**
|
|
19
27
|
* The text beside the checkbox — rendered inside a `<label>` that wraps the input, so the
|
package/components/checkbox.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { i as e } from "../react-shared.mjs";
|
|
3
3
|
import t from "../box.mjs";
|
|
4
4
|
import { n } from "../forms.mjs";
|
|
5
5
|
import { forwardRef as r, useEffect as i, useImperativeHandle as a, useRef as o } from "react";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ClassNameType } from '@box-kite/core';
|
|
2
|
+
import { ComboboxRowDef } from '../../utils/combobox/comboboxUtils';
|
|
3
|
+
export interface ComboboxChipsProps<TRow> {
|
|
4
|
+
selection: TRow[];
|
|
5
|
+
def: ComboboxRowDef<TRow>;
|
|
6
|
+
/** Custom chip content. The label is still the accessible name of its remove button. */
|
|
7
|
+
display?: (row: TRow) => React.ReactNode;
|
|
8
|
+
/** The remove button's accessible name, given the row's label. */
|
|
9
|
+
removeLabel: (label: string) => string;
|
|
10
|
+
onRemove: (row: TRow, event: React.MouseEvent) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
variant: ClassNameType;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The selection, in front of the field, one chip each. The remove buttons are deliberately **not** tab
|
|
16
|
+
* stops: a control holding twenty selections would otherwise cost twenty presses to Tab past. Removal
|
|
17
|
+
* from the keyboard is Backspace on an empty field and toggling the row in the listbox, so the function
|
|
18
|
+
* is reachable without them — and each button still carries a name, so it can be found and pressed by
|
|
19
|
+
* anyone reading the control rather than tabbing through it.
|
|
20
|
+
*/
|
|
21
|
+
export default function ComboboxChips<TRow>(props: ComboboxChipsProps<TRow>): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ClassNameType } from '@box-kite/core';
|
|
2
|
+
import { BoxStyleProps } from '@box-kite/core/types';
|
|
3
|
+
import { ComboboxRow, ComboboxRowDef } from '../../utils/combobox/comboboxUtils';
|
|
4
|
+
import { ElementLike } from '../../utils/dom/domUtils';
|
|
5
|
+
import { PresenceHandle } from '../presence';
|
|
6
|
+
/** How a long list is windowed, or `false` to render every row of it however many there are. */
|
|
7
|
+
export interface ComboboxVirtualize {
|
|
8
|
+
/** The pitch of a row, when it should be declared rather than measured off the rendered ones. */
|
|
9
|
+
itemHeight?: number;
|
|
10
|
+
/** Rows kept either side of what is visible. */
|
|
11
|
+
overscan?: number;
|
|
12
|
+
/** How many rows it takes before windowing starts. */
|
|
13
|
+
threshold?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ComboboxListboxProps<TRow> {
|
|
16
|
+
/** Which way the popup is going, from the `<Presence>` that owns its mount. */
|
|
17
|
+
presence: PresenceHandle;
|
|
18
|
+
/** Every row the listbox shows, already in keyboard order. */
|
|
19
|
+
rows: ComboboxRow<TRow>[];
|
|
20
|
+
def: ComboboxRowDef<TRow>;
|
|
21
|
+
/** Custom row rendering. The label is still what is searched and what the field shows. */
|
|
22
|
+
display?: (row: TRow) => React.ReactNode;
|
|
23
|
+
selection: TRow[];
|
|
24
|
+
multiple: boolean;
|
|
25
|
+
/** The row the keyboard is on, or `-1` when it is on none of them. */
|
|
26
|
+
activeIndex: number;
|
|
27
|
+
optionId: (index: number) => string;
|
|
28
|
+
rowRef: (index: number) => (element: HTMLElement | null) => void;
|
|
29
|
+
onSelect: (index: number, event: React.SyntheticEvent) => void;
|
|
30
|
+
/** The shell the popup hangs off: the field and its chips. */
|
|
31
|
+
anchorRef: ElementLike;
|
|
32
|
+
/** The layer element — what the dismissal hook treats as *inside* the popup. */
|
|
33
|
+
popupRef: React.Ref<HTMLDivElement>;
|
|
34
|
+
listboxId: string;
|
|
35
|
+
labelledBy: string;
|
|
36
|
+
/** Options are on their way. Says so rather than claiming the list is empty. */
|
|
37
|
+
loading?: boolean;
|
|
38
|
+
loadingText: React.ReactNode;
|
|
39
|
+
emptyText: React.ReactNode;
|
|
40
|
+
/** What the create row reads. Given the query, since the row it would make is not shown. */
|
|
41
|
+
createLabel: (query: string) => React.ReactNode;
|
|
42
|
+
/** Render only the rows on screen. On above the threshold by default; `false` never. */
|
|
43
|
+
virtualize?: boolean | ComboboxVirtualize;
|
|
44
|
+
variant: ClassNameType;
|
|
45
|
+
itemsProps?: BoxStyleProps;
|
|
46
|
+
}
|
|
47
|
+
export default function ComboboxListbox<TRow>(props: ComboboxListboxProps<TRow>): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../effects.cjs"),t=require("../box.cjs"),n=require("../behavior.cjs"),r=require("../identity.cjs"),i=require("./svg.cjs"),a=require("./flex.cjs"),o=require("./overlay.cjs"),s=require("./presence.cjs");let c=require("react"),l=require("react/jsx-runtime");var u;(function(e){function t(e,t){return typeof e==`function`?e(t):t[e]}e.read=t;function n(e,n){let r=t(e.label,n);return r==null?``:String(r)}e.labelOf=n;function r(e,r){return e.key===void 0?n(e,r):t(e.key,r)}e.keyOf=r;function i(e,n){return e.disabled!==void 0&&t(e.disabled,n)===!0}e.isDisabled=i;let a=/\p{M}/gu;function o(e){return e.normalize(`NFD`).replace(a,``).toLowerCase()}e.normalize=o;function s(e,t){return o(e).includes(o(t))}e.matches=s;function c(e,t,n){return t===``?e:e.filter(e=>s(n(e),t))}e.filterRows=c;function l(e){return e==null?[]:Array.isArray(e)?e:[e]}e.toArray=l;function u(e,t,n){let r=n(t);return e.some(e=>n(e)===r)}e.isSelected=u;function d(e,t,n,r){return n?u(e,t,r)?e.filter(e=>r(e)!==r(t)):[...e,t]:[t]}e.toggle=d;function f(e){let{data:t,def:r,query:i,filter:a,typed:s,createRow:c}=e,l=e=>n(r,e),u=(!s||a===!1?t:a(t,i,l)).map(e=>({kind:`option`,row:e}));return c&&i!==``&&!t.some(e=>o(l(e))===o(i))&&c(i)!==null&&u.push({kind:`create`,query:i}),u}e.rowsFor=f;function p(e,t){return t.kind===`option`&&i(e,t.row)}e.isRowDisabled=p;function m(e,t,n,i=`first`){let a=e=>r(n,e),o=e.findIndex(e=>e.kind===`option`&&u(t,e.row,a));if(o!==-1&&!p(n,e[o]))return o;let s=e.map((e,t)=>p(n,e)?-1:t).filter(e=>e!==-1);return(i===`last`?s[s.length-1]:s[0])??-1}e.activeIndexFor=m})(u||={});var d=u;function f(e){let{selection:t,def:n,display:r,removeLabel:o,onRemove:s,disabled:c,variant:u}=e;return(0,l.jsx)(l.Fragment,{children:t.map(e=>{let t=d.labelOf(n,e);return(0,l.jsxs)(a.default,{component:`combobox.chip`,variant:u,ai:`center`,gap:1,children:[r?.(e)??t,!c&&(0,l.jsx)(a.default,{tag:`button`,component:`combobox.remove`,variant:u,ai:`center`,jc:`center`,props:{type:`button`,tabIndex:-1,"aria-label":o(t),onMouseDown:e=>e.preventDefault(),onClick:t=>{t.stopPropagation(),s(e,t)}},children:(0,l.jsx)(i.Svg,{viewBox:`0 0 24 24`,width:`0.625rem`,props:{fill:`none`},children:(0,l.jsx)(i.Path,{d:`M6 6 18 18M18 6 6 18`,stroke:`currentColor`,strokeWidth:3,strokeLinecap:`round`})})})]},d.keyOf(n,e))})})}var p;(function(e){let t=e.DEFAULT_OVERSCAN=4,n=e.DEFAULT_THRESHOLD=100;e.DEFAULT_ITEM_HEIGHT=36,e.DEFAULT_VIEW_HEIGHT=248;function r(e,t,n){return Math.min(Math.max(e,t),n)}function i(e,t,r=n){return t??e>r}e.shouldVirtualize=i;function a(e){let{count:n,itemHeight:i,viewHeight:a,scrollTop:o,overscan:s=t,activeIndex:c=-1}=e;if(n<=0||i<=0)return{startIndex:0,endIndex:Math.max(0,n),offsetY:0,totalHeight:0};let l=Math.max(1,Math.ceil(a/i)),u=Math.min(n,l+s*2),d=n-u,f=r(Math.floor(o/i)-s,0,d);return c>=0&&c<n&&(c<f?f=r(c-s,0,d):c>=f+u&&(f=r(c+1+s-u,0,d))),{startIndex:f,endIndex:f+u,offsetY:f*i,totalHeight:n*i}}e.windowFor=a})(p||={});var m=p;function h(t){let{count:r,scrollerRef:i,itemHeight:a,viewHeight:o,overscan:s,threshold:l,enabled:u,activeIndex:d}=t,[f,p]=(0,c.useState)({top:0,at:-1}),[h,g]=(0,c.useState)({itemHeight:0,viewHeight:0}),_=(0,c.useRef)(null),v=(0,c.useCallback)(e=>{_.current=e},[]),y=m.shouldVirtualize(r,u,l),b=n.a(()=>{let e=i.current,t=_.current;if(!e||!t)return;let n=t.children,r=n[0],a=n[1],o=a?a.offsetTop-r.offsetTop:r?.offsetHeight??0,s=e.clientHeight;g(e=>e.itemHeight===o&&e.viewHeight===s?e:{itemHeight:o,viewHeight:s})});e.n(()=>{if(!y||(b(),typeof ResizeObserver>`u`))return;let e=i.current;if(!e)return;let t=new ResizeObserver(b);return t.observe(e),()=>t.disconnect()},[y,r,b,i]);let x=n.a(e=>{p({top:e.currentTarget.scrollTop,at:d??-1})}),S=m.windowFor({count:r,itemHeight:a??(h.itemHeight>0?h.itemHeight:m.DEFAULT_ITEM_HEIGHT),viewHeight:o??(h.viewHeight>0?h.viewHeight:m.DEFAULT_VIEW_HEIGHT),scrollTop:f.top,overscan:s,activeIndex:d===f.at?-1:d});return y?{...S,virtualized:y,contentRef:v,onScroll:x}:{startIndex:0,endIndex:r,offsetY:0,totalHeight:0,virtualized:y,contentRef:v,onScroll:x}}function g(e,t,n,r){return e?{role:`listbox`,"aria-labelledby":r,...t?{"aria-multiselectable":!0}:{},...n?{"aria-busy":!0}:{}}:{role:`status`}}function _(e){let{presence:n,rows:r,def:i,display:s,selection:u,multiple:f,activeIndex:p,optionId:m,rowRef:_,onSelect:v}=e,{anchorRef:y,popupRef:b,listboxId:x,labelledBy:S,loading:C,loadingText:ee,emptyText:w,createLabel:te,variant:T,itemsProps:ne}=e,{virtualize:E}=e,{present:D,ref:O,props:re}=n,k=e=>d.keyOf(i,e),[A,ie]=(0,c.useState)(!1),ae=(0,c.useCallback)(e=>ie(e===`top`),[]),j=(0,c.useRef)(null),oe=(0,c.useCallback)(e=>{j.current=e,O(e)},[O]),M=typeof E==`object`?E:{},{virtualized:N,startIndex:P,endIndex:se,offsetY:F,totalHeight:I,contentRef:L,onScroll:R}=h({count:r.length,scrollerRef:j,enabled:typeof E==`boolean`?E:void 0,activeIndex:p,...M}),z=N?r.slice(P,se):r,B=(e,t)=>{let n=N?P+t:t,o=e.kind===`option`&&d.isSelected(u,e.row,k),c=d.isRowDisabled(i,e);return(0,l.jsx)(a.default,{ref:_(n),component:`combobox.item`,variant:[T,{create:e.kind===`create`,highlighted:n===p}],selected:o,ai:`center`,gap:2,id:m(n),props:{role:`option`,...N?{"aria-setsize":r.length,"aria-posinset":n+1}:{},...c?{"aria-disabled":!0}:{},onMouseDown:e=>e.preventDefault(),onClick:e=>!c&&v(n,e)},children:e.kind===`create`?te(e.query):s?.(e.row)??d.labelOf(i,e.row)},e.kind===`option`?k(e.row):`create`)};return(0,l.jsx)(o.default,{ref:b,anchor:y,side:`bottom`,align:`start`,offset:.5,matchWidth:!0,onSideChange:ae,children:(0,l.jsxs)(t.default,{ref:oe,component:`combobox.items`,...ne,variant:[T,{closed:!D&&!A,closedUp:!D&&A}],id:x,props:{...g(r.length>0,f,C===!0,S),...re,...N?{onScroll:R}:{}},children:[N?(0,l.jsx)(t.default,{ref:L,component:`combobox.window`,variant:T,style:{height:I,paddingTop:F},children:z.map(B)}):z.map(B),r.length===0&&(0,l.jsx)(t.default,{component:`combobox.message`,variant:T,children:C?ee:w})]})})}var v=new Set([` `,`Home`,`End`,`ArrowLeft`,`ArrowRight`]);function y(o,u){let{data:p,def:m,label:h,labelProps:g,placeholder:y,name:b,disabled:x,props:S,itemsProps:C,hideIcon:ee,filter:w=d.filterRows,loading:te,loadingText:T=`Loading...`,emptyText:ne=`No results`,createRow:E,createLabel:D=e=>`Create "${e}"`,removeLabel:O=e=>`Remove ${e}`,virtualize:re,query:k,defaultQuery:A,onQueryChange:ie,open:ae,defaultOpen:j,onOpenChange:oe,multiple:M=!1,value:N,defaultValue:P,onValueChange:se,...F}=o,I=r.t(`combobox`),L=F.id??`${I}-field`,R=`${I}-listbox`,z=`${I}-label`,B=h!=null&&h!==!1,ce=(0,c.useCallback)(e=>`${I}-option-${e}`,[I]),V=(0,c.useRef)(null),le=(0,c.useRef)(null),H=(0,c.useRef)(null),ue=(0,c.useCallback)(e=>{H.current=e,typeof u==`function`?u(e):u&&(u.current=e)},[u]),de=n.a((e,t)=>{se?.(M?e:e[0]??null,t)}),fe=(0,c.useMemo)(()=>N===void 0?void 0:d.toArray(N),[N]),[U,pe]=n.i({value:fe,defaultValue:()=>d.toArray(P),onChange:de}),[W,G]=n.i({value:ae,defaultValue:j??!1,onChange:oe}),[me,K]=n.i({value:k,defaultValue:A??``,onChange:ie}),[q,J]=(0,c.useState)(!1),Y=(0,c.useCallback)(e=>d.keyOf(m,e),[m]),he=M||U[0]===void 0?``:d.labelOf(m,U[0]),X=q||me!==``?me:he,Z=(0,c.useMemo)(()=>d.rowsFor({data:p,def:m,query:X,filter:w,typed:q,createRow:E}),[p,m,X,w,q,E]),ge=(0,c.useCallback)(e=>Z[e]?d.isRowDisabled(m,Z[e]):!1,[Z,m]),_e=n.a((e,t)=>{G(!1,{reason:e,event:t}),e!==`escape`&&(J(!1),K(``,{reason:`close`,event:t}))}),Q=n.a((e,t)=>{let n=Z[e];if(!n||ge(e))return;let r=n.kind===`create`?E?.(n.query):n.row;if(r==null)return;let i=d.isSelected(U,r,Y),a=n.kind===`create`?`create`:i&&M?`deselect`:`select`;pe(d.toggle(U,r,M,Y),{reason:a,event:t}),J(!1),K(``,{reason:`select`,event:t}),M||G(!1,{reason:`select`,event:t})}),ve=n.t({count:Z.length,focusItems:!1,defaultActiveIndex:-1,isDisabled:ge,onSelect:Q}),{activeIndex:$,setActiveIndex:ye,activeItem:be}=ve;n.r({enabled:W,inside:[V,le],onDismiss:(e,t)=>_e(e===`escape`?`escape`:`outside-pointer`,t)}),e.n(()=>{!W||$===-1||be()?.scrollIntoView?.({block:`nearest`})},[W,$,be]);let xe=(e,t,n)=>{G(!0,{reason:n,event:t});let r=e===`none`?-1:d.activeIndexFor(Z,U,m,e);ye(r,{reason:`programmatic`,event:t})},Se=n.a(e=>{J(!0),K(e.target.value,{reason:`input`,event:e}),W||G(!0,{reason:`input`,event:e}),ye(-1,{reason:`programmatic`,event:e})}),Ce=n.a((e,t)=>{pe(U.filter(t=>Y(t)!==Y(e)),{reason:`remove`,event:t})}),we=e=>{let{key:t}=e;if(t===`ArrowDown`||t===`ArrowUp`){e.preventDefault(),xe(t===`ArrowUp`?`last`:e.altKey?`none`:`first`,e,`trigger`);return}t===`Escape`&&X!==``&&(J(!0),K(``,{reason:`clear`,event:e}))},Te=n.a(e=>{if(S?.onKeyDown?.(e),!(e.defaultPrevented||x)){if(e.key===`Backspace`&&M&&X===``&&U.length>0){Ce(U[U.length-1],e);return}if(!W){we(e);return}if(e.key===`Tab`){$!==-1&&Q($,e),_e(`tab`,e);return}if(e.altKey&&e.key===`ArrowUp`){e.preventDefault(),$===-1?_e(`trigger`,e):Q($,e);return}if(v.has(e.key)){ye(-1,{reason:`programmatic`,event:e});return}ve.onKeyDown(e)}}),Ee=n.a(e=>{!x&&!W&&xe(`first`,e,`trigger`)}),De=n.a(e=>{x||e.target===H.current||(e.preventDefault(),H.current?.focus(),W||xe(`first`,e,`trigger`))}),Oe=Z.length>0||te===!0||ne!==null,ke=W&&$!==-1&&Z.length>0?ce($):void 0,Ae=(0,l.jsx)(t.default,{tag:`input`,component:`combobox.field`,ref:ue,id:L,disabled:x,props:{...S,role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":W,"aria-controls":W&&Oe?R:void 0,"aria-activedescendant":ke,"aria-labelledby":B?z:S?.[`aria-labelledby`],autoComplete:`off`,spellCheck:!1,type:`text`,value:X,placeholder:y,onChange:Se,onKeyDown:Te,onClick:Ee}}),je=!ee&&(0,l.jsx)(a.default,{component:`combobox.icon`,rotate:W?180:0,props:{"aria-hidden":!0},children:(0,l.jsx)(i.Svg,{viewBox:`0 0 10 6`,width:`0.6rem`,props:{fill:`none`},children:(0,l.jsx)(i.Path,{d:`m1 1 4 4 4-4`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`})})}),Me=b===void 0?null:U.map(e=>(0,l.jsx)(t.default,{tag:`input`,props:{type:`hidden`,name:b,value:String(Y(e))}},Y(e))),Ne=Oe&&(0,l.jsx)(s.default,{present:W,children:e=>(0,l.jsx)(_,{presence:e,rows:Z,def:m,display:m.display,selection:U,multiple:M,activeIndex:$,optionId:ce,rowRef:e=>ve.itemProps(e).ref,onSelect:Q,anchorRef:V,popupRef:le,listboxId:R,labelledBy:B?z:L,loading:te,loadingText:T,emptyText:ne,createLabel:D,virtualize:re,variant:F.variant,itemsProps:C})}),Pe=(0,l.jsxs)(a.default,{ref:V,component:`combobox`,ai:`center`,gap:1,flexWrap:`wrap`,...F,props:{onPointerDown:De},children:[Me,M&&(0,l.jsx)(f,{selection:U,def:m,display:m.display,removeLabel:O,onRemove:Ce,disabled:x,variant:F.variant}),Ae,je]});return B?(0,l.jsxs)(a.default,{d:`column`,gap:1,width:`fit-content`,children:[(0,l.jsx)(t.default,{tag:`label`,component:`combobox.label`,id:z,...g,props:{htmlFor:L},children:h}),Pe,Ne]}):(0,l.jsxs)(l.Fragment,{children:[Pe,Ne]})}var b=(0,c.forwardRef)(y);b.displayName=`Combobox`,exports.ComboboxUtils=d,exports.default=b;
|