@customafk/lunas-ui 0.0.62 → 0.0.64

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 (517) hide show
  1. package/dist/{add-new-LGex5x9J.cjs → add-new-C2dDiCV3.cjs} +1 -1
  2. package/dist/{add-new-LGex5x9J.cjs.map → add-new-C2dDiCV3.cjs.map} +1 -1
  3. package/dist/{add-new-VnpqRAAB.js → add-new-Dw0uZWxo.js} +1 -1
  4. package/dist/{add-new-VnpqRAAB.js.map → add-new-Dw0uZWxo.js.map} +1 -1
  5. package/dist/alert-dialog-BOMy-TmT.js +2 -0
  6. package/dist/alert-dialog-BOMy-TmT.js.map +1 -0
  7. package/dist/alert-dialog-lwTxSl-r.cjs +2 -0
  8. package/dist/alert-dialog-lwTxSl-r.cjs.map +1 -0
  9. package/dist/avatar-BaNIRUku.cjs +2 -0
  10. package/dist/avatar-BaNIRUku.cjs.map +1 -0
  11. package/dist/avatar-DZU7feMQ.js +2 -0
  12. package/dist/avatar-DZU7feMQ.js.map +1 -0
  13. package/dist/badge-6RQPy3Eo.js +2 -0
  14. package/dist/badge-6RQPy3Eo.js.map +1 -0
  15. package/dist/badge-BMXpbMfX.cjs +2 -0
  16. package/dist/badge-BMXpbMfX.cjs.map +1 -0
  17. package/dist/{button-CwL7dO-u.d.ts → button-CS4aajjP.d.ts} +5 -5
  18. package/dist/{button-DmNWC9JF.d.cts → button-De2032Bs.d.cts} +5 -5
  19. package/dist/calendar-BZRNZdsJ.js +2 -0
  20. package/dist/calendar-BZRNZdsJ.js.map +1 -0
  21. package/dist/{calendar-CrtbhiDy.cjs → calendar-CUDdTiC-.cjs} +2 -2
  22. package/dist/calendar-CUDdTiC-.cjs.map +1 -0
  23. package/dist/cards/simple-card.d.ts +2 -2
  24. package/dist/{command-COUM-XfY.cjs → command-B9nlrxXh.cjs} +1 -1
  25. package/dist/{command-COUM-XfY.cjs.map → command-B9nlrxXh.cjs.map} +1 -1
  26. package/dist/{command-BQPzYASM.d.cts → command-D7AHVkgQ.d.ts} +12 -12
  27. package/dist/{command-DNfCX3KZ.js → command-DKD5gHi_.js} +1 -1
  28. package/dist/{command-DNfCX3KZ.js.map → command-DKD5gHi_.js.map} +1 -1
  29. package/dist/{command-USUF3JZz.d.ts → command-Db5JViIx.d.cts} +12 -12
  30. package/dist/data-display/country.cjs +1 -1
  31. package/dist/data-display/country.d.ts +1 -1
  32. package/dist/data-display/country.js +1 -1
  33. package/dist/data-display/data-list.cjs +1 -1
  34. package/dist/data-display/data-list.js +1 -1
  35. package/dist/data-display/date-tooltip.cjs +1 -1
  36. package/dist/data-display/date-tooltip.js +1 -1
  37. package/dist/data-display/empty.cjs +1 -1
  38. package/dist/data-display/empty.js +1 -1
  39. package/dist/data-display/name.cjs +1 -1
  40. package/dist/data-display/name.js +1 -1
  41. package/dist/data-display/phone-number.cjs +1 -1
  42. package/dist/data-display/phone-number.js +1 -1
  43. package/dist/data-display/role-badge.cjs +1 -1
  44. package/dist/data-display/role-badge.d.ts +1 -1
  45. package/dist/data-display/role-badge.js +1 -1
  46. package/dist/data-display/statistic.cjs +1 -1
  47. package/dist/data-display/statistic.d.cts +2 -2
  48. package/dist/data-display/statistic.d.ts +2 -2
  49. package/dist/data-display/statistic.js +1 -1
  50. package/dist/{dialog-Bw_T5aco.d.cts → dialog-CiqPVetj.d.cts} +12 -12
  51. package/dist/{dialog-DRDVtDc5.d.ts → dialog-yE-2SRfz.d.ts} +12 -12
  52. package/dist/dialogs/confirm-dialog.cjs +1 -1
  53. package/dist/dialogs/confirm-dialog.js +1 -1
  54. package/dist/dialogs/detail-dialog/component/sidebar.cjs +1 -1
  55. package/dist/dialogs/detail-dialog/component/sidebar.d.cts +28 -28
  56. package/dist/dialogs/detail-dialog/component/sidebar.d.ts +30 -30
  57. package/dist/dialogs/detail-dialog/component/sidebar.js +1 -1
  58. package/dist/dialogs/detail-dialog/index.cjs +1 -1
  59. package/dist/dialogs/detail-dialog/index.js +1 -1
  60. package/dist/dialogs/error-dialog.cjs +1 -1
  61. package/dist/dialogs/error-dialog.js +1 -1
  62. package/dist/dialogs/form-dialog.cjs +1 -1
  63. package/dist/dialogs/form-dialog.cjs.map +1 -1
  64. package/dist/dialogs/form-dialog.d.cts +2 -2
  65. package/dist/dialogs/form-dialog.d.ts +2 -2
  66. package/dist/dialogs/form-dialog.js +1 -1
  67. package/dist/dialogs/form-dialog.js.map +1 -1
  68. package/dist/drawer-B7OJzlXZ.js +2 -0
  69. package/dist/drawer-B7OJzlXZ.js.map +1 -0
  70. package/dist/drawer-Dh9uXVnU.cjs +2 -0
  71. package/dist/drawer-Dh9uXVnU.cjs.map +1 -0
  72. package/dist/{dropdown-menu-CfHXIhdy.cjs → dropdown-menu-BtNJk8EZ.cjs} +1 -1
  73. package/dist/{dropdown-menu-CfHXIhdy.cjs.map → dropdown-menu-BtNJk8EZ.cjs.map} +1 -1
  74. package/dist/{dropdown-menu-t-SeMS1_.js → dropdown-menu-Cn96vqMy.js} +1 -1
  75. package/dist/{dropdown-menu-t-SeMS1_.js.map → dropdown-menu-Cn96vqMy.js.map} +1 -1
  76. package/dist/{error-dialog-COyyui94.cjs → error-dialog-BkCaUR7F.cjs} +2 -2
  77. package/dist/{error-dialog-COyyui94.cjs.map → error-dialog-BkCaUR7F.cjs.map} +1 -1
  78. package/dist/{error-dialog-YlSsQqiT.js → error-dialog-D3tnycqF.js} +2 -2
  79. package/dist/{error-dialog-YlSsQqiT.js.map → error-dialog-D3tnycqF.js.map} +1 -1
  80. package/dist/flex-BZHWRUkz.js +2 -0
  81. package/dist/flex-BZHWRUkz.js.map +1 -0
  82. package/dist/flex-DMgD86BT.cjs +2 -0
  83. package/dist/flex-DMgD86BT.cjs.map +1 -0
  84. package/dist/form-CaxhlWxK.cjs +2 -0
  85. package/dist/form-CaxhlWxK.cjs.map +1 -0
  86. package/dist/form-D-gDMD-J.js +2 -0
  87. package/dist/form-D-gDMD-J.js.map +1 -0
  88. package/dist/{form-wrapper-D0-p7R15.cjs → form-wrapper-BUkoh-c7.cjs} +2 -2
  89. package/dist/{form-wrapper-D0-p7R15.cjs.map → form-wrapper-BUkoh-c7.cjs.map} +1 -1
  90. package/dist/{form-wrapper-C4OO_eLu.js → form-wrapper-BbScjpBv.js} +2 -2
  91. package/dist/{form-wrapper-C4OO_eLu.js.map → form-wrapper-BbScjpBv.js.map} +1 -1
  92. package/dist/forms/combobox-field.cjs +1 -1
  93. package/dist/forms/combobox-field.d.cts +2 -2
  94. package/dist/forms/combobox-field.d.ts +2 -2
  95. package/dist/forms/combobox-field.js +1 -1
  96. package/dist/forms/date-field.cjs +1 -1
  97. package/dist/forms/date-field.d.cts +2 -2
  98. package/dist/forms/date-field.d.ts +2 -2
  99. package/dist/forms/date-field.js +1 -1
  100. package/dist/forms/form-wrapper.cjs +1 -1
  101. package/dist/forms/form-wrapper.d.cts +2 -2
  102. package/dist/forms/form-wrapper.d.ts +2 -2
  103. package/dist/forms/form-wrapper.js +1 -1
  104. package/dist/forms/multi-select-field.cjs +1 -1
  105. package/dist/forms/multi-select-field.d.cts +2 -2
  106. package/dist/forms/multi-select-field.d.ts +2 -2
  107. package/dist/forms/multi-select-field.js +1 -1
  108. package/dist/forms/number-field.cjs +1 -1
  109. package/dist/forms/number-field.cjs.map +1 -1
  110. package/dist/forms/number-field.d.cts +2 -2
  111. package/dist/forms/number-field.d.ts +2 -2
  112. package/dist/forms/number-field.js +1 -1
  113. package/dist/forms/number-field.js.map +1 -1
  114. package/dist/forms/password-field.cjs +1 -1
  115. package/dist/forms/password-field.cjs.map +1 -1
  116. package/dist/forms/password-field.d.cts +2 -2
  117. package/dist/forms/password-field.d.ts +2 -2
  118. package/dist/forms/password-field.js +1 -1
  119. package/dist/forms/password-field.js.map +1 -1
  120. package/dist/forms/select-field.cjs +1 -1
  121. package/dist/forms/select-field.d.cts +2 -2
  122. package/dist/forms/select-field.d.ts +2 -2
  123. package/dist/forms/select-field.js +1 -1
  124. package/dist/forms/switch-field.cjs +1 -1
  125. package/dist/forms/switch-field.d.cts +2 -2
  126. package/dist/forms/switch-field.d.ts +2 -2
  127. package/dist/forms/switch-field.js +1 -1
  128. package/dist/forms/text-field.cjs +1 -1
  129. package/dist/forms/text-field.d.cts +2 -2
  130. package/dist/forms/text-field.d.ts +2 -2
  131. package/dist/forms/text-field.js +1 -1
  132. package/dist/forms/textarea-field.cjs +1 -1
  133. package/dist/forms/textarea-field.d.cts +2 -2
  134. package/dist/forms/textarea-field.d.ts +2 -2
  135. package/dist/forms/textarea-field.js +1 -1
  136. package/dist/input-BFZuwsER.js +2 -0
  137. package/dist/input-BFZuwsER.js.map +1 -0
  138. package/dist/{input-vLuNZody.d.ts → input-BayoSfCE.d.cts} +3 -4
  139. package/dist/{input-DRU216h-.d.cts → input-BjiwI6EW.d.ts} +3 -4
  140. package/dist/input-ERPHY3v4.cjs +2 -0
  141. package/dist/input-ERPHY3v4.cjs.map +1 -0
  142. package/dist/label-BBPPT0-L.cjs +2 -0
  143. package/dist/label-BBPPT0-L.cjs.map +1 -0
  144. package/dist/label-DdpIoRiG.js +2 -0
  145. package/dist/label-DdpIoRiG.js.map +1 -0
  146. package/dist/layouts/app-layout/index.cjs +1 -1
  147. package/dist/layouts/app-layout/index.cjs.map +1 -1
  148. package/dist/layouts/app-layout/index.d.cts +26 -27
  149. package/dist/layouts/app-layout/index.d.ts +26 -27
  150. package/dist/layouts/app-layout/index.js +1 -1
  151. package/dist/layouts/app-layout/index.js.map +1 -1
  152. package/dist/layouts/flex.cjs +1 -1
  153. package/dist/layouts/flex.d.cts +4 -5
  154. package/dist/layouts/flex.d.ts +2 -3
  155. package/dist/layouts/flex.js +1 -1
  156. package/dist/layouts/service-layout/index.cjs +2 -0
  157. package/dist/layouts/service-layout/index.cjs.map +1 -0
  158. package/dist/layouts/service-layout/index.d.cts +129 -0
  159. package/dist/layouts/service-layout/index.d.ts +130 -0
  160. package/dist/layouts/service-layout/index.js +2 -0
  161. package/dist/layouts/service-layout/index.js.map +1 -0
  162. package/dist/multi-select-BAXHYtlU.cjs +2 -0
  163. package/dist/multi-select-BAXHYtlU.cjs.map +1 -0
  164. package/dist/multi-select-oXuLHx0A.js +2 -0
  165. package/dist/multi-select-oXuLHx0A.js.map +1 -0
  166. package/dist/{popover-BsF6vWTX.cjs → popover-ByL6Igxn.cjs} +1 -1
  167. package/dist/{popover-BsF6vWTX.cjs.map → popover-ByL6Igxn.cjs.map} +1 -1
  168. package/dist/{popover-CT9ZjjNA.js → popover-DMt7GPSm.js} +1 -1
  169. package/dist/{popover-CT9ZjjNA.js.map → popover-DMt7GPSm.js.map} +1 -1
  170. package/dist/progress-Cet_LGmM.cjs +2 -0
  171. package/dist/progress-Cet_LGmM.cjs.map +1 -0
  172. package/dist/progress-DdINdNdF.js +2 -0
  173. package/dist/progress-DdINdNdF.js.map +1 -0
  174. package/dist/{refresh-B2wYinm5.cjs → refresh-BVSXOk3A.cjs} +1 -1
  175. package/dist/{refresh-B2wYinm5.cjs.map → refresh-BVSXOk3A.cjs.map} +1 -1
  176. package/dist/{refresh-BMR_jPST.js → refresh-CHzDlf3i.js} +1 -1
  177. package/dist/{refresh-BMR_jPST.js.map → refresh-CHzDlf3i.js.map} +1 -1
  178. package/dist/{scroll-area-F3yESo8d.js → scroll-area-C4Mg89Qh.js} +1 -1
  179. package/dist/{scroll-area-F3yESo8d.js.map → scroll-area-C4Mg89Qh.js.map} +1 -1
  180. package/dist/{scroll-area-CbABlDpy.cjs → scroll-area-qPdEy4lg.cjs} +1 -1
  181. package/dist/{scroll-area-CbABlDpy.cjs.map → scroll-area-qPdEy4lg.cjs.map} +1 -1
  182. package/dist/{search-input-tivZy8LE.js → search-input-B_L6kaz-.js} +2 -2
  183. package/dist/{search-input-tivZy8LE.js.map → search-input-B_L6kaz-.js.map} +1 -1
  184. package/dist/{search-input-BsnMUPtZ.cjs → search-input-DWLfcXEU.cjs} +2 -2
  185. package/dist/{search-input-BsnMUPtZ.cjs.map → search-input-DWLfcXEU.cjs.map} +1 -1
  186. package/dist/{select-_oIGH0ax.js → select-CijI0HX0.js} +1 -1
  187. package/dist/{select-_oIGH0ax.js.map → select-CijI0HX0.js.map} +1 -1
  188. package/dist/{select-S75hVYoR.cjs → select-oxr4KoHx.cjs} +1 -1
  189. package/dist/{select-S75hVYoR.cjs.map → select-oxr4KoHx.cjs.map} +1 -1
  190. package/dist/{separator-BJoqBpEK.d.cts → separator-BSmwGEtT.d.cts} +3 -3
  191. package/dist/{separator-CxCq7NYP.js → separator-DW2PaiUK.js} +1 -1
  192. package/dist/{separator-CxCq7NYP.js.map → separator-DW2PaiUK.js.map} +1 -1
  193. package/dist/{separator-hulDSW7B.cjs → separator-JGL-8B0V.cjs} +1 -1
  194. package/dist/{separator-hulDSW7B.cjs.map → separator-JGL-8B0V.cjs.map} +1 -1
  195. package/dist/{separator-0LK1LCy9.d.ts → separator-zD-G3xIG.d.ts} +3 -3
  196. package/dist/{sheet-amjZQ7nX.js → sheet-BumlzKcW.js} +1 -1
  197. package/dist/{sheet-amjZQ7nX.js.map → sheet-BumlzKcW.js.map} +1 -1
  198. package/dist/{sheet-D8iW1o50.cjs → sheet-slcLNlWv.cjs} +1 -1
  199. package/dist/{sheet-D8iW1o50.cjs.map → sheet-slcLNlWv.cjs.map} +1 -1
  200. package/dist/{sidebar-BwIH2lFJ.cjs → sidebar-BxGyCuTJ.cjs} +2 -2
  201. package/dist/{sidebar-BwIH2lFJ.cjs.map → sidebar-BxGyCuTJ.cjs.map} +1 -1
  202. package/dist/{sidebar-Cf5tv_x0.js → sidebar-CMWETVDr.js} +2 -2
  203. package/dist/{sidebar-Cf5tv_x0.js.map → sidebar-CMWETVDr.js.map} +1 -1
  204. package/dist/switch-BPSKvrTw.cjs +2 -0
  205. package/dist/switch-BPSKvrTw.cjs.map +1 -0
  206. package/dist/switch-Crju8DJO.js +2 -0
  207. package/dist/switch-Crju8DJO.js.map +1 -0
  208. package/dist/table/index.cjs +1 -1
  209. package/dist/table/index.cjs.map +1 -1
  210. package/dist/table/index.d.cts +0 -1
  211. package/dist/table/index.d.ts +2 -3
  212. package/dist/table/index.js +1 -1
  213. package/dist/table/index.js.map +1 -1
  214. package/dist/table-CSvLRXlk.cjs +2 -0
  215. package/dist/table-CSvLRXlk.cjs.map +1 -0
  216. package/dist/table-DCmuhHSH.js +2 -0
  217. package/dist/table-DCmuhHSH.js.map +1 -0
  218. package/dist/tabs-BYS9bv-R.cjs +2 -0
  219. package/dist/tabs-BYS9bv-R.cjs.map +1 -0
  220. package/dist/tabs-D4Q78tF2.js +2 -0
  221. package/dist/tabs-D4Q78tF2.js.map +1 -0
  222. package/dist/textarea-BCZiUxv7.js +2 -0
  223. package/dist/textarea-BCZiUxv7.js.map +1 -0
  224. package/dist/textarea-BtACo9UF.cjs +2 -0
  225. package/dist/textarea-BtACo9UF.cjs.map +1 -0
  226. package/dist/{title-DiaFg5B5.js → title-CtD4oOTk.js} +1 -1
  227. package/dist/{title-DiaFg5B5.js.map → title-CtD4oOTk.js.map} +1 -1
  228. package/dist/{title-DMOj1cgG.cjs → title-sD8UJhwY.cjs} +1 -1
  229. package/dist/{title-DMOj1cgG.cjs.map → title-sD8UJhwY.cjs.map} +1 -1
  230. package/dist/{toggle-CYHeyOUa.d.ts → toggle-BtGh6fdx.d.ts} +5 -6
  231. package/dist/{toggle-BLlf4Xgl.d.cts → toggle-CP8phE7Y.d.cts} +5 -6
  232. package/dist/toggle-D8VezYdr.js +2 -0
  233. package/dist/toggle-D8VezYdr.js.map +1 -0
  234. package/dist/toggle-D_5Xh3Rl.cjs +2 -0
  235. package/dist/toggle-D_5Xh3Rl.cjs.map +1 -0
  236. package/dist/tooltip-CQ8hkJ42.cjs +2 -0
  237. package/dist/tooltip-CQ8hkJ42.cjs.map +1 -0
  238. package/dist/tooltip-CTUSyCdh.js +2 -0
  239. package/dist/tooltip-CTUSyCdh.js.map +1 -0
  240. package/dist/{tooltip-Bj9r2ENW.d.ts → tooltip-CamHYf1v.d.ts} +6 -7
  241. package/dist/{tooltip-etVeWcFC.d.cts → tooltip-DLNDOfBF.d.cts} +6 -7
  242. package/dist/{types-CmcNT14g.d.ts → types-BpvTO4OF.d.ts} +1 -1
  243. package/dist/typography/paragraph.d.ts +2 -2
  244. package/dist/typography/title.cjs +1 -1
  245. package/dist/typography/title.d.cts +2 -2
  246. package/dist/typography/title.d.ts +2 -2
  247. package/dist/typography/title.js +1 -1
  248. package/dist/ui/alert-dialog.cjs +1 -1
  249. package/dist/ui/alert-dialog.d.cts +12 -13
  250. package/dist/ui/alert-dialog.d.ts +12 -13
  251. package/dist/ui/alert-dialog.js +1 -1
  252. package/dist/ui/alert.cjs +1 -1
  253. package/dist/ui/alert.cjs.map +1 -1
  254. package/dist/ui/alert.d.cts +6 -7
  255. package/dist/ui/alert.d.ts +6 -7
  256. package/dist/ui/alert.js +1 -1
  257. package/dist/ui/alert.js.map +1 -1
  258. package/dist/ui/aspect-ratio.cjs +1 -1
  259. package/dist/ui/aspect-ratio.cjs.map +1 -1
  260. package/dist/ui/aspect-ratio.d.cts +2 -3
  261. package/dist/ui/aspect-ratio.d.ts +2 -3
  262. package/dist/ui/aspect-ratio.js +1 -1
  263. package/dist/ui/aspect-ratio.js.map +1 -1
  264. package/dist/ui/avatar.cjs +1 -2
  265. package/dist/ui/avatar.d.cts +4 -5
  266. package/dist/ui/avatar.d.ts +4 -5
  267. package/dist/ui/avatar.js +1 -2
  268. package/dist/ui/badge.cjs +1 -1
  269. package/dist/ui/badge.d.cts +4 -5
  270. package/dist/ui/badge.d.ts +4 -5
  271. package/dist/ui/badge.js +1 -1
  272. package/dist/ui/breadcrumb.cjs +1 -1
  273. package/dist/ui/breadcrumb.cjs.map +1 -1
  274. package/dist/ui/breadcrumb.d.cts +8 -9
  275. package/dist/ui/breadcrumb.d.ts +8 -9
  276. package/dist/ui/breadcrumb.js +1 -1
  277. package/dist/ui/breadcrumb.js.map +1 -1
  278. package/dist/ui/button.d.cts +1 -1
  279. package/dist/ui/button.d.ts +1 -1
  280. package/dist/ui/buttons/add-new.cjs +1 -1
  281. package/dist/ui/buttons/add-new.js +1 -1
  282. package/dist/ui/buttons/refresh.cjs +1 -1
  283. package/dist/ui/buttons/refresh.js +1 -1
  284. package/dist/ui/buttons/upload-image.cjs +1 -1
  285. package/dist/ui/buttons/upload-image.cjs.map +1 -1
  286. package/dist/ui/buttons/upload-image.d.cts +1 -1
  287. package/dist/ui/buttons/upload-image.d.ts +1 -1
  288. package/dist/ui/buttons/upload-image.js +1 -1
  289. package/dist/ui/buttons/upload-image.js.map +1 -1
  290. package/dist/ui/calendar.cjs +1 -1
  291. package/dist/ui/calendar.d.cts +4 -5
  292. package/dist/ui/calendar.d.ts +4 -5
  293. package/dist/ui/calendar.js +1 -1
  294. package/dist/ui/card.d.cts +8 -8
  295. package/dist/ui/card.d.ts +8 -8
  296. package/dist/ui/carousel.cjs +1 -1
  297. package/dist/ui/carousel.cjs.map +1 -1
  298. package/dist/ui/carousel.d.cts +7 -8
  299. package/dist/ui/carousel.d.ts +7 -8
  300. package/dist/ui/carousel.js +1 -1
  301. package/dist/ui/carousel.js.map +1 -1
  302. package/dist/ui/collapsible.cjs +1 -1
  303. package/dist/ui/collapsible.cjs.map +1 -1
  304. package/dist/ui/collapsible.d.cts +4 -5
  305. package/dist/ui/collapsible.d.ts +4 -5
  306. package/dist/ui/collapsible.js +1 -1
  307. package/dist/ui/collapsible.js.map +1 -1
  308. package/dist/ui/command.cjs +1 -1
  309. package/dist/ui/command.d.cts +2 -2
  310. package/dist/ui/command.d.ts +2 -2
  311. package/dist/ui/command.js +1 -1
  312. package/dist/ui/context-menu.cjs +1 -1
  313. package/dist/ui/context-menu.cjs.map +1 -1
  314. package/dist/ui/context-menu.d.cts +16 -17
  315. package/dist/ui/context-menu.d.ts +16 -17
  316. package/dist/ui/context-menu.js +1 -1
  317. package/dist/ui/context-menu.js.map +1 -1
  318. package/dist/ui/dialog.d.cts +1 -1
  319. package/dist/ui/dialog.d.ts +1 -1
  320. package/dist/ui/dropdown-menu.cjs +1 -1
  321. package/dist/ui/dropdown-menu.d.cts +16 -16
  322. package/dist/ui/dropdown-menu.d.ts +16 -16
  323. package/dist/ui/dropdown-menu.js +1 -1
  324. package/dist/ui/file-uploader.cjs +1 -1
  325. package/dist/ui/file-uploader.cjs.map +1 -1
  326. package/dist/ui/file-uploader.d.cts +2 -3
  327. package/dist/ui/file-uploader.d.ts +2 -3
  328. package/dist/ui/file-uploader.js +2 -2
  329. package/dist/ui/file-uploader.js.map +1 -1
  330. package/dist/ui/form.cjs +1 -1
  331. package/dist/ui/form.d.cts +7 -8
  332. package/dist/ui/form.d.ts +7 -8
  333. package/dist/ui/form.js +1 -1
  334. package/dist/ui/hover-card.cjs +1 -1
  335. package/dist/ui/hover-card.cjs.map +1 -1
  336. package/dist/ui/hover-card.d.cts +4 -5
  337. package/dist/ui/hover-card.d.ts +4 -5
  338. package/dist/ui/hover-card.js +1 -1
  339. package/dist/ui/hover-card.js.map +1 -1
  340. package/dist/ui/input-otp.cjs +1 -1
  341. package/dist/ui/input-otp.cjs.map +1 -1
  342. package/dist/ui/input-otp.d.cts +5 -6
  343. package/dist/ui/input-otp.d.ts +5 -6
  344. package/dist/ui/input-otp.js +1 -1
  345. package/dist/ui/input-otp.js.map +1 -1
  346. package/dist/ui/input.cjs +1 -1
  347. package/dist/ui/input.d.cts +1 -1
  348. package/dist/ui/input.d.ts +1 -1
  349. package/dist/ui/input.js +1 -1
  350. package/dist/ui/inputs/search-input.cjs +1 -1
  351. package/dist/ui/inputs/search-input.d.cts +3 -3
  352. package/dist/ui/inputs/search-input.d.ts +3 -3
  353. package/dist/ui/inputs/search-input.js +1 -1
  354. package/dist/ui/label.cjs +1 -1
  355. package/dist/ui/label.d.cts +2 -3
  356. package/dist/ui/label.d.ts +2 -3
  357. package/dist/ui/label.js +1 -1
  358. package/dist/ui/menubar.cjs +1 -1
  359. package/dist/ui/menubar.cjs.map +1 -1
  360. package/dist/ui/menubar.d.cts +17 -18
  361. package/dist/ui/menubar.d.ts +17 -18
  362. package/dist/ui/menubar.js +1 -1
  363. package/dist/ui/menubar.js.map +1 -1
  364. package/dist/ui/multi-select.cjs +1 -1
  365. package/dist/ui/multi-select.d.cts +4 -4
  366. package/dist/ui/multi-select.d.ts +4 -4
  367. package/dist/ui/multi-select.js +1 -1
  368. package/dist/ui/navigation-menu.d.cts +11 -11
  369. package/dist/ui/navigation-menu.d.ts +11 -11
  370. package/dist/ui/pagination.cjs +1 -1
  371. package/dist/ui/pagination.cjs.map +1 -1
  372. package/dist/ui/pagination.d.cts +9 -10
  373. package/dist/ui/pagination.d.ts +9 -10
  374. package/dist/ui/pagination.js +1 -1
  375. package/dist/ui/pagination.js.map +1 -1
  376. package/dist/ui/popover.cjs +1 -1
  377. package/dist/ui/popover.d.cts +5 -5
  378. package/dist/ui/popover.d.ts +5 -5
  379. package/dist/ui/popover.js +1 -1
  380. package/dist/ui/progress.cjs +1 -1
  381. package/dist/ui/progress.d.cts +2 -3
  382. package/dist/ui/progress.d.ts +2 -3
  383. package/dist/ui/progress.js +1 -1
  384. package/dist/ui/radio-group.cjs +1 -1
  385. package/dist/ui/radio-group.cjs.map +1 -1
  386. package/dist/ui/radio-group.d.cts +3 -4
  387. package/dist/ui/radio-group.d.ts +3 -4
  388. package/dist/ui/radio-group.js +1 -1
  389. package/dist/ui/radio-group.js.map +1 -1
  390. package/dist/ui/resizable.cjs +1 -1
  391. package/dist/ui/resizable.cjs.map +1 -1
  392. package/dist/ui/resizable.d.cts +4 -5
  393. package/dist/ui/resizable.d.ts +4 -5
  394. package/dist/ui/resizable.js +1 -1
  395. package/dist/ui/resizable.js.map +1 -1
  396. package/dist/ui/scroll-area.cjs +1 -1
  397. package/dist/ui/scroll-area.d.cts +3 -3
  398. package/dist/ui/scroll-area.d.ts +3 -3
  399. package/dist/ui/scroll-area.js +1 -1
  400. package/dist/ui/select.cjs +1 -1
  401. package/dist/ui/select.d.cts +11 -11
  402. package/dist/ui/select.d.ts +11 -11
  403. package/dist/ui/select.js +1 -1
  404. package/dist/ui/separator.cjs +1 -1
  405. package/dist/ui/separator.d.cts +1 -1
  406. package/dist/ui/separator.d.ts +1 -1
  407. package/dist/ui/separator.js +1 -1
  408. package/dist/ui/sheet.cjs +1 -1
  409. package/dist/ui/sheet.d.cts +9 -9
  410. package/dist/ui/sheet.d.ts +9 -9
  411. package/dist/ui/sheet.js +1 -1
  412. package/dist/ui/sidebar.cjs +1 -1
  413. package/dist/ui/sidebar.cjs.map +1 -1
  414. package/dist/ui/sidebar.d.cts +30 -31
  415. package/dist/ui/sidebar.d.ts +30 -31
  416. package/dist/ui/sidebar.js +1 -1
  417. package/dist/ui/sidebar.js.map +1 -1
  418. package/dist/ui/skeleton.d.cts +2 -2
  419. package/dist/ui/skeleton.d.ts +2 -2
  420. package/dist/ui/slider.cjs +1 -1
  421. package/dist/ui/slider.cjs.map +1 -1
  422. package/dist/ui/slider.d.cts +2 -3
  423. package/dist/ui/slider.d.ts +2 -3
  424. package/dist/ui/slider.js +1 -1
  425. package/dist/ui/slider.js.map +1 -1
  426. package/dist/ui/sonner.d.cts +2 -2
  427. package/dist/ui/sonner.d.ts +2 -2
  428. package/dist/ui/switch.cjs +1 -1
  429. package/dist/ui/switch.d.cts +2 -3
  430. package/dist/ui/switch.d.ts +2 -3
  431. package/dist/ui/switch.js +1 -1
  432. package/dist/ui/table.cjs +1 -1
  433. package/dist/ui/table.d.cts +9 -10
  434. package/dist/ui/table.d.ts +9 -10
  435. package/dist/ui/table.js +1 -1
  436. package/dist/ui/tabs.cjs +1 -2
  437. package/dist/ui/tabs.d.cts +5 -5
  438. package/dist/ui/tabs.d.ts +5 -5
  439. package/dist/ui/tabs.js +1 -2
  440. package/dist/ui/textarea.cjs +1 -1
  441. package/dist/ui/textarea.d.cts +2 -3
  442. package/dist/ui/textarea.d.ts +2 -3
  443. package/dist/ui/textarea.js +1 -1
  444. package/dist/ui/toggle-group.cjs +1 -1
  445. package/dist/ui/toggle-group.cjs.map +1 -1
  446. package/dist/ui/toggle-group.d.cts +4 -5
  447. package/dist/ui/toggle-group.d.ts +4 -5
  448. package/dist/ui/toggle-group.js +1 -1
  449. package/dist/ui/toggle-group.js.map +1 -1
  450. package/dist/ui/toggle.cjs +1 -1
  451. package/dist/ui/toggle.d.cts +1 -1
  452. package/dist/ui/toggle.d.ts +1 -1
  453. package/dist/ui/toggle.js +1 -1
  454. package/dist/ui/tooltip.cjs +1 -1
  455. package/dist/ui/tooltip.d.cts +1 -1
  456. package/dist/ui/tooltip.d.ts +1 -1
  457. package/dist/ui/tooltip.js +1 -1
  458. package/package.json +6 -2
  459. package/dist/alert-dialog-7AEaiJxA.cjs +0 -2
  460. package/dist/alert-dialog-7AEaiJxA.cjs.map +0 -1
  461. package/dist/alert-dialog-B8Whrlfq.js +0 -2
  462. package/dist/alert-dialog-B8Whrlfq.js.map +0 -1
  463. package/dist/badge-8wMMxROk.js +0 -2
  464. package/dist/badge-8wMMxROk.js.map +0 -1
  465. package/dist/badge-BnFraaZ1.cjs +0 -2
  466. package/dist/badge-BnFraaZ1.cjs.map +0 -1
  467. package/dist/calendar-BgoGbit6.js +0 -2
  468. package/dist/calendar-BgoGbit6.js.map +0 -1
  469. package/dist/calendar-CrtbhiDy.cjs.map +0 -1
  470. package/dist/flex-BxBmZCWh.js +0 -2
  471. package/dist/flex-BxBmZCWh.js.map +0 -1
  472. package/dist/flex-C-4TxUDe.cjs +0 -2
  473. package/dist/flex-C-4TxUDe.cjs.map +0 -1
  474. package/dist/form-B0fOiANW.js +0 -2
  475. package/dist/form-B0fOiANW.js.map +0 -1
  476. package/dist/form-DAwCSzSe.cjs +0 -2
  477. package/dist/form-DAwCSzSe.cjs.map +0 -1
  478. package/dist/input-Bt7b3-NW.cjs +0 -2
  479. package/dist/input-Bt7b3-NW.cjs.map +0 -1
  480. package/dist/input-i5Nm0R1X.js +0 -2
  481. package/dist/input-i5Nm0R1X.js.map +0 -1
  482. package/dist/label-BbuMrcie.cjs +0 -2
  483. package/dist/label-BbuMrcie.cjs.map +0 -1
  484. package/dist/label-CyaoUND0.js +0 -2
  485. package/dist/label-CyaoUND0.js.map +0 -1
  486. package/dist/multi-select-C8kzA628.cjs +0 -2
  487. package/dist/multi-select-C8kzA628.cjs.map +0 -1
  488. package/dist/multi-select-CaBcDGi6.js +0 -2
  489. package/dist/multi-select-CaBcDGi6.js.map +0 -1
  490. package/dist/progress-BhSNuH1w.cjs +0 -2
  491. package/dist/progress-BhSNuH1w.cjs.map +0 -1
  492. package/dist/progress-PzPWivBh.js +0 -2
  493. package/dist/progress-PzPWivBh.js.map +0 -1
  494. package/dist/switch-BN4ghEjT.cjs +0 -2
  495. package/dist/switch-BN4ghEjT.cjs.map +0 -1
  496. package/dist/switch-BeQqTAw4.js +0 -2
  497. package/dist/switch-BeQqTAw4.js.map +0 -1
  498. package/dist/table-Bz4GB66J.cjs +0 -2
  499. package/dist/table-Bz4GB66J.cjs.map +0 -1
  500. package/dist/table-Fby8ksbK.js +0 -2
  501. package/dist/table-Fby8ksbK.js.map +0 -1
  502. package/dist/textarea-CWLU6cai.cjs +0 -2
  503. package/dist/textarea-CWLU6cai.cjs.map +0 -1
  504. package/dist/textarea-S2APrJU-.js +0 -2
  505. package/dist/textarea-S2APrJU-.js.map +0 -1
  506. package/dist/toggle-BrHo4W70.cjs +0 -2
  507. package/dist/toggle-BrHo4W70.cjs.map +0 -1
  508. package/dist/toggle-DCZ9RTZZ.js +0 -2
  509. package/dist/toggle-DCZ9RTZZ.js.map +0 -1
  510. package/dist/tooltip-CN8vvmWA.js +0 -2
  511. package/dist/tooltip-CN8vvmWA.js.map +0 -1
  512. package/dist/tooltip-meYt4lxB.cjs +0 -2
  513. package/dist/tooltip-meYt4lxB.cjs.map +0 -1
  514. package/dist/ui/avatar.cjs.map +0 -1
  515. package/dist/ui/avatar.js.map +0 -1
  516. package/dist/ui/tabs.cjs.map +0 -1
  517. package/dist/ui/tabs.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-D-gDMD-J.js","names":["Label","SlotPrimitive"],"sources":["../packages/components/ui/form.tsx"],"sourcesContent":["'use client'\nimport { createContext, useContext, useId } from 'react'\nimport { Controller, type ControllerProps, type FieldPath, type FieldValues, FormProvider, useFormContext, useFormState } from 'react-hook-form'\nimport { cn } from '@customafk/react-toolkit/utils'\n\nimport { Label } from '@/components/ui/label'\n\nimport { Label as LabelPrimitive, Slot as SlotPrimitive } from 'radix-ui'\n\nconst Form = FormProvider\n\ntype FormFieldContextValue<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {\n name: TName\n}\n\nconst FormFieldContext = createContext<FormFieldContextValue>({} as FormFieldContextValue)\n\nconst FormField = <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n )\n}\n\nconst useFormField = () => {\n const fieldContext = useContext(FormFieldContext)\n const itemContext = useContext(FormItemContext)\n const { getFieldState, control, resetField } = useFormContext()\n const formState = useFormState({ name: fieldContext.name })\n const fieldState = getFieldState(fieldContext.name, formState)\n\n if (!fieldContext) {\n throw new Error('useFormField should be used within <FormField>')\n }\n\n const { id } = itemContext\n\n return {\n id,\n control,\n resetField,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n }\n}\n\ntype FormItemContextValue = {\n id: string\n}\n\nconst FormItemContext = createContext<FormItemContextValue>({} as FormItemContextValue)\n\nfunction FormItem({ className, ...props }: React.ComponentProps<'div'>) {\n const id = useId()\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div data-slot=\"form-item\" className={cn('grid gap-1', className)} {...props} />\n </FormItemContext.Provider>\n )\n}\n\nfunction FormLabel({ className, ...props }: React.ComponentProps<typeof LabelPrimitive.Root>) {\n const { formItemId } = useFormField()\n return <Label data-slot=\"form-label\" className={cn('text-xs', className)} htmlFor={formItemId} {...props} />\n}\n\nfunction FormControl({ ...props }: React.ComponentProps<typeof SlotPrimitive.Slot>) {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField()\n\n return (\n <SlotPrimitive.Slot\n data-slot=\"form-control\"\n id={formItemId}\n aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}\n aria-invalid={!!error}\n {...props}\n />\n )\n}\n\nfunction FormDescription({ className, ...props }: React.ComponentProps<'p'>) {\n const { formDescriptionId } = useFormField()\n\n return <p data-slot=\"form-description\" id={formDescriptionId} className={cn('text-text-positive-weak text-sm', className)} {...props} />\n}\n\nfunction FormMessage({ className, children, ...props }: React.ComponentProps<'p'>) {\n const { error, formMessageId } = useFormField()\n\n return (\n <span data-slot=\"form-message\" id={formMessageId} className={cn('text-danger text-xs', className)} {...props}>\n {error ? String(error?.message ?? '') : children}\n </span>\n )\n}\n\n// eslint-disable-next-line react-refresh/only-export-components\nexport { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField }\n"],"mappings":"yVASA,MAAM,EAAO,EAMP,EAAmB,EAAqC,IAExD,GAA8H,CAClI,GAAG,KAGD,EAAC,EAAiB,SAAA,CAAS,MAAO,CAAE,KAAM,EAAM,eAC9C,EAAC,EAAA,CAAW,GAAI,MAKhB,MAAqB,CACzB,IAAM,EAAe,EAAW,GAC1B,EAAc,EAAW,GACzB,CAAE,gBAAe,UAAS,cAAe,IACzC,EAAY,EAAa,CAAE,KAAM,EAAa,OAC9C,EAAa,EAAc,EAAa,KAAM,GAEpD,GAAI,CAAC,EACH,MAAU,MAAM,kDAGlB,GAAM,CAAE,MAAO,EAEf,MAAO,CACL,KACA,UACA,aACA,KAAM,EAAa,KACnB,WAAY,GAAG,EAAG,YAClB,kBAAmB,GAAG,EAAG,wBACzB,cAAe,GAAG,EAAG,oBACrB,GAAG,IAQD,EAAkB,EAAoC,IAE5D,SAAS,EAAS,CAAE,YAAW,GAAG,GAAsC,CACtE,IAAM,EAAK,IAEX,OACE,EAAC,EAAgB,SAAA,CAAS,MAAO,CAAE,eACjC,EAAC,MAAA,CAAI,YAAU,YAAY,UAAW,EAAG,aAAc,GAAY,GAAI,MAK7E,SAAS,EAAU,CAAE,YAAW,GAAG,GAA2D,CAC5F,GAAM,CAAE,cAAe,IACvB,OAAO,EAACA,EAAAA,CAAM,YAAU,aAAa,UAAW,EAAG,UAAW,GAAY,QAAS,EAAY,GAAI,IAGrG,SAAS,EAAY,CAAE,GAAG,GAA0D,CAClF,GAAM,CAAE,QAAO,aAAY,oBAAmB,iBAAkB,IAEhE,OACE,EAACC,EAAc,KAAA,CACb,YAAU,eACV,GAAI,EACJ,mBAAmB,EAAiC,GAAG,EAAkB,GAAG,IAAjD,GAAG,IAC9B,eAAc,CAAC,CAAC,EAChB,GAAI,IAKV,SAAS,EAAgB,CAAE,YAAW,GAAG,GAAoC,CAC3E,GAAM,CAAE,qBAAsB,IAE9B,OAAO,EAAC,IAAA,CAAE,YAAU,mBAAmB,GAAI,EAAmB,UAAW,EAAG,kCAAmC,GAAY,GAAI,IAGjI,SAAS,EAAY,CAAE,YAAW,WAAU,GAAG,GAAoC,CACjF,GAAM,CAAE,QAAO,iBAAkB,IAEjC,OACE,EAAC,OAAA,CAAK,YAAU,eAAe,GAAI,EAAe,UAAW,EAAG,sBAAuB,GAAY,GAAI,WACpG,EAAQ,OAAO,GAAO,SAAW,IAAM"}
