@box-kite/react 0.0.1 → 2.0.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.
Files changed (280) hide show
  1. package/.claude/rules/box-kite-rules.md +65 -0
  2. package/.claude/skills/box-kite/SKILL.md +138 -0
  3. package/.claude/skills/box-kite/references/components.md +235 -0
  4. package/.claude/skills/box-kite/references/extending.md +42 -0
  5. package/.claude/skills/box-kite/references/patterns.md +27 -0
  6. package/.claude/skills/box-kite/references/styling.md +222 -0
  7. package/.cursor/rules/box-kite.mdc +73 -0
  8. package/AGENTS.md +102 -0
  9. package/BOX_AI_CONTEXT.md +2804 -0
  10. package/BOX_KITE_AI_CONTEXT.md +2804 -0
  11. package/LICENSE +21 -0
  12. package/README.md +744 -7
  13. package/a11y.cjs +1 -0
  14. package/a11y.d.ts +15 -0
  15. package/a11y.mjs +4 -0
  16. package/anchor.cjs +1 -0
  17. package/anchor.d.ts +14 -0
  18. package/anchor.mjs +3 -0
  19. package/behavior.cjs +1 -0
  20. package/behavior.mjs +277 -0
  21. package/box.cjs +1 -0
  22. package/box.d.ts +46 -0
  23. package/box.mjs +23 -0
  24. package/client.cjs +1 -0
  25. package/client.mjs +164 -0
  26. package/components/accordion.cjs +1 -0
  27. package/components/accordion.d.ts +114 -0
  28. package/components/accordion.mjs +251 -0
  29. package/components/baseSvg.cjs +1 -0
  30. package/components/baseSvg.d.ts +5 -0
  31. package/components/baseSvg.mjs +21 -0
  32. package/components/button.cjs +1 -0
  33. package/components/button.d.ts +19 -0
  34. package/components/button.mjs +19 -0
  35. package/components/chart.cjs +1 -0
  36. package/components/chart.d.ts +83 -0
  37. package/components/chart.mjs +236 -0
  38. package/components/checkbox.cjs +1 -0
  39. package/components/checkbox.d.ts +36 -0
  40. package/components/checkbox.mjs +38 -0
  41. package/components/combobox/comboboxChips.d.ts +21 -0
  42. package/components/combobox/comboboxListbox.d.ts +47 -0
  43. package/components/combobox.cjs +1 -0
  44. package/components/combobox.d.ts +121 -0
  45. package/components/combobox.mjs +563 -0
  46. package/components/dataGrid/components/dataGridAggregateValue.d.ts +10 -0
  47. package/components/dataGrid/components/dataGridBody.d.ts +7 -0
  48. package/components/dataGrid/components/dataGridBottomBar.d.ts +6 -0
  49. package/components/dataGrid/components/dataGridCell.d.ts +16 -0
  50. package/components/dataGrid/components/dataGridCellEditor.d.ts +15 -0
  51. package/components/dataGrid/components/dataGridCellPlaceholder.d.ts +14 -0
  52. package/components/dataGrid/components/dataGridCellRowDetail.d.ts +6 -0
  53. package/components/dataGrid/components/dataGridCellRowSelection.d.ts +6 -0
  54. package/components/dataGrid/components/dataGridCellText.d.ts +6 -0
  55. package/components/dataGrid/components/dataGridCellTree.d.ts +16 -0
  56. package/components/dataGrid/components/dataGridColumnFilter.d.ts +9 -0
  57. package/components/dataGrid/components/dataGridColumnGroups.d.ts +7 -0
  58. package/components/dataGrid/components/dataGridContent.d.ts +6 -0
  59. package/components/dataGrid/components/dataGridDataSourceError.d.ts +12 -0
  60. package/components/dataGrid/components/dataGridDetailRow.d.ts +8 -0
  61. package/components/dataGrid/components/dataGridEmptyColumns.d.ts +6 -0
  62. package/components/dataGrid/components/dataGridExport.d.ts +10 -0
  63. package/components/dataGrid/components/dataGridFilterCell.d.ts +11 -0
  64. package/components/dataGrid/components/dataGridFilterRow.d.ts +6 -0
  65. package/components/dataGrid/components/dataGridFooter.d.ts +11 -0
  66. package/components/dataGrid/components/dataGridGlobalFilter.d.ts +6 -0
  67. package/components/dataGrid/components/dataGridGroupRow.d.ts +8 -0
  68. package/components/dataGrid/components/dataGridHeader.d.ts +6 -0
  69. package/components/dataGrid/components/dataGridHeaderCell.d.ts +9 -0
  70. package/components/dataGrid/components/dataGridHeaderCellContextMenu.d.ts +11 -0
  71. package/components/dataGrid/components/dataGridHeaderCellResizer.d.ts +14 -0
  72. package/components/dataGrid/components/dataGridLoader.d.ts +11 -0
  73. package/components/dataGrid/components/dataGridPagination.d.ts +6 -0
  74. package/components/dataGrid/components/dataGridRow.d.ts +8 -0
  75. package/components/dataGrid/components/dataGridTopBar.d.ts +6 -0
  76. package/components/dataGrid/components/dataGridTopBarContextMenu.d.ts +6 -0
  77. package/components/dataGrid/contracts/dataGridContract.d.ts +671 -0
  78. package/components/dataGrid/export/gridExport.d.ts +10 -0
  79. package/components/dataGrid/gridNavigationContext.d.ts +32 -0
  80. package/components/dataGrid/models/aggregateCellModel.d.ts +34 -0
  81. package/components/dataGrid/models/aggregationModel.d.ts +32 -0
  82. package/components/dataGrid/models/cellKeys.d.ts +11 -0
  83. package/components/dataGrid/models/cellModel.d.ts +44 -0
  84. package/components/dataGrid/models/columnModel.d.ts +160 -0
  85. package/components/dataGrid/models/columnVisibilityModel.d.ts +24 -0
  86. package/components/dataGrid/models/dataSourceModel.d.ts +177 -0
  87. package/components/dataGrid/models/detailRowModel.d.ts +22 -0
  88. package/components/dataGrid/models/editModel.d.ts +77 -0
  89. package/components/dataGrid/models/exportModel.d.ts +51 -0
  90. package/components/dataGrid/models/filterModel.d.ts +22 -0
  91. package/components/dataGrid/models/gridModel.d.ts +293 -0
  92. package/components/dataGrid/models/groupRowCellModel.d.ts +34 -0
  93. package/components/dataGrid/models/groupRowModel.d.ts +68 -0
  94. package/components/dataGrid/models/headerCellModel.d.ts +83 -0
  95. package/components/dataGrid/models/paginationModel.d.ts +32 -0
  96. package/components/dataGrid/models/rowModel.d.ts +46 -0
  97. package/components/dataGrid/models/sourceGroupRowModel.d.ts +45 -0
  98. package/components/dataGrid/models/sourceLevel.d.ts +71 -0
  99. package/components/dataGrid/models/sourceRowModel.d.ts +29 -0
  100. package/components/dataGrid/models/sourceTreeRowModel.d.ts +23 -0
  101. package/components/dataGrid/models/treeModel.d.ts +94 -0
  102. package/components/dataGrid/models/treeRow.d.ts +22 -0
  103. package/components/dataGrid/models/treeRowModel.d.ts +50 -0
  104. package/components/dataGrid/models/viewportModel.d.ts +44 -0
  105. package/components/dataGrid/useGrid.d.ts +8 -0
  106. package/components/dataGrid/useGridNavigation.d.ts +21 -0
  107. package/components/dataGrid.cjs +1 -0
  108. package/components/dataGrid.d.ts +4 -0
  109. package/components/dataGrid.mjs +4907 -0
  110. package/components/dialog.cjs +1 -0
  111. package/components/dialog.d.ts +151 -0
  112. package/components/dialog.mjs +223 -0
  113. package/components/dropdown/dropdownContext.d.ts +44 -0
  114. package/components/dropdown/dropdownItems.d.ts +22 -0
  115. package/components/dropdown/dropdownRowRenderer.d.ts +8 -0
  116. package/components/dropdown/dropdownSearch.d.ts +21 -0
  117. package/components/dropdown/utils.d.ts +1 -0
  118. package/components/dropdown.cjs +1 -0
  119. package/components/dropdown.d.ts +77 -0
  120. package/components/dropdown.mjs +491 -0
  121. package/components/flex.cjs +1 -0
  122. package/components/flex.d.ts +6 -0
  123. package/components/flex.mjs +16 -0
  124. package/components/form.cjs +1 -0
  125. package/components/form.d.ts +10 -0
  126. package/components/form.mjs +58 -0
  127. package/components/grid.cjs +1 -0
  128. package/components/grid.d.ts +6 -0
  129. package/components/grid.mjs +16 -0
  130. package/components/icon.cjs +1 -0
  131. package/components/icon.d.ts +37 -0
  132. package/components/icon.mjs +41 -0
  133. package/components/menu.cjs +1 -0
  134. package/components/menu.d.ts +234 -0
  135. package/components/menu.mjs +422 -0
  136. package/components/overlay.cjs +1 -0
  137. package/components/overlay.d.ts +47 -0
  138. package/components/overlay.mjs +52 -0
  139. package/components/popover.cjs +1 -0
  140. package/components/popover.d.ts +100 -0
  141. package/components/popover.mjs +69 -0
  142. package/components/presence.cjs +1 -0
  143. package/components/presence.d.ts +36 -0
  144. package/components/presence.mjs +11 -0
  145. package/components/progress.cjs +1 -0
  146. package/components/progress.d.ts +47 -0
  147. package/components/progress.mjs +28 -0
  148. package/components/radioButton.cjs +1 -0
  149. package/components/radioButton.d.ts +32 -0
  150. package/components/radioButton.mjs +32 -0
  151. package/components/radioGroup.cjs +1 -0
  152. package/components/radioGroup.d.ts +51 -0
  153. package/components/radioGroup.mjs +83 -0
  154. package/components/select.cjs +1 -0
  155. package/components/select.d.ts +51 -0
  156. package/components/select.mjs +36 -0
  157. package/components/semantics.cjs +1 -0
  158. package/components/semantics.d.ts +39 -0
  159. package/components/semantics.mjs +17 -0
  160. package/components/slider.cjs +1 -0
  161. package/components/slider.d.ts +98 -0
  162. package/components/slider.mjs +250 -0
  163. package/components/svg.cjs +1 -0
  164. package/components/svg.d.ts +65 -0
  165. package/components/svg.mjs +141 -0
  166. package/components/switch.cjs +1 -0
  167. package/components/switch.d.ts +29 -0
  168. package/components/switch.mjs +25 -0
  169. package/components/tabs.cjs +1 -0
  170. package/components/tabs.d.ts +87 -0
  171. package/components/tabs.mjs +324 -0
  172. package/components/textarea.cjs +1 -0
  173. package/components/textarea.d.ts +41 -0
  174. package/components/textarea.mjs +33 -0
  175. package/components/textbox.cjs +1 -0
  176. package/components/textbox.d.ts +38 -0
  177. package/components/textbox.mjs +33 -0
  178. package/components/toaster.cjs +1 -0
  179. package/components/toaster.d.ts +106 -0
  180. package/components/toaster.mjs +295 -0
  181. package/components/tooltip.cjs +1 -0
  182. package/components/tooltip.d.ts +98 -0
  183. package/components/tooltip.mjs +110 -0
  184. package/components/visuallyHidden.cjs +1 -0
  185. package/components/visuallyHidden.d.ts +6 -0
  186. package/components/visuallyHidden.mjs +23 -0
  187. package/docs/a11y.md +199 -0
  188. package/docs/anchor.md +139 -0
  189. package/docs/components.md +48 -0
  190. package/docs/index.md +11 -0
  191. package/docs/props.md +1777 -0
  192. package/effects.cjs +1 -0
  193. package/effects.mjs +6 -0
  194. package/forms.cjs +1 -0
  195. package/forms.mjs +21 -0
  196. package/gridExport.cjs +2 -0
  197. package/gridExport.mjs +244 -0
  198. package/icons/dotsIcon.d.ts +2 -0
  199. package/icons/expandIcon.d.ts +2 -0
  200. package/icons/groupingIcon.d.ts +2 -0
  201. package/icons/pinIcon.d.ts +2 -0
  202. package/icons/searchIcon.d.ts +2 -0
  203. package/icons/sortIcon.d.ts +2 -0
  204. package/identity.cjs +1 -0
  205. package/identity.mjs +12 -0
  206. package/keyboard.cjs +1 -0
  207. package/keyboard.mjs +30 -0
  208. package/layer.cjs +1 -0
  209. package/layer.mjs +127 -0
  210. package/motion.cjs +1 -0
  211. package/motion.mjs +66 -0
  212. package/package.json +327 -7
  213. package/placement.cjs +1 -0
  214. package/placement.mjs +180 -0
  215. package/platform.cjs +1 -0
  216. package/platform.mjs +45 -0
  217. package/react/a11y/callbacks.d.ts +12 -0
  218. package/react/a11y/useControllableState.d.ts +25 -0
  219. package/react/a11y/useDismiss.d.ts +25 -0
  220. package/react/a11y/useFocusReturn.d.ts +18 -0
  221. package/react/a11y/useRovingFocus.d.ts +84 -0
  222. package/react/anchor/useAnchorPosition.d.ts +79 -0
  223. package/react/animation/usePresence.d.ts +32 -0
  224. package/react/boxClassNames.d.ts +25 -0
  225. package/react/boxProps.d.ts +49 -0
  226. package/react/boxTagProps.d.ts +7 -0
  227. package/react/clientRuntime.d.ts +11 -0
  228. package/react/dialog/useScrollLock.d.ts +12 -0
  229. package/react/effects.d.ts +10 -0
  230. package/react/forms/labelledControl.d.ts +17 -0
  231. package/react/forms/placeholderProp.d.ts +13 -0
  232. package/react/hooks/usePortalContainer.d.ts +6 -0
  233. package/react/hooks/useVirtualization.d.ts +32 -0
  234. package/react/hooks/useVisibility.d.ts +9 -0
  235. package/react/identity/useIdentifier.d.ts +17 -0
  236. package/react/popover/usePopoverLayer.d.ts +87 -0
  237. package/react/reactTypes.d.ts +10 -0
  238. package/react/resolveStyles.d.ts +18 -0
  239. package/react/styleElements.d.ts +3 -0
  240. package/react/svg/attributesInProps.d.ts +4 -0
  241. package/react/svg/svgNaming.d.ts +15 -0
  242. package/react/theme/theme.d.ts +26 -0
  243. package/react/theme/themeContext.d.ts +7 -0
  244. package/react/useStyles.d.ts +22 -0
  245. package/react-shared.cjs +1 -0
  246. package/react-shared.mjs +122 -0
  247. package/rolldown-runtime.cjs +1 -0
  248. package/rsc.cjs +1 -0
  249. package/rsc.d.ts +27 -0
  250. package/rsc.mjs +18 -0
  251. package/ssg.cjs +1 -0
  252. package/ssg.d.ts +24 -0
  253. package/ssg.mjs +25 -0
  254. package/utils/accordion/accordionUtils.d.ts +48 -0
  255. package/utils/anchor/anchorUtils.d.ts +79 -0
  256. package/utils/animation/animationUtils.d.ts +29 -0
  257. package/utils/array/arrayUtils.d.ts +15 -0
  258. package/utils/array/lazyList.d.ts +10 -0
  259. package/utils/box/boxUtils.d.ts +5 -0
  260. package/utils/chart/chartPalette.d.ts +15 -0
  261. package/utils/chart/chartUtils.d.ts +92 -0
  262. package/utils/combobox/comboboxUtils.d.ts +89 -0
  263. package/utils/dom/domUtils.d.ts +32 -0
  264. package/utils/environment/environmentUtils.d.ts +28 -0
  265. package/utils/export/csvUtils.d.ts +23 -0
  266. package/utils/export/downloadUtils.d.ts +12 -0
  267. package/utils/export/xlsxUtils.d.ts +56 -0
  268. package/utils/export/zipUtils.d.ts +26 -0
  269. package/utils/fn/fnUtils.d.ts +4 -0
  270. package/utils/form/formUtils.d.ts +8 -0
  271. package/utils/keyboard/typeaheadUtils.d.ts +31 -0
  272. package/utils/memo.d.ts +10 -0
  273. package/utils/menu/menuUtils.d.ts +25 -0
  274. package/utils/object/objectUtils.d.ts +13 -0
  275. package/utils/slider/sliderUtils.d.ts +67 -0
  276. package/utils/string/fuzzySearch.d.ts +27 -0
  277. package/utils/string/stringUtils.d.ts +4 -0
  278. package/utils/tabs/tabsUtils.d.ts +75 -0
  279. package/utils/toast/toastStore.d.ts +73 -0
  280. package/utils/virtual/virtualUtils.d.ts +47 -0
