@techzyapp/ui-library 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Accordion-Dy_dM79Y.cjs → Accordion-P3PNqSER.cjs} +2 -2
- package/dist/{Accordion-Dy_dM79Y.cjs.map → Accordion-P3PNqSER.cjs.map} +1 -1
- package/dist/{Accordion-CAxa1I-m.js → Accordion-w-w_WxxV.js} +3 -3
- package/dist/{Accordion-CAxa1I-m.js.map → Accordion-w-w_WxxV.js.map} +1 -1
- package/dist/{AdminRoot-DlpMJNTx.cjs → AdminRoot-BDRLuMX6.cjs} +2 -2
- package/dist/{AdminRoot-DlpMJNTx.cjs.map → AdminRoot-BDRLuMX6.cjs.map} +1 -1
- package/dist/{AdminRoot-B2J1cHK5.js → AdminRoot-DvF0js0q.js} +4 -4
- package/dist/{AdminRoot-B2J1cHK5.js.map → AdminRoot-DvF0js0q.js.map} +1 -1
- package/dist/{Alert-DRZdNwDm.cjs → Alert-CwoRkKq4.cjs} +2 -2
- package/dist/{Alert-DRZdNwDm.cjs.map → Alert-CwoRkKq4.cjs.map} +1 -1
- package/dist/{Alert-yldGvhVM.js → Alert-DPYmdaWs.js} +5 -5
- package/dist/{Alert-yldGvhVM.js.map → Alert-DPYmdaWs.js.map} +1 -1
- package/dist/{AuthLayout-B1tzhzHo.cjs → AuthLayout-BRUxDgzs.cjs} +2 -2
- package/dist/{AuthLayout-B1tzhzHo.cjs.map → AuthLayout-BRUxDgzs.cjs.map} +1 -1
- package/dist/{AuthLayout-j7EAPPXT.js → AuthLayout-CP9qu6Bv.js} +2 -2
- package/dist/{AuthLayout-j7EAPPXT.js.map → AuthLayout-CP9qu6Bv.js.map} +1 -1
- package/dist/{Avatar-_ufXh3AY.cjs → Avatar-Dgf04PBC.cjs} +2 -2
- package/dist/{Avatar-_ufXh3AY.cjs.map → Avatar-Dgf04PBC.cjs.map} +1 -1
- package/dist/{Avatar-BJVCdo-K.js → Avatar-Q50J8wdN.js} +3 -3
- package/dist/{Avatar-BJVCdo-K.js.map → Avatar-Q50J8wdN.js.map} +1 -1
- package/dist/{AvatarGroup-DdJf4aT7.js → AvatarGroup-YaNasLMS.js} +2 -2
- package/dist/{AvatarGroup-DdJf4aT7.js.map → AvatarGroup-YaNasLMS.js.map} +1 -1
- package/dist/{AvatarGroup-TW1pt4tj.cjs → AvatarGroup-uW0SD5P4.cjs} +2 -2
- package/dist/{AvatarGroup-TW1pt4tj.cjs.map → AvatarGroup-uW0SD5P4.cjs.map} +1 -1
- package/dist/{Breadcrumbs-f0GE4lCI.cjs → Breadcrumbs-CknDBLMw.cjs} +2 -2
- package/dist/{Breadcrumbs-f0GE4lCI.cjs.map → Breadcrumbs-CknDBLMw.cjs.map} +1 -1
- package/dist/{Breadcrumbs-FpIOHx_q.js → Breadcrumbs-l0PlUpQ4.js} +5 -5
- package/dist/{Breadcrumbs-FpIOHx_q.js.map → Breadcrumbs-l0PlUpQ4.js.map} +1 -1
- package/dist/{Button-Cu0XdnW6.cjs → Button-BdihbLYJ.cjs} +2 -2
- package/dist/{Button-Cu0XdnW6.cjs.map → Button-BdihbLYJ.cjs.map} +1 -1
- package/dist/{Button-BkjZ7wEu.js → Button-RljTGqHl.js} +2 -2
- package/dist/{Button-BkjZ7wEu.js.map → Button-RljTGqHl.js.map} +1 -1
- package/dist/{Calendar-DsJ6GICt.js → Calendar-CKCikOQL.js} +4 -4
- package/dist/{Calendar-DsJ6GICt.js.map → Calendar-CKCikOQL.js.map} +1 -1
- package/dist/{Calendar-CGQCditF.cjs → Calendar-DVg1uQuj.cjs} +2 -2
- package/dist/{Calendar-CGQCditF.cjs.map → Calendar-DVg1uQuj.cjs.map} +1 -1
- package/dist/{Card-CumMi_XB.js → Card-B0bYi4g2.js} +4 -4
- package/dist/{Card-CumMi_XB.js.map → Card-B0bYi4g2.js.map} +1 -1
- package/dist/{Card-DGTGdaTZ.cjs → Card-BYFuYD-a.cjs} +2 -2
- package/dist/{Card-DGTGdaTZ.cjs.map → Card-BYFuYD-a.cjs.map} +1 -1
- package/dist/Checkbox-ZYOSBYRt.js +98 -0
- package/dist/Checkbox-ZYOSBYRt.js.map +1 -0
- package/dist/Checkbox-fzJCwe0j.cjs +2 -0
- package/dist/Checkbox-fzJCwe0j.cjs.map +1 -0
- package/dist/{Chip-D83svOCW.js → Chip-BiqfnRUi.js} +3 -3
- package/dist/{Chip-D83svOCW.js.map → Chip-BiqfnRUi.js.map} +1 -1
- package/dist/{Chip-CJuAvgst.cjs → Chip-CdKUtUGE.cjs} +2 -2
- package/dist/{Chip-CJuAvgst.cjs.map → Chip-CdKUtUGE.cjs.map} +1 -1
- package/dist/{ChoiceCardGroup-CvFzZlgI.js → ChoiceCardGroup-DBohUnRj.js} +3 -3
- package/dist/{ChoiceCardGroup-CvFzZlgI.js.map → ChoiceCardGroup-DBohUnRj.js.map} +1 -1
- package/dist/{ChoiceCardGroup-6eFM1eL0.cjs → ChoiceCardGroup-d0VVTUi5.cjs} +2 -2
- package/dist/{ChoiceCardGroup-6eFM1eL0.cjs.map → ChoiceCardGroup-d0VVTUi5.cjs.map} +1 -1
- package/dist/{CodeBlock-BK_KXhos.js → CodeBlock-BX_0tpk3.js} +4 -4
- package/dist/{CodeBlock-BK_KXhos.js.map → CodeBlock-BX_0tpk3.js.map} +1 -1
- package/dist/{CodeBlock-C_UDrrY6.cjs → CodeBlock-CAAggVXS.cjs} +2 -2
- package/dist/{CodeBlock-C_UDrrY6.cjs.map → CodeBlock-CAAggVXS.cjs.map} +1 -1
- package/dist/{ColorPicker-BmxZnsNC.cjs → ColorPicker-BCSaT1A-.cjs} +2 -2
- package/dist/{ColorPicker-BmxZnsNC.cjs.map → ColorPicker-BCSaT1A-.cjs.map} +1 -1
- package/dist/{ColorPicker-DLnB_AvZ.js → ColorPicker-DhSlvwNj.js} +3 -3
- package/dist/{ColorPicker-DLnB_AvZ.js.map → ColorPicker-DhSlvwNj.js.map} +1 -1
- package/dist/{ColorPickerPanel-CoyKplF5.cjs → ColorPickerPanel-BOGYXXF1.cjs} +2 -2
- package/dist/{ColorPickerPanel-CoyKplF5.cjs.map → ColorPickerPanel-BOGYXXF1.cjs.map} +1 -1
- package/dist/{ColorPickerPanel-CG9idF4A.js → ColorPickerPanel-D4t3b9bB.js} +3 -3
- package/dist/{ColorPickerPanel-CG9idF4A.js.map → ColorPickerPanel-D4t3b9bB.js.map} +1 -1
- package/dist/{ConfigProvider-h1WoGC3R.cjs → ConfigProvider-C7DUWHrb.cjs} +2 -2
- package/dist/{ConfigProvider-h1WoGC3R.cjs.map → ConfigProvider-C7DUWHrb.cjs.map} +1 -1
- package/dist/{ConfigProvider-DDuIJSM7.js → ConfigProvider-DT0yrgmd.js} +2 -2
- package/dist/{ConfigProvider-DDuIJSM7.js.map → ConfigProvider-DT0yrgmd.js.map} +1 -1
- package/dist/{CopyButton-tRMAy59I.cjs → CopyButton-3585thVM.cjs} +2 -2
- package/dist/{CopyButton-tRMAy59I.cjs.map → CopyButton-3585thVM.cjs.map} +1 -1
- package/dist/{CopyButton-DdQ-8ExN.js → CopyButton-BEY1gJzK.js} +4 -4
- package/dist/{CopyButton-DdQ-8ExN.js.map → CopyButton-BEY1gJzK.js.map} +1 -1
- package/dist/{DashedButton-q7AOqKUE.cjs → DashedButton-3C4IZuo4.cjs} +2 -2
- package/dist/{DashedButton-q7AOqKUE.cjs.map → DashedButton-3C4IZuo4.cjs.map} +1 -1
- package/dist/{DashedButton-DeiALUPA.js → DashedButton-BXZAyMtw.js} +3 -3
- package/dist/{DashedButton-DeiALUPA.js.map → DashedButton-BXZAyMtw.js.map} +1 -1
- package/dist/{DatePicker-pz634ktl.js → DatePicker-CEFGgXLF.js} +5 -5
- package/dist/{DatePicker-pz634ktl.js.map → DatePicker-CEFGgXLF.js.map} +1 -1
- package/dist/{DatePicker-eryY6Xmx.cjs → DatePicker-Dyj2halw.cjs} +2 -2
- package/dist/{DatePicker-eryY6Xmx.cjs.map → DatePicker-Dyj2halw.cjs.map} +1 -1
- package/dist/{DateTimePicker-CmH3ZuzN.cjs → DateTimePicker-CjX4-8PP.cjs} +2 -2
- package/dist/{DateTimePicker-CmH3ZuzN.cjs.map → DateTimePicker-CjX4-8PP.cjs.map} +1 -1
- package/dist/{DateTimePicker-BJLq9Fud.js → DateTimePicker-hmYBEuUM.js} +8 -8
- package/dist/{DateTimePicker-BJLq9Fud.js.map → DateTimePicker-hmYBEuUM.js.map} +1 -1
- package/dist/{EmptyState-Cxf4H8Cc.cjs → EmptyState-Bj-vX_UV.cjs} +2 -2
- package/dist/{EmptyState-Cxf4H8Cc.cjs.map → EmptyState-Bj-vX_UV.cjs.map} +1 -1
- package/dist/{EmptyState-B2QPNhWW.js → EmptyState-DJDNLKT7.js} +4 -4
- package/dist/{EmptyState-B2QPNhWW.js.map → EmptyState-DJDNLKT7.js.map} +1 -1
- package/dist/{FileCard-Do9D72NA.js → FileCard-C9Ncifnu.js} +5 -5
- package/dist/{FileCard-Do9D72NA.js.map → FileCard-C9Ncifnu.js.map} +1 -1
- package/dist/{FileCard-D0Sa7WJt.cjs → FileCard-Dr5-z1R3.cjs} +2 -2
- package/dist/{FileCard-D0Sa7WJt.cjs.map → FileCard-Dr5-z1R3.cjs.map} +1 -1
- package/dist/{FileUploader-B1Arfj1a.cjs → FileUploader-DeyZENqq.cjs} +2 -2
- package/dist/{FileUploader-B1Arfj1a.cjs.map → FileUploader-DeyZENqq.cjs.map} +1 -1
- package/dist/{FileUploader-4900qKEE.js → FileUploader-XFmBNkA0.js} +6 -6
- package/dist/{FileUploader-4900qKEE.js.map → FileUploader-XFmBNkA0.js.map} +1 -1
- package/dist/{Flag-DNhhLtCC.js → Flag-Bs0xNP-P.js} +2 -2
- package/dist/{Flag-DNhhLtCC.js.map → Flag-Bs0xNP-P.js.map} +1 -1
- package/dist/{Flag-D7Vlczlw.cjs → Flag-Bxnx26DM.cjs} +2 -2
- package/dist/{Flag-D7Vlczlw.cjs.map → Flag-Bxnx26DM.cjs.map} +1 -1
- package/dist/{FullscreenToggle-dU2ai_OZ.cjs → FullscreenToggle-BncatGKj.cjs} +2 -2
- package/dist/{FullscreenToggle-dU2ai_OZ.cjs.map → FullscreenToggle-BncatGKj.cjs.map} +1 -1
- package/dist/{FullscreenToggle-Bc4fB-Mi.js → FullscreenToggle-DMlp05UN.js} +4 -4
- package/dist/{FullscreenToggle-Bc4fB-Mi.js.map → FullscreenToggle-DMlp05UN.js.map} +1 -1
- package/dist/Icon-BVULqOJD.cjs +2 -0
- package/dist/Icon-BVULqOJD.cjs.map +1 -0
- package/dist/{Icon-CophpkHo.js → Icon-DaTvzLBu.js} +2 -1
- package/dist/Icon-DaTvzLBu.js.map +1 -0
- package/dist/{IconButton-DpTxmj3d.js → IconButton-DXMmtuLA.js} +2 -2
- package/dist/{IconButton-DpTxmj3d.js.map → IconButton-DXMmtuLA.js.map} +1 -1
- package/dist/{IconButton-DyRC514t.cjs → IconButton-Lv0sDDR9.cjs} +2 -2
- package/dist/{IconButton-DyRC514t.cjs.map → IconButton-Lv0sDDR9.cjs.map} +1 -1
- package/dist/{ListItem-B4Upc0Hy.js → ListItem-Cn15lJBr.js} +3 -3
- package/dist/{ListItem-B4Upc0Hy.js.map → ListItem-Cn15lJBr.js.map} +1 -1
- package/dist/{ListItem-DWQorRxG.cjs → ListItem-yXXjtepZ.cjs} +2 -2
- package/dist/{ListItem-DWQorRxG.cjs.map → ListItem-yXXjtepZ.cjs.map} +1 -1
- package/dist/{Loader-B45H2SMP.cjs → Loader-53HFNMVX.cjs} +2 -2
- package/dist/{Loader-B45H2SMP.cjs.map → Loader-53HFNMVX.cjs.map} +1 -1
- package/dist/{Loader-B9VXX401.js → Loader-WsjQFl4p.js} +2 -2
- package/dist/{Loader-B9VXX401.js.map → Loader-WsjQFl4p.js.map} +1 -1
- package/dist/{Modal-Us_E-lb2.js → Modal-DBYcoCbJ.js} +5 -5
- package/dist/{Modal-Us_E-lb2.js.map → Modal-DBYcoCbJ.js.map} +1 -1
- package/dist/{Modal-DsoSz0Sp.cjs → Modal-V6eyGSzW.cjs} +2 -2
- package/dist/{Modal-DsoSz0Sp.cjs.map → Modal-V6eyGSzW.cjs.map} +1 -1
- package/dist/{MultiSelect-sKk2KzOd.js → MultiSelect-BsYPr3LD.js} +6 -6
- package/dist/{MultiSelect-sKk2KzOd.js.map → MultiSelect-BsYPr3LD.js.map} +1 -1
- package/dist/{MultiSelect-CtLpWaBX.cjs → MultiSelect-DS2DRpaP.cjs} +2 -2
- package/dist/{MultiSelect-CtLpWaBX.cjs.map → MultiSelect-DS2DRpaP.cjs.map} +1 -1
- package/dist/{NumberField-C6qj3nCa.cjs → NumberField-DC3TdGTt.cjs} +2 -2
- package/dist/{NumberField-C6qj3nCa.cjs.map → NumberField-DC3TdGTt.cjs.map} +1 -1
- package/dist/{NumberField-Cz03nksO.js → NumberField-mFb9pKCx.js} +4 -4
- package/dist/{NumberField-Cz03nksO.js.map → NumberField-mFb9pKCx.js.map} +1 -1
- package/dist/{OtpField-DLXQYMw1.js → OtpField-1ullIIZQ.js} +2 -2
- package/dist/{OtpField-DLXQYMw1.js.map → OtpField-1ullIIZQ.js.map} +1 -1
- package/dist/{OtpField-B46P6aMy.cjs → OtpField-BYj9SDHb.cjs} +2 -2
- package/dist/{OtpField-B46P6aMy.cjs.map → OtpField-BYj9SDHb.cjs.map} +1 -1
- package/dist/{PageLayout-BfeRjBek.cjs → PageLayout-pYL43wI9.cjs} +2 -2
- package/dist/{PageLayout-BfeRjBek.cjs.map → PageLayout-pYL43wI9.cjs.map} +1 -1
- package/dist/{PageLayout-BWU-p_N9.js → PageLayout-qf0H_EmS.js} +2 -2
- package/dist/{PageLayout-BWU-p_N9.js.map → PageLayout-qf0H_EmS.js.map} +1 -1
- package/dist/{PageNotFound-nvZm-UCG.cjs → PageNotFound-D1795gJ7.cjs} +2 -2
- package/dist/{PageNotFound-nvZm-UCG.cjs.map → PageNotFound-D1795gJ7.cjs.map} +1 -1
- package/dist/{PageNotFound-B_nTMrCD.js → PageNotFound-YGVMVvyG.js} +5 -5
- package/dist/{PageNotFound-B_nTMrCD.js.map → PageNotFound-YGVMVvyG.js.map} +1 -1
- package/dist/{Pagination-BYXUhmSz.js → Pagination-BTvUJiee.js} +3 -3
- package/dist/{Pagination-BYXUhmSz.js.map → Pagination-BTvUJiee.js.map} +1 -1
- package/dist/{Pagination-CsClNqIu.cjs → Pagination-WJq_7QNi.cjs} +2 -2
- package/dist/{Pagination-CsClNqIu.cjs.map → Pagination-WJq_7QNi.cjs.map} +1 -1
- package/dist/{RemoveDialog-PHdZi9-d.js → RemoveDialog-BSQ6EMW-.js} +5 -5
- package/dist/{RemoveDialog-PHdZi9-d.js.map → RemoveDialog-BSQ6EMW-.js.map} +1 -1
- package/dist/{RemoveDialog-D5J9TYap.cjs → RemoveDialog-BhcwsY0q.cjs} +2 -2
- package/dist/{RemoveDialog-D5J9TYap.cjs.map → RemoveDialog-BhcwsY0q.cjs.map} +1 -1
- package/dist/{RichTextEditor-jWv0t3vJ.cjs → RichTextEditor-Bc1fhvzn.cjs} +2 -2
- package/dist/{RichTextEditor-jWv0t3vJ.cjs.map → RichTextEditor-Bc1fhvzn.cjs.map} +1 -1
- package/dist/{RichTextEditor-BcmsnYGJ.js → RichTextEditor-CaGPtwXe.js} +9 -9
- package/dist/{RichTextEditor-BcmsnYGJ.js.map → RichTextEditor-CaGPtwXe.js.map} +1 -1
- package/dist/{RootLayout-q_oWf5et.js → RootLayout-BNwHsuhC.js} +31 -31
- package/dist/{RootLayout-q_oWf5et.js.map → RootLayout-BNwHsuhC.js.map} +1 -1
- package/dist/{RootLayout-DtZcqk9N.cjs → RootLayout-CB-3FgOp.cjs} +2 -2
- package/dist/{RootLayout-DtZcqk9N.cjs.map → RootLayout-CB-3FgOp.cjs.map} +1 -1
- package/dist/{Select-CWCeBQ8Q.cjs → Select-Cx1Yl8nq.cjs} +2 -2
- package/dist/{Select-CWCeBQ8Q.cjs.map → Select-Cx1Yl8nq.cjs.map} +1 -1
- package/dist/{Select-UygxT1Ry.js → Select-vKZzS9K4.js} +6 -6
- package/dist/{Select-UygxT1Ry.js.map → Select-vKZzS9K4.js.map} +1 -1
- package/dist/{Sidebar-C0OJK29L.js → Sidebar-CJ7DtOqb.js} +5 -5
- package/dist/{Sidebar-C0OJK29L.js.map → Sidebar-CJ7DtOqb.js.map} +1 -1
- package/dist/{Sidebar-BfBggyuh.cjs → Sidebar-Cv95DJxZ.cjs} +2 -2
- package/dist/{Sidebar-BfBggyuh.cjs.map → Sidebar-Cv95DJxZ.cjs.map} +1 -1
- package/dist/{SpeedDial-DbvOJ4no.js → SpeedDial-Bb0ioXaO.js} +4 -4
- package/dist/{SpeedDial-DbvOJ4no.js.map → SpeedDial-Bb0ioXaO.js.map} +1 -1
- package/dist/{SpeedDial-cKvuSMuk.cjs → SpeedDial-D6sO-9ES.cjs} +2 -2
- package/dist/{SpeedDial-cKvuSMuk.cjs.map → SpeedDial-D6sO-9ES.cjs.map} +1 -1
- package/dist/{Stepper-BxGrP6JZ.js → Stepper-BaEOUnYe.js} +4 -4
- package/dist/{Stepper-BxGrP6JZ.js.map → Stepper-BaEOUnYe.js.map} +1 -1
- package/dist/{Stepper-Db_ALAc4.cjs → Stepper-CVY8NJEI.cjs} +2 -2
- package/dist/{Stepper-Db_ALAc4.cjs.map → Stepper-CVY8NJEI.cjs.map} +1 -1
- package/dist/{SwatchPicker-DbAU9-ux.cjs → SwatchPicker-CCJltwHI.cjs} +2 -2
- package/dist/{SwatchPicker-DbAU9-ux.cjs.map → SwatchPicker-CCJltwHI.cjs.map} +1 -1
- package/dist/{SwatchPicker-D30aSrbY.js → SwatchPicker-CqyWngFJ.js} +2 -2
- package/dist/{SwatchPicker-D30aSrbY.js.map → SwatchPicker-CqyWngFJ.js.map} +1 -1
- package/dist/{Table-Dvna5_TR.cjs → Table-AQ7yJhtW.cjs} +2 -2
- package/dist/{Table-Dvna5_TR.cjs.map → Table-AQ7yJhtW.cjs.map} +1 -1
- package/dist/{Table-tPOJ9umi.js → Table-wn-B7iLj.js} +143 -143
- package/dist/{Table-tPOJ9umi.js.map → Table-wn-B7iLj.js.map} +1 -1
- package/dist/{Tabs-ozklGWmX.cjs → Tabs-BtcJ2jBl.cjs} +2 -2
- package/dist/{Tabs-ozklGWmX.cjs.map → Tabs-BtcJ2jBl.cjs.map} +1 -1
- package/dist/{Tabs-B0mWCNaC.js → Tabs-DJMfAUni.js} +4 -4
- package/dist/{Tabs-B0mWCNaC.js.map → Tabs-DJMfAUni.js.map} +1 -1
- package/dist/{TagsField-BIxwLfSJ.cjs → TagsField-4x3RmGwt.cjs} +2 -2
- package/dist/{TagsField-BIxwLfSJ.cjs.map → TagsField-4x3RmGwt.cjs.map} +1 -1
- package/dist/{TagsField-CGFm17lP.js → TagsField-Bvh6Fm5Y.js} +5 -5
- package/dist/{TagsField-CGFm17lP.js.map → TagsField-Bvh6Fm5Y.js.map} +1 -1
- package/dist/{TextField-DvKEj36A.cjs → TextField-DNqnpAWB.cjs} +2 -2
- package/dist/{TextField-DvKEj36A.cjs.map → TextField-DNqnpAWB.cjs.map} +1 -1
- package/dist/{TextField-CRCYLPpr.js → TextField-DcdwUA9d.js} +4 -4
- package/dist/{TextField-CRCYLPpr.js.map → TextField-DcdwUA9d.js.map} +1 -1
- package/dist/{ThemeToggle-BwW9L115.js → ThemeToggle-BVQmSMsj.js} +4 -4
- package/dist/{ThemeToggle-BwW9L115.js.map → ThemeToggle-BVQmSMsj.js.map} +1 -1
- package/dist/{ThemeToggle-DxxLN79b.cjs → ThemeToggle-isboxfZk.cjs} +2 -2
- package/dist/{ThemeToggle-DxxLN79b.cjs.map → ThemeToggle-isboxfZk.cjs.map} +1 -1
- package/dist/{TimeColumns-D3nqkQbh.js → TimeColumns-CFy_PynH.js} +2 -2
- package/dist/{TimeColumns-D3nqkQbh.js.map → TimeColumns-CFy_PynH.js.map} +1 -1
- package/dist/{TimeColumns-DB-V4KpQ.cjs → TimeColumns-DxFjjtc7.cjs} +2 -2
- package/dist/{TimeColumns-DB-V4KpQ.cjs.map → TimeColumns-DxFjjtc7.cjs.map} +1 -1
- package/dist/{TimePicker-D51QkQYy.js → TimePicker-ZO7jOJVa.js} +6 -6
- package/dist/{TimePicker-D51QkQYy.js.map → TimePicker-ZO7jOJVa.js.map} +1 -1
- package/dist/{TimePicker-D__72q2J.cjs → TimePicker-v1yA7Igl.cjs} +2 -2
- package/dist/{TimePicker-D__72q2J.cjs.map → TimePicker-v1yA7Igl.cjs.map} +1 -1
- package/dist/{Timeline-WkV4k_we.js → Timeline-D3kzt1dy.js} +3 -3
- package/dist/{Timeline-WkV4k_we.js.map → Timeline-D3kzt1dy.js.map} +1 -1
- package/dist/{Timeline-CoxW0Ia_.cjs → Timeline-ONU_3gi3.cjs} +2 -2
- package/dist/{Timeline-CoxW0Ia_.cjs.map → Timeline-ONU_3gi3.cjs.map} +1 -1
- package/dist/{Toaster-BynCHvUr.js → Toaster-C6UK_2TB.js} +2 -2
- package/dist/{Toaster-BynCHvUr.js.map → Toaster-C6UK_2TB.js.map} +1 -1
- package/dist/{Toaster-tHet1M-T.cjs → Toaster-Qnsq3guQ.cjs} +2 -2
- package/dist/{Toaster-tHet1M-T.cjs.map → Toaster-Qnsq3guQ.cjs.map} +1 -1
- package/dist/{ToggleButtonGroup-BWd7MOcc.js → ToggleButtonGroup-D9odYMzD.js} +3 -3
- package/dist/{ToggleButtonGroup-BWd7MOcc.js.map → ToggleButtonGroup-D9odYMzD.js.map} +1 -1
- package/dist/{ToggleButtonGroup-DYRLwKKh.cjs → ToggleButtonGroup-M2oj_3mc.cjs} +2 -2
- package/dist/{ToggleButtonGroup-DYRLwKKh.cjs.map → ToggleButtonGroup-M2oj_3mc.cjs.map} +1 -1
- package/dist/{TranslatedFields-DHRFcB3n.js → TranslatedFields-Bo5rZ7so.js} +5 -5
- package/dist/{TranslatedFields-DHRFcB3n.js.map → TranslatedFields-Bo5rZ7so.js.map} +1 -1
- package/dist/{TranslatedFields-B3Gli3TZ.cjs → TranslatedFields-CLMvRpJi.cjs} +2 -2
- package/dist/{TranslatedFields-B3Gli3TZ.cjs.map → TranslatedFields-CLMvRpJi.cjs.map} +1 -1
- package/dist/UserCard-454Kc7JS.js +74 -0
- package/dist/UserCard-454Kc7JS.js.map +1 -0
- package/dist/UserCard-CIjZz5xd.cjs +2 -0
- package/dist/UserCard-CIjZz5xd.cjs.map +1 -0
- package/dist/components/Accordion/index.cjs +1 -1
- package/dist/components/Accordion/index.js +1 -1
- package/dist/components/Alert/index.cjs +1 -1
- package/dist/components/Alert/index.js +1 -1
- package/dist/components/AuthLayout/index.cjs +1 -1
- package/dist/components/AuthLayout/index.js +1 -1
- package/dist/components/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +2 -2
- package/dist/components/Breadcrumbs/index.cjs +1 -1
- package/dist/components/Breadcrumbs/index.js +1 -1
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Card/index.cjs +1 -1
- package/dist/components/Card/index.js +1 -1
- package/dist/components/Checkbox/Checkbox.d.cts +7 -0
- package/dist/components/Checkbox/Checkbox.d.ts +7 -0
- package/dist/components/Checkbox/index.cjs +1 -1
- package/dist/components/Checkbox/index.js +1 -1
- package/dist/components/Chip/index.cjs +1 -1
- package/dist/components/Chip/index.js +1 -1
- package/dist/components/ChoiceCard/index.cjs +1 -1
- package/dist/components/ChoiceCard/index.js +1 -1
- package/dist/components/CodeBlock/index.cjs +1 -1
- package/dist/components/CodeBlock/index.js +1 -1
- package/dist/components/ColorPicker/index.cjs +1 -1
- package/dist/components/ColorPicker/index.js +1 -1
- package/dist/components/CopyButton/index.cjs +1 -1
- package/dist/components/CopyButton/index.js +1 -1
- package/dist/components/DashedButton/index.cjs +1 -1
- package/dist/components/DashedButton/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/DateTimePicker/index.cjs +1 -1
- package/dist/components/DateTimePicker/index.js +1 -1
- package/dist/components/EmptyState/index.cjs +1 -1
- package/dist/components/EmptyState/index.js +1 -1
- package/dist/components/FileCard/index.cjs +1 -1
- package/dist/components/FileCard/index.js +1 -1
- package/dist/components/FileUploader/index.cjs +1 -1
- package/dist/components/FileUploader/index.js +1 -1
- package/dist/components/Flag/index.cjs +1 -1
- package/dist/components/Flag/index.js +1 -1
- package/dist/components/FullscreenToggle/index.cjs +1 -1
- package/dist/components/FullscreenToggle/index.js +1 -1
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +2 -2
- package/dist/components/IconButton/index.cjs +1 -1
- package/dist/components/IconButton/index.js +1 -1
- package/dist/components/List/index.cjs +1 -1
- package/dist/components/List/index.js +1 -1
- package/dist/components/Loader/index.cjs +1 -1
- package/dist/components/Loader/index.js +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/MultiSelect/index.cjs +1 -1
- package/dist/components/MultiSelect/index.js +1 -1
- package/dist/components/NumberField/index.cjs +1 -1
- package/dist/components/NumberField/index.js +1 -1
- package/dist/components/OtpField/index.cjs +1 -1
- package/dist/components/OtpField/index.js +1 -1
- package/dist/components/PageLayout/index.cjs +1 -1
- package/dist/components/PageLayout/index.js +1 -1
- package/dist/components/PageNotFound/index.cjs +1 -1
- package/dist/components/PageNotFound/index.js +1 -1
- package/dist/components/Pagination/index.cjs +1 -1
- package/dist/components/Pagination/index.js +1 -1
- package/dist/components/RemoveDialog/index.cjs +1 -1
- package/dist/components/RemoveDialog/index.js +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RootLayout/index.cjs +1 -1
- package/dist/components/RootLayout/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +1 -1
- package/dist/components/Sidebar/index.cjs +1 -1
- package/dist/components/Sidebar/index.js +1 -1
- package/dist/components/SpeedDial/index.cjs +1 -1
- package/dist/components/SpeedDial/index.js +1 -1
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/SwatchPicker/index.cjs +1 -1
- package/dist/components/SwatchPicker/index.js +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Tabs/index.cjs +1 -1
- package/dist/components/Tabs/index.js +1 -1
- package/dist/components/TagsField/index.cjs +1 -1
- package/dist/components/TagsField/index.js +1 -1
- package/dist/components/TextField/index.cjs +1 -1
- package/dist/components/TextField/index.js +1 -1
- package/dist/components/ThemeToggle/index.cjs +1 -1
- package/dist/components/ThemeToggle/index.js +1 -1
- package/dist/components/TimePicker/index.cjs +1 -1
- package/dist/components/TimePicker/index.js +1 -1
- package/dist/components/Timeline/index.cjs +1 -1
- package/dist/components/Timeline/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/ToggleButton/index.cjs +1 -1
- package/dist/components/ToggleButton/index.js +1 -1
- package/dist/components/TranslatedFields/index.cjs +1 -1
- package/dist/components/TranslatedFields/index.js +1 -1
- package/dist/components/UserCard/UserCard.d.cts +4 -1
- package/dist/components/UserCard/UserCard.d.ts +4 -1
- package/dist/components/UserCard/index.cjs +1 -1
- package/dist/components/UserCard/index.js +1 -1
- package/dist/entries/app.cjs +1 -1
- package/dist/entries/app.js +1 -1
- package/dist/entries/components.cjs +1 -1
- package/dist/entries/components.js +53 -53
- package/dist/entries/i18n.cjs +1 -1
- package/dist/entries/i18n.js +2 -2
- package/dist/entries/icons.cjs +1 -1
- package/dist/entries/icons.js +2 -2
- package/dist/entries/theme.cjs +1 -1
- package/dist/entries/theme.js +1 -1
- package/dist/i18n/messages.d.cts +1 -0
- package/dist/i18n/messages.d.ts +1 -0
- package/dist/icons/names.d.cts +3 -3
- package/dist/icons/names.d.ts +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +56 -56
- package/dist/{messages-FciBtnCL.js → messages-CGHhwf6F.js} +10 -3
- package/dist/messages-CGHhwf6F.js.map +1 -0
- package/dist/messages-DZJyiaf9.cjs +36 -0
- package/dist/messages-DZJyiaf9.cjs.map +1 -0
- package/dist/names-BJnFU_5m.cjs +2 -0
- package/dist/names-BJnFU_5m.cjs.map +1 -0
- package/dist/{names-D8ABK2Wk.js → names-r21QPjcU.js} +3 -2
- package/dist/names-r21QPjcU.js.map +1 -0
- package/package.json +1 -1
- package/dist/Checkbox-DXOzYIAz.cjs +0 -2
- package/dist/Checkbox-DXOzYIAz.cjs.map +0 -1
- package/dist/Checkbox-XKL_Q5qj.js +0 -84
- package/dist/Checkbox-XKL_Q5qj.js.map +0 -1
- package/dist/Icon-CXTl_QAP.cjs +0 -2
- package/dist/Icon-CXTl_QAP.cjs.map +0 -1
- package/dist/Icon-CophpkHo.js.map +0 -1
- package/dist/UserCard-D7U-CLbM.js +0 -74
- package/dist/UserCard-D7U-CLbM.js.map +0 -1
- package/dist/UserCard-GHw2gTx9.cjs +0 -2
- package/dist/UserCard-GHw2gTx9.cjs.map +0 -1
- package/dist/messages-C0YutUM1.cjs +0 -36
- package/dist/messages-C0YutUM1.cjs.map +0 -1
- package/dist/messages-FciBtnCL.js.map +0 -1
- package/dist/names-C2Yj1p3u.cjs +0 -2
- package/dist/names-C2Yj1p3u.cjs.map +0 -1
- package/dist/names-D8ABK2Wk.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberField-Cz03nksO.js","sources":["../src/components/NumberField/NumberField.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type ChangeEvent,\n type CSSProperties,\n type FocusEvent,\n type InputHTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useFormContext } from '../../form/formContext'\nimport { useT } from '../../theme'\nimport { Icon } from '../Icon'\nimport { IconButton } from '../IconButton'\nimport { Typography } from '../Typography'\n// shared field chrome (label/control/helper) AND the `.control .iconButton` styling for the steppers\nimport fieldStyles from '../TextField/TextField.module.css'\n\nexport type NumberFieldSize = 'sm' | 'md' | 'lg'\n\n/** Allowed while typing — digits, an optional leading `-`, and one decimal point. */\nconst NUMERIC_RE = /^-?\\d*\\.?\\d*$/\n\n/** Parses the display string to a number, treating empty / in-progress input (`\"\"`, `\"-\"`, `\".\"`) as null. */\nfunction parseValue(raw: string): number | null {\n if (raw === '' || raw === '-' || raw === '.' || raw === '-.') return null\n const n = Number(raw)\n return Number.isNaN(n) ? null : n\n}\n\nfunction clampValue(n: number, min?: number, max?: number): number {\n if (min != null && n < min) return min\n if (max != null && n > max) return max\n return n\n}\n\n/** Kills binary float drift from repeated stepping (e.g. 0.1 + 0.2). */\nfunction roundStep(n: number): number {\n return Math.round(n * 1e6) / 1e6\n}\n\n/** Groups the integer part with `separator` for display (e.g. 32345345 → \"32.345.345\"). */\nfunction groupThousands(value: number, separator: string): string {\n const [intPart, decPart] = String(value).split('.')\n const sign = intPart.startsWith('-') ? '-' : ''\n const digits = sign ? intPart.slice(1) : intPart\n const grouped = digits.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator)\n return decPart != null ? `${sign}${grouped}.${decPart}` : `${sign}${grouped}`\n}\n\n/** Counts the \"significant\" (non-separator) chars — used to keep the caret stable across regrouping. */\nfunction countExcept(s: string, sep: string): number {\n let n = 0\n for (const c of s) if (c !== sep) n++\n return n\n}\n\n/** Index just after the `n`-th non-separator char in `str` (where the caret should land after regrouping). */\nfunction positionAfterExcept(str: string, sep: string, n: number): number {\n if (n <= 0) return 0\n let count = 0\n for (let i = 0; i < str.length; i++) {\n if (str[i] !== sep) {\n count += 1\n if (count === n) return i + 1\n }\n }\n return str.length\n}\n\nexport interface NumberFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'size' | 'value' | 'defaultValue' | 'onChange' | 'type' | 'min' | 'max' | 'step' | 'prefix'\n> {\n /** Label rendered above the field. */\n label?: ReactNode\n /** Preset size — drives the control height, font size and padding. */\n size?: NumberFieldSize\n /** Marks the field invalid: red border/focus ring + the `helperText` in the error color. */\n error?: boolean\n /** Helper / validation text under the field. Adopts the error color while `error`. */\n helperText?: ReactNode\n /** Adds a red asterisk after the label. */\n required?: boolean\n /** Stretches the field to fill its container width. Defaults to `true`. */\n fullWidth?: boolean\n /** Controlled numeric value (`null` = empty). */\n value?: number | null\n /** Initial value for uncontrolled use (`null` = empty). Defaults to `null`. */\n defaultValue?: number | null\n /** Fires with the parsed numeric value (or `null` when the field is empty). */\n onChange?: (value: number | null) => void\n /** Minimum value — clamps on blur and on the stepper, and disables `−` at the floor. Defaults to `0`; pass a negative `min` to allow negatives. */\n min?: number\n /** Maximum value — clamps on blur and on the stepper, and disables `+` at the ceiling. */\n max?: number\n /** Amount the `+`/`−` buttons add or subtract. Defaults to `1`. */\n step?: number\n /** Hides the `+`/`−` stepper buttons (keyboard entry only). */\n hideStepper?: boolean\n /**\n * Thousands-group separator shown **live** as you type, e.g. `\".\"` displays `32345345` as\n * `32.345.345` (or `\",\"`). The caret is preserved across regrouping; the `value`/`onChange`/form\n * value stay a plain `number`. Best for integers — with `\".\"` decimals aren't supported (the dot is\n * the group separator).\n */\n thousandSeparator?: string\n}\n\n/**\n * A numeric input with `+`/`−` stepper buttons. Supports `min`/`max` clamping, a `step` amount,\n * controlled (`value` + `onChange`) or uncontrolled (`defaultValue`) use, optional live thousands\n * grouping, and — like `TextField` — binds to a surrounding `<Form>` by `name` (its form value is a\n * real `number`, validated by the Zod schema). `onChange` emits a `number` or `null` (empty). Shares\n * `TextField`'s field chrome, so label, sizing, error and focus styling are identical.\n */\nexport const NumberField = forwardRef<HTMLInputElement, NumberFieldProps>(function NumberField(\n {\n label,\n size = 'md',\n error,\n helperText,\n required = false,\n fullWidth = true,\n value,\n defaultValue = null,\n onChange,\n min = 0,\n max,\n step = 1,\n hideStepper = false,\n thousandSeparator,\n name,\n onBlur,\n disabled = false,\n id: idProp,\n className,\n style,\n ...props\n },\n ref,\n) {\n const t = useT()\n const reactId = useId()\n const id = idProp ?? reactId\n const helperId = `${id}-helper`\n\n // Auto-bind to a surrounding <Form> by `name`. The form stores a real number; we use field() for\n // touched/error/helper and read/write the numeric value through values/setValue.\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = form && name ? form.field(name) : undefined\n\n const externalValue: number | null | undefined =\n value !== undefined\n ? value\n : isFormBound\n ? ((form!.values[name!] as number | null | undefined) ?? null)\n : undefined\n const isControlled = externalValue !== undefined\n const [internal, setInternal] = useState<number | null>(defaultValue)\n const numValue: number | null = isControlled ? externalValue! : internal\n\n // number <-> display string, applying live thousands grouping when `thousandSeparator` is set.\n const toDisplay = (v: number | null): string =>\n v == null ? '' : thousandSeparator != null ? groupThousands(v, thousandSeparator) : String(v)\n const fromDisplay = (raw: string): number | null =>\n parseValue(thousandSeparator != null ? raw.split(thousandSeparator).join('') : raw)\n\n // The display string mirrors `numValue` but tolerates in-progress input (\"-\", \"1.\" …).\n const [text, setText] = useState<string>(() => toDisplay(numValue))\n useEffect(() => {\n if (fromDisplay(text) !== numValue) setText(toDisplay(numValue))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [numValue]) // re-sync only when the value changes from the outside (stepper, form, reset)\n\n // Caret restoration after regrouping (the formatted string length changes as separators move).\n const innerRef = useRef<HTMLInputElement>(null)\n const pendingCaret = useRef<number | null>(null)\n const setInputRef = useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n useLayoutEffect(() => {\n const pos = pendingCaret.current\n if (pos == null) return\n pendingCaret.current = null\n innerRef.current?.setSelectionRange(pos, pos)\n })\n\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n const commit = (next: number | null) => {\n if (!isControlled) setInternal(next)\n if (isFormBound) form!.setValue(name!, next)\n onChange?.(next)\n }\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const el = event.target\n const raw = el.value\n\n if (thousandSeparator == null) {\n if (raw !== '' && !NUMERIC_RE.test(raw)) return // reject non-numeric keystrokes\n setText(raw)\n commit(parseValue(raw))\n return\n }\n\n // Live grouping: strip separators, validate, regroup, and remember where the caret should land.\n const sep = thousandSeparator\n const cleaned = raw.split(sep).join('')\n if (cleaned !== '' && !NUMERIC_RE.test(cleaned)) return\n const caret = el.selectionStart ?? raw.length\n const significantBefore = countExcept(raw.slice(0, caret), sep)\n const next = parseValue(cleaned)\n const formatted = next == null ? cleaned : groupThousands(next, sep)\n setText(formatted)\n commit(next)\n pendingCaret.current = positionAfterExcept(formatted, sep, significantBefore)\n }\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n if (numValue != null) {\n const clamped = clampValue(numValue, min, max)\n if (clamped !== numValue) commit(clamped)\n }\n bound?.onBlur(event)\n onBlur?.(event)\n }\n\n const stepBy = (direction: 1 | -1) => {\n const base = numValue ?? min ?? 0\n commit(clampValue(roundStep(base + direction * step), min, max))\n }\n\n const atMax = max != null && numValue != null && numValue >= max\n const atMin = min != null && numValue != null && numValue <= min\n\n return (\n <div\n className={clsx(\n fieldStyles.field,\n fieldStyles[size],\n fullWidth && fieldStyles.fullWidth,\n resolvedError && fieldStyles.error,\n disabled && fieldStyles.disabled,\n className,\n )}\n style={style as CSSProperties}\n >\n {label != null && (\n <label htmlFor={id} className={fieldStyles.label}>\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\">\n {label}\n </Typography>\n {required && (\n <span className={fieldStyles.required} aria-hidden=\"true\">\n *\n </span>\n )}\n </label>\n )}\n\n <div className={clsx(fieldStyles.control, !hideStepper && fieldStyles.hasRightAdornment)}>\n <input\n ref={setInputRef}\n id={id}\n name={name}\n type=\"text\"\n inputMode=\"decimal\"\n className={fieldStyles.input}\n value={text}\n onChange={handleChange}\n onBlur={handleBlur}\n disabled={disabled}\n aria-invalid={resolvedError || undefined}\n aria-describedby={resolvedHelperText != null ? helperId : undefined}\n {...props}\n />\n {!hideStepper && (\n <>\n {/* Filled icon buttons, sized via the shared `.control .iconButton` rule (flush square,\n stretched to the control height, scaled). The minus glyph is nudged for optical centering. */}\n <IconButton\n variant=\"filled\"\n color=\"primary\"\n className={fieldStyles.iconButton}\n style={{ marginRight: -2 }}\n disabled={disabled || atMin}\n aria-label={t('numberField.decrease')}\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => stepBy(-1)}\n >\n <Icon name=\"Minus\" />\n </IconButton>\n <IconButton\n variant=\"filled\"\n color=\"primary\"\n className={fieldStyles.iconButton}\n disabled={disabled || atMax}\n aria-label={t('numberField.increase')}\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => stepBy(1)}\n >\n <Icon name=\"Add\" />\n </IconButton>\n </>\n )}\n </div>\n\n {resolvedHelperText != null && (\n <Typography\n as=\"span\"\n id={helperId}\n variant=\"bodySmall\"\n color={resolvedError ? 'error' : 'muted'}\n className={fieldStyles.helper}\n >\n {resolvedHelperText}\n </Typography>\n )}\n </div>\n )\n})\n"],"names":["NUMERIC_RE","parseValue","raw","clampValue","n","min","max","roundStep","groupThousands","value","separator","intPart","decPart","sign","grouped","countExcept","s","sep","c","positionAfterExcept","str","count","i","NumberField","forwardRef","label","size","error","helperText","required","fullWidth","defaultValue","onChange","step","hideStepper","thousandSeparator","name","onBlur","disabled","idProp","className","style","props","ref","t","useT","reactId","useId","id","helperId","form","useFormContext","isFormBound","bound","externalValue","isControlled","internal","setInternal","useState","numValue","toDisplay","v","fromDisplay","text","setText","useEffect","innerRef","useRef","pendingCaret","setInputRef","useCallback","node","useLayoutEffect","pos","_a","resolvedError","resolvedHelperText","commit","next","handleChange","event","el","cleaned","caret","significantBefore","formatted","handleBlur","clamped","stepBy","direction","atMax","atMin","jsxs","clsx","fieldStyles","jsx","Typography","Fragment","IconButton","Icon"],"mappings":";;;;;;;;;AA0BA,MAAMA,IAAa;AAGnB,SAASC,EAAWC,GA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,YACR,OAAO0B,IAAgB,UAAU;AAAA,YACjC,WAAWmB,EAAY;AAAA,YAEtB,UAAAlB;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
1
|
+
{"version":3,"file":"NumberField-mFb9pKCx.js","sources":["../src/components/NumberField/NumberField.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type ChangeEvent,\n type CSSProperties,\n type FocusEvent,\n type InputHTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useFormContext } from '../../form/formContext'\nimport { useT } from '../../theme'\nimport { Icon } from '../Icon'\nimport { IconButton } from '../IconButton'\nimport { Typography } from '../Typography'\n// shared field chrome (label/control/helper) AND the `.control .iconButton` styling for the steppers\nimport fieldStyles from '../TextField/TextField.module.css'\n\nexport type NumberFieldSize = 'sm' | 'md' | 'lg'\n\n/** Allowed while typing — digits, an optional leading `-`, and one decimal point. */\nconst NUMERIC_RE = /^-?\\d*\\.?\\d*$/\n\n/** Parses the display string to a number, treating empty / in-progress input (`\"\"`, `\"-\"`, `\".\"`) as null. */\nfunction parseValue(raw: string): number | null {\n if (raw === '' || raw === '-' || raw === '.' || raw === '-.') return null\n const n = Number(raw)\n return Number.isNaN(n) ? null : n\n}\n\nfunction clampValue(n: number, min?: number, max?: number): number {\n if (min != null && n < min) return min\n if (max != null && n > max) return max\n return n\n}\n\n/** Kills binary float drift from repeated stepping (e.g. 0.1 + 0.2). */\nfunction roundStep(n: number): number {\n return Math.round(n * 1e6) / 1e6\n}\n\n/** Groups the integer part with `separator` for display (e.g. 32345345 → \"32.345.345\"). */\nfunction groupThousands(value: number, separator: string): string {\n const [intPart, decPart] = String(value).split('.')\n const sign = intPart.startsWith('-') ? '-' : ''\n const digits = sign ? intPart.slice(1) : intPart\n const grouped = digits.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator)\n return decPart != null ? `${sign}${grouped}.${decPart}` : `${sign}${grouped}`\n}\n\n/** Counts the \"significant\" (non-separator) chars — used to keep the caret stable across regrouping. */\nfunction countExcept(s: string, sep: string): number {\n let n = 0\n for (const c of s) if (c !== sep) n++\n return n\n}\n\n/** Index just after the `n`-th non-separator char in `str` (where the caret should land after regrouping). */\nfunction positionAfterExcept(str: string, sep: string, n: number): number {\n if (n <= 0) return 0\n let count = 0\n for (let i = 0; i < str.length; i++) {\n if (str[i] !== sep) {\n count += 1\n if (count === n) return i + 1\n }\n }\n return str.length\n}\n\nexport interface NumberFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'size' | 'value' | 'defaultValue' | 'onChange' | 'type' | 'min' | 'max' | 'step' | 'prefix'\n> {\n /** Label rendered above the field. */\n label?: ReactNode\n /** Preset size — drives the control height, font size and padding. */\n size?: NumberFieldSize\n /** Marks the field invalid: red border/focus ring + the `helperText` in the error color. */\n error?: boolean\n /** Helper / validation text under the field. Adopts the error color while `error`. */\n helperText?: ReactNode\n /** Adds a red asterisk after the label. */\n required?: boolean\n /** Stretches the field to fill its container width. Defaults to `true`. */\n fullWidth?: boolean\n /** Controlled numeric value (`null` = empty). */\n value?: number | null\n /** Initial value for uncontrolled use (`null` = empty). Defaults to `null`. */\n defaultValue?: number | null\n /** Fires with the parsed numeric value (or `null` when the field is empty). */\n onChange?: (value: number | null) => void\n /** Minimum value — clamps on blur and on the stepper, and disables `−` at the floor. Defaults to `0`; pass a negative `min` to allow negatives. */\n min?: number\n /** Maximum value — clamps on blur and on the stepper, and disables `+` at the ceiling. */\n max?: number\n /** Amount the `+`/`−` buttons add or subtract. Defaults to `1`. */\n step?: number\n /** Hides the `+`/`−` stepper buttons (keyboard entry only). */\n hideStepper?: boolean\n /**\n * Thousands-group separator shown **live** as you type, e.g. `\".\"` displays `32345345` as\n * `32.345.345` (or `\",\"`). The caret is preserved across regrouping; the `value`/`onChange`/form\n * value stay a plain `number`. Best for integers — with `\".\"` decimals aren't supported (the dot is\n * the group separator).\n */\n thousandSeparator?: string\n}\n\n/**\n * A numeric input with `+`/`−` stepper buttons. Supports `min`/`max` clamping, a `step` amount,\n * controlled (`value` + `onChange`) or uncontrolled (`defaultValue`) use, optional live thousands\n * grouping, and — like `TextField` — binds to a surrounding `<Form>` by `name` (its form value is a\n * real `number`, validated by the Zod schema). `onChange` emits a `number` or `null` (empty). Shares\n * `TextField`'s field chrome, so label, sizing, error and focus styling are identical.\n */\nexport const NumberField = forwardRef<HTMLInputElement, NumberFieldProps>(function NumberField(\n {\n label,\n size = 'md',\n error,\n helperText,\n required = false,\n fullWidth = true,\n value,\n defaultValue = null,\n onChange,\n min = 0,\n max,\n step = 1,\n hideStepper = false,\n thousandSeparator,\n name,\n onBlur,\n disabled = false,\n id: idProp,\n className,\n style,\n ...props\n },\n ref,\n) {\n const t = useT()\n const reactId = useId()\n const id = idProp ?? reactId\n const helperId = `${id}-helper`\n\n // Auto-bind to a surrounding <Form> by `name`. The form stores a real number; we use field() for\n // touched/error/helper and read/write the numeric value through values/setValue.\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = form && name ? form.field(name) : undefined\n\n const externalValue: number | null | undefined =\n value !== undefined\n ? value\n : isFormBound\n ? ((form!.values[name!] as number | null | undefined) ?? null)\n : undefined\n const isControlled = externalValue !== undefined\n const [internal, setInternal] = useState<number | null>(defaultValue)\n const numValue: number | null = isControlled ? externalValue! : internal\n\n // number <-> display string, applying live thousands grouping when `thousandSeparator` is set.\n const toDisplay = (v: number | null): string =>\n v == null ? '' : thousandSeparator != null ? groupThousands(v, thousandSeparator) : String(v)\n const fromDisplay = (raw: string): number | null =>\n parseValue(thousandSeparator != null ? raw.split(thousandSeparator).join('') : raw)\n\n // The display string mirrors `numValue` but tolerates in-progress input (\"-\", \"1.\" …).\n const [text, setText] = useState<string>(() => toDisplay(numValue))\n useEffect(() => {\n if (fromDisplay(text) !== numValue) setText(toDisplay(numValue))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [numValue]) // re-sync only when the value changes from the outside (stepper, form, reset)\n\n // Caret restoration after regrouping (the formatted string length changes as separators move).\n const innerRef = useRef<HTMLInputElement>(null)\n const pendingCaret = useRef<number | null>(null)\n const setInputRef = useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n useLayoutEffect(() => {\n const pos = pendingCaret.current\n if (pos == null) return\n pendingCaret.current = null\n innerRef.current?.setSelectionRange(pos, pos)\n })\n\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n const commit = (next: number | null) => {\n if (!isControlled) setInternal(next)\n if (isFormBound) form!.setValue(name!, next)\n onChange?.(next)\n }\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const el = event.target\n const raw = el.value\n\n if (thousandSeparator == null) {\n if (raw !== '' && !NUMERIC_RE.test(raw)) return // reject non-numeric keystrokes\n setText(raw)\n commit(parseValue(raw))\n return\n }\n\n // Live grouping: strip separators, validate, regroup, and remember where the caret should land.\n const sep = thousandSeparator\n const cleaned = raw.split(sep).join('')\n if (cleaned !== '' && !NUMERIC_RE.test(cleaned)) return\n const caret = el.selectionStart ?? raw.length\n const significantBefore = countExcept(raw.slice(0, caret), sep)\n const next = parseValue(cleaned)\n const formatted = next == null ? cleaned : groupThousands(next, sep)\n setText(formatted)\n commit(next)\n pendingCaret.current = positionAfterExcept(formatted, sep, significantBefore)\n }\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n if (numValue != null) {\n const clamped = clampValue(numValue, min, max)\n if (clamped !== numValue) commit(clamped)\n }\n bound?.onBlur(event)\n onBlur?.(event)\n }\n\n const stepBy = (direction: 1 | -1) => {\n const base = numValue ?? min ?? 0\n commit(clampValue(roundStep(base + direction * step), min, max))\n }\n\n const atMax = max != null && numValue != null && numValue >= max\n const atMin = min != null && numValue != null && numValue <= min\n\n return (\n <div\n className={clsx(\n fieldStyles.field,\n fieldStyles[size],\n fullWidth && fieldStyles.fullWidth,\n resolvedError && fieldStyles.error,\n disabled && fieldStyles.disabled,\n className,\n )}\n style={style as CSSProperties}\n >\n {label != null && (\n <label htmlFor={id} className={fieldStyles.label}>\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\">\n {label}\n </Typography>\n {required && (\n <span className={fieldStyles.required} aria-hidden=\"true\">\n *\n </span>\n )}\n </label>\n )}\n\n <div className={clsx(fieldStyles.control, !hideStepper && fieldStyles.hasRightAdornment)}>\n <input\n ref={setInputRef}\n id={id}\n name={name}\n type=\"text\"\n inputMode=\"decimal\"\n className={fieldStyles.input}\n value={text}\n onChange={handleChange}\n onBlur={handleBlur}\n disabled={disabled}\n aria-invalid={resolvedError || undefined}\n aria-describedby={resolvedHelperText != null ? helperId : undefined}\n {...props}\n />\n {!hideStepper && (\n <>\n {/* Filled icon buttons, sized via the shared `.control .iconButton` rule (flush square,\n stretched to the control height, scaled). The minus glyph is nudged for optical centering. */}\n <IconButton\n variant=\"filled\"\n color=\"primary\"\n className={fieldStyles.iconButton}\n style={{ marginRight: -2 }}\n disabled={disabled || atMin}\n aria-label={t('numberField.decrease')}\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => stepBy(-1)}\n >\n <Icon name=\"Minus\" />\n </IconButton>\n <IconButton\n variant=\"filled\"\n color=\"primary\"\n className={fieldStyles.iconButton}\n disabled={disabled || atMax}\n aria-label={t('numberField.increase')}\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => stepBy(1)}\n >\n <Icon name=\"Add\" />\n </IconButton>\n </>\n )}\n </div>\n\n {resolvedHelperText != null && (\n <Typography\n as=\"span\"\n id={helperId}\n variant=\"bodySmall\"\n color={resolvedError ? 'error' : 'muted'}\n className={fieldStyles.helper}\n >\n {resolvedHelperText}\n </Typography>\n )}\n </div>\n )\n})\n"],"names":["NUMERIC_RE","parseValue","raw","clampValue","n","min","max","roundStep","groupThousands","value","separator","intPart","decPart","sign","grouped","countExcept","s","sep","c","positionAfterExcept","str","count","i","NumberField","forwardRef","label","size","error","helperText","required","fullWidth","defaultValue","onChange","step","hideStepper","thousandSeparator","name","onBlur","disabled","idProp","className","style","props","ref","t","useT","reactId","useId","id","helperId","form","useFormContext","isFormBound","bound","externalValue","isControlled","internal","setInternal","useState","numValue","toDisplay","v","fromDisplay","text","setText","useEffect","innerRef","useRef","pendingCaret","setInputRef","useCallback","node","useLayoutEffect","pos","_a","resolvedError","resolvedHelperText","commit","next","handleChange","event","el","cleaned","caret","significantBefore","formatted","handleBlur","clamped","stepBy","direction","atMax","atMin","jsxs","clsx","fieldStyles","jsx","Typography","Fragment","IconButton","Icon"],"mappings":";;;;;;;;;AA0BA,MAAMA,IAAa;AAGnB,SAASC,EAAWC,GAA4B;AAC9C,MAAIA,MAAQ,MAAMA,MAAQ,OAAOA,MAAQ,OAAOA,MAAQ,KAAM,QAAO;AACrE,QAAM,IAAI,OAAOA,CAAG;AACpB,SAAO,OAAO,MAAM,CAAC,IAAI,OAAO;AAClC;AAEA,SAASC,EAAWC,GAAWC,GAAcC,GAAsB;AACjE,SAAID,KAAO,QAAQD,IAAIC,IAAYA,IAC/BC,KAAO,QAAQF,IAAIE,IAAYA,IAC5BF;AACT;AAGA,SAASG,GAAUH,GAAmB;AACpC,SAAO,KAAK,MAAMA,IAAI,GAAG,IAAI;AAC/B;AAGA,SAASI,GAAeC,GAAeC,GAA2B;AAChE,QAAM,CAACC,GAASC,CAAO,IAAI,OAAOH,CAAK,EAAE,MAAM,GAAG,GAC5CI,IAAOF,EAAQ,WAAW,GAAG,IAAI,MAAM,IAEvCG,KADSD,IAAOF,EAAQ,MAAM,CAAC,IAAIA,GAClB,QAAQ,yBAAyBD,CAAS;AACjE,SAAOE,KAAW,OAAO,GAAGC,CAAI,GAAGC,CAAO,IAAIF,CAAO,KAAK,GAAGC,CAAI,GAAGC,CAAO;AAC7E;AAGA,SAASC,GAAYC,GAAWC,GAAqB;AACnD,MAAIb,IAAI;AACR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AA,cAAA;AAAA,gBACC,SAAQ;AAAA,gBACR,OAAM;AAAA,gBACN,WAAWJ,EAAY;AAAA,gBACvB,UAAUxD,KAAYoD;AAAA,gBACtB,cAAY9C,EAAE,sBAAsB;AAAA,gBACpC,aAAa,CAACoC,MAAUA,EAAM,eAAA;AAAA,gBAC9B,SAAS,MAAMQ,EAAO,CAAC;AAAA,gBAEvB,UAAA,gBAAAO,EAACI,GAAA,EAAK,MAAK,MAAA,CAAM;AAAA,cAAA;AAAA,YAAA;AAAA,UACnB,EAAA,CACF;AAAA,QAAA,GAEJ;AAAA,QAECvB,KAAsB,QACrB,gBAAAmB;AAAA,UAACC;AAAA,UAAA;AAAA,YACC,IAAG;AAAA,YACH,IAAI/C;AAAA,YACJ,SAAQ;AAAA,YACR,OAAO0B,IAAgB,UAAU;AAAA,YACjC,WAAWmB,EAAY;AAAA,YAEtB,UAAAlB;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
@@ -4,7 +4,7 @@ import { clsx as T } from "clsx";
|
|
|
4
4
|
import { u as st } from "./formContext-B7ln1Miy.js";
|
|
5
5
|
import { T as R } from "./Typography-Cta6Rg4L.js";
|
|
6
6
|
import { f as d } from "./TextField.module-QePvGeJ3.js";
|
|
7
|
-
import { a as at } from "./ConfigProvider-
|
|
7
|
+
import { a as at } from "./ConfigProvider-DT0yrgmd.js";
|
|
8
8
|
const lt = "_row_1tqpn_2", nt = "_sm_1tqpn_8", ct = "_md_1tqpn_12", it = "_lg_1tqpn_16", ft = "_box_1tqpn_22", dt = "_filled_1tqpn_46", ut = "_invalid_1tqpn_63", _ = {
|
|
9
9
|
row: lt,
|
|
10
10
|
sm: nt,
|
|
@@ -168,4 +168,4 @@ const Dt = Y(function({
|
|
|
168
168
|
export {
|
|
169
169
|
Dt as O
|
|
170
170
|
};
|
|
171
|
-
//# sourceMappingURL=OtpField-
|
|
171
|
+
//# sourceMappingURL=OtpField-1ullIIZQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtpField-DLXQYMw1.js","sources":["../src/components/OtpField/OtpField.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type ClipboardEvent,\n type CSSProperties,\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useFormContext } from '../../form/formContext'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport styles from './OtpField.module.css'\n\nexport type OtpFieldSize = 'sm' | 'md' | 'lg'\n/** Which characters the code accepts. */\nexport type OtpFieldType = 'numeric' | 'alphabetic' | 'alphanumeric'\n\n/** Allowed-character matcher per `type`. */\nconst PATTERN: Record<OtpFieldType, RegExp> = {\n numeric: /[0-9]/,\n alphabetic: /[A-Za-z]/,\n alphanumeric: /[A-Za-z0-9]/,\n}\n\n/** Split a code string into exactly `length` single-char slots, padded with empties. */\nfunction toChars(value: string, length: number): string[] {\n const out = [...value].slice(0, length)\n while (out.length < length) out.push('')\n return out\n}\n\nexport interface OtpFieldProps {\n /** Number of input boxes (the code length). Defaults to `4`. */\n length?: number\n /** Which characters are accepted (also drives the mobile keyboard). Defaults to `'numeric'`. */\n type?: OtpFieldType\n /** Controlled value — the concatenated code string. */\n value?: string\n /** Initial value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the full code string on every change. */\n onChange?: (value: string) => void\n /** Fires with the code once every box is filled. */\n onComplete?: (value: string) => void\n /** Field name — the `<Form>` binding key (form value is the code `string`). */\n name?: string\n /** Label rendered above the boxes. */\n label?: ReactNode\n /** Helper / error text under the boxes (shown in the error color while `error`). */\n helperText?: ReactNode\n /** Marks the field invalid — reddens the boxes + helper. */\n error?: boolean\n /** Adds a red asterisk after the label. */\n required?: boolean\n /** Disables every box. */\n disabled?: boolean\n /** Focus the first box on mount. */\n autoFocus?: boolean\n /** Placeholder character shown in empty boxes (e.g. `'•'`). */\n placeholder?: string\n /** Preset size. Defaults to `'md'`. */\n size?: OtpFieldSize\n /** Theme palette token for the focus ring / active box. Defaults to `'primary'`. */\n color?: ThemeColor\n className?: string\n style?: CSSProperties\n}\n\n/**\n * A one-time-passcode input — a row of single-character boxes for verification codes. **`length`**\n * (default `4`) sets the box count; **`type`** (`'numeric'` default · `'alphabetic'` · `'alphanumeric'`)\n * restricts the accepted characters and the mobile keyboard. Typing advances to the next box, Backspace\n * clears + steps back, Arrows navigate, and **paste / SMS autofill** (`autocomplete=\"one-time-code\"`)\n * distributes the whole code across the boxes. The value is the concatenated string — controlled\n * (`value` + `onChange`) or uncontrolled (`defaultValue`); **`onComplete`** fires when all boxes are\n * filled. Shares the field-family chrome (`label` · `error` + `helperText` · `required` · `disabled` ·\n * `size`) and binds to a surrounding `<Form>` by **`name`** (form value = the code string; validate with\n * e.g. `z.string().length(4)` or a `type`-matching regex). Tinted by `color` via the shared\n * `--tz-btn-rgb` pattern; `role=\"group\"` with per-box `aria-label`s. Own CSS module (+ TextField's for\n * the label/helper chrome).\n */\nexport const OtpField = forwardRef<HTMLDivElement, OtpFieldProps>(function OtpField(\n {\n length = 4,\n type = 'numeric',\n value,\n defaultValue,\n onChange,\n onComplete,\n name,\n label,\n helperText,\n error,\n required = false,\n disabled = false,\n autoFocus = false,\n placeholder,\n size = 'md',\n color = 'primary',\n className,\n style,\n },\n ref,\n) {\n const t = useT()\n const reactId = useId()\n const helperId = `${reactId}-helper`\n const allowed = PATTERN[type]\n\n // bind to a surrounding <Form> by `name` — form value is the code string; error/touched via field()\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = form && name ? form.field(name) : undefined\n\n const externalValue =\n value !== undefined ? value : isFormBound ? (form!.values[name!] as string) : undefined\n const isControlled = value !== undefined || isFormBound\n const [internal, setInternal] = useState<string>(defaultValue ?? '')\n const currentValue = isControlled ? (externalValue ?? '') : internal\n\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n // the code split into exactly `length` single-char slots (padded with empties)\n const chars = toChars(currentValue, length)\n\n const inputsRef = useRef<(HTMLInputElement | null)[]>([])\n\n useEffect(() => {\n if (autoFocus) inputsRef.current[0]?.focus()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const focusBox = (i: number) => {\n const el = inputsRef.current[Math.max(0, Math.min(i, length - 1))]\n el?.focus()\n el?.select()\n }\n\n const commit = (nextChars: string[]) => {\n const next = nextChars.join('')\n if (!isControlled) setInternal(next)\n if (isFormBound) form!.setValue(name!, next)\n onChange?.(next)\n if (nextChars.every((c) => c !== '')) onComplete?.(next)\n }\n\n const handleChange = (index: number, raw: string) => {\n const filtered = [...raw].filter((c) => allowed.test(c))\n // a disallowed keystroke (raw non-empty but nothing survives the filter) is ignored\n if (raw !== '' && filtered.length === 0) return\n const nextChars = [...chars]\n if (filtered.length <= 1) {\n // a single typed char (boxes select-on-focus, so this replaces) — or a clear ('')\n nextChars[index] = filtered[0] ?? ''\n commit(nextChars)\n if (filtered[0]) focusBox(index + 1)\n } else {\n // multiple chars (SMS autofill dumps the whole code into one box) → distribute from here\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n }\n\n const handleKeyDown = (index: number, event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Backspace') {\n if (chars[index] === '' && index > 0) {\n // empty box → step back and clear the previous one\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index - 1] = ''\n commit(nextChars)\n focusBox(index - 1)\n }\n // a non-empty box lets the native delete run → onChange fires with '' (stays put)\n } else if (event.key === 'ArrowLeft') {\n event.preventDefault()\n focusBox(index - 1)\n } else if (event.key === 'ArrowRight') {\n event.preventDefault()\n focusBox(index + 1)\n } else if (event.key === 'Delete') {\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index] = ''\n commit(nextChars)\n }\n }\n\n const handlePaste = (index: number, event: ClipboardEvent<HTMLInputElement>) => {\n event.preventDefault()\n const filtered = [...event.clipboardData.getData('text')].filter((c) => allowed.test(c))\n if (filtered.length === 0) return\n const nextChars = [...chars]\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n\n // mark the field touched when focus leaves the whole widget (not when it hops between boxes)\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {\n bound?.onBlur(event as unknown as FocusEvent<HTMLInputElement>)\n }\n }\n\n return (\n <div\n ref={ref}\n className={clsx(\n fieldStyles.field,\n resolvedError && fieldStyles.error,\n disabled && fieldStyles.disabled,\n className,\n )}\n style={\n {\n '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`,\n ...style,\n } as CSSProperties\n }\n >\n {label != null && (\n <span className={fieldStyles.label}>\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\">\n {label}\n </Typography>\n {required && (\n <span className={fieldStyles.required} aria-hidden=\"true\">\n *\n </span>\n )}\n </span>\n )}\n\n <div\n role=\"group\"\n aria-label={typeof label === 'string' ? label : 'One-time code'}\n aria-invalid={resolvedError || undefined}\n aria-describedby={resolvedHelperText != null ? helperId : undefined}\n className={clsx(styles.row, styles[size], resolvedError && styles.invalid)}\n onBlur={handleBlur}\n >\n {chars.map((char, i) => (\n <input\n key={i}\n ref={(el) => {\n inputsRef.current[i] = el\n }}\n // the name goes on the first box only, so the form's scroll-to-error can target it\n name={i === 0 ? name : undefined}\n type=\"text\"\n inputMode={type === 'numeric' ? 'numeric' : 'text'}\n autoComplete={i === 0 ? 'one-time-code' : 'off'}\n aria-label={t('otpField.digit', { index: i + 1, total: length })}\n className={clsx(styles.box, char !== '' && styles.filled)}\n value={char}\n placeholder={placeholder}\n disabled={disabled}\n onChange={(e) => handleChange(i, e.target.value)}\n onKeyDown={(e) => handleKeyDown(i, e)}\n onPaste={(e) => handlePaste(i, e)}\n onFocus={(e) => e.target.select()}\n />\n ))}\n </div>\n\n {resolvedHelperText != null && (\n <Typography\n as=\"span\"\n id={helperId}\n variant=\"bodySmall\"\n color={resolvedError ? 'error' : 'muted'}\n className={fieldStyles.helper}\n >\n {resolvedHelperText}\n </Typography>\n )}\n </div>\n )\n})\n"],"names":["PATTERN","toChars","value","length","out","OtpField","forwardRef","type","defaultValue","onChange","onComplete","name","label","helperText","error","required","disabled","autoFocus","placeholder","size","color","className","style","ref","t","useT","helperId","useId","allowed","form","useFormContext","isFormBound","bound","externalValue","isControlled","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","chars","inputsRef","useRef","useEffect","_a","focusBox","i","el","commit","nextChars","next","c","handleChange","index","raw","filtered","k","ch","handleKeyDown","event","handlePaste","handleBlur","jsxs","clsx","fieldStyles","jsx","Typography","styles","char","e"],"mappings":";;;;;;;;;;;;;;;GAwBMA,KAAwC;AAAA,EAC5C,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,cAAc;AAChB;AAGA,SAASC,GAAQC,GAAeC,GAA0B;AACxD,QAAMC,IAAM,CAAC,GAAGF,CAAK,EAAE,MAAM,GAAGC,CAAM;AACtC,SAAOC,EAAI,SAASD,IAAQ,CAAAC,EAAI,KAAK,EAAE;AACvC,SAAOA;AACT;AAoDO,MAAMC,KAAWC,EAA0C,SAChE;AAAA,EACE,QAAAH,IAAS;AAAA,EACT,MAAAI,IAAO;AAAA,EACP,OAAAL;AAAA,EACA,cAAAM;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW;AAAA,EACX,WAAAC,IAAY;AAAA,EACZ,aAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,OAAAC,IAAQ;AAAA,EACR,WAAAC;AAAA,EACA,OAAAC;AACF,GACAC,GACA;AACA,QA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,YAEP,UAAArB,EAAM,IAAI,CAAC4B,GAAMtB,MAChB,gBAAAmB;AAAA,cAAC;AAAA,cAAA;AAAA,gBAEC,KAAK,CAAClB,MAAO;AACX,kBAAAN,EAAU,QAAQK,CAAC,IAAIC;AAAA,gBACzB;AAAA,gBAEA,MAAMD,MAAM,IAAIpC,IAAO;AAAA,gBACvB,MAAK;AAAA,gBACL,WAAWJ,MAAS,YAAY,YAAY;AAAA,gBAC5C,cAAcwC,MAAM,IAAI,kBAAkB;AAAA,gBAC1C,cAAYvB,EAAE,kBAAkB,EAAE,OAAOuB,IAAI,GAAG,OAAO5C,GAAQ;AAAA,gBAC/D,WAAW6D,EAAKI,EAAO,KAAKC,MAAS,MAAMD,EAAO,MAAM;AAAA,gBACxD,OAAOC;AAAA,gBACP,aAAAnD;AAAA,gBACA,UAAAF;AAAA,gBACA,UAAU,CAACsD,MAAMjB,EAAaN,GAAGuB,EAAE,OAAO,KAAK;AAAA,gBAC/C,WAAW,CAACA,MAAMX,EAAcZ,GAAGuB,CAAC;AAAA,gBACpC,SAAS,CAACA,MAAMT,EAAYd,GAAGuB,CAAC;AAAA,gBAChC,SAAS,CAACA,MAAMA,EAAE,OAAO,OAAA;AAAA,cAAO;AAAA,cAjB3BvB;AAAA,YAAA,CAmBR;AAAA,UAAA;AAAA,QAAA;AAAA,QAGFP,KAAsB,QACrB,gBAAA0B;AAAA,UAACC;AAAA,UAAA;AAAA,YACC,IAAG;AAAA,YACH,IAAIzC;AAAA,YACJ,SAAQ;AAAA,YACR,OAAOa,IAAgB,UAAU;AAAA,YACjC,WAAW0B,EAAY;AAAA,YAEtB,UAAAzB;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
1
|
+
{"version":3,"file":"OtpField-1ullIIZQ.js","sources":["../src/components/OtpField/OtpField.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type ClipboardEvent,\n type CSSProperties,\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useFormContext } from '../../form/formContext'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport styles from './OtpField.module.css'\n\nexport type OtpFieldSize = 'sm' | 'md' | 'lg'\n/** Which characters the code accepts. */\nexport type OtpFieldType = 'numeric' | 'alphabetic' | 'alphanumeric'\n\n/** Allowed-character matcher per `type`. */\nconst PATTERN: Record<OtpFieldType, RegExp> = {\n numeric: /[0-9]/,\n alphabetic: /[A-Za-z]/,\n alphanumeric: /[A-Za-z0-9]/,\n}\n\n/** Split a code string into exactly `length` single-char slots, padded with empties. */\nfunction toChars(value: string, length: number): string[] {\n const out = [...value].slice(0, length)\n while (out.length < length) out.push('')\n return out\n}\n\nexport interface OtpFieldProps {\n /** Number of input boxes (the code length). Defaults to `4`. */\n length?: number\n /** Which characters are accepted (also drives the mobile keyboard). Defaults to `'numeric'`. */\n type?: OtpFieldType\n /** Controlled value — the concatenated code string. */\n value?: string\n /** Initial value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the full code string on every change. */\n onChange?: (value: string) => void\n /** Fires with the code once every box is filled. */\n onComplete?: (value: string) => void\n /** Field name — the `<Form>` binding key (form value is the code `string`). */\n name?: string\n /** Label rendered above the boxes. */\n label?: ReactNode\n /** Helper / error text under the boxes (shown in the error color while `error`). */\n helperText?: ReactNode\n /** Marks the field invalid — reddens the boxes + helper. */\n error?: boolean\n /** Adds a red asterisk after the label. */\n required?: boolean\n /** Disables every box. */\n disabled?: boolean\n /** Focus the first box on mount. */\n autoFocus?: boolean\n /** Placeholder character shown in empty boxes (e.g. `'•'`). */\n placeholder?: string\n /** Preset size. Defaults to `'md'`. */\n size?: OtpFieldSize\n /** Theme palette token for the focus ring / active box. Defaults to `'primary'`. */\n color?: ThemeColor\n className?: string\n style?: CSSProperties\n}\n\n/**\n * A one-time-passcode input — a row of single-character boxes for verification codes. **`length`**\n * (default `4`) sets the box count; **`type`** (`'numeric'` default · `'alphabetic'` · `'alphanumeric'`)\n * restricts the accepted characters and the mobile keyboard. Typing advances to the next box, Backspace\n * clears + steps back, Arrows navigate, and **paste / SMS autofill** (`autocomplete=\"one-time-code\"`)\n * distributes the whole code across the boxes. The value is the concatenated string — controlled\n * (`value` + `onChange`) or uncontrolled (`defaultValue`); **`onComplete`** fires when all boxes are\n * filled. Shares the field-family chrome (`label` · `error` + `helperText` · `required` · `disabled` ·\n * `size`) and binds to a surrounding `<Form>` by **`name`** (form value = the code string; validate with\n * e.g. `z.string().length(4)` or a `type`-matching regex). Tinted by `color` via the shared\n * `--tz-btn-rgb` pattern; `role=\"group\"` with per-box `aria-label`s. Own CSS module (+ TextField's for\n * the label/helper chrome).\n */\nexport const OtpField = forwardRef<HTMLDivElement, OtpFieldProps>(function OtpField(\n {\n length = 4,\n type = 'numeric',\n value,\n defaultValue,\n onChange,\n onComplete,\n name,\n label,\n helperText,\n error,\n required = false,\n disabled = false,\n autoFocus = false,\n placeholder,\n size = 'md',\n color = 'primary',\n className,\n style,\n },\n ref,\n) {\n const t = useT()\n const reactId = useId()\n const helperId = `${reactId}-helper`\n const allowed = PATTERN[type]\n\n // bind to a surrounding <Form> by `name` — form value is the code string; error/touched via field()\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = form && name ? form.field(name) : undefined\n\n const externalValue =\n value !== undefined ? value : isFormBound ? (form!.values[name!] as string) : undefined\n const isControlled = value !== undefined || isFormBound\n const [internal, setInternal] = useState<string>(defaultValue ?? '')\n const currentValue = isControlled ? (externalValue ?? '') : internal\n\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n // the code split into exactly `length` single-char slots (padded with empties)\n const chars = toChars(currentValue, length)\n\n const inputsRef = useRef<(HTMLInputElement | null)[]>([])\n\n useEffect(() => {\n if (autoFocus) inputsRef.current[0]?.focus()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const focusBox = (i: number) => {\n const el = inputsRef.current[Math.max(0, Math.min(i, length - 1))]\n el?.focus()\n el?.select()\n }\n\n const commit = (nextChars: string[]) => {\n const next = nextChars.join('')\n if (!isControlled) setInternal(next)\n if (isFormBound) form!.setValue(name!, next)\n onChange?.(next)\n if (nextChars.every((c) => c !== '')) onComplete?.(next)\n }\n\n const handleChange = (index: number, raw: string) => {\n const filtered = [...raw].filter((c) => allowed.test(c))\n // a disallowed keystroke (raw non-empty but nothing survives the filter) is ignored\n if (raw !== '' && filtered.length === 0) return\n const nextChars = [...chars]\n if (filtered.length <= 1) {\n // a single typed char (boxes select-on-focus, so this replaces) — or a clear ('')\n nextChars[index] = filtered[0] ?? ''\n commit(nextChars)\n if (filtered[0]) focusBox(index + 1)\n } else {\n // multiple chars (SMS autofill dumps the whole code into one box) → distribute from here\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n }\n\n const handleKeyDown = (index: number, event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Backspace') {\n if (chars[index] === '' && index > 0) {\n // empty box → step back and clear the previous one\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index - 1] = ''\n commit(nextChars)\n focusBox(index - 1)\n }\n // a non-empty box lets the native delete run → onChange fires with '' (stays put)\n } else if (event.key === 'ArrowLeft') {\n event.preventDefault()\n focusBox(index - 1)\n } else if (event.key === 'ArrowRight') {\n event.preventDefault()\n focusBox(index + 1)\n } else if (event.key === 'Delete') {\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index] = ''\n commit(nextChars)\n }\n }\n\n const handlePaste = (index: number, event: ClipboardEvent<HTMLInputElement>) => {\n event.preventDefault()\n const filtered = [...event.clipboardData.getData('text')].filter((c) => allowed.test(c))\n if (filtered.length === 0) return\n const nextChars = [...chars]\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n\n // mark the field touched when focus leaves the whole widget (not when it hops between boxes)\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {\n bound?.onBlur(event as unknown as FocusEvent<HTMLInputElement>)\n }\n }\n\n return (\n <div\n ref={ref}\n className={clsx(\n fieldStyles.field,\n resolvedError && fieldStyles.error,\n disabled && fieldStyles.disabled,\n className,\n )}\n style={\n {\n '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`,\n ...style,\n } as CSSProperties\n }\n >\n {label != null && (\n <span className={fieldStyles.label}>\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\">\n {label}\n </Typography>\n {required && (\n <span className={fieldStyles.required} aria-hidden=\"true\">\n *\n </span>\n )}\n </span>\n )}\n\n <div\n role=\"group\"\n aria-label={typeof label === 'string' ? label : 'One-time code'}\n aria-invalid={resolvedError || undefined}\n aria-describedby={resolvedHelperText != null ? helperId : undefined}\n className={clsx(styles.row, styles[size], resolvedError && styles.invalid)}\n onBlur={handleBlur}\n >\n {chars.map((char, i) => (\n <input\n key={i}\n ref={(el) => {\n inputsRef.current[i] = el\n }}\n // the name goes on the first box only, so the form's scroll-to-error can target it\n name={i === 0 ? name : undefined}\n type=\"text\"\n inputMode={type === 'numeric' ? 'numeric' : 'text'}\n autoComplete={i === 0 ? 'one-time-code' : 'off'}\n aria-label={t('otpField.digit', { index: i + 1, total: length })}\n className={clsx(styles.box, char !== '' && styles.filled)}\n value={char}\n placeholder={placeholder}\n disabled={disabled}\n onChange={(e) => handleChange(i, e.target.value)}\n onKeyDown={(e) => handleKeyDown(i, e)}\n onPaste={(e) => handlePaste(i, e)}\n onFocus={(e) => e.target.select()}\n />\n ))}\n </div>\n\n {resolvedHelperText != null && (\n <Typography\n as=\"span\"\n id={helperId}\n variant=\"bodySmall\"\n color={resolvedError ? 'error' : 'muted'}\n className={fieldStyles.helper}\n >\n {resolvedHelperText}\n </Typography>\n )}\n </div>\n )\n})\n"],"names":["PATTERN","toChars","value","length","out","OtpField","forwardRef","type","defaultValue","onChange","onComplete","name","label","helperText","error","required","disabled","autoFocus","placeholder","size","color","className","style","ref","t","useT","helperId","useId","allowed","form","useFormContext","isFormBound","bound","externalValue","isControlled","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","chars","inputsRef","useRef","useEffect","_a","focusBox","i","el","commit","nextChars","next","c","handleChange","index","raw","filtered","k","ch","handleKeyDown","event","handlePaste","handleBlur","jsxs","clsx","fieldStyles","jsx","Typography","styles","char","e"],"mappings":";;;;;;;;;;;;;;;GAwBMA,KAAwC;AAAA,EAC5C,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,cAAc;AAChB;AAGA,SAASC,GAAQC,GAAeC,GAA0B;AACxD,QAAMC,IAAM,CAAC,GAAGF,CAAK,EAAE,MAAM,GAAGC,CAAM;AACtC,SAAOC,EAAI,SAASD,IAAQ,CAAAC,EAAI,KAAK,EAAE;AACvC,SAAOA;AACT;AAoDO,MAAMC,KAAWC,EAA0C,SAChE;AAAA,EACE,QAAAH,IAAS;AAAA,EACT,MAAAI,IAAO;AAAA,EACP,OAAAL;AAAA,EACA,cAAAM;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW;AAAA,EACX,WAAAC,IAAY;AAAA,EACZ,aAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,OAAAC,IAAQ;AAAA,EACR,WAAAC;AAAA,EACA,OAAAC;AACF,GACAC,GACA;AACA,QAAMC,IAAIC,GAAA,GAEJC,IAAW,GADDC,GAAA,CACW,WACrBC,IAAU5B,GAAQO,CAAI,GAGtBsB,IAAOC,GAAA,GACPC,IAAc,GAAQF,KAAQlB,IAC9BqB,IAAQH,KAAQlB,IAAOkB,EAAK,MAAMlB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gBAEA,MAAMD,MAAM,IAAIpC,IAAO;AAAA,gBACvB,MAAK;AAAA,gBACL,WAAWJ,MAAS,YAAY,YAAY;AAAA,gBAC5C,cAAcwC,MAAM,IAAI,kBAAkB;AAAA,gBAC1C,cAAYvB,EAAE,kBAAkB,EAAE,OAAOuB,IAAI,GAAG,OAAO5C,GAAQ;AAAA,gBAC/D,WAAW6D,EAAKI,EAAO,KAAKC,MAAS,MAAMD,EAAO,MAAM;AAAA,gBACxD,OAAOC;AAAA,gBACP,aAAAnD;AAAA,gBACA,UAAAF;AAAA,gBACA,UAAU,CAACsD,MAAMjB,EAAaN,GAAGuB,EAAE,OAAO,KAAK;AAAA,gBAC/C,WAAW,CAACA,MAAMX,EAAcZ,GAAGuB,CAAC;AAAA,gBACpC,SAAS,CAACA,MAAMT,EAAYd,GAAGuB,CAAC;AAAA,gBAChC,SAAS,CAACA,MAAMA,EAAE,OAAO,OAAA;AAAA,cAAO;AAAA,cAjB3BvB;AAAA,YAAA,CAmBR;AAAA,UAAA;AAAA,QAAA;AAAA,QAGFP,KAAsB,QACrB,gBAAA0B;AAAA,UAACC;AAAA,UAAA;AAAA,YACC,IAAG;AAAA,YACH,IAAIzC;AAAA,YACJ,SAAQ;AAAA,YACR,OAAOa,IAAgB,UAAU;AAAA,YACjC,WAAW0B,EAAY;AAAA,YAEtB,UAAAzB;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const n=require("react/jsx-runtime"),y=require("react"),j=require("clsx"),Y=require("./formContext-bTWrqdEV.cjs"),R=require("./Typography-BFatE1_A.cjs"),u=require("./TextField.module-m-UllwzG.cjs"),ee=require("./ConfigProvider-
|
|
2
|
-
//# sourceMappingURL=OtpField-
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),y=require("react"),j=require("clsx"),Y=require("./formContext-bTWrqdEV.cjs"),R=require("./Typography-BFatE1_A.cjs"),u=require("./TextField.module-m-UllwzG.cjs"),ee=require("./ConfigProvider-C7DUWHrb.cjs"),te="_row_1tqpn_2",re="_sm_1tqpn_8",se="_md_1tqpn_12",oe="_lg_1tqpn_16",le="_box_1tqpn_22",ce="_filled_1tqpn_46",ne="_invalid_1tqpn_63",x={row:te,sm:re,md:se,lg:oe,box:le,filled:ce,invalid:ne},ie={numeric:/[0-9]/,alphabetic:/[A-Za-z]/,alphanumeric:/[A-Za-z0-9]/};function ae(k,l){const i=[...k].slice(0,l);for(;i.length<l;)i.push("");return i}const fe=y.forwardRef(function({length:l=4,type:i="numeric",value:g,defaultValue:A,onChange:q,onComplete:T,name:a,label:_,helperText:I,error:z,required:O=!1,disabled:S=!1,autoFocus:P=!1,placeholder:C,size:E="md",color:M="primary",className:V,style:K},Z){const $=ee.useT(),F=`${y.useId()}-helper`,B=ie[i],p=Y.useFormContext(),b=!!(p&&a),o=p&&a?p.field(a):void 0,H=g!==void 0?g:b?p.values[a]:void 0,N=g!==void 0||b,[L,G]=y.useState(A??""),J=N?H??"":L,v=z??(o==null?void 0:o.error)??!1,w=I??(o==null?void 0:o.helperText),f=ae(J,l),D=y.useRef([]);y.useEffect(()=>{var t;P&&((t=D.current[0])==null||t.focus())},[]);const d=t=>{const e=D.current[Math.max(0,Math.min(t,l-1))];e==null||e.focus(),e==null||e.select()},m=t=>{const e=t.join("");N||G(e),b&&p.setValue(a,e),q==null||q(e),t.every(r=>r!=="")&&(T==null||T(e))},Q=(t,e)=>{const r=[...e].filter(s=>B.test(s));if(e!==""&&r.length===0)return;const c=[...f];if(r.length<=1)c[t]=r[0]??"",m(c),r[0]&&d(t+1);else{let s=t;for(const h of r){if(s>=l)break;c[s]=h,s++}m(c),d(s)}},U=(t,e)=>{if(e.key==="Backspace"){if(f[t]===""&&t>0){e.preventDefault();const r=[...f];r[t-1]="",m(r),d(t-1)}}else if(e.key==="ArrowLeft")e.preventDefault(),d(t-1);else if(e.key==="ArrowRight")e.preventDefault(),d(t+1);else if(e.key==="Delete"){e.preventDefault();const r=[...f];r[t]="",m(r)}},W=(t,e)=>{e.preventDefault();const r=[...e.clipboardData.getData("text")].filter(h=>B.test(h));if(r.length===0)return;const c=[...f];let s=t;for(const h of r){if(s>=l)break;c[s]=h,s++}m(c),d(s)},X=t=>{t.currentTarget.contains(t.relatedTarget)||o==null||o.onBlur(t)};return n.jsxs("div",{ref:Z,className:j.clsx(u.fieldStyles.field,v&&u.fieldStyles.error,S&&u.fieldStyles.disabled,V),style:{"--tz-btn-rgb":`var(--tz-color-${M}-rgb)`,...K},children:[_!=null&&n.jsxs("span",{className:u.fieldStyles.label,children:[n.jsx(R.Typography,{as:"span",variant:"bodySmall",color:"muted",children:_}),O&&n.jsx("span",{className:u.fieldStyles.required,"aria-hidden":"true",children:"*"})]}),n.jsx("div",{role:"group","aria-label":typeof _=="string"?_:"One-time code","aria-invalid":v||void 0,"aria-describedby":w!=null?F:void 0,className:j.clsx(x.row,x[E],v&&x.invalid),onBlur:X,children:f.map((t,e)=>n.jsx("input",{ref:r=>{D.current[e]=r},name:e===0?a:void 0,type:"text",inputMode:i==="numeric"?"numeric":"text",autoComplete:e===0?"one-time-code":"off","aria-label":$("otpField.digit",{index:e+1,total:l}),className:j.clsx(x.box,t!==""&&x.filled),value:t,placeholder:C,disabled:S,onChange:r=>Q(e,r.target.value),onKeyDown:r=>U(e,r),onPaste:r=>W(e,r),onFocus:r=>r.target.select()},e))}),w!=null&&n.jsx(R.Typography,{as:"span",id:F,variant:"bodySmall",color:v?"error":"muted",className:u.fieldStyles.helper,children:w})]})});exports.OtpField=fe;
|
|
2
|
+
//# sourceMappingURL=OtpField-BYj9SDHb.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtpField-B46P6aMy.cjs","sources":["../src/components/OtpField/OtpField.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type ClipboardEvent,\n type CSSProperties,\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useFormContext } from '../../form/formContext'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport styles from './OtpField.module.css'\n\nexport type OtpFieldSize = 'sm' | 'md' | 'lg'\n/** Which characters the code accepts. */\nexport type OtpFieldType = 'numeric' | 'alphabetic' | 'alphanumeric'\n\n/** Allowed-character matcher per `type`. */\nconst PATTERN: Record<OtpFieldType, RegExp> = {\n numeric: /[0-9]/,\n alphabetic: /[A-Za-z]/,\n alphanumeric: /[A-Za-z0-9]/,\n}\n\n/** Split a code string into exactly `length` single-char slots, padded with empties. */\nfunction toChars(value: string, length: number): string[] {\n const out = [...value].slice(0, length)\n while (out.length < length) out.push('')\n return out\n}\n\nexport interface OtpFieldProps {\n /** Number of input boxes (the code length). Defaults to `4`. */\n length?: number\n /** Which characters are accepted (also drives the mobile keyboard). Defaults to `'numeric'`. */\n type?: OtpFieldType\n /** Controlled value — the concatenated code string. */\n value?: string\n /** Initial value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the full code string on every change. */\n onChange?: (value: string) => void\n /** Fires with the code once every box is filled. */\n onComplete?: (value: string) => void\n /** Field name — the `<Form>` binding key (form value is the code `string`). */\n name?: string\n /** Label rendered above the boxes. */\n label?: ReactNode\n /** Helper / error text under the boxes (shown in the error color while `error`). */\n helperText?: ReactNode\n /** Marks the field invalid — reddens the boxes + helper. */\n error?: boolean\n /** Adds a red asterisk after the label. */\n required?: boolean\n /** Disables every box. */\n disabled?: boolean\n /** Focus the first box on mount. */\n autoFocus?: boolean\n /** Placeholder character shown in empty boxes (e.g. `'•'`). */\n placeholder?: string\n /** Preset size. Defaults to `'md'`. */\n size?: OtpFieldSize\n /** Theme palette token for the focus ring / active box. Defaults to `'primary'`. */\n color?: ThemeColor\n className?: string\n style?: CSSProperties\n}\n\n/**\n * A one-time-passcode input — a row of single-character boxes for verification codes. **`length`**\n * (default `4`) sets the box count; **`type`** (`'numeric'` default · `'alphabetic'` · `'alphanumeric'`)\n * restricts the accepted characters and the mobile keyboard. Typing advances to the next box, Backspace\n * clears + steps back, Arrows navigate, and **paste / SMS autofill** (`autocomplete=\"one-time-code\"`)\n * distributes the whole code across the boxes. The value is the concatenated string — controlled\n * (`value` + `onChange`) or uncontrolled (`defaultValue`); **`onComplete`** fires when all boxes are\n * filled. Shares the field-family chrome (`label` · `error` + `helperText` · `required` · `disabled` ·\n * `size`) and binds to a surrounding `<Form>` by **`name`** (form value = the code string; validate with\n * e.g. `z.string().length(4)` or a `type`-matching regex). Tinted by `color` via the shared\n * `--tz-btn-rgb` pattern; `role=\"group\"` with per-box `aria-label`s. Own CSS module (+ TextField's for\n * the label/helper chrome).\n */\nexport const OtpField = forwardRef<HTMLDivElement, OtpFieldProps>(function OtpField(\n {\n length = 4,\n type = 'numeric',\n value,\n defaultValue,\n onChange,\n onComplete,\n name,\n label,\n helperText,\n error,\n required = false,\n disabled = false,\n autoFocus = false,\n placeholder,\n size = 'md',\n color = 'primary',\n className,\n style,\n },\n ref,\n) {\n const t = useT()\n const reactId = useId()\n const helperId = `${reactId}-helper`\n const allowed = PATTERN[type]\n\n // bind to a surrounding <Form> by `name` — form value is the code string; error/touched via field()\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = form && name ? form.field(name) : undefined\n\n const externalValue =\n value !== undefined ? value : isFormBound ? (form!.values[name!] as string) : undefined\n const isControlled = value !== undefined || isFormBound\n const [internal, setInternal] = useState<string>(defaultValue ?? '')\n const currentValue = isControlled ? (externalValue ?? '') : internal\n\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n // the code split into exactly `length` single-char slots (padded with empties)\n const chars = toChars(currentValue, length)\n\n const inputsRef = useRef<(HTMLInputElement | null)[]>([])\n\n useEffect(() => {\n if (autoFocus) inputsRef.current[0]?.focus()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const focusBox = (i: number) => {\n const el = inputsRef.current[Math.max(0, Math.min(i, length - 1))]\n el?.focus()\n el?.select()\n }\n\n const commit = (nextChars: string[]) => {\n const next = nextChars.join('')\n if (!isControlled) setInternal(next)\n if (isFormBound) form!.setValue(name!, next)\n onChange?.(next)\n if (nextChars.every((c) => c !== '')) onComplete?.(next)\n }\n\n const handleChange = (index: number, raw: string) => {\n const filtered = [...raw].filter((c) => allowed.test(c))\n // a disallowed keystroke (raw non-empty but nothing survives the filter) is ignored\n if (raw !== '' && filtered.length === 0) return\n const nextChars = [...chars]\n if (filtered.length <= 1) {\n // a single typed char (boxes select-on-focus, so this replaces) — or a clear ('')\n nextChars[index] = filtered[0] ?? ''\n commit(nextChars)\n if (filtered[0]) focusBox(index + 1)\n } else {\n // multiple chars (SMS autofill dumps the whole code into one box) → distribute from here\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n }\n\n const handleKeyDown = (index: number, event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Backspace') {\n if (chars[index] === '' && index > 0) {\n // empty box → step back and clear the previous one\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index - 1] = ''\n commit(nextChars)\n focusBox(index - 1)\n }\n // a non-empty box lets the native delete run → onChange fires with '' (stays put)\n } else if (event.key === 'ArrowLeft') {\n event.preventDefault()\n focusBox(index - 1)\n } else if (event.key === 'ArrowRight') {\n event.preventDefault()\n focusBox(index + 1)\n } else if (event.key === 'Delete') {\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index] = ''\n commit(nextChars)\n }\n }\n\n const handlePaste = (index: number, event: ClipboardEvent<HTMLInputElement>) => {\n event.preventDefault()\n const filtered = [...event.clipboardData.getData('text')].filter((c) => allowed.test(c))\n if (filtered.length === 0) return\n const nextChars = [...chars]\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n\n // mark the field touched when focus leaves the whole widget (not when it hops between boxes)\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {\n bound?.onBlur(event as unknown as FocusEvent<HTMLInputElement>)\n }\n }\n\n return (\n <div\n ref={ref}\n className={clsx(\n fieldStyles.field,\n resolvedError && fieldStyles.error,\n disabled && fieldStyles.disabled,\n className,\n )}\n style={\n {\n '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`,\n ...style,\n } as CSSProperties\n }\n >\n {label != null && (\n <span className={fieldStyles.label}>\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\">\n {label}\n </Typography>\n {required && (\n <span className={fieldStyles.required} aria-hidden=\"true\">\n *\n </span>\n )}\n </span>\n )}\n\n <div\n role=\"group\"\n aria-label={typeof label === 'string' ? label : 'One-time code'}\n aria-invalid={resolvedError || undefined}\n aria-describedby={resolvedHelperText != null ? helperId : undefined}\n className={clsx(styles.row, styles[size], resolvedError && styles.invalid)}\n onBlur={handleBlur}\n >\n {chars.map((char, i) => (\n <input\n key={i}\n ref={(el) => {\n inputsRef.current[i] = el\n }}\n // the name goes on the first box only, so the form's scroll-to-error can target it\n name={i === 0 ? name : undefined}\n type=\"text\"\n inputMode={type === 'numeric' ? 'numeric' : 'text'}\n autoComplete={i === 0 ? 'one-time-code' : 'off'}\n aria-label={t('otpField.digit', { index: i + 1, total: length })}\n className={clsx(styles.box, char !== '' && styles.filled)}\n value={char}\n placeholder={placeholder}\n disabled={disabled}\n onChange={(e) => handleChange(i, e.target.value)}\n onKeyDown={(e) => handleKeyDown(i, e)}\n onPaste={(e) => handlePaste(i, e)}\n onFocus={(e) => e.target.select()}\n />\n ))}\n </div>\n\n {resolvedHelperText != null && (\n <Typography\n as=\"span\"\n id={helperId}\n variant=\"bodySmall\"\n color={resolvedError ? 'error' : 'muted'}\n className={fieldStyles.helper}\n >\n {resolvedHelperText}\n </Typography>\n )}\n </div>\n )\n})\n"],"names":["PATTERN","toChars","value","length","out","OtpField","forwardRef","type","defaultValue","onChange","onComplete","name","label","helperText","error","required","disabled","autoFocus","placeholder","size","color","className","style","ref","t","useT","helperId","useId","allowed","form","useFormContext","isFormBound","bound","externalValue","isControlled","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","chars","inputsRef","useRef","useEffect","_a","focusBox","i","el","commit","nextChars","next","c","handleChange","index","raw","filtered","k","ch","handleKeyDown","event","handlePaste","handleBlur","jsxs","clsx","fieldStyles","jsx","Typography","styles","char","e"],"mappings":"+bAwBMA,GAAwC,CAC5C,QAAS,QACT,WAAY,WACZ,aAAc,aAChB,EAGA,SAASC,GAAQC,EAAeC,EAA0B,CACxD,MAAMC,EAAM,CAAC,GAAGF,CAAK,EAAE,MAAM,EAAGC,CAAM,EACtC,KAAOC,EAAI,OAASD,GAAQC,EAAI,KAAK,EAAE,EACvC,OAAOA,CACT,CAoDO,MAAMC,GAAWC,EAAAA,WAA0C,SAChE,CACE,OAAAH,EAAS,EACT,KAAAI,EAAO,UACP,MAAAL,EACA,aAAAM,EACA,SAAAC,EACA,WAAAC,EACA,KAAAC,EACA,MAAAC,EACA,WAAAC,EACA,MAAAC,EACA,SAAAC,EAAW,GACX,SAAAC,EAAW,GACX,UAAAC,EAAY,GACZ,YAAAC,EACA,KAAAC,EAAO,KACP,MAAAC,EAAQ,UACR,UAAAC,EACA,MAAAC,CACF,EACAC,EACA,CACA,MAAMC,EAAIC,GAAAA,KAAA,EAEJC,EAAW,GADDC,EAAAA,MAAA,CACW,UACrBC,EAAU5B,GAAQO,CAAI,EAGtBsB,EAAOC,EAAAA,eAAA,EACPC,EAAc,GAAQF,GAAQlB,GAC9BqB,EAAQH,GAAQlB,EAAOkB,EAAK,MAAMlB,CAAI,EAAI,OAE1CsB,EACJ/B,IAAU,OAAYA,EAAQ6B,EAAeF,EAAM,OAAOlB,CAAK,EAAe,OAC1EuB,EAAehC,IAAU,QAAa6B,EACtC,CAACI,EAAUC,C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AAA,EAGFP,GAAsB,MACrB0B,EAAAA,IAACC,EAAAA,WAAA,CACC,GAAG,OACH,GAAIzC,EACJ,QAAQ,YACR,MAAOa,EAAgB,QAAU,QACjC,UAAW0B,EAAAA,YAAY,OAEtB,SAAAzB,CAAA,CAAA,CACH,CAAA,CAAA,CAIR,CAAC"}
|
|
1
|
+
{"version":3,"file":"OtpField-BYj9SDHb.cjs","sources":["../src/components/OtpField/OtpField.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type ClipboardEvent,\n type CSSProperties,\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useFormContext } from '../../form/formContext'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport styles from './OtpField.module.css'\n\nexport type OtpFieldSize = 'sm' | 'md' | 'lg'\n/** Which characters the code accepts. */\nexport type OtpFieldType = 'numeric' | 'alphabetic' | 'alphanumeric'\n\n/** Allowed-character matcher per `type`. */\nconst PATTERN: Record<OtpFieldType, RegExp> = {\n numeric: /[0-9]/,\n alphabetic: /[A-Za-z]/,\n alphanumeric: /[A-Za-z0-9]/,\n}\n\n/** Split a code string into exactly `length` single-char slots, padded with empties. */\nfunction toChars(value: string, length: number): string[] {\n const out = [...value].slice(0, length)\n while (out.length < length) out.push('')\n return out\n}\n\nexport interface OtpFieldProps {\n /** Number of input boxes (the code length). Defaults to `4`. */\n length?: number\n /** Which characters are accepted (also drives the mobile keyboard). Defaults to `'numeric'`. */\n type?: OtpFieldType\n /** Controlled value — the concatenated code string. */\n value?: string\n /** Initial value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the full code string on every change. */\n onChange?: (value: string) => void\n /** Fires with the code once every box is filled. */\n onComplete?: (value: string) => void\n /** Field name — the `<Form>` binding key (form value is the code `string`). */\n name?: string\n /** Label rendered above the boxes. */\n label?: ReactNode\n /** Helper / error text under the boxes (shown in the error color while `error`). */\n helperText?: ReactNode\n /** Marks the field invalid — reddens the boxes + helper. */\n error?: boolean\n /** Adds a red asterisk after the label. */\n required?: boolean\n /** Disables every box. */\n disabled?: boolean\n /** Focus the first box on mount. */\n autoFocus?: boolean\n /** Placeholder character shown in empty boxes (e.g. `'•'`). */\n placeholder?: string\n /** Preset size. Defaults to `'md'`. */\n size?: OtpFieldSize\n /** Theme palette token for the focus ring / active box. Defaults to `'primary'`. */\n color?: ThemeColor\n className?: string\n style?: CSSProperties\n}\n\n/**\n * A one-time-passcode input — a row of single-character boxes for verification codes. **`length`**\n * (default `4`) sets the box count; **`type`** (`'numeric'` default · `'alphabetic'` · `'alphanumeric'`)\n * restricts the accepted characters and the mobile keyboard. Typing advances to the next box, Backspace\n * clears + steps back, Arrows navigate, and **paste / SMS autofill** (`autocomplete=\"one-time-code\"`)\n * distributes the whole code across the boxes. The value is the concatenated string — controlled\n * (`value` + `onChange`) or uncontrolled (`defaultValue`); **`onComplete`** fires when all boxes are\n * filled. Shares the field-family chrome (`label` · `error` + `helperText` · `required` · `disabled` ·\n * `size`) and binds to a surrounding `<Form>` by **`name`** (form value = the code string; validate with\n * e.g. `z.string().length(4)` or a `type`-matching regex). Tinted by `color` via the shared\n * `--tz-btn-rgb` pattern; `role=\"group\"` with per-box `aria-label`s. Own CSS module (+ TextField's for\n * the label/helper chrome).\n */\nexport const OtpField = forwardRef<HTMLDivElement, OtpFieldProps>(function OtpField(\n {\n length = 4,\n type = 'numeric',\n value,\n defaultValue,\n onChange,\n onComplete,\n name,\n label,\n helperText,\n error,\n required = false,\n disabled = false,\n autoFocus = false,\n placeholder,\n size = 'md',\n color = 'primary',\n className,\n style,\n },\n ref,\n) {\n const t = useT()\n const reactId = useId()\n const helperId = `${reactId}-helper`\n const allowed = PATTERN[type]\n\n // bind to a surrounding <Form> by `name` — form value is the code string; error/touched via field()\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = form && name ? form.field(name) : undefined\n\n const externalValue =\n value !== undefined ? value : isFormBound ? (form!.values[name!] as string) : undefined\n const isControlled = value !== undefined || isFormBound\n const [internal, setInternal] = useState<string>(defaultValue ?? '')\n const currentValue = isControlled ? (externalValue ?? '') : internal\n\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n // the code split into exactly `length` single-char slots (padded with empties)\n const chars = toChars(currentValue, length)\n\n const inputsRef = useRef<(HTMLInputElement | null)[]>([])\n\n useEffect(() => {\n if (autoFocus) inputsRef.current[0]?.focus()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const focusBox = (i: number) => {\n const el = inputsRef.current[Math.max(0, Math.min(i, length - 1))]\n el?.focus()\n el?.select()\n }\n\n const commit = (nextChars: string[]) => {\n const next = nextChars.join('')\n if (!isControlled) setInternal(next)\n if (isFormBound) form!.setValue(name!, next)\n onChange?.(next)\n if (nextChars.every((c) => c !== '')) onComplete?.(next)\n }\n\n const handleChange = (index: number, raw: string) => {\n const filtered = [...raw].filter((c) => allowed.test(c))\n // a disallowed keystroke (raw non-empty but nothing survives the filter) is ignored\n if (raw !== '' && filtered.length === 0) return\n const nextChars = [...chars]\n if (filtered.length <= 1) {\n // a single typed char (boxes select-on-focus, so this replaces) — or a clear ('')\n nextChars[index] = filtered[0] ?? ''\n commit(nextChars)\n if (filtered[0]) focusBox(index + 1)\n } else {\n // multiple chars (SMS autofill dumps the whole code into one box) → distribute from here\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n }\n\n const handleKeyDown = (index: number, event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Backspace') {\n if (chars[index] === '' && index > 0) {\n // empty box → step back and clear the previous one\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index - 1] = ''\n commit(nextChars)\n focusBox(index - 1)\n }\n // a non-empty box lets the native delete run → onChange fires with '' (stays put)\n } else if (event.key === 'ArrowLeft') {\n event.preventDefault()\n focusBox(index - 1)\n } else if (event.key === 'ArrowRight') {\n event.preventDefault()\n focusBox(index + 1)\n } else if (event.key === 'Delete') {\n event.preventDefault()\n const nextChars = [...chars]\n nextChars[index] = ''\n commit(nextChars)\n }\n }\n\n const handlePaste = (index: number, event: ClipboardEvent<HTMLInputElement>) => {\n event.preventDefault()\n const filtered = [...event.clipboardData.getData('text')].filter((c) => allowed.test(c))\n if (filtered.length === 0) return\n const nextChars = [...chars]\n let k = index\n for (const ch of filtered) {\n if (k >= length) break\n nextChars[k] = ch\n k++\n }\n commit(nextChars)\n focusBox(k)\n }\n\n // mark the field touched when focus leaves the whole widget (not when it hops between boxes)\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {\n bound?.onBlur(event as unknown as FocusEvent<HTMLInputElement>)\n }\n }\n\n return (\n <div\n ref={ref}\n className={clsx(\n fieldStyles.field,\n resolvedError && fieldStyles.error,\n disabled && fieldStyles.disabled,\n className,\n )}\n style={\n {\n '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`,\n ...style,\n } as CSSProperties\n }\n >\n {label != null && (\n <span className={fieldStyles.label}>\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\">\n {label}\n </Typography>\n {required && (\n <span className={fieldStyles.required} aria-hidden=\"true\">\n *\n </span>\n )}\n </span>\n )}\n\n <div\n role=\"group\"\n aria-label={typeof label === 'string' ? label : 'One-time code'}\n aria-invalid={resolvedError || undefined}\n aria-describedby={resolvedHelperText != null ? helperId : undefined}\n className={clsx(styles.row, styles[size], resolvedError && styles.invalid)}\n onBlur={handleBlur}\n >\n {chars.map((char, i) => (\n <input\n key={i}\n ref={(el) => {\n inputsRef.current[i] = el\n }}\n // the name goes on the first box only, so the form's scroll-to-error can target it\n name={i === 0 ? name : undefined}\n type=\"text\"\n inputMode={type === 'numeric' ? 'numeric' : 'text'}\n autoComplete={i === 0 ? 'one-time-code' : 'off'}\n aria-label={t('otpField.digit', { index: i + 1, total: length })}\n className={clsx(styles.box, char !== '' && styles.filled)}\n value={char}\n placeholder={placeholder}\n disabled={disabled}\n onChange={(e) => handleChange(i, e.target.value)}\n onKeyDown={(e) => handleKeyDown(i, e)}\n onPaste={(e) => handlePaste(i, e)}\n onFocus={(e) => e.target.select()}\n />\n ))}\n </div>\n\n {resolvedHelperText != null && (\n <Typography\n as=\"span\"\n id={helperId}\n variant=\"bodySmall\"\n color={resolvedError ? 'error' : 'muted'}\n className={fieldStyles.helper}\n >\n {resolvedHelperText}\n </Typography>\n )}\n </div>\n )\n})\n"],"names":["PATTERN","toChars","value","length","out","OtpField","forwardRef","type","defaultValue","onChange","onComplete","name","label","helperText","error","required","disabled","autoFocus","placeholder","size","color","className","style","ref","t","useT","helperId","useId","allowed","form","useFormContext","isFormBound","bound","externalValue","isControlled","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","chars","inputsRef","useRef","useEffect","_a","focusBox","i","el","commit","nextChars","next","c","handleChange","index","raw","filtered","k","ch","handleKeyDown","event","handlePaste","handleBlur","jsxs","clsx","fieldStyles","jsx","Typography","styles","char","e"],"mappings":"+bAwBMA,GAAwC,CAC5C,QAAS,QACT,WAAY,WACZ,aAAc,aAChB,EAGA,SAASC,GAAQC,EAAeC,EAA0B,CACxD,MAAMC,EAAM,CAAC,GAAGF,CAAK,EAAE,MAAM,EAAGC,CAAM,EACtC,KAAOC,EAAI,OAASD,GAAQC,EAAI,KAAK,EAAE,EACvC,OAAOA,CACT,CAoDO,MAAMC,GAAWC,EAAAA,WAA0C,SAChE,CACE,OAAAH,EAAS,EACT,KAAAI,EAAO,UACP,MAAAL,EACA,aAAAM,EACA,SAAAC,EACA,WAAAC,EACA,KAAAC,EACA,MAAAC,EACA,WAAAC,EACA,MAAAC,EACA,SAAAC,EAAW,GACX,SAAAC,EAAW,GACX,UAAAC,EAAY,GACZ,YAAAC,EACA,KAAAC,EAAO,KACP,MAAAC,EAAQ,UACR,UAAAC,EAC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,CAAE,MAAOuB,EAAI,EAAG,MAAO5C,EAAQ,EAC/D,UAAW6D,EAAAA,KAAKI,EAAO,IAAKC,IAAS,IAAMD,EAAO,MAAM,EACxD,MAAOC,EACP,YAAAnD,EACA,SAAAF,EACA,SAAWsD,GAAMjB,EAAaN,EAAGuB,EAAE,OAAO,KAAK,EAC/C,UAAYA,GAAMX,EAAcZ,EAAGuB,CAAC,EACpC,QAAUA,GAAMT,EAAYd,EAAGuB,CAAC,EAChC,QAAUA,GAAMA,EAAE,OAAO,OAAA,CAAO,EAjB3BvB,CAAA,CAmBR,CAAA,CAAA,EAGFP,GAAsB,MACrB0B,EAAAA,IAACC,EAAAA,WAAA,CACC,GAAG,OACH,GAAIzC,EACJ,QAAQ,YACR,MAAOa,EAAgB,QAAU,QACjC,UAAW0B,EAAAA,YAAY,OAEtB,SAAAzB,CAAA,CAAA,CACH,CAAA,CAAA,CAIR,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const t=require("react/jsx-runtime"),a=require("react"),u=require("./Card-
|
|
2
|
-
//# sourceMappingURL=PageLayout-
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),a=require("react"),u=require("./Card-BYFuYD-a.cjs"),o=a.forwardRef(function(e,r){return t.jsx(u.Card,{ref:r,flat:!0,...e})});exports.PageLayout=o;
|
|
2
|
+
//# sourceMappingURL=PageLayout-pYL43wI9.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageLayout-
|
|
1
|
+
{"version":3,"file":"PageLayout-pYL43wI9.cjs","sources":["../src/components/PageLayout/PageLayout.tsx"],"sourcesContent":["import { forwardRef } from 'react'\nimport { Card, type CardProps } from '../Card'\n\n/** PageLayout is a flat `Card`, so it gains all of Card's slots minus the `flat` toggle (always flat). */\nexport interface PageLayoutProps extends Omit<CardProps, 'flat'> {}\n\n/**\n * The content container a page's body sits in — a **flat `Card`** (no shadow, the page `background`\n * color), so it blends with the shell while the Cards/inputs placed inside it read as elevated. Being\n * a Card, it gains the full Card anatomy: an optional header (`icon` + `title` + `subtitle` +\n * `actions`), the body (`children`), a `footer` / `footerStart`, and `collapsible`. Rendered by the\n * consumer inside each route, below the shell's breadcrumbs + page title:\n * `<PageLayout title=\"Settings\" actions={…}>…</PageLayout>`. Styling uses `--tz-*` tokens only.\n */\nexport const PageLayout = forwardRef<HTMLDivElement, PageLayoutProps>(\n function PageLayout(props, ref) {\n return <Card ref={ref} flat {...props} />\n },\n)\n"],"names":["PageLayout","forwardRef","props","ref","Card"],"mappings":"sGAcaA,EAAaC,EAAAA,WACxB,SAAoBC,EAAOC,EAAK,CAC9B,aAAQC,EAAAA,KAAA,CAAK,IAAAD,EAAU,KAAI,GAAE,GAAGD,EAAO,CACzC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef as a } from "react";
|
|
3
|
-
import { C as f } from "./Card-
|
|
3
|
+
import { C as f } from "./Card-B0bYi4g2.js";
|
|
4
4
|
const n = a(
|
|
5
5
|
function(r, o) {
|
|
6
6
|
return /* @__PURE__ */ t(f, { ref: o, flat: !0, ...r });
|
|
@@ -9,4 +9,4 @@ const n = a(
|
|
|
9
9
|
export {
|
|
10
10
|
n as P
|
|
11
11
|
};
|
|
12
|
-
//# sourceMappingURL=PageLayout-
|
|
12
|
+
//# sourceMappingURL=PageLayout-qf0H_EmS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageLayout-
|
|
1
|
+
{"version":3,"file":"PageLayout-qf0H_EmS.js","sources":["../src/components/PageLayout/PageLayout.tsx"],"sourcesContent":["import { forwardRef } from 'react'\nimport { Card, type CardProps } from '../Card'\n\n/** PageLayout is a flat `Card`, so it gains all of Card's slots minus the `flat` toggle (always flat). */\nexport interface PageLayoutProps extends Omit<CardProps, 'flat'> {}\n\n/**\n * The content container a page's body sits in — a **flat `Card`** (no shadow, the page `background`\n * color), so it blends with the shell while the Cards/inputs placed inside it read as elevated. Being\n * a Card, it gains the full Card anatomy: an optional header (`icon` + `title` + `subtitle` +\n * `actions`), the body (`children`), a `footer` / `footerStart`, and `collapsible`. Rendered by the\n * consumer inside each route, below the shell's breadcrumbs + page title:\n * `<PageLayout title=\"Settings\" actions={…}>…</PageLayout>`. Styling uses `--tz-*` tokens only.\n */\nexport const PageLayout = forwardRef<HTMLDivElement, PageLayoutProps>(\n function PageLayout(props, ref) {\n return <Card ref={ref} flat {...props} />\n },\n)\n"],"names":["PageLayout","forwardRef","props","ref","Card"],"mappings":";;;AAcO,MAAMA,IAAaC;AAAA,EACxB,SAAoBC,GAAOC,GAAK;AAC9B,6BAAQC,GAAA,EAAK,KAAAD,GAAU,MAAI,IAAE,GAAGD,GAAO;AAAA,EACzC;AACF;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const c=require("react/jsx-runtime"),a=require("react"),m=require("@tanstack/react-router"),u=require("./access-DPUHbE-S.cjs"),y=require("./EmptyState-
|
|
2
|
-
//# sourceMappingURL=PageNotFound-
|
|
1
|
+
"use strict";const c=require("react/jsx-runtime"),a=require("react"),m=require("@tanstack/react-router"),u=require("./access-DPUHbE-S.cjs"),y=require("./EmptyState-Bj-vX_UV.cjs"),R=require("./Button-BdihbLYJ.cjs"),i=require("./Sidebar-Cv95DJxZ.cjs"),S=require("./ConfigProvider-C7DUWHrb.cjs"),j=a.forwardRef(function({icon:l="SearchStatus",title:d,description:f,actionLabel:v,to:s,showAction:q=!0,...g},p){const n=S.useT(),t=m.useRouter({warn:!1}),F=u.useAccessKeys(),r=a.useMemo(()=>{if(s!=null)return s;if(!t)return;const h=i.buildNavTree(Object.values(t.looseRoutesById).map(o=>{var e;return{fullPath:o.fullPath,staticData:(e=o.options)==null?void 0:e.staticData}}).filter(o=>{var e;return u.hasAccess((e=o.staticData)==null?void 0:e.roles)}));return i.firstNavTo(h)??"/"},[t,s,F]),N=!!t&&r!=null,P=q&&N?c.jsx(R.Button,{onClick:()=>t.navigate({to:r}),children:v??n("notFound.action")}):void 0;return c.jsx(y.EmptyState,{ref:p,icon:l,title:d??n("notFound.title"),description:f??n("notFound.description"),action:P,...g})});exports.PageNotFound=j;
|
|
2
|
+
//# sourceMappingURL=PageNotFound-D1795gJ7.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageNotFound-
|
|
1
|
+
{"version":3,"file":"PageNotFound-D1795gJ7.cjs","sources":["../src/components/PageNotFound/PageNotFound.tsx"],"sourcesContent":["import { forwardRef, useMemo, type HTMLAttributes, type ReactNode } from 'react'\nimport { useRouter, type LinkProps } from '@tanstack/react-router'\nimport { useT } from '../../theme'\nimport { hasAccess, useAccessKeys } from '../../helpers/access'\nimport { EmptyState, type EmptyStateSize } from '../EmptyState'\nimport { Button } from '../Button'\nimport { buildNavTree, firstNavTo } from '../Sidebar/Sidebar'\nimport type { IconName } from '../../icons/names'\n\nexport interface PageNotFoundProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {\n /** Hero glyph — an `IconName`, any node, or `false` to hide it. Defaults to `SearchStatus`. */\n icon?: IconName | ReactNode | false\n /** Heading. Defaults to the localized `notFound.title`. */\n title?: ReactNode\n /** Muted description. Defaults to the localized `notFound.description`. */\n description?: ReactNode\n /** Action button label. Defaults to the localized `notFound.action`. */\n actionLabel?: ReactNode\n /** Where the action navigates. Defaults to the first allowed menu page (RBAC-aware), else `/`. */\n to?: string\n /** Show the \"back home\" action button. Defaults to `true` (hidden anyway when there's no router). */\n showAction?: boolean\n /** Faded-grid hero backdrop — passed to `EmptyState`. Defaults to `true` (its default). */\n pattern?: boolean\n /** Size — passed to `EmptyState`. Defaults to `md`. */\n size?: EmptyStateSize\n}\n\n/**\n * The shared **404** page. Drop it straight into TanStack Router as the\n * `defaultNotFoundComponent` — zero props needed: the title/description/action strings come from the\n * built-in i18n (`useT`), so they translate with the panel language, and the action navigates to the\n * **first allowed menu page** (the same RBAC-aware target as `FirstRouteRedirect`), falling back to\n * `/`. Built on `EmptyState` (hero glyph + title + description + action, `pattern` on by default), so\n * it renders inside the `RootLayout` content area with the shell/sidebar intact. Lenient: with no\n * router context the `EmptyState` still renders, just without the action button. Token-only styling.\n *\n * @example\n * const router = createRouter({ routeTree, defaultNotFoundComponent: PageNotFound })\n */\nexport const PageNotFound = forwardRef<HTMLDivElement, PageNotFoundProps>(function PageNotFound(\n { icon = 'SearchStatus', title, description, actionLabel, to, showAction = true, ...props },\n ref,\n) {\n const t = useT()\n // lenient router access — returns undefined (no throw) outside a <RouterProvider>\n const router = useRouter({ warn: false })\n const accessKeys = useAccessKeys()\n\n // the first allowed menu page — same logic as FirstRouteRedirect, RBAC-aware; `/` fallback\n const resolvedTo = useMemo(() => {\n if (to != null) return to\n if (!router) return undefined\n const tree = buildNavTree(\n Object.values(router.looseRoutesById)\n .map((route) => ({ fullPath: route.fullPath, staticData: route.options?.staticData }))\n .filter((route) => hasAccess(route.staticData?.roles)),\n )\n return firstNavTo(tree) ?? '/'\n }, [router, to, accessKeys])\n\n const canNavigate = !!router && resolvedTo != null\n const action =\n showAction && canNavigate ? (\n <Button onClick={() => router.navigate({ to: resolvedTo as LinkProps['to'] })}>\n {actionLabel ?? t('notFound.action')}\n </Button>\n ) : undefined\n\n return (\n <EmptyState\n ref={ref}\n icon={icon}\n title={title ?? t('notFound.title')}\n description={description ?? t('notFound.description')}\n action={action}\n {...props}\n />\n )\n})\n"],"names":["PageNotFound","forwardRef","icon","title","description","actionLabel","to","showAction","props","ref","t","useT","router","useRouter","accessKeys","useAccessKeys","resolvedTo","useMemo","tree","buildNavTree","route","_a","hasAccess","firstNavTo","canNavigate","action","Button","jsx","EmptyState"],"mappings":"qSAwCaA,EAAeC,EAAAA,WAA8C,SACxE,CAAE,KAAAC,EAAO,eAAgB,MAAAC,EAAO,YAAAC,EAAa,YAAAC,EAAa,GAAAC,EAAI,WAAAC,EAAa,GAAM,GAAGC,CAAA,EACpFC,EACA,CACA,MAAMC,EAAIC,EAAAA,KAAA,EAEJC,EAASC,EAAAA,UAAU,CAAE,KAAM,GAAO,EAClCC,EAAaC,EAAAA,cAAA,EAGbC,EAAaC,EAAAA,QAAQ,IAAM,CAC/B,GAAIX,GAAM,KAAM,OAAOA,EACvB,GAAI,CAACM,EAAQ,OACb,MAAMM,EAAOC,EAAAA,aACX,OAAO,OAAOP,EAAO,eAAe,EACjC,IAAKQ,UAAW,OAAE,SAAUA,EAAM,SAAU,YAAYC,EAAAD,EAAM,UAAN,YAAAC,EAAe,YAAa,EACpF,OAAQD,GAAA,OAAUE,OAAAA,aAAUD,EAAAD,EAAM,aAAN,YAAAC,EAAkB,KAAK,EAAC,CAAA,EAEzD,OAAOE,EAAAA,WAAWL,CAAI,GAAK,GAC7B,EAAG,CAACN,EAAQN,EAAIQ,CAAU,CAAC,EAErBU,EAAc,CAAC,CAACZ,GAAUI,GAAc,KACxCS,EACJlB,GAAciB,QACXE,EAAAA,OAAA,CAAO,QAAS,IAAMd,EAAO,SAAS,CAAE,GAAII,EAA+B,EACzE,YAAeN,EAAE,iBAAiB,EACrC,EACE,OAEN,OACEiB,EAAAA,IAACC,EAAAA,WAAA,CACC,IAAAnB,EACA,KAAAP,EACA,MAAOC,GAASO,EAAE,gBAAgB,EAClC,YAAaN,GAAeM,EAAE,sBAAsB,EACpD,OAAAe,EACC,GAAGjB,CAAA,CAAA,CAGV,CAAC"}
|
|
@@ -2,10 +2,10 @@ import { jsx as n } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef as N, useMemo as P } from "react";
|
|
3
3
|
import { useRouter as g } from "@tanstack/react-router";
|
|
4
4
|
import { u as y, h as T } from "./access-Db4knwyR.js";
|
|
5
|
-
import { E as b } from "./EmptyState-
|
|
6
|
-
import { B } from "./Button-
|
|
7
|
-
import { b as D, f as R } from "./Sidebar-
|
|
8
|
-
import { a as S } from "./ConfigProvider-
|
|
5
|
+
import { E as b } from "./EmptyState-DJDNLKT7.js";
|
|
6
|
+
import { B } from "./Button-RljTGqHl.js";
|
|
7
|
+
import { b as D, f as R } from "./Sidebar-CJ7DtOqb.js";
|
|
8
|
+
import { a as S } from "./ConfigProvider-DT0yrgmd.js";
|
|
9
9
|
const M = N(function({ icon: i = "SearchStatus", title: c, description: u, actionLabel: f, to: e, showAction: l = !0, ...m }, d) {
|
|
10
10
|
const a = S(), t = g({ warn: !1 }), p = y(), r = P(() => {
|
|
11
11
|
if (e != null) return e;
|
|
@@ -36,4 +36,4 @@ const M = N(function({ icon: i = "SearchStatus", title: c, description: u, actio
|
|
|
36
36
|
export {
|
|
37
37
|
M as P
|
|
38
38
|
};
|
|
39
|
-
//# sourceMappingURL=PageNotFound-
|
|
39
|
+
//# sourceMappingURL=PageNotFound-YGVMVvyG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageNotFound-
|
|
1
|
+
{"version":3,"file":"PageNotFound-YGVMVvyG.js","sources":["../src/components/PageNotFound/PageNotFound.tsx"],"sourcesContent":["import { forwardRef, useMemo, type HTMLAttributes, type ReactNode } from 'react'\nimport { useRouter, type LinkProps } from '@tanstack/react-router'\nimport { useT } from '../../theme'\nimport { hasAccess, useAccessKeys } from '../../helpers/access'\nimport { EmptyState, type EmptyStateSize } from '../EmptyState'\nimport { Button } from '../Button'\nimport { buildNavTree, firstNavTo } from '../Sidebar/Sidebar'\nimport type { IconName } from '../../icons/names'\n\nexport interface PageNotFoundProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {\n /** Hero glyph — an `IconName`, any node, or `false` to hide it. Defaults to `SearchStatus`. */\n icon?: IconName | ReactNode | false\n /** Heading. Defaults to the localized `notFound.title`. */\n title?: ReactNode\n /** Muted description. Defaults to the localized `notFound.description`. */\n description?: ReactNode\n /** Action button label. Defaults to the localized `notFound.action`. */\n actionLabel?: ReactNode\n /** Where the action navigates. Defaults to the first allowed menu page (RBAC-aware), else `/`. */\n to?: string\n /** Show the \"back home\" action button. Defaults to `true` (hidden anyway when there's no router). */\n showAction?: boolean\n /** Faded-grid hero backdrop — passed to `EmptyState`. Defaults to `true` (its default). */\n pattern?: boolean\n /** Size — passed to `EmptyState`. Defaults to `md`. */\n size?: EmptyStateSize\n}\n\n/**\n * The shared **404** page. Drop it straight into TanStack Router as the\n * `defaultNotFoundComponent` — zero props needed: the title/description/action strings come from the\n * built-in i18n (`useT`), so they translate with the panel language, and the action navigates to the\n * **first allowed menu page** (the same RBAC-aware target as `FirstRouteRedirect`), falling back to\n * `/`. Built on `EmptyState` (hero glyph + title + description + action, `pattern` on by default), so\n * it renders inside the `RootLayout` content area with the shell/sidebar intact. Lenient: with no\n * router context the `EmptyState` still renders, just without the action button. Token-only styling.\n *\n * @example\n * const router = createRouter({ routeTree, defaultNotFoundComponent: PageNotFound })\n */\nexport const PageNotFound = forwardRef<HTMLDivElement, PageNotFoundProps>(function PageNotFound(\n { icon = 'SearchStatus', title, description, actionLabel, to, showAction = true, ...props },\n ref,\n) {\n const t = useT()\n // lenient router access — returns undefined (no throw) outside a <RouterProvider>\n const router = useRouter({ warn: false })\n const accessKeys = useAccessKeys()\n\n // the first allowed menu page — same logic as FirstRouteRedirect, RBAC-aware; `/` fallback\n const resolvedTo = useMemo(() => {\n if (to != null) return to\n if (!router) return undefined\n const tree = buildNavTree(\n Object.values(router.looseRoutesById)\n .map((route) => ({ fullPath: route.fullPath, staticData: route.options?.staticData }))\n .filter((route) => hasAccess(route.staticData?.roles)),\n )\n return firstNavTo(tree) ?? '/'\n }, [router, to, accessKeys])\n\n const canNavigate = !!router && resolvedTo != null\n const action =\n showAction && canNavigate ? (\n <Button onClick={() => router.navigate({ to: resolvedTo as LinkProps['to'] })}>\n {actionLabel ?? t('notFound.action')}\n </Button>\n ) : undefined\n\n return (\n <EmptyState\n ref={ref}\n icon={icon}\n title={title ?? t('notFound.title')}\n description={description ?? t('notFound.description')}\n action={action}\n {...props}\n />\n )\n})\n"],"names":["PageNotFound","forwardRef","icon","title","description","actionLabel","to","showAction","props","ref","t","useT","router","useRouter","accessKeys","useAccessKeys","resolvedTo","useMemo","tree","buildNavTree","route","_a","hasAccess","firstNavTo","canNavigate","action","Button","jsx","EmptyState"],"mappings":";;;;;;;;AAwCO,MAAMA,IAAeC,EAA8C,SACxE,EAAE,MAAAC,IAAO,gBAAgB,OAAAC,GAAO,aAAAC,GAAa,aAAAC,GAAa,IAAAC,GAAI,YAAAC,IAAa,IAAM,GAAGC,EAAA,GACpFC,GACA;AACA,QAAMC,IAAIC,EAAA,GAEJC,IAASC,EAAU,EAAE,MAAM,IAAO,GAClCC,IAAaC,EAAA,GAGbC,IAAaC,EAAQ,MAAM;AAC/B,QAAIX,KAAM,KAAM,QAAOA;AACvB,QAAI,CAACM,EAAQ;AACb,UAAMM,IAAOC;AAAA,MACX,OAAO,OAAOP,EAAO,eAAe,EACjC,IAAI,CAACQ;;AAAW,iBAAE,UAAUA,EAAM,UAAU,aAAYC,IAAAD,EAAM,YAAN,gBAAAC,EAAe;OAAa,EACpF,OAAO,CAACD,MAAA;;AAAU,eAAAE,GAAUD,IAAAD,EAAM,eAAN,gBAAAC,EAAkB,KAAK;AAAA,OAAC;AAAA,IAAA;AAEzD,WAAOE,EAAWL,CAAI,KAAK;AAAA,EAC7B,GAAG,CAACN,GAAQN,GAAIQ,CAAU,CAAC,GAErBU,IAAc,CAAC,CAACZ,KAAUI,KAAc,MACxCS,IACJlB,KAAciB,sBACXE,GAAA,EAAO,SAAS,MAAMd,EAAO,SAAS,EAAE,IAAII,GAA+B,GACzE,eAAeN,EAAE,iBAAiB,GACrC,IACE;AAEN,SACE,gBAAAiB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,KAAAnB;AAAA,MACA,MAAAP;AAAA,MACA,OAAOC,KAASO,EAAE,gBAAgB;AAAA,MAClC,aAAaN,KAAeM,EAAE,sBAAsB;AAAA,MACpD,QAAAe;AAAA,MACC,GAAGjB;AAAA,IAAA;AAAA,EAAA;AAGV,CAAC;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as r, jsxs as Q } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef as U, useState as V } from "react";
|
|
3
3
|
import { clsx as d } from "clsx";
|
|
4
|
-
import { I as W } from "./Icon-
|
|
5
|
-
import { a as X } from "./ConfigProvider-
|
|
4
|
+
import { I as W } from "./Icon-DaTvzLBu.js";
|
|
5
|
+
import { a as X } from "./ConfigProvider-DT0yrgmd.js";
|
|
6
6
|
const w = (s, t) => Array.from({ length: Math.max(t - s + 1, 0) }, (l, a) => s + a);
|
|
7
7
|
function Y({
|
|
8
8
|
count: s,
|
|
@@ -136,4 +136,4 @@ const Z = "_pagination_wk3op_3", b = "_list_wk3op_8", y = "_item_wk3op_18", u =
|
|
|
136
136
|
export {
|
|
137
137
|
fa as P
|
|
138
138
|
};
|
|
139
|
-
//# sourceMappingURL=Pagination-
|
|
139
|
+
//# sourceMappingURL=Pagination-BTvUJiee.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination-BYXUhmSz.js","sources":["../src/components/Pagination/paginationRange.ts","../src/components/Pagination/Pagination.tsx"],"sourcesContent":["/** A gap placeholder rendered as `…` — at the start (`1 … 4`) or end (`6 … 10`) of the range. */\nexport type PaginationEllipsis = 'start-ellipsis' | 'end-ellipsis'\n\n/** One item in a pagination range: a 1-based page number, or an ellipsis placeholder. */\nexport type PaginationItem = number | PaginationEllipsis\n\n/** Inputs for {@link paginationRange}. */\nexport interface PaginationRangeOptions {\n /** Total number of pages. */\n count: number\n /** Current page (1-based). */\n page: number\n /** Pages shown on each side of the current page. Defaults to `1`. */\n siblingCount?: number\n /** Pages always shown at the start and end. Defaults to `1`. */\n boundaryCount?: number\n}\n\n/** Inclusive integer range `[start, end]` (empty when `end < start`). */\nconst range = (start: number, end: number): number[] =>\n Array.from({ length: Math.max(end - start + 1, 0) }, (_, i) => start + i)\n\n/**\n * Build the page-item sequence for a pager — the boundary pages, the current page with its siblings,\n * and `start`/`end` ellipses where pages are skipped (the classic `1 … 4 5 6 … 10`). Pure and\n * framework-free so it can be unit-tested in isolation and reused. Assumes `1 <= page <= count`.\n */\nexport function paginationRange({\n count,\n page,\n siblingCount = 1,\n boundaryCount = 1,\n}: PaginationRangeOptions): PaginationItem[] {\n if (count <= 0) return []\n\n // Pages pinned at each edge.\n const startPages = range(1, Math.min(boundaryCount, count))\n const endPages = range(Math.max(count - boundaryCount + 1, boundaryCount + 1), count)\n\n // The window of pages around the current one, clamped so it never overlaps the boundaries.\n const siblingsStart = Math.max(\n Math.min(page - siblingCount, count - boundaryCount - siblingCount * 2 - 1),\n boundaryCount + 2,\n )\n const siblingsEnd = Math.min(\n Math.max(page + siblingCount, boundaryCount + siblingCount * 2 + 2),\n endPages.length > 0 ? endPages[0] - 2 : count - 1,\n )\n\n return [\n ...startPages,\n // A start ellipsis, OR the single page that sits between the start boundary and the siblings.\n ...(siblingsStart > boundaryCount + 2\n ? (['start-ellipsis'] as PaginationItem[])\n : boundaryCount + 1 < count - boundaryCount\n ? [boundaryCount + 1]\n : []),\n ...range(siblingsStart, siblingsEnd),\n // An end ellipsis, OR the single page between the siblings and the end boundary.\n ...(siblingsEnd < count - boundaryCount - 1\n ? (['end-ellipsis'] as PaginationItem[])\n : count - boundaryCount > boundaryCount\n ? [count - boundaryCount]\n : []),\n ...endPages,\n ]\n}\n","import {\n forwardRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { Icon, type IconName } from '../Icon'\nimport { useT, type ThemeColor } from '../../theme'\nimport { paginationRange } from './paginationRange'\nimport styles from './Pagination.module.css'\n\nexport type PaginationVariant = 'outlined' | 'text'\nexport type PaginationSize = 'sm' | 'md' | 'lg'\n\nexport interface PaginationProps extends Omit<HTMLAttributes<HTMLElement>, 'color' | 'onChange'> {\n /** Total number of pages (required). From a row count, pass `Math.ceil(total / pageSize)`. */\n count: number\n /** Controlled current page (1-based). */\n page?: number\n /** Initial page for uncontrolled use (1-based). Defaults to `1`. */\n defaultPage?: number\n /** Fires with the next page (1-based) when a page or arrow is activated. */\n onChange?: (page: number) => void\n /** Pages shown on each side of the current page. Defaults to `1`. */\n siblingCount?: number\n /** Pages always shown at the start and end. Defaults to `1`. */\n boundaryCount?: number\n /** Show a jump-to-first-page button before the previous arrow. Defaults to `false`. */\n showFirstButton?: boolean\n /** Show a jump-to-last-page button after the next arrow. Defaults to `false`. */\n showLastButton?: boolean\n /** Hide the previous-page arrow. Defaults to `false`. */\n hidePrevButton?: boolean\n /** Hide the next-page arrow. Defaults to `false`. */\n hideNextButton?: boolean\n /** Item style: `outlined` (bordered boxes, default) or `text` (borderless). */\n variant?: PaginationVariant\n /** Control size — sets the box, font, and icon sizes. Defaults to `md`. */\n size?: PaginationSize\n /** Theme palette token that tints the selected page. Defaults to `accent`. */\n color?: ThemeColor\n /** Render circular page buttons instead of rounded rectangles. Defaults to `false`. */\n rounded?: boolean\n /** Disable the whole control. Defaults to `false`. */\n disabled?: boolean\n}\n\nconst clamp = (n: number, lo: number, hi: number) => Math.min(Math.max(n, lo), hi)\n\n/**\n * A page navigator — previous/next arrows around a numbered range with `…` gaps (`1 … 4 5 6 … 10`),\n * the classic pager. Reusable across tables, lists, and galleries: drive it with `count` (total\n * pages) + `page`/`onChange`, computing `count` as `Math.ceil(total / pageSize)`. The selected page\n * is tinted via the shared `--tz-btn-rgb` pattern; unselected items are bordered (`outlined`) or\n * borderless (`text`). Controlled (`page` + `onChange`) or uncontrolled (`defaultPage`).\n */\nexport const Pagination = forwardRef<HTMLElement, PaginationProps>(function Pagination(\n {\n count,\n page,\n defaultPage = 1,\n onChange,\n siblingCount = 1,\n boundaryCount = 1,\n showFirstButton = false,\n showLastButton = false,\n hidePrevButton = false,\n hideNextButton = false,\n variant = 'outlined',\n size = 'md',\n color = 'accent',\n rounded = false,\n disabled = false,\n className,\n style,\n 'aria-label': ariaLabel = 'Pagination',\n ...props\n },\n ref,\n) {\n const isControlled = page !== undefined\n const [internal, setInternal] = useState(defaultPage)\n const lastPage = Math.max(count, 1)\n const current = clamp(isControlled ? page! : internal, 1, lastPage)\n\n const go = (next: number) => {\n const target = clamp(next, 1, lastPage)\n if (target === current) return\n if (!isControlled) setInternal(target)\n onChange?.(target)\n }\n\n const t = useT()\n const items = paginationRange({ count, page: current, siblingCount, boundaryCount })\n\n // The selected fill + its readable text color, derived once via the shared button-tint vars.\n const rootStyle = {\n '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`,\n '--tz-btn-on': `var(--tz-color-${color}-contrast, #fff)`,\n ...style,\n } as CSSProperties\n\n // An arrow / jump control. `flip` mirrors the (left-pointing) icon to face right — the icon set has\n // no matching plain right arrow, so the next/last glyphs are the left ones flipped for symmetry.\n const control = (\n key: string,\n icon: IconName,\n label: string,\n target: number,\n hidden: boolean,\n atBound: boolean,\n flip = false,\n ): ReactNode =>\n hidden ? null : (\n <li key={key} className={styles.item}>\n <button\n type=\"button\"\n className={clsx(styles.page, styles.arrow)}\n aria-label={label}\n disabled={disabled || atBound}\n onClick={() => go(target)}\n >\n <Icon name={icon} size={size} className={flip ? styles.flip : undefined} />\n </button>\n </li>\n )\n\n return (\n <nav\n ref={ref}\n aria-label={ariaLabel}\n className={clsx(\n styles.pagination,\n styles[variant],\n styles[size],\n rounded && styles.rounded,\n className,\n )}\n style={rootStyle}\n {...props}\n >\n <ul className={styles.list}>\n {showFirstButton &&\n control('first', 'Previous', t('pagination.first'), 1, false, current <= 1)}\n {control(\n 'prev',\n 'ArrowLeft',\n t('pagination.previous'),\n current - 1,\n hidePrevButton,\n current <= 1,\n )}\n {items.map((item, i) =>\n typeof item === 'number' ? (\n <li key={item} className={styles.item}>\n <button\n type=\"button\"\n className={clsx(styles.page, item === current && styles.selected)}\n aria-label={t('pagination.page', { page: item })}\n aria-current={item === current ? 'page' : undefined}\n disabled={disabled}\n onClick={() => go(item)}\n >\n {item}\n </button>\n </li>\n ) : (\n <li key={`${item}-${i}`} className={styles.item} aria-hidden>\n <span className={styles.ellipsis}>…</span>\n </li>\n ),\n )}\n {control(\n 'next',\n 'ArrowLeft',\n t('pagination.next'),\n current + 1,\n hideNextButton,\n current >= count,\n true,\n )}\n {showLastButton &&\n control('last', 'Next', t('pagination.last'), count, false, current >= count)}\n </ul>\n </nav>\n )\n})\n"],"names":["range","start","end","_","i","paginationRange","count","page","siblingCount","boundaryCount","startPages","endPages","siblingsStart","siblingsEnd","clamp","n","lo","hi","Pagination","forwardRef","defaultPage","onChange","showFirstButton","showLastButton","hidePrevButton","hideNextButton","variant","size","color","rounded","disabled","className","style","ariaLabel","props","ref","isControlled","internal","setInternal","useState","lastPage","current","go","next","target","t","useT","items","rootStyle","control","key","icon","label","hidden","atBound","flip","jsx","styles","clsx","Icon","jsxs","item"],"mappings":";;;;;AAmBA,MAAMA,IAAQ,CAACC,GAAeC,MAC5B,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAIA,IAAMD,IAAQ,GAAG,CAAC,EAAA,GAAK,CAACE,GAAGC,MAAMH,IAAQG,CAAC;AAOnE,SAASC,EAAgB;AAAA,EAC9B,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,eAAAC,IAAgB;AAClB,GAA6C;AAC3C,MAAIH,KAAS,EAAG,QAAO,CAAA;AAGvB,QAAMI,IAAaV,EAAM,GAAG,KAAK,IAAIS,GAAeH,CAAK,CAAC,GACpDK,IAAWX,EAAM,KAAK,IAAIM,IAAQG,IAAgB,GAAGA,IAAgB,CAAC,GAAGH,CAAK,GAG9EM,IAAgB,KAAK;AAAA,IACzB,KAAK,IAAIL,IAAOC,GAAcF,IAAQG,IAAgBD,IAAe,IAAI,CAAC;AAAA,IAC1EC,IAAgB;AAAA,EAAA,GAEZI,IAAc,KAAK;AAAA,IACvB,KAAK,IAAIN,IAAOC,GAAcC,IAAgBD,IAAe,IAAI,CAAC;AAAA,IAClEG,EAAS,SAAS,IAAIA,EAAS,CAAC,IAAI,IAAIL,IAAQ;AAAA,EAAA;AAGl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,EAAE,qBAAqB;AAAA,UACvBJ,IAAU;AAAA,UACVjB;AAAA,UACAiB,KAAW;AAAA,QAAA;AAAA,QAEZM,EAAM;AAAA,UAAI,CAACc,GAAMzD,MAChB,OAAOyD,KAAS,WACd,gBAAAL,EAAC,MAAA,EAAc,WAAWC,EAAO,MAC/B,UAAA,gBAAAD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,MAAK;AAAA,cACL,WAAWE,EAAKD,EAAO,MAAMI,MAASpB,KAAWgB,EAAO,QAAQ;AAAA,cAChE,cAAYZ,EAAE,mBAAmB,EAAE,MAAMgB,GAAM;AAAA,cAC/C,gBAAcA,MAASpB,IAAU,SAAS;AAAA,cAC1C,UAAAX;AAAA,cACA,SAAS,MAAMY,EAAGmB,CAAI;AAAA,cAErB,UAAAA;AAAA,YAAA;AAAA,UAAA,EACH,GAVOA,CAWT,IAEA,gBAAAL,EAAC,QAAwB,WAAWC,EAAO,MAAM,eAAW,IAC1D,4BAAC,QAAA,EAAK,WAAWA,EAAO,UAAU,UAAA,IAAA,CAAC,KAD5B,GAAGI,CAAI,IAAIzD,CAAC,EAErB;AAAA,QAAA;AAAA,QAGH6C;AAAA,UACC;AAAA,UACA;AAAA,UACAJ,EAAE,iBAAiB;AAAA,UACnBJ,IAAU;AAAA,UACVhB;AAAA,UACAgB,KAAWnC;AAAA,UACX;AAAA,QAAA;AAAA,QAEDiB,KACC0B,EAAQ,QAAQ,QAAQJ,EAAE,iBAAiB,GAAGvC,GAAO,IAAOmC,KAAWnC,CAAK;AAAA,MAAA,EAAA,CAChF;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Pagination-BTvUJiee.js","sources":["../src/components/Pagination/paginationRange.ts","../src/components/Pagination/Pagination.tsx"],"sourcesContent":["/** A gap placeholder rendered as `…` — at the start (`1 … 4`) or end (`6 … 10`) of the range. */\nexport type PaginationEllipsis = 'start-ellipsis' | 'end-ellipsis'\n\n/** One item in a pagination range: a 1-based page number, or an ellipsis placeholder. */\nexport type PaginationItem = number | PaginationEllipsis\n\n/** Inputs for {@link paginationRange}. */\nexport interface PaginationRangeOptions {\n /** Total number of pages. */\n count: number\n /** Current page (1-based). */\n page: number\n /** Pages shown on each side of the current page. Defaults to `1`. */\n siblingCount?: number\n /** Pages always shown at the start and end. Defaults to `1`. */\n boundaryCount?: number\n}\n\n/** Inclusive integer range `[start, end]` (empty when `end < start`). */\nconst range = (start: number, end: number): number[] =>\n Array.from({ length: Math.max(end - start + 1, 0) }, (_, i) => start + i)\n\n/**\n * Build the page-item sequence for a pager — the boundary pages, the current page with its siblings,\n * and `start`/`end` ellipses where pages are skipped (the classic `1 … 4 5 6 … 10`). Pure and\n * framework-free so it can be unit-tested in isolation and reused. Assumes `1 <= page <= count`.\n */\nexport function paginationRange({\n count,\n page,\n siblingCount = 1,\n boundaryCount = 1,\n}: PaginationRangeOptions): PaginationItem[] {\n if (count <= 0) return []\n\n // Pages pinned at each edge.\n const startPages = range(1, Math.min(boundaryCount, count))\n const endPages = range(Math.max(count - boundaryCount + 1, boundaryCount + 1), count)\n\n // The window of pages around the current one, clamped so it never overlaps the boundaries.\n const siblingsStart = Math.max(\n Math.min(page - siblingCount, count - boundaryCount - siblingCount * 2 - 1),\n boundaryCount + 2,\n )\n const siblingsEnd = Math.min(\n Math.max(page + siblingCount, boundaryCount + siblingCount * 2 + 2),\n endPages.length > 0 ? endPages[0] - 2 : count - 1,\n )\n\n return [\n ...startPages,\n // A start ellipsis, OR the single page that sits between the start boundary and the siblings.\n ...(siblingsStart > boundaryCount + 2\n ? (['start-ellipsis'] as PaginationItem[])\n : boundaryCount + 1 < count - boundaryCount\n ? [boundaryCount + 1]\n : []),\n ...range(siblingsStart, siblingsEnd),\n // An end ellipsis, OR the single page between the siblings and the end boundary.\n ...(siblingsEnd < count - boundaryCount - 1\n ? (['end-ellipsis'] as PaginationItem[])\n : count - boundaryCount > boundaryCount\n ? [count - boundaryCount]\n : []),\n ...endPages,\n ]\n}\n","import {\n forwardRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { Icon, type IconName } from '../Icon'\nimport { useT, type ThemeColor } from '../../theme'\nimport { paginationRange } from './paginationRange'\nimport styles from './Pagination.module.css'\n\nexport type PaginationVariant = 'outlined' | 'text'\nexport type PaginationSize = 'sm' | 'md' | 'lg'\n\nexport interface PaginationProps extends Omit<HTMLAttributes<HTMLElement>, 'color' | 'onChange'> {\n /** Total number of pages (required). From a row count, pass `Math.ceil(total / pageSize)`. */\n count: number\n /** Controlled current page (1-based). */\n page?: number\n /** Initial page for uncontrolled use (1-based). Defaults to `1`. */\n defaultPage?: number\n /** Fires with the next page (1-based) when a page or arrow is activated. */\n onChange?: (page: number) => void\n /** Pages shown on each side of the current page. Defaults to `1`. */\n siblingCount?: number\n /** Pages always shown at the start and end. Defaults to `1`. */\n boundaryCount?: number\n /** Show a jump-to-first-page button before the previous arrow. Defaults to `false`. */\n showFirstButton?: boolean\n /** Show a jump-to-last-page button after the next arrow. Defaults to `false`. */\n showLastButton?: boolean\n /** Hide the previous-page arrow. Defaults to `false`. */\n hidePrevButton?: boolean\n /** Hide the next-page arrow. Defaults to `false`. */\n hideNextButton?: boolean\n /** Item style: `outlined` (bordered boxes, default) or `text` (borderless). */\n variant?: PaginationVariant\n /** Control size — sets the box, font, and icon sizes. Defaults to `md`. */\n size?: PaginationSize\n /** Theme palette token that tints the selected page. Defaults to `accent`. */\n color?: ThemeColor\n /** Render circular page buttons instead of rounded rectangles. Defaults to `false`. */\n rounded?: boolean\n /** Disable the whole control. Defaults to `false`. */\n disabled?: boolean\n}\n\nconst clamp = (n: number, lo: number, hi: number) => Math.min(Math.max(n, lo), hi)\n\n/**\n * A page navigator — previous/next arrows around a numbered range with `…` gaps (`1 … 4 5 6 … 10`),\n * the classic pager. Reusable across tables, lists, and galleries: drive it with `count` (total\n * pages) + `page`/`onChange`, computing `count` as `Math.ceil(total / pageSize)`. The selected page\n * is tinted via the shared `--tz-btn-rgb` pattern; unselected items are bordered (`outlined`) or\n * borderless (`text`). Controlled (`page` + `onChange`) or uncontrolled (`defaultPage`).\n */\nexport const Pagination = forwardRef<HTMLElement, PaginationProps>(function Pagination(\n {\n count,\n page,\n defaultPage = 1,\n onChange,\n siblingCount = 1,\n boundaryCount = 1,\n showFirstButton = false,\n showLastButton = false,\n hidePrevButton = false,\n hideNextButton = false,\n variant = 'outlined',\n size = 'md',\n color = 'accent',\n rounded = false,\n disabled = false,\n className,\n style,\n 'aria-label': ariaLabel = 'Pagination',\n ...props\n },\n ref,\n) {\n const isControlled = page !== undefined\n const [internal, setInternal] = useState(defaultPage)\n const lastPage = Math.max(count, 1)\n const current = clamp(isControlled ? page! : internal, 1, lastPage)\n\n const go = (next: number) => {\n const target = clamp(next, 1, lastPage)\n if (target === current) return\n if (!isControlled) setInternal(target)\n onChange?.(target)\n }\n\n const t = useT()\n const items = paginationRange({ count, page: current, siblingCount, boundaryCount })\n\n // The selected fill + its readable text color, derived once via the shared button-tint vars.\n const rootStyle = {\n '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`,\n '--tz-btn-on': `var(--tz-color-${color}-contrast, #fff)`,\n ...style,\n } as CSSProperties\n\n // An arrow / jump control. `flip` mirrors the (left-pointing) icon to face right — the icon set has\n // no matching plain right arrow, so the next/last glyphs are the left ones flipped for symmetry.\n const control = (\n key: string,\n icon: IconName,\n label: string,\n target: number,\n hidden: boolean,\n atBound: boolean,\n flip = false,\n ): ReactNode =>\n hidden ? null : (\n <li key={key} className={styles.item}>\n <button\n type=\"button\"\n className={clsx(styles.page, styles.arrow)}\n aria-label={label}\n disabled={disabled || atBound}\n onClick={() => go(target)}\n >\n <Icon name={icon} size={size} className={flip ? styles.flip : undefined} />\n </button>\n </li>\n )\n\n return (\n <nav\n ref={ref}\n aria-label={ariaLabel}\n className={clsx(\n styles.pagination,\n styles[variant],\n styles[size],\n rounded && styles.rounded,\n className,\n )}\n style={rootStyle}\n {...props}\n >\n <ul className={styles.list}>\n {showFirstButton &&\n control('first', 'Previous', t('pagination.first'), 1, false, current <= 1)}\n {control(\n 'prev',\n 'ArrowLeft',\n t('pagination.previous'),\n current - 1,\n hidePrevButton,\n current <= 1,\n )}\n {items.map((item, i) =>\n typeof item === 'number' ? (\n <li key={item} className={styles.item}>\n <button\n type=\"button\"\n className={clsx(styles.page, item === current && styles.selected)}\n aria-label={t('pagination.page', { page: item })}\n aria-current={item === current ? 'page' : undefined}\n disabled={disabled}\n onClick={() => go(item)}\n >\n {item}\n </button>\n </li>\n ) : (\n <li key={`${item}-${i}`} className={styles.item} aria-hidden>\n <span className={styles.ellipsis}>…</span>\n </li>\n ),\n )}\n {control(\n 'next',\n 'ArrowLeft',\n t('pagination.next'),\n current + 1,\n hideNextButton,\n current >= count,\n true,\n )}\n {showLastButton &&\n control('last', 'Next', t('pagination.last'), count, false, current >= count)}\n </ul>\n </nav>\n )\n})\n"],"names":["range","start","end","_","i","paginationRange","count","page","siblingCount","boundaryCount","startPages","endPages","siblingsStart","siblingsEnd","clamp","n","lo","hi","Pagination","forwardRef","defaultPage","onChange","showFirstButton","showLastButton","hidePrevButton","hideNextButton","variant","size","color","rounded","disabled","className","style","ariaLabel","props","ref","isControlled","internal","setInternal","useState","lastPage","current","go","next","target","t","useT","items","rootStyle","control","key","icon","label","hidden","atBound","flip","jsx","styles","clsx","Icon","jsxs","item"],"mappings":";;;;;AAmBA,MAAMA,IAAQ,CAACC,GAAeC,MAC5B,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAIA,IAAMD,IAAQ,GAAG,CAAC,EAAA,GAAK,CAACE,GAAGC,MAAMH,IAAQG,CAAC;AAOnE,SAASC,EAAgB;AAAA,EAC9B,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,eAAAC,IAAgB;AAClB,GAA6C;AAC3C,MAAIH,KAAS,EAAG,QAAO,CAAA;AAGvB,QAAMI,IAAaV,EA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ACAgB,KAAWnC;AAAA,UACX;AAAA,QAAA;AAAA,QAEDiB,KACC0B,EAAQ,QAAQ,QAAQJ,EAAE,iBAAiB,GAAGvC,GAAO,IAAOmC,KAAWnC,CAAK;AAAA,MAAA,EAAA,CAChF;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const r=require("react/jsx-runtime"),N=require("react"),d=require("clsx"),U=require("./Icon-
|
|
2
|
-
//# sourceMappingURL=Pagination-
|
|
1
|
+
"use strict";const r=require("react/jsx-runtime"),N=require("react"),d=require("clsx"),U=require("./Icon-BVULqOJD.cjs"),V=require("./ConfigProvider-C7DUWHrb.cjs"),x=(e,t)=>Array.from({length:Math.max(t-e+1,0)},(l,s)=>e+s);function W({count:e,page:t,siblingCount:l=1,boundaryCount:s=1}){if(e<=0)return[];const o=x(1,Math.min(s,e)),p=x(Math.max(e-s+1,s+1),e),m=Math.max(Math.min(t-l,e-s-l*2-1),s+2),g=Math.min(Math.max(t+l,s+l*2+2),p.length>0?p[0]-2:e-1);return[...o,...m>s+2?["start-ellipsis"]:s+1<e-s?[s+1]:[],...x(m,g),...g<e-s-1?["end-ellipsis"]:e-s>s?[e-s]:[],...p]}const X="_pagination_wk3op_3",Y="_list_wk3op_8",Z="_item_wk3op_18",b="_sm_wk3op_28",u="_md_wk3op_33",y="_lg_wk3op_38",C="_page_wk3op_45",ss="_selected_wk3op_64",es="_outlined_wk3op_80",as="_rounded_wk3op_96",ts="_arrow_wk3op_26",is="_flip_wk3op_107",ls="_ellipsis_wk3op_112",a={pagination:X,list:Y,item:Z,sm:b,md:u,lg:y,page:C,selected:ss,outlined:es,rounded:as,arrow:ts,flip:is,ellipsis:ls},P=(e,t,l)=>Math.min(Math.max(e,t),l),ns=N.forwardRef(function({count:t,page:l,defaultPage:s=1,onChange:o,siblingCount:p=1,boundaryCount:m=1,showFirstButton:g=!1,showLastButton:q=!1,hidePrevButton:$=!1,hideNextButton:z=!1,variant:A="outlined",size:w="md",color:h="accent",rounded:I=!1,disabled:k=!1,className:R,style:S,"aria-label":L="Pagination",...E},T){const j=l!==void 0,[B,D]=N.useState(s),v=Math.max(t,1),n=P(j?l:B,1,v),M=i=>{const c=P(i,1,v);c!==n&&(j||D(c),o==null||o(c))},_=V.useT(),F=W({count:t,page:n,siblingCount:p,boundaryCount:m}),G={"--tz-btn-rgb":`var(--tz-color-${h}-rgb)`,"--tz-btn-on":`var(--tz-color-${h}-contrast, #fff)`,...S},f=(i,c,H,J,K,O,Q=!1)=>K?null:r.jsx("li",{className:a.item,children:r.jsx("button",{type:"button",className:d.clsx(a.page,a.arrow),"aria-label":H,disabled:k||O,onClick:()=>M(J),children:r.jsx(U.Icon,{name:c,size:w,className:Q?a.flip:void 0})})},i);return r.jsx("nav",{ref:T,"aria-label":L,className:d.clsx(a.pagination,a[A],a[w],I&&a.rounded,R),style:G,...E,children:r.jsxs("ul",{className:a.list,children:[g&&f("first","Previous",_("pagination.first"),1,!1,n<=1),f("prev","ArrowLeft",_("pagination.previous"),n-1,$,n<=1),F.map((i,c)=>typeof i=="number"?r.jsx("li",{className:a.item,children:r.jsx("button",{type:"button",className:d.clsx(a.page,i===n&&a.selected),"aria-label":_("pagination.page",{page:i}),"aria-current":i===n?"page":void 0,disabled:k,onClick:()=>M(i),children:i})},i):r.jsx("li",{className:a.item,"aria-hidden":!0,children:r.jsx("span",{className:a.ellipsis,children:"…"})},`${i}-${c}`)),f("next","ArrowLeft",_("pagination.next"),n+1,z,n>=t,!0),q&&f("last","Next",_("pagination.last"),t,!1,n>=t)]})})});exports.Pagination=ns;
|
|
2
|
+
//# sourceMappingURL=Pagination-WJq_7QNi.cjs.map
|