@@ -1,2 +1,2 @@
1
- const e=require(`./chunk-CUT6urMc.cjs`),t=require(`./error-dialog-COyyui94.cjs`),n=require(`./form-DAwCSzSe.cjs`),r=e.__toESM(require(`lucide-react`)),i=e.__toESM(require(`react/jsx-runtime`)),a=e.__toESM(require(`react`)),o=e.__toESM(require(`react-hook-form`)),s=e.__toESM(require(`@hookform/error-message`)),c=({form:e,isResetAfterSubmit:c=!0,className:l,onSubmit:u,onError:d,onSubcribe:f,children:p})=>{let m=(0,o.useForm)({...e,criteriaMode:`all`}),{formState:h,reset:g,handleSubmit:_,subscribe:v}=m,{dirtyFields:y}=h,[b,x]=(0,a.useState)(!1),S=(0,a.useCallback)(e=>{u(e,h,y),c&&g()},[y,h,c,u,g]),C=(0,a.useCallback)(e=>{let t=Object.keys(e);t.length!==0&&(d?.(e),x(!0))},[d]);return(0,a.useEffect)(()=>{if(!f)return;let e=v({formState:{values:!0},callback:({values:e})=>{f(e)}});return()=>e()},[f,v]),(0,i.jsxs)(n.Form,{...m,children:[(0,i.jsx)(`form`,{className:l,onSubmit:_(S,C),children:p}),(0,i.jsx)(t.ErrorDialog,{open:b,title:`Lỗi nhập dữ liệu`,description:`An unexpected error has occurred. Please check the errors below and try again.`,onOpenChange:x,children:b&&(0,i.jsx)(i.Fragment,{children:Object.keys(h.errors).length>0?(0,i.jsxs)(`div`,{className:`flex max-w-100 flex-col gap-2 px-4`,children:[(0,i.jsx)(`p`,{className:`text-muted-foreground text-sm font-semibold`,children:`Cảnh báo: Vui lòng kiểm tra các lỗi sau:`}),(0,i.jsx)(`div`,{className:`flex flex-col space-y-1`,children:Object.entries(h.errors).map(([e])=>(0,i.jsx)(s.ErrorMessage,{errors:h.errors,name:e,render:({messages:e})=>(0,i.jsx)(i.Fragment,{children:e?Object.entries(e).map(([e,t])=>(0,i.jsxs)(`div`,{className:`text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal`,children:[(0,i.jsx)(r.AlertCircleIcon,{size:16,className:`text-destructive mt-0.5 min-w-4 flex-0`}),(0,i.jsx)(`p`,{className:`line-clamp-2 flex-1 text-wrap`,children:t})]},e)):null})},e))})]}):(0,i.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No errors found.`})})})]})};Object.defineProperty(exports,`FormWrapper`,{enumerable:!0,get:function(){return c}});
2
- //# sourceMappingURL=form-wrapper-D0-p7R15.cjs.map
1
+ const e=require(`./chunk-CUT6urMc.cjs`),t=require(`./error-dialog-BkCaUR7F.cjs`),n=require(`./form-CaxhlWxK.cjs`),r=e.__toESM(require(`lucide-react`)),i=e.__toESM(require(`react/jsx-runtime`)),a=e.__toESM(require(`react`)),o=e.__toESM(require(`react-hook-form`)),s=e.__toESM(require(`@hookform/error-message`)),c=({form:e,isResetAfterSubmit:c=!0,className:l,onSubmit:u,onError:d,onSubcribe:f,children:p})=>{let m=(0,o.useForm)({...e,criteriaMode:`all`}),{formState:h,reset:g,handleSubmit:_,subscribe:v}=m,{dirtyFields:y}=h,[b,x]=(0,a.useState)(!1),S=(0,a.useCallback)(e=>{u(e,h,y),c&&g()},[y,h,c,u,g]),C=(0,a.useCallback)(e=>{let t=Object.keys(e);t.length!==0&&(d?.(e),x(!0))},[d]);return(0,a.useEffect)(()=>{if(!f)return;let e=v({formState:{values:!0},callback:({values:e})=>{f(e)}});return()=>e()},[f,v]),(0,i.jsxs)(n.Form,{...m,children:[(0,i.jsx)(`form`,{className:l,onSubmit:_(S,C),children:p}),(0,i.jsx)(t.ErrorDialog,{open:b,title:`Lỗi nhập dữ liệu`,description:`An unexpected error has occurred. Please check the errors below and try again.`,onOpenChange:x,children:b&&(0,i.jsx)(i.Fragment,{children:Object.keys(h.errors).length>0?(0,i.jsxs)(`div`,{className:`flex max-w-100 flex-col gap-2 px-4`,children:[(0,i.jsx)(`p`,{className:`text-muted-foreground text-sm font-semibold`,children:`Cảnh báo: Vui lòng kiểm tra các lỗi sau:`}),(0,i.jsx)(`div`,{className:`flex flex-col space-y-1`,children:Object.entries(h.errors).map(([e])=>(0,i.jsx)(s.ErrorMessage,{errors:h.errors,name:e,render:({messages:e})=>(0,i.jsx)(i.Fragment,{children:e?Object.entries(e).map(([e,t])=>(0,i.jsxs)(`div`,{className:`text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal`,children:[(0,i.jsx)(r.AlertCircleIcon,{size:16,className:`text-destructive mt-0.5 min-w-4 flex-0`}),(0,i.jsx)(`p`,{className:`line-clamp-2 flex-1 text-wrap`,children:t})]},e)):null})},e))})]}):(0,i.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No errors found.`})})})]})};Object.defineProperty(exports,`FormWrapper`,{enumerable:!0,get:function(){return c}});
2
+ //# sourceMappingURL=form-wrapper-BUkoh-c7.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"form-wrapper-D0-p7R15.cjs","names":["Form","ErrorDialog","ErrorMessage","AlertCircleIcon"],"sources":["../packages/components/forms/form-wrapper.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { type FieldValues, type FormState, type SubmitErrorHandler, type SubmitHandler, useForm, type UseFormProps } from 'react-hook-form'\n\nimport { AlertCircleIcon } from 'lucide-react'\n\nimport type { AnyEntity } from '@/types'\nimport { ErrorMessage } from '@hookform/error-message'\n\nimport { ErrorDialog } from '../dialogs/error-dialog'\nimport { Form } from '../ui/form'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n form: UseFormProps<TFieldValues>\n isResetAfterSubmit?: boolean\n className?: string\n onSubmit: (data: TFieldValues, formState: FormState<FieldValues>, dirtyFields: FormState<FieldValues>['dirtyFields']) => void | Promise<void>\n onError?: SubmitErrorHandler<TFieldValues>\n onSubcribe?: (values: TFieldValues) => void\n}\n\nexport const FormWrapper = <TFieldValues extends FieldValues = FieldValues>({\n form: FormConfig,\n isResetAfterSubmit = true,\n className,\n onSubmit,\n onError,\n onSubcribe,\n children,\n}: React.PropsWithChildren<Props<TFieldValues>>) => {\n const form = useForm({\n ...FormConfig,\n criteriaMode: 'all',\n })\n\n const { formState, reset, handleSubmit, subscribe } = form\n const { dirtyFields } = formState\n\n const [errorOpen, setErrorOpen] = useState<boolean>(false)\n\n const handleFormSubmit = useCallback<SubmitHandler<TFieldValues>>(\n (data) => {\n onSubmit(data, formState, dirtyFields)\n if (isResetAfterSubmit) {\n reset()\n }\n },\n [dirtyFields, formState, isResetAfterSubmit, onSubmit, reset],\n )\n\n const handleFormError = useCallback<SubmitErrorHandler<TFieldValues>>(\n (errors) => {\n const errorKeys = Object.keys(errors)\n if (errorKeys.length === 0) return\n onError?.(errors)\n setErrorOpen(true)\n },\n [onError],\n )\n\n useEffect(() => {\n if (!onSubcribe) return\n const callback = subscribe({\n formState: { values: true },\n callback: ({ values }) => {\n onSubcribe(values)\n },\n })\n return () => callback()\n }, [onSubcribe, subscribe])\n\n return (\n <Form {...form}>\n <form className={className} onSubmit={handleSubmit(handleFormSubmit, handleFormError)}>\n {children}\n </form>\n <ErrorDialog\n open={errorOpen}\n title=\"Lỗi nhập dữ liệu\"\n description=\"An unexpected error has occurred. Please check the errors below and try again.\"\n onOpenChange={setErrorOpen}\n >\n {errorOpen && (\n <>\n {Object.keys(formState.errors).length > 0 ? (\n <div className=\"flex max-w-100 flex-col gap-2 px-4\">\n <p className=\"text-muted-foreground text-sm font-semibold\">Cảnh báo: Vui lòng kiểm tra các lỗi sau:</p>\n <div className=\"flex flex-col space-y-1\">\n {Object.entries(formState.errors).map(([key]) => (\n <ErrorMessage\n key={key}\n errors={formState.errors}\n name={key as AnyEntity}\n render={({ messages }) => {\n return (\n <>\n {messages\n ? Object.entries(messages).map(([type, message]) => {\n return (\n <div key={type} className=\"text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal\">\n <AlertCircleIcon size={16} className=\"text-destructive mt-0.5 min-w-4 flex-0\" />\n <p className=\"line-clamp-2 flex-1 text-wrap\">{message}</p>\n </div>\n )\n })\n : null}\n </>\n )\n }}\n />\n ))}\n </div>\n </div>\n ) : (\n <p className=\"text-muted-foreground text-sm\">No errors found.</p>\n )}\n </>\n )}\n </ErrorDialog>\n </Form>\n )\n}\n"],"mappings":"uTAoBa,GAA+D,CAC1E,KAAM,EACN,qBAAqB,GACrB,YACA,WACA,UACA,aACA,cACkD,CAClD,IAAM,GAAA,EAAA,EAAA,SAAe,CACnB,GAAG,EACH,aAAc,QAGV,CAAE,YAAW,QAAO,eAAc,aAAc,EAChD,CAAE,eAAgB,EAElB,CAAC,EAAW,IAAA,EAAA,EAAA,UAA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,EAAA,EAAA,KAAC,IAAA,CAAE,UAAU,yCAAgC"}
1
+ {"version":3,"file":"form-wrapper-BUkoh-c7.cjs","names":["Form","ErrorDialog","ErrorMessage","AlertCircleIcon"],"sources":["../packages/components/forms/form-wrapper.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { type FieldValues, type FormState, type SubmitErrorHandler, type SubmitHandler, useForm, type UseFormProps } from 'react-hook-form'\n\nimport { AlertCircleIcon } from 'lucide-react'\n\nimport type { AnyEntity } from '@/types'\nimport { ErrorMessage } from '@hookform/error-message'\n\nimport { ErrorDialog } from '../dialogs/error-dialog'\nimport { Form } from '../ui/form'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n form: UseFormProps<TFieldValues>\n isResetAfterSubmit?: boolean\n className?: string\n onSubmit: (data: TFieldValues, formState: FormState<FieldValues>, dirtyFields: FormState<FieldValues>['dirtyFields']) => void | Promise<void>\n onError?: SubmitErrorHandler<TFieldValues>\n onSubcribe?: (values: TFieldValues) => void\n}\n\nexport const FormWrapper = <TFieldValues extends FieldValues = FieldValues>({\n form: FormConfig,\n isResetAfterSubmit = true,\n className,\n onSubmit,\n onError,\n onSubcribe,\n children,\n}: React.PropsWithChildren<Props<TFieldValues>>) => {\n const form = useForm({\n ...FormConfig,\n criteriaMode: 'all',\n })\n\n const { formState, reset, handleSubmit, subscribe } = form\n const { dirtyFields } = formState\n\n const [errorOpen, setErrorOpen] = useState<boolean>(false)\n\n const handleFormSubmit = useCallback<SubmitHandler<TFieldValues>>(\n (data) => {\n onSubmit(data, formState, dirtyFields)\n if (isResetAfterSubmit) {\n reset()\n }\n },\n [dirtyFields, formState, isResetAfterSubmit, onSubmit, reset],\n )\n\n const handleFormError = useCallback<SubmitErrorHandler<TFieldValues>>(\n (errors) => {\n const errorKeys = Object.keys(errors)\n if (errorKeys.length === 0) return\n onError?.(errors)\n setErrorOpen(true)\n },\n [onError],\n )\n\n useEffect(() => {\n if (!onSubcribe) return\n const callback = subscribe({\n formState: { values: true },\n callback: ({ values }) => {\n onSubcribe(values)\n },\n })\n return () => callback()\n }, [onSubcribe, subscribe])\n\n return (\n <Form {...form}>\n <form className={className} onSubmit={handleSubmit(handleFormSubmit, handleFormError)}>\n {children}\n </form>\n <ErrorDialog\n open={errorOpen}\n title=\"Lỗi nhập dữ liệu\"\n description=\"An unexpected error has occurred. Please check the errors below and try again.\"\n onOpenChange={setErrorOpen}\n >\n {errorOpen && (\n <>\n {Object.keys(formState.errors).length > 0 ? (\n <div className=\"flex max-w-100 flex-col gap-2 px-4\">\n <p className=\"text-muted-foreground text-sm font-semibold\">Cảnh báo: Vui lòng kiểm tra các lỗi sau:</p>\n <div className=\"flex flex-col space-y-1\">\n {Object.entries(formState.errors).map(([key]) => (\n <ErrorMessage\n key={key}\n errors={formState.errors}\n name={key as AnyEntity}\n render={({ messages }) => {\n return (\n <>\n {messages\n ? Object.entries(messages).map(([type, message]) => {\n return (\n <div key={type} className=\"text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal\">\n <AlertCircleIcon size={16} className=\"text-destructive mt-0.5 min-w-4 flex-0\" />\n <p className=\"line-clamp-2 flex-1 text-wrap\">{message}</p>\n </div>\n )\n })\n : null}\n </>\n )\n }}\n />\n ))}\n </div>\n </div>\n ) : (\n <p className=\"text-muted-foreground text-sm\">No errors found.</p>\n )}\n </>\n )}\n </ErrorDialog>\n </Form>\n )\n}\n"],"mappings":"uTAoBa,GAA+D,CAC1E,KAAM,EACN,qBAAqB,GACrB,YACA,WACA,UACA,aACA,cACkD,CAClD,IAAM,GAAA,EAAA,EAAA,SAAe,CACnB,GAAG,EACH,aAAc,QAGV,CAAE,YAAW,QAAO,eAAc,aAAc,EAChD,CAAE,eAAgB,EAElB,CAAC,EAAW,IAAA,EAAA,EAAA,UAAkC,IAE9C,GAAA,EAAA,EAAA,aACH,GAAS,CACR,EAAS,EAAM,EAAW,GACtB,GACF,KAGJ,CAAC,EAAa,EAAW,EAAoB,EAAU,IAGnD,GA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form-B0fOiANW.js";import{AlertCircleIcon as n}from"lucide-react";import{Fragment as r,jsx as i,jsxs as a}from"react/jsx-runtime";import{useCallback as o,useEffect as s,useState as c}from"react";import{useForm as l}from"react-hook-form";import{ErrorMessage as u}from"@hookform/error-message";const d=({form:d,isResetAfterSubmit:f=!0,className:p,onSubmit:m,onError:h,onSubcribe:g,children:_})=>{let v=l({...d,criteriaMode:`all`}),{formState:y,reset:b,handleSubmit:x,subscribe:S}=v,{dirtyFields:C}=y,[w,T]=c(!1),E=o(e=>{m(e,y,C),f&&b()},[C,y,f,m,b]),D=o(e=>{let t=Object.keys(e);t.length!==0&&(h?.(e),T(!0))},[h]);return s(()=>{if(!g)return;let e=S({formState:{values:!0},callback:({values:e})=>{g(e)}});return()=>e()},[g,S]),a(t,{...v,children:[i(`form`,{className:p,onSubmit:x(E,D),children:_}),i(e,{open:w,title:`Lỗi nhập dữ liệu`,description:`An unexpected error has occurred. Please check the errors below and try again.`,onOpenChange:T,children:w&&i(r,{children:Object.keys(y.errors).length>0?a(`div`,{className:`flex max-w-100 flex-col gap-2 px-4`,children:[i(`p`,{className:`text-muted-foreground text-sm font-semibold`,children:`Cảnh báo: Vui lòng kiểm tra các lỗi sau:`}),i(`div`,{className:`flex flex-col space-y-1`,children:Object.entries(y.errors).map(([e])=>i(u,{errors:y.errors,name:e,render:({messages:e})=>i(r,{children:e?Object.entries(e).map(([e,t])=>a(`div`,{className:`text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal`,children:[i(n,{size:16,className:`text-destructive mt-0.5 min-w-4 flex-0`}),i(`p`,{className:`line-clamp-2 flex-1 text-wrap`,children:t})]},e)):null})},e))})]}):i(`p`,{className:`text-muted-foreground text-sm`,children:`No errors found.`})})})]})};export{d as FormWrapper};
2
- //# sourceMappingURL=form-wrapper-C4OO_eLu.js.map
1
+ import{ErrorDialog as e}from"./error-dialog-D3tnycqF.js";import{Form as t}from"./form-D-gDMD-J.js";import{AlertCircleIcon as n}from"lucide-react";import{Fragment as r,jsx as i,jsxs as a}from"react/jsx-runtime";import{useCallback as o,useEffect as s,useState as c}from"react";import{useForm as l}from"react-hook-form";import{ErrorMessage as u}from"@hookform/error-message";const d=({form:d,isResetAfterSubmit:f=!0,className:p,onSubmit:m,onError:h,onSubcribe:g,children:_})=>{let v=l({...d,criteriaMode:`all`}),{formState:y,reset:b,handleSubmit:x,subscribe:S}=v,{dirtyFields:C}=y,[w,T]=c(!1),E=o(e=>{m(e,y,C),f&&b()},[C,y,f,m,b]),D=o(e=>{let t=Object.keys(e);t.length!==0&&(h?.(e),T(!0))},[h]);return s(()=>{if(!g)return;let e=S({formState:{values:!0},callback:({values:e})=>{g(e)}});return()=>e()},[g,S]),a(t,{...v,children:[i(`form`,{className:p,onSubmit:x(E,D),children:_}),i(e,{open:w,title:`Lỗi nhập dữ liệu`,description:`An unexpected error has occurred. Please check the errors below and try again.`,onOpenChange:T,children:w&&i(r,{children:Object.keys(y.errors).length>0?a(`div`,{className:`flex max-w-100 flex-col gap-2 px-4`,children:[i(`p`,{className:`text-muted-foreground text-sm font-semibold`,children:`Cảnh báo: Vui lòng kiểm tra các lỗi sau:`}),i(`div`,{className:`flex flex-col space-y-1`,children:Object.entries(y.errors).map(([e])=>i(u,{errors:y.errors,name:e,render:({messages:e})=>i(r,{children:e?Object.entries(e).map(([e,t])=>a(`div`,{className:`text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal`,children:[i(n,{size:16,className:`text-destructive mt-0.5 min-w-4 flex-0`}),i(`p`,{className:`line-clamp-2 flex-1 text-wrap`,children:t})]},e)):null})},e))})]}):i(`p`,{className:`text-muted-foreground text-sm`,children:`No errors found.`})})})]})};export{d as FormWrapper};
2
+ //# sourceMappingURL=form-wrapper-BbScjpBv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"form-wrapper-C4OO_eLu.js","names":[],"sources":["../packages/components/forms/form-wrapper.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { type FieldValues, type FormState, type SubmitErrorHandler, type SubmitHandler, useForm, type UseFormProps } from 'react-hook-form'\n\nimport { AlertCircleIcon } from 'lucide-react'\n\nimport type { AnyEntity } from '@/types'\nimport { ErrorMessage } from '@hookform/error-message'\n\nimport { ErrorDialog } from '../dialogs/error-dialog'\nimport { Form } from '../ui/form'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n form: UseFormProps<TFieldValues>\n isResetAfterSubmit?: boolean\n className?: string\n onSubmit: (data: TFieldValues, formState: FormState<FieldValues>, dirtyFields: FormState<FieldValues>['dirtyFields']) => void | Promise<void>\n onError?: SubmitErrorHandler<TFieldValues>\n onSubcribe?: (values: TFieldValues) => void\n}\n\nexport const FormWrapper = <TFieldValues extends FieldValues = FieldValues>({\n form: FormConfig,\n isResetAfterSubmit = true,\n className,\n onSubmit,\n onError,\n onSubcribe,\n children,\n}: React.PropsWithChildren<Props<TFieldValues>>) => {\n const form = useForm({\n ...FormConfig,\n criteriaMode: 'all',\n })\n\n const { formState, reset, handleSubmit, subscribe } = form\n const { dirtyFields } = formState\n\n const [errorOpen, setErrorOpen] = useState<boolean>(false)\n\n const handleFormSubmit = useCallback<SubmitHandler<TFieldValues>>(\n (data) => {\n onSubmit(data, formState, dirtyFields)\n if (isResetAfterSubmit) {\n reset()\n }\n },\n [dirtyFields, formState, isResetAfterSubmit, onSubmit, reset],\n )\n\n const handleFormError = useCallback<SubmitErrorHandler<TFieldValues>>(\n (errors) => {\n const errorKeys = Object.keys(errors)\n if (errorKeys.length === 0) return\n onError?.(errors)\n setErrorOpen(true)\n },\n [onError],\n )\n\n useEffect(() => {\n if (!onSubcribe) return\n const callback = subscribe({\n formState: { values: true },\n callback: ({ values }) => {\n onSubcribe(values)\n },\n })\n return () => callback()\n }, [onSubcribe, subscribe])\n\n return (\n <Form {...form}>\n <form className={className} onSubmit={handleSubmit(handleFormSubmit, handleFormError)}>\n {children}\n </form>\n <ErrorDialog\n open={errorOpen}\n title=\"Lỗi nhập dữ liệu\"\n description=\"An unexpected error has occurred. Please check the errors below and try again.\"\n onOpenChange={setErrorOpen}\n >\n {errorOpen && (\n <>\n {Object.keys(formState.errors).length > 0 ? (\n <div className=\"flex max-w-100 flex-col gap-2 px-4\">\n <p className=\"text-muted-foreground text-sm font-semibold\">Cảnh báo: Vui lòng kiểm tra các lỗi sau:</p>\n <div className=\"flex flex-col space-y-1\">\n {Object.entries(formState.errors).map(([key]) => (\n <ErrorMessage\n key={key}\n errors={formState.errors}\n name={key as AnyEntity}\n render={({ messages }) => {\n return (\n <>\n {messages\n ? Object.entries(messages).map(([type, message]) => {\n return (\n <div key={type} className=\"text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal\">\n <AlertCircleIcon size={16} className=\"text-destructive mt-0.5 min-w-4 flex-0\" />\n <p className=\"line-clamp-2 flex-1 text-wrap\">{message}</p>\n </div>\n )\n })\n : null}\n </>\n )\n }}\n />\n ))}\n </div>\n </div>\n ) : (\n <p className=\"text-muted-foreground text-sm\">No errors found.</p>\n )}\n </>\n )}\n </ErrorDialog>\n </Form>\n )\n}\n"],"mappings":"oXAoBA,MAAa,GAA+D,CAC1E,KAAM,EACN,qBAAqB,GACrB,YACA,WACA,UACA,aACA,cACkD,CAClD,IAAM,EAAO,EAAQ,CACnB,GAAG,EACH,aAAc,QAGV,CAAE,YAAW,QAAO,eAAc,aAAc,EAChD,CAAE,eAAgB,EAElB,CAAC,EAAW,GAAgB,EAAkB,IAE9C,EAAmB,EACtB,GAAS,CACR,EAAS,EAAM,EAAW,GACtB,GACF,KAGJ,CAAC,EAAa,EAAW,EAAoB,EAAU,IAGnD,EAAkB,EACrB,GAAW,CACV,IAAM,EAAY,OAAO,KAAK,GAC1B,EAAU,SAAW,IACzB,IAAU,GACV,EAAa,MAEf,CAAC,IAcH,OAXA,MAAgB,CACd,GAAI,CAAC,EAAY,OACjB,IAAM,EAAW,EAAU,CACzB,UAAW,CAAE,OAAQ,IACrB,UAAW,CAAE,YAAa,CACxB,EAAW,MAGf,UAAa,KACZ,CAAC,EAAY,IAGd,EAAC,EAAA,CAAK,GAAI,YACR,EAAC,OAAA,CAAgB,YAAW,SAAU,EAAa,EAAkB,GAClE,aAEH,EAAC,EAAA,CACC,KAAM,EACN,MAAM,mBACN,YAAY,iFACZ,aAAc,WAEb,GACC,EAAA,EAAA,CAAA,SACG,OAAO,KAAK,EAAU,QAAQ,OAAS,EACtC,EAAC,MAAA,CAAI,UAAU,+CACb,EAAC,IAAA,CAAE,UAAU,uDAA8C,6CAC3D,EAAC,MAAA,CAAI,UAAU,mCACZ,OAAO,QAAQ,EAAU,QAAQ,KAAK,CAAC,KACtC,EAAC,EAAA,CAEC,OAAQ,EAAU,OAClB,KAAM,EACN,QAAS,CAAE,cAEP,EAAA,EAAA,CAAA,SACG,EACG,OAAO,QAAQ,GAAU,KAAK,CAAC,EAAM,KAEjC,EAAC,MAAA,CAAe,UAAU,yFACxB,EAAC,EAAA,CAAgB,KAAM,GAAI,UAAU,2CACrC,EAAC,IAAA,CAAE,UAAU,yCAAiC,MAFtC,IAMd,QAfL,SAwBb,EAAC,IAAA,CAAE,UAAU,yCAAgC"}
1
+ {"version":3,"file":"form-wrapper-BbScjpBv.js","names":[],"sources":["../packages/components/forms/form-wrapper.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { type FieldValues, type FormState, type SubmitErrorHandler, type SubmitHandler, useForm, type UseFormProps } from 'react-hook-form'\n\nimport { AlertCircleIcon } from 'lucide-react'\n\nimport type { AnyEntity } from '@/types'\nimport { ErrorMessage } from '@hookform/error-message'\n\nimport { ErrorDialog } from '../dialogs/error-dialog'\nimport { Form } from '../ui/form'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n form: UseFormProps<TFieldValues>\n isResetAfterSubmit?: boolean\n className?: string\n onSubmit: (data: TFieldValues, formState: FormState<FieldValues>, dirtyFields: FormState<FieldValues>['dirtyFields']) => void | Promise<void>\n onError?: SubmitErrorHandler<TFieldValues>\n onSubcribe?: (values: TFieldValues) => void\n}\n\nexport const FormWrapper = <TFieldValues extends FieldValues = FieldValues>({\n form: FormConfig,\n isResetAfterSubmit = true,\n className,\n onSubmit,\n onError,\n onSubcribe,\n children,\n}: React.PropsWithChildren<Props<TFieldValues>>) => {\n const form = useForm({\n ...FormConfig,\n criteriaMode: 'all',\n })\n\n const { formState, reset, handleSubmit, subscribe } = form\n const { dirtyFields } = formState\n\n const [errorOpen, setErrorOpen] = useState<boolean>(false)\n\n const handleFormSubmit = useCallback<SubmitHandler<TFieldValues>>(\n (data) => {\n onSubmit(data, formState, dirtyFields)\n if (isResetAfterSubmit) {\n reset()\n }\n },\n [dirtyFields, formState, isResetAfterSubmit, onSubmit, reset],\n )\n\n const handleFormError = useCallback<SubmitErrorHandler<TFieldValues>>(\n (errors) => {\n const errorKeys = Object.keys(errors)\n if (errorKeys.length === 0) return\n onError?.(errors)\n setErrorOpen(true)\n },\n [onError],\n )\n\n useEffect(() => {\n if (!onSubcribe) return\n const callback = subscribe({\n formState: { values: true },\n callback: ({ values }) => {\n onSubcribe(values)\n },\n })\n return () => callback()\n }, [onSubcribe, subscribe])\n\n return (\n <Form {...form}>\n <form className={className} onSubmit={handleSubmit(handleFormSubmit, handleFormError)}>\n {children}\n </form>\n <ErrorDialog\n open={errorOpen}\n title=\"Lỗi nhập dữ liệu\"\n description=\"An unexpected error has occurred. Please check the errors below and try again.\"\n onOpenChange={setErrorOpen}\n >\n {errorOpen && (\n <>\n {Object.keys(formState.errors).length > 0 ? (\n <div className=\"flex max-w-100 flex-col gap-2 px-4\">\n <p className=\"text-muted-foreground text-sm font-semibold\">Cảnh báo: Vui lòng kiểm tra các lỗi sau:</p>\n <div className=\"flex flex-col space-y-1\">\n {Object.entries(formState.errors).map(([key]) => (\n <ErrorMessage\n key={key}\n errors={formState.errors}\n name={key as AnyEntity}\n render={({ messages }) => {\n return (\n <>\n {messages\n ? Object.entries(messages).map(([type, message]) => {\n return (\n <div key={type} className=\"text-accent-foreground flex items-start gap-x-1 truncate text-sm font-normal\">\n <AlertCircleIcon size={16} className=\"text-destructive mt-0.5 min-w-4 flex-0\" />\n <p className=\"line-clamp-2 flex-1 text-wrap\">{message}</p>\n </div>\n )\n })\n : null}\n </>\n )\n }}\n />\n ))}\n </div>\n </div>\n ) : (\n <p className=\"text-muted-foreground text-sm\">No errors found.</p>\n )}\n </>\n )}\n </ErrorDialog>\n </Form>\n )\n}\n"],"mappings":"oXAoBA,MAAa,GAA+D,CAC1E,KAAM,EACN,qBAAqB,GACrB,YACA,WACA,UACA,aACA,cACkD,CAClD,IAAM,EAAO,EAAQ,CACnB,GAAG,EACH,aAAc,QAGV,CAAE,YAAW,QAAO,eAAc,aAAc,EAChD,CAAE,eAAgB,EAElB,CAAC,EAAW,GAAgB,EAAkB,IAE9C,EAAmB,EACtB,GAAS,CACR,EAAS,EAAM,EAAW,GACtB,GACF,KAGJ,CAAC,EAAa,EAAW,EAAoB,EAAU,IAGnD,EAAkB,EACrB,GAAW,CACV,IAAM,EAAY,OAAO,KAAK,GAC1B,EAAU,SAAW,IACzB,IAAU,GACV,EAAa,MAEf,CAAC,IAcH,OAXA,MAAgB,CACd,GAAI,CAAC,EAAY,OACjB,IAAM,EAAW,EAAU,CACzB,UAAW,CAAE,OAAQ,IACrB,UAAW,CAAE,YAAa,CACxB,EAAW,MAGf,UAAa,KACZ,CAAC,EAAY,IAGd,EAAC,EAAA,CAAK,GAAI,YACR,EAAC,OAAA,CAAgB,YAAW,SAAU,EAAa,EAAkB,GAClE,aAEH,EAAC,EAAA,CACC,KAAM,EACN,MAAM,mBACN,YAAY,iFACZ,aAAc,WAEb,GACC,EAAA,EAAA,CAAA,SACG,OAAO,KAAK,EAAU,QAAQ,OAAS,EACtC,EAAC,MAAA,CAAI,UAAU,+CACb,EAAC,IAAA,CAAE,UAAU,uDAA8C,6CAC3D,EAAC,MAAA,CAAI,UAAU,mCACZ,OAAO,QAAQ,EAAU,QAAQ,KAAK,CAAC,KACtC,EAAC,EAAA,CAEC,OAAQ,EAAU,OAClB,KAAM,EACN,QAAS,CAAE,cAEP,EAAA,EAAA,CAAA,SACG,EACG,OAAO,QAAQ,GAAU,KAAK,CAAC,EAAM,KAEjC,EAAC,MAAA,CAAe,UAAU,yFACxB,EAAC,EAAA,CAAgB,KAAM,GAAI,UAAU,2CACrC,EAAC,IAAA,CAAE,UAAU,yCAAiC,MAFtC,IAMd,QAfL,SAwBb,EAAC,IAAA,CAAE,UAAU,yCAAgC"}
@@ -1,2 +1,2 @@
1
- "use client";const e=require(`../chunk-CUT6urMc.cjs`),t=require(`../button-119IIVCy.cjs`);require(`../label-BbuMrcie.cjs`);const n=require(`../form-DAwCSzSe.cjs`);require(`../dialog-CGrbU7PO.cjs`);const r=require(`../command-COUM-XfY.cjs`),i=require(`../popover-BsF6vWTX.cjs`),a=e.__toESM(require(`lucide-react`)),o=e.__toESM(require(`@customafk/react-toolkit/utils`)),s=e.__toESM(require(`react/jsx-runtime`)),c=({name:e,label:c=`Combobox`,placeholder:l=`Chọn một mục`,description:u,options:d,onAddNewItem:f})=>(0,s.jsx)(n.FormField,{name:e,render:({field:e})=>(0,s.jsxs)(n.FormItem,{className:`w-full`,children:[(0,s.jsx)(n.FormLabel,{children:c}),(0,s.jsxs)(i.Popover,{modal:!0,children:[(0,s.jsx)(i.PopoverTrigger,{asChild:!0,children:(0,s.jsx)(n.FormControl,{children:(0,s.jsxs)(t.Button,{type:`button`,variant:`outline`,role:`combobox`,color:`muted`,className:(0,o.cn)(`shadow-input flex justify-between rounded-md px-3`,`outline-border-weak font-normal`,`[&_div]:w-full`,`[&_div]:justify-between`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`),children:[e.value?(0,s.jsx)(`span`,{className:`flex min-w-0 items-center gap-2`,children:d?.find(({value:t})=>t===e.value)?.label}):(0,s.jsx)(`span`,{className:`text-text-positive-muted`,children:l}),(0,s.jsx)(a.ChevronDownIcon,{size:16,className:`text-text-positive-weak shrink-0`,"aria-hidden":`true`})]})})}),(0,s.jsx)(i.PopoverContent,{className:`w-[var(--radix-popover-trigger-width)] p-0`,children:(0,s.jsxs)(r.Command,{className:`border-none`,children:[(0,s.jsx)(r.CommandInput,{placeholder:l??`Tìm kiếm`}),(0,s.jsxs)(r.CommandList,{children:[(0,s.jsx)(r.CommandGroup,{className:`max-h-40 overflow-y-auto`,children:d?.map(({value:t,label:n})=>(0,s.jsx)(r.CommandItem,{value:n,onSelect:()=>e.onChange(t),children:n},t))}),f&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.CommandSeparator,{}),(0,s.jsx)(r.CommandGroup,{children:(0,s.jsxs)(t.Button,{type:`button`,variant:`ghost`,className:`w-full justify-start font-normal`,children:[(0,s.jsx)(a.PlusIcon,{size:14,className:`-ms-2 opacity-60`,"aria-hidden":`true`}),`Thêm mới`]})})]})]}),(0,s.jsx)(r.CommandEmpty,{children:`Không có kết quả`})]})})]}),!!u&&(0,s.jsx)(n.FormDescription,{children:u})]})});exports.ComboboxField=c;
1
+ "use client";const e=require(`../chunk-CUT6urMc.cjs`),t=require(`../button-119IIVCy.cjs`);require(`../label-BBPPT0-L.cjs`);const n=require(`../form-CaxhlWxK.cjs`);require(`../dialog-CGrbU7PO.cjs`);const r=require(`../command-B9nlrxXh.cjs`),i=require(`../popover-ByL6Igxn.cjs`),a=e.__toESM(require(`lucide-react`)),o=e.__toESM(require(`@customafk/react-toolkit/utils`)),s=e.__toESM(require(`react/jsx-runtime`)),c=({name:e,label:c=`Combobox`,placeholder:l=`Chọn một mục`,description:u,options:d,onAddNewItem:f})=>(0,s.jsx)(n.FormField,{name:e,render:({field:e})=>(0,s.jsxs)(n.FormItem,{className:`w-full`,children:[(0,s.jsx)(n.FormLabel,{children:c}),(0,s.jsxs)(i.Popover,{modal:!0,children:[(0,s.jsx)(i.PopoverTrigger,{asChild:!0,children:(0,s.jsx)(n.FormControl,{children:(0,s.jsxs)(t.Button,{type:`button`,variant:`outline`,role:`combobox`,color:`muted`,className:(0,o.cn)(`shadow-input flex justify-between rounded-md px-3`,`outline-border-weak font-normal`,`[&_div]:w-full`,`[&_div]:justify-between`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`),children:[e.value?(0,s.jsx)(`span`,{className:`flex min-w-0 items-center gap-2`,children:d?.find(({value:t})=>t===e.value)?.label}):(0,s.jsx)(`span`,{className:`text-text-positive-muted`,children:l}),(0,s.jsx)(a.ChevronDownIcon,{size:16,className:`text-text-positive-weak shrink-0`,"aria-hidden":`true`})]})})}),(0,s.jsx)(i.PopoverContent,{className:`w-[var(--radix-popover-trigger-width)] p-0`,children:(0,s.jsxs)(r.Command,{className:`border-none`,children:[(0,s.jsx)(r.CommandInput,{placeholder:l??`Tìm kiếm`}),(0,s.jsxs)(r.CommandList,{children:[(0,s.jsx)(r.CommandGroup,{className:`max-h-40 overflow-y-auto`,children:d?.map(({value:t,label:n})=>(0,s.jsx)(r.CommandItem,{value:n,onSelect:()=>e.onChange(t),children:n},t))}),f&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.CommandSeparator,{}),(0,s.jsx)(r.CommandGroup,{children:(0,s.jsxs)(t.Button,{type:`button`,variant:`ghost`,className:`w-full justify-start font-normal`,children:[(0,s.jsx)(a.PlusIcon,{size:14,className:`-ms-2 opacity-60`,"aria-hidden":`true`}),`Thêm mới`]})})]})]}),(0,s.jsx)(r.CommandEmpty,{children:`Không có kết quả`})]})})]}),!!u&&(0,s.jsx)(n.FormDescription,{children:u})]})});exports.ComboboxField=c;
2
2
  //# sourceMappingURL=combobox-field.cjs.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime1 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/combobox-field.d.ts
