@central-ui/react 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/LICENSE +49 -0
  2. package/dist/components/accordion/index.d.ts +4 -3
  3. package/dist/components/accordion/index.js +7 -4
  4. package/dist/components/autocomplete/index.d.ts +23 -30
  5. package/dist/components/autocomplete/index.js +81 -56
  6. package/dist/components/avatar/index.d.ts +1 -2
  7. package/dist/components/avatar/index.js +0 -1
  8. package/dist/components/badge/index.d.ts +0 -1
  9. package/dist/components/badge/index.js +2 -2
  10. package/dist/components/banner/index.d.ts +1 -1
  11. package/dist/components/banner/index.js +23 -25
  12. package/dist/components/barchart/index.d.ts +106 -0
  13. package/dist/components/barchart/index.js +122 -0
  14. package/dist/components/breadcrumb/index.d.ts +0 -1
  15. package/dist/components/breadcrumb/index.js +6 -7
  16. package/dist/components/button/index.d.ts +2 -3
  17. package/dist/components/button/index.js +11 -12
  18. package/dist/components/card/index.d.ts +0 -1
  19. package/dist/components/card/index.js +0 -1
  20. package/dist/components/carousel/index.d.ts +169 -0
  21. package/dist/components/carousel/index.js +299 -0
  22. package/dist/components/checkbox/index.d.ts +13 -11
  23. package/dist/components/checkbox/index.js +51 -31
  24. package/dist/components/chip/index.d.ts +1 -1
  25. package/dist/components/chip/index.js +2 -3
  26. package/dist/components/combobox/index.d.ts +33 -49
  27. package/dist/components/combobox/index.js +102 -70
  28. package/dist/components/datepicker/index.d.ts +18 -31
  29. package/dist/components/datepicker/index.js +81 -99
  30. package/dist/components/dialog/index.d.ts +14 -27
  31. package/dist/components/dialog/index.js +17 -18
  32. package/dist/components/divider/index.d.ts +0 -1
  33. package/dist/components/divider/index.js +0 -1
  34. package/dist/components/donutchart/index.d.ts +100 -0
  35. package/dist/components/donutchart/index.js +178 -0
  36. package/dist/components/drawer/index.d.ts +12 -21
  37. package/dist/components/drawer/index.js +34 -36
  38. package/dist/components/empty/index.d.ts +3 -3
  39. package/dist/components/empty/index.js +4 -5
  40. package/dist/components/exception/index.d.ts +86 -0
  41. package/dist/components/exception/index.js +116 -0
  42. package/dist/components/fileupload/index.d.ts +4 -9
  43. package/dist/components/fileupload/index.js +26 -38
  44. package/dist/components/form/index.d.ts +0 -1
  45. package/dist/components/form/index.js +0 -1
  46. package/dist/components/horizontalbarchart/index.d.ts +120 -0
  47. package/dist/components/horizontalbarchart/index.js +193 -0
  48. package/dist/components/input/index.d.ts +22 -22
  49. package/dist/components/input/index.js +76 -105
  50. package/dist/components/linechart/index.d.ts +114 -0
  51. package/dist/components/linechart/index.js +139 -0
  52. package/dist/components/menu/index.d.ts +9 -11
  53. package/dist/components/menu/index.js +42 -39
  54. package/dist/components/metric/index.d.ts +0 -1
  55. package/dist/components/metric/index.js +0 -1
  56. package/dist/components/numberinput/index.d.ts +14 -21
  57. package/dist/components/numberinput/index.js +40 -53
  58. package/dist/components/otpinput/index.d.ts +14 -9
  59. package/dist/components/otpinput/index.js +25 -18
  60. package/dist/components/page/index.d.ts +0 -1
  61. package/dist/components/page/index.js +1 -3
  62. package/dist/components/passwordinput/index.d.ts +14 -11
  63. package/dist/components/passwordinput/index.js +36 -45
  64. package/dist/components/popover/index.d.ts +21 -19
  65. package/dist/components/popover/index.js +34 -15
  66. package/dist/components/radio/index.d.ts +13 -9
  67. package/dist/components/radio/index.js +69 -60
  68. package/dist/components/ratinginput/index.d.ts +13 -8
  69. package/dist/components/ratinginput/index.js +37 -17
  70. package/dist/components/select/index.d.ts +30 -30
  71. package/dist/components/select/index.js +80 -41
  72. package/dist/components/skeleton/index.d.ts +0 -1
  73. package/dist/components/skeleton/index.js +0 -1
  74. package/dist/components/slider/index.d.ts +14 -9
  75. package/dist/components/slider/index.js +64 -63
  76. package/dist/components/spinner/index.d.ts +1 -2
  77. package/dist/components/spinner/index.js +2 -3
  78. package/dist/components/splitter/index.d.ts +1 -2
  79. package/dist/components/splitter/index.js +5 -6
  80. package/dist/components/stepper/index.d.ts +8 -20
  81. package/dist/components/stepper/index.js +15 -16
  82. package/dist/components/switch/index.d.ts +12 -10
  83. package/dist/components/switch/index.js +46 -30
  84. package/dist/components/table/index.d.ts +3 -3
  85. package/dist/components/table/index.js +14 -13
  86. package/dist/components/tabs/index.d.ts +0 -1
  87. package/dist/components/tabs/index.js +1 -2
  88. package/dist/components/textarea/index.d.ts +14 -11
  89. package/dist/components/textarea/index.js +37 -46
  90. package/dist/components/textlink/index.d.ts +3 -1
  91. package/dist/components/textlink/index.js +4 -1
  92. package/dist/components/toast/index.d.ts +8 -14
  93. package/dist/components/toast/index.js +48 -48
  94. package/dist/components/toggle/index.d.ts +0 -1
  95. package/dist/components/toggle/index.js +17 -24
  96. package/dist/components/tooltip/index.d.ts +11 -13
  97. package/dist/components/tooltip/index.js +12 -9
  98. package/dist/components/tour/index.d.ts +154 -0
  99. package/dist/components/tour/index.js +280 -0
  100. package/dist/index.d.ts +7 -2
  101. package/dist/index.js +7 -1
  102. package/dist/types/Icon.d.ts +0 -1
  103. package/dist/types/Icon.js +0 -1
  104. package/dist/types/Style.d.ts +0 -1
  105. package/dist/types/Style.js +0 -1
  106. package/dist/types/Validation.d.ts +12 -0
  107. package/dist/types/Validation.js +1 -0
  108. package/dist/utils/ArkStateToDataAttributes.d.ts +0 -1
  109. package/dist/utils/ArkStateToDataAttributes.js +0 -1
  110. package/dist/utils/Validation.d.ts +14 -0
  111. package/dist/utils/Validation.js +23 -0
  112. package/dist/utils/asChild.d.ts +41 -0
  113. package/dist/utils/asChild.js +15 -0
  114. package/dist/utils/icons.d.ts +24 -0
  115. package/dist/utils/icons.js +160 -0
  116. package/dist/utils/useForwardClickToInput.d.ts +0 -1
  117. package/dist/utils/useForwardClickToInput.js +0 -1
  118. package/dist/utils/virtualization/useVirtualizedAutocomplete.d.ts +0 -1
  119. package/dist/utils/virtualization/useVirtualizedAutocomplete.js +0 -1
  120. package/dist/utils/virtualization/useVirtualizedCombobox.d.ts +0 -1
  121. package/dist/utils/virtualization/useVirtualizedCombobox.js +0 -1
  122. package/dist/utils/virtualization/useVirtualizedTable.d.ts +0 -1
  123. package/dist/utils/virtualization/useVirtualizedTable.js +0 -1
  124. package/package.json +14 -11
  125. package/src/presets/shopify-polaris/shopify-polaris-autocomplete.css +2 -2
  126. package/src/presets/shopify-polaris/shopify-polaris-barchart.css +64 -0
  127. package/src/presets/shopify-polaris/shopify-polaris-carousel.css +62 -0
  128. package/src/presets/shopify-polaris/shopify-polaris-checkbox.css +2 -2
  129. package/src/presets/shopify-polaris/shopify-polaris-combobox.css +2 -2
  130. package/src/presets/shopify-polaris/shopify-polaris-datepicker.css +4 -4
  131. package/src/presets/shopify-polaris/shopify-polaris-dialog.css +16 -0
  132. package/src/presets/shopify-polaris/shopify-polaris-donutchart.css +172 -0
  133. package/src/presets/shopify-polaris/shopify-polaris-drawer.css +16 -0
  134. package/src/presets/shopify-polaris/shopify-polaris-exception.css +40 -0
  135. package/src/presets/shopify-polaris/shopify-polaris-fileupload.css +1 -1
  136. package/src/presets/shopify-polaris/shopify-polaris-horizontalbarchart.css +60 -0
  137. package/src/presets/shopify-polaris/shopify-polaris-input.css +2 -2
  138. package/src/presets/shopify-polaris/shopify-polaris-linechart.css +68 -0
  139. package/src/presets/shopify-polaris/shopify-polaris-menu.css +16 -0
  140. package/src/presets/shopify-polaris/shopify-polaris-numberinput.css +2 -2
  141. package/src/presets/shopify-polaris/shopify-polaris-otpinput.css +2 -2
  142. package/src/presets/shopify-polaris/shopify-polaris-passwordinput.css +2 -2
  143. package/src/presets/shopify-polaris/shopify-polaris-popover.css +29 -0
  144. package/src/presets/shopify-polaris/shopify-polaris-radio.css +2 -2
  145. package/src/presets/shopify-polaris/shopify-polaris-ratinginput.css +2 -2
  146. package/src/presets/shopify-polaris/shopify-polaris-select.css +2 -2
  147. package/src/presets/shopify-polaris/shopify-polaris-slider.css +2 -2
  148. package/src/presets/shopify-polaris/shopify-polaris-stepper.css +16 -0
  149. package/src/presets/shopify-polaris/shopify-polaris-switch.css +2 -2
  150. package/src/presets/shopify-polaris/shopify-polaris-textarea.css +2 -2
  151. package/src/presets/shopify-polaris/shopify-polaris-tooltip.css +16 -0
  152. package/src/presets/shopify-polaris/shopify-polaris.css +6 -0
  153. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-autocomplete.css +2 -2
  154. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-barchart.css +64 -0
  155. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-carousel.css +55 -0
  156. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-checkbox.css +2 -2
  157. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-combobox.css +2 -2
  158. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-datepicker.css +2 -2
  159. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-dialog.css +9 -0
  160. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-donutchart.css +172 -0
  161. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-drawer.css +9 -0
  162. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-exception.css +40 -0
  163. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-fileupload.css +1 -1
  164. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-horizontalbarchart.css +60 -0
  165. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-input.css +2 -2
  166. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-linechart.css +68 -0
  167. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-menu.css +9 -0
  168. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-numberinput.css +2 -2
  169. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-otpinput.css +2 -2
  170. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-passwordinput.css +2 -2
  171. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-popover.css +22 -0
  172. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-radio.css +2 -2
  173. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-ratinginput.css +2 -2
  174. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-slider.css +2 -2
  175. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-stepper.css +9 -0
  176. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-switch.css +2 -2
  177. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-textarea.css +2 -2
  178. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-tooltip.css +9 -0
  179. package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy.css +6 -0
  180. package/dist/components/accordion/index.d.ts.map +0 -1
  181. package/dist/components/accordion/index.js.map +0 -1
  182. package/dist/components/autocomplete/index.d.ts.map +0 -1
  183. package/dist/components/autocomplete/index.js.map +0 -1
  184. package/dist/components/avatar/index.d.ts.map +0 -1
  185. package/dist/components/avatar/index.js.map +0 -1
  186. package/dist/components/badge/index.d.ts.map +0 -1
  187. package/dist/components/badge/index.js.map +0 -1
  188. package/dist/components/banner/index.d.ts.map +0 -1
  189. package/dist/components/banner/index.js.map +0 -1
  190. package/dist/components/breadcrumb/index.d.ts.map +0 -1
  191. package/dist/components/breadcrumb/index.js.map +0 -1
  192. package/dist/components/button/index.d.ts.map +0 -1
  193. package/dist/components/button/index.js.map +0 -1
  194. package/dist/components/card/index.d.ts.map +0 -1
  195. package/dist/components/card/index.js.map +0 -1
  196. package/dist/components/checkbox/index.d.ts.map +0 -1
  197. package/dist/components/checkbox/index.js.map +0 -1
  198. package/dist/components/chip/index.d.ts.map +0 -1
  199. package/dist/components/chip/index.js.map +0 -1
  200. package/dist/components/combobox/index.d.ts.map +0 -1
  201. package/dist/components/combobox/index.js.map +0 -1
  202. package/dist/components/datepicker/index.d.ts.map +0 -1
  203. package/dist/components/datepicker/index.js.map +0 -1
  204. package/dist/components/dialog/index.d.ts.map +0 -1
  205. package/dist/components/dialog/index.js.map +0 -1
  206. package/dist/components/divider/index.d.ts.map +0 -1
  207. package/dist/components/divider/index.js.map +0 -1
  208. package/dist/components/drawer/index.d.ts.map +0 -1
  209. package/dist/components/drawer/index.js.map +0 -1
  210. package/dist/components/empty/index.d.ts.map +0 -1
  211. package/dist/components/empty/index.js.map +0 -1
  212. package/dist/components/fileupload/index.d.ts.map +0 -1
  213. package/dist/components/fileupload/index.js.map +0 -1
  214. package/dist/components/form/index.d.ts.map +0 -1
  215. package/dist/components/form/index.js.map +0 -1
  216. package/dist/components/input/index.d.ts.map +0 -1
  217. package/dist/components/input/index.js.map +0 -1
  218. package/dist/components/menu/index.d.ts.map +0 -1
  219. package/dist/components/menu/index.js.map +0 -1
  220. package/dist/components/metric/index.d.ts.map +0 -1
  221. package/dist/components/metric/index.js.map +0 -1
  222. package/dist/components/numberinput/index.d.ts.map +0 -1
  223. package/dist/components/numberinput/index.js.map +0 -1
  224. package/dist/components/otpinput/index.d.ts.map +0 -1
  225. package/dist/components/otpinput/index.js.map +0 -1
  226. package/dist/components/page/index.d.ts.map +0 -1
  227. package/dist/components/page/index.js.map +0 -1
  228. package/dist/components/passwordinput/index.d.ts.map +0 -1
  229. package/dist/components/passwordinput/index.js.map +0 -1
  230. package/dist/components/popover/index.d.ts.map +0 -1
  231. package/dist/components/popover/index.js.map +0 -1
  232. package/dist/components/radio/index.d.ts.map +0 -1
  233. package/dist/components/radio/index.js.map +0 -1
  234. package/dist/components/ratinginput/index.d.ts.map +0 -1
  235. package/dist/components/ratinginput/index.js.map +0 -1
  236. package/dist/components/select/index.d.ts.map +0 -1
  237. package/dist/components/select/index.js.map +0 -1
  238. package/dist/components/skeleton/index.d.ts.map +0 -1
  239. package/dist/components/skeleton/index.js.map +0 -1
  240. package/dist/components/slider/index.d.ts.map +0 -1
  241. package/dist/components/slider/index.js.map +0 -1
  242. package/dist/components/spinner/index.d.ts.map +0 -1
  243. package/dist/components/spinner/index.js.map +0 -1
  244. package/dist/components/splitter/index.d.ts.map +0 -1
  245. package/dist/components/splitter/index.js.map +0 -1
  246. package/dist/components/stepper/index.d.ts.map +0 -1
  247. package/dist/components/stepper/index.js.map +0 -1
  248. package/dist/components/switch/index.d.ts.map +0 -1
  249. package/dist/components/switch/index.js.map +0 -1
  250. package/dist/components/table/index.d.ts.map +0 -1
  251. package/dist/components/table/index.js.map +0 -1
  252. package/dist/components/tabs/index.d.ts.map +0 -1
  253. package/dist/components/tabs/index.js.map +0 -1
  254. package/dist/components/textarea/index.d.ts.map +0 -1
  255. package/dist/components/textarea/index.js.map +0 -1
  256. package/dist/components/textlink/index.d.ts.map +0 -1
  257. package/dist/components/textlink/index.js.map +0 -1
  258. package/dist/components/toast/index.d.ts.map +0 -1
  259. package/dist/components/toast/index.js.map +0 -1
  260. package/dist/components/toggle/index.d.ts.map +0 -1
  261. package/dist/components/toggle/index.js.map +0 -1
  262. package/dist/components/tooltip/index.d.ts.map +0 -1
  263. package/dist/components/tooltip/index.js.map +0 -1
  264. package/dist/index.d.ts.map +0 -1
  265. package/dist/index.js.map +0 -1
  266. package/dist/types/Icon.d.ts.map +0 -1
  267. package/dist/types/Icon.js.map +0 -1
  268. package/dist/types/Style.d.ts.map +0 -1
  269. package/dist/types/Style.js.map +0 -1
  270. package/dist/types/Tone.d.ts +0 -4
  271. package/dist/types/Tone.d.ts.map +0 -1
  272. package/dist/types/Tone.js +0 -2
  273. package/dist/types/Tone.js.map +0 -1
  274. package/dist/utils/ArkStateToDataAttributes.d.ts.map +0 -1
  275. package/dist/utils/ArkStateToDataAttributes.js.map +0 -1
  276. package/dist/utils/Tone.d.ts +0 -3
  277. package/dist/utils/Tone.d.ts.map +0 -1
  278. package/dist/utils/Tone.js +0 -7
  279. package/dist/utils/Tone.js.map +0 -1
  280. package/dist/utils/useForwardClickToInput.d.ts.map +0 -1
  281. package/dist/utils/useForwardClickToInput.js.map +0 -1
  282. package/dist/utils/virtualization/useVirtualizedAutocomplete.d.ts.map +0 -1
  283. package/dist/utils/virtualization/useVirtualizedAutocomplete.js.map +0 -1
  284. package/dist/utils/virtualization/useVirtualizedCombobox.d.ts.map +0 -1
  285. package/dist/utils/virtualization/useVirtualizedCombobox.js.map +0 -1
  286. package/dist/utils/virtualization/useVirtualizedTable.d.ts.map +0 -1
  287. package/dist/utils/virtualization/useVirtualizedTable.js.map +0 -1