@@ -0,0 +1,236 @@
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
+ //#region src/utils/chart/chartUtils.ts
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
+ return Math.round(e * 100) / 100;
12
+ }
13
+ function c(e) {
14
+ return Math.round(Math.min(Math.max(e, 0), 1) / o) * o;
15
+ }
16
+ r.fraction = c;
17
+ function l(e, t = {}) {
18
+ if (e.length === 0) return [];
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
+ if (e.length === 1) return [{
21
+ x: 0,
22
+ y: o(e[0])
23
+ }, {
24
+ x: i,
25
+ y: o(e[0])
26
+ }];
27
+ let c = i / (e.length - 1);
28
+ return e.map((e, t) => ({
29
+ x: s(t * c),
30
+ y: o(e)
31
+ }));
32
+ }
33
+ r.points = l;
34
+ function u(e) {
35
+ return e.length === 0 ? "" : e.map((e, t) => `${t === 0 ? "M" : "L"}${e.x} ${e.y}`).join("");
36
+ }
37
+ r.linePath = u;
38
+ function d(e) {
39
+ if (e.length === 0) return "";
40
+ let t = e[e.length - 1];
41
+ return `${u(e)}L${t.x} ${i}L${e[0].x} ${i}Z`;
42
+ }
43
+ r.areaPath = d;
44
+ function f(e, t = {}, n = .25) {
45
+ if (e.length === 0) return "";
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
+ }).join("");
51
+ }
52
+ r.barsPath = f;
53
+ function p(e) {
54
+ return s(a - e / 2);
55
+ }
56
+ r.radius = p;
57
+ function m(e) {
58
+ return s(2 * Math.PI * e);
59
+ }
60
+ r.circumference = m;
61
+ function h(e, t) {
62
+ return {
63
+ strokeDasharray: s(e),
64
+ strokeDashoffset: s(e * (1 - c(t)))
65
+ };
66
+ }
67
+ r.dash = h;
68
+ function g(e, t) {
69
+ let n = (t - 90) * Math.PI / 180;
70
+ return {
71
+ x: s(a + e * Math.cos(n)),
72
+ y: s(a + e * Math.sin(n))
73
+ };
74
+ }
75
+ function _(e, t) {
76
+ return s(m(e) * (Math.min(Math.abs(t), 360) / 360));
77
+ }
78
+ r.arcLength = _;
79
+ function v(e, t, n) {
80
+ if (Math.abs(n) >= 360) {
81
+ let n = g(e, t), r = g(e, t + 180);
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
+ }
84
+ let r = g(e, t), i = g(e, t + n), a = +(Math.abs(n) > 180), o = n < 0 ? 0 : 1;
85
+ return `M${r.x} ${r.y}A${e} ${e} 0 ${a} ${o} ${i.x} ${i.y}`;
86
+ }
87
+ r.arcPath = v;
88
+ function y(e, t) {
89
+ let n = e.reduce((e, t) => e + Math.max(t, 0), 0);
90
+ if (n <= 0) return [];
91
+ let r = 0;
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
+ rotate: l,
97
+ value: e,
98
+ index: i
99
+ };
100
+ });
101
+ }
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) {
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), {});
107
+ }
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",
119
+ preserveAspectRatio: "none",
120
+ width: "100%",
121
+ height: "1.5rem",
122
+ ref: t,
123
+ ...m,
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]
134
+ });
135
+ }
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",
143
+ width: "3rem",
144
+ height: "3rem",
145
+ strokeWidth: i,
146
+ ref: t,
147
+ ...u,
148
+ children: [
149
+ /* @__PURE__ */ c(r, {
150
+ component: "progressRing.track",
151
+ cx: f.CENTRE,
152
+ cy: f.CENTRE,
153
+ r: d,
154
+ strokeOpacity: o
155
+ }),
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)
163
+ }),
164
+ s
165
+ ]
166
+ });
167
+ }
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",
175
+ width: "4rem",
176
+ height: "4rem",
177
+ strokeWidth: r,
178
+ ref: t,
179
+ ...m,
180
+ children: [
181
+ /* @__PURE__ */ c(i, {
182
+ component: "gauge.track",
183
+ d: _,
184
+ strokeOpacity: o
185
+ }),
186
+ /* @__PURE__ */ c(i, {
187
+ component: "gauge.arc",
188
+ d: _,
189
+ ...f.dash(g, n)
190
+ }),
191
+ d
192
+ ]
193
+ });
194
+ }
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",
202
+ width: "3rem",
203
+ height: "3rem",
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]
216
+ });
217
+ }
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) : {},
223
+ ...r
224
+ };
225
+ return /* @__PURE__ */ c(u, {
226
+ ref: t,
227
+ component: "chartContainer",
228
+ vars: a,
229
+ ...i
230
+ });
231
+ }
232
+ var w = o(C);
233
+ w.displayName = "ChartContainer";
234
+ var T = w;
235
+ //#endregion
236
+ export { T as ChartContainer, b as Gauge, S as MiniDonut, v as ProgressRing, g as Sparkline };
@@ -0,0 +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.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;
@@ -0,0 +1,36 @@
1
+ import { RefAttributes } from 'react';
2
+ import { BoxTagProps, BoxProps } from '../box';
3
+ import { OmitTagProps } from '../react/boxProps';
4
+ import { ComponentsAndVariants } from '@box-kite/core/types';
5
+ declare const tagProps: readonly ["name", "onInput", "onChange", "autoFocus", "readOnly", "value", "defaultChecked"];
6
+ type TagPropsType = (typeof tagProps)[number];
7
+ type CheckboxProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'input', TKey>, 'tag' | 'props'>;
8
+ type CheckboxTagProps = OmitTagProps<BoxTagProps<'input'>, TagPropsType | 'type'>;
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. */
11
+ name?: string;
12
+ /** Attributes for the `<input>` itself — `type` is the component's, and so is `aria-checked`. */
13
+ props?: CheckboxTagProps;
14
+ /** Fires on every click or keystroke. On a checkbox this is the same moment as `onChange`. */
15
+ onInput?: (e: React.ChangeEvent<HTMLInputElement>) => void;
16
+ /** Fires when the box is ticked or cleared. `e.target.checked` is the new state. */
17
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
18
+ /** The value the form submits when it is checked. Defaults to `"on"`, as HTML does. */
19
+ value?: string | number;
20
+ /** Focus it on mount. One per page at most — a stolen focus is a lost place in the document. */
21
+ autoFocus?: boolean;
22
+ /** Rendered and read, but not toggleable. Unlike `disabled` it stays in the tab order and submits. */
23
+ readOnly?: boolean;
24
+ /** The state it starts in when the checkbox is uncontrolled. Pass `checked` instead to control it. */
25
+ defaultChecked?: boolean;
26
+ /**
27
+ * The text beside the checkbox — rendered inside a `<label>` that wraps the input, so the
28
+ * association is the component's job. Without it a consumer has to wire `htmlFor`/`id` by hand,
29
+ * and a checkbox with no label is the single most common accessibility failure there is.
30
+ */
31
+ label?: React.ReactNode;
32
+ /** Styles for the wrapping `<label>`: the row's layout, not the box's own appearance. */
33
+ labelProps?: BoxProps<'label'>;
34
+ }
35
+ declare const _default: <TKey extends keyof ComponentsAndVariants = "checkbox">(props: Props<TKey> & RefAttributes<HTMLInputElement>) => React.ReactNode;
36
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import { i as e } from "../react-shared.mjs";
3
+ import t from "../box.mjs";
4
+ import { n } from "../forms.mjs";
5
+ import { forwardRef as r, useEffect as i, useImperativeHandle as a, useRef as o } from "react";
6
+ import { jsx as s } from "react/jsx-runtime";
7
+ //#region src/components/checkbox.tsx
8
+ var c = [
9
+ "name",
10
+ "onInput",
11
+ "onChange",
12
+ "autoFocus",
13
+ "readOnly",
14
+ "value",
15
+ "defaultChecked"
16
+ ];
17
+ function l(r, l) {
18
+ let { label: u, labelProps: d, ...f } = r, p = Array.isArray(r.indeterminate) ? r.indeterminate[0] : r.indeterminate, m = typeof p == "boolean" && p, h = e.buildProps(f, c, {
19
+ type: "checkbox",
20
+ ...m ? { "aria-checked": "mixed" } : {}
21
+ }), g = o(null);
22
+ return a(l, () => g.current), i(() => {
23
+ g.current && (g.current.indeterminate = m);
24
+ }, [g, m]), /* @__PURE__ */ s(n, {
25
+ label: u,
26
+ labelProps: d,
27
+ children: /* @__PURE__ */ s(t, {
28
+ tag: "input",
29
+ ref: g,
30
+ component: "checkbox",
31
+ ...h
32
+ })
33
+ });
34
+ }
35
+ var u = r(l);
36
+ u.displayName = "Checkbox";
37
+ //#endregion
38
+ export { u as default };
@@ -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;
@@ -0,0 +1,121 @@
1
+ import { RefAttributes } from 'react';
2
+ import { BoxProps } from '../box';
3
+ import { ChangeHandler } from '../react/a11y/useControllableState';
4
+ import { BoxStyleProps, ComponentsAndVariants } from '@box-kite/core/types';
5
+ import { ComboboxFilter, ComboboxRow, ComboboxRowDef } from '../utils/combobox/comboboxUtils';
6
+ import { ComboboxVirtualize } from './combobox/comboboxListbox';
7
+ /** Why the listbox opened or closed. `select` is the transition worth telling apart from a dismissal. */
8
+ export type ComboboxOpenReason = 'trigger' | 'input' | 'select' | 'escape' | 'outside-pointer' | 'tab' | 'imperative';
9
+ /** Why the selection changed. `remove` is a chip's own button; `deselect` is toggling a row back off. */
10
+ export type ComboboxValueReason = 'select' | 'deselect' | 'create' | 'remove';
11
+ /** Why the typed text changed. Only `input` came from a keystroke; the rest are the component tidying up. */
12
+ export type ComboboxQueryReason = 'input' | 'select' | 'clear' | 'close';
13
+ /** How a row is read and how it is drawn. Only `label` is required — it is the text and the name. */
14
+ export interface ComboboxDef<TRow> extends ComboboxRowDef<TRow> {
15
+ /** Custom row rendering. The label is still what is searched, what the field shows and what is read out. */
16
+ display?: (row: TRow) => React.ReactNode;
17
+ }
18
+ interface BaseProps<TRow, TKey extends keyof ComponentsAndVariants = 'combobox'> extends Omit<BoxProps<'div', TKey>, 'ref' | 'tag' | 'children' | 'defaultValue' | 'onChange' | 'disabled' | 'placeholder' | 'open'> {
19
+ /** Every row the combobox can offer. Filtered by the query unless `filter` is `false`. */
20
+ data: TRow[];
21
+ /**
22
+ * How to read a row: its `label` (the text, which is searched and read out), its `key` (what makes two
23
+ * rows the same row), and optionally `disabled` and `display`. A key of the row, or a function.
24
+ */
25
+ def: ComboboxDef<TRow>;
26
+ /**
27
+ * The combobox's name, rendered above it in a real `<label>`. A combobox is not named by what it
28
+ * contains, so without this (or an `aria-label` of your own in `props`) it has no accessible name.
29
+ */
30
+ label?: React.ReactNode;
31
+ /** Styles for the `<label>` itself — it sits above the control rather than wrapping it. */
32
+ labelProps?: BoxProps<'label'>;
33
+ /** The field's placeholder. Not a name — it is gone on the first keystroke. See `label`. */
34
+ placeholder?: string;
35
+ /** What the selection submits under: one hidden input per selected row, carrying its key. */
36
+ name?: string;
37
+ /** Not editable and not openable, but still read out. The real attribute, on the field itself. */
38
+ disabled?: boolean;
39
+ /** Attributes for the `<input>` that *is* the combobox — an `aria-label`, an `inputMode`, an `id`. */
40
+ props?: Record<string, unknown>;
41
+ /** Styles for the popup (`combobox.items`). */
42
+ itemsProps?: BoxStyleProps;
43
+ /** Drop the chevron. It is decoration either way: `aria-hidden` and never focusable. */
44
+ hideIcon?: boolean;
45
+ /**
46
+ * Which rows a query leaves, and in what order — it takes the whole list so it can rank as well as
47
+ * reject, and is handed the label reader so composing it with the built-in one costs nothing.
48
+ * `false` means the data is already filtered, which is what a server that searched needs.
49
+ */
50
+ filter?: ComboboxFilter<TRow> | false;
51
+ /** Rows are on their way. The popup says so rather than claiming there are none. */
52
+ loading?: boolean;
53
+ /** What the popup shows while `loading` and there is nothing to show yet. */
54
+ loadingText?: React.ReactNode;
55
+ /** What the popup shows when the query matched nothing. */
56
+ emptyText?: React.ReactNode;
57
+ /**
58
+ * Turns the query into the row it would create, or `null` to refuse it. Its presence is what offers a
59
+ * create row at all, and one is never offered for a query a row already answers by name.
60
+ */
61
+ createRow?: (query: string) => TRow | null;
62
+ /** What the create row reads. Given the query, since the row it would make is not the one shown. */
63
+ createLabel?: (query: string) => React.ReactNode;
64
+ /**
65
+ * Render only the rows on screen, which is what a list of thousands needs to open in one frame. On by
66
+ * default above a hundred rows; an object tunes it (`threshold` is what turns it on earlier),
67
+ * `false` never windows and `true` always does. Rows have to be a uniform height for it, which is
68
+ * measured rather than declared — a `display` that varies one wants `false`.
69
+ */
70
+ virtualize?: boolean | ComboboxVirtualize;
71
+ /** A chip's remove button's accessible name, given the row's label. */
72
+ removeLabel?: (label: string) => string;
73
+ /** The typed text. Controlled — pair it with `onQueryChange`, which is also the hook an async search uses. */
74
+ query?: string;
75
+ /** The text the field starts with when the combobox owns its own query. */
76
+ defaultQuery?: string;
77
+ /** Fires with the text and why it changed. Only `input` came from a keystroke. */
78
+ onQueryChange?: ChangeHandler<string, ComboboxQueryReason>;
79
+ /** Whether the listbox is showing. Controlled — pair it with `onOpenChange`. */
80
+ open?: boolean;
81
+ /** Whether it starts open, when the combobox owns that itself. */
82
+ defaultOpen?: boolean;
83
+ /** Fires with the new state and why: a press, a keystroke, a choice, Escape, or a press outside. */
84
+ onOpenChange?: ChangeHandler<boolean, ComboboxOpenReason>;
85
+ }
86
+ /**
87
+ * One row at a time, which is the default: the value is a row or `null`, and the field shows the selected
88
+ * row's label whenever nothing is being typed.
89
+ */
90
+ interface SingleProps<TRow> {
91
+ /** Leave it off, or `false`. See the multiple half for the other shape. */
92
+ multiple?: false;
93
+ /** The selected row, or `null`. Controlled — pair it with `onValueChange`. */
94
+ value?: TRow | null;
95
+ /** What is selected to begin with, when the combobox owns its own value. */
96
+ defaultValue?: TRow | null;
97
+ /** Fires with the row itself — the object out of `data`, not a key dug out of it — and why. */
98
+ onValueChange?: ChangeHandler<TRow | null, ComboboxValueReason>;
99
+ }
100
+ /**
101
+ * Several rows, shown as chips in front of the field, and the value is an array. Choosing a row that is
102
+ * already chosen takes it off again, which is the keyboard's way to a chip its own button cannot reach.
103
+ */
104
+ interface MultipleProps<TRow> {
105
+ /** `true` is what turns the value into an array — the one shape a combobox cannot read off its value. */
106
+ multiple: true;
107
+ /** The selected rows. Controlled — pair it with `onValueChange`. */
108
+ value?: TRow[];
109
+ /** What is selected to begin with, when the combobox owns its own value. */
110
+ defaultValue?: TRow[];
111
+ /** Fires with the whole selection, as rows, and why it changed. */
112
+ onValueChange?: ChangeHandler<TRow[], ComboboxValueReason>;
113
+ }
114
+ type Props<TRow, TKey extends keyof ComponentsAndVariants = 'combobox'> = BaseProps<TRow, TKey> & (SingleProps<TRow> | MultipleProps<TRow>);
115
+ interface ComboboxType {
116
+ <TRow, TKey extends keyof ComponentsAndVariants = 'combobox'>(props: Props<TRow, TKey> & RefAttributes<HTMLInputElement>): React.ReactNode;
117
+ }
118
+ declare const Combobox: ComboboxType;
119
+ export default Combobox;
120
+ export { default as ComboboxUtils } from '../utils/combobox/comboboxUtils';
121
+ export type { ComboboxFilter, ComboboxRow, ComboboxRowDef, ComboboxVirtualize };