@codefast/ui 0.3.13-canary.2 → 0.3.13-canary.4

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 (367) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/components/accordion.d.mts +37 -0
  3. package/dist/components/accordion.mjs +53 -0
  4. package/dist/components/alert-dialog.d.mts +74 -0
  5. package/dist/components/alert-dialog.mjs +92 -0
  6. package/dist/components/alert.d.mts +30 -0
  7. package/dist/components/alert.mjs +49 -0
  8. package/dist/components/aspect-ratio.d.mts +10 -0
  9. package/dist/components/aspect-ratio.mjs +12 -0
  10. package/dist/components/avatar.d.mts +21 -0
  11. package/dist/components/avatar.mjs +28 -0
  12. package/dist/components/badge.d.mts +24 -0
  13. package/dist/components/badge.mjs +56 -0
  14. package/dist/components/breadcrumb.d.mts +44 -0
  15. package/dist/components/breadcrumb.mjs +67 -0
  16. package/dist/components/button-group.d.mts +34 -0
  17. package/dist/components/button-group.mjs +53 -0
  18. package/dist/components/button.d.mts +38 -0
  19. package/dist/components/button.mjs +99 -0
  20. package/dist/components/calendar.d.mts +27 -0
  21. package/dist/components/calendar.mjs +114 -0
  22. package/dist/components/card.d.mts +41 -0
  23. package/dist/components/card.mjs +55 -0
  24. package/dist/components/carousel.d.mts +68 -0
  25. package/dist/components/carousel.mjs +135 -0
  26. package/dist/components/chart.d.mts +93 -0
  27. package/dist/components/chart.mjs +189 -0
  28. package/dist/components/checkbox-cards.d.mts +17 -0
  29. package/dist/components/checkbox-cards.mjs +30 -0
  30. package/dist/components/checkbox-group.d.mts +16 -0
  31. package/dist/components/checkbox-group.mjs +27 -0
  32. package/dist/components/checkbox.d.mts +11 -0
  33. package/dist/components/checkbox.mjs +20 -0
  34. package/dist/components/collapsible.d.mts +18 -0
  35. package/dist/components/collapsible.mjs +24 -0
  36. package/dist/components/command.d.mts +57 -0
  37. package/dist/components/command.mjs +92 -0
  38. package/dist/components/context-menu.d.mts +91 -0
  39. package/dist/components/context-menu.mjs +122 -0
  40. package/dist/components/dialog.d.mts +65 -0
  41. package/dist/components/dialog.mjs +93 -0
  42. package/dist/components/drawer.d.mts +65 -0
  43. package/dist/components/drawer.mjs +78 -0
  44. package/dist/components/dropdown-menu.d.mts +92 -0
  45. package/dist/components/dropdown-menu.mjs +129 -0
  46. package/dist/components/empty.d.mts +44 -0
  47. package/dist/components/empty.mjs +64 -0
  48. package/dist/components/field.d.mts +79 -0
  49. package/dist/components/field.mjs +132 -0
  50. package/dist/components/form.d.mts +48 -0
  51. package/dist/components/form.mjs +92 -0
  52. package/dist/components/hover-card.d.mts +26 -0
  53. package/dist/components/hover-card.mjs +35 -0
  54. package/dist/components/input-group.d.mts +61 -0
  55. package/dist/components/input-group.mjs +142 -0
  56. package/dist/components/input-number.d.mts +28 -0
  57. package/dist/components/input-number.mjs +61 -0
  58. package/dist/components/input-otp.d.mts +29 -0
  59. package/dist/components/input-otp.mjs +48 -0
  60. package/dist/components/input-password.d.mts +13 -0
  61. package/dist/components/input-password.mjs +38 -0
  62. package/dist/components/input-search.d.mts +20 -0
  63. package/dist/components/input-search.mjs +50 -0
  64. package/dist/components/input.d.mts +11 -0
  65. package/dist/components/input.mjs +14 -0
  66. package/dist/components/item.d.mts +82 -0
  67. package/dist/components/item.mjs +137 -0
  68. package/dist/components/kbd.d.mts +15 -0
  69. package/dist/components/kbd.mjs +19 -0
  70. package/dist/components/label.d.mts +11 -0
  71. package/dist/components/label.mjs +14 -0
  72. package/dist/components/menubar.d.mts +100 -0
  73. package/dist/components/menubar.mjs +133 -0
  74. package/dist/components/native-select.d.mts +19 -0
  75. package/dist/components/native-select.mjs +34 -0
  76. package/dist/components/navigation-menu.d.mts +44 -0
  77. package/dist/components/navigation-menu.mjs +79 -0
  78. package/dist/components/pagination.d.mts +46 -0
  79. package/dist/components/pagination.mjs +71 -0
  80. package/dist/components/popover.d.mts +30 -0
  81. package/dist/components/popover.mjs +41 -0
  82. package/dist/components/progress-circle.d.mts +124 -0
  83. package/dist/components/progress-circle.mjs +120 -0
  84. package/dist/components/progress.d.mts +12 -0
  85. package/dist/components/progress.mjs +19 -0
  86. package/dist/components/{radio-cards.d.ts → radio-cards.d.mts} +10 -5
  87. package/dist/components/radio-cards.mjs +29 -0
  88. package/dist/components/radio-group.d.mts +16 -0
  89. package/dist/components/radio-group.mjs +25 -0
  90. package/dist/components/radio.d.mts +14 -0
  91. package/dist/components/radio.mjs +16 -0
  92. package/dist/components/resizable.d.mts +23 -0
  93. package/dist/components/resizable.mjs +32 -0
  94. package/dist/components/scroll-area.d.mts +40 -0
  95. package/dist/components/scroll-area.mjs +101 -0
  96. package/dist/components/select.d.mts +62 -0
  97. package/dist/components/select.mjs +101 -0
  98. package/dist/components/separator.d.mts +32 -0
  99. package/dist/components/separator.mjs +45 -0
  100. package/dist/components/sheet.d.mts +75 -0
  101. package/dist/components/sheet.mjs +134 -0
  102. package/dist/components/sidebar.d.mts +195 -0
  103. package/dist/components/sidebar.mjs +375 -0
  104. package/dist/components/skeleton.d.mts +10 -0
  105. package/dist/components/skeleton.mjs +12 -0
  106. package/dist/components/slider.d.mts +15 -0
  107. package/dist/components/slider.mjs +40 -0
  108. package/dist/components/sonner.d.mts +10 -0
  109. package/dist/components/sonner.mjs +21 -0
  110. package/dist/components/spinner.d.mts +14 -0
  111. package/dist/components/spinner.mjs +40 -0
  112. package/dist/components/switch.d.mts +11 -0
  113. package/dist/components/switch.mjs +18 -0
  114. package/dist/components/table.d.mts +45 -0
  115. package/dist/components/table.mjs +65 -0
  116. package/dist/components/tabs.d.mts +26 -0
  117. package/dist/components/tabs.mjs +35 -0
  118. package/dist/components/textarea.d.mts +10 -0
  119. package/dist/components/textarea.mjs +12 -0
  120. package/dist/components/toggle-group.d.mts +30 -0
  121. package/dist/components/toggle-group.mjs +53 -0
  122. package/dist/components/toggle.d.mts +28 -0
  123. package/dist/components/toggle.mjs +53 -0
  124. package/dist/components/tooltip.d.mts +30 -0
  125. package/dist/components/tooltip.mjs +42 -0
  126. package/dist/hooks/{use-animated-value.d.ts → use-animated-value.d.mts} +4 -2
  127. package/dist/hooks/use-animated-value.mjs +62 -0
  128. package/dist/hooks/{use-copy-to-clipboard.d.ts → use-copy-to-clipboard.d.mts} +11 -6
  129. package/dist/hooks/use-copy-to-clipboard.mjs +43 -0
  130. package/dist/hooks/{use-is-mobile.d.ts → use-is-mobile.d.mts} +4 -2
  131. package/dist/hooks/use-is-mobile.mjs +26 -0
  132. package/dist/hooks/{use-media-query.d.ts → use-media-query.d.mts} +4 -2
  133. package/dist/hooks/use-media-query.mjs +50 -0
  134. package/dist/hooks/{use-mutation-observer.d.ts → use-mutation-observer.d.mts} +6 -3
  135. package/dist/hooks/use-mutation-observer.mjs +41 -0
  136. package/dist/hooks/use-pagination.d.mts +44 -0
  137. package/dist/hooks/use-pagination.mjs +107 -0
  138. package/dist/index.d.mts +69 -0
  139. package/dist/index.mjs +69 -0
  140. package/dist/lib/utils.d.mts +13 -0
  141. package/dist/lib/utils.mjs +10 -0
  142. package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/clsx.d.mts +6 -0
  143. package/dist/primitives/checkbox-group.d.mts +144 -0
  144. package/dist/primitives/checkbox-group.mjs +126 -0
  145. package/dist/primitives/input-number.d.mts +73 -0
  146. package/dist/primitives/input-number.mjs +514 -0
  147. package/dist/primitives/input.d.mts +72 -0
  148. package/dist/primitives/input.mjs +75 -0
  149. package/dist/primitives/progress-circle.d.mts +146 -0
  150. package/dist/primitives/progress-circle.mjs +178 -0
  151. package/package.json +164 -170
  152. package/dist/components/accordion.d.ts +0 -19
  153. package/dist/components/accordion.d.ts.map +0 -1
  154. package/dist/components/accordion.js +0 -26
  155. package/dist/components/alert-dialog.d.ts +0 -39
  156. package/dist/components/alert-dialog.d.ts.map +0 -1
  157. package/dist/components/alert-dialog.js +0 -39
  158. package/dist/components/alert.d.ts +0 -19
  159. package/dist/components/alert.d.ts.map +0 -1
  160. package/dist/components/alert.js +0 -41
  161. package/dist/components/aspect-ratio.d.ts +0 -7
  162. package/dist/components/aspect-ratio.d.ts.map +0 -1
  163. package/dist/components/aspect-ratio.js +0 -10
  164. package/dist/components/avatar.d.ts +0 -11
  165. package/dist/components/avatar.d.ts.map +0 -1
  166. package/dist/components/avatar.js +0 -17
  167. package/dist/components/badge.d.ts +0 -18
  168. package/dist/components/badge.d.ts.map +0 -1
  169. package/dist/components/badge.js +0 -59
  170. package/dist/components/breadcrumb.d.ts +0 -22
  171. package/dist/components/breadcrumb.d.ts.map +0 -1
  172. package/dist/components/breadcrumb.js +0 -31
  173. package/dist/components/button-group.d.ts +0 -20
  174. package/dist/components/button-group.d.ts.map +0 -1
  175. package/dist/components/button-group.js +0 -48
  176. package/dist/components/button.d.ts +0 -29
  177. package/dist/components/button.d.ts.map +0 -1
  178. package/dist/components/button.js +0 -92
  179. package/dist/components/calendar.d.ts +0 -13
  180. package/dist/components/calendar.d.ts.map +0 -1
  181. package/dist/components/calendar.js +0 -104
  182. package/dist/components/card.d.ts +0 -18
  183. package/dist/components/card.d.ts.map +0 -1
  184. package/dist/components/card.js +0 -27
  185. package/dist/components/carousel.d.ts +0 -38
  186. package/dist/components/carousel.d.ts.map +0 -1
  187. package/dist/components/carousel.js +0 -103
  188. package/dist/components/chart.d.ts +0 -58
  189. package/dist/components/chart.d.ts.map +0 -1
  190. package/dist/components/chart.js +0 -198
  191. package/dist/components/checkbox-cards.d.ts +0 -11
  192. package/dist/components/checkbox-cards.d.ts.map +0 -1
  193. package/dist/components/checkbox-cards.js +0 -16
  194. package/dist/components/checkbox-group.d.ts +0 -9
  195. package/dist/components/checkbox-group.d.ts.map +0 -1
  196. package/dist/components/checkbox-group.js +0 -15
  197. package/dist/components/checkbox.d.ts +0 -7
  198. package/dist/components/checkbox.d.ts.map +0 -1
  199. package/dist/components/checkbox.js +0 -12
  200. package/dist/components/collapsible.d.ts +0 -11
  201. package/dist/components/collapsible.d.ts.map +0 -1
  202. package/dist/components/collapsible.js +0 -16
  203. package/dist/components/command.d.ts +0 -26
  204. package/dist/components/command.d.ts.map +0 -1
  205. package/dist/components/command.js +0 -41
  206. package/dist/components/context-menu.d.ts +0 -42
  207. package/dist/components/context-menu.d.ts.map +0 -1
  208. package/dist/components/context-menu.js +0 -54
  209. package/dist/components/dialog.d.ts +0 -35
  210. package/dist/components/dialog.d.ts.map +0 -1
  211. package/dist/components/dialog.js +0 -41
  212. package/dist/components/drawer.d.ts +0 -34
  213. package/dist/components/drawer.d.ts.map +0 -1
  214. package/dist/components/drawer.js +0 -36
  215. package/dist/components/dropdown-menu.d.ts +0 -42
  216. package/dist/components/dropdown-menu.d.ts.map +0 -1
  217. package/dist/components/dropdown-menu.js +0 -54
  218. package/dist/components/empty.d.ts +0 -23
  219. package/dist/components/empty.d.ts.map +0 -1
  220. package/dist/components/empty.js +0 -47
  221. package/dist/components/field.d.ts +0 -42
  222. package/dist/components/field.d.ts.map +0 -1
  223. package/dist/components/field.js +0 -85
  224. package/dist/components/form.d.ts +0 -27
  225. package/dist/components/form.d.ts.map +0 -1
  226. package/dist/components/form.js +0 -76
  227. package/dist/components/hover-card.d.ts +0 -13
  228. package/dist/components/hover-card.d.ts.map +0 -1
  229. package/dist/components/hover-card.js +0 -20
  230. package/dist/components/input-group.d.ts +0 -37
  231. package/dist/components/input-group.d.ts.map +0 -1
  232. package/dist/components/input-group.js +0 -127
  233. package/dist/components/input-number.d.ts +0 -8
  234. package/dist/components/input-number.d.ts.map +0 -1
  235. package/dist/components/input-number.js +0 -20
  236. package/dist/components/input-otp.d.ts +0 -16
  237. package/dist/components/input-otp.d.ts.map +0 -1
  238. package/dist/components/input-otp.js +0 -25
  239. package/dist/components/input-password.d.ts +0 -7
  240. package/dist/components/input-password.d.ts.map +0 -1
  241. package/dist/components/input-password.js +0 -17
  242. package/dist/components/input-search.d.ts +0 -11
  243. package/dist/components/input-search.d.ts.map +0 -1
  244. package/dist/components/input-search.js +0 -22
  245. package/dist/components/input.d.ts +0 -6
  246. package/dist/components/input.d.ts.map +0 -1
  247. package/dist/components/input.js +0 -10
  248. package/dist/components/item.d.ts +0 -46
  249. package/dist/components/item.d.ts.map +0 -1
  250. package/dist/components/item.js +0 -94
  251. package/dist/components/kbd.d.ts +0 -8
  252. package/dist/components/kbd.d.ts.map +0 -1
  253. package/dist/components/kbd.js +0 -12
  254. package/dist/components/label.d.ts +0 -7
  255. package/dist/components/label.d.ts.map +0 -1
  256. package/dist/components/label.js +0 -11
  257. package/dist/components/menubar.d.ts +0 -44
  258. package/dist/components/menubar.d.ts.map +0 -1
  259. package/dist/components/menubar.js +0 -57
  260. package/dist/components/native-select.d.ts +0 -10
  261. package/dist/components/native-select.d.ts.map +0 -1
  262. package/dist/components/native-select.js +0 -16
  263. package/dist/components/navigation-menu.d.ts +0 -21
  264. package/dist/components/navigation-menu.d.ts.map +0 -1
  265. package/dist/components/navigation-menu.js +0 -43
  266. package/dist/components/pagination.d.ts +0 -26
  267. package/dist/components/pagination.d.ts.map +0 -1
  268. package/dist/components/pagination.js +0 -29
  269. package/dist/components/popover.d.ts +0 -15
  270. package/dist/components/popover.d.ts.map +0 -1
  271. package/dist/components/popover.js +0 -23
  272. package/dist/components/progress-circle.d.ts +0 -107
  273. package/dist/components/progress-circle.d.ts.map +0 -1
  274. package/dist/components/progress-circle.js +0 -83
  275. package/dist/components/progress.d.ts +0 -7
  276. package/dist/components/progress.d.ts.map +0 -1
  277. package/dist/components/progress.js +0 -13
  278. package/dist/components/radio-cards.d.ts.map +0 -1
  279. package/dist/components/radio-cards.js +0 -15
  280. package/dist/components/radio-group.d.ts +0 -9
  281. package/dist/components/radio-group.d.ts.map +0 -1
  282. package/dist/components/radio-group.js +0 -14
  283. package/dist/components/radio.d.ts +0 -8
  284. package/dist/components/radio.d.ts.map +0 -1
  285. package/dist/components/radio.js +0 -11
  286. package/dist/components/resizable.d.ts +0 -13
  287. package/dist/components/resizable.d.ts.map +0 -1
  288. package/dist/components/resizable.js +0 -18
  289. package/dist/components/scroll-area.d.ts +0 -28
  290. package/dist/components/scroll-area.d.ts.map +0 -1
  291. package/dist/components/scroll-area.js +0 -77
  292. package/dist/components/select.d.ts +0 -29
  293. package/dist/components/select.d.ts.map +0 -1
  294. package/dist/components/select.js +0 -49
  295. package/dist/components/separator.d.ts +0 -23
  296. package/dist/components/separator.d.ts.map +0 -1
  297. package/dist/components/separator.js +0 -36
  298. package/dist/components/sheet.d.ts +0 -43
  299. package/dist/components/sheet.d.ts.map +0 -1
  300. package/dist/components/sheet.js +0 -90
  301. package/dist/components/sidebar.d.ts +0 -102
  302. package/dist/components/sidebar.d.ts.map +0 -1
  303. package/dist/components/sidebar.js +0 -241
  304. package/dist/components/skeleton.d.ts +0 -6
  305. package/dist/components/skeleton.d.ts.map +0 -1
  306. package/dist/components/skeleton.js +0 -9
  307. package/dist/components/slider.d.ts +0 -7
  308. package/dist/components/slider.d.ts.map +0 -1
  309. package/dist/components/slider.js +0 -18
  310. package/dist/components/sonner.d.ts +0 -8
  311. package/dist/components/sonner.d.ts.map +0 -1
  312. package/dist/components/sonner.js +0 -18
  313. package/dist/components/spinner.d.ts +0 -8
  314. package/dist/components/spinner.d.ts.map +0 -1
  315. package/dist/components/spinner.js +0 -27
  316. package/dist/components/switch.d.ts +0 -7
  317. package/dist/components/switch.d.ts.map +0 -1
  318. package/dist/components/switch.js +0 -11
  319. package/dist/components/table.d.ts +0 -20
  320. package/dist/components/table.d.ts.map +0 -1
  321. package/dist/components/table.js +0 -30
  322. package/dist/components/tabs.d.ts +0 -13
  323. package/dist/components/tabs.d.ts.map +0 -1
  324. package/dist/components/tabs.js +0 -20
  325. package/dist/components/textarea.d.ts +0 -6
  326. package/dist/components/textarea.d.ts.map +0 -1
  327. package/dist/components/textarea.js +0 -9
  328. package/dist/components/toggle-group.d.ts +0 -16
  329. package/dist/components/toggle-group.d.ts.map +0 -1
  330. package/dist/components/toggle-group.js +0 -35
  331. package/dist/components/toggle.d.ts +0 -21
  332. package/dist/components/toggle.d.ts.map +0 -1
  333. package/dist/components/toggle.js +0 -49
  334. package/dist/components/tooltip.d.ts +0 -15
  335. package/dist/components/tooltip.d.ts.map +0 -1
  336. package/dist/components/tooltip.js +0 -23
  337. package/dist/hooks/use-animated-value.d.ts.map +0 -1
  338. package/dist/hooks/use-animated-value.js +0 -71
  339. package/dist/hooks/use-copy-to-clipboard.d.ts.map +0 -1
  340. package/dist/hooks/use-copy-to-clipboard.js +0 -46
  341. package/dist/hooks/use-is-mobile.d.ts.map +0 -1
  342. package/dist/hooks/use-is-mobile.js +0 -23
  343. package/dist/hooks/use-media-query.d.ts.map +0 -1
  344. package/dist/hooks/use-media-query.js +0 -53
  345. package/dist/hooks/use-mutation-observer.d.ts.map +0 -1
  346. package/dist/hooks/use-mutation-observer.js +0 -40
  347. package/dist/hooks/use-pagination.d.ts +0 -37
  348. package/dist/hooks/use-pagination.d.ts.map +0 -1
  349. package/dist/hooks/use-pagination.js +0 -107
  350. package/dist/index.d.ts +0 -131
  351. package/dist/index.d.ts.map +0 -1
  352. package/dist/index.js +0 -68
  353. package/dist/lib/utils.d.ts +0 -10
  354. package/dist/lib/utils.d.ts.map +0 -1
  355. package/dist/lib/utils.js +0 -10
  356. package/dist/primitives/checkbox-group.d.ts +0 -123
  357. package/dist/primitives/checkbox-group.d.ts.map +0 -1
  358. package/dist/primitives/checkbox-group.js +0 -112
  359. package/dist/primitives/input-number.d.ts +0 -63
  360. package/dist/primitives/input-number.d.ts.map +0 -1
  361. package/dist/primitives/input-number.js +0 -458
  362. package/dist/primitives/input.d.ts +0 -67
  363. package/dist/primitives/input.d.ts.map +0 -1
  364. package/dist/primitives/input.js +0 -76
  365. package/dist/primitives/progress-circle.d.ts +0 -116
  366. package/dist/primitives/progress-circle.d.ts.map +0 -1
  367. package/dist/primitives/progress-circle.js +0 -163