@@ -22,7 +22,7 @@ declare const ComboboxField: <TFieldValues extends FieldValues = FieldValues>({
22
22
  description,
23
23
  options,
24
24
  onAddNewItem
25
- }: Props<TFieldValues>) => react_jsx_runtime1.JSX.Element;
25
+ }: Props<TFieldValues>) => react_jsx_runtime3.JSX.Element;
26
26
  //#endregion
27
27
  export { ComboboxField };
28
28
  //# sourceMappingURL=combobox-field.d.cts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime3 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/combobox-field.d.ts
@@ -22,7 +22,7 @@ declare const ComboboxField: <TFieldValues extends FieldValues = FieldValues>({
22
22
  description,
23
23
  options,
24
24
  onAddNewItem
25
- }: Props<TFieldValues>) => react_jsx_runtime3.JSX.Element;
25
+ }: Props<TFieldValues>) => react_jsx_runtime2.JSX.Element;
26
26
  //#endregion
27
27
  export { ComboboxField };
28
28
  //# sourceMappingURL=combobox-field.d.ts.map
@@ -1,2 +1,2 @@
1
- "use client";import{Button as e}from"../button-CvQQTSka.js";import"../label-CyaoUND0.js";import{FormControl as t,FormDescription as n,FormField as r,FormItem as i,FormLabel as a}from"../form-B0fOiANW.js";import"../dialog-DbI18XF9.js";import{Command as o,CommandEmpty as s,CommandGroup as c,CommandInput as l,CommandItem as u,CommandList as d,CommandSeparator as f}from"../command-DNfCX3KZ.js";import{Popover as p,PopoverContent as m,PopoverTrigger as h}from"../popover-CT9ZjjNA.js";import{ChevronDownIcon as g,PlusIcon as _}from"lucide-react";import{cn as v}from"@customafk/react-toolkit/utils";import{Fragment as y,jsx as b,jsxs as x}from"react/jsx-runtime";const S=({name:S,label:C=`Combobox`,placeholder:w=`Chọn một mục`,description:T,options:E,onAddNewItem:D})=>b(r,{name:S,render:({field:r})=>x(i,{className:`w-full`,children:[b(a,{children:C}),x(p,{modal:!0,children:[b(h,{asChild:!0,children:b(t,{children:x(e,{type:`button`,variant:`outline`,role:`combobox`,color:`muted`,className:v(`shadow-input flex justify-between rounded-md px-3`,`outline-border-weak font-normal`,`[&_div]:w-full`,`[&_div]:justify-between`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`),children:[r.value?b(`span`,{className:`flex min-w-0 items-center gap-2`,children:E?.find(({value:e})=>e===r.value)?.label}):b(`span`,{className:`text-text-positive-muted`,children:w}),b(g,{size:16,className:`text-text-positive-weak shrink-0`,"aria-hidden":`true`})]})})}),b(m,{className:`w-[var(--radix-popover-trigger-width)] p-0`,children:x(o,{className:`border-none`,children:[b(l,{placeholder:w??`Tìm kiếm`}),x(d,{children:[b(c,{className:`max-h-40 overflow-y-auto`,children:E?.map(({value:e,label:t})=>b(u,{value:t,onSelect:()=>r.onChange(e),children:t},e))}),D&&x(y,{children:[b(f,{}),b(c,{children:x(e,{type:`button`,variant:`ghost`,className:`w-full justify-start font-normal`,children:[b(_,{size:14,className:`-ms-2 opacity-60`,"aria-hidden":`true`}),`Thêm mới`]})})]})]}),b(s,{children:`Không có kết quả`})]})})]}),!!T&&b(n,{children:T})]})});export{S as ComboboxField};
1
+ "use client";import{Button as e}from"../button-CvQQTSka.js";import"../label-DdpIoRiG.js";import{FormControl as t,FormDescription as n,FormField as r,FormItem as i,FormLabel as a}from"../form-D-gDMD-J.js";import"../dialog-DbI18XF9.js";import{Command as o,CommandEmpty as s,CommandGroup as c,CommandInput as l,CommandItem as u,CommandList as d,CommandSeparator as f}from"../command-DKD5gHi_.js";import{Popover as p,PopoverContent as m,PopoverTrigger as h}from"../popover-DMt7GPSm.js";import{ChevronDownIcon as g,PlusIcon as _}from"lucide-react";import{cn as v}from"@customafk/react-toolkit/utils";import{Fragment as y,jsx as b,jsxs as x}from"react/jsx-runtime";const S=({name:S,label:C=`Combobox`,placeholder:w=`Chọn một mục`,description:T,options:E,onAddNewItem:D})=>b(r,{name:S,render:({field:r})=>x(i,{className:`w-full`,children:[b(a,{children:C}),x(p,{modal:!0,children:[b(h,{asChild:!0,children:b(t,{children:x(e,{type:`button`,variant:`outline`,role:`combobox`,color:`muted`,className:v(`shadow-input flex justify-between rounded-md px-3`,`outline-border-weak font-normal`,`[&_div]:w-full`,`[&_div]:justify-between`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`),children:[r.value?b(`span`,{className:`flex min-w-0 items-center gap-2`,children:E?.find(({value:e})=>e===r.value)?.label}):b(`span`,{className:`text-text-positive-muted`,children:w}),b(g,{size:16,className:`text-text-positive-weak shrink-0`,"aria-hidden":`true`})]})})}),b(m,{className:`w-[var(--radix-popover-trigger-width)] p-0`,children:x(o,{className:`border-none`,children:[b(l,{placeholder:w??`Tìm kiếm`}),x(d,{children:[b(c,{className:`max-h-40 overflow-y-auto`,children:E?.map(({value:e,label:t})=>b(u,{value:t,onSelect:()=>r.onChange(e),children:t},e))}),D&&x(y,{children:[b(f,{}),b(c,{children:x(e,{type:`button`,variant:`ghost`,className:`w-full justify-start font-normal`,children:[b(_,{size:14,className:`-ms-2 opacity-60`,"aria-hidden":`true`}),`Thêm mới`]})})]})]}),b(s,{children:`Không có kết quả`})]})})]}),!!T&&b(n,{children:T})]})});export{S as ComboboxField};
2
2
  //# sourceMappingURL=combobox-field.js.map