@@ -0,0 +1,139 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useLayoutEffect, useState } from 'react';
3
+ import { twMerge } from 'tailwind-merge';
4
+ import { Area as RechartsArea, CartesianGrid as RechartsGrid, ComposedChart as RechartsComposedChart, Curve as RechartsCurve, Line as RechartsLine, Tooltip as RechartsTooltip, XAxis as RechartsXAxis, YAxis as RechartsYAxis, } from 'recharts';
5
+ const ChartContext = /* @__PURE__ */ createContext(null);
6
+ /** Provides the chart data, formatting, and accessibility settings to its parts. Renders no element. */
7
+ export function Root({ children, labelToString = (label) => label, valueToString = (value) => value.toLocaleString(), allowDecimals = false, curve = 'monotone', ...chart }) {
8
+ return (_jsx(ChartContext.Provider, { value: { ...chart, labelToString, valueToString, allowDecimals, curve }, children: children }));
9
+ }
10
+ function useChart(part) {
11
+ const chart = useContext(ChartContext);
12
+ if (!chart)
13
+ throw new Error(`LineChart.${part} must be inside LineChart.Root`);
14
+ return chart;
15
+ }
16
+ /** Lets a Tooltip part hand its content to the Container, which owns the single Recharts tooltip. */
17
+ const TooltipSlotContext = /* @__PURE__ */ createContext(null);
18
+ /** Recharts supplies its own responsive container, so no extra wrapper is needed. */
19
+ export function Container({ height = 300, className, style, children, hoverGuide = true, ...props }) {
20
+ const chart = useChart('Container');
21
+ const [tooltip, setTooltip] = useState(null);
22
+ return (_jsxs(RechartsComposedChart, { margin: { top: 12, right: 12, bottom: 0, left: 0 }, ...props, data: chart.data, accessibilityLayer: chart.accessibilityLayer, desc: chart.desc, title: chart['aria-label'], className: twMerge('min-w-0 w-full', className), style: { ...style, background: 'transparent' }, height: height, width: "100%", responsive: true, layout: "horizontal", children: [_jsx(TooltipSlotContext.Provider, { value: setTooltip, children: children }), _jsx(RechartsTooltip, { offset: 12, ...tooltip?.props,
23
+ // Native popup slide, timed to match the hover guide's transition.
24
+ animationDuration: 200, animationEasing: "ease-out", shared: true, cursor: hoverGuide && _jsx(HoverGuide, {}), content: (state) => {
25
+ if (!tooltip || !state.active || !state.payload.length)
26
+ return null;
27
+ // Recharts types the payload as unknown; payload[0] is always the hovered record.
28
+ const datum = state.payload[0].payload;
29
+ return (_jsx(TooltipContext.Provider, { value: datum, children: tooltip.render(datum) }));
30
+ } })] }));
31
+ }
32
+ const lineProps = (line, part) =>
33
+ // Recharts forwards data attributes at runtime; its types omit them.
34
+ (line && { 'data-component': part });
35
+ export function XAxis({ className, labelGap = 8, axisLine = false, tickLine = false, ...props }) {
36
+ const chart = useChart('XAxis');
37
+ return (_jsx(RechartsXAxis, { height: "auto", ...props, axisLine: lineProps(axisLine, 'linechart-xaxis-line'), tickLine: lineProps(tickLine, 'linechart-xaxis-tickline'), tick: {
38
+ className,
39
+ 'data-component': 'linechart-xaxis-ticklabel',
40
+ }, tickMargin: labelGap, tickFormatter: chart.labelToString,
41
+ // Recharts measures labels at this size when it hides overlapping ones.
42
+ fontSize: 12, dataKey: "label", type: "category",
43
+ // Points sit on the chart edges instead of in the middle of bar-style slots.
44
+ scale: "point", label: false, angle: 0,
45
+ // Drops labels at a steady step when they would overlap, so the remaining ones stay evenly spaced.
46
+ interval: "equidistantPreserveStart", minTickGap: 8 }));
47
+ }
48
+ export function YAxis({ className, labelGap = 8, axisLine = false, tickLine = false, ...props }) {
49
+ const chart = useChart('YAxis');
50
+ return (_jsx(RechartsYAxis, { width: "auto", ...props, axisLine: lineProps(axisLine, 'linechart-yaxis-line'), tickLine: lineProps(tickLine, 'linechart-yaxis-tickline'), tick: {
51
+ className,
52
+ 'data-component': 'linechart-yaxis-ticklabel',
53
+ }, tickMargin: labelGap, tickFormatter: chart.valueToString, allowDecimals: chart.allowDecimals, fontSize: 12, type: "number", label: false, angle: 0,
54
+ // Always include zero so the line has a baseline, and never collapse the range when every value is 0.
55
+ domain: ([minimum, maximum]) => [
56
+ Math.min(0, minimum),
57
+ Math.max(Math.min(0, minimum) + 1, maximum, 0),
58
+ ], interval: "preserveStartEnd", minTickGap: 8 }));
59
+ }
60
+ /** Horizontal lines only, one per Y value tick. */
61
+ export function Grid({ className }) {
62
+ return (_jsx(RechartsGrid
63
+ // Recharts' native line slot: each line gets the class and a data-component hook.
64
+ , {
65
+ // Recharts' native line slot: each line gets the class and a data-component hook.
66
+ horizontal: { className, 'data-component': 'linechart-gridline' }, vertical: false, fill: "none" }));
67
+ }
68
+ export function Line({ className, activeDot = true, ...props }) {
69
+ const chart = useChart('Line');
70
+ return (_jsx(RechartsLine, { strokeWidth: 2, ...props,
71
+ // Recharts' native shape slot renders the line ourselves, so className and data attributes land on the drawn path.
72
+ shape: (line) => (_jsx(RechartsCurve, { ...line, className: className, "data-component": "linechart-line", "data-curve": chart.curve })), activeDot: activeDot &&
73
+ {
74
+ r: 4,
75
+ strokeWidth: 2,
76
+ // Recharts forwards data attributes at runtime; its types omit them.
77
+ 'data-component': 'linechart-activedot',
78
+ }, dataKey: "value", type: chart.curve,
79
+ // Points only appear on hover; at rest the line stays clean.
80
+ dot: false, isAnimationActive: false }));
81
+ }
82
+ /** Optional shading under the line. Render it before Line so the line draws on top. */
83
+ export function Area({ className, ...props }) {
84
+ const chart = useChart('Area');
85
+ return (_jsx(RechartsArea, { ...props, shape: (area) => (_jsx(RechartsCurve, { ...area, className: className, "data-component": "linechart-area", "data-curve": chart.curve, stroke: "none" })), dataKey: "value", type: chart.curve, stroke: "none",
86
+ // The Line owns the hover dot; the area is only a backdrop.
87
+ activeDot: false, tooltipType: "none", isAnimationActive: false }));
88
+ }
89
+ const TooltipContext = /* @__PURE__ */ createContext(null);
90
+ /** Renders no element: hands its popup to the Container. For extra fields, specify the record type: Tooltip<(typeof data)[number]>. */
91
+ export function Tooltip({ children, offset, allowEscapeViewBox, portal, }) {
92
+ const setTooltip = useContext(TooltipSlotContext);
93
+ if (!setTooltip)
94
+ throw new Error('LineChart.Tooltip must be inside LineChart.Container');
95
+ useLayoutEffect(() => {
96
+ setTooltip({
97
+ render: children,
98
+ props: { offset, allowEscapeViewBox, portal },
99
+ });
100
+ return () => setTooltip(null);
101
+ }, [setTooltip, children, offset, allowEscapeViewBox, portal]);
102
+ return null;
103
+ }
104
+ /** Recharts gives a line chart's cursor the guide's two end points. */
105
+ function HoverGuide({ points, }) {
106
+ if (!points || points.length < 2)
107
+ return null;
108
+ const [start, end] = points;
109
+ return (_jsx("line", { "data-component": "linechart-hoverguide",
110
+ // Draw at x=0 and move with a transform, so CSS can slide it between points (Recharts' cursor has no animation of its own).
111
+ x1: 0, x2: 0, y1: start.y, y2: end.y,
112
+ // The slide between points is built in.
113
+ className: "transition-transform duration-200 ease-out motion-reduce:transition-none", style: { transform: `translateX(${start.x}px)` }, pointerEvents: "none" }));
114
+ }
115
+ export function TooltipPopup({ disableStyle, className, ...props }) {
116
+ return (_jsx("div", { ...props, "data-component": "linechart-tooltip", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
117
+ }
118
+ export function TooltipTitle({ disableStyle, className, ...props }) {
119
+ return (_jsx("p", { ...props, "data-component": "linechart-tooltiptitle", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
120
+ }
121
+ /** Shows the hovered record's label, formatted by `labelToString` on Root. */
122
+ export function TooltipLabel({ disableStyle, className, ...props }) {
123
+ const chart = useChart('TooltipLabel');
124
+ const datum = useContext(TooltipContext);
125
+ if (!datum)
126
+ throw new Error('LineChart.TooltipLabel must be inside LineChart.Tooltip');
127
+ return (_jsx("p", { ...props, "data-component": "linechart-tooltiplabel", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: chart.labelToString(datum.label) }));
128
+ }
129
+ /** Shows the hovered record's value, formatted by `valueToString` on Root. */
130
+ export function TooltipValue({ disableStyle, className, ...props }) {
131
+ const chart = useChart('TooltipValue');
132
+ const datum = useContext(TooltipContext);
133
+ if (!datum)
134
+ throw new Error('LineChart.TooltipValue must be inside LineChart.Tooltip');
135
+ return (_jsx("p", { ...props, "data-component": "linechart-tooltipvalue", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: chart.valueToString(datum.value) }));
136
+ }
137
+ export function TooltipColorIndicator({ disableStyle, className, ...props }) {
138
+ return (_jsx("span", { "aria-hidden": "true", ...props, "data-component": "linechart-tooltipcolorindicator", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
139
+ }
@@ -1,9 +1,10 @@
1
1
  import type { StyleProps } from '../../types/Style.ts';
2
+ import type { AsChildProps } from '../../utils/asChild.ts';
2
3
  import { Menu as BaseMenu } from '@base-ui/react/menu';
3
4
  import type { ComponentPropsWithRef, ReactElement } from 'react';
4
5
  import type { SVGIconProps } from '../../types/Icon.ts';
5
6
  /**
6
- * OpenHandler gives a button menu-trigger behavior. Popup already includes its portal and positioner. Choose ButtonItem for actions and LinkItem for navigation. Use the matching checkbox/radio composition for persistent choices; submenu parts belong in SubMenuRoot.
7
+ * OpenButton renders its own trigger button; pass asChild to give its behavior to your own button instead. Popup already includes its portal and positioner. Choose ButtonItem for actions and LinkItem for navigation. Use the matching checkbox/radio composition for persistent choices; submenu parts belong in SubMenuRoot.
7
8
  *
8
9
  * @example Complete composition
9
10
  * import { Button, Menu } from '@central-ui/react'
@@ -11,9 +12,9 @@ import type { SVGIconProps } from '../../types/Icon.ts';
11
12
  * function Example() {
12
13
  * return (
13
14
  * <Menu.Root>
14
- * <Menu.OpenHandler>
15
+ * <Menu.OpenButton asChild>
15
16
  * <Button.default variant="primary">Options</Button.default>
16
- * </Menu.OpenHandler>
17
+ * </Menu.OpenButton>
17
18
  * <Menu.Popup>
18
19
  * <Menu.Group>
19
20
  * <Menu.GroupLabel>Account</Menu.GroupLabel>
@@ -47,19 +48,17 @@ import type { SVGIconProps } from '../../types/Icon.ts';
47
48
  * </Menu.Popup>
48
49
  * </Menu.SubMenuRoot>
49
50
  */
50
- export declare const Root: typeof BaseMenu.Root;
51
+ export declare function Root<Payload = unknown>(props: BaseMenu.Root.Props<Payload>): import("react").JSX.Element;
51
52
  export declare const SubMenuRoot: typeof BaseMenu.SubmenuRoot;
52
- /** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
53
- export declare const OpenHandler: import("react").ForwardRefExoticComponent<Omit<Omit<BaseMenu.Trigger.Props<unknown>, "children" | "className" | "render"> & {
53
+ /** Opens the menu. Pass asChild to give this behavior to your own element, like your app's Button. */
54
+ export declare const OpenButton: import("react").ForwardRefExoticComponent<Omit<Omit<BaseMenu.Trigger.Props<unknown>, "className" | "render"> & {
54
55
  className?: string;
55
- /** Supply your own accessible control. It receives the behavior; its own className owns the appearance. */
56
- children: ReactElement;
57
- }, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
56
+ } & AsChildProps & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
58
57
  export type PopupProps = Omit<ComponentPropsWithRef<typeof BaseMenu.Popup>, 'className'> & {
59
58
  className?: string;
60
59
  } & Pick<BaseMenu.Portal.Props, 'container' | 'keepMounted'> & Pick<BaseMenu.Positioner.Props, 'anchor' | 'positionMethod' | 'side' | 'sideOffset' | 'align' | 'alignOffset' | 'collisionBoundary' | 'collisionPadding' | 'sticky' | 'arrowPadding' | 'disableAnchorTracking' | 'collisionAvoidance'> & StyleProps;
61
60
  /** Already includes the portal and positioner. Keep it in the matching Root and let the native open state control visibility. */
62
- export declare function Popup({ disableStyle, container, keepMounted, anchor, positionMethod, side, sideOffset, align, alignOffset, collisionBoundary, collisionPadding, sticky, arrowPadding, disableAnchorTracking, collisionAvoidance, className, style, ...props }: PopupProps & StyleProps): import("react").JSX.Element;
61
+ export declare function Popup({ disableStyle, container, keepMounted, anchor, positionMethod, side, sideOffset, align, alignOffset, collisionBoundary, collisionPadding, sticky, arrowPadding, disableAnchorTracking, collisionAvoidance, className, style, ...props }: PopupProps): import("react").JSX.Element;
63
62
  export declare const Arrow: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").SVGProps<SVGSVGElement>, "children" | "dangerouslySetInnerHTML"> & StyleProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
64
63
  export declare const Group: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ContextMenuGroupProps, "className"> & {
65
64
  className?: string;
@@ -112,4 +111,3 @@ export declare const RadioLabel: import("react").ForwardRefExoticComponent<Omit<
112
111
  export declare const RadioItemIndicator: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ContextMenuRadioItemIndicatorProps, "className"> & {
113
112
  className?: string;
114
113
  } & StyleProps, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
115
- //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { asChildRendering } from "../../utils/asChild.js";
2
3
  import { Menu as BaseMenu } from '@base-ui/react/menu';
3
4
  import { cloneElement, createContext, forwardRef, useContext, useEffect, useId, useState, } from 'react';
4
5
  import { twMerge } from 'tailwind-merge';
5
- import { Check, ChevronRight } from 'lucide-react';
6
+ import { Check, ChevronRight } from "../../utils/icons.js";
6
7
  /**
7
- * OpenHandler gives a button menu-trigger behavior. Popup already includes its portal and positioner. Choose ButtonItem for actions and LinkItem for navigation. Use the matching checkbox/radio composition for persistent choices; submenu parts belong in SubMenuRoot.
8
+ * OpenButton renders its own trigger button; pass asChild to give its behavior to your own button instead. Popup already includes its portal and positioner. Choose ButtonItem for actions and LinkItem for navigation. Use the matching checkbox/radio composition for persistent choices; submenu parts belong in SubMenuRoot.
8
9
  *
9
10
  * @example Complete composition
10
11
  * import { Button, Menu } from '@central-ui/react'
@@ -12,9 +13,9 @@ import { Check, ChevronRight } from 'lucide-react';
12
13
  * function Example() {
13
14
  * return (
14
15
  * <Menu.Root>
15
- * <Menu.OpenHandler>
16
+ * <Menu.OpenButton asChild>
16
17
  * <Button.default variant="primary">Options</Button.default>
17
- * </Menu.OpenHandler>
18
+ * </Menu.OpenButton>
18
19
  * <Menu.Popup>
19
20
  * <Menu.Group>
20
21
  * <Menu.GroupLabel>Account</Menu.GroupLabel>
@@ -48,11 +49,14 @@ import { Check, ChevronRight } from 'lucide-react';
48
49
  * </Menu.Popup>
49
50
  * </Menu.SubMenuRoot>
50
51
  */
51
- export const Root = BaseMenu.Root;
52
+ export function Root(props) {
53
+ return _jsx(BaseMenu.Root, { ...props });
54
+ }
52
55
  export const SubMenuRoot = BaseMenu.SubmenuRoot;
53
- /** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
54
- export const OpenHandler = /* @__PURE__ */ forwardRef(function OpenHandler({ children, ...props }, ref) {
55
- return _jsx(BaseMenu.Trigger, { ...props, ref: ref, render: children });
56
+ /** Opens the menu. Pass asChild to give this behavior to your own element, like your app's Button. */
57
+ export const OpenButton = /* @__PURE__ */ forwardRef(function OpenButton({ asChild, disableStyle, children, ...props }, ref) {
58
+ const rendering = asChildRendering({ asChild, children, component: 'menu-openbutton', disableStyle });
59
+ return _jsx(BaseMenu.Trigger, { ...props, ref: ref, ...rendering });
56
60
  });
57
61
  /** Already includes the portal and positioner. Keep it in the matching Root and let the native open state control visibility. */
58
62
  export function Popup({ disableStyle, container, keepMounted, anchor, positionMethod, side = 'bottom', sideOffset = 5, align = 'start', alignOffset, collisionBoundary, collisionPadding, sticky, arrowPadding, disableAnchorTracking, collisionAvoidance, className, style, ...props }) {
@@ -102,7 +106,7 @@ export const Icon = /* @__PURE__ */ forwardRef(function Icon({ disableStyle, chi
102
106
  'data-component': 'menu-icon',
103
107
  'data-style-disabled': disableStyle ? '' : undefined,
104
108
  },
105
- className: twMerge(children?.props.className, className),
109
+ className: twMerge(children.props.className, className),
106
110
  });
107
111
  });
108
112
  /** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
@@ -118,49 +122,49 @@ export const SubMenuOpenButtonIcon = /* @__PURE__ */ forwardRef(function SubMenu
118
122
  className: twMerge(children?.props.className, className),
119
123
  });
120
124
  });
121
- export const CheckboxContainer = /* @__PURE__ */ forwardRef(function CheckboxContainer({ disableStyle, className, ...props }, ref) {
122
- const id = useId();
123
- const [label, setLabel] = useState('');
124
- const [state, setState] = useState({
125
- checked: false,
126
- disabled: false,
127
- highlighted: false,
128
- });
129
- return (_jsx(CheckableContext.Provider, { value: { id, label, setLabel, state, setState }, children: _jsx("div", { ...props, ref: ref, "data-disabled": state.disabled ? '' : undefined, "data-highlighted": state.highlighted ? '' : undefined, "data-checked": state.checked ? '' : undefined, "data-component": "menu-checkboxcontainer", "data-style-disabled": disableStyle ? '' : undefined, className: className }) }));
125
+ export const CheckboxContainer = /* @__PURE__ */ forwardRef(function CheckboxContainer(props, ref) {
126
+ return _jsx(CheckableContainer, { ...props, ref: ref, component: "menu-checkboxcontainer" });
130
127
  });
131
128
  export const CheckboxButtonItem = /* @__PURE__ */ forwardRef(function CheckboxButtonItem({ disableStyle, className, label, ...props }, ref) {
132
129
  const context = useCheckableContext();
133
130
  return (_jsx(BaseMenu.CheckboxItem, { ...props, ref: ref, id: context.id, "aria-labelledby": context.id + '-label', label: label ?? context.label, nativeButton: true, "data-component": "menu-checkboxbuttonitem", "data-style-disabled": disableStyle ? '' : undefined, className: className, render: (buttonProps, state) => (_jsx(CheckableButtonSurface, { ...buttonProps, state: state })) }));
134
131
  });
135
- export const CheckboxLabel = /* @__PURE__ */ forwardRef(function CheckboxLabel({ disableStyle, className, children, ...props }, ref) {
136
- const context = useCheckableContext();
137
- return (_jsx("label", { ...props, ref: ref, id: context.id + '-label', htmlFor: context.id, "data-disabled": context.state.disabled ? '' : undefined, "data-component": "menu-checkboxlabel", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: _jsx(CheckableLabelText, { children: children }) }));
132
+ export const CheckboxLabel = /* @__PURE__ */ forwardRef(function CheckboxLabel(props, ref) {
133
+ return _jsx(CheckableLabel, { ...props, ref: ref, component: "menu-checkboxlabel" });
138
134
  });
139
135
  export const CheckboxItemIndicator = /* @__PURE__ */ forwardRef(function CheckboxItemIndicator({ disableStyle, children, className, ...props }, ref) {
140
136
  return (_jsx(BaseMenu.CheckboxItemIndicator, { ...props, ref: ref, "data-component": "menu-checkboxitemindicator", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: children ?? (_jsx(Check, { "aria-hidden": true, strokeWidth: 3.5, "data-component": "menu-checkboxitemindicator-1" })) }));
141
137
  });
142
- export const RadioContainer = /* @__PURE__ */ forwardRef(function RadioContainer({ disableStyle, className, ...props }, ref) {
143
- const id = useId();
144
- const [label, setLabel] = useState('');
145
- const [state, setState] = useState({
146
- checked: false,
147
- disabled: false,
148
- highlighted: false,
149
- });
150
- return (_jsx(CheckableContext.Provider, { value: { id, label, setLabel, state, setState }, children: _jsx("div", { ...props, ref: ref, "data-disabled": state.disabled ? '' : undefined, "data-highlighted": state.highlighted ? '' : undefined, "data-checked": state.checked ? '' : undefined, "data-component": "menu-radiocontainer", "data-style-disabled": disableStyle ? '' : undefined, className: className }) }));
138
+ export const RadioContainer = /* @__PURE__ */ forwardRef(function RadioContainer(props, ref) {
139
+ return _jsx(CheckableContainer, { ...props, ref: ref, component: "menu-radiocontainer" });
151
140
  });
152
141
  export const RadioButtonItem = /* @__PURE__ */ forwardRef(function RadioButtonItem({ disableStyle, className, label, ...props }, ref) {
153
142
  const context = useCheckableContext();
154
143
  return (_jsx(BaseMenu.RadioItem, { ...props, ref: ref, id: context.id, "aria-labelledby": context.id + '-label', label: label ?? context.label, nativeButton: true, "data-component": "menu-radiobuttonitem", "data-style-disabled": disableStyle ? '' : undefined, className: className, render: (buttonProps, state) => (_jsx(CheckableButtonSurface, { ...buttonProps, state: state })) }));
155
144
  });
156
- export const RadioLabel = /* @__PURE__ */ forwardRef(function RadioLabel({ disableStyle, className, children, ...props }, ref) {
157
- const context = useCheckableContext();
158
- return (_jsx("label", { ...props, ref: ref, id: context.id + '-label', htmlFor: context.id, "data-disabled": context.state.disabled ? '' : undefined, "data-component": "menu-radiolabel", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: _jsx(CheckableLabelText, { children: children }) }));
145
+ export const RadioLabel = /* @__PURE__ */ forwardRef(function RadioLabel(props, ref) {
146
+ return _jsx(CheckableLabel, { ...props, ref: ref, component: "menu-radiolabel" });
159
147
  });
160
148
  export const RadioItemIndicator = /* @__PURE__ */ forwardRef(function RadioItemIndicator({ disableStyle, children, className, ...props }, ref) {
161
149
  return (_jsx(BaseMenu.RadioItemIndicator, { ...props, ref: ref, "data-component": "menu-radioitemindicator", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: children ?? _jsx("span", { "data-component": "menu-radioitemindicator-1" }) }));
162
150
  });
163
151
  const CheckableContext = /* @__PURE__ */ createContext(null);
152
+ // Shared by CheckboxContainer and RadioContainer, which only differ by their data-component name
153
+ const CheckableContainer = /* @__PURE__ */ forwardRef(function CheckableContainer({ disableStyle, className, component, ...props }, ref) {
154
+ const id = useId();
155
+ const [label, setLabel] = useState('');
156
+ const [state, setState] = useState({
157
+ checked: false,
158
+ disabled: false,
159
+ highlighted: false,
160
+ });
161
+ return (_jsx(CheckableContext.Provider, { value: { id, label, setLabel, state, setState }, children: _jsx("div", { ...props, ref: ref, "data-disabled": state.disabled ? '' : undefined, "data-highlighted": state.highlighted ? '' : undefined, "data-checked": state.checked ? '' : undefined, "data-component": component, "data-style-disabled": disableStyle ? '' : undefined, className: className }) }));
162
+ });
163
+ // Shared by CheckboxLabel and RadioLabel, which only differ by their data-component name
164
+ const CheckableLabel = /* @__PURE__ */ forwardRef(function CheckableLabel({ disableStyle, className, children, component, ...props }, ref) {
165
+ const context = useCheckableContext();
166
+ return (_jsx("label", { ...props, ref: ref, id: context.id + '-label', htmlFor: context.id, "data-disabled": context.state.disabled ? '' : undefined, "data-component": component, "data-style-disabled": disableStyle ? '' : undefined, className: className, children: _jsx(CheckableLabelText, { children: children }) }));
167
+ });
164
168
  function useCheckableContext() {
165
169
  const context = useContext(CheckableContext);
166
170
  if (!context)
@@ -168,21 +172,20 @@ function useCheckableContext() {
168
172
  return context;
169
173
  }
170
174
  const CheckableButtonSurface = /* @__PURE__ */ forwardRef(function CheckableButtonSurface({ state, ...props }, ref) {
171
- const { setState } = useCheckableContext();
175
+ const context = useCheckableContext();
172
176
  useEffect(() => {
173
- setState({
177
+ context.setState({
174
178
  checked: state.checked,
175
179
  disabled: state.disabled,
176
180
  highlighted: state.highlighted,
177
181
  });
178
- }, [state.checked, state.disabled, state.highlighted, setState]);
182
+ }, [state.checked, state.disabled, state.highlighted, context.setState]);
179
183
  return _jsx("button", { type: "button", ...props, ref: ref });
180
184
  });
181
185
  function CheckableLabelText({ children }) {
182
- const { setLabel } = useCheckableContext();
186
+ const context = useCheckableContext();
183
187
  return (_jsx("span", { ref: (element) => {
184
188
  if (element)
185
- setLabel(element.textContent ?? '');
189
+ context.setLabel(element.textContent ?? '');
186
190
  }, children: children }));
187
191
  }
188
- //# sourceMappingURL=index.js.map
@@ -21,4 +21,3 @@ export declare function Number({ disableStyle, children, className, ...props }:
21
21
  children: number;
22
22
  }) & StyleProps): import("react").JSX.Element;
23
23
  export declare function Unit({ disableStyle, className, ...props }: HTMLAttributes<HTMLParagraphElement> & StyleProps): import("react").JSX.Element;
24
- //# sourceMappingURL=index.d.ts.map
@@ -23,4 +23,3 @@ export function Number({ disableStyle, children, className, ...props }) {
23
23
  export function Unit({ disableStyle, className, ...props }) {
24
24
  return (_jsx("p", { "data-component": "metric-unit", "data-style-disabled": disableStyle ? '' : undefined, className: className, ...props }));
25
25
  }
26
- //# sourceMappingURL=index.js.map
@@ -2,13 +2,15 @@ import type { StyleProps } from '../../types/Style.ts';
2
2
  import { NumberField as BaseNumber } from '@base-ui/react/number-field';
3
3
  import type { SVGIconProps } from '../../types/Icon.ts';
4
4
  import type { ComponentProps, ReactElement } from 'react';
5
+ import type { Validation } from '../../types/Validation.ts';
6
+ import type { ValidationMessageChildren } from '../../utils/Validation.ts';
5
7
  export type RootProps = Omit<BaseNumber.Root.Props, 'className' | 'render'> & {
6
8
  className?: string;
7
- /** Choose the visual tone. This does not validate data or show/hide feedback messages. */
8
- tone?: 'neutral' | 'valid' | 'invalid';
9
+ /** The field's validation state, with an optional message: `'error'` styles it as invalid, `['error', 'Email is required']` also shows that message in Error. Same for `'success'` and Success. Omit it for a neutral field. */
10
+ validation?: Validation;
9
11
  };
10
12
  /**
11
- * Configure value, bounds, and step on Root. IncrementButton and DecrementButton update the number automatically; no custom arithmetic handlers needed. Use ButtonsList to organize them beside Input, or behavior-only handlers for custom buttons.
13
+ * Configure value, bounds, and step on Root. IncrementButton and DecrementButton update the number automatically; no custom arithmetic handlers needed. Use ButtonsList to organize them beside Input.
12
14
  *
13
15
  * @example Complete composition
14
16
  * import { NumberInput } from '@central-ui/react'
@@ -44,17 +46,20 @@ export type RootProps = Omit<BaseNumber.Root.Props, 'className' | 'render'> & {
44
46
  * </NumberInput.Root>
45
47
  */
46
48
  export declare const Root: import("react").ForwardRefExoticComponent<Omit<RootProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
47
- export declare const Input: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").NumberFieldInputProps, "form" | "className" | "defaultValue" | "id" | "name" | "disabled" | "value" | "render" | "required" | "readOnly"> & {
49
+ export declare const Input: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").NumberFieldInputProps, "className" | "id" | "name" | "form" | "defaultValue" | "disabled" | "value" | "render" | "required" | "readOnly"> & {
48
50
  className?: string;
49
51
  } & StyleProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
50
52
  export declare const Container: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
51
53
  /** Labels the associated control automatically. Supply the visible text; do not wire a second label association. */
52
54
  export declare const Label: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "htmlFor"> & StyleProps, "ref"> & import("react").RefAttributes<HTMLLabelElement>>;
53
55
  export declare const Description: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
54
- /** You decide when to show this feedback. Changing tone does not validate data or render the message for you. */
55
- export declare const Error: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
56
- /** You decide when to show this feedback. Changing tone does not validate data or render the message for you. */
57
- export declare const Success: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
56
+ type MessageProps = Omit<ComponentProps<'div'>, 'children'> & StyleProps & {
57
+ children?: ValidationMessageChildren;
58
+ };
59
+ /** Shows itself only while Root's validation is `'error'`: with no children it shows the message from `['error', message]`, a function children formats that message, and other children replace it. */
60
+ export declare const Error: import("react").ForwardRefExoticComponent<Omit<MessageProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
61
+ /** Shows itself only while Root's validation is `'success'`: with no children it shows the message from `['success', message]`, a function children formats that message, and other children replace it. */
62
+ export declare const Success: import("react").ForwardRefExoticComponent<Omit<MessageProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
58
63
  export declare const Addon: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
59
64
  /** Choose the preset appearance; this does not add action behavior. */
60
65
  variant?: "normal" | "emphasized";
@@ -77,12 +82,6 @@ export declare const ValueText: import("react").ForwardRefExoticComponent<Omit<O
77
82
  export declare const IncrementButton: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").NumberFieldIncrementProps, "className"> & {
78
83
  className?: string;
79
84
  } & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
80
- /** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
81
- export declare const IncrementHandler: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").NumberFieldIncrementProps, "children" | "className" | "render"> & {
82
- className?: string;
83
- /** Supply your own accessible control. It receives the behavior; its own className owns the appearance. */
84
- children: ReactElement;
85
- }, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
86
85
  /** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
87
86
  export declare function IncrementButtonIcon({ disableStyle, children, className, ...props }: (Omit<ComponentProps<'svg'>, 'children'> & {
88
87
  /** Omit for the supplied default icon; pass a child only to replace it. */
@@ -91,15 +90,9 @@ export declare function IncrementButtonIcon({ disableStyle, children, className,
91
90
  export declare const DecrementButton: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").NumberFieldDecrementProps, "className"> & {
92
91
  className?: string;
93
92
  } & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
94
- /** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
95
- export declare const DecrementHandler: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").NumberFieldDecrementProps, "children" | "className" | "render"> & {
96
- className?: string;
97
- /** Supply your own accessible control. It receives the behavior; its own className owns the appearance. */
98
- children: ReactElement;
99
- }, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
100
93
  /** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
101
94
  export declare function DecrementButtonIcon({ disableStyle, children, className, ...props }: (Omit<ComponentProps<'svg'>, 'children'> & {
102
95
  /** Omit for the supplied default icon; pass a child only to replace it. */
103
96
  children?: ReactElement<ComponentProps<'svg'>>;
104
97
  }) & StyleProps): ReactElement<import("react").SVGProps<SVGSVGElement>, string | import("react").JSXElementConstructor<any>>;
105
- //# sourceMappingURL=index.d.ts.map
98
+ export {};
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { NumberField as BaseNumber } from '@base-ui/react/number-field';
3
- import { ChevronUp, ChevronDown, LoaderCircle } from 'lucide-react';
3
+ import { ChevronUp, ChevronDown, LoaderCircle } from "../../utils/icons.js";
4
4
  import { useForwardClickToInput } from "../../utils/useForwardClickToInput.js";
5
5
  import { cloneElement, createContext, forwardRef, useContext, useEffect, useId, useState, } from 'react';
6
6
  import { twMerge } from 'tailwind-merge';
7
- import { ToneProvider, useToneContext } from "../../utils/Tone.js";
7
+ import { readValidation, validationAttributes, validationMessageContent } from "../../utils/Validation.js";
8
8
  /**
9
- * Configure value, bounds, and step on Root. IncrementButton and DecrementButton update the number automatically; no custom arithmetic handlers needed. Use ButtonsList to organize them beside Input, or behavior-only handlers for custom buttons.
9
+ * Configure value, bounds, and step on Root. IncrementButton and DecrementButton update the number automatically; no custom arithmetic handlers needed. Use ButtonsList to organize them beside Input.
10
10
  *
11
11
  * @example Complete composition
12
12
  * import { NumberInput } from '@central-ui/react'
@@ -41,25 +41,24 @@ import { ToneProvider, useToneContext } from "../../utils/Tone.js";
41
41
  * }
42
42
  * </NumberInput.Root>
43
43
  */
44
- export const Root = /* @__PURE__ */ forwardRef(function Root({ id, tone = 'neutral', children, ...props }, ref) {
44
+ export const Root = /* @__PURE__ */ forwardRef(function Root({ id, validation, children, ...props }, ref) {
45
45
  const generatedId = useId();
46
46
  const inputId = id ?? generatedId;
47
- const [connections, setConnections] = useState({
48
- descriptionIds: [],
49
- });
50
- return (_jsx(ToneProvider, { value: tone, children: _jsx(BaseNumber.Root, { ...props, id: inputId, ref: ref, render: (rootProps, state) => (_jsx(InputContext.Provider, { value: {
51
- ...state,
52
- inputId,
53
- connections,
54
- setConnections,
55
- min: props.min,
56
- max: props.max,
57
- }, children: _jsx("div", { ...rootProps }) })), children: children }) }));
47
+ // Holding the ids of Description, Error and Success, so the control announces them to screen readers through aria-describedby
48
+ const [describedByIds, setDescribedByIds] = useState([]);
49
+ return (_jsx(BaseNumber.Root, { ...props, id: inputId, ref: ref, render: (rootProps, state) => (_jsx(InputContext.Provider, { value: {
50
+ ...state,
51
+ inputId,
52
+ describedByIds,
53
+ setDescribedByIds,
54
+ min: props.min,
55
+ max: props.max,
56
+ validation: readValidation(validation),
57
+ }, children: _jsx("div", { ...rootProps }) })), children: children }));
58
58
  });
59
59
  export const Input = /* @__PURE__ */ forwardRef(function Input({ disableStyle, className, 'aria-describedby': describedBy, ...props }, ref) {
60
60
  const context = useInputContext();
61
- const tone = useToneContext();
62
- return (_jsx(BaseNumber.Input, { ...props, ref: ref, "data-tone": tone, "aria-invalid": tone === 'invalid' || props['aria-invalid'] || undefined, "aria-describedby": [describedBy, ...context.connections.descriptionIds]
61
+ return (_jsx(BaseNumber.Input, { ...props, ref: ref, ...validationAttributes(context.validation), "aria-invalid": context.validation.state === 'error' || props['aria-invalid'] || undefined, "aria-describedby": [describedBy, ...context.describedByIds]
63
62
  .filter(Boolean)
64
63
  .join(' ') || undefined, "data-component": "numberinput-input", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
65
64
  });
@@ -72,13 +71,6 @@ export const Label = /* @__PURE__ */ forwardRef(function Label({ disableStyle, c
72
71
  const context = useInputContext();
73
72
  const labelId = id ?? context.inputId + '-label';
74
73
  const attributes = usePartAttributes();
75
- useEffect(() => {
76
- context.setConnections((current) => ({ ...current, labelId }));
77
- return () => context.setConnections((current) => ({
78
- ...current,
79
- labelId: current.labelId === labelId ? undefined : current.labelId,
80
- }));
81
- }, [labelId, context.setConnections]);
82
74
  return (_jsx("label", { ...attributes, ...props, id: labelId, ref: ref, htmlFor: context.inputId, "data-component": "numberinput-label", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
83
75
  });
84
76
  export const Description = /* @__PURE__ */ forwardRef(function Description({ disableStyle, className, id, ...props }, ref) {
@@ -86,17 +78,27 @@ export const Description = /* @__PURE__ */ forwardRef(function Description({ dis
86
78
  const attributes = usePartAttributes();
87
79
  return (_jsx("div", { ...attributes, ...props, id: messageId, ref: ref, "data-component": "numberinput-description", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
88
80
  });
89
- /** You decide when to show this feedback. Changing tone does not validate data or render the message for you. */
90
- export const Error = /* @__PURE__ */ forwardRef(function Error({ disableStyle, className, id, ...props }, ref) {
91
- const messageId = useMessageId(id);
92
- const attributes = usePartAttributes();
93
- return (_jsx("div", { role: "alert", "aria-atomic": "true", ...attributes, ...props, id: messageId, ref: ref, "data-component": "numberinput-error", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
81
+ /** Shows itself only while Root's validation is `'error'`: with no children it shows the message from `['error', message]`, a function children formats that message, and other children replace it. */
82
+ export const Error = /* @__PURE__ */ forwardRef(function Error({ children, ...props }, ref) {
83
+ const context = useInputContext();
84
+ const content = validationMessageContent(context.validation, 'error', children);
85
+ if (content === undefined)
86
+ return null;
87
+ return _jsx(Message, { ...props, ref: ref, role: "alert", component: "numberinput-error", children: content });
94
88
  });
95
- /** You decide when to show this feedback. Changing tone does not validate data or render the message for you. */
96
- export const Success = /* @__PURE__ */ forwardRef(function Success({ disableStyle, className, id, ...props }, ref) {
89
+ /** Shows itself only while Root's validation is `'success'`: with no children it shows the message from `['success', message]`, a function children formats that message, and other children replace it. */
90
+ export const Success = /* @__PURE__ */ forwardRef(function Success({ children, ...props }, ref) {
91
+ const context = useInputContext();
92
+ const content = validationMessageContent(context.validation, 'success', children);
93
+ if (content === undefined)
94
+ return null;
95
+ return _jsx(Message, { ...props, ref: ref, role: "status", component: "numberinput-success", children: content });
96
+ });
97
+ // The shared body of Error and Success, mounted only while they show, so only visible messages describe the number input
98
+ const Message = /* @__PURE__ */ forwardRef(function Message({ disableStyle, className, id, component, ...props }, ref) {
97
99
  const messageId = useMessageId(id);
98
100
  const attributes = usePartAttributes();
99
- return (_jsx("div", { role: "status", "aria-atomic": "true", ...attributes, ...props, id: messageId, ref: ref, "data-component": "numberinput-success", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
101
+ return _jsx("div", { "aria-atomic": "true", ...attributes, ...props, id: messageId, ref: ref, "data-component": component, "data-style-disabled": disableStyle ? '' : undefined, className: className });
100
102
  });
101
103
  export const Addon = /* @__PURE__ */ forwardRef(function Addon({ disableStyle, className, variant = 'normal', ...props }, ref) {
102
104
  const attributes = usePartAttributes();
@@ -149,10 +151,6 @@ export const ValueText = /* @__PURE__ */ forwardRef(function ValueText({ disable
149
151
  export const IncrementButton = /* @__PURE__ */ forwardRef(function IncrementButton({ disableStyle, className, ...props }, ref) {
150
152
  return (_jsx(BaseNumber.Increment, { ...props, ref: ref, "data-component": "numberinput-incrementbutton", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
151
153
  });
152
- /** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
153
- export const IncrementHandler = /* @__PURE__ */ forwardRef(function IncrementHandler({ children, ...props }, ref) {
154
- return _jsx(BaseNumber.Increment, { ...props, ref: ref, render: children });
155
- });
156
154
  /** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
157
155
  export function IncrementButtonIcon({ disableStyle, children = _jsx(ChevronUp, {}), className, ...props }) {
158
156
  const context = useInputContext();
@@ -178,10 +176,6 @@ export function IncrementButtonIcon({ disableStyle, children = _jsx(ChevronUp, {
178
176
  export const DecrementButton = /* @__PURE__ */ forwardRef(function DecrementButton({ disableStyle, className, ...props }, ref) {
179
177
  return (_jsx(BaseNumber.Decrement, { ...props, ref: ref, "data-component": "numberinput-decrementbutton", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
180
178
  });
181
- /** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
182
- export const DecrementHandler = /* @__PURE__ */ forwardRef(function DecrementHandler({ children, ...props }, ref) {
183
- return _jsx(BaseNumber.Decrement, { ...props, ref: ref, render: children });
184
- });
185
179
  /** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
186
180
  export function DecrementButtonIcon({ disableStyle, children = _jsx(ChevronDown, {}), className, ...props }) {
187
181
  const context = useInputContext();
@@ -213,28 +207,21 @@ function useInputContext() {
213
207
  }
214
208
  function usePartAttributes() {
215
209
  const context = useInputContext();
216
- const tone = useToneContext();
217
210
  return {
218
211
  'data-disabled': context.disabled ? '' : undefined,
219
212
  'data-readonly': context.readOnly ? '' : undefined,
220
213
  'data-required': context.required ? '' : undefined,
221
- 'data-tone': tone,
214
+ ...validationAttributes(context.validation),
222
215
  };
223
216
  }
217
+ // Registering a message part's id in the control's aria-describedby while the part is mounted
224
218
  function useMessageId(id) {
219
+ const context = useInputContext();
225
220
  const generatedId = useId();
226
221
  const messageId = id ?? generatedId;
227
- const context = useInputContext();
228
222
  useEffect(() => {
229
- context.setConnections((current) => ({
230
- ...current,
231
- descriptionIds: [...current.descriptionIds, messageId],
232
- }));
233
- return () => context.setConnections((current) => ({
234
- ...current,
235
- descriptionIds: current.descriptionIds.filter((id) => id !== messageId),
236
- }));
237
- }, [messageId, context.setConnections]);
223
+ context.setDescribedByIds((current) => [...current, messageId]);
224
+ return () => context.setDescribedByIds((current) => current.filter((currentId) => currentId !== messageId));
225
+ }, [messageId, context.setDescribedByIds]);
238
226
  return messageId;
239
227
  }
240
- //# sourceMappingURL=index.js.map