@@ -1,112 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
3
- import { createCheckboxScope } from "@radix-ui/react-checkbox";
4
- import { createContextScope } from "@radix-ui/react-context";
5
- import { useDirection } from "@radix-ui/react-direction";
6
- import * as RovingFocusGroup from "@radix-ui/react-roving-focus";
7
- import { createRovingFocusGroupScope } from "@radix-ui/react-roving-focus";
8
- import { useControllableState } from "@radix-ui/react-use-controllable-state";
9
- import { useCallback } from "react";
10
- /* -----------------------------------------------------------------------------
11
- * Context: CheckboxGroup
12
- * --------------------------------------------------------------------------- */
13
- const CHECKBOX_GROUP_NAME = "CheckboxGroup";
14
- const [createCheckboxGroupContext, createCheckboxGroupScope] = createContextScope(CHECKBOX_GROUP_NAME, [createRovingFocusGroupScope, createCheckboxScope]);
15
- const useRovingFocusGroupScope = createRovingFocusGroupScope();
16
- const useCheckboxScope = createCheckboxScope();
17
- const [CheckboxGroupContextProvider, useCheckboxGroupContext] = createCheckboxGroupContext(CHECKBOX_GROUP_NAME);
18
- /**
19
- * CheckboxGroup component that manages a group of checkboxes with roving focus
20
- */
21
- function CheckboxGroup({ __scopeCheckboxGroup, defaultValue, dir, disabled = false, loop = true, name, onValueChange, orientation, required = false, value: valueProperty, ...props }) {
22
- /**
23
- * Scope for the RovingFocusGroup component
24
- */
25
- const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
26
- /**
27
- * Direction for layout and navigation
28
- */
29
- const direction = useDirection(dir);
30
- /**
31
- * State for managing selected checkbox values
32
- */
33
- const [value = [], setValue] = useControllableState({
34
- defaultProp: defaultValue,
35
- onChange: onValueChange,
36
- prop: valueProperty,
37
- });
38
- /**
39
- * Handles checking a checkbox item
40
- * @param itemValue - Value of the checkbox being checked
41
- */
42
- const handleItemCheck = useCallback((itemValue) => {
43
- setValue((previousValue) => [...(previousValue ?? []), itemValue]);
44
- }, [setValue]);
45
- /**
46
- * Handles unchecking a checkbox item
47
- * @param itemValue - Value of the checkbox being unchecked
48
- */
49
- const handleItemUncheck = useCallback((itemValue) => {
50
- setValue((previousValue) => {
51
- const currentValue = previousValue ?? [];
52
- // If this is the last selected item and required=true, prevent unchecking
53
- if (required && currentValue.length === 1 && currentValue[0] === itemValue) {
54
- return currentValue; // Keep the current state
55
- }
56
- // Otherwise, proceed with unchecking
57
- return currentValue.filter((inputValue) => inputValue !== itemValue);
58
- });
59
- }, [setValue, required]);
60
- return (_jsx(CheckboxGroupContextProvider, { disabled: disabled, name: name, required: required, scope: __scopeCheckboxGroup, value: value, onItemCheck: handleItemCheck, onItemUncheck: handleItemUncheck, children: _jsx(RovingFocusGroup.Root, { asChild: true, ...rovingFocusGroupScope, dir: direction, loop: loop, orientation: orientation, children: _jsx("div", { "data-disabled": disabled ? "" : undefined, dir: direction, role: "group", ...props }) }) }));
61
- }
62
- /* -----------------------------------------------------------------------------
63
- * Component: CheckboxGroupItem
64
- * --------------------------------------------------------------------------- */
65
- const ITEM_NAME = "CheckboxGroupItem";
66
- /**
67
- * Individual checkbox item within a CheckboxGroup
68
- */
69
- function CheckboxGroupItem({ __scopeCheckboxGroup, disabled, ...props }) {
70
- /**
71
- * Context values from the parent CheckboxGroup
72
- */
73
- const context = useCheckboxGroupContext(ITEM_NAME, __scopeCheckboxGroup);
74
- /**
75
- * Combined disabled state from both context and props
76
- */
77
- const isDisabled = context.disabled || disabled;
78
- /**
79
- * Scope for the RovingFocusGroup component
80
- */
81
- const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
82
- /**
83
- * Scope for the Checkbox component
84
- */
85
- const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
86
- /**
87
- * Whether this checkbox is currently checked
88
- */
89
- const checked = context.value?.includes(props.value);
90
- return (_jsx(RovingFocusGroup.Item, { asChild: true, ...rovingFocusGroupScope, active: checked, focusable: !isDisabled, children: _jsx(CheckboxPrimitive.Root, { "aria-label": props.value, checked: checked, disabled: isDisabled, name: context.name, required: context.required, ...checkboxScope, ...props, onCheckedChange: (checkedState) => {
91
- if (checkedState) {
92
- context.onItemCheck(props.value);
93
- }
94
- else {
95
- context.onItemUncheck(props.value);
96
- }
97
- } }) }));
98
- }
99
- /**
100
- * Visual indicator component for a CheckboxGroupItem
101
- */
102
- function CheckboxGroupIndicator({ __scopeCheckboxGroup, ...props }) {
103
- /**
104
- * Scope for the Checkbox component
105
- */
106
- const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
107
- return _jsx(CheckboxPrimitive.Indicator, { ...checkboxScope, ...props });
108
- }
109
- /* -----------------------------------------------------------------------------
110
- * Exports
111
- * -------------------------------------------------------------------------- */
112
- export { CheckboxGroup, CheckboxGroupIndicator, CheckboxGroupItem, createCheckboxGroupScope, CheckboxGroupIndicator as Indicator, CheckboxGroupItem as Item, CheckboxGroup as Root, };
@@ -1,63 +0,0 @@
1
- import type { Scope } from "@radix-ui/react-context";
2
- import type { ComponentProps, JSX } from "react";
3
- import * as InputPrimitive from "#primitives/input";
4
- /**
5
- * Props that include an optional scope for the InputNumber component.
6
- */
7
- type ScopedProps<P> = P & {
8
- /** Optional scope for the InputNumber component context */
9
- __scopeInputNumber?: Scope;
10
- };
11
- declare const createInputNumberScope: import("@radix-ui/react-context").CreateScope;
12
- /**
13
- * Props for the main InputNumber component.
14
- */
15
- interface InputNumberProps extends ComponentProps<typeof InputPrimitive.Root> {
16
- /** Accessible label for the decrement button */
17
- ariaDecrementLabel?: string;
18
- /** Accessible label for the increment button */
19
- ariaIncrementLabel?: string;
20
- /** Initial value when uncontrolled */
21
- defaultValue?: number;
22
- /** Options for number formatting */
23
- formatOptions?: Intl.NumberFormatOptions;
24
- /** Unique identifier for the input */
25
- id?: string;
26
- /** Locale used for number formatting */
27
- locale?: string;
28
- /** Maximum allowed value */
29
- max?: number;
30
- /** Minimum allowed value */
31
- min?: number;
32
- /** Handler called when the value changes */
33
- onChange?: (value?: number) => void;
34
- /** Step value for increments/decrements */
35
- step?: number;
36
- /** Current value when controlled */
37
- value?: number;
38
- }
39
- declare function InputNumber(numberInputProps: ScopedProps<InputNumberProps>): JSX.Element;
40
- /**
41
- * Defines the props for the `InputNumberField` component.
42
- */
43
- type InputNumberFieldProps = Omit<ComponentProps<typeof InputPrimitive.Field>, "defaultValue" | "disabled" | "id" | "max" | "min" | "onChange" | "prefix" | "readOnly" | "step" | "value">;
44
- declare function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }: ScopedProps<InputNumberFieldProps>): JSX.Element;
45
- /**
46
- * Props for the NumberStepperButton component.
47
- */
48
- interface NumberStepperButtonProps extends ComponentProps<"button"> {
49
- /**
50
- * The operation to perform when the button is pressed.
51
- * - `'increment'`: Increases the value.
52
- * - `'decrement'`: Decreases the value.
53
- */
54
- operation: "decrement" | "increment";
55
- }
56
- declare function NumberStepperButton({ __scopeInputNumber, operation, ...props }: ScopedProps<NumberStepperButtonProps>): JSX.Element;
57
- type InputNumberIncrementButtonProps = Omit<ComponentProps<typeof NumberStepperButton>, "operation">;
58
- declare function InputNumberIncrementButton(props: InputNumberIncrementButtonProps): JSX.Element;
59
- type InputNumberDecrementButtonProps = Omit<ComponentProps<typeof NumberStepperButton>, "operation">;
60
- declare function InputNumberDecrementButton(props: InputNumberDecrementButtonProps): JSX.Element;
61
- export { createInputNumberScope, InputNumberDecrementButton as DecrementButton, InputNumberField as Field, InputNumberIncrementButton as IncrementButton, InputNumber, InputNumberDecrementButton, InputNumberField, InputNumberIncrementButton, InputNumber as Root, };
62
- export type { InputNumberDecrementButtonProps, InputNumberFieldProps, InputNumberIncrementButtonProps, InputNumberProps, };
63
- //# sourceMappingURL=input-number.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"input-number.d.ts","sourceRoot":"","sources":["../../src/primitives/input-number.tsx"],"names":[],"mappings":"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"}
@@ -1,458 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { composeEventHandlers } from "@radix-ui/primitive";
3
- import { createContextScope } from "@radix-ui/react-context";
4
- import { useControllableState } from "@radix-ui/react-use-controllable-state";
5
- import { useCallback, useEffect, useMemo, useRef } from "react";
6
- import * as InputPrimitive from "#primitives/input";
7
- import { createInputScope } from "#primitives/input";
8
- /* -----------------------------------------------------------------------------
9
- * Context: InputNumber
10
- * -------------------------------------------------------------------------- */
11
- /**
12
- * The name of the InputNumber component constant.
13
- */
14
- const NUMBER_INPUT_NAME = "InputNumber";
15
- const [createInputNumberContext, createInputNumberScope] = createContextScope(NUMBER_INPUT_NAME, [
16
- createInputScope,
17
- ]);
18
- const useInputScope = createInputScope();
19
- const [InputNumberContextProvider, useInputNumberContext] = createInputNumberContext(NUMBER_INPUT_NAME);
20
- function InputNumber(numberInputProps) {
21
- const { __scopeInputNumber, ariaDecrementLabel, ariaIncrementLabel, defaultValue, formatOptions = { minimumFractionDigits: 0, style: "decimal" }, id, locale, max, min, onChange, step = 1, value: valueProperty, ...props } = numberInputProps;
22
- /** Scope for the input component */
23
- const inputScope = useInputScope(__scopeInputNumber);
24
- /** Reference to the input element */
25
- const inputRef = useRef(null);
26
- /** Controlled or uncontrolled value state */
27
- const [value, setValue] = useControllableState({
28
- defaultProp: defaultValue,
29
- onChange,
30
- prop: valueProperty,
31
- });
32
- /** Separators used for number formatting based on locale */
33
- const { decimalSeparator, thousandSeparator } = useMemo(() => getNumberFormatSeparators(locale), [locale]);
34
- /**
35
- * Formats a number value into a string representation
36
- * @param inputValue - The number to format
37
- * @returns A formatted string representation of the number
38
- */
39
- const formatValue = useCallback((inputValue) => {
40
- if (inputValue === undefined || Number.isNaN(inputValue)) {
41
- return "";
42
- }
43
- return new Intl.NumberFormat(locale, formatOptions).format(inputValue);
44
- }, [formatOptions, locale]);
45
- /**
46
- * Parses a string or number input into a normalized number value
47
- * @param inputValue - The value to parse
48
- * @returns The parsed number value, clamped between min and max
49
- */
50
- const parseValue = useCallback((inputValue) => {
51
- if (typeof inputValue === "number") {
52
- return clamp(inputValue, min, max);
53
- }
54
- if (typeof inputValue !== "string") {
55
- return Number.NaN;
56
- }
57
- const cleanedValue = inputValue.trim().replaceAll(/[^\d.,\-()]/g, "");
58
- if (cleanedValue === "") {
59
- return Number.NaN;
60
- }
61
- const normalizedValue = normalizeInputValue(cleanedValue, thousandSeparator, decimalSeparator);
62
- let parsedValue = Number.parseFloat(normalizedValue);
63
- if (formatOptions.style === "percent") {
64
- parsedValue /= 100;
65
- }
66
- return Number.isNaN(parsedValue) ? 0 : clamp(parsedValue, min, max);
67
- }, [decimalSeparator, formatOptions.style, max, min, thousandSeparator]);
68
- /**
69
- * Changes the current value based on a provided operation
70
- * @param operation - Function that takes the current value and returns a new value
71
- */
72
- const changeNumberValue = useCallback((operation) => {
73
- const inputElement = inputRef.current;
74
- if (!inputElement || props.disabled || props.readOnly) {
75
- return;
76
- }
77
- const currentValue = parseValue(inputElement.value) || 0;
78
- const newValue = clamp(operation(currentValue), min, max);
79
- inputElement.value = formatValue(newValue);
80
- setValue(newValue);
81
- }, [props.disabled, formatValue, max, min, parseValue, props.readOnly, setValue]);
82
- /**
83
- * Increments the current value by the step amount
84
- */
85
- const handleIncrement = useCallback(() => {
86
- changeNumberValue((number) => number + step);
87
- }, [changeNumberValue, step]);
88
- /**
89
- * Decrements the current value by the step amount
90
- */
91
- const handleDecrement = useCallback(() => {
92
- changeNumberValue((number) => number - step);
93
- }, [changeNumberValue, step]);
94
- /**
95
- * Sets the value to the maximum allowed
96
- */
97
- const handleIncrementToMax = useCallback(() => {
98
- changeNumberValue((number) => max ?? number + step);
99
- }, [changeNumberValue, max, step]);
100
- /**
101
- * Sets the value to the minimum allowed
102
- */
103
- const handleDecrementToMin = useCallback(() => {
104
- changeNumberValue((number) => min ?? number - step);
105
- }, [changeNumberValue, min, step]);
106
- return (_jsx(InputNumberContextProvider, { ariaDecrementLabel: ariaDecrementLabel, ariaIncrementLabel: ariaIncrementLabel, defaultValue: defaultValue, disabled: props.disabled, formatOptions: formatOptions, formatValue: formatValue, id: id, inputRef: inputRef, max: max, min: min, parseValue: parseValue, readOnly: props.readOnly, scope: __scopeInputNumber, value: value, onChange: setValue, onDecrement: handleDecrement, onDecrementToMin: handleDecrementToMin, onIncrement: handleIncrement, onIncrementToMax: handleIncrementToMax, children: _jsx(InputPrimitive.Root, { ...inputScope, ...props }) }));
107
- }
108
- /* -----------------------------------------------------------------------------
109
- * Component: InputNumberField
110
- * -------------------------------------------------------------------------- */
111
- /**
112
- * The name of the InputNumberField component constant.
113
- */
114
- const NUMBER_INPUT_FIELD_NAME = "InputNumberField";
115
- function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
116
- // Retrieve input number context and input scope
117
- const inputScope = useInputScope(__scopeInputNumber);
118
- const { defaultValue, disabled, formatValue, id, inputRef, max, min, onChange, onDecrement, onDecrementToMin, onIncrement, onIncrementToMax, parseValue, readOnly, step, value, } = useInputNumberContext(NUMBER_INPUT_FIELD_NAME, __scopeInputNumber);
119
- /**
120
- * Handles the blur event to format the value of the input.
121
- *
122
- * @param event - The blur event triggered when the input loses focus.
123
- */
124
- const handleBlur = useCallback((event) => {
125
- const numericValue = parseValue(event.target.value);
126
- const formattedValue = formatValue(numericValue);
127
- if (formattedValue !== event.target.value) {
128
- event.target.value = formattedValue;
129
- }
130
- onChange(numericValue);
131
- }, [formatValue, onChange, parseValue]);
132
- /**
133
- * Handles keydown events to increment, decrement, or perform other actions.
134
- *
135
- * @param event - The keyboard event triggered by key presses.
136
- */
137
- const handleKeyDown = useCallback((event) => {
138
- switch (event.key) {
139
- case "ArrowUp": {
140
- onIncrement();
141
- event.preventDefault();
142
- break;
143
- }
144
- case "PageUp": {
145
- onIncrementToMax();
146
- event.preventDefault();
147
- break;
148
- }
149
- case "ArrowDown": {
150
- onDecrement();
151
- event.preventDefault();
152
- break;
153
- }
154
- case "PageDown": {
155
- onDecrementToMin();
156
- event.preventDefault();
157
- break;
158
- }
159
- default: {
160
- break;
161
- }
162
- }
163
- }, [onIncrement, onIncrementToMax, onDecrement, onDecrementToMin]);
164
- /**
165
- * Prevents invalid keyboard input for the numeric input field.
166
- *
167
- * @param event - The keyboard event to handle.
168
- */
169
- const handleKeyDownPrevent = useCallback((event) => {
170
- switch (event.key) {
171
- case "ArrowUp":
172
- case "ArrowDown":
173
- case "ArrowLeft":
174
- case "ArrowRight":
175
- case "PageUp":
176
- case "PageDown":
177
- case "Tab":
178
- case "Escape":
179
- case "Enter":
180
- case "Backspace":
181
- case "Delete":
182
- case "Home":
183
- case "End":
184
- case ".":
185
- case ",":
186
- case "-":
187
- case "%": {
188
- return;
189
- }
190
- default: {
191
- if (isNumberKey(event.key) || isModifierKey(event) || isFunctionKey(event.key)) {
192
- return;
193
- }
194
- event.preventDefault();
195
- }
196
- }
197
- }, []);
198
- /**
199
- * Handles the Enter key to format the value of the input.
200
- *
201
- * @param event - The keyboard event triggered by pressing Enter.
202
- */
203
- const handleKeyDownEnter = useCallback((event) => {
204
- const inputElement = inputRef.current;
205
- if (event.key !== "Enter" || !inputElement) {
206
- return;
207
- }
208
- const numericValue = parseValue(inputElement.value);
209
- const formattedValue = formatValue(numericValue);
210
- if (formattedValue !== inputElement.value) {
211
- inputElement.value = formattedValue;
212
- }
213
- onChange(numericValue);
214
- }, [formatValue, inputRef, onChange, parseValue]);
215
- /**
216
- * Creates a combined keydown event handler that processes keyboard events in sequence.
217
- *
218
- * The handler chain executes in the following order:
219
- * 1. User-provided onKeyDown handler (if any)
220
- * 2. handleKeyDownPrevent - Prevents non-numeric input
221
- * 3. handleKeyDown - Handles arrow keys and page up/down for value adjustments
222
- * 4. handleKeyDownEnter - Handles Enter key press to format and update the value
223
- *
224
- * @returns A composed event handler function for the onKeyDown event
225
- */
226
- const combinedKeyDownHandler = useCallback((event) => {
227
- composeEventHandlers(onKeyDown, chain(handleKeyDownPrevent, handleKeyDown, handleKeyDownEnter))(event);
228
- }, [onKeyDown, handleKeyDown, handleKeyDownEnter, handleKeyDownPrevent]);
229
- /**
230
- * Adds a listener to handle wheel events for incrementing or decrementing the value.
231
- */
232
- useEffect(() => {
233
- const handleWheel = (event) => {
234
- const inputElement = inputRef.current;
235
- if (!inputElement || disabled || readOnly || document.activeElement !== inputElement) {
236
- return;
237
- }
238
- event.preventDefault();
239
- if (event.deltaY > 0) {
240
- onIncrement();
241
- }
242
- else {
243
- onDecrement();
244
- }
245
- };
246
- const inputElement = inputRef.current;
247
- inputElement?.addEventListener("wheel", handleWheel);
248
- return () => {
249
- inputElement?.removeEventListener("wheel", handleWheel);
250
- };
251
- }, [onIncrement, onDecrement, inputRef, disabled, readOnly]);
252
- /**
253
- * Updates the input field's value when it changes in the context.
254
- */
255
- useEffect(() => {
256
- const inputElement = inputRef.current;
257
- if (inputElement && inputElement !== document.activeElement) {
258
- inputElement.value = formatValue(value);
259
- }
260
- }, [formatValue, inputRef, value]);
261
- /**
262
- * Adds a listener to handle form reset events by clearing the input value.
263
- */
264
- useEffect(() => {
265
- const inputElement = inputRef.current;
266
- if (!inputElement) {
267
- return;
268
- }
269
- const handleReset = () => {
270
- onChange(parseValue(defaultValue));
271
- };
272
- const form = inputElement.form;
273
- form?.addEventListener("reset", handleReset);
274
- return () => {
275
- form?.removeEventListener("reset", handleReset);
276
- };
277
- }, [defaultValue, inputRef, onChange, parseValue]);
278
- return (_jsx(InputPrimitive.Field, { ref: inputRef, defaultValue: formatValue(value), disabled: disabled, id: id, inputMode: "decimal", max: max, min: min, readOnly: readOnly, step: step, onBlur: composeEventHandlers(onBlur, handleBlur), onKeyDown: combinedKeyDownHandler, ...inputScope, ...props }));
279
- }
280
- /* -----------------------------------------------------------------------------
281
- * Component: NumberStepperButton
282
- * -------------------------------------------------------------------------- */
283
- /**
284
- * The name of the NumberStepperButton component constant.
285
- */
286
- const NUMBER_STEPPER_BUTTON_NAME = "NumberStepperButton";
287
- function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
288
- // Destructures relevant context values for the button functionality.
289
- const { ariaDecrementLabel, ariaIncrementLabel, disabled, id, max, min, onDecrement, onIncrement, value, } = useInputNumberContext(NUMBER_STEPPER_BUTTON_NAME, __scopeInputNumber);
290
- const isDisabled = useMemo(() => {
291
- const atMin = min !== undefined && value !== undefined && value <= min;
292
- const atMax = max !== undefined && value !== undefined && value >= max;
293
- return (disabled ?? atMin) || atMax;
294
- }, [min, max, value, disabled]);
295
- /**
296
- * Ref to store a timeout ID for managing repeated button actions.
297
- */
298
- const timeoutIdRef = useRef(null);
299
- /**
300
- * Starts a repeated action at a regular interval.
301
- * The action begins immediately and then continues with a delay.
302
- *
303
- * @param callback - The callback function to execute repeatedly.
304
- */
305
- const startActionInterval = useCallback((callback) => {
306
- // Time between repeated actions (in milliseconds).
307
- const interval = 100;
308
- // Function to perform the action and set the next interval.
309
- const repeatAction = () => {
310
- callback();
311
- timeoutIdRef.current = setTimeout(repeatAction, interval);
312
- };
313
- callback();
314
- timeoutIdRef.current = setTimeout(repeatAction, interval * 2);
315
- }, []);
316
- /**
317
- * Clears any ongoing action intervals.
318
- */
319
- const clearActionInterval = useCallback(() => {
320
- if (timeoutIdRef.current) {
321
- clearTimeout(timeoutIdRef.current);
322
- timeoutIdRef.current = null;
323
- }
324
- }, []);
325
- /**
326
- * Handles pointer down events and triggers the appropriate action
327
- * (`increment` or `decrement`).
328
- */
329
- const handlePointerDown = useCallback(() => {
330
- const action = operation === "increment" ? onIncrement : onDecrement;
331
- startActionInterval(action);
332
- }, [onDecrement, onIncrement, operation, startActionInterval]);
333
- /**
334
- * Prevents the context menu from displaying when the button is right-clicked.
335
- *
336
- * @param event - The mouse event triggered by the right-click.
337
- */
338
- const handleContextMenu = useCallback((event) => {
339
- event.preventDefault();
340
- }, []);
341
- /**
342
- * Handles keyboard events to support activation of the button using
343
- * keyboard navigation (Enter or Space).
344
- *
345
- * @param event - The keyboard event with the triggered key.
346
- */
347
- const handleKeyDown = useCallback((event) => {
348
- if (event.key === "Enter" || event.key === " ") {
349
- event.preventDefault();
350
- const action = operation === "increment" ? onIncrement : onDecrement;
351
- action();
352
- }
353
- }, [onDecrement, onIncrement, operation]);
354
- return (_jsx("button", { "aria-controls": id, "aria-label": operation === "increment" ? ariaIncrementLabel : ariaDecrementLabel, "aria-live": "polite", disabled: isDisabled, type: "button", onContextMenu: handleContextMenu, onKeyDown: handleKeyDown, onPointerCancel: clearActionInterval, onPointerDown: handlePointerDown, onPointerLeave: clearActionInterval, onPointerUp: clearActionInterval, ...props }));
355
- }
356
- function InputNumberIncrementButton(props) {
357
- return _jsx(NumberStepperButton, { operation: "increment", ...props });
358
- }
359
- function InputNumberDecrementButton(props) {
360
- return _jsx(NumberStepperButton, { operation: "decrement", ...props });
361
- }
362
- /* -----------------------------------------------------------------------------
363
- * Utility Functions
364
- * -------------------------------------------------------------------------- */
365
- /**
366
- * Chains multiple callbacks into a single function
367
- *
368
- * @param callbacks - Array of callback functions that will be executed in order
369
- * @returns A single function that executes all callbacks
370
- */
371
- function chain(...callbacks) {
372
- return (...args) => {
373
- for (const callback of callbacks) {
374
- callback(...args);
375
- }
376
- };
377
- }
378
- /**
379
- * Extracts decimal and a thousand separators from a given locale's number format
380
- *
381
- * @param locale - The locale string to use for number formatting (e.g., 'en-US', 'de-DE')
382
- * @returns Object containing decimal and a thousand separators
383
- */
384
- function getNumberFormatSeparators(locale) {
385
- const numberFormat = new Intl.NumberFormat(locale);
386
- const parts = numberFormat.formatToParts(12_345.6);
387
- let thousandSeparator = "";
388
- let decimalSeparator = "";
389
- for (const part of parts) {
390
- if (part.type === "group") {
391
- thousandSeparator = part.value;
392
- }
393
- if (part.type === "decimal") {
394
- decimalSeparator = part.value;
395
- }
396
- // Stop early if you've found enough.
397
- if (thousandSeparator && decimalSeparator) {
398
- break;
399
- }
400
- }
401
- return { decimalSeparator, thousandSeparator };
402
- }
403
- /**
404
- * Normalizes an input value by removing formatting characters
405
- *
406
- * @param value - The input string to normalize
407
- * @param thousandSeparator - The thousand-separator character to remove
408
- * @param decimalSeparator - The decimal separator to convert to standard dot notation
409
- * @returns Normalized string value ready for numeric conversion
410
- */
411
- function normalizeInputValue(value, thousandSeparator, decimalSeparator) {
412
- return value
413
- .replaceAll(new RegExp(`\\${thousandSeparator}`, "g"), "")
414
- .replace(new RegExp(`\\${decimalSeparator}`), ".")
415
- .replaceAll(/[()]/g, "-");
416
- }
417
- /**
418
- * Checks if a keyboard event includes modifier keys (Ctrl, Alt, Meta, Shift)
419
- *
420
- * @param event - The keyboard event to check
421
- * @returns True if any modifier key is pressed
422
- */
423
- function isModifierKey(event) {
424
- return event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
425
- }
426
- /**
427
- * Determines if a key is a function key (F1-F12)
428
- *
429
- * @param key - The key name to check
430
- * @returns True if the key is a function key
431
- */
432
- function isFunctionKey(key) {
433
- return key.startsWith("F") && key.length > 1;
434
- }
435
- /**
436
- * Checks if a key represents a number (0-9)
437
- *
438
- * @param key - The key name to check
439
- * @returns True if the key represents a number
440
- */
441
- function isNumberKey(key) {
442
- return !Number.isNaN(Number(key));
443
- }
444
- /**
445
- * Clamps a numeric value between a minimum and maximum
446
- *
447
- * @param value - The value to clamp
448
- * @param min - The minimum allowed value (defaults to \-Infinity)
449
- * @param max - The maximum allowed value (defaults to Infinity)
450
- * @returns The clamped value
451
- */
452
- function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY) {
453
- return Math.min(Math.max(value, min), max);
454
- }
455
- /* -----------------------------------------------------------------------------
456
- * Exports
457
- * -------------------------------------------------------------------------- */
458
- export { createInputNumberScope, InputNumberDecrementButton as DecrementButton, InputNumberField as Field, InputNumberIncrementButton as IncrementButton, InputNumber, InputNumberDecrementButton, InputNumberField, InputNumberIncrementButton, InputNumber as Root, };