@@ -1,2 +1,2 @@
1
- "use client";const e=require(`../chunk-CUT6urMc.cjs`),t=require(`../button-119IIVCy.cjs`);require(`../label-BbuMrcie.cjs`);const n=require(`../form-DAwCSzSe.cjs`),r=require(`../popover-BsF6vWTX.cjs`),i=require(`../calendar-CrtbhiDy.cjs`),a=e.__toESM(require(`lucide-react`)),o=e.__toESM(require(`@customafk/react-toolkit/utils`)),s=e.__toESM(require(`react/jsx-runtime`)),c=e.__toESM(require(`@customafk/react-toolkit/date-fns`)),l=({name:e,label:l=`Date Field`,placeholder:u=`Select a date`,description:d=``,isShowErrorMsg:f=!1})=>(0,s.jsx)(n.FormField,{name:e,render:({field:e})=>(0,s.jsxs)(n.FormItem,{className:`w-full`,children:[(0,s.jsx)(n.FormLabel,{children:l}),(0,s.jsxs)(r.Popover,{modal:!0,children:[(0,s.jsx)(r.PopoverTrigger,{asChild:!0,children:(0,s.jsx)(n.FormControl,{children:(0,s.jsxs)(t.Button,{variant:`outline`,color:`muted`,className:(0,o.cn)(`w-full pl-3 text-left font-normal`,`outline-border-weak font-normal`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`,!e.value&&`text-text-positive-muted`),children:[e.value?(0,c.format)(e.value,`PPP`):(0,s.jsxs)(`span`,{children:[` `,u||`Pick a date`]}),(0,s.jsx)(a.CalendarIcon,{className:`text-text-positive-weak ml-auto size-4`})]})})}),(0,s.jsx)(r.PopoverContent,{className:`w-auto p-0`,align:`start`,children:(0,s.jsx)(i.Calendar,{mode:`single`,selected:e.value,onSelect:t=>{e.onChange(t?.toISOString())},captionLayout:`dropdown`,disabled:e=>e<new Date(`2022-01-01`)})})]}),!!d&&(0,s.jsx)(n.FormDescription,{children:d}),f&&(0,s.jsx)(n.FormMessage,{})]})});exports.DateField=l;
1
+ "use client";const e=require(`../chunk-CUT6urMc.cjs`),t=require(`../button-119IIVCy.cjs`);require(`../label-BBPPT0-L.cjs`);const n=require(`../form-CaxhlWxK.cjs`),r=require(`../popover-ByL6Igxn.cjs`),i=require(`../calendar-CUDdTiC-.cjs`),a=e.__toESM(require(`lucide-react`)),o=e.__toESM(require(`@customafk/react-toolkit/utils`)),s=e.__toESM(require(`react/jsx-runtime`)),c=e.__toESM(require(`@customafk/react-toolkit/date-fns`)),l=({name:e,label:l=`Date Field`,placeholder:u=`Select a date`,description:d=``,isShowErrorMsg:f=!1})=>(0,s.jsx)(n.FormField,{name:e,render:({field:e})=>(0,s.jsxs)(n.FormItem,{className:`w-full`,children:[(0,s.jsx)(n.FormLabel,{children:l}),(0,s.jsxs)(r.Popover,{modal:!0,children:[(0,s.jsx)(r.PopoverTrigger,{asChild:!0,children:(0,s.jsx)(n.FormControl,{children:(0,s.jsxs)(t.Button,{variant:`outline`,color:`muted`,className:(0,o.cn)(`w-full pl-3 text-left font-normal`,`outline-border-weak font-normal`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`,!e.value&&`text-text-positive-muted`),children:[e.value?(0,c.format)(e.value,`PPP`):(0,s.jsxs)(`span`,{children:[` `,u||`Pick a date`]}),(0,s.jsx)(a.CalendarIcon,{className:`text-text-positive-weak ml-auto size-4`})]})})}),(0,s.jsx)(r.PopoverContent,{className:`w-auto p-0`,align:`start`,children:(0,s.jsx)(i.Calendar,{mode:`single`,selected:e.value,onSelect:t=>{e.onChange(t?.toISOString())},captionLayout:`dropdown`,disabled:e=>e<new Date(`2022-01-01`)})})]}),!!d&&(0,s.jsx)(n.FormDescription,{children:d}),f&&(0,s.jsx)(n.FormMessage,{})]})});exports.DateField=l;
2
2
  //# sourceMappingURL=date-field.cjs.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime9 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/date-field.d.ts
@@ -16,7 +16,7 @@ declare const DateField: <TFieldValues extends FieldValues = FieldValues>({
16
16
  placeholder,
17
17
  description,
18
18
  isShowErrorMsg
19
- }: Props<TFieldValues>) => react_jsx_runtime9.JSX.Element;
19
+ }: Props<TFieldValues>) => react_jsx_runtime2.JSX.Element;
20
20
  //#endregion
21
21
  export { DateField };
22
22
  //# sourceMappingURL=date-field.d.cts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime5 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/date-field.d.ts
@@ -16,7 +16,7 @@ declare const DateField: <TFieldValues extends FieldValues = FieldValues>({
16
16
  placeholder,
17
17
  description,
18
18
  isShowErrorMsg
19
- }: Props<TFieldValues>) => react_jsx_runtime5.JSX.Element;
19
+ }: Props<TFieldValues>) => react_jsx_runtime3.JSX.Element;
20
20
  //#endregion
21
21
  export { DateField };
22
22
  //# sourceMappingURL=date-field.d.ts.map
@@ -1,2 +1,2 @@
1
- "use client";import{Button as e}from"../button-CvQQTSka.js";import"../label-CyaoUND0.js";import{FormControl as t,FormDescription as n,FormField as r,FormItem as i,FormLabel as a,FormMessage as o}from"../form-B0fOiANW.js";import{Popover as s,PopoverContent as c,PopoverTrigger as l}from"../popover-CT9ZjjNA.js";import{Calendar as u}from"../calendar-BgoGbit6.js";import{CalendarIcon as d}from"lucide-react";import{cn as f}from"@customafk/react-toolkit/utils";import{jsx as p,jsxs as m}from"react/jsx-runtime";import{format as h}from"@customafk/react-toolkit/date-fns";const g=({name:g,label:_=`Date Field`,placeholder:v=`Select a date`,description:y=``,isShowErrorMsg:b=!1})=>p(r,{name:g,render:({field:r})=>m(i,{className:`w-full`,children:[p(a,{children:_}),m(s,{modal:!0,children:[p(l,{asChild:!0,children:p(t,{children:m(e,{variant:`outline`,color:`muted`,className:f(`w-full pl-3 text-left font-normal`,`outline-border-weak font-normal`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`,!r.value&&`text-text-positive-muted`),children:[r.value?h(r.value,`PPP`):m(`span`,{children:[` `,v||`Pick a date`]}),p(d,{className:`text-text-positive-weak ml-auto size-4`})]})})}),p(c,{className:`w-auto p-0`,align:`start`,children:p(u,{mode:`single`,selected:r.value,onSelect:e=>{r.onChange(e?.toISOString())},captionLayout:`dropdown`,disabled:e=>e<new Date(`2022-01-01`)})})]}),!!y&&p(n,{children:y}),b&&p(o,{})]})});export{g as DateField};
1
+ "use client";import{Button as e}from"../button-CvQQTSka.js";import"../label-DdpIoRiG.js";import{FormControl as t,FormDescription as n,FormField as r,FormItem as i,FormLabel as a,FormMessage as o}from"../form-D-gDMD-J.js";import{Popover as s,PopoverContent as c,PopoverTrigger as l}from"../popover-DMt7GPSm.js";import{Calendar as u}from"../calendar-BZRNZdsJ.js";import{CalendarIcon as d}from"lucide-react";import{cn as f}from"@customafk/react-toolkit/utils";import{jsx as p,jsxs as m}from"react/jsx-runtime";import{format as h}from"@customafk/react-toolkit/date-fns";const g=({name:g,label:_=`Date Field`,placeholder:v=`Select a date`,description:y=``,isShowErrorMsg:b=!1})=>p(r,{name:g,render:({field:r})=>m(i,{className:`w-full`,children:[p(a,{children:_}),m(s,{modal:!0,children:[p(l,{asChild:!0,children:p(t,{children:m(e,{variant:`outline`,color:`muted`,className:f(`w-full pl-3 text-left font-normal`,`outline-border-weak font-normal`,`hover:outline-border`,`data-[state=open]:text-text-positive-muted`,`data-[state=open]:outline-1`,`data-[state=open]:outline-primary-strong`,`data-[state=open]:ring-primary-weak`,`data-[state=open]:ring-4`,`focus:border-primary-strong`,`focus:ring-4`,`focus:ring-primary-weak`,`focus:outline-1`,`focus:outline-primary-strong`,!r.value&&`text-text-positive-muted`),children:[r.value?h(r.value,`PPP`):m(`span`,{children:[` `,v||`Pick a date`]}),p(d,{className:`text-text-positive-weak ml-auto size-4`})]})})}),p(c,{className:`w-auto p-0`,align:`start`,children:p(u,{mode:`single`,selected:r.value,onSelect:e=>{r.onChange(e?.toISOString())},captionLayout:`dropdown`,disabled:e=>e<new Date(`2022-01-01`)})})]}),!!y&&p(n,{children:y}),b&&p(o,{})]})});export{g as DateField};
2
2
  //# sourceMappingURL=date-field.js.map
@@ -1 +1 @@
1
- require(`../button-119IIVCy.cjs`),require(`../alert-dialog-7AEaiJxA.cjs`),require(`../error-dialog-COyyui94.cjs`),require(`../label-BbuMrcie.cjs`),require(`../form-DAwCSzSe.cjs`);const e=require(`../form-wrapper-D0-p7R15.cjs`);exports.FormWrapper=e.FormWrapper;
1
+ require(`../button-119IIVCy.cjs`),require(`../alert-dialog-lwTxSl-r.cjs`),require(`../error-dialog-BkCaUR7F.cjs`),require(`../label-BBPPT0-L.cjs`),require(`../form-CaxhlWxK.cjs`);const e=require(`../form-wrapper-BUkoh-c7.cjs`);exports.FormWrapper=e.FormWrapper;
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime8 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime63 from "react/jsx-runtime";
2
2
  import { FieldValues, FormState, SubmitErrorHandler, UseFormProps } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/form-wrapper.d.ts
@@ -18,7 +18,7 @@ declare const FormWrapper: <TFieldValues extends FieldValues = FieldValues>({
18
18
  onError,
19
19
  onSubcribe,
20
20
  children
21
- }: React.PropsWithChildren<Props<TFieldValues>>) => react_jsx_runtime8.JSX.Element;
21
+ }: React.PropsWithChildren<Props<TFieldValues>>) => react_jsx_runtime63.JSX.Element;
22
22
  //#endregion
23
23
  export { FormWrapper };
24
24
  //# sourceMappingURL=form-wrapper.d.cts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime4 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime7 from "react/jsx-runtime";
2
2
  import { FieldValues, FormState, SubmitErrorHandler, UseFormProps } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/form-wrapper.d.ts
@@ -18,7 +18,7 @@ declare const FormWrapper: <TFieldValues extends FieldValues = FieldValues>({
18
18
  onError,
19
19
  onSubcribe,
20
20
  children
21
- }: React.PropsWithChildren<Props<TFieldValues>>) => react_jsx_runtime4.JSX.Element;
21
+ }: React.PropsWithChildren<Props<TFieldValues>>) => react_jsx_runtime7.JSX.Element;
22
22
  //#endregion
23
23
  export { FormWrapper };
24
24
  //# sourceMappingURL=form-wrapper.d.ts.map
@@ -1 +1 @@
1
- import"../button-CvQQTSka.js";import"../alert-dialog-B8Whrlfq.js";import"../error-dialog-YlSsQqiT.js";import"../label-CyaoUND0.js";import"../form-B0fOiANW.js";import{FormWrapper as e}from"../form-wrapper-C4OO_eLu.js";export{e as FormWrapper};
1
+ import"../button-CvQQTSka.js";import"../alert-dialog-BOMy-TmT.js";import"../error-dialog-D3tnycqF.js";import"../label-DdpIoRiG.js";import"../form-D-gDMD-J.js";import{FormWrapper as e}from"../form-wrapper-BbScjpBv.js";export{e as FormWrapper};
@@ -1,2 +1,2 @@
1
- "use client";const e=require(`../chunk-CUT6urMc.cjs`);require(`../button-119IIVCy.cjs`),require(`../label-BbuMrcie.cjs`);const t=require(`../form-DAwCSzSe.cjs`);require(`../dialog-CGrbU7PO.cjs`),require(`../command-COUM-XfY.cjs`);const n=require(`../multi-select-C8kzA628.cjs`),r=e.__toESM(require(`react/jsx-runtime`)),i=({name:e,label:i=`Multi Select Field`,isShowLabel:a=!0,isShowErrorMsg:o,placeholder:s=`Select options`,description:c=``,options:l=[],onAdd:u})=>(0,r.jsx)(t.FormField,{name:e,render:({field:{value:e,onChange:d}})=>{let f=l.filter(t=>e?.includes(t.value)),p=e=>{let t=e.map(e=>e.value);d(t)};return(0,r.jsxs)(t.FormItem,{className:`w-full gap-0`,children:[a&&(0,r.jsx)(t.FormLabel,{children:i}),(0,r.jsx)(t.FormControl,{children:(0,r.jsx)(n.MultipleSelector,{placeholder:s,emptyIndicator:`No options available`,value:f,options:l,onChange:p,onAddNewItem:u})}),!!c&&(0,r.jsx)(t.FormDescription,{children:c}),o&&(0,r.jsx)(t.FormMessage,{})]})}});exports.MultiSelectField=i;
1
+ "use client";const e=require(`../chunk-CUT6urMc.cjs`);require(`../button-119IIVCy.cjs`),require(`../label-BBPPT0-L.cjs`);const t=require(`../form-CaxhlWxK.cjs`);require(`../dialog-CGrbU7PO.cjs`),require(`../command-B9nlrxXh.cjs`);const n=require(`../multi-select-BAXHYtlU.cjs`),r=e.__toESM(require(`react/jsx-runtime`)),i=({name:e,label:i=`Multi Select Field`,isShowLabel:a=!0,isShowErrorMsg:o,placeholder:s=`Select options`,description:c=``,options:l=[],onAdd:u})=>(0,r.jsx)(t.FormField,{name:e,render:({field:{value:e,onChange:d}})=>{let f=l.filter(t=>e?.includes(t.value)),p=e=>{let t=e.map(e=>e.value);d(t)};return(0,r.jsxs)(t.FormItem,{className:`w-full gap-0`,children:[a&&(0,r.jsx)(t.FormLabel,{children:i}),(0,r.jsx)(t.FormControl,{children:(0,r.jsx)(n.MultipleSelector,{placeholder:s,emptyIndicator:`No options available`,value:f,options:l,onChange:p,onAddNewItem:u})}),!!c&&(0,r.jsx)(t.FormDescription,{children:c}),o&&(0,r.jsx)(t.FormMessage,{})]})}});exports.MultiSelectField=i;
2
2
  //# sourceMappingURL=multi-select-field.cjs.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime15 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime5 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/multi-select-field.d.ts
@@ -24,7 +24,7 @@ declare const MultiSelectField: <TFieldValues extends FieldValues = FieldValues>
24
24
  description,
25
25
  options,
26
26
  onAdd
27
- }: Props<TFieldValues>) => react_jsx_runtime15.JSX.Element;
27
+ }: Props<TFieldValues>) => react_jsx_runtime5.JSX.Element;
28
28
  //#endregion
29
29
  export { MultiSelectField };
30
30
  //# sourceMappingURL=multi-select-field.d.cts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime7 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime8 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/multi-select-field.d.ts
@@ -24,7 +24,7 @@ declare const MultiSelectField: <TFieldValues extends FieldValues = FieldValues>
24
24
  description,
25
25
  options,
26
26
  onAdd
27
- }: Props<TFieldValues>) => react_jsx_runtime7.JSX.Element;
27
+ }: Props<TFieldValues>) => react_jsx_runtime8.JSX.Element;
28
28
  //#endregion
29
29
  export { MultiSelectField };
30
30
  //# sourceMappingURL=multi-select-field.d.ts.map
@@ -1,2 +1,2 @@
1
- "use client";import"../button-CvQQTSka.js";import"../label-CyaoUND0.js";import{FormControl as e,FormDescription as t,FormField as n,FormItem as r,FormLabel as i,FormMessage as a}from"../form-B0fOiANW.js";import"../dialog-DbI18XF9.js";import"../command-DNfCX3KZ.js";import{MultipleSelector as o}from"../multi-select-CaBcDGi6.js";import{jsx as s,jsxs as c}from"react/jsx-runtime";const l=({name:l,label:u=`Multi Select Field`,isShowLabel:d=!0,isShowErrorMsg:f,placeholder:p=`Select options`,description:m=``,options:h=[],onAdd:g})=>s(n,{name:l,render:({field:{value:n,onChange:l}})=>{let _=h.filter(e=>n?.includes(e.value)),v=e=>{let t=e.map(e=>e.value);l(t)};return c(r,{className:`w-full gap-0`,children:[d&&s(i,{children:u}),s(e,{children:s(o,{placeholder:p,emptyIndicator:`No options available`,value:_,options:h,onChange:v,onAddNewItem:g})}),!!m&&s(t,{children:m}),f&&s(a,{})]})}});export{l as MultiSelectField};
1
+ "use client";import"../button-CvQQTSka.js";import"../label-DdpIoRiG.js";import{FormControl as e,FormDescription as t,FormField as n,FormItem as r,FormLabel as i,FormMessage as a}from"../form-D-gDMD-J.js";import"../dialog-DbI18XF9.js";import"../command-DKD5gHi_.js";import{MultipleSelector as o}from"../multi-select-oXuLHx0A.js";import{jsx as s,jsxs as c}from"react/jsx-runtime";const l=({name:l,label:u=`Multi Select Field`,isShowLabel:d=!0,isShowErrorMsg:f,placeholder:p=`Select options`,description:m=``,options:h=[],onAdd:g})=>s(n,{name:l,render:({field:{value:n,onChange:l}})=>{let _=h.filter(e=>n?.includes(e.value)),v=e=>{let t=e.map(e=>e.value);l(t)};return c(r,{className:`w-full gap-0`,children:[d&&s(i,{children:u}),s(e,{children:s(o,{placeholder:p,emptyIndicator:`No options available`,value:_,options:h,onChange:v,onAddNewItem:g})}),!!m&&s(t,{children:m}),f&&s(a,{})]})}});export{l as MultiSelectField};
2
2
  //# sourceMappingURL=multi-select-field.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../chunk-CUT6urMc.cjs`);require(`../label-BbuMrcie.cjs`);const t=require(`../form-DAwCSzSe.cjs`),n=require(`../input-Bt7b3-NW.cjs`),r=e.__toESM(require(`@customafk/react-toolkit/utils`)),i=e.__toESM(require(`react/jsx-runtime`)),a=e.__toESM(require(`react`)),o=e.__toESM(require(`react-hook-form`)),s=e=>e?/^-?\d*\.?\d*$/:/^\d*\.?\d*$/,c=e=>Number(e).toLocaleString(),l=({disabled:e=!1,readonly:t=!1,allowNegative:o=!1,numberAfterDecimalPoint:l=2,roundingRule:u=`none`,value:d=``,unitText:f,decimal:p,placeholder:m,precision:h,onChange:g,onValueChange:_,onBlur:v,...y})=>{let b=a.default.useRef(null),x=a.default.useRef(null),[S,C]=a.default.useState(d.toString()),w=p?.[1]??l,T=p&&p[0]-p[1],E=a.default.useMemo(()=>s(o),[o]),D=a.default.useCallback(e=>{if(!w&&e.includes(`.`))return!1;let t=e.split(`.`)[1];return!t||t.length<=w},[w]),O=a.default.useCallback(e=>{if(!p||e===`-`)return!0;let[t,n=``]=e.split(`.`);return n.length<=p[1]&&(t.startsWith(`-`)?t.length-1:t.length)<=T},[p,T]),k=a.default.useCallback((e,t)=>{if(u===`none`)return e;let n=Math.pow(10,t),r=e*n;switch(u){case`up`:return Math.ceil(r)/n;case`down`:return Math.floor(r)/n;case`nearest`:return r%1<.1?Math.floor(r)/n:r%1>=.59?Math.ceil(r)/n:(Math.floor(r)+.5)/n;default:return e}},[u]),A=a.default.useCallback(e=>!l&&e.includes(`.`)||e.split(`.`)[1]?.length>l,[l]),j=a.default.useCallback(e=>{if(e===`0`)return`0`;if(!Number(e))return``;let t=parseFloat(e),n=Math.min(w-1,h||0),r=k(t,n).toString(),[i,a=``]=r.split(`.`),o=c(i);return a?`${o}.${a}`:o},[k,w,h]),M=a.default.useCallback(e=>{if(!p||e===`-`)return!0;let[t,n=``]=e.split(`.`),r=t.startsWith(`-`)?t.length-1:t.length,i=p[0]-p[1];return n.length<=p[1]&&r<=i},[p]),N=a.default.useCallback(e=>{g?.(e);let{value:t}=e.target;if(!t){_?.(void 0),C(``);return}let n=t===`0`,r=t===`-`&&o;if(n||r){_?.(0),C(t);return}let i=E.test(t)&&O(t)&&(p||D(t));if(!i)return;let a=parseFloat(t)||0;_?.(a),C(t)},[o,p,D,O,g,_,E]),P=a.default.useCallback(()=>{t||C(e=>e.replace(/,/g,``))},[t]),F=a.default.useCallback(()=>{t||(v?.(),C(e=>j(e)))},[t,v,j]);return a.default.useEffect(()=>{let e=document.activeElement===x.current;if(!d||!E.test(d.toString())||!M(d.toString())||!p&&A(d.toString())){C(``);return}C(t=>t===`-`?`-`:t?e?d.toString():j(d.toString()):``)},[p,j,d,A,M,E]),a.default.useEffect(()=>{if(!b.current||!x.current||!f)return;let e=b.current.offsetWidth;x.current.style.setProperty(`padding-right`,`${(e+10)/16}rem`)},[e,f]),(0,i.jsxs)(`div`,{className:`relative`,children:[(0,i.jsx)(n.Input,{...y,ref:x,value:S||(t?`0`:``),placeholder:m,disabled:e,readOnly:t,className:(0,r.cn)(`font-number text-end`,t&&`bg-muted text-muted-foreground`),onChange:N,onFocus:P,onBlur:F}),f&&(0,i.jsx)(`span`,{ref:b,className:`text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm`,children:f})]})},u=({name:e,label:n=`Number Field`,placeholder:r=`0`,isShowErrorMsg:a=!1,isShowCount:s=!1,unitText:c=``,description:u=``,onValueChange:d})=>{let f=(0,o.useWatch)({name:e});return(0,i.jsx)(t.FormField,{name:e,render:({field:{onChange:e,...o}})=>(0,i.jsxs)(t.FormItem,{className:`w-full gap-0`,children:[(0,i.jsx)(t.FormLabel,{children:n}),(0,i.jsx)(t.FormControl,{children:(0,i.jsx)(l,{...o,placeholder:r,className:`w-full`,unitText:c,onValueChange:t=>{e(t),d?.(t)}})}),s&&(0,i.jsxs)(`div`,{className:`text-muted-foreground text-end text-xs`,children:[f?.length??0,` characters`]}),!!u&&(0,i.jsx)(t.FormDescription,{children:u}),a&&(0,i.jsx)(t.FormMessage,{})]})})};exports.NumberField=u;
1
+ const e=require(`../chunk-CUT6urMc.cjs`);require(`../label-BBPPT0-L.cjs`);const t=require(`../form-CaxhlWxK.cjs`),n=require(`../input-ERPHY3v4.cjs`),r=e.__toESM(require(`@customafk/react-toolkit/utils`)),i=e.__toESM(require(`react/jsx-runtime`)),a=e.__toESM(require(`react`)),o=e.__toESM(require(`react-hook-form`)),s=e=>e?/^-?\d*\.?\d*$/:/^\d*\.?\d*$/,c=e=>Number(e).toLocaleString(),l=({disabled:e=!1,readonly:t=!1,allowNegative:o=!1,numberAfterDecimalPoint:l=2,roundingRule:u=`none`,value:d=``,unitText:f,decimal:p,placeholder:m,precision:h,onChange:g,onValueChange:_,onBlur:v,...y})=>{let b=(0,a.useRef)(null),x=(0,a.useRef)(null),[S,C]=(0,a.useState)(d.toString()),w=p?.[1]??l,T=p&&p[0]-p[1],E=(0,a.useMemo)(()=>s(o),[o]),D=(0,a.useCallback)(e=>{if(!w&&e.includes(`.`))return!1;let t=e.split(`.`)[1];return!t||t.length<=w},[w]),O=(0,a.useCallback)(e=>{if(!p||e===`-`)return!0;let[t,n=``]=e.split(`.`);return n.length<=p[1]&&(t.startsWith(`-`)?t.length-1:t.length)<=T},[p,T]),k=(0,a.useCallback)((e,t)=>{if(u===`none`)return e;let n=Math.pow(10,t),r=e*n;switch(u){case`up`:return Math.ceil(r)/n;case`down`:return Math.floor(r)/n;case`nearest`:return r%1<.1?Math.floor(r)/n:r%1>=.59?Math.ceil(r)/n:(Math.floor(r)+.5)/n;default:return e}},[u]),A=(0,a.useCallback)(e=>!l&&e.includes(`.`)||e.split(`.`)[1]?.length>l,[l]),j=(0,a.useCallback)(e=>{if(e===`0`)return`0`;if(!Number(e))return``;let t=parseFloat(e),n=Math.min(w-1,h||0),r=k(t,n).toString(),[i,a=``]=r.split(`.`),o=c(i);return a?`${o}.${a}`:o},[k,w,h]),M=(0,a.useCallback)(e=>{if(!p||e===`-`)return!0;let[t,n=``]=e.split(`.`),r=t.startsWith(`-`)?t.length-1:t.length,i=p[0]-p[1];return n.length<=p[1]&&r<=i},[p]),N=(0,a.useCallback)(e=>{g?.(e);let{value:t}=e.target;if(!t){_?.(void 0),C(``);return}let n=t===`0`,r=t===`-`&&o;if(n||r){_?.(0),C(t);return}let i=E.test(t)&&O(t)&&(p||D(t));if(!i)return;let a=parseFloat(t)||0;_?.(a),C(t)},[o,p,D,O,g,_,E]),P=(0,a.useCallback)(()=>{t||C(e=>e.replace(/,/g,``))},[t]),F=(0,a.useCallback)(()=>{t||(v?.(),C(e=>j(e)))},[t,v,j]);return(0,a.useEffect)(()=>{let e=document.activeElement===x.current;if(!d||!E.test(d.toString())||!M(d.toString())||!p&&A(d.toString())){C(``);return}C(t=>t===`-`?`-`:t?e?d.toString():j(d.toString()):``)},[p,j,d,A,M,E]),(0,a.useEffect)(()=>{if(!b.current||!x.current||!f)return;let e=b.current.offsetWidth;x.current.style.setProperty(`padding-right`,`${(e+10)/16}rem`)},[e,f]),(0,i.jsxs)(`div`,{className:`relative`,children:[(0,i.jsx)(n.Input,{...y,ref:x,value:S||(t?`0`:``),placeholder:m,disabled:e,readOnly:t,className:(0,r.cn)(`font-number text-end`,t&&`bg-muted text-muted-foreground`),onChange:N,onFocus:P,onBlur:F}),f&&(0,i.jsx)(`span`,{ref:b,className:`text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm`,children:f})]})},u=({name:e,label:n=`Number Field`,placeholder:r=`0`,isShowErrorMsg:a=!1,isShowCount:s=!1,unitText:c=``,description:u=``,onValueChange:d})=>{let f=(0,o.useWatch)({name:e});return(0,i.jsx)(t.FormField,{name:e,render:({field:{onChange:e,...o}})=>(0,i.jsxs)(t.FormItem,{className:`w-full gap-0`,children:[(0,i.jsx)(t.FormLabel,{children:n}),(0,i.jsx)(t.FormControl,{children:(0,i.jsx)(l,{...o,placeholder:r,className:`w-full`,unitText:c,onValueChange:t=>{e(t),d?.(t)}})}),s&&(0,i.jsxs)(`div`,{className:`text-muted-foreground text-end text-xs`,children:[f?.length??0,` characters`]}),!!u&&(0,i.jsx)(t.FormDescription,{children:u}),a&&(0,i.jsx)(t.FormMessage,{})]})})};exports.NumberField=u;
2
2
  //# sourceMappingURL=number-field.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"number-field.cjs","names":["NumberInput: React.FC<IProps>","React","value","precision","maxIntegerLength","Input","FormField","FormItem","FormLabel","FormControl","FormDescription","FormMessage"],"sources":["../../packages/components/ui/inputs/number-input.tsx","../../packages/components/forms/number-field.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\nimport { cn } from '@customafk/react-toolkit/utils'\n\nimport { Input } from '../input'\n\nconst createValidationRegex = (allowNegative: boolean): RegExp => {\n return allowNegative ? /^-?\\d*\\.?\\d*$/ : /^\\d*\\.?\\d*$/\n}\n\nconst formatNumberWithCommas = (num: number | string): string => {\n return Number(num).toLocaleString()\n}\n\ninterface IProps extends React.HTMLAttributes<HTMLInputElement> {\n /**\n * Description: Value for the text field\n *\n * Default: ''\n *\n * Usage: Value for the text field\n */\n value?: string | number\n /**\n * Description: Disabled state of the text field\n *\n * Default: `false`\n *\n * Usage: Disabled state of the text field\n *\n * Note: If true, the text field will be disabled\n */\n disabled?: boolean\n /**\n * Description: Readonly state of the text field\n *\n * Default: `false`\n *\n * Usage: Readonly state of the text field\n */\n readonly?: boolean\n /**\n * Description: Allow negative value for the text field\n *\n * Default: `false`\n *\n * Usage: Allow negative value for the text field\n */\n allowNegative?: boolean\n /**\n * Description: Decimal point for the text field\n *\n * Default: `undefined`\n *\n * Usage: Ex: [12,3] => console.log(2323.23) // True\n *\n * Note: IF use this prop, `numberAfterDecimalPoint` will be ignored\n */\n decimal?: [number, number]\n /**\n * Description: Rounding rule for the text field\n *\n * Default: `nearest`\n *\n * Usage: Rounding rule for the text field\n */\n roundingRule?: 'up' | 'down' | 'nearest' | 'none'\n /**\n * Description: Number of digits after the decimal point\n *\n * Default: `2`\n *\n * Usage: Number of digits after the decimal point\n */\n numberAfterDecimalPoint?: number\n /**\n * Description: Placeholder for the text field\n *\n * Default: ''\n *\n * Usage: Placeholder for the text field\n */\n placeholder?: string\n /**\n * Description: Unit text for the text field\n *\n * Default: ''\n *\n * E.g. 'kg', 'm', 'USD'...\n */\n unitText?: string\n /**\n * Description: Invalid state of the text field\n *\n * Default: `false`\n *\n * Usage: Invalid state of the text field\n */\n invalid?: boolean\n /**\n * Description: Precision for the text field\n *\n * Default: `undefined`\n * E.g.\n * - 2.13 => 2.1 when precision is 1\n * - 2.134 => 2.13 when precision is 2\n */\n precision?: number\n /**\n * Description: Callback function for the value change\n * Usage: Callback function for the value change\n */\n onValueChange?: (value?: number) => void\n onBlur?: () => void\n}\n/**\n * ## Unit Text Field Component\n *\n * **Description**: This component is to display common text field with unit\n *\n * **Usage**: Text field with unit example: 1000 (kg), 100 (m), 1000 (USD)...\n */\nexport const NumberInput: React.FC<IProps> = ({\n disabled = false,\n readonly = false,\n allowNegative = false,\n numberAfterDecimalPoint = 2,\n roundingRule = 'none',\n value: initialValue = '',\n unitText,\n decimal,\n placeholder,\n precision,\n onChange,\n onValueChange,\n onBlur,\n ...props\n}) => {\n const _unitRef = React.useRef<HTMLSpanElement>(null)\n const _inputRef = React.useRef<HTMLInputElement>(null)\n\n const [value, setValue] = React.useState<string>(initialValue.toString())\n\n // Memoized values for validation and formatting\n const maxDecimalPlaces = decimal?.[1] ?? numberAfterDecimalPoint\n const maxIntegerLength = decimal && decimal[0] - decimal[1]\n const validationRegex = React.useMemo(() => createValidationRegex(allowNegative), [allowNegative])\n\n // Validation functions\n const isValidDecimalLength = React.useCallback(\n (value: string): boolean => {\n if (!maxDecimalPlaces && value.includes('.')) return false\n const decimalPart = value.split('.')[1]\n return !decimalPart || decimalPart.length <= maxDecimalPlaces\n },\n [maxDecimalPlaces],\n )\n const isValidFormat = React.useCallback(\n (value: string): boolean => {\n if (!decimal || value === '-') return true\n const [integerPart, decimalPart = ''] = value.split('.')\n\n return decimalPart.length <= decimal[1] && (integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length) <= maxIntegerLength!\n },\n [decimal, maxIntegerLength],\n )\n const customRoundedValue = React.useCallback(\n (value: number, precision: number) => {\n if (roundingRule === 'none') return value\n\n const factor = Math.pow(10, precision)\n const scaledValue = value * factor\n\n switch (roundingRule) {\n case 'up':\n return Math.ceil(scaledValue) / factor\n case 'down':\n return Math.floor(scaledValue) / factor\n case 'nearest': {\n if (scaledValue % 1 < 0.1) return Math.floor(scaledValue) / factor\n if (scaledValue % 1 >= 0.59) return Math.ceil(scaledValue) / factor\n return (Math.floor(scaledValue) + 0.5) / factor\n }\n default:\n return value\n }\n },\n [roundingRule],\n )\n const isDecimalPointGreaterThanLimit = React.useCallback(\n (value: string) => (!numberAfterDecimalPoint && value.includes('.')) || value.split('.')[1]?.length > numberAfterDecimalPoint,\n [numberAfterDecimalPoint],\n )\n const formattedValue = React.useCallback(\n (val: string) => {\n if (val === '0') return '0'\n if (!Number(val)) return ''\n\n const numValue = parseFloat(val)\n const effectivePrecision = Math.min(maxDecimalPlaces - 1, precision || 0)\n const roundedValue = customRoundedValue(numValue, effectivePrecision).toString()\n const [integerPart, decimalPart = ''] = roundedValue.split('.')\n const formattedInteger = formatNumberWithCommas(integerPart)\n return decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger\n },\n [customRoundedValue, maxDecimalPlaces, precision],\n )\n // Validate decimal point is less than or equal to the limit\n const validateDecimalPoint = React.useCallback(\n (value: string) => {\n if (!decimal || value === '-') return true\n\n const [integerPart, decimalPart = ''] = value.split('.')\n const integerLength = integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length\n const maxIntegerLength = decimal[0] - decimal[1]\n\n return decimalPart.length <= decimal[1] && integerLength <= maxIntegerLength\n },\n [decimal],\n )\n const handleChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n // Don't prevent default behavior of input change\n onChange?.(e)\n\n // Custom event handler for value change\n const { value: inputValue } = e.target\n\n // Handle empty input\n if (!inputValue) {\n onValueChange?.(undefined)\n setValue('')\n return\n }\n\n // Handle zero and negative zero\n const isZero = inputValue === '0'\n const isNegativeZero = inputValue === '-' && allowNegative\n if (isZero || isNegativeZero) {\n onValueChange?.(0)\n setValue(inputValue)\n return\n }\n\n // Validate input format\n const isValid = validationRegex.test(inputValue) && isValidFormat(inputValue) && (decimal || isValidDecimalLength(inputValue))\n if (!isValid) return\n\n const numericValue = parseFloat(inputValue) || 0\n onValueChange?.(numericValue)\n setValue(inputValue)\n },\n [allowNegative, decimal, isValidDecimalLength, isValidFormat, onChange, onValueChange, validationRegex],\n )\n\n const handleFocus = React.useCallback(() => {\n if (readonly) return\n setValue((prev) => prev.replace(/,/g, '')) // Remove commas for easier editing\n }, [readonly])\n\n const handleBlur = React.useCallback(() => {\n if (readonly) return\n onBlur?.()\n setValue((prev) => formattedValue(prev))\n }, [readonly, onBlur, formattedValue])\n\n // Set initial value\n React.useEffect(() => {\n const isFocused = document.activeElement === _inputRef.current\n\n if (\n !initialValue ||\n !validationRegex.test(initialValue.toString()) ||\n !validateDecimalPoint(initialValue.toString()) ||\n (!decimal && isDecimalPointGreaterThanLimit(initialValue.toString()))\n ) {\n setValue('')\n return\n }\n\n setValue((prev) => {\n if (prev === '-') return '-'\n if (!prev) return ''\n return isFocused ? initialValue.toString() : formattedValue(initialValue.toString())\n })\n }, [decimal, formattedValue, initialValue, isDecimalPointGreaterThanLimit, validateDecimalPoint, validationRegex])\n\n // Set padding right for the input field\n React.useEffect(() => {\n if (!_unitRef.current || !_inputRef.current || !unitText) return\n const unitWidth = _unitRef.current.offsetWidth\n _inputRef.current.style.setProperty('padding-right', `${(unitWidth + 10) / 16}rem`)\n }, [disabled, unitText])\n\n return (\n <div className=\"relative\">\n <Input\n {...props}\n ref={_inputRef}\n value={value || (readonly ? '0' : '')}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readonly}\n className={cn('font-number text-end', readonly && 'bg-muted text-muted-foreground')}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n {unitText && (\n <span ref={_unitRef} className=\"text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm\">\n {unitText}\n </span>\n )}\n </div>\n )\n}\n","import { type FieldPath, type FieldValues, useWatch } from 'react-hook-form'\n\nimport { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '../ui/form'\nimport { NumberInput } from '../ui/inputs/number-input'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n name: FieldPath<TFieldValues>\n label?: string\n description?: string\n placeholder?: string\n unitText?: string\n isShowClearButton?: boolean\n isShowErrorMsg?: boolean\n isShowCount?: boolean\n onValueChange?: (value?: number) => void\n}\nexport const NumberField = <TFieldValues extends FieldValues = FieldValues>({\n name,\n label = 'Number Field',\n placeholder = '0',\n isShowErrorMsg = false,\n isShowCount = false,\n unitText = '',\n description = '',\n onValueChange,\n}: Props<TFieldValues>) => {\n const valueWatch = useWatch({ name })\n\n return (\n <FormField\n name={name}\n render={({ field: { onChange, ...field } }) => (\n <FormItem className=\"w-full gap-0\">\n <FormLabel>{label}</FormLabel>\n <FormControl>\n <NumberInput\n {...field}\n placeholder={placeholder}\n className=\"w-full\"\n unitText={unitText}\n onValueChange={(value) => {\n onChange(value)\n onValueChange?.(value)\n }}\n />\n </FormControl>\n {isShowCount && <div className=\"text-muted-foreground text-end text-xs\">{valueWatch?.length ?? 0} characters</div>}\n {!!description && <FormDescription>{description}</FormDescription>}\n {isShowErrorMsg && <FormMessage />}\n </FormItem>\n )}\n />\n )\n}\n"],"mappings":"4TAMM,EAAyB,GACtB,EAAgB,gBAAkB,cAGrC,EAA0B,GACvB,OAAO,GAAK,iBA+GRA,GAAiC,CAC5C,WAAW,GACX,WAAW,GACX,gBAAgB,GAChB,0BAA0B,EAC1B,eAAe,OACf,MAAO,EAAe,GACtB,WACA,UACA,cACA,YACA,WACA,gBACA,SACA,GAAG,KACC,CACJ,IAAM,EAAWC,EAAAA,QAAM,OAAwB,MACzC,EAAYA,EAAAA,QAAM,OAAyB,MAE3C,CAAC,EAAO,GAAYA,EAAAA,QAAM,SAAiB,EAAa,YAGxD,EAAmB,IAAU,IAAM,EACnC,EAAmB,GAAW,EAAQ,GAAK,EAAQ,GACnD,EAAkBA,EAAAA,QAAM,YAAc,EAAsB,GAAgB,CAAC,IAG7E,EAAuBA,EAAAA,QAAM,YAChC,GAA2B,CAC1B,GAAI,CAAC,GAAoBC,EAAM,SAAS,KAAM,MAAO,GACrD,IAAM,EAAcA,EAAM,MAAM,KAAK,GACrC,MAAO,CAAC,GAAe,EAAY,QAAU,GAE/C,CAAC,IAEG,EAAgBD,EAAAA,QAAM,Y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,MAAM,YAAY,gBAAiB,IAAI,EAAY,IAAM,GAAG,OAC7E,CAAC,EAAU,KAGZ,EAAA,EAAA,MAAC,MAAA,CAAI,UAAU,sBACb,EAAA,EAAA,KAACI,EAAAA,MAAAA,CACC,GAAI,EACJ,IAAK,EACL,MAAO,IAAU,EAAW,IAAM,IACrB,cACH,WACV,SAAU,EACV,WAAA,EAAA,EAAA,IAAc,uBAAwB,GAAY,kCAClD,SAAU,EACV,QAAS,EACT,OAAQ,IAET,IACC,EAAA,EAAA,KAAC,OAAA,CAAK,IAAK,EAAU,UAAU,uGAC5B,QCtSE,GAA+D,CAC1E,OACA,QAAQ,eACR,cAAc,IACd,iBAAiB,GACjB,cAAc,GACd,WAAW,GACX,cAAc,GACd,mBACyB,CACzB,IAAM,GAAA,EAAA,EAAA,UAAsB,CAAE,SAE9B,OACE,EAAA,EAAA,KAACC,EAAAA,UAAAA,CACO,OACN,QAAS,CAAE,MAAO,CAAE,WAAU,GAAG,OAC/B,EAAA,EAAA,MAACC,EAAAA,SAAAA,CAAS,UAAU,0BAClB,EAAA,EAAA,KAACC,EAAAA,UAAAA,CAAAA,SAAW,KACZ,EAAA,EAAA,KAACC,EAAAA,YAAAA,CAAAA,UACC,EAAA,EAAA,KAAC,EAAA,CACC,GAAI,EACS,cACb,UAAU,SACA,WACV,cAAgB,GAAU,CACxB,EAAS,GACT,IAAgB,QAIrB,IAAe,EAAA,EAAA,MAAC,MAAA,CAAI,UAAU,mDAA0C,GAAY,QAAU,EAAE,iBAChG,CAAC,CAAC,IAAe,EAAA,EAAA,KAACC,EAAAA,gBAAAA,CAAAA,SAAiB,IACnC,IAAkB,EAAA,EAAA,KAACC,EAAAA,YAAAA"}
1
+ {"version":3,"file":"number-field.cjs","names":["NumberInput: React.FC<IProps>","value","precision","maxIntegerLength","Input","FormField","FormItem","FormLabel","FormControl","FormDescription","FormMessage"],"sources":["../../packages/components/ui/inputs/number-input.tsx","../../packages/components/forms/number-field.tsx"],"sourcesContent":["'use client'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { cn } from '@customafk/react-toolkit/utils'\n\nimport { Input } from '../input'\n\nconst createValidationRegex = (allowNegative: boolean): RegExp => {\n return allowNegative ? /^-?\\d*\\.?\\d*$/ : /^\\d*\\.?\\d*$/\n}\n\nconst formatNumberWithCommas = (num: number | string): string => {\n return Number(num).toLocaleString()\n}\n\ninterface IProps extends React.HTMLAttributes<HTMLInputElement> {\n /**\n * Description: Value for the text field\n *\n * Default: ''\n *\n * Usage: Value for the text field\n */\n value?: string | number\n /**\n * Description: Disabled state of the text field\n *\n * Default: `false`\n *\n * Usage: Disabled state of the text field\n *\n * Note: If true, the text field will be disabled\n */\n disabled?: boolean\n /**\n * Description: Readonly state of the text field\n *\n * Default: `false`\n *\n * Usage: Readonly state of the text field\n */\n readonly?: boolean\n /**\n * Description: Allow negative value for the text field\n *\n * Default: `false`\n *\n * Usage: Allow negative value for the text field\n */\n allowNegative?: boolean\n /**\n * Description: Decimal point for the text field\n *\n * Default: `undefined`\n *\n * Usage: Ex: [12,3] => console.log(2323.23) // True\n *\n * Note: IF use this prop, `numberAfterDecimalPoint` will be ignored\n */\n decimal?: [number, number]\n /**\n * Description: Rounding rule for the text field\n *\n * Default: `nearest`\n *\n * Usage: Rounding rule for the text field\n */\n roundingRule?: 'up' | 'down' | 'nearest' | 'none'\n /**\n * Description: Number of digits after the decimal point\n *\n * Default: `2`\n *\n * Usage: Number of digits after the decimal point\n */\n numberAfterDecimalPoint?: number\n /**\n * Description: Placeholder for the text field\n *\n * Default: ''\n *\n * Usage: Placeholder for the text field\n */\n placeholder?: string\n /**\n * Description: Unit text for the text field\n *\n * Default: ''\n *\n * E.g. 'kg', 'm', 'USD'...\n */\n unitText?: string\n /**\n * Description: Invalid state of the text field\n *\n * Default: `false`\n *\n * Usage: Invalid state of the text field\n */\n invalid?: boolean\n /**\n * Description: Precision for the text field\n *\n * Default: `undefined`\n * E.g.\n * - 2.13 => 2.1 when precision is 1\n * - 2.134 => 2.13 when precision is 2\n */\n precision?: number\n /**\n * Description: Callback function for the value change\n * Usage: Callback function for the value change\n */\n onValueChange?: (value?: number) => void\n onBlur?: () => void\n}\n/**\n * ## Unit Text Field Component\n *\n * **Description**: This component is to display common text field with unit\n *\n * **Usage**: Text field with unit example: 1000 (kg), 100 (m), 1000 (USD)...\n */\nexport const NumberInput: React.FC<IProps> = ({\n disabled = false,\n readonly = false,\n allowNegative = false,\n numberAfterDecimalPoint = 2,\n roundingRule = 'none',\n value: initialValue = '',\n unitText,\n decimal,\n placeholder,\n precision,\n onChange,\n onValueChange,\n onBlur,\n ...props\n}) => {\n const _unitRef = useRef<HTMLSpanElement>(null)\n const _inputRef = useRef<HTMLInputElement>(null)\n\n const [value, setValue] = useState<string>(initialValue.toString())\n\n // Memoized values for validation and formatting\n const maxDecimalPlaces = decimal?.[1] ?? numberAfterDecimalPoint\n const maxIntegerLength = decimal && decimal[0] - decimal[1]\n const validationRegex = useMemo(() => createValidationRegex(allowNegative), [allowNegative])\n\n // Validation functions\n const isValidDecimalLength = useCallback(\n (value: string): boolean => {\n if (!maxDecimalPlaces && value.includes('.')) return false\n const decimalPart = value.split('.')[1]\n return !decimalPart || decimalPart.length <= maxDecimalPlaces\n },\n [maxDecimalPlaces],\n )\n const isValidFormat = useCallback(\n (value: string): boolean => {\n if (!decimal || value === '-') return true\n const [integerPart, decimalPart = ''] = value.split('.')\n\n return decimalPart.length <= decimal[1] && (integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length) <= maxIntegerLength!\n },\n [decimal, maxIntegerLength],\n )\n const customRoundedValue = useCallback(\n (value: number, precision: number) => {\n if (roundingRule === 'none') return value\n\n const factor = Math.pow(10, precision)\n const scaledValue = value * factor\n\n switch (roundingRule) {\n case 'up':\n return Math.ceil(scaledValue) / factor\n case 'down':\n return Math.floor(scaledValue) / factor\n case 'nearest': {\n if (scaledValue % 1 < 0.1) return Math.floor(scaledValue) / factor\n if (scaledValue % 1 >= 0.59) return Math.ceil(scaledValue) / factor\n return (Math.floor(scaledValue) + 0.5) / factor\n }\n default:\n return value\n }\n },\n [roundingRule],\n )\n const isDecimalPointGreaterThanLimit = useCallback(\n (value: string) => (!numberAfterDecimalPoint && value.includes('.')) || value.split('.')[1]?.length > numberAfterDecimalPoint,\n [numberAfterDecimalPoint],\n )\n const formattedValue = useCallback(\n (val: string) => {\n if (val === '0') return '0'\n if (!Number(val)) return ''\n\n const numValue = parseFloat(val)\n const effectivePrecision = Math.min(maxDecimalPlaces - 1, precision || 0)\n const roundedValue = customRoundedValue(numValue, effectivePrecision).toString()\n const [integerPart, decimalPart = ''] = roundedValue.split('.')\n const formattedInteger = formatNumberWithCommas(integerPart)\n return decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger\n },\n [customRoundedValue, maxDecimalPlaces, precision],\n )\n // Validate decimal point is less than or equal to the limit\n const validateDecimalPoint = useCallback(\n (value: string) => {\n if (!decimal || value === '-') return true\n\n const [integerPart, decimalPart = ''] = value.split('.')\n const integerLength = integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length\n const maxIntegerLength = decimal[0] - decimal[1]\n\n return decimalPart.length <= decimal[1] && integerLength <= maxIntegerLength\n },\n [decimal],\n )\n const handleChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n // Don't prevent default behavior of input change\n onChange?.(e)\n\n // Custom event handler for value change\n const { value: inputValue } = e.target\n\n // Handle empty input\n if (!inputValue) {\n onValueChange?.(undefined)\n setValue('')\n return\n }\n\n // Handle zero and negative zero\n const isZero = inputValue === '0'\n const isNegativeZero = inputValue === '-' && allowNegative\n if (isZero || isNegativeZero) {\n onValueChange?.(0)\n setValue(inputValue)\n return\n }\n\n // Validate input format\n const isValid = validationRegex.test(inputValue) && isValidFormat(inputValue) && (decimal || isValidDecimalLength(inputValue))\n if (!isValid) return\n\n const numericValue = parseFloat(inputValue) || 0\n onValueChange?.(numericValue)\n setValue(inputValue)\n },\n [allowNegative, decimal, isValidDecimalLength, isValidFormat, onChange, onValueChange, validationRegex],\n )\n\n const handleFocus = useCallback(() => {\n if (readonly) return\n setValue((prev) => prev.replace(/,/g, '')) // Remove commas for easier editing\n }, [readonly])\n\n const handleBlur = useCallback(() => {\n if (readonly) return\n onBlur?.()\n setValue((prev) => formattedValue(prev))\n }, [readonly, onBlur, formattedValue])\n\n // Set initial value\n useEffect(() => {\n const isFocused = document.activeElement === _inputRef.current\n\n if (\n !initialValue ||\n !validationRegex.test(initialValue.toString()) ||\n !validateDecimalPoint(initialValue.toString()) ||\n (!decimal && isDecimalPointGreaterThanLimit(initialValue.toString()))\n ) {\n setValue('')\n return\n }\n\n setValue((prev) => {\n if (prev === '-') return '-'\n if (!prev) return ''\n return isFocused ? initialValue.toString() : formattedValue(initialValue.toString())\n })\n }, [decimal, formattedValue, initialValue, isDecimalPointGreaterThanLimit, validateDecimalPoint, validationRegex])\n\n // Set padding right for the input field\n useEffect(() => {\n if (!_unitRef.current || !_inputRef.current || !unitText) return\n const unitWidth = _unitRef.current.offsetWidth\n _inputRef.current.style.setProperty('padding-right', `${(unitWidth + 10) / 16}rem`)\n }, [disabled, unitText])\n\n return (\n <div className=\"relative\">\n <Input\n {...props}\n ref={_inputRef}\n value={value || (readonly ? '0' : '')}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readonly}\n className={cn('font-number text-end', readonly && 'bg-muted text-muted-foreground')}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n {unitText && (\n <span ref={_unitRef} className=\"text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm\">\n {unitText}\n </span>\n )}\n </div>\n )\n}\n","import { type FieldPath, type FieldValues, useWatch } from 'react-hook-form'\n\nimport { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '../ui/form'\nimport { NumberInput } from '../ui/inputs/number-input'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n name: FieldPath<TFieldValues>\n label?: string\n description?: string\n placeholder?: string\n unitText?: string\n isShowClearButton?: boolean\n isShowErrorMsg?: boolean\n isShowCount?: boolean\n onValueChange?: (value?: number) => void\n}\nexport const NumberField = <TFieldValues extends FieldValues = FieldValues>({\n name,\n label = 'Number Field',\n placeholder = '0',\n isShowErrorMsg = false,\n isShowCount = false,\n unitText = '',\n description = '',\n onValueChange,\n}: Props<TFieldValues>) => {\n const valueWatch = useWatch({ name })\n\n return (\n <FormField\n name={name}\n render={({ field: { onChange, ...field } }) => (\n <FormItem className=\"w-full gap-0\">\n <FormLabel>{label}</FormLabel>\n <FormControl>\n <NumberInput\n {...field}\n placeholder={placeholder}\n className=\"w-full\"\n unitText={unitText}\n onValueChange={(value) => {\n onChange(value)\n onValueChange?.(value)\n }}\n />\n </FormControl>\n {isShowCount && <div className=\"text-muted-foreground text-end text-xs\">{valueWatch?.length ?? 0} characters</div>}\n {!!description && <FormDescription>{description}</FormDescription>}\n {isShowErrorMsg && <FormMessage />}\n </FormItem>\n )}\n />\n )\n}\n"],"mappings":"4TAMM,EAAyB,GACtB,EAAgB,gBAAkB,cAGrC,EAA0B,GACvB,OAAO,GAAK,iBA+GRA,GAAiC,CAC5C,WAAW,GACX,WAAW,GACX,gBAAgB,GAChB,0BAA0B,EAC1B,eAAe,OACf,MAAO,EAAe,GACtB,WACA,UACA,cACA,YACA,WACA,gBACA,SACA,GAAG,KACC,CACJ,IAAM,GAAA,EAAA,EAAA,QAAmC,MACnC,GAAA,EAAA,EAAA,QAAqC,MAErC,CAAC,EAAO,IAAA,EAAA,EAAA,UAA6B,EAAa,YAGlD,EAAmB,IAAU,IAAM,EACnC,EAAmB,GAAW,EAAQ,GAAK,EAAQ,GACnD,GAAA,EAAA,EAAA,aAAgC,EAAsB,GAAgB,CAAC,IAGvE,GAAA,EAAA,EAAA,aACH,GAA2B,CAC1B,GAAI,CAAC,GAAoBC,EAAM,SAAS,KAAM,MAAO,GACrD,IAAM,EAAcA,EAAM,MAAM,KAAK,GACrC,MAAO,CAAC,GAAe,EAAY,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AAU,QAAQ,MAAM,YAAY,gBAAiB,IAAI,EAAY,IAAM,GAAG,OAC7E,CAAC,EAAU,KAGZ,EAAA,EAAA,MAAC,MAAA,CAAI,UAAU,sBACb,EAAA,EAAA,KAACC,EAAAA,MAAAA,CACC,GAAI,EACJ,IAAK,EACL,MAAO,IAAU,EAAW,IAAM,IACrB,cACH,WACV,SAAU,EACV,WAAA,EAAA,EAAA,IAAc,uBAAwB,GAAY,kCAClD,SAAU,EACV,QAAS,EACT,OAAQ,IAET,IACC,EAAA,EAAA,KAAC,OAAA,CAAK,IAAK,EAAU,UAAU,uGAC5B,QCtSE,GAA+D,CAC1E,OACA,QAAQ,eACR,cAAc,IACd,iBAAiB,GACjB,cAAc,GACd,WAAW,GACX,cAAc,GACd,mBACyB,CACzB,IAAM,GAAA,EAAA,EAAA,UAAsB,CAAE,SAE9B,OACE,EAAA,EAAA,KAACC,EAAAA,UAAAA,CACO,OACN,QAAS,CAAE,MAAO,CAAE,WAAU,GAAG,OAC/B,EAAA,EAAA,MAACC,EAAAA,SAAAA,CAAS,UAAU,0BAClB,EAAA,EAAA,KAACC,EAAAA,UAAAA,CAAAA,SAAW,KACZ,EAAA,EAAA,KAACC,EAAAA,YAAAA,CAAAA,UACC,EAAA,EAAA,KAAC,EAAA,CACC,GAAI,EACS,cACb,UAAU,SACA,WACV,cAAgB,GAAU,CACxB,EAAS,GACT,IAAgB,QAIrB,IAAe,EAAA,EAAA,MAAC,MAAA,CAAI,UAAU,mDAA0C,GAAY,QAAU,EAAE,iBAChG,CAAC,CAAC,IAAe,EAAA,EAAA,KAACC,EAAAA,gBAAAA,CAAAA,SAAiB,IACnC,IAAkB,EAAA,EAAA,KAACC,EAAAA,YAAAA"}
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime17 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/number-field.d.ts
@@ -22,7 +22,7 @@ declare const NumberField: <TFieldValues extends FieldValues = FieldValues>({
22
22
  unitText,
23
23
  description,
24
24
  onValueChange
25
- }: Props<TFieldValues>) => react_jsx_runtime17.JSX.Element;
25
+ }: Props<TFieldValues>) => react_jsx_runtime1.JSX.Element;
26
26
  //#endregion
27
27
  export { NumberField };
28
28
  //# sourceMappingURL=number-field.d.cts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime13 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime5 from "react/jsx-runtime";
2
2
  import { FieldPath, FieldValues } from "react-hook-form";
3
3
 
4
4
  //#region packages/components/forms/number-field.d.ts
@@ -22,7 +22,7 @@ declare const NumberField: <TFieldValues extends FieldValues = FieldValues>({
22
22
  unitText,
23
23
  description,
24
24
  onValueChange
25
- }: Props<TFieldValues>) => react_jsx_runtime13.JSX.Element;
25
+ }: Props<TFieldValues>) => react_jsx_runtime5.JSX.Element;
26
26
  //#endregion
27
27
  export { NumberField };
28
28
  //# sourceMappingURL=number-field.d.ts.map
@@ -1,2 +1,2 @@
1
- import"../label-CyaoUND0.js";import{FormControl as e,FormDescription as t,FormField as n,FormItem as r,FormLabel as i,FormMessage as a}from"../form-B0fOiANW.js";import{Input as o}from"../input-i5Nm0R1X.js";import{cn as s}from"@customafk/react-toolkit/utils";import{jsx as c,jsxs as l}from"react/jsx-runtime";import u from"react";import{useWatch as d}from"react-hook-form";const f=e=>e?/^-?\d*\.?\d*$/:/^\d*\.?\d*$/,p=e=>Number(e).toLocaleString(),m=({disabled:e=!1,readonly:t=!1,allowNegative:n=!1,numberAfterDecimalPoint:r=2,roundingRule:i=`none`,value:a=``,unitText:d,decimal:m,placeholder:h,precision:g,onChange:_,onValueChange:v,onBlur:y,...b})=>{let x=u.useRef(null),S=u.useRef(null),[C,w]=u.useState(a.toString()),T=m?.[1]??r,E=m&&m[0]-m[1],D=u.useMemo(()=>f(n),[n]),O=u.useCallback(e=>{if(!T&&e.includes(`.`))return!1;let t=e.split(`.`)[1];return!t||t.length<=T},[T]),k=u.useCallback(e=>{if(!m||e===`-`)return!0;let[t,n=``]=e.split(`.`);return n.length<=m[1]&&(t.startsWith(`-`)?t.length-1:t.length)<=E},[m,E]),A=u.useCallback((e,t)=>{if(i===`none`)return e;let n=Math.pow(10,t),r=e*n;switch(i){case`up`:return Math.ceil(r)/n;case`down`:return Math.floor(r)/n;case`nearest`:return r%1<.1?Math.floor(r)/n:r%1>=.59?Math.ceil(r)/n:(Math.floor(r)+.5)/n;default:return e}},[i]),j=u.useCallback(e=>!r&&e.includes(`.`)||e.split(`.`)[1]?.length>r,[r]),M=u.useCallback(e=>{if(e===`0`)return`0`;if(!Number(e))return``;let t=parseFloat(e),n=Math.min(T-1,g||0),r=A(t,n).toString(),[i,a=``]=r.split(`.`),o=p(i);return a?`${o}.${a}`:o},[A,T,g]),N=u.useCallback(e=>{if(!m||e===`-`)return!0;let[t,n=``]=e.split(`.`),r=t.startsWith(`-`)?t.length-1:t.length,i=m[0]-m[1];return n.length<=m[1]&&r<=i},[m]),P=u.useCallback(e=>{_?.(e);let{value:t}=e.target;if(!t){v?.(void 0),w(``);return}let r=t===`0`,i=t===`-`&&n;if(r||i){v?.(0),w(t);return}let a=D.test(t)&&k(t)&&(m||O(t));if(!a)return;let o=parseFloat(t)||0;v?.(o),w(t)},[n,m,O,k,_,v,D]),F=u.useCallback(()=>{t||w(e=>e.replace(/,/g,``))},[t]),I=u.useCallback(()=>{t||(y?.(),w(e=>M(e)))},[t,y,M]);return u.useEffect(()=>{let e=document.activeElement===S.current;if(!a||!D.test(a.toString())||!N(a.toString())||!m&&j(a.toString())){w(``);return}w(t=>t===`-`?`-`:t?e?a.toString():M(a.toString()):``)},[m,M,a,j,N,D]),u.useEffect(()=>{if(!x.current||!S.current||!d)return;let e=x.current.offsetWidth;S.current.style.setProperty(`padding-right`,`${(e+10)/16}rem`)},[e,d]),l(`div`,{className:`relative`,children:[c(o,{...b,ref:S,value:C||(t?`0`:``),placeholder:h,disabled:e,readOnly:t,className:s(`font-number text-end`,t&&`bg-muted text-muted-foreground`),onChange:P,onFocus:F,onBlur:I}),d&&c(`span`,{ref:x,className:`text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm`,children:d})]})},h=({name:o,label:s=`Number Field`,placeholder:u=`0`,isShowErrorMsg:f=!1,isShowCount:p=!1,unitText:h=``,description:g=``,onValueChange:_})=>{let v=d({name:o});return c(n,{name:o,render:({field:{onChange:n,...o}})=>l(r,{className:`w-full gap-0`,children:[c(i,{children:s}),c(e,{children:c(m,{...o,placeholder:u,className:`w-full`,unitText:h,onValueChange:e=>{n(e),_?.(e)}})}),p&&l(`div`,{className:`text-muted-foreground text-end text-xs`,children:[v?.length??0,` characters`]}),!!g&&c(t,{children:g}),f&&c(a,{})]})})};export{h as NumberField};
1
+ import"../label-DdpIoRiG.js";import{FormControl as e,FormDescription as t,FormField as n,FormItem as r,FormLabel as i,FormMessage as a}from"../form-D-gDMD-J.js";import{Input as o}from"../input-BFZuwsER.js";import{cn as s}from"@customafk/react-toolkit/utils";import{jsx as c,jsxs as l}from"react/jsx-runtime";import{useCallback as u,useEffect as d,useMemo as f,useRef as p,useState as m}from"react";import{useWatch as h}from"react-hook-form";const g=e=>e?/^-?\d*\.?\d*$/:/^\d*\.?\d*$/,_=e=>Number(e).toLocaleString(),v=({disabled:e=!1,readonly:t=!1,allowNegative:n=!1,numberAfterDecimalPoint:r=2,roundingRule:i=`none`,value:a=``,unitText:h,decimal:v,placeholder:y,precision:b,onChange:x,onValueChange:S,onBlur:C,...w})=>{let T=p(null),E=p(null),[D,O]=m(a.toString()),k=v?.[1]??r,A=v&&v[0]-v[1],j=f(()=>g(n),[n]),M=u(e=>{if(!k&&e.includes(`.`))return!1;let t=e.split(`.`)[1];return!t||t.length<=k},[k]),N=u(e=>{if(!v||e===`-`)return!0;let[t,n=``]=e.split(`.`);return n.length<=v[1]&&(t.startsWith(`-`)?t.length-1:t.length)<=A},[v,A]),P=u((e,t)=>{if(i===`none`)return e;let n=Math.pow(10,t),r=e*n;switch(i){case`up`:return Math.ceil(r)/n;case`down`:return Math.floor(r)/n;case`nearest`:return r%1<.1?Math.floor(r)/n:r%1>=.59?Math.ceil(r)/n:(Math.floor(r)+.5)/n;default:return e}},[i]),F=u(e=>!r&&e.includes(`.`)||e.split(`.`)[1]?.length>r,[r]),I=u(e=>{if(e===`0`)return`0`;if(!Number(e))return``;let t=parseFloat(e),n=Math.min(k-1,b||0),r=P(t,n).toString(),[i,a=``]=r.split(`.`),o=_(i);return a?`${o}.${a}`:o},[P,k,b]),L=u(e=>{if(!v||e===`-`)return!0;let[t,n=``]=e.split(`.`),r=t.startsWith(`-`)?t.length-1:t.length,i=v[0]-v[1];return n.length<=v[1]&&r<=i},[v]),R=u(e=>{x?.(e);let{value:t}=e.target;if(!t){S?.(void 0),O(``);return}let r=t===`0`,i=t===`-`&&n;if(r||i){S?.(0),O(t);return}let a=j.test(t)&&N(t)&&(v||M(t));if(!a)return;let o=parseFloat(t)||0;S?.(o),O(t)},[n,v,M,N,x,S,j]),z=u(()=>{t||O(e=>e.replace(/,/g,``))},[t]),B=u(()=>{t||(C?.(),O(e=>I(e)))},[t,C,I]);return d(()=>{let e=document.activeElement===E.current;if(!a||!j.test(a.toString())||!L(a.toString())||!v&&F(a.toString())){O(``);return}O(t=>t===`-`?`-`:t?e?a.toString():I(a.toString()):``)},[v,I,a,F,L,j]),d(()=>{if(!T.current||!E.current||!h)return;let e=T.current.offsetWidth;E.current.style.setProperty(`padding-right`,`${(e+10)/16}rem`)},[e,h]),l(`div`,{className:`relative`,children:[c(o,{...w,ref:E,value:D||(t?`0`:``),placeholder:y,disabled:e,readOnly:t,className:s(`font-number text-end`,t&&`bg-muted text-muted-foreground`),onChange:R,onFocus:z,onBlur:B}),h&&c(`span`,{ref:T,className:`text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm`,children:h})]})},y=({name:o,label:s=`Number Field`,placeholder:u=`0`,isShowErrorMsg:d=!1,isShowCount:f=!1,unitText:p=``,description:m=``,onValueChange:g})=>{let _=h({name:o});return c(n,{name:o,render:({field:{onChange:n,...o}})=>l(r,{className:`w-full gap-0`,children:[c(i,{children:s}),c(e,{children:c(v,{...o,placeholder:u,className:`w-full`,unitText:p,onValueChange:e=>{n(e),g?.(e)}})}),f&&l(`div`,{className:`text-muted-foreground text-end text-xs`,children:[_?.length??0,` characters`]}),!!m&&c(t,{children:m}),d&&c(a,{})]})})};export{y as NumberField};
2
2
  //# sourceMappingURL=number-field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"number-field.js","names":["NumberInput: React.FC<IProps>","value","precision","maxIntegerLength"],"sources":["../../packages/components/ui/inputs/number-input.tsx","../../packages/components/forms/number-field.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\nimport { cn } from '@customafk/react-toolkit/utils'\n\nimport { Input } from '../input'\n\nconst createValidationRegex = (allowNegative: boolean): RegExp => {\n return allowNegative ? /^-?\\d*\\.?\\d*$/ : /^\\d*\\.?\\d*$/\n}\n\nconst formatNumberWithCommas = (num: number | string): string => {\n return Number(num).toLocaleString()\n}\n\ninterface IProps extends React.HTMLAttributes<HTMLInputElement> {\n /**\n * Description: Value for the text field\n *\n * Default: ''\n *\n * Usage: Value for the text field\n */\n value?: string | number\n /**\n * Description: Disabled state of the text field\n *\n * Default: `false`\n *\n * Usage: Disabled state of the text field\n *\n * Note: If true, the text field will be disabled\n */\n disabled?: boolean\n /**\n * Description: Readonly state of the text field\n *\n * Default: `false`\n *\n * Usage: Readonly state of the text field\n */\n readonly?: boolean\n /**\n * Description: Allow negative value for the text field\n *\n * Default: `false`\n *\n * Usage: Allow negative value for the text field\n */\n allowNegative?: boolean\n /**\n * Description: Decimal point for the text field\n *\n * Default: `undefined`\n *\n * Usage: Ex: [12,3] => console.log(2323.23) // True\n *\n * Note: IF use this prop, `numberAfterDecimalPoint` will be ignored\n */\n decimal?: [number, number]\n /**\n * Description: Rounding rule for the text field\n *\n * Default: `nearest`\n *\n * Usage: Rounding rule for the text field\n */\n roundingRule?: 'up' | 'down' | 'nearest' | 'none'\n /**\n * Description: Number of digits after the decimal point\n *\n * Default: `2`\n *\n * Usage: Number of digits after the decimal point\n */\n numberAfterDecimalPoint?: number\n /**\n * Description: Placeholder for the text field\n *\n * Default: ''\n *\n * Usage: Placeholder for the text field\n */\n placeholder?: string\n /**\n * Description: Unit text for the text field\n *\n * Default: ''\n *\n * E.g. 'kg', 'm', 'USD'...\n */\n unitText?: string\n /**\n * Description: Invalid state of the text field\n *\n * Default: `false`\n *\n * Usage: Invalid state of the text field\n */\n invalid?: boolean\n /**\n * Description: Precision for the text field\n *\n * Default: `undefined`\n * E.g.\n * - 2.13 => 2.1 when precision is 1\n * - 2.134 => 2.13 when precision is 2\n */\n precision?: number\n /**\n * Description: Callback function for the value change\n * Usage: Callback function for the value change\n */\n onValueChange?: (value?: number) => void\n onBlur?: () => void\n}\n/**\n * ## Unit Text Field Component\n *\n * **Description**: This component is to display common text field with unit\n *\n * **Usage**: Text field with unit example: 1000 (kg), 100 (m), 1000 (USD)...\n */\nexport const NumberInput: React.FC<IProps> = ({\n disabled = false,\n readonly = false,\n allowNegative = false,\n numberAfterDecimalPoint = 2,\n roundingRule = 'none',\n value: initialValue = '',\n unitText,\n decimal,\n placeholder,\n precision,\n onChange,\n onValueChange,\n onBlur,\n ...props\n}) => {\n const _unitRef = React.useRef<HTMLSpanElement>(null)\n const _inputRef = React.useRef<HTMLInputElement>(null)\n\n const [value, setValue] = React.useState<string>(initialValue.toString())\n\n // Memoized values for validation and formatting\n const maxDecimalPlaces = decimal?.[1] ?? numberAfterDecimalPoint\n const maxIntegerLength = decimal && decimal[0] - decimal[1]\n const validationRegex = React.useMemo(() => createValidationRegex(allowNegative), [allowNegative])\n\n // Validation functions\n const isValidDecimalLength = React.useCallback(\n (value: string): boolean => {\n if (!maxDecimalPlaces && value.includes('.')) return false\n const decimalPart = value.split('.')[1]\n return !decimalPart || decimalPart.length <= maxDecimalPlaces\n },\n [maxDecimalPlaces],\n )\n const isValidFormat = React.useCallback(\n (value: string): boolean => {\n if (!decimal || value === '-') return true\n const [integerPart, decimalPart = ''] = value.split('.')\n\n return decimalPart.length <= decimal[1] && (integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length) <= maxIntegerLength!\n },\n [decimal, maxIntegerLength],\n )\n const customRoundedValue = React.useCallback(\n (value: number, precision: number) => {\n if (roundingRule === 'none') return value\n\n const factor = Math.pow(10, precision)\n const scaledValue = value * factor\n\n switch (roundingRule) {\n case 'up':\n return Math.ceil(scaledValue) / factor\n case 'down':\n return Math.floor(scaledValue) / factor\n case 'nearest': {\n if (scaledValue % 1 < 0.1) return Math.floor(scaledValue) / factor\n if (scaledValue % 1 >= 0.59) return Math.ceil(scaledValue) / factor\n return (Math.floor(scaledValue) + 0.5) / factor\n }\n default:\n return value\n }\n },\n [roundingRule],\n )\n const isDecimalPointGreaterThanLimit = React.useCallback(\n (value: string) => (!numberAfterDecimalPoint && value.includes('.')) || value.split('.')[1]?.length > numberAfterDecimalPoint,\n [numberAfterDecimalPoint],\n )\n const formattedValue = React.useCallback(\n (val: string) => {\n if (val === '0') return '0'\n if (!Number(val)) return ''\n\n const numValue = parseFloat(val)\n const effectivePrecision = Math.min(maxDecimalPlaces - 1, precision || 0)\n const roundedValue = customRoundedValue(numValue, effectivePrecision).toString()\n const [integerPart, decimalPart = ''] = roundedValue.split('.')\n const formattedInteger = formatNumberWithCommas(integerPart)\n return decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger\n },\n [customRoundedValue, maxDecimalPlaces, precision],\n )\n // Validate decimal point is less than or equal to the limit\n const validateDecimalPoint = React.useCallback(\n (value: string) => {\n if (!decimal || value === '-') return true\n\n const [integerPart, decimalPart = ''] = value.split('.')\n const integerLength = integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length\n const maxIntegerLength = decimal[0] - decimal[1]\n\n return decimalPart.length <= decimal[1] && integerLength <= maxIntegerLength\n },\n [decimal],\n )\n const handleChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n // Don't prevent default behavior of input change\n onChange?.(e)\n\n // Custom event handler for value change\n const { value: inputValue } = e.target\n\n // Handle empty input\n if (!inputValue) {\n onValueChange?.(undefined)\n setValue('')\n return\n }\n\n // Handle zero and negative zero\n const isZero = inputValue === '0'\n const isNegativeZero = inputValue === '-' && allowNegative\n if (isZero || isNegativeZero) {\n onValueChange?.(0)\n setValue(inputValue)\n return\n }\n\n // Validate input format\n const isValid = validationRegex.test(inputValue) && isValidFormat(inputValue) && (decimal || isValidDecimalLength(inputValue))\n if (!isValid) return\n\n const numericValue = parseFloat(inputValue) || 0\n onValueChange?.(numericValue)\n setValue(inputValue)\n },\n [allowNegative, decimal, isValidDecimalLength, isValidFormat, onChange, onValueChange, validationRegex],\n )\n\n const handleFocus = React.useCallback(() => {\n if (readonly) return\n setValue((prev) => prev.replace(/,/g, '')) // Remove commas for easier editing\n }, [readonly])\n\n const handleBlur = React.useCallback(() => {\n if (readonly) return\n onBlur?.()\n setValue((prev) => formattedValue(prev))\n }, [readonly, onBlur, formattedValue])\n\n // Set initial value\n React.useEffect(() => {\n const isFocused = document.activeElement === _inputRef.current\n\n if (\n !initialValue ||\n !validationRegex.test(initialValue.toString()) ||\n !validateDecimalPoint(initialValue.toString()) ||\n (!decimal && isDecimalPointGreaterThanLimit(initialValue.toString()))\n ) {\n setValue('')\n return\n }\n\n setValue((prev) => {\n if (prev === '-') return '-'\n if (!prev) return ''\n return isFocused ? initialValue.toString() : formattedValue(initialValue.toString())\n })\n }, [decimal, formattedValue, initialValue, isDecimalPointGreaterThanLimit, validateDecimalPoint, validationRegex])\n\n // Set padding right for the input field\n React.useEffect(() => {\n if (!_unitRef.current || !_inputRef.current || !unitText) return\n const unitWidth = _unitRef.current.offsetWidth\n _inputRef.current.style.setProperty('padding-right', `${(unitWidth + 10) / 16}rem`)\n }, [disabled, unitText])\n\n return (\n <div className=\"relative\">\n <Input\n {...props}\n ref={_inputRef}\n value={value || (readonly ? '0' : '')}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readonly}\n className={cn('font-number text-end', readonly && 'bg-muted text-muted-foreground')}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n {unitText && (\n <span ref={_unitRef} className=\"text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm\">\n {unitText}\n </span>\n )}\n </div>\n )\n}\n","import { type FieldPath, type FieldValues, useWatch } from 'react-hook-form'\n\nimport { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '../ui/form'\nimport { NumberInput } from '../ui/inputs/number-input'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n name: FieldPath<TFieldValues>\n label?: string\n description?: string\n placeholder?: string\n unitText?: string\n isShowClearButton?: boolean\n isShowErrorMsg?: boolean\n isShowCount?: boolean\n onValueChange?: (value?: number) => void\n}\nexport const NumberField = <TFieldValues extends FieldValues = FieldValues>({\n name,\n label = 'Number Field',\n placeholder = '0',\n isShowErrorMsg = false,\n isShowCount = false,\n unitText = '',\n description = '',\n onValueChange,\n}: Props<TFieldValues>) => {\n const valueWatch = useWatch({ name })\n\n return (\n <FormField\n name={name}\n render={({ field: { onChange, ...field } }) => (\n <FormItem className=\"w-full gap-0\">\n <FormLabel>{label}</FormLabel>\n <FormControl>\n <NumberInput\n {...field}\n placeholder={placeholder}\n className=\"w-full\"\n unitText={unitText}\n onValueChange={(value) => {\n onChange(value)\n onValueChange?.(value)\n }}\n />\n </FormControl>\n {isShowCount && <div className=\"text-muted-foreground text-end text-xs\">{valueWatch?.length ?? 0} characters</div>}\n {!!description && <FormDescription>{description}</FormDescription>}\n {isShowErrorMsg && <FormMessage />}\n </FormItem>\n )}\n />\n )\n}\n"],"mappings":"oXAMA,MAAM,EAAyB,GACtB,EAAgB,gBAAkB,cAGrC,EAA0B,GACvB,OAAO,GAAK,iBA+GRA,GAAiC,CAC5C,WAAW,GAC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AAC,EAAA,CAAA,SAAiB,IACnC,GAAkB,EAAC,EAAA"}
1
+ {"version":3,"file":"number-field.js","names":["NumberInput: React.FC<IProps>","value","precision","maxIntegerLength"],"sources":["../../packages/components/ui/inputs/number-input.tsx","../../packages/components/forms/number-field.tsx"],"sourcesContent":["'use client'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { cn } from '@customafk/react-toolkit/utils'\n\nimport { Input } from '../input'\n\nconst createValidationRegex = (allowNegative: boolean): RegExp => {\n return allowNegative ? /^-?\\d*\\.?\\d*$/ : /^\\d*\\.?\\d*$/\n}\n\nconst formatNumberWithCommas = (num: number | string): string => {\n return Number(num).toLocaleString()\n}\n\ninterface IProps extends React.HTMLAttributes<HTMLInputElement> {\n /**\n * Description: Value for the text field\n *\n * Default: ''\n *\n * Usage: Value for the text field\n */\n value?: string | number\n /**\n * Description: Disabled state of the text field\n *\n * Default: `false`\n *\n * Usage: Disabled state of the text field\n *\n * Note: If true, the text field will be disabled\n */\n disabled?: boolean\n /**\n * Description: Readonly state of the text field\n *\n * Default: `false`\n *\n * Usage: Readonly state of the text field\n */\n readonly?: boolean\n /**\n * Description: Allow negative value for the text field\n *\n * Default: `false`\n *\n * Usage: Allow negative value for the text field\n */\n allowNegative?: boolean\n /**\n * Description: Decimal point for the text field\n *\n * Default: `undefined`\n *\n * Usage: Ex: [12,3] => console.log(2323.23) // True\n *\n * Note: IF use this prop, `numberAfterDecimalPoint` will be ignored\n */\n decimal?: [number, number]\n /**\n * Description: Rounding rule for the text field\n *\n * Default: `nearest`\n *\n * Usage: Rounding rule for the text field\n */\n roundingRule?: 'up' | 'down' | 'nearest' | 'none'\n /**\n * Description: Number of digits after the decimal point\n *\n * Default: `2`\n *\n * Usage: Number of digits after the decimal point\n */\n numberAfterDecimalPoint?: number\n /**\n * Description: Placeholder for the text field\n *\n * Default: ''\n *\n * Usage: Placeholder for the text field\n */\n placeholder?: string\n /**\n * Description: Unit text for the text field\n *\n * Default: ''\n *\n * E.g. 'kg', 'm', 'USD'...\n */\n unitText?: string\n /**\n * Description: Invalid state of the text field\n *\n * Default: `false`\n *\n * Usage: Invalid state of the text field\n */\n invalid?: boolean\n /**\n * Description: Precision for the text field\n *\n * Default: `undefined`\n * E.g.\n * - 2.13 => 2.1 when precision is 1\n * - 2.134 => 2.13 when precision is 2\n */\n precision?: number\n /**\n * Description: Callback function for the value change\n * Usage: Callback function for the value change\n */\n onValueChange?: (value?: number) => void\n onBlur?: () => void\n}\n/**\n * ## Unit Text Field Component\n *\n * **Description**: This component is to display common text field with unit\n *\n * **Usage**: Text field with unit example: 1000 (kg), 100 (m), 1000 (USD)...\n */\nexport const NumberInput: React.FC<IProps> = ({\n disabled = false,\n readonly = false,\n allowNegative = false,\n numberAfterDecimalPoint = 2,\n roundingRule = 'none',\n value: initialValue = '',\n unitText,\n decimal,\n placeholder,\n precision,\n onChange,\n onValueChange,\n onBlur,\n ...props\n}) => {\n const _unitRef = useRef<HTMLSpanElement>(null)\n const _inputRef = useRef<HTMLInputElement>(null)\n\n const [value, setValue] = useState<string>(initialValue.toString())\n\n // Memoized values for validation and formatting\n const maxDecimalPlaces = decimal?.[1] ?? numberAfterDecimalPoint\n const maxIntegerLength = decimal && decimal[0] - decimal[1]\n const validationRegex = useMemo(() => createValidationRegex(allowNegative), [allowNegative])\n\n // Validation functions\n const isValidDecimalLength = useCallback(\n (value: string): boolean => {\n if (!maxDecimalPlaces && value.includes('.')) return false\n const decimalPart = value.split('.')[1]\n return !decimalPart || decimalPart.length <= maxDecimalPlaces\n },\n [maxDecimalPlaces],\n )\n const isValidFormat = useCallback(\n (value: string): boolean => {\n if (!decimal || value === '-') return true\n const [integerPart, decimalPart = ''] = value.split('.')\n\n return decimalPart.length <= decimal[1] && (integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length) <= maxIntegerLength!\n },\n [decimal, maxIntegerLength],\n )\n const customRoundedValue = useCallback(\n (value: number, precision: number) => {\n if (roundingRule === 'none') return value\n\n const factor = Math.pow(10, precision)\n const scaledValue = value * factor\n\n switch (roundingRule) {\n case 'up':\n return Math.ceil(scaledValue) / factor\n case 'down':\n return Math.floor(scaledValue) / factor\n case 'nearest': {\n if (scaledValue % 1 < 0.1) return Math.floor(scaledValue) / factor\n if (scaledValue % 1 >= 0.59) return Math.ceil(scaledValue) / factor\n return (Math.floor(scaledValue) + 0.5) / factor\n }\n default:\n return value\n }\n },\n [roundingRule],\n )\n const isDecimalPointGreaterThanLimit = useCallback(\n (value: string) => (!numberAfterDecimalPoint && value.includes('.')) || value.split('.')[1]?.length > numberAfterDecimalPoint,\n [numberAfterDecimalPoint],\n )\n const formattedValue = useCallback(\n (val: string) => {\n if (val === '0') return '0'\n if (!Number(val)) return ''\n\n const numValue = parseFloat(val)\n const effectivePrecision = Math.min(maxDecimalPlaces - 1, precision || 0)\n const roundedValue = customRoundedValue(numValue, effectivePrecision).toString()\n const [integerPart, decimalPart = ''] = roundedValue.split('.')\n const formattedInteger = formatNumberWithCommas(integerPart)\n return decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger\n },\n [customRoundedValue, maxDecimalPlaces, precision],\n )\n // Validate decimal point is less than or equal to the limit\n const validateDecimalPoint = useCallback(\n (value: string) => {\n if (!decimal || value === '-') return true\n\n const [integerPart, decimalPart = ''] = value.split('.')\n const integerLength = integerPart.startsWith('-') ? integerPart.length - 1 : integerPart.length\n const maxIntegerLength = decimal[0] - decimal[1]\n\n return decimalPart.length <= decimal[1] && integerLength <= maxIntegerLength\n },\n [decimal],\n )\n const handleChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n // Don't prevent default behavior of input change\n onChange?.(e)\n\n // Custom event handler for value change\n const { value: inputValue } = e.target\n\n // Handle empty input\n if (!inputValue) {\n onValueChange?.(undefined)\n setValue('')\n return\n }\n\n // Handle zero and negative zero\n const isZero = inputValue === '0'\n const isNegativeZero = inputValue === '-' && allowNegative\n if (isZero || isNegativeZero) {\n onValueChange?.(0)\n setValue(inputValue)\n return\n }\n\n // Validate input format\n const isValid = validationRegex.test(inputValue) && isValidFormat(inputValue) && (decimal || isValidDecimalLength(inputValue))\n if (!isValid) return\n\n const numericValue = parseFloat(inputValue) || 0\n onValueChange?.(numericValue)\n setValue(inputValue)\n },\n [allowNegative, decimal, isValidDecimalLength, isValidFormat, onChange, onValueChange, validationRegex],\n )\n\n const handleFocus = useCallback(() => {\n if (readonly) return\n setValue((prev) => prev.replace(/,/g, '')) // Remove commas for easier editing\n }, [readonly])\n\n const handleBlur = useCallback(() => {\n if (readonly) return\n onBlur?.()\n setValue((prev) => formattedValue(prev))\n }, [readonly, onBlur, formattedValue])\n\n // Set initial value\n useEffect(() => {\n const isFocused = document.activeElement === _inputRef.current\n\n if (\n !initialValue ||\n !validationRegex.test(initialValue.toString()) ||\n !validateDecimalPoint(initialValue.toString()) ||\n (!decimal && isDecimalPointGreaterThanLimit(initialValue.toString()))\n ) {\n setValue('')\n return\n }\n\n setValue((prev) => {\n if (prev === '-') return '-'\n if (!prev) return ''\n return isFocused ? initialValue.toString() : formattedValue(initialValue.toString())\n })\n }, [decimal, formattedValue, initialValue, isDecimalPointGreaterThanLimit, validateDecimalPoint, validationRegex])\n\n // Set padding right for the input field\n useEffect(() => {\n if (!_unitRef.current || !_inputRef.current || !unitText) return\n const unitWidth = _unitRef.current.offsetWidth\n _inputRef.current.style.setProperty('padding-right', `${(unitWidth + 10) / 16}rem`)\n }, [disabled, unitText])\n\n return (\n <div className=\"relative\">\n <Input\n {...props}\n ref={_inputRef}\n value={value || (readonly ? '0' : '')}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readonly}\n className={cn('font-number text-end', readonly && 'bg-muted text-muted-foreground')}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n {unitText && (\n <span ref={_unitRef} className=\"text-muted-foreground pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 text-sm\">\n {unitText}\n </span>\n )}\n </div>\n )\n}\n","import { type FieldPath, type FieldValues, useWatch } from 'react-hook-form'\n\nimport { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '../ui/form'\nimport { NumberInput } from '../ui/inputs/number-input'\n\ntype Props<TFieldValues extends FieldValues = FieldValues> = {\n name: FieldPath<TFieldValues>\n label?: string\n description?: string\n placeholder?: string\n unitText?: string\n isShowClearButton?: boolean\n isShowErrorMsg?: boolean\n isShowCount?: boolean\n onValueChange?: (value?: number) => void\n}\nexport const NumberField = <TFieldValues extends FieldValues = FieldValues>({\n name,\n label = 'Number Field',\n placeholder = '0',\n isShowErrorMsg = false,\n isShowCount = false,\n unitText = '',\n description = '',\n onValueChange,\n}: Props<TFieldValues>) => {\n const valueWatch = useWatch({ name })\n\n return (\n <FormField\n name={name}\n render={({ field: { onChange, ...field } }) => (\n <FormItem className=\"w-full gap-0\">\n <FormLabel>{label}</FormLabel>\n <FormControl>\n <NumberInput\n {...field}\n placeholder={placeholder}\n className=\"w-full\"\n unitText={unitText}\n onValueChange={(value) => {\n onChange(value)\n onValueChange?.(value)\n }}\n />\n </FormControl>\n {isShowCount && <div className=\"text-muted-foreground text-end text-xs\">{valueWatch?.length ?? 0} characters</div>}\n {!!description && <FormDescription>{description}</FormDescription>}\n {isShowErrorMsg && <FormMessage />}\n </FormItem>\n )}\n />\n )\n}\n"],"mappings":"ybAMA,MAAM,EAAyB,GACtB,EAAgB,gBAAkB,cAGrC,EAA0B,GACvB,OAAO,GAAK,iBA+GRA,GAAiC,CAC5C,WAAW,GACX,WAAW,GACX,gBAAgB,GAChB,0BAA0B,EAC1B,eAAe,OACf,MAAO,EAAe,GACtB,WACA,UACA,cACA,YACA,WACA,gBACA,SACA,GAAG,KACC,CACJ,IAAM,EAAW,EAAwB,MACnC,EAAY,EAAyB,MAErC,CAAC,EAAO,GAAY,EAAiB,EAAa,YAGlD,EAAmB,IAAU,IAAM,EACnC,EAAmB,GAAW,EAAQ,GAAK,EAAQ,GACnD,EAAkB,MAAc,EAAsB,GAAgB,CAAC,IAGvE,EAAu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,EAAY,EAAS,QAAQ,YACnC,EAAU,QAAQ,MAAM,YAAY,gBAAiB,IAAI,EAAY,IAAM,GAAG,OAC7E,CAAC,EAAU,IAGZ,EAAC,MAAA,CAAI,UAAU,qBACb,EAAC,EAAA,CACC,GAAI,EACJ,IAAK,EACL,MAAO,IAAU,EAAW,IAAM,IACrB,cACH,WACV,SAAU,EACV,UAAW,EAAG,uBAAwB,GAAY,kCAClD,SAAU,EACV,QAAS,EACT,OAAQ,IAET,GACC,EAAC,OAAA,CAAK,IAAK,EAAU,UAAU,uGAC5B,QCtSE,GAA+D,CAC1E,OACA,QAAQ,eACR,cAAc,IACd,iBAAiB,GACjB,cAAc,GACd,WAAW,GACX,cAAc,GACd,mBACyB,CACzB,IAAM,EAAa,EAAS,CAAE,SAE9B,OACE,EAAC,EAAA,CACO,OACN,QAAS,CAAE,MAAO,CAAE,WAAU,GAAG,MAC/B,EAAC,EAAA,CAAS,UAAU,yBAClB,EAAC,EAAA,CAAA,SAAW,IACZ,EAAC,EAAA,CAAA,SACC,EAAC,EAAA,CACC,GAAI,EACS,cACb,UAAU,SACA,WACV,cAAgB,GAAU,CACxB,EAAS,GACT,IAAgB,QAIrB,GAAe,EAAC,MAAA,CAAI,UAAU,mDAA0C,GAAY,QAAU,EAAE,iBAChG,CAAC,CAAC,GAAe,EAAC,EAAA,CAAA,SAAiB,IACnC,GAAkB,EAAC,EAAA"}
@@ -1,2 +1,2 @@
1
- "use client";const e=require(`../chunk-CUT6urMc.cjs`);require(`../label-BbuMrcie.cjs`);const t=require(`../form-DAwCSzSe.cjs`),n=require(`../input-Bt7b3-NW.cjs`),r=e.__toESM(require(`lucide-react`)),i=e.__toESM(require(`@customafk/react-toolkit/utils`)),a=e.__toESM(require(`react/jsx-runtime`)),o=e.__toESM(require(`react`)),s=({className:e,...t})=>{let s=o.default.useId(),[c,l]=o.default.useState(!1),u=o.default.useCallback(()=>l(e=>!e),[]);return(0,a.jsxs)(`div`,{className:`relative`,children:[(0,a.jsx)(n.Input,{...t,id:s,placeholder:`Password`,type:c?`text`:`password`,className:(0,i.cn)(`pe-9`,e)}),(0,a.jsx)(`button`,{className:`text-muted-foreground/80 hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 absolute inset-y-0 end-0 flex h-full w-9 items-center justify-center rounded-e-md transition-[color,box-shadow] outline-none focus:z-10 focus-visible:ring-[3px] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,onClick:u,"aria-label":c?`Hide password`:`Show password`,"aria-pressed":c,"aria-controls":`password`,children:c?(0,a.jsx)(r.EyeOffIcon,{size:16,"aria-hidden":`true`}):(0,a.jsx)(r.EyeIcon,{size:16,"aria-hidden":`true`})})]})},c=({name:e,label:n=`Text Field`,placeholder:r=`Enter text here`,isShowErrorMsg:i=!1,description:o,onValueChange:c})=>(0,a.jsx)(t.FormField,{name:e,render:({field:e})=>(0,a.jsxs)(t.FormItem,{className:`w-full`,children:[(0,a.jsx)(t.FormLabel,{children:n}),(0,a.jsx)(t.FormControl,{children:(0,a.jsx)(s,{placeholder:r,...e,onValueChange:c})}),!!o&&(0,a.jsx)(t.FormDescription,{children:o}),i&&(0,a.jsx)(t.FormMessage,{})]})});exports.PasswordField=c;
1
+ "use client";const e=require(`../chunk-CUT6urMc.cjs`);require(`../label-BBPPT0-L.cjs`);const t=require(`../form-CaxhlWxK.cjs`),n=require(`../input-ERPHY3v4.cjs`),r=e.__toESM(require(`lucide-react`)),i=e.__toESM(require(`@customafk/react-toolkit/utils`)),a=e.__toESM(require(`react/jsx-runtime`)),o=({className:e,...t})=>{let o=React.useId(),[s,c]=React.useState(!1),l=React.useCallback(()=>c(e=>!e),[]);return(0,a.jsxs)(`div`,{className:`relative`,children:[(0,a.jsx)(n.Input,{...t,id:o,placeholder:`Password`,type:s?`text`:`password`,className:(0,i.cn)(`pe-9`,e)}),(0,a.jsx)(`button`,{className:`text-muted-foreground/80 hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 absolute inset-y-0 end-0 flex h-full w-9 items-center justify-center rounded-e-md transition-[color,box-shadow] outline-none focus:z-10 focus-visible:ring-[3px] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,onClick:l,"aria-label":s?`Hide password`:`Show password`,"aria-pressed":s,"aria-controls":`password`,children:s?(0,a.jsx)(r.EyeOffIcon,{size:16,"aria-hidden":`true`}):(0,a.jsx)(r.EyeIcon,{size:16,"aria-hidden":`true`})})]})},s=({name:e,label:n=`Text Field`,placeholder:r=`Enter text here`,isShowErrorMsg:i=!1,description:s,onValueChange:c})=>(0,a.jsx)(t.FormField,{name:e,render:({field:e})=>(0,a.jsxs)(t.FormItem,{className:`w-full`,children:[(0,a.jsx)(t.FormLabel,{children:n}),(0,a.jsx)(t.FormControl,{children:(0,a.jsx)(o,{placeholder:r,...e,onValueChange:c})}),!!s&&(0,a.jsx)(t.FormDescription,{children:s}),i&&(0,a.jsx)(t.FormMessage,{})]})});exports.PasswordField=s;
2
2
  //# sourceMappingURL=password-field.cjs.map