@techzyapp/ui-library 1.0.33 → 1.0.35
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/{AdminRoot-CwUHa2us.js → AdminRoot-C_SNXQkB.js} +9 -9
- package/dist/{AdminRoot-CwUHa2us.js.map → AdminRoot-C_SNXQkB.js.map} +1 -1
- package/dist/{AdminRoot-cjP_Ad4r.cjs → AdminRoot-D97qDVTM.cjs} +2 -2
- package/dist/{AdminRoot-cjP_Ad4r.cjs.map → AdminRoot-D97qDVTM.cjs.map} +1 -1
- package/dist/{Alert-LJDrtkJy.js → Alert-BXtQFAVl.js} +3 -3
- package/dist/{Alert-LJDrtkJy.js.map → Alert-BXtQFAVl.js.map} +1 -1
- package/dist/{Alert-CfjDmLR8.cjs → Alert-CggrNMn5.cjs} +2 -2
- package/dist/{Alert-CfjDmLR8.cjs.map → Alert-CggrNMn5.cjs.map} +1 -1
- package/dist/{AuthLayout-m1BQ6Ixx.js → AuthLayout-C47vXKYp.js} +2 -2
- package/dist/{AuthLayout-m1BQ6Ixx.js.map → AuthLayout-C47vXKYp.js.map} +1 -1
- package/dist/{AuthLayout-DIcR__vo.cjs → AuthLayout-Cl3tb4-E.cjs} +2 -2
- package/dist/{AuthLayout-DIcR__vo.cjs.map → AuthLayout-Cl3tb4-E.cjs.map} +1 -1
- package/dist/{Breadcrumbs-COb2zmDk.cjs → Breadcrumbs-Cpa_LSY2.cjs} +2 -2
- package/dist/{Breadcrumbs-COb2zmDk.cjs.map → Breadcrumbs-Cpa_LSY2.cjs.map} +1 -1
- package/dist/{Breadcrumbs-DYeVrOns.js → Breadcrumbs-D_QnKw8q.js} +3 -3
- package/dist/{Breadcrumbs-DYeVrOns.js.map → Breadcrumbs-D_QnKw8q.js.map} +1 -1
- package/dist/{Button-PBZnkRNn.js → Button-BQ7jsm5P.js} +2 -2
- package/dist/{Button-PBZnkRNn.js.map → Button-BQ7jsm5P.js.map} +1 -1
- package/dist/{Button-BD5wpg-t.cjs → Button-Cm64ROip.cjs} +2 -2
- package/dist/{Button-BD5wpg-t.cjs.map → Button-Cm64ROip.cjs.map} +1 -1
- package/dist/{Calendar-Bb5Ekbpr.js → Calendar-BrpJOBTt.js} +3 -3
- package/dist/{Calendar-Bb5Ekbpr.js.map → Calendar-BrpJOBTt.js.map} +1 -1
- package/dist/{Calendar-842vjtdN.cjs → Calendar-C2x9ZtPV.cjs} +2 -2
- package/dist/{Calendar-842vjtdN.cjs.map → Calendar-C2x9ZtPV.cjs.map} +1 -1
- package/dist/{Card-CV_rHego.js → Card-kizK1B7N.js} +2 -2
- package/dist/{Card-CV_rHego.js.map → Card-kizK1B7N.js.map} +1 -1
- package/dist/{Card-DL7XnkOA.cjs → Card-yhly3Xdp.cjs} +2 -2
- package/dist/{Card-DL7XnkOA.cjs.map → Card-yhly3Xdp.cjs.map} +1 -1
- package/dist/{Chip-CLPIPC9a.cjs → Chip-BPcnO5WI.cjs} +2 -2
- package/dist/{Chip-CLPIPC9a.cjs.map → Chip-BPcnO5WI.cjs.map} +1 -1
- package/dist/{Chip-DdOUVF0Z.js → Chip-BzyzLEeX.js} +2 -2
- package/dist/{Chip-DdOUVF0Z.js.map → Chip-BzyzLEeX.js.map} +1 -1
- package/dist/{ChoiceCardGroup-BTbKjJdp.js → ChoiceCardGroup-BBD8ai4s.js} +2 -2
- package/dist/{ChoiceCardGroup-BTbKjJdp.js.map → ChoiceCardGroup-BBD8ai4s.js.map} +1 -1
- package/dist/{ChoiceCardGroup-Bg2jtFpe.cjs → ChoiceCardGroup-BWsG_Vh5.cjs} +2 -2
- package/dist/{ChoiceCardGroup-Bg2jtFpe.cjs.map → ChoiceCardGroup-BWsG_Vh5.cjs.map} +1 -1
- package/dist/{CodeBlock-B35NXZzd.js → CodeBlock-BTt40oh5.js} +3 -3
- package/dist/{CodeBlock-B35NXZzd.js.map → CodeBlock-BTt40oh5.js.map} +1 -1
- package/dist/{CodeBlock-C0dbyxcl.cjs → CodeBlock-BgSum_bB.cjs} +2 -2
- package/dist/{CodeBlock-C0dbyxcl.cjs.map → CodeBlock-BgSum_bB.cjs.map} +1 -1
- package/dist/{ColorPicker-6UraVYFy.js → ColorPicker-BNM75F5E.js} +4 -4
- package/dist/{ColorPicker-6UraVYFy.js.map → ColorPicker-BNM75F5E.js.map} +1 -1
- package/dist/{ColorPicker-DmLGKaYF.cjs → ColorPicker-C33dlkhN.cjs} +2 -2
- package/dist/{ColorPicker-DmLGKaYF.cjs.map → ColorPicker-C33dlkhN.cjs.map} +1 -1
- package/dist/{ColorPickerPanel-WuxwwfCI.cjs → ColorPickerPanel-BZ_ZNu2B.cjs} +2 -2
- package/dist/{ColorPickerPanel-WuxwwfCI.cjs.map → ColorPickerPanel-BZ_ZNu2B.cjs.map} +1 -1
- package/dist/{ColorPickerPanel-DZ-W_wOI.js → ColorPickerPanel-Bh1K0YS8.js} +2 -2
- package/dist/{ColorPickerPanel-DZ-W_wOI.js.map → ColorPickerPanel-Bh1K0YS8.js.map} +1 -1
- package/dist/{ColorRamp-D_9gsqJl.cjs → ColorRamp-BJWNKzoX.cjs} +2 -2
- package/dist/{ColorRamp-D_9gsqJl.cjs.map → ColorRamp-BJWNKzoX.cjs.map} +1 -1
- package/dist/{ColorRamp-CSqzzHZx.js → ColorRamp-BnuXrSxa.js} +3 -3
- package/dist/{ColorRamp-CSqzzHZx.js.map → ColorRamp-BnuXrSxa.js.map} +1 -1
- package/dist/{ConfigProvider-tvLbKiqu.js → ConfigProvider-DZMtq2Fz.js} +2 -2
- package/dist/ConfigProvider-DZMtq2Fz.js.map +1 -0
- package/dist/{ConfigProvider-CVLHPXQm.cjs → ConfigProvider-th4GYhcU.cjs} +2 -2
- package/dist/ConfigProvider-th4GYhcU.cjs.map +1 -0
- package/dist/{CopyButton-0w4OToIy.cjs → CopyButton-C9oHGs6W.cjs} +2 -2
- package/dist/{CopyButton-0w4OToIy.cjs.map → CopyButton-C9oHGs6W.cjs.map} +1 -1
- package/dist/{CopyButton-B_mYxcXV.js → CopyButton-hZqLdXJq.js} +3 -3
- package/dist/{CopyButton-B_mYxcXV.js.map → CopyButton-hZqLdXJq.js.map} +1 -1
- package/dist/{DatePicker-Bt-M87zX.js → DatePicker-B6ZL_T-E.js} +5 -5
- package/dist/{DatePicker-Bt-M87zX.js.map → DatePicker-B6ZL_T-E.js.map} +1 -1
- package/dist/{DatePicker-D1uFIm3M.cjs → DatePicker-DXwJB4MH.cjs} +2 -2
- package/dist/{DatePicker-D1uFIm3M.cjs.map → DatePicker-DXwJB4MH.cjs.map} +1 -1
- package/dist/{DateTimePicker-zJUc9crs.js → DateTimePicker-BynW1Eeg.js} +8 -8
- package/dist/{DateTimePicker-zJUc9crs.js.map → DateTimePicker-BynW1Eeg.js.map} +1 -1
- package/dist/{DateTimePicker-DPt-LDVJ.cjs → DateTimePicker-CHi1H2k1.cjs} +2 -2
- package/dist/{DateTimePicker-DPt-LDVJ.cjs.map → DateTimePicker-CHi1H2k1.cjs.map} +1 -1
- package/dist/{DescriptionList-CPCbzU9b.cjs → DescriptionList-BqYwp08t.cjs} +2 -2
- package/dist/{DescriptionList-CPCbzU9b.cjs.map → DescriptionList-BqYwp08t.cjs.map} +1 -1
- package/dist/{DescriptionList-BLx9NfAW.js → DescriptionList-C6Gfk6I_.js} +5 -5
- package/dist/{DescriptionList-BLx9NfAW.js.map → DescriptionList-C6Gfk6I_.js.map} +1 -1
- package/dist/{EmptyState-BEVEGcLx.js → EmptyState-BvAA5mYO.js} +2 -2
- package/dist/{EmptyState-BEVEGcLx.js.map → EmptyState-BvAA5mYO.js.map} +1 -1
- package/dist/{EmptyState-C54C0Qwc.cjs → EmptyState-CZ6X5-Zy.cjs} +2 -2
- package/dist/{EmptyState-C54C0Qwc.cjs.map → EmptyState-CZ6X5-Zy.cjs.map} +1 -1
- package/dist/{ErrorBoundary-BSJL381Y.js → ErrorBoundary-BS0x9RVO.js} +14 -6
- package/dist/ErrorBoundary-BS0x9RVO.js.map +1 -0
- package/dist/ErrorBoundary-WwmJrL6o.cjs +2 -0
- package/dist/ErrorBoundary-WwmJrL6o.cjs.map +1 -0
- package/dist/ErrorState-BTSGKrJq.js +178 -0
- package/dist/ErrorState-BTSGKrJq.js.map +1 -0
- package/dist/ErrorState-DRXuV6na.cjs +4 -0
- package/dist/ErrorState-DRXuV6na.cjs.map +1 -0
- package/dist/{FileCard-R_sB8Qbx.js → FileCard-CxZ3o4BO.js} +4 -4
- package/dist/{FileCard-R_sB8Qbx.js.map → FileCard-CxZ3o4BO.js.map} +1 -1
- package/dist/{FileCard-B3dfdTVN.cjs → FileCard-ZZNd_tUN.cjs} +2 -2
- package/dist/{FileCard-B3dfdTVN.cjs.map → FileCard-ZZNd_tUN.cjs.map} +1 -1
- package/dist/{FileUploader-4UMy0urx.cjs → FileUploader-B--hPV3b.cjs} +2 -2
- package/dist/{FileUploader-4UMy0urx.cjs.map → FileUploader-B--hPV3b.cjs.map} +1 -1
- package/dist/{FileUploader-B55atuxq.js → FileUploader-CPah0hUe.js} +6 -6
- package/dist/{FileUploader-B55atuxq.js.map → FileUploader-CPah0hUe.js.map} +1 -1
- package/dist/{Flag-CFvJHC0u.cjs → Flag-C4La35rA.cjs} +2 -2
- package/dist/{Flag-CFvJHC0u.cjs.map → Flag-C4La35rA.cjs.map} +1 -1
- package/dist/{Flag-D7fmMqqy.js → Flag-DikEV1jI.js} +2 -2
- package/dist/{Flag-D7fmMqqy.js.map → Flag-DikEV1jI.js.map} +1 -1
- package/dist/{FullscreenToggle-CXmPqxJv.js → FullscreenToggle-CTt7_Kv_.js} +3 -3
- package/dist/{FullscreenToggle-CXmPqxJv.js.map → FullscreenToggle-CTt7_Kv_.js.map} +1 -1
- package/dist/{FullscreenToggle-D7tUPCNI.cjs → FullscreenToggle-ejjFFd9a.cjs} +2 -2
- package/dist/{FullscreenToggle-D7tUPCNI.cjs.map → FullscreenToggle-ejjFFd9a.cjs.map} +1 -1
- package/dist/{IconButton-sC_E_TXd.js → IconButton-BUmXN_lD.js} +2 -2
- package/dist/{IconButton-sC_E_TXd.js.map → IconButton-BUmXN_lD.js.map} +1 -1
- package/dist/{IconButton-BVrO9TBP.cjs → IconButton-CYMvszcM.cjs} +2 -2
- package/dist/{IconButton-BVrO9TBP.cjs.map → IconButton-CYMvszcM.cjs.map} +1 -1
- package/dist/{Loader-DNCEHqZb.cjs → Loader-DkwiCGbB.cjs} +2 -2
- package/dist/{Loader-DNCEHqZb.cjs.map → Loader-DkwiCGbB.cjs.map} +1 -1
- package/dist/{Loader-ChrouvaR.js → Loader-jh7XMRhy.js} +2 -2
- package/dist/{Loader-ChrouvaR.js.map → Loader-jh7XMRhy.js.map} +1 -1
- package/dist/{LocationPicker-DxiQ27k6.js → LocationPicker-Cdm7BCX5.js} +7 -7
- package/dist/{LocationPicker-DxiQ27k6.js.map → LocationPicker-Cdm7BCX5.js.map} +1 -1
- package/dist/{LocationPicker-CJ6bCJC4.cjs → LocationPicker-D-9mrCVD.cjs} +2 -2
- package/dist/{LocationPicker-CJ6bCJC4.cjs.map → LocationPicker-D-9mrCVD.cjs.map} +1 -1
- package/dist/{Modal-Do8pzyMl.js → Modal-CrvOHbNy.js} +3 -3
- package/dist/{Modal-Do8pzyMl.js.map → Modal-CrvOHbNy.js.map} +1 -1
- package/dist/{Modal-BL_XihC8.cjs → Modal-eI6QL-LM.cjs} +2 -2
- package/dist/{Modal-BL_XihC8.cjs.map → Modal-eI6QL-LM.cjs.map} +1 -1
- package/dist/{MultiSelect-BfsEdXNa.js → MultiSelect-BTilYrXp.js} +5 -5
- package/dist/{MultiSelect-BfsEdXNa.js.map → MultiSelect-BTilYrXp.js.map} +1 -1
- package/dist/{MultiSelect-WS5YNGRD.cjs → MultiSelect-B_Jenpgv.cjs} +2 -2
- package/dist/{MultiSelect-WS5YNGRD.cjs.map → MultiSelect-B_Jenpgv.cjs.map} +1 -1
- package/dist/{MultilineTextField-BgfBFeeF.js → MultilineTextField-DJ26nTdF.js} +2 -2
- package/dist/{MultilineTextField-BgfBFeeF.js.map → MultilineTextField-DJ26nTdF.js.map} +1 -1
- package/dist/{MultilineTextField-B6EYAdik.cjs → MultilineTextField-ihcPDX3D.cjs} +2 -2
- package/dist/{MultilineTextField-B6EYAdik.cjs.map → MultilineTextField-ihcPDX3D.cjs.map} +1 -1
- package/dist/{NumberField-P68n6q5m.js → NumberField-DEoaxFJj.js} +4 -4
- package/dist/{NumberField-P68n6q5m.js.map → NumberField-DEoaxFJj.js.map} +1 -1
- package/dist/{NumberField-CxiEfRAi.cjs → NumberField-czWHuAyt.cjs} +2 -2
- package/dist/{NumberField-CxiEfRAi.cjs.map → NumberField-czWHuAyt.cjs.map} +1 -1
- package/dist/{OtpField-XieJfl1y.cjs → OtpField-DK5KikOt.cjs} +2 -2
- package/dist/{OtpField-XieJfl1y.cjs.map → OtpField-DK5KikOt.cjs.map} +1 -1
- package/dist/{OtpField-DjTJH4Kh.js → OtpField-v2RuXdsE.js} +3 -3
- package/dist/{OtpField-DjTJH4Kh.js.map → OtpField-v2RuXdsE.js.map} +1 -1
- package/dist/PageError-CIVYNLTW.cjs +2 -0
- package/dist/{PageError-D7_Q8wz8.cjs.map → PageError-CIVYNLTW.cjs.map} +1 -1
- package/dist/PageError-CyMdVrxL.js +70 -0
- package/dist/{PageError-ClR7k0Zb.js.map → PageError-CyMdVrxL.js.map} +1 -1
- package/dist/{PageLayout-XQ_aQTf5.js → PageLayout-BtukUUfe.js} +2 -2
- package/dist/{PageLayout-XQ_aQTf5.js.map → PageLayout-BtukUUfe.js.map} +1 -1
- package/dist/{PageLayout-DTG83hLL.cjs → PageLayout-C_daDKkg.cjs} +2 -2
- package/dist/{PageLayout-DTG83hLL.cjs.map → PageLayout-C_daDKkg.cjs.map} +1 -1
- package/dist/{PageNotFound-D3wJ4Job.cjs → PageNotFound-CHb8DlqC.cjs} +2 -2
- package/dist/{PageNotFound-D3wJ4Job.cjs.map → PageNotFound-CHb8DlqC.cjs.map} +1 -1
- package/dist/{PageNotFound-CpwHMTxG.js → PageNotFound-DQ-OvU_O.js} +5 -5
- package/dist/{PageNotFound-CpwHMTxG.js.map → PageNotFound-DQ-OvU_O.js.map} +1 -1
- package/dist/{Pagination-Df-F9i2o.js → Pagination-BjufY1mt.js} +2 -2
- package/dist/{Pagination-Df-F9i2o.js.map → Pagination-BjufY1mt.js.map} +1 -1
- package/dist/{Pagination-BF8cmQMi.cjs → Pagination-jLyJa8iL.cjs} +2 -2
- package/dist/{Pagination-BF8cmQMi.cjs.map → Pagination-jLyJa8iL.cjs.map} +1 -1
- package/dist/{PaletteField-BFRPv7AC.cjs → PaletteField-DGaV7VJ9.cjs} +2 -2
- package/dist/{PaletteField-BFRPv7AC.cjs.map → PaletteField-DGaV7VJ9.cjs.map} +1 -1
- package/dist/{PaletteField-DUu4jz1c.js → PaletteField-DTfV8Lny.js} +3 -3
- package/dist/{PaletteField-DUu4jz1c.js.map → PaletteField-DTfV8Lny.js.map} +1 -1
- package/dist/{PhoneField-CXIQX_hR.js → PhoneField-BSIhBMW2.js} +5 -5
- package/dist/{PhoneField-CXIQX_hR.js.map → PhoneField-BSIhBMW2.js.map} +1 -1
- package/dist/{PhoneField-O5syyH7u.cjs → PhoneField-DchrnSiE.cjs} +2 -2
- package/dist/{PhoneField-O5syyH7u.cjs.map → PhoneField-DchrnSiE.cjs.map} +1 -1
- package/dist/{Popconfirm-bEoOPmZY.cjs → Popconfirm-l9au66oY.cjs} +2 -2
- package/dist/{Popconfirm-bEoOPmZY.cjs.map → Popconfirm-l9au66oY.cjs.map} +1 -1
- package/dist/{Popconfirm-D4J7tlk_.js → Popconfirm-p2O8Vmz0.js} +3 -3
- package/dist/{Popconfirm-D4J7tlk_.js.map → Popconfirm-p2O8Vmz0.js.map} +1 -1
- package/dist/{Progress-BxvqmmGS.js → Progress-C-VGs3yJ.js} +2 -2
- package/dist/{Progress-BxvqmmGS.js.map → Progress-C-VGs3yJ.js.map} +1 -1
- package/dist/{Progress-CqXX0rRp.cjs → Progress-Cqr2_BF1.cjs} +2 -2
- package/dist/{Progress-CqXX0rRp.cjs.map → Progress-Cqr2_BF1.cjs.map} +1 -1
- package/dist/{QrCode-osD23Vkt.js → QrCode-B9YbQNVc.js} +2 -2
- package/dist/{QrCode-osD23Vkt.js.map → QrCode-B9YbQNVc.js.map} +1 -1
- package/dist/{QrCode-BQ1eUiAJ.cjs → QrCode-CNVYpz9j.cjs} +2 -2
- package/dist/{QrCode-BQ1eUiAJ.cjs.map → QrCode-CNVYpz9j.cjs.map} +1 -1
- package/dist/{RadioGroup-CvC2yc4p.cjs → RadioGroup-687BVZ7k.cjs} +2 -2
- package/dist/{RadioGroup-CvC2yc4p.cjs.map → RadioGroup-687BVZ7k.cjs.map} +1 -1
- package/dist/{RadioGroup-CTAayuMv.js → RadioGroup-CD209tlb.js} +2 -2
- package/dist/{RadioGroup-CTAayuMv.js.map → RadioGroup-CD209tlb.js.map} +1 -1
- package/dist/{RemoveDialog-DH3eNUxC.js → RemoveDialog-BKgWohkG.js} +6 -6
- package/dist/{RemoveDialog-DH3eNUxC.js.map → RemoveDialog-BKgWohkG.js.map} +1 -1
- package/dist/{RemoveDialog-FrieNcjL.cjs → RemoveDialog-eGCbOuuM.cjs} +2 -2
- package/dist/{RemoveDialog-FrieNcjL.cjs.map → RemoveDialog-eGCbOuuM.cjs.map} +1 -1
- package/dist/{RichTextEditor-B-C4NPDk.cjs → RichTextEditor-BPAD4ISz.cjs} +2 -2
- package/dist/{RichTextEditor-B-C4NPDk.cjs.map → RichTextEditor-BPAD4ISz.cjs.map} +1 -1
- package/dist/{RichTextEditor-6frB2C5G.js → RichTextEditor-C24uBIWh.js} +8 -8
- package/dist/{RichTextEditor-6frB2C5G.js.map → RichTextEditor-C24uBIWh.js.map} +1 -1
- package/dist/RootLayout-BY_BxQ0C.cjs +2 -0
- package/dist/RootLayout-BY_BxQ0C.cjs.map +1 -0
- package/dist/RootLayout-CicjlAUF.js +641 -0
- package/dist/RootLayout-CicjlAUF.js.map +1 -0
- package/dist/{Select-Bjq_p8_e.cjs → Select-BbgueWwN.cjs} +2 -2
- package/dist/{Select-Bjq_p8_e.cjs.map → Select-BbgueWwN.cjs.map} +1 -1
- package/dist/{Select-DO3zDQYV.js → Select-DEi_ZUHR.js} +4 -4
- package/dist/{Select-DO3zDQYV.js.map → Select-DEi_ZUHR.js.map} +1 -1
- package/dist/{Sidebar-2oH285Xs.cjs → Sidebar-D-nR8Cu6.cjs} +2 -2
- package/dist/{Sidebar-2oH285Xs.cjs.map → Sidebar-D-nR8Cu6.cjs.map} +1 -1
- package/dist/{Sidebar-CKbSWc5q.js → Sidebar-nORfjIg8.js} +4 -4
- package/dist/{Sidebar-CKbSWc5q.js.map → Sidebar-nORfjIg8.js.map} +1 -1
- package/dist/{Slider-Cu1FhxR2.cjs → Slider-0joKXhPo.cjs} +2 -2
- package/dist/{Slider-Cu1FhxR2.cjs.map → Slider-0joKXhPo.cjs.map} +1 -1
- package/dist/{Slider-DoQJWgGU.js → Slider-CwZYxDO0.js} +2 -2
- package/dist/{Slider-DoQJWgGU.js.map → Slider-CwZYxDO0.js.map} +1 -1
- package/dist/{SpeedDial-BZK-z_r9.js → SpeedDial-BMpJtYP6.js} +2 -2
- package/dist/{SpeedDial-BZK-z_r9.js.map → SpeedDial-BMpJtYP6.js.map} +1 -1
- package/dist/{SpeedDial-KGf8b4Gq.cjs → SpeedDial-D5uk_E5v.cjs} +2 -2
- package/dist/{SpeedDial-KGf8b4Gq.cjs.map → SpeedDial-D5uk_E5v.cjs.map} +1 -1
- package/dist/{Stepper-s9Vah5R2.cjs → Stepper-BRksGDK1.cjs} +2 -2
- package/dist/{Stepper-s9Vah5R2.cjs.map → Stepper-BRksGDK1.cjs.map} +1 -1
- package/dist/{Stepper-BI3pjWf_.js → Stepper-D8bRyyhl.js} +2 -2
- package/dist/{Stepper-BI3pjWf_.js.map → Stepper-D8bRyyhl.js.map} +1 -1
- package/dist/{SwatchPicker-CpwVq0xp.cjs → SwatchPicker-BVW_yhRU.cjs} +2 -2
- package/dist/{SwatchPicker-CpwVq0xp.cjs.map → SwatchPicker-BVW_yhRU.cjs.map} +1 -1
- package/dist/{SwatchPicker-BAKslSY4.js → SwatchPicker-C-_wLaf6.js} +2 -2
- package/dist/{SwatchPicker-BAKslSY4.js.map → SwatchPicker-C-_wLaf6.js.map} +1 -1
- package/dist/{Table-PsNnKn_j.js → Table-C0RDylA0.js} +18 -18
- package/dist/{Table-PsNnKn_j.js.map → Table-C0RDylA0.js.map} +1 -1
- package/dist/{Table-CLjLsYYS.cjs → Table-CGIip6UL.cjs} +2 -2
- package/dist/{Table-CLjLsYYS.cjs.map → Table-CGIip6UL.cjs.map} +1 -1
- package/dist/{Tabs-DQoNP0QT.cjs → Tabs-BzbSNmBj.cjs} +2 -2
- package/dist/{Tabs-DQoNP0QT.cjs.map → Tabs-BzbSNmBj.cjs.map} +1 -1
- package/dist/{Tabs-B2WzlRXI.js → Tabs-CQvfqazt.js} +2 -2
- package/dist/{Tabs-B2WzlRXI.js.map → Tabs-CQvfqazt.js.map} +1 -1
- package/dist/{TagsField-pdvQU4zh.js → TagsField-BdM-xre0.js} +5 -5
- package/dist/{TagsField-pdvQU4zh.js.map → TagsField-BdM-xre0.js.map} +1 -1
- package/dist/{TagsField-CLfAAz4N.cjs → TagsField-CGL1oI7b.cjs} +2 -2
- package/dist/{TagsField-CLfAAz4N.cjs.map → TagsField-CGL1oI7b.cjs.map} +1 -1
- package/dist/{TextField-CgPfN-4d.cjs → TextField-D49Lpbjt.cjs} +2 -2
- package/dist/{TextField-CgPfN-4d.cjs.map → TextField-D49Lpbjt.cjs.map} +1 -1
- package/dist/{TextField-LONfx4jy.js → TextField-otYGVuwF.js} +4 -4
- package/dist/{TextField-LONfx4jy.js.map → TextField-otYGVuwF.js.map} +1 -1
- package/dist/{ThemeToggle-9RBaRALj.cjs → ThemeToggle-B8rkRTis.cjs} +2 -2
- package/dist/{ThemeToggle-9RBaRALj.cjs.map → ThemeToggle-B8rkRTis.cjs.map} +1 -1
- package/dist/{ThemeToggle-DTkFppOd.js → ThemeToggle-D33Tqv2F.js} +3 -3
- package/dist/{ThemeToggle-DTkFppOd.js.map → ThemeToggle-D33Tqv2F.js.map} +1 -1
- package/dist/{TimeColumns-B7af5Cbj.js → TimeColumns-DyjTpZbD.js} +2 -2
- package/dist/{TimeColumns-B7af5Cbj.js.map → TimeColumns-DyjTpZbD.js.map} +1 -1
- package/dist/{TimeColumns-CJ13uf3K.cjs → TimeColumns-qEHHZC1N.cjs} +2 -2
- package/dist/{TimeColumns-CJ13uf3K.cjs.map → TimeColumns-qEHHZC1N.cjs.map} +1 -1
- package/dist/{TimePicker-Dshko7IJ.cjs → TimePicker-DJrNO01U.cjs} +2 -2
- package/dist/{TimePicker-Dshko7IJ.cjs.map → TimePicker-DJrNO01U.cjs.map} +1 -1
- package/dist/{TimePicker-BitZ7wv-.js → TimePicker-yfYqLbj3.js} +6 -6
- package/dist/{TimePicker-BitZ7wv-.js.map → TimePicker-yfYqLbj3.js.map} +1 -1
- package/dist/{Toaster-8ynQTcc0.cjs → Toaster-B7Xd2IaM.cjs} +2 -2
- package/dist/{Toaster-8ynQTcc0.cjs.map → Toaster-B7Xd2IaM.cjs.map} +1 -1
- package/dist/{Toaster-CYVETXVZ.js → Toaster-D8cxkhwr.js} +2 -2
- package/dist/{Toaster-CYVETXVZ.js.map → Toaster-D8cxkhwr.js.map} +1 -1
- package/dist/{TranslatedFields-BKI3jrNd.cjs → TranslatedFields-BvqqdNWz.cjs} +2 -2
- package/dist/{TranslatedFields-BKI3jrNd.cjs.map → TranslatedFields-BvqqdNWz.cjs.map} +1 -1
- package/dist/{TranslatedFields-dmb-0Yn7.js → TranslatedFields-CsSsTrnF.js} +5 -5
- package/dist/{TranslatedFields-dmb-0Yn7.js.map → TranslatedFields-CsSsTrnF.js.map} +1 -1
- package/dist/Typography-ChSuxgkc.js +74 -0
- package/dist/Typography-ChSuxgkc.js.map +1 -0
- package/dist/Typography-d97DdbNd.cjs +2 -0
- package/dist/Typography-d97DdbNd.cjs.map +1 -0
- package/dist/{UserCard-pEJZqiDF.js → UserCard-CsZ4Ogac.js} +4 -4
- package/dist/{UserCard-pEJZqiDF.js.map → UserCard-CsZ4Ogac.js.map} +1 -1
- package/dist/{UserCard-ah6K1y0H.cjs → UserCard-Die7JV4z.cjs} +2 -2
- package/dist/{UserCard-ah6K1y0H.cjs.map → UserCard-Die7JV4z.cjs.map} +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/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/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/ColorRamp/index.cjs +1 -1
- package/dist/components/ColorRamp/index.js +1 -1
- package/dist/components/CopyButton/index.cjs +1 -1
- package/dist/components/CopyButton/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/DescriptionList/index.cjs +1 -1
- package/dist/components/DescriptionList/index.js +1 -1
- package/dist/components/EmptyState/index.cjs +1 -1
- package/dist/components/EmptyState/index.js +1 -1
- package/dist/components/ErrorState/ErrorDetailsModal.d.cts +12 -0
- package/dist/components/ErrorState/ErrorDetailsModal.d.ts +12 -0
- package/dist/components/ErrorState/ErrorState.d.cts +23 -24
- package/dist/components/ErrorState/ErrorState.d.ts +23 -24
- package/dist/components/ErrorState/QueryError.d.cts +3 -3
- package/dist/components/ErrorState/QueryError.d.ts +3 -3
- package/dist/components/ErrorState/index.cjs +1 -1
- package/dist/components/ErrorState/index.js +2 -2
- 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/IconButton/index.cjs +1 -1
- package/dist/components/IconButton/index.js +1 -1
- package/dist/components/Loader/index.cjs +1 -1
- package/dist/components/Loader/index.js +1 -1
- package/dist/components/LocationPicker/index.cjs +1 -1
- package/dist/components/LocationPicker/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/MultilineTextField/index.cjs +1 -1
- package/dist/components/MultilineTextField/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/PageError/index.cjs +1 -1
- package/dist/components/PageError/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/PaletteField/index.cjs +1 -1
- package/dist/components/PaletteField/index.js +1 -1
- package/dist/components/PhoneField/index.cjs +1 -1
- package/dist/components/PhoneField/index.js +1 -1
- package/dist/components/Popconfirm/index.cjs +1 -1
- package/dist/components/Popconfirm/index.js +1 -1
- package/dist/components/Progress/index.cjs +1 -1
- package/dist/components/Progress/index.js +1 -1
- package/dist/components/QrCode/index.cjs +1 -1
- package/dist/components/QrCode/index.js +1 -1
- package/dist/components/Radio/index.cjs +1 -1
- package/dist/components/Radio/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/RootLayout.d.cts +6 -1
- package/dist/components/RootLayout/RootLayout.d.ts +6 -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/Slider/index.cjs +1 -1
- package/dist/components/Slider/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/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TranslatedFields/index.cjs +1 -1
- package/dist/components/TranslatedFields/index.js +1 -1
- package/dist/components/Typography/Typography.d.cts +7 -1
- package/dist/components/Typography/Typography.d.ts +7 -1
- package/dist/components/Typography/index.cjs +1 -1
- package/dist/components/Typography/index.js +1 -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 +58 -58
- package/dist/entries/i18n.cjs +1 -1
- package/dist/entries/i18n.js +2 -2
- package/dist/entries/theme.cjs +1 -1
- package/dist/entries/theme.d.cts +1 -1
- package/dist/entries/theme.d.ts +1 -1
- package/dist/entries/theme.js +1 -1
- package/dist/i18n/messages.d.cts +6 -0
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +61 -61
- package/dist/messages-DYXyWU3X.cjs +36 -0
- package/dist/messages-DYXyWU3X.cjs.map +1 -0
- package/dist/{messages-C1eTrGJy.js → messages-zarEtcsN.js} +25 -4
- package/dist/messages-zarEtcsN.js.map +1 -0
- package/dist/theme/ConfigProvider.d.cts +21 -2
- package/dist/theme/ConfigProvider.d.ts +21 -2
- package/dist/theme/index.d.cts +1 -1
- package/dist/theme/index.d.ts +1 -1
- package/dist/{useHomeTo-yTXajO22.js → useHomeTo-DVMyLZbb.js} +2 -2
- package/dist/{useHomeTo-yTXajO22.js.map → useHomeTo-DVMyLZbb.js.map} +1 -1
- package/dist/{useHomeTo-Cr6Usr_D.cjs → useHomeTo-Dnu6VAvU.cjs} +2 -2
- package/dist/{useHomeTo-Cr6Usr_D.cjs.map → useHomeTo-Dnu6VAvU.cjs.map} +1 -1
- package/dist/{useOptionMenu-DK0ixg-p.js → useOptionMenu-DNYlfNO_.js} +4 -4
- package/dist/{useOptionMenu-DK0ixg-p.js.map → useOptionMenu-DNYlfNO_.js.map} +1 -1
- package/dist/{useOptionMenu-DHGSbQmS.cjs → useOptionMenu-OAYGUWP_.cjs} +2 -2
- package/dist/{useOptionMenu-DHGSbQmS.cjs.map → useOptionMenu-OAYGUWP_.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/ConfigProvider-CVLHPXQm.cjs.map +0 -1
- package/dist/ConfigProvider-tvLbKiqu.js.map +0 -1
- package/dist/ErrorBoundary-8iu-mR5Y.cjs +0 -2
- package/dist/ErrorBoundary-8iu-mR5Y.cjs.map +0 -1
- package/dist/ErrorBoundary-BSJL381Y.js.map +0 -1
- package/dist/ErrorState-BXMjBWav.cjs +0 -4
- package/dist/ErrorState-BXMjBWav.cjs.map +0 -1
- package/dist/ErrorState-DKhZ4aJh.js +0 -142
- package/dist/ErrorState-DKhZ4aJh.js.map +0 -1
- package/dist/PageError-ClR7k0Zb.js +0 -69
- package/dist/PageError-D7_Q8wz8.cjs +0 -2
- package/dist/RootLayout-C7n79JjM.js +0 -621
- package/dist/RootLayout-C7n79JjM.js.map +0 -1
- package/dist/RootLayout-CtkpgPGV.cjs +0 -2
- package/dist/RootLayout-CtkpgPGV.cjs.map +0 -1
- package/dist/Typography-B6ASPrzT.cjs +0 -2
- package/dist/Typography-B6ASPrzT.cjs.map +0 -1
- package/dist/Typography-CJv5AnRP.js +0 -70
- package/dist/Typography-CJv5AnRP.js.map +0 -1
- package/dist/messages-C1eTrGJy.js.map +0 -1
- package/dist/messages-DCr7iFmv.cjs +0 -36
- package/dist/messages-DCr7iFmv.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneField-CXIQX_hR.js","sources":["../src/components/PhoneField/phone.ts","../src/components/PhoneField/PhoneField.tsx"],"sourcesContent":["import type * as PhoneLibModule from 'libphonenumber-js'\nimport type { CountryCode } from 'libphonenumber-js'\nimport { optionalPeer } from '../../hooks/useOptionalPeer'\n\n/**\n * `libphonenumber-js` is an optional peer, loaded **lazily** (see `optionalPeer`) — never imported\n * statically, so apps that don't install it still build + run when they import the barrel. PhoneField\n * waits for it on mount; the helpers below run only once it's loaded (`lib()`).\n */\nexport const phonePeer = optionalPeer<typeof PhoneLibModule>(\n 'libphonenumber-js',\n 'PhoneField',\n () => import('libphonenumber-js'),\n)\nconst lib = () => phonePeer.get()!\n\n/** An ISO-3166 alpha-2 country code, as `libphonenumber-js` knows it (`'GE'`, `'US'`, …). */\nexport type PhoneCountry = CountryCode\n/** How the number is shown in the input while typing (the value is always E.164). */\nexport type PhoneFormat = 'national' | 'international'\n\nlet allCountries: readonly PhoneCountry[] | undefined\n/** Every country `libphonenumber-js` has metadata for (once loaded). */\nexport function getPhoneCountries(): readonly PhoneCountry[] {\n return (allCountries ??= lib().getCountries())\n}\n\n/** The country's calling code without the `+` — `'GE'` → `'995'`. */\nexport const callingCodeOf = (country: PhoneCountry): string => lib().getCountryCallingCode(country)\n\n/**\n * `true` for a complete, valid number (E.164 or any parseable international form). Use it in a schema:\n * `phone: z.string().refine(isValidPhone, 'Enter a valid phone number')`. Needs `libphonenumber-js`\n * loaded — it is once any PhoneField has mounted; before that it starts the load and returns `false`.\n */\nexport function isValidPhone(value: unknown): boolean {\n const loaded = phonePeer.get()\n // not loaded yet (no PhoneField mounted so far) → start loading and report \"not valid\" for now\n if (!loaded) {\n void phonePeer.load()\n return false\n }\n return typeof value === 'string' && value.trim() !== '' && loaded.isValidPhoneNumber(value)\n}\n\n/** A flag emoji from the two regional-indicator letters — no image assets (Windows shows the letters). */\nexport function flagEmoji(country: string): string {\n return String.fromCodePoint(\n ...[...country.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65),\n )\n}\n\nconst displayNamesCache = new Map<string, Intl.DisplayNames | null>()\n/** The country's name in `locale` via `Intl.DisplayNames` (no catalog to ship); falls back to the code. */\nexport function countryName(country: string, locale: string): string {\n if (!displayNamesCache.has(locale)) {\n try {\n displayNamesCache.set(locale, new Intl.DisplayNames([locale], { type: 'region' }))\n } catch {\n displayNamesCache.set(locale, null)\n }\n }\n try {\n return displayNamesCache.get(locale)?.of(country) ?? country\n } catch {\n return country\n }\n}\n\n// the main country for a calling code shared by several (a partial \"+44…\" parses as Guernsey otherwise)\nconst MAIN_FOR_CODE: Record<string, PhoneCountry> = {\n '1': 'US',\n '7': 'RU',\n '39': 'IT',\n '44': 'GB',\n '47': 'NO',\n '61': 'AU',\n '212': 'MA',\n '262': 'RE',\n '290': 'SH',\n '358': 'FI',\n '590': 'GP',\n '599': 'CW',\n}\n// base UI language → its usual country, for the default when the locale carries no region\nconst LANGUAGE_COUNTRY: Record<string, PhoneCountry> = {\n ka: 'GE',\n en: 'US',\n es: 'ES',\n de: 'DE',\n it: 'IT',\n fr: 'FR',\n ru: 'RU',\n}\n\n/** The default country: the locale's region → its language's usual country → the browser's region → US. */\nexport function detectCountry(locale: string, allowed: readonly PhoneCountry[]): PhoneCountry {\n const [base, region] = locale.split('-')\n const browser =\n typeof navigator !== 'undefined' ? navigator.language?.split('-')[1]?.toUpperCase() : undefined\n const candidates = [region?.toUpperCase(), LANGUAGE_COUNTRY[base?.toLowerCase()], browser, 'US']\n return (candidates.find((c) => c && allowed.includes(c as PhoneCountry)) ??\n allowed[0]) as PhoneCountry\n}\n\n/** The result of reading what's in the input. */\nexport interface PhoneReading {\n /** The canonical value — `'+995555123456'`, or `''` when empty. */\n e164: string\n /** The country the number belongs to (may switch when a `+code` is typed). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number. */\n valid: boolean\n /** What the input should show (formatted as you type). */\n display: string\n}\n\nconst digitsOf = (s: string) => s.replace(/\\D/g, '')\n\n/** Which allowed country a `+code…` number belongs to — keep the current one when it shares the code. */\nfunction countryForCode(\n code: string,\n current: PhoneCountry,\n detected: PhoneCountry | undefined,\n allowed: readonly PhoneCountry[],\n): PhoneCountry {\n if (callingCodeOf(current) === code) return current\n const pick = [detected, MAIN_FOR_CODE[code], ...allowed.filter((c) => callingCodeOf(c) === code)]\n return (pick.find((c) => c && allowed.includes(c)) as PhoneCountry | undefined) ?? current\n}\n\n/** Read raw input text → the canonical value + the formatted display, as the user types. */\nexport function readPhoneInput(\n raw: string,\n country: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): PhoneReading {\n const text = raw.trimStart()\n const digits = digitsOf(text)\n if (!digits) {\n return {\n e164: '',\n country,\n national: '',\n valid: false,\n display: text.startsWith('+') ? '+' : '',\n }\n }\n\n // an explicit \"+code…\" (typed or pasted) — the calling code decides the country\n if (text.startsWith('+')) {\n const typer = new (lib().AsYouType)()\n const display = typer.input(`+${digits}`)\n const code = typer.getCallingCode()\n const parsed = lib().parsePhoneNumberFromString(`+${digits}`)\n const next = code\n ? countryForCode(code, country, parsed?.country ?? typer.getCountry(), allowed)\n : country\n const e164 = `+${digits}`\n return {\n e164,\n country: next,\n national: code ? digits.slice(code.length) : '',\n valid: lib().isValidPhoneNumber(e164),\n display,\n }\n }\n\n // national digits under the selected country (a leading trunk \"0\" is dropped from the value)\n const code = callingCodeOf(country)\n const parsed = lib().parsePhoneNumberFromString(digits, country)\n const national = parsed?.nationalNumber ?? digits.replace(/^0+/, '')\n const e164 = national ? `+${code}${national}` : ''\n const display =\n format === 'international'\n ? new (lib().AsYouType)(country).input(`+${code}${national}`)\n : new (lib().AsYouType)(country).input(digits)\n return {\n e164,\n country,\n national,\n valid: e164 !== '' && lib().isValidPhoneNumber(e164),\n display,\n }\n}\n\n/** Derive the country + display from an E.164 value (initial / external value changes). */\nexport function phoneFromValue(\n value: string,\n fallback: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): { country: PhoneCountry; display: string } {\n if (!value) return { country: fallback, display: '' }\n const parsed = lib().parsePhoneNumberFromString(value)\n if (parsed) {\n const country = countryForCode(parsed.countryCallingCode, fallback, parsed.country, allowed)\n return {\n country,\n display: format === 'national' ? parsed.formatNational() : parsed.formatInternational(),\n }\n }\n const reading = readPhoneInput(value, fallback, 'international', allowed)\n const display =\n format === 'national' && reading.national\n ? new (lib().AsYouType)(reading.country).input(reading.national)\n : reading.display\n return { country: reading.country, display }\n}\n\n/** Caret index in `display` right after its `n`-th digit — keeps the caret put while reformatting. */\nexport function caretAfterDigits(display: string, n: number): number {\n if (n <= 0) return display.startsWith('+') ? 1 : 0\n let seen = 0\n for (let i = 0; i < display.length; i++) {\n if (/\\d/.test(display[i])) seen++\n if (seen === n) return i + 1\n }\n return display.length\n}\n","import {\n forwardRef,\n useCallback,\n useId,\n useLayoutEffect,\n useMemo,\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 { useLanguage, useT } from '../../theme'\nimport { useOptionalPeer } from '../../hooks/useOptionalPeer'\nimport { useFormContext } from '../../form/formContext'\nimport { Icon } from '../Icon'\nimport { TextField } from '../TextField'\nimport { OptionMenu } from '../OptionMenu/OptionMenu'\nimport { useOptionMenu, type SelectOption } from '../OptionMenu/useOptionMenu'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport {\n callingCodeOf,\n getPhoneCountries,\n caretAfterDigits,\n countryName,\n detectCountry,\n flagEmoji,\n phoneFromValue,\n phonePeer,\n readPhoneInput,\n type PhoneCountry,\n type PhoneFormat,\n} from './phone'\nimport styles from './PhoneField.module.css'\n\nexport type PhoneFieldSize = 'sm' | 'md' | 'lg'\n\n/** Extra details handed to `onChange` alongside the E.164 value. */\nexport interface PhoneFieldChangeMeta {\n /** The number's country (ISO alpha-2). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number for that country. */\n valid: boolean\n}\n\nexport interface PhoneFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'value' | 'defaultValue' | 'onChange' | 'type' | 'size' | 'color'\n> {\n /** The number in **E.164** (`'+995555123456'`) — the only form the field emits. `''` when empty. */\n value?: string\n /** Initial E.164 value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the E.164 value (`''` when cleared) and `{ country, national, valid }`. */\n onChange?: (value: string, meta: PhoneFieldChangeMeta) => void\n /** The country to start with. Defaults to one derived from the UI language / browser locale. */\n defaultCountry?: PhoneCountry\n /** Restrict the selectable countries (e.g. only where you operate). Defaults to all. */\n countries?: readonly PhoneCountry[]\n /** Countries pinned to the top of the list, in this order. */\n preferredCountries?: readonly PhoneCountry[]\n /**\n * How the number reads while typing — `national` (default: `555 12 34 56`, the calling code lives in\n * the country button) or `international` (`+995 555 12 34 56`). The value is E.164 either way.\n */\n format?: PhoneFormat\n /** Field label. */\n label?: ReactNode\n /** Helper / validation text under the field. */\n helperText?: ReactNode\n /** Error state (red border + helper). */\n error?: boolean\n /** Shows a required asterisk. */\n required?: boolean\n /** `sm` / `md` / `lg` — control height + type. Defaults to `md`. */\n size?: PhoneFieldSize\n /** Stretch to the container. Defaults to `true`. */\n fullWidth?: boolean\n}\n\n/** The field itself — rendered once `libphonenumber-js` has loaded. */\nconst PhoneFieldInner = forwardRef<HTMLInputElement, PhoneFieldProps>(function PhoneFieldInner(\n {\n value,\n defaultValue,\n onChange,\n defaultCountry,\n countries: countriesProp,\n preferredCountries = [],\n format = 'national',\n label,\n helperText,\n error,\n required,\n size = 'md',\n fullWidth = true,\n name,\n disabled = false,\n id: idProp,\n className,\n style,\n onBlur,\n placeholder,\n ...props\n },\n ref,\n) {\n const t = useT()\n const { language } = useLanguage()\n const countries = countriesProp ?? getPhoneCountries()\n const reactId = useId()\n const id = idProp ?? reactId\n const helperId = `${id}-helper`\n\n // ── value: controlled / form-bound / uncontrolled — always E.164 ──\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = isFormBound ? form!.field(name!) : undefined\n const [internal, setInternal] = useState(defaultValue ?? '')\n const currentValue =\n value !== undefined\n ? value\n : isFormBound\n ? ((form!.values[name!] as string | undefined) ?? '')\n : internal\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n const fallbackCountry = useMemo<PhoneCountry>(\n () =>\n defaultCountry && countries.includes(defaultCountry)\n ? defaultCountry\n : detectCountry(language, countries),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [defaultCountry, language, countries.join()],\n )\n\n const [country, setCountry] = useState<PhoneCountry>(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).country,\n )\n const [display, setDisplay] = useState(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).display,\n )\n\n // re-derive the display when the value changes from OUTSIDE (a reset / a controlled update) — the\n // values we emit ourselves are skipped, so formatting never fights the user mid-typing\n const lastEmitted = useRef(currentValue)\n if (lastEmitted.current !== currentValue) {\n lastEmitted.current = currentValue\n const next = phoneFromValue(currentValue, country, format, countries)\n setCountry(next.country)\n setDisplay(next.display)\n }\n\n // caret restore after reformatting\n const innerRef = useRef<HTMLInputElement | 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 as { current: HTMLInputElement | null }).current = node\n },\n [ref],\n )\n const pendingCaret = useRef<number | null>(null)\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 emit = (reading: ReturnType<typeof readPhoneInput>) => {\n lastEmitted.current = reading.e164\n setDisplay(reading.display)\n if (reading.country !== country) setCountry(reading.country)\n if (value === undefined && !isFormBound) setInternal(reading.e164)\n if (isFormBound) form!.setValue(name!, reading.e164)\n onChange?.(reading.e164, {\n country: reading.country,\n national: reading.national,\n valid: reading.valid,\n })\n }\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const el = event.target\n let raw = el.value\n const caret = el.selectionStart ?? raw.length\n let digitsBefore = raw.slice(0, caret).replace(/\\D/g, '').length\n // backspace over a formatting char (space / paren / dash) would be re-added by the formatter —\n // treat it as deleting the digit before it instead\n const prevDigits = display.replace(/\\D/g, '')\n if (raw.length < display.length && raw.replace(/\\D/g, '') === prevDigits && digitsBefore > 0) {\n let seen = 0\n let cut = -1\n for (let i = 0; i < raw.length; i++) {\n if (/\\d/.test(raw[i]) && ++seen === digitsBefore) {\n cut = i\n break\n }\n }\n if (cut >= 0) raw = raw.slice(0, cut) + raw.slice(cut + 1)\n digitsBefore -= 1\n }\n const reading = readPhoneInput(raw, country, format, countries)\n pendingCaret.current =\n caret >= el.value.length\n ? reading.display.length\n : caretAfterDigits(reading.display, digitsBefore)\n emit(reading)\n }\n\n // ── country picker — the shared option menu (search matches name, ISO code, calling code) ──\n const controlRef = useRef<HTMLDivElement | null>(null)\n const countryOptions = useMemo<SelectOption[]>(() => {\n const toOption = (c: PhoneCountry): SelectOption => {\n const dial = callingCodeOf(c)\n return {\n value: c,\n label: countryName(c, language),\n icon: (\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(c)}\n </span>\n ),\n keywords: [c, dial, `+${dial}`],\n trailing: <span className={styles.dial}>+{dial}</span>,\n }\n }\n // preferred countries first (in the given order), then the rest A→Z by their localized name —\n // as two groups (\"Suggested\" / \"All Countries\") when there are preferred ones\n const pinned = preferredCountries.filter((c) => countries.includes(c)).map(toOption)\n const rest = countries\n .filter((c) => !preferredCountries.includes(c))\n .map(toOption)\n .sort((a, b) => a.label.localeCompare(b.label, language))\n if (pinned.length === 0) return rest\n return [\n ...pinned.map((o) => ({ ...o, group: t('phoneField.suggested') })),\n ...rest.map((o) => ({ ...o, group: t('phoneField.allCountries') })),\n ]\n }, [countries, preferredCountries, language, t])\n\n const pickCountry = (next: PhoneCountry) => {\n // keep the typed national digits, re-read under the new calling code\n const national = readPhoneInput(display, country, format, countries).national\n setCountry(next)\n emit({ ...readPhoneInput(national, next, format, countries), country: next })\n }\n\n const menu = useOptionMenu({\n idBase: `${id}-country`,\n options: countryOptions,\n isSelected: (o) => o.value === country,\n onPick: (o) => pickCountry(o.value as PhoneCountry),\n searchable: true,\n disabled,\n // after a pick / Esc, typing continues in the number\n focusRef: innerRef,\n })\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n bound?.onBlur(event)\n onBlur?.(event)\n }\n\n const describedBy = resolvedHelperText != null ? helperId : undefined\n const chevronPx = size === 'sm' ? 16 : size === 'md' ? 14 : 12\n const code = callingCodeOf(country)\n const name_ = countryName(country, language)\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 styles.phoneField,\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 ref={controlRef} className={clsx(fieldStyles.control, styles.control)}>\n <button\n type=\"button\"\n className={styles.country}\n aria-haspopup=\"listbox\"\n aria-expanded={menu.open}\n aria-controls={menu.open ? menu.listboxId : undefined}\n aria-label={`${t('phoneField.country')}: ${name_} (+${code})`}\n disabled={disabled}\n onClick={menu.toggleMenu}\n onKeyDown={(e) => {\n // ↓ / ↑ open the list (Enter / Space already click the button)\n if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !menu.open) {\n e.preventDefault()\n menu.openMenu()\n }\n }}\n >\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(country)}\n </span>\n {format === 'national' && <span className={styles.code}>+{code}</span>}\n {/* the same chevron as Select / MultiSelect (ArrowDown4, sized per field size: sm 16 · md 14 · lg 12) */}\n <Icon\n name=\"ArrowDown4\"\n className={clsx(styles.chevron, menu.open && styles.chevronOpen)}\n style={{ width: chevronPx, height: chevronPx }}\n aria-hidden=\"true\"\n />\n </button>\n <input\n ref={setInputRef}\n id={id}\n name={name}\n type=\"tel\"\n inputMode=\"tel\"\n autoComplete=\"tel\"\n className={fieldStyles.input}\n value={display}\n placeholder={placeholder}\n onChange={handleChange}\n onBlur={handleBlur}\n disabled={disabled}\n aria-invalid={resolvedError || undefined}\n aria-describedby={describedBy}\n {...props}\n />\n </div>\n\n <OptionMenu\n menu={menu}\n anchorRef={controlRef}\n size={size}\n searchPlaceholder={t('phoneField.search')}\n ariaLabel={t('phoneField.country')}\n />\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\n/**\n * A phone-number field: a **country button** (flag + `+code`, opening a searchable, localized country\n * list) inside the input frame, and the number **formatted as you type** for that country. The value is\n * always **E.164** (`'+995555123456'`) — one canonical form for the backend. Typing or pasting `+44…`\n * switches the country by its calling code. `onChange(value, { country, national, valid })`; binds to a\n * `<Form>` by `name` (the form value is the E.164 string — validate with `isValidPhone`). Country names\n * come from `Intl.DisplayNames` in the active UI language; flags are emoji. Needs the optional peer\n * **`libphonenumber-js`** (formatting, parsing, validation metadata), loaded lazily on first mount — until\n * it's ready (or if it isn't installed) a disabled look-alike field renders. Reuses the `TextField` look.\n */\nexport const PhoneField = forwardRef<HTMLInputElement, PhoneFieldProps>(\n function PhoneField(props, ref) {\n const { module } = useOptionalPeer(phonePeer)\n if (module) return <PhoneFieldInner ref={ref} {...props} />\n // loading (a tick, first mount only) or the peer is missing: the same frame, disabled — never bound\n // to a <Form> (no `name`) so it can't write a value\n const {\n label,\n helperText,\n error,\n required,\n size,\n fullWidth = true,\n className,\n style,\n placeholder,\n } = props\n return (\n <TextField\n ref={ref}\n type=\"tel\"\n label={label}\n helperText={helperText}\n error={error}\n required={required}\n size={size}\n fullWidth={fullWidth}\n className={className}\n style={style}\n placeholder={placeholder}\n value={props.value ?? props.defaultValue ?? ''}\n readOnly\n disabled\n />\n )\n },\n)\n"],"names":["phonePeer","optionalPeer","lib","allCountries","getPhoneCountries","callingCodeOf","country","isValidPhone","value","loaded","flagEmoji","c","displayNamesCache","countryName","locale","_a","MAIN_FOR_CODE","LANGUAGE_COUNTRY","detectCountry","allowed","base","region","browser","_b","digitsOf","s","countryForCode","code","current","detected","readPhoneInput","raw","format","text","digits","typer","display","parsed","next","e164","national","phoneFromValue","fallback","reading","caretAfterDigits","n","seen","i","PhoneFieldInner","forwardRef","defaultValue","onChange","defaultCountry","countriesProp","preferredCountries","label","helperText","error","required","size","fullWidth","name","disabled","idProp","className","style","onBlur","placeholder","props","ref","t","useT","language","useLanguage","countries","reactId","useId","id","helperId","form","useFormContext","isFormBound","bound","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","fallbackCountry","useMemo","setCountry","setDisplay","lastEmitted","useRef","innerRef","setInputRef","useCallback","node","pendingCaret","useLayoutEffect","pos","emit","handleChange","event","el","caret","digitsBefore","prevDigits","cut","controlRef","countryOptions","toOption","dial","jsx","styles","jsxs","pinned","rest","a","b","o","pickCountry","menu","useOptionMenu","handleBlur","describedBy","chevronPx","name_","clsx","fieldStyles","Typography","e","Icon","OptionMenu","PhoneField","module","useOptionalPeer","TextField"],"mappings":";;;;;;;;;;;AASO,MAAMA,IAAYC;AAAA,EACvB;AAAA,EACA;AAAA,EACA,MAAM,OAAO,mBAAmB;AAClC,GACMC,IAAM,MAAMF,EAAU,IAAA;AAO5B,IAAIG;AAEG,SAASC,KAA6C;AAC3D,SAAQD,YAAiBD,EAAA,EAAM,aAAA;AACjC;AAGO,MAAMG,IAAgB,CAACC,MAAkCJ,EAAA,EAAM,sBAAsBI,CAAO;AAO5F,SAASC,GAAaC,GAAyB;AACpD,QAAMC,IAAST,EAAU,IAAA;AAEzB,SAAKS,IAIE,OAAOD,KAAU,YAAYA,EAAM,WAAW,MAAMC,EAAO,mBAAmBD,CAAK,KAHnFR,EAAU,KAAA,GACR;AAGX;AAGO,SAASU,GAAUJ,GAAyB;AACjD,SAAO,OAAO;AAAA,IACZ,GAAG,CAAC,GAAGA,EAAQ,aAAa,EAAE,IAAI,CAACK,MAAM,SAAUA,EAAE,WAAW,CAAC,IAAI,EA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QAAA;AAAA,QAGlCkB,KAAsB,QACrB,gBAAA0B;AAAA,UAACiB;AAAA,UAAA;AAAA,YACC,IAAG;AAAA,YACH,IAAIrD;AAAA,YACJ,SAAQ;AAAA,YACR,OAAOS,IAAgB,UAAU;AAAA,YACjC,WAAW2C,EAAY;AAAA,YAEtB,UAAA1C;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC,GAYY+C,KAAatF;AAAA,EACxB,SAAoBmB,GAAOC,GAAK;AAC9B,UAAM,EAAE,QAAAmE,EAAA,IAAWC,GAAgBzI,CAAS;AAC5C,QAAIwI,EAAQ,QAAO,gBAAAtB,EAAClE,IAAA,EAAgB,KAAAqB,GAAW,GAAGD,GAAO;AAGzD,UAAM;AAAA,MACJ,OAAAb;AAAA,MACA,YAAAC;AAAA,MACA,OAAAC;AAAA,MACA,UAAAC;AAAA,MACA,MAAAC;AAAA,MACA,WAAAC,IAAY;AAAA,MACZ,WAAAI;AAAA,MACA,OAAAC;AAAA,MACA,aAAAE;AAAA,IAAA,IACEC;AACJ,WACE,gBAAA8C;AAAA,MAACwB;AAAA,MAAA;AAAA,QACC,KAAArE;AAAA,QACA,MAAK;AAAA,QACL,OAAAd;AAAA,QACA,YAAAC;AAAA,QACA,OAAAC;AAAA,QACA,UAAAC;AAAA,QACA,MAAAC;AAAA,QACA,WAAAC;AAAA,QACA,WAAAI;AAAA,QACA,OAAAC;AAAA,QACA,aAAAE;AAAA,QACA,OAAOC,EAAM,SAASA,EAAM,gBAAgB;AAAA,QAC5C,UAAQ;AAAA,QACR,UAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,EAGd;AACF;"}
|
|
1
|
+
{"version":3,"file":"PhoneField-BSIhBMW2.js","sources":["../src/components/PhoneField/phone.ts","../src/components/PhoneField/PhoneField.tsx"],"sourcesContent":["import type * as PhoneLibModule from 'libphonenumber-js'\nimport type { CountryCode } from 'libphonenumber-js'\nimport { optionalPeer } from '../../hooks/useOptionalPeer'\n\n/**\n * `libphonenumber-js` is an optional peer, loaded **lazily** (see `optionalPeer`) — never imported\n * statically, so apps that don't install it still build + run when they import the barrel. PhoneField\n * waits for it on mount; the helpers below run only once it's loaded (`lib()`).\n */\nexport const phonePeer = optionalPeer<typeof PhoneLibModule>(\n 'libphonenumber-js',\n 'PhoneField',\n () => import('libphonenumber-js'),\n)\nconst lib = () => phonePeer.get()!\n\n/** An ISO-3166 alpha-2 country code, as `libphonenumber-js` knows it (`'GE'`, `'US'`, …). */\nexport type PhoneCountry = CountryCode\n/** How the number is shown in the input while typing (the value is always E.164). */\nexport type PhoneFormat = 'national' | 'international'\n\nlet allCountries: readonly PhoneCountry[] | undefined\n/** Every country `libphonenumber-js` has metadata for (once loaded). */\nexport function getPhoneCountries(): readonly PhoneCountry[] {\n return (allCountries ??= lib().getCountries())\n}\n\n/** The country's calling code without the `+` — `'GE'` → `'995'`. */\nexport const callingCodeOf = (country: PhoneCountry): string => lib().getCountryCallingCode(country)\n\n/**\n * `true` for a complete, valid number (E.164 or any parseable international form). Use it in a schema:\n * `phone: z.string().refine(isValidPhone, 'Enter a valid phone number')`. Needs `libphonenumber-js`\n * loaded — it is once any PhoneField has mounted; before that it starts the load and returns `false`.\n */\nexport function isValidPhone(value: unknown): boolean {\n const loaded = phonePeer.get()\n // not loaded yet (no PhoneField mounted so far) → start loading and report \"not valid\" for now\n if (!loaded) {\n void phonePeer.load()\n return false\n }\n return typeof value === 'string' && value.trim() !== '' && loaded.isValidPhoneNumber(value)\n}\n\n/** A flag emoji from the two regional-indicator letters — no image assets (Windows shows the letters). */\nexport function flagEmoji(country: string): string {\n return String.fromCodePoint(\n ...[...country.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65),\n )\n}\n\nconst displayNamesCache = new Map<string, Intl.DisplayNames | null>()\n/** The country's name in `locale` via `Intl.DisplayNames` (no catalog to ship); falls back to the code. */\nexport function countryName(country: string, locale: string): string {\n if (!displayNamesCache.has(locale)) {\n try {\n displayNamesCache.set(locale, new Intl.DisplayNames([locale], { type: 'region' }))\n } catch {\n displayNamesCache.set(locale, null)\n }\n }\n try {\n return displayNamesCache.get(locale)?.of(country) ?? country\n } catch {\n return country\n }\n}\n\n// the main country for a calling code shared by several (a partial \"+44…\" parses as Guernsey otherwise)\nconst MAIN_FOR_CODE: Record<string, PhoneCountry> = {\n '1': 'US',\n '7': 'RU',\n '39': 'IT',\n '44': 'GB',\n '47': 'NO',\n '61': 'AU',\n '212': 'MA',\n '262': 'RE',\n '290': 'SH',\n '358': 'FI',\n '590': 'GP',\n '599': 'CW',\n}\n// base UI language → its usual country, for the default when the locale carries no region\nconst LANGUAGE_COUNTRY: Record<string, PhoneCountry> = {\n ka: 'GE',\n en: 'US',\n es: 'ES',\n de: 'DE',\n it: 'IT',\n fr: 'FR',\n ru: 'RU',\n}\n\n/** The default country: the locale's region → its language's usual country → the browser's region → US. */\nexport function detectCountry(locale: string, allowed: readonly PhoneCountry[]): PhoneCountry {\n const [base, region] = locale.split('-')\n const browser =\n typeof navigator !== 'undefined' ? navigator.language?.split('-')[1]?.toUpperCase() : undefined\n const candidates = [region?.toUpperCase(), LANGUAGE_COUNTRY[base?.toLowerCase()], browser, 'US']\n return (candidates.find((c) => c && allowed.includes(c as PhoneCountry)) ??\n allowed[0]) as PhoneCountry\n}\n\n/** The result of reading what's in the input. */\nexport interface PhoneReading {\n /** The canonical value — `'+995555123456'`, or `''` when empty. */\n e164: string\n /** The country the number belongs to (may switch when a `+code` is typed). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number. */\n valid: boolean\n /** What the input should show (formatted as you type). */\n display: string\n}\n\nconst digitsOf = (s: string) => s.replace(/\\D/g, '')\n\n/** Which allowed country a `+code…` number belongs to — keep the current one when it shares the code. */\nfunction countryForCode(\n code: string,\n current: PhoneCountry,\n detected: PhoneCountry | undefined,\n allowed: readonly PhoneCountry[],\n): PhoneCountry {\n if (callingCodeOf(current) === code) return current\n const pick = [detected, MAIN_FOR_CODE[code], ...allowed.filter((c) => callingCodeOf(c) === code)]\n return (pick.find((c) => c && allowed.includes(c)) as PhoneCountry | undefined) ?? current\n}\n\n/** Read raw input text → the canonical value + the formatted display, as the user types. */\nexport function readPhoneInput(\n raw: string,\n country: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): PhoneReading {\n const text = raw.trimStart()\n const digits = digitsOf(text)\n if (!digits) {\n return {\n e164: '',\n country,\n national: '',\n valid: false,\n display: text.startsWith('+') ? '+' : '',\n }\n }\n\n // an explicit \"+code…\" (typed or pasted) — the calling code decides the country\n if (text.startsWith('+')) {\n const typer = new (lib().AsYouType)()\n const display = typer.input(`+${digits}`)\n const code = typer.getCallingCode()\n const parsed = lib().parsePhoneNumberFromString(`+${digits}`)\n const next = code\n ? countryForCode(code, country, parsed?.country ?? typer.getCountry(), allowed)\n : country\n const e164 = `+${digits}`\n return {\n e164,\n country: next,\n national: code ? digits.slice(code.length) : '',\n valid: lib().isValidPhoneNumber(e164),\n display,\n }\n }\n\n // national digits under the selected country (a leading trunk \"0\" is dropped from the value)\n const code = callingCodeOf(country)\n const parsed = lib().parsePhoneNumberFromString(digits, country)\n const national = parsed?.nationalNumber ?? digits.replace(/^0+/, '')\n const e164 = national ? `+${code}${national}` : ''\n const display =\n format === 'international'\n ? new (lib().AsYouType)(country).input(`+${code}${national}`)\n : new (lib().AsYouType)(country).input(digits)\n return {\n e164,\n country,\n national,\n valid: e164 !== '' && lib().isValidPhoneNumber(e164),\n display,\n }\n}\n\n/** Derive the country + display from an E.164 value (initial / external value changes). */\nexport function phoneFromValue(\n value: string,\n fallback: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): { country: PhoneCountry; display: string } {\n if (!value) return { country: fallback, display: '' }\n const parsed = lib().parsePhoneNumberFromString(value)\n if (parsed) {\n const country = countryForCode(parsed.countryCallingCode, fallback, parsed.country, allowed)\n return {\n country,\n display: format === 'national' ? parsed.formatNational() : parsed.formatInternational(),\n }\n }\n const reading = readPhoneInput(value, fallback, 'international', allowed)\n const display =\n format === 'national' && reading.national\n ? new (lib().AsYouType)(reading.country).input(reading.national)\n : reading.display\n return { country: reading.country, display }\n}\n\n/** Caret index in `display` right after its `n`-th digit — keeps the caret put while reformatting. */\nexport function caretAfterDigits(display: string, n: number): number {\n if (n <= 0) return display.startsWith('+') ? 1 : 0\n let seen = 0\n for (let i = 0; i < display.length; i++) {\n if (/\\d/.test(display[i])) seen++\n if (seen === n) return i + 1\n }\n return display.length\n}\n","import {\n forwardRef,\n useCallback,\n useId,\n useLayoutEffect,\n useMemo,\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 { useLanguage, useT } from '../../theme'\nimport { useOptionalPeer } from '../../hooks/useOptionalPeer'\nimport { useFormContext } from '../../form/formContext'\nimport { Icon } from '../Icon'\nimport { TextField } from '../TextField'\nimport { OptionMenu } from '../OptionMenu/OptionMenu'\nimport { useOptionMenu, type SelectOption } from '../OptionMenu/useOptionMenu'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport {\n callingCodeOf,\n getPhoneCountries,\n caretAfterDigits,\n countryName,\n detectCountry,\n flagEmoji,\n phoneFromValue,\n phonePeer,\n readPhoneInput,\n type PhoneCountry,\n type PhoneFormat,\n} from './phone'\nimport styles from './PhoneField.module.css'\n\nexport type PhoneFieldSize = 'sm' | 'md' | 'lg'\n\n/** Extra details handed to `onChange` alongside the E.164 value. */\nexport interface PhoneFieldChangeMeta {\n /** The number's country (ISO alpha-2). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number for that country. */\n valid: boolean\n}\n\nexport interface PhoneFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'value' | 'defaultValue' | 'onChange' | 'type' | 'size' | 'color'\n> {\n /** The number in **E.164** (`'+995555123456'`) — the only form the field emits. `''` when empty. */\n value?: string\n /** Initial E.164 value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the E.164 value (`''` when cleared) and `{ country, national, valid }`. */\n onChange?: (value: string, meta: PhoneFieldChangeMeta) => void\n /** The country to start with. Defaults to one derived from the UI language / browser locale. */\n defaultCountry?: PhoneCountry\n /** Restrict the selectable countries (e.g. only where you operate). Defaults to all. */\n countries?: readonly PhoneCountry[]\n /** Countries pinned to the top of the list, in this order. */\n preferredCountries?: readonly PhoneCountry[]\n /**\n * How the number reads while typing — `national` (default: `555 12 34 56`, the calling code lives in\n * the country button) or `international` (`+995 555 12 34 56`). The value is E.164 either way.\n */\n format?: PhoneFormat\n /** Field label. */\n label?: ReactNode\n /** Helper / validation text under the field. */\n helperText?: ReactNode\n /** Error state (red border + helper). */\n error?: boolean\n /** Shows a required asterisk. */\n required?: boolean\n /** `sm` / `md` / `lg` — control height + type. Defaults to `md`. */\n size?: PhoneFieldSize\n /** Stretch to the container. Defaults to `true`. */\n fullWidth?: boolean\n}\n\n/** The field itself — rendered once `libphonenumber-js` has loaded. */\nconst PhoneFieldInner = forwardRef<HTMLInputElement, PhoneFieldProps>(function PhoneFieldInner(\n {\n value,\n defaultValue,\n onChange,\n defaultCountry,\n countries: countriesProp,\n preferredCountries = [],\n format = 'national',\n label,\n helperText,\n error,\n required,\n size = 'md',\n fullWidth = true,\n name,\n disabled = false,\n id: idProp,\n className,\n style,\n onBlur,\n placeholder,\n ...props\n },\n ref,\n) {\n const t = useT()\n const { language } = useLanguage()\n const countries = countriesProp ?? getPhoneCountries()\n const reactId = useId()\n const id = idProp ?? reactId\n const helperId = `${id}-helper`\n\n // ── value: controlled / form-bound / uncontrolled — always E.164 ──\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = isFormBound ? form!.field(name!) : undefined\n const [internal, setInternal] = useState(defaultValue ?? '')\n const currentValue =\n value !== undefined\n ? value\n : isFormBound\n ? ((form!.values[name!] as string | undefined) ?? '')\n : internal\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n const fallbackCountry = useMemo<PhoneCountry>(\n () =>\n defaultCountry && countries.includes(defaultCountry)\n ? defaultCountry\n : detectCountry(language, countries),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [defaultCountry, language, countries.join()],\n )\n\n const [country, setCountry] = useState<PhoneCountry>(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).country,\n )\n const [display, setDisplay] = useState(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).display,\n )\n\n // re-derive the display when the value changes from OUTSIDE (a reset / a controlled update) — the\n // values we emit ourselves are skipped, so formatting never fights the user mid-typing\n const lastEmitted = useRef(currentValue)\n if (lastEmitted.current !== currentValue) {\n lastEmitted.current = currentValue\n const next = phoneFromValue(currentValue, country, format, countries)\n setCountry(next.country)\n setDisplay(next.display)\n }\n\n // caret restore after reformatting\n const innerRef = useRef<HTMLInputElement | 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 as { current: HTMLInputElement | null }).current = node\n },\n [ref],\n )\n const pendingCaret = useRef<number | null>(null)\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 emit = (reading: ReturnType<typeof readPhoneInput>) => {\n lastEmitted.current = reading.e164\n setDisplay(reading.display)\n if (reading.country !== country) setCountry(reading.country)\n if (value === undefined && !isFormBound) setInternal(reading.e164)\n if (isFormBound) form!.setValue(name!, reading.e164)\n onChange?.(reading.e164, {\n country: reading.country,\n national: reading.national,\n valid: reading.valid,\n })\n }\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const el = event.target\n let raw = el.value\n const caret = el.selectionStart ?? raw.length\n let digitsBefore = raw.slice(0, caret).replace(/\\D/g, '').length\n // backspace over a formatting char (space / paren / dash) would be re-added by the formatter —\n // treat it as deleting the digit before it instead\n const prevDigits = display.replace(/\\D/g, '')\n if (raw.length < display.length && raw.replace(/\\D/g, '') === prevDigits && digitsBefore > 0) {\n let seen = 0\n let cut = -1\n for (let i = 0; i < raw.length; i++) {\n if (/\\d/.test(raw[i]) && ++seen === digitsBefore) {\n cut = i\n break\n }\n }\n if (cut >= 0) raw = raw.slice(0, cut) + raw.slice(cut + 1)\n digitsBefore -= 1\n }\n const reading = readPhoneInput(raw, country, format, countries)\n pendingCaret.current =\n caret >= el.value.length\n ? reading.display.length\n : caretAfterDigits(reading.display, digitsBefore)\n emit(reading)\n }\n\n // ── country picker — the shared option menu (search matches name, ISO code, calling code) ──\n const controlRef = useRef<HTMLDivElement | null>(null)\n const countryOptions = useMemo<SelectOption[]>(() => {\n const toOption = (c: PhoneCountry): SelectOption => {\n const dial = callingCodeOf(c)\n return {\n value: c,\n label: countryName(c, language),\n icon: (\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(c)}\n </span>\n ),\n keywords: [c, dial, `+${dial}`],\n trailing: <span className={styles.dial}>+{dial}</span>,\n }\n }\n // preferred countries first (in the given order), then the rest A→Z by their localized name —\n // as two groups (\"Suggested\" / \"All Countries\") when there are preferred ones\n const pinned = preferredCountries.filter((c) => countries.includes(c)).map(toOption)\n const rest = countries\n .filter((c) => !preferredCountries.includes(c))\n .map(toOption)\n .sort((a, b) => a.label.localeCompare(b.label, language))\n if (pinned.length === 0) return rest\n return [\n ...pinned.map((o) => ({ ...o, group: t('phoneField.suggested') })),\n ...rest.map((o) => ({ ...o, group: t('phoneField.allCountries') })),\n ]\n }, [countries, preferredCountries, language, t])\n\n const pickCountry = (next: PhoneCountry) => {\n // keep the typed national digits, re-read under the new calling code\n const national = readPhoneInput(display, country, format, countries).national\n setCountry(next)\n emit({ ...readPhoneInput(national, next, format, countries), country: next })\n }\n\n const menu = useOptionMenu({\n idBase: `${id}-country`,\n options: countryOptions,\n isSelected: (o) => o.value === country,\n onPick: (o) => pickCountry(o.value as PhoneCountry),\n searchable: true,\n disabled,\n // after a pick / Esc, typing continues in the number\n focusRef: innerRef,\n })\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n bound?.onBlur(event)\n onBlur?.(event)\n }\n\n const describedBy = resolvedHelperText != null ? helperId : undefined\n const chevronPx = size === 'sm' ? 16 : size === 'md' ? 14 : 12\n const code = callingCodeOf(country)\n const name_ = countryName(country, language)\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 styles.phoneField,\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 ref={controlRef} className={clsx(fieldStyles.control, styles.control)}>\n <button\n type=\"button\"\n className={styles.country}\n aria-haspopup=\"listbox\"\n aria-expanded={menu.open}\n aria-controls={menu.open ? menu.listboxId : undefined}\n aria-label={`${t('phoneField.country')}: ${name_} (+${code})`}\n disabled={disabled}\n onClick={menu.toggleMenu}\n onKeyDown={(e) => {\n // ↓ / ↑ open the list (Enter / Space already click the button)\n if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !menu.open) {\n e.preventDefault()\n menu.openMenu()\n }\n }}\n >\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(country)}\n </span>\n {format === 'national' && <span className={styles.code}>+{code}</span>}\n {/* the same chevron as Select / MultiSelect (ArrowDown4, sized per field size: sm 16 · md 14 · lg 12) */}\n <Icon\n name=\"ArrowDown4\"\n className={clsx(styles.chevron, menu.open && styles.chevronOpen)}\n style={{ width: chevronPx, height: chevronPx }}\n aria-hidden=\"true\"\n />\n </button>\n <input\n ref={setInputRef}\n id={id}\n name={name}\n type=\"tel\"\n inputMode=\"tel\"\n autoComplete=\"tel\"\n className={fieldStyles.input}\n value={display}\n placeholder={placeholder}\n onChange={handleChange}\n onBlur={handleBlur}\n disabled={disabled}\n aria-invalid={resolvedError || undefined}\n aria-describedby={describedBy}\n {...props}\n />\n </div>\n\n <OptionMenu\n menu={menu}\n anchorRef={controlRef}\n size={size}\n searchPlaceholder={t('phoneField.search')}\n ariaLabel={t('phoneField.country')}\n />\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\n/**\n * A phone-number field: a **country button** (flag + `+code`, opening a searchable, localized country\n * list) inside the input frame, and the number **formatted as you type** for that country. The value is\n * always **E.164** (`'+995555123456'`) — one canonical form for the backend. Typing or pasting `+44…`\n * switches the country by its calling code. `onChange(value, { country, national, valid })`; binds to a\n * `<Form>` by `name` (the form value is the E.164 string — validate with `isValidPhone`). Country names\n * come from `Intl.DisplayNames` in the active UI language; flags are emoji. Needs the optional peer\n * **`libphonenumber-js`** (formatting, parsing, validation metadata), loaded lazily on first mount — until\n * it's ready (or if it isn't installed) a disabled look-alike field renders. Reuses the `TextField` look.\n */\nexport const PhoneField = forwardRef<HTMLInputElement, PhoneFieldProps>(\n function PhoneField(props, ref) {\n const { module } = useOptionalPeer(phonePeer)\n if (module) return <PhoneFieldInner ref={ref} {...props} />\n // loading (a tick, first mount only) or the peer is missing: the same frame, disabled — never bound\n // to a <Form> (no `name`) so it can't write a value\n const {\n label,\n helperText,\n error,\n required,\n size,\n fullWidth = true,\n className,\n style,\n placeholder,\n } = props\n return (\n <TextField\n ref={ref}\n type=\"tel\"\n label={label}\n helperText={helperText}\n error={error}\n required={required}\n size={size}\n fullWidth={fullWidth}\n className={className}\n style={style}\n placeholder={placeholder}\n value={props.value ?? props.defaultValue ?? ''}\n readOnly\n disabled\n />\n )\n },\n)\n"],"names":["phonePeer","optionalPeer","lib","allCountries","getPhoneCountries","callingCodeOf","country","isValidPhone","value","loaded","flagEmoji","c","displayNamesCache","countryName","locale","_a","MAIN_FOR_CODE","LANGUAGE_COUNTRY","detectCountry","allowed","base","region","browser","_b","digitsOf","s","countryForCode","code","current","detected","readPhoneInput","raw","format","text","digits","typer","display","parsed","next","e164","national","phoneFromValue","fallback","reading","caretAfterDigits","n","seen","i","PhoneFieldInner","forwardRef","defaultValue","onChange","defaultCountry","countriesProp","preferredCountries","label","helperText","error","required","size","fullWidth","name","disabled","idProp","className","style","onBlur","placeholder","props","ref","t","useT","language","useLanguage","countries","reactId","useId","id","helperId","form","useFormContext","isFormBound","bound","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","fallbackCountry","useMemo","setCountry","setDisplay","lastEmitted","useRef","innerRef","setInputRef","useCallback","node","pendingCaret","useLayoutEffect","pos","emit","handleChange","event","el","caret","digitsBefore","prevDigits","cut","controlRef","countryOptions","toOption","dial","jsx","styles","jsxs","pinned","rest","a","b","o","pickCountry","menu","useOptionMenu","handleBlur","describedBy","chevronPx","name_","clsx","fieldStyles","Typography","e","Icon","OptionMenu","PhoneField","module","useOptionalPeer","TextField"],"mappings":";;;;;;;;;;;AASO,MAAMA,IAAYC;AAAA,EACvB;AAAA,EACA;AAAA,EACA,MAAM,OAAO,mBAAmB;AAClC,GACMC,IAAM,MAAMF,EAAU,IAAA;AAO5B,IAAIG;AAEG,SAASC,KAA6C;AAC3D,SAAQD,YAAiBD,EAAA,EAAM,aAAA;AACjC;AAGO,MAAMG,IAAgB,CAACC,MAAkCJ,EAAA,EAAM,sBAAsBI,CAAO;AAO5F,SAASC,GAAaC,GAAyB;AACpD,QAAMC,IAAST,EAAU,IAAA;AAEzB,SAAKS,IAIE,OAAOD,KAAU,YAAYA,EAAM,WAAW,MAAMC,EAAO,mBAAmBD,CAAK,KAHnFR,EAAU,KAAA,GACR;AAGX;AAGO,SAASU,GAAUJ,GA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Property;var Ae=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Ue=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of De(e))!$e.call(t,r)&&r!==s&&ce(t,r,{get:()=>e[r],enumerable:!(o=Ae(e,r))||o.enumerable});return t};var Me=(t,e,s)=>(s=t!=null?we(qe(t)):{},Ue(e||!t||!t.__esModule?ce(s,"default",{value:t,enumerable:!0}):s,t));const a=require("react/jsx-runtime"),u=require("react"),z=require("clsx"),fe=require("./useOptionalPeer-9Fkx5Leb.cjs"),ke=require("./formContext-bTWrqdEV.cjs"),Ee=require("./Icon-BUP5_kRs.cjs"),Ve=require("./TextField-
|
|
2
|
-
//# sourceMappingURL=PhoneField-
|
|
1
|
+
"use strict";var we=Object.create;var ce=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Ue=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of De(e))!$e.call(t,r)&&r!==s&&ce(t,r,{get:()=>e[r],enumerable:!(o=Ae(e,r))||o.enumerable});return t};var Me=(t,e,s)=>(s=t!=null?we(qe(t)):{},Ue(e||!t||!t.__esModule?ce(s,"default",{value:t,enumerable:!0}):s,t));const a=require("react/jsx-runtime"),u=require("react"),z=require("clsx"),fe=require("./useOptionalPeer-9Fkx5Leb.cjs"),ke=require("./formContext-bTWrqdEV.cjs"),Ee=require("./Icon-BUP5_kRs.cjs"),Ve=require("./TextField-D49Lpbjt.cjs"),ae=require("./useOptionMenu-OAYGUWP_.cjs"),ue=require("./Typography-d97DdbNd.cjs"),v=require("./TextField.module-DsNCo8vN.cjs"),de=require("./ConfigProvider-th4GYhcU.cjs"),G=fe.optionalPeer("libphonenumber-js","PhoneField",()=>import("libphonenumber-js")),g=()=>G.get();let We;function Be(){return We??(We=g().getCountries())}const D=t=>g().getCountryCallingCode(t);function Ge(t){const e=G.get();return e?typeof t=="string"&&t.trim()!==""&&e.isValidPhoneNumber(t):(G.load(),!1)}function pe(t){return String.fromCodePoint(...[...t.toUpperCase()].map(e=>127462+e.charCodeAt(0)-65))}const W=new Map;function he(t,e){var s;if(!W.has(e))try{W.set(e,new Intl.DisplayNames([e],{type:"region"}))}catch{W.set(e,null)}try{return((s=W.get(e))==null?void 0:s.of(t))??t}catch{return t}}const Le={1:"US",7:"RU",39:"IT",44:"GB",47:"NO",61:"AU",212:"MA",262:"RE",290:"SH",358:"FI",590:"GP",599:"CW"},Ye={ka:"GE",en:"US",es:"ES",de:"DE",it:"IT",fr:"FR",ru:"RU"};function He(t,e){var d,c;const[s,o]=t.split("-"),r=typeof navigator<"u"?(c=(d=navigator.language)==null?void 0:d.split("-")[1])==null?void 0:c.toUpperCase():void 0;return[o==null?void 0:o.toUpperCase(),Ye[s==null?void 0:s.toLowerCase()],r,"US"].find(h=>h&&e.includes(h))??e[0]}const Ke=t=>t.replace(/\D/g,"");function ye(t,e,s,o){return D(e)===t?e:[s,Le[t],...o.filter(i=>D(i)===t)].find(i=>i&&o.includes(i))??e}function B(t,e,s,o){const r=t.trimStart(),i=Ke(r);if(!i)return{e164:"",country:e,national:"",valid:!1,display:r.startsWith("+")?"+":""};if(r.startsWith("+")){const _=new(g()).AsYouType,F=_.input(`+${i}`),j=_.getCallingCode(),x=g().parsePhoneNumberFromString(`+${i}`),R=j?ye(j,e,(x==null?void 0:x.country)??_.getCountry(),o):e,q=`+${i}`;return{e164:q,country:R,national:j?i.slice(j.length):"",valid:g().isValidPhoneNumber(q),display:F}}const d=D(e),c=g().parsePhoneNumberFromString(i,e),h=(c==null?void 0:c.nationalNumber)??i.replace(/^0+/,""),P=h?`+${d}${h}`:"",w=s==="international"?new(g()).AsYouType(e).input(`+${d}${h}`):new(g()).AsYouType(e).input(i);return{e164:P,country:e,national:h,valid:P!==""&&g().isValidPhoneNumber(P),display:w}}function ee(t,e,s,o){if(!t)return{country:e,display:""};const r=g().parsePhoneNumberFromString(t);if(r)return{country:ye(r.countryCallingCode,e,r.country,o),display:s==="national"?r.formatNational():r.formatInternational()};const i=B(t,e,"international",o),d=s==="national"&&i.national?new(g()).AsYouType(i.country).input(i.national):i.display;return{country:i.country,display:d}}function Je(t,e){if(e<=0)return t.startsWith("+")?1:0;let s=0;for(let o=0;o<t.length;o++)if(/\d/.test(t[o])&&s++,s===e)return o+1;return t.length}const Qe="_phoneField_sbp1s_4",Xe="_country_sbp1s_9",Ze="_flag_sbp1s_35",ze="_code_sbp1s_40",et="_chevron_sbp1s_44",tt="_chevronOpen_sbp1s_48",nt="_dial_sbp1s_53",C={phoneField:Qe,country:Xe,flag:Ze,code:ze,chevron:et,chevronOpen:tt,dial:nt},st=u.forwardRef(function({value:e,defaultValue:s,onChange:o,defaultCountry:r,countries:i,preferredCountries:d=[],format:c="national",label:h,helperText:P,error:w,required:_,size:F="md",fullWidth:j=!0,name:x,disabled:R=!1,id:q,className:ge,style:me,onBlur:L,placeholder:ve,...xe},A){const O=de.useT(),{language:I}=de.useLanguage(),f=i??Be(),be=u.useId(),$=q??be,te=`${$}-helper`,U=ke.useFormContext(),M=!!(U&&x),b=M?U.field(x):void 0,[Ce,Fe]=u.useState(s??""),T=e!==void 0?e:M?U.values[x]??"":Ce,Y=w??(b==null?void 0:b.error)??!1,H=P??(b==null?void 0:b.helperText),ne=u.useMemo(()=>r&&f.includes(r)?r:He(I,f),[r,I,f.join()]),[N,K]=u.useState(()=>ee(T,ne,c,f).country),[k,se]=u.useState(()=>ee(T,ne,c,f).display),J=u.useRef(T);if(J.current!==T){J.current=T;const n=ee(T,N,c,f);K(n.country),se(n.display)}const Q=u.useRef(null),Ne=u.useCallback(n=>{Q.current=n,typeof A=="function"?A(n):A&&(A.current=n)},[A]),X=u.useRef(null);u.useLayoutEffect(()=>{var y;const n=X.current;n!=null&&(X.current=null,(y=Q.current)==null||y.setSelectionRange(n,n))});const oe=n=>{J.current=n.e164,se(n.display),n.country!==N&&K(n.country),e===void 0&&!M&&Fe(n.e164),M&&U.setValue(x,n.e164),o==null||o(n.e164,{country:n.country,national:n.national,valid:n.valid})},Se=n=>{const y=n.target;let p=y.value;const l=y.selectionStart??p.length;let m=p.slice(0,l).replace(/\D/g,"").length;const Ie=k.replace(/\D/g,"");if(p.length<k.length&&p.replace(/\D/g,"")===Ie&&m>0){let Te=0,E=-1;for(let V=0;V<p.length;V++)if(/\d/.test(p[V])&&++Te===m){E=V;break}E>=0&&(p=p.slice(0,E)+p.slice(E+1)),m-=1}const Z=B(p,N,c,f);X.current=l>=y.value.length?Z.display.length:Je(Z.display,m),oe(Z)},re=u.useRef(null),Pe=u.useMemo(()=>{const n=l=>{const m=D(l);return{value:l,label:he(l,I),icon:a.jsx("span",{className:C.flag,"aria-hidden":"true",children:pe(l)}),keywords:[l,m,`+${m}`],trailing:a.jsxs("span",{className:C.dial,children:["+",m]})}},y=d.filter(l=>f.includes(l)).map(n),p=f.filter(l=>!d.includes(l)).map(n).sort((l,m)=>l.label.localeCompare(m.label,I));return y.length===0?p:[...y.map(l=>({...l,group:O("phoneField.suggested")})),...p.map(l=>({...l,group:O("phoneField.allCountries")}))]},[f,d,I,O]),_e=n=>{const y=B(k,N,c,f).national;K(n),oe({...B(y,n,c,f),country:n})},S=ae.useOptionMenu({idBase:`${$}-country`,options:Pe,isSelected:n=>n.value===N,onPick:n=>_e(n.value),searchable:!0,disabled:R,focusRef:Q}),je=n=>{b==null||b.onBlur(n),L==null||L(n)},Re=H!=null?te:void 0,ie=F==="sm"?16:F==="md"?14:12,le=D(N),Oe=he(N,I);return a.jsxs("div",{className:z.clsx(v.fieldStyles.field,v.fieldStyles[F],j&&v.fieldStyles.fullWidth,Y&&v.fieldStyles.error,R&&v.fieldStyles.disabled,C.phoneField,ge),style:me,children:[h!=null&&a.jsxs("label",{htmlFor:$,className:v.fieldStyles.label,children:[a.jsx(ue.Typography,{as:"span",variant:"bodySmall",color:"muted",children:h}),_&&a.jsx("span",{className:v.fieldStyles.required,"aria-hidden":"true",children:"*"})]}),a.jsxs("div",{ref:re,className:z.clsx(v.fieldStyles.control,C.control),children:[a.jsxs("button",{type:"button",className:C.country,"aria-haspopup":"listbox","aria-expanded":S.open,"aria-controls":S.open?S.listboxId:void 0,"aria-label":`${O("phoneField.country")}: ${Oe} (+${le})`,disabled:R,onClick:S.toggleMenu,onKeyDown:n=>{(n.key==="ArrowDown"||n.key==="ArrowUp")&&!S.open&&(n.preventDefault(),S.openMenu())},children:[a.jsx("span",{className:C.flag,"aria-hidden":"true",children:pe(N)}),c==="national"&&a.jsxs("span",{className:C.code,children:["+",le]}),a.jsx(Ee.Icon,{name:"ArrowDown4",className:z.clsx(C.chevron,S.open&&C.chevronOpen),style:{width:ie,height:ie},"aria-hidden":"true"})]}),a.jsx("input",{ref:Ne,id:$,name:x,type:"tel",inputMode:"tel",autoComplete:"tel",className:v.fieldStyles.input,value:k,placeholder:ve,onChange:Se,onBlur:je,disabled:R,"aria-invalid":Y||void 0,"aria-describedby":Re,...xe})]}),a.jsx(ae.OptionMenu,{menu:S,anchorRef:re,size:F,searchPlaceholder:O("phoneField.search"),ariaLabel:O("phoneField.country")}),H!=null&&a.jsx(ue.Typography,{as:"span",id:te,variant:"bodySmall",color:Y?"error":"muted",className:v.fieldStyles.helper,children:H})]})}),ot=u.forwardRef(function(e,s){const{module:o}=fe.useOptionalPeer(G);if(o)return a.jsx(st,{ref:s,...e});const{label:r,helperText:i,error:d,required:c,size:h,fullWidth:P=!0,className:w,style:_,placeholder:F}=e;return a.jsx(Ve.TextField,{ref:s,type:"tel",label:r,helperText:i,error:d,required:c,size:h,fullWidth:P,className:w,style:_,placeholder:F,value:e.value??e.defaultValue??"",readOnly:!0,disabled:!0})});exports.PhoneField=ot;exports.isValidPhone=Ge;
|
|
2
|
+
//# sourceMappingURL=PhoneField-DchrnSiE.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneField-O5syyH7u.cjs","sources":["../src/components/PhoneField/phone.ts","../src/components/PhoneField/PhoneField.tsx"],"sourcesContent":["import type * as PhoneLibModule from 'libphonenumber-js'\nimport type { CountryCode } from 'libphonenumber-js'\nimport { optionalPeer } from '../../hooks/useOptionalPeer'\n\n/**\n * `libphonenumber-js` is an optional peer, loaded **lazily** (see `optionalPeer`) — never imported\n * statically, so apps that don't install it still build + run when they import the barrel. PhoneField\n * waits for it on mount; the helpers below run only once it's loaded (`lib()`).\n */\nexport const phonePeer = optionalPeer<typeof PhoneLibModule>(\n 'libphonenumber-js',\n 'PhoneField',\n () => import('libphonenumber-js'),\n)\nconst lib = () => phonePeer.get()!\n\n/** An ISO-3166 alpha-2 country code, as `libphonenumber-js` knows it (`'GE'`, `'US'`, …). */\nexport type PhoneCountry = CountryCode\n/** How the number is shown in the input while typing (the value is always E.164). */\nexport type PhoneFormat = 'national' | 'international'\n\nlet allCountries: readonly PhoneCountry[] | undefined\n/** Every country `libphonenumber-js` has metadata for (once loaded). */\nexport function getPhoneCountries(): readonly PhoneCountry[] {\n return (allCountries ??= lib().getCountries())\n}\n\n/** The country's calling code without the `+` — `'GE'` → `'995'`. */\nexport const callingCodeOf = (country: PhoneCountry): string => lib().getCountryCallingCode(country)\n\n/**\n * `true` for a complete, valid number (E.164 or any parseable international form). Use it in a schema:\n * `phone: z.string().refine(isValidPhone, 'Enter a valid phone number')`. Needs `libphonenumber-js`\n * loaded — it is once any PhoneField has mounted; before that it starts the load and returns `false`.\n */\nexport function isValidPhone(value: unknown): boolean {\n const loaded = phonePeer.get()\n // not loaded yet (no PhoneField mounted so far) → start loading and report \"not valid\" for now\n if (!loaded) {\n void phonePeer.load()\n return false\n }\n return typeof value === 'string' && value.trim() !== '' && loaded.isValidPhoneNumber(value)\n}\n\n/** A flag emoji from the two regional-indicator letters — no image assets (Windows shows the letters). */\nexport function flagEmoji(country: string): string {\n return String.fromCodePoint(\n ...[...country.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65),\n )\n}\n\nconst displayNamesCache = new Map<string, Intl.DisplayNames | null>()\n/** The country's name in `locale` via `Intl.DisplayNames` (no catalog to ship); falls back to the code. */\nexport function countryName(country: string, locale: string): string {\n if (!displayNamesCache.has(locale)) {\n try {\n displayNamesCache.set(locale, new Intl.DisplayNames([locale], { type: 'region' }))\n } catch {\n displayNamesCache.set(locale, null)\n }\n }\n try {\n return displayNamesCache.get(locale)?.of(country) ?? country\n } catch {\n return country\n }\n}\n\n// the main country for a calling code shared by several (a partial \"+44…\" parses as Guernsey otherwise)\nconst MAIN_FOR_CODE: Record<string, PhoneCountry> = {\n '1': 'US',\n '7': 'RU',\n '39': 'IT',\n '44': 'GB',\n '47': 'NO',\n '61': 'AU',\n '212': 'MA',\n '262': 'RE',\n '290': 'SH',\n '358': 'FI',\n '590': 'GP',\n '599': 'CW',\n}\n// base UI language → its usual country, for the default when the locale carries no region\nconst LANGUAGE_COUNTRY: Record<string, PhoneCountry> = {\n ka: 'GE',\n en: 'US',\n es: 'ES',\n de: 'DE',\n it: 'IT',\n fr: 'FR',\n ru: 'RU',\n}\n\n/** The default country: the locale's region → its language's usual country → the browser's region → US. */\nexport function detectCountry(locale: string, allowed: readonly PhoneCountry[]): PhoneCountry {\n const [base, region] = locale.split('-')\n const browser =\n typeof navigator !== 'undefined' ? navigator.language?.split('-')[1]?.toUpperCase() : undefined\n const candidates = [region?.toUpperCase(), LANGUAGE_COUNTRY[base?.toLowerCase()], browser, 'US']\n return (candidates.find((c) => c && allowed.includes(c as PhoneCountry)) ??\n allowed[0]) as PhoneCountry\n}\n\n/** The result of reading what's in the input. */\nexport interface PhoneReading {\n /** The canonical value — `'+995555123456'`, or `''` when empty. */\n e164: string\n /** The country the number belongs to (may switch when a `+code` is typed). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number. */\n valid: boolean\n /** What the input should show (formatted as you type). */\n display: string\n}\n\nconst digitsOf = (s: string) => s.replace(/\\D/g, '')\n\n/** Which allowed country a `+code…` number belongs to — keep the current one when it shares the code. */\nfunction countryForCode(\n code: string,\n current: PhoneCountry,\n detected: PhoneCountry | undefined,\n allowed: readonly PhoneCountry[],\n): PhoneCountry {\n if (callingCodeOf(current) === code) return current\n const pick = [detected, MAIN_FOR_CODE[code], ...allowed.filter((c) => callingCodeOf(c) === code)]\n return (pick.find((c) => c && allowed.includes(c)) as PhoneCountry | undefined) ?? current\n}\n\n/** Read raw input text → the canonical value + the formatted display, as the user types. */\nexport function readPhoneInput(\n raw: string,\n country: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): PhoneReading {\n const text = raw.trimStart()\n const digits = digitsOf(text)\n if (!digits) {\n return {\n e164: '',\n country,\n national: '',\n valid: false,\n display: text.startsWith('+') ? '+' : '',\n }\n }\n\n // an explicit \"+code…\" (typed or pasted) — the calling code decides the country\n if (text.startsWith('+')) {\n const typer = new (lib().AsYouType)()\n const display = typer.input(`+${digits}`)\n const code = typer.getCallingCode()\n const parsed = lib().parsePhoneNumberFromString(`+${digits}`)\n const next = code\n ? countryForCode(code, country, parsed?.country ?? typer.getCountry(), allowed)\n : country\n const e164 = `+${digits}`\n return {\n e164,\n country: next,\n national: code ? digits.slice(code.length) : '',\n valid: lib().isValidPhoneNumber(e164),\n display,\n }\n }\n\n // national digits under the selected country (a leading trunk \"0\" is dropped from the value)\n const code = callingCodeOf(country)\n const parsed = lib().parsePhoneNumberFromString(digits, country)\n const national = parsed?.nationalNumber ?? digits.replace(/^0+/, '')\n const e164 = national ? `+${code}${national}` : ''\n const display =\n format === 'international'\n ? new (lib().AsYouType)(country).input(`+${code}${national}`)\n : new (lib().AsYouType)(country).input(digits)\n return {\n e164,\n country,\n national,\n valid: e164 !== '' && lib().isValidPhoneNumber(e164),\n display,\n }\n}\n\n/** Derive the country + display from an E.164 value (initial / external value changes). */\nexport function phoneFromValue(\n value: string,\n fallback: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): { country: PhoneCountry; display: string } {\n if (!value) return { country: fallback, display: '' }\n const parsed = lib().parsePhoneNumberFromString(value)\n if (parsed) {\n const country = countryForCode(parsed.countryCallingCode, fallback, parsed.country, allowed)\n return {\n country,\n display: format === 'national' ? parsed.formatNational() : parsed.formatInternational(),\n }\n }\n const reading = readPhoneInput(value, fallback, 'international', allowed)\n const display =\n format === 'national' && reading.national\n ? new (lib().AsYouType)(reading.country).input(reading.national)\n : reading.display\n return { country: reading.country, display }\n}\n\n/** Caret index in `display` right after its `n`-th digit — keeps the caret put while reformatting. */\nexport function caretAfterDigits(display: string, n: number): number {\n if (n <= 0) return display.startsWith('+') ? 1 : 0\n let seen = 0\n for (let i = 0; i < display.length; i++) {\n if (/\\d/.test(display[i])) seen++\n if (seen === n) return i + 1\n }\n return display.length\n}\n","import {\n forwardRef,\n useCallback,\n useId,\n useLayoutEffect,\n useMemo,\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 { useLanguage, useT } from '../../theme'\nimport { useOptionalPeer } from '../../hooks/useOptionalPeer'\nimport { useFormContext } from '../../form/formContext'\nimport { Icon } from '../Icon'\nimport { TextField } from '../TextField'\nimport { OptionMenu } from '../OptionMenu/OptionMenu'\nimport { useOptionMenu, type SelectOption } from '../OptionMenu/useOptionMenu'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport {\n callingCodeOf,\n getPhoneCountries,\n caretAfterDigits,\n countryName,\n detectCountry,\n flagEmoji,\n phoneFromValue,\n phonePeer,\n readPhoneInput,\n type PhoneCountry,\n type PhoneFormat,\n} from './phone'\nimport styles from './PhoneField.module.css'\n\nexport type PhoneFieldSize = 'sm' | 'md' | 'lg'\n\n/** Extra details handed to `onChange` alongside the E.164 value. */\nexport interface PhoneFieldChangeMeta {\n /** The number's country (ISO alpha-2). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number for that country. */\n valid: boolean\n}\n\nexport interface PhoneFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'value' | 'defaultValue' | 'onChange' | 'type' | 'size' | 'color'\n> {\n /** The number in **E.164** (`'+995555123456'`) — the only form the field emits. `''` when empty. */\n value?: string\n /** Initial E.164 value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the E.164 value (`''` when cleared) and `{ country, national, valid }`. */\n onChange?: (value: string, meta: PhoneFieldChangeMeta) => void\n /** The country to start with. Defaults to one derived from the UI language / browser locale. */\n defaultCountry?: PhoneCountry\n /** Restrict the selectable countries (e.g. only where you operate). Defaults to all. */\n countries?: readonly PhoneCountry[]\n /** Countries pinned to the top of the list, in this order. */\n preferredCountries?: readonly PhoneCountry[]\n /**\n * How the number reads while typing — `national` (default: `555 12 34 56`, the calling code lives in\n * the country button) or `international` (`+995 555 12 34 56`). The value is E.164 either way.\n */\n format?: PhoneFormat\n /** Field label. */\n label?: ReactNode\n /** Helper / validation text under the field. */\n helperText?: ReactNode\n /** Error state (red border + helper). */\n error?: boolean\n /** Shows a required asterisk. */\n required?: boolean\n /** `sm` / `md` / `lg` — control height + type. Defaults to `md`. */\n size?: PhoneFieldSize\n /** Stretch to the container. Defaults to `true`. */\n fullWidth?: boolean\n}\n\n/** The field itself — rendered once `libphonenumber-js` has loaded. */\nconst PhoneFieldInner = forwardRef<HTMLInputElement, PhoneFieldProps>(function PhoneFieldInner(\n {\n value,\n defaultValue,\n onChange,\n defaultCountry,\n countries: countriesProp,\n preferredCountries = [],\n format = 'national',\n label,\n helperText,\n error,\n required,\n size = 'md',\n fullWidth = true,\n name,\n disabled = false,\n id: idProp,\n className,\n style,\n onBlur,\n placeholder,\n ...props\n },\n ref,\n) {\n const t = useT()\n const { language } = useLanguage()\n const countries = countriesProp ?? getPhoneCountries()\n const reactId = useId()\n const id = idProp ?? reactId\n const helperId = `${id}-helper`\n\n // ── value: controlled / form-bound / uncontrolled — always E.164 ──\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = isFormBound ? form!.field(name!) : undefined\n const [internal, setInternal] = useState(defaultValue ?? '')\n const currentValue =\n value !== undefined\n ? value\n : isFormBound\n ? ((form!.values[name!] as string | undefined) ?? '')\n : internal\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n const fallbackCountry = useMemo<PhoneCountry>(\n () =>\n defaultCountry && countries.includes(defaultCountry)\n ? defaultCountry\n : detectCountry(language, countries),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [defaultCountry, language, countries.join()],\n )\n\n const [country, setCountry] = useState<PhoneCountry>(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).country,\n )\n const [display, setDisplay] = useState(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).display,\n )\n\n // re-derive the display when the value changes from OUTSIDE (a reset / a controlled update) — the\n // values we emit ourselves are skipped, so formatting never fights the user mid-typing\n const lastEmitted = useRef(currentValue)\n if (lastEmitted.current !== currentValue) {\n lastEmitted.current = currentValue\n const next = phoneFromValue(currentValue, country, format, countries)\n setCountry(next.country)\n setDisplay(next.display)\n }\n\n // caret restore after reformatting\n const innerRef = useRef<HTMLInputElement | 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 as { current: HTMLInputElement | null }).current = node\n },\n [ref],\n )\n const pendingCaret = useRef<number | null>(null)\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 emit = (reading: ReturnType<typeof readPhoneInput>) => {\n lastEmitted.current = reading.e164\n setDisplay(reading.display)\n if (reading.country !== country) setCountry(reading.country)\n if (value === undefined && !isFormBound) setInternal(reading.e164)\n if (isFormBound) form!.setValue(name!, reading.e164)\n onChange?.(reading.e164, {\n country: reading.country,\n national: reading.national,\n valid: reading.valid,\n })\n }\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const el = event.target\n let raw = el.value\n const caret = el.selectionStart ?? raw.length\n let digitsBefore = raw.slice(0, caret).replace(/\\D/g, '').length\n // backspace over a formatting char (space / paren / dash) would be re-added by the formatter —\n // treat it as deleting the digit before it instead\n const prevDigits = display.replace(/\\D/g, '')\n if (raw.length < display.length && raw.replace(/\\D/g, '') === prevDigits && digitsBefore > 0) {\n let seen = 0\n let cut = -1\n for (let i = 0; i < raw.length; i++) {\n if (/\\d/.test(raw[i]) && ++seen === digitsBefore) {\n cut = i\n break\n }\n }\n if (cut >= 0) raw = raw.slice(0, cut) + raw.slice(cut + 1)\n digitsBefore -= 1\n }\n const reading = readPhoneInput(raw, country, format, countries)\n pendingCaret.current =\n caret >= el.value.length\n ? reading.display.length\n : caretAfterDigits(reading.display, digitsBefore)\n emit(reading)\n }\n\n // ── country picker — the shared option menu (search matches name, ISO code, calling code) ──\n const controlRef = useRef<HTMLDivElement | null>(null)\n const countryOptions = useMemo<SelectOption[]>(() => {\n const toOption = (c: PhoneCountry): SelectOption => {\n const dial = callingCodeOf(c)\n return {\n value: c,\n label: countryName(c, language),\n icon: (\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(c)}\n </span>\n ),\n keywords: [c, dial, `+${dial}`],\n trailing: <span className={styles.dial}>+{dial}</span>,\n }\n }\n // preferred countries first (in the given order), then the rest A→Z by their localized name —\n // as two groups (\"Suggested\" / \"All Countries\") when there are preferred ones\n const pinned = preferredCountries.filter((c) => countries.includes(c)).map(toOption)\n const rest = countries\n .filter((c) => !preferredCountries.includes(c))\n .map(toOption)\n .sort((a, b) => a.label.localeCompare(b.label, language))\n if (pinned.length === 0) return rest\n return [\n ...pinned.map((o) => ({ ...o, group: t('phoneField.suggested') })),\n ...rest.map((o) => ({ ...o, group: t('phoneField.allCountries') })),\n ]\n }, [countries, preferredCountries, language, t])\n\n const pickCountry = (next: PhoneCountry) => {\n // keep the typed national digits, re-read under the new calling code\n const national = readPhoneInput(display, country, format, countries).national\n setCountry(next)\n emit({ ...readPhoneInput(national, next, format, countries), country: next })\n }\n\n const menu = useOptionMenu({\n idBase: `${id}-country`,\n options: countryOptions,\n isSelected: (o) => o.value === country,\n onPick: (o) => pickCountry(o.value as PhoneCountry),\n searchable: true,\n disabled,\n // after a pick / Esc, typing continues in the number\n focusRef: innerRef,\n })\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n bound?.onBlur(event)\n onBlur?.(event)\n }\n\n const describedBy = resolvedHelperText != null ? helperId : undefined\n const chevronPx = size === 'sm' ? 16 : size === 'md' ? 14 : 12\n const code = callingCodeOf(country)\n const name_ = countryName(country, language)\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 styles.phoneField,\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 ref={controlRef} className={clsx(fieldStyles.control, styles.control)}>\n <button\n type=\"button\"\n className={styles.country}\n aria-haspopup=\"listbox\"\n aria-expanded={menu.open}\n aria-controls={menu.open ? menu.listboxId : undefined}\n aria-label={`${t('phoneField.country')}: ${name_} (+${code})`}\n disabled={disabled}\n onClick={menu.toggleMenu}\n onKeyDown={(e) => {\n // ↓ / ↑ open the list (Enter / Space already click the button)\n if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !menu.open) {\n e.preventDefault()\n menu.openMenu()\n }\n }}\n >\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(country)}\n </span>\n {format === 'national' && <span className={styles.code}>+{code}</span>}\n {/* the same chevron as Select / MultiSelect (ArrowDown4, sized per field size: sm 16 · md 14 · lg 12) */}\n <Icon\n name=\"ArrowDown4\"\n className={clsx(styles.chevron, menu.open && styles.chevronOpen)}\n style={{ width: chevronPx, height: chevronPx }}\n aria-hidden=\"true\"\n />\n </button>\n <input\n ref={setInputRef}\n id={id}\n name={name}\n type=\"tel\"\n inputMode=\"tel\"\n autoComplete=\"tel\"\n className={fieldStyles.input}\n value={display}\n placeholder={placeholder}\n onChange={handleChange}\n onBlur={handleBlur}\n disabled={disabled}\n aria-invalid={resolvedError || undefined}\n aria-describedby={describedBy}\n {...props}\n />\n </div>\n\n <OptionMenu\n menu={menu}\n anchorRef={controlRef}\n size={size}\n searchPlaceholder={t('phoneField.search')}\n ariaLabel={t('phoneField.country')}\n />\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\n/**\n * A phone-number field: a **country button** (flag + `+code`, opening a searchable, localized country\n * list) inside the input frame, and the number **formatted as you type** for that country. The value is\n * always **E.164** (`'+995555123456'`) — one canonical form for the backend. Typing or pasting `+44…`\n * switches the country by its calling code. `onChange(value, { country, national, valid })`; binds to a\n * `<Form>` by `name` (the form value is the E.164 string — validate with `isValidPhone`). Country names\n * come from `Intl.DisplayNames` in the active UI language; flags are emoji. Needs the optional peer\n * **`libphonenumber-js`** (formatting, parsing, validation metadata), loaded lazily on first mount — until\n * it's ready (or if it isn't installed) a disabled look-alike field renders. Reuses the `TextField` look.\n */\nexport const PhoneField = forwardRef<HTMLInputElement, PhoneFieldProps>(\n function PhoneField(props, ref) {\n const { module } = useOptionalPeer(phonePeer)\n if (module) return <PhoneFieldInner ref={ref} {...props} />\n // loading (a tick, first mount only) or the peer is missing: the same frame, disabled — never bound\n // to a <Form> (no `name`) so it can't write a value\n const {\n label,\n helperText,\n error,\n required,\n size,\n fullWidth = true,\n className,\n style,\n placeholder,\n } = props\n return (\n <TextField\n ref={ref}\n type=\"tel\"\n label={label}\n helperText={helperText}\n error={error}\n required={required}\n size={size}\n fullWidth={fullWidth}\n className={className}\n style={style}\n placeholder={placeholder}\n value={props.value ?? props.defaultValue ?? ''}\n readOnly\n disabled\n />\n )\n },\n)\n"],"names":["phonePeer","optionalPeer","lib","allCountries","getPhoneCountries","callingCodeOf","country","isValidPhone","value","loaded","flagEmoji","c","displayNamesCache","countryName","locale","_a","MAIN_FOR_CODE","LANGUAGE_COUNTRY","detectCountry","allowed","base","region","browser","_b","digitsOf","s","countryForCode","code","current","detected","readPhoneInput","raw","format","text","digits","typer","display","parsed","next","e164","national","phoneFromValue","fallback","reading","caretAfterDigits","n","seen","i","PhoneFieldInner","forwardRef","defaultValue","onChange","defaultCountry","countriesProp","preferredCountries","label","helperText","error","required","size","fullWidth","name","disabled","idProp","className","style","onBlur","placeholder","props","ref","t","useT","language","useLanguage","countries","reactId","useId","id","helperId","form","useFormContext","isFormBound","bound","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","fallbackCountry","useMemo","setCountry","setDisplay","lastEmitted","useRef","innerRef","setInputRef","useCallback","node","pendingCaret","useLayoutEffect","pos","emit","handleChange","event","el","caret","digitsBefore","prevDigits","cut","controlRef","countryOptions","toOption","dial","jsx","styles","jsxs","pinned","rest","a","b","o","pickCountry","menu","useOptionMenu","handleBlur","describedBy","chevronPx","name_","clsx","fieldStyles","Typography","e","Icon","OptionMenu","PhoneField","module","useOptionalPeer","TextField"],"mappings":"63BASaA,EAAYC,GAAAA,aACvB,oBACA,aACA,IAAM,OAAO,mBAAmB,CAClC,EACMC,EAAM,IAAMF,EAAU,IAAA,EAO5B,IAAIG,GAEG,SAASC,IAA6C,CAC3D,OAAQD,QAAiBD,EAAA,EAAM,aAAA,EACjC,CAGO,MAAMG,EAAiBC,GAAkCJ,EAAA,EAAM,sBAAsBI,CAAO,EAO5F,SAASC,GAAaC,EAAyB,CACpD,MAAMC,EAAST,EAAU,IAAA,EAEzB,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AA,YAAY,MACvB,MAAO9F,EACP,YAAA+B,GACA,SAAUoC,GACV,OAAQsB,GACR,SAAA/D,EACA,eAAcyB,GAAiB,OAC/B,mBAAkBuC,GACjB,GAAG1D,EAAA,CAAA,CACN,EACF,EAEA8C,EAAAA,IAACoB,GAAAA,WAAA,CACC,KAAAX,EACA,UAAWb,GACX,KAAAnD,EACA,kBAAmBW,EAAE,mBAAmB,EACxC,UAAWA,EAAE,oBAAoB,CAAA,CAAA,EAGlCkB,GAAsB,MACrB0B,EAAAA,IAACiB,GAAAA,WAAA,CACC,GAAG,OACH,GAAIrD,GACJ,QAAQ,YACR,MAAOS,EAAgB,QAAU,QACjC,UAAW2C,EAAAA,YAAY,OAEtB,SAAA1C,CAAA,CAAA,CACH,CAAA,CAAA,CAIR,CAAC,EAYY+C,GAAatF,EAAAA,WACxB,SAAoBmB,EAAOC,EAAK,CAC9B,KAAM,CAAE,OAAAmE,CAAA,EAAWC,GAAAA,gBAAgBzI,CAAS,EAC5C,GAAIwI,EAAQ,OAAOtB,MAAClE,GAAA,CAAgB,IAAAqB,EAAW,GAAGD,EAAO,EAGzD,KAAM,CACJ,MAAAb,EACA,WAAAC,EACA,MAAAC,EACA,SAAAC,EACA,KAAAC,EACA,UAAAC,EAAY,GACZ,UAAAI,EACA,MAAAC,EACA,YAAAE,CAAA,EACEC,EACJ,OACE8C,EAAAA,IAACwB,GAAAA,UAAA,CACC,IAAArE,EACA,KAAK,MACL,MAAAd,EACA,WAAAC,EACA,MAAAC,EACA,SAAAC,EACA,KAAAC,EACA,UAAAC,EACA,UAAAI,EACA,MAAAC,EACA,YAAAE,EACA,MAAOC,EAAM,OAASA,EAAM,cAAgB,GAC5C,SAAQ,GACR,SAAQ,EAAA,CAAA,CAGd,CACF"}
|
|
1
|
+
{"version":3,"file":"PhoneField-DchrnSiE.cjs","sources":["../src/components/PhoneField/phone.ts","../src/components/PhoneField/PhoneField.tsx"],"sourcesContent":["import type * as PhoneLibModule from 'libphonenumber-js'\nimport type { CountryCode } from 'libphonenumber-js'\nimport { optionalPeer } from '../../hooks/useOptionalPeer'\n\n/**\n * `libphonenumber-js` is an optional peer, loaded **lazily** (see `optionalPeer`) — never imported\n * statically, so apps that don't install it still build + run when they import the barrel. PhoneField\n * waits for it on mount; the helpers below run only once it's loaded (`lib()`).\n */\nexport const phonePeer = optionalPeer<typeof PhoneLibModule>(\n 'libphonenumber-js',\n 'PhoneField',\n () => import('libphonenumber-js'),\n)\nconst lib = () => phonePeer.get()!\n\n/** An ISO-3166 alpha-2 country code, as `libphonenumber-js` knows it (`'GE'`, `'US'`, …). */\nexport type PhoneCountry = CountryCode\n/** How the number is shown in the input while typing (the value is always E.164). */\nexport type PhoneFormat = 'national' | 'international'\n\nlet allCountries: readonly PhoneCountry[] | undefined\n/** Every country `libphonenumber-js` has metadata for (once loaded). */\nexport function getPhoneCountries(): readonly PhoneCountry[] {\n return (allCountries ??= lib().getCountries())\n}\n\n/** The country's calling code without the `+` — `'GE'` → `'995'`. */\nexport const callingCodeOf = (country: PhoneCountry): string => lib().getCountryCallingCode(country)\n\n/**\n * `true` for a complete, valid number (E.164 or any parseable international form). Use it in a schema:\n * `phone: z.string().refine(isValidPhone, 'Enter a valid phone number')`. Needs `libphonenumber-js`\n * loaded — it is once any PhoneField has mounted; before that it starts the load and returns `false`.\n */\nexport function isValidPhone(value: unknown): boolean {\n const loaded = phonePeer.get()\n // not loaded yet (no PhoneField mounted so far) → start loading and report \"not valid\" for now\n if (!loaded) {\n void phonePeer.load()\n return false\n }\n return typeof value === 'string' && value.trim() !== '' && loaded.isValidPhoneNumber(value)\n}\n\n/** A flag emoji from the two regional-indicator letters — no image assets (Windows shows the letters). */\nexport function flagEmoji(country: string): string {\n return String.fromCodePoint(\n ...[...country.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65),\n )\n}\n\nconst displayNamesCache = new Map<string, Intl.DisplayNames | null>()\n/** The country's name in `locale` via `Intl.DisplayNames` (no catalog to ship); falls back to the code. */\nexport function countryName(country: string, locale: string): string {\n if (!displayNamesCache.has(locale)) {\n try {\n displayNamesCache.set(locale, new Intl.DisplayNames([locale], { type: 'region' }))\n } catch {\n displayNamesCache.set(locale, null)\n }\n }\n try {\n return displayNamesCache.get(locale)?.of(country) ?? country\n } catch {\n return country\n }\n}\n\n// the main country for a calling code shared by several (a partial \"+44…\" parses as Guernsey otherwise)\nconst MAIN_FOR_CODE: Record<string, PhoneCountry> = {\n '1': 'US',\n '7': 'RU',\n '39': 'IT',\n '44': 'GB',\n '47': 'NO',\n '61': 'AU',\n '212': 'MA',\n '262': 'RE',\n '290': 'SH',\n '358': 'FI',\n '590': 'GP',\n '599': 'CW',\n}\n// base UI language → its usual country, for the default when the locale carries no region\nconst LANGUAGE_COUNTRY: Record<string, PhoneCountry> = {\n ka: 'GE',\n en: 'US',\n es: 'ES',\n de: 'DE',\n it: 'IT',\n fr: 'FR',\n ru: 'RU',\n}\n\n/** The default country: the locale's region → its language's usual country → the browser's region → US. */\nexport function detectCountry(locale: string, allowed: readonly PhoneCountry[]): PhoneCountry {\n const [base, region] = locale.split('-')\n const browser =\n typeof navigator !== 'undefined' ? navigator.language?.split('-')[1]?.toUpperCase() : undefined\n const candidates = [region?.toUpperCase(), LANGUAGE_COUNTRY[base?.toLowerCase()], browser, 'US']\n return (candidates.find((c) => c && allowed.includes(c as PhoneCountry)) ??\n allowed[0]) as PhoneCountry\n}\n\n/** The result of reading what's in the input. */\nexport interface PhoneReading {\n /** The canonical value — `'+995555123456'`, or `''` when empty. */\n e164: string\n /** The country the number belongs to (may switch when a `+code` is typed). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number. */\n valid: boolean\n /** What the input should show (formatted as you type). */\n display: string\n}\n\nconst digitsOf = (s: string) => s.replace(/\\D/g, '')\n\n/** Which allowed country a `+code…` number belongs to — keep the current one when it shares the code. */\nfunction countryForCode(\n code: string,\n current: PhoneCountry,\n detected: PhoneCountry | undefined,\n allowed: readonly PhoneCountry[],\n): PhoneCountry {\n if (callingCodeOf(current) === code) return current\n const pick = [detected, MAIN_FOR_CODE[code], ...allowed.filter((c) => callingCodeOf(c) === code)]\n return (pick.find((c) => c && allowed.includes(c)) as PhoneCountry | undefined) ?? current\n}\n\n/** Read raw input text → the canonical value + the formatted display, as the user types. */\nexport function readPhoneInput(\n raw: string,\n country: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): PhoneReading {\n const text = raw.trimStart()\n const digits = digitsOf(text)\n if (!digits) {\n return {\n e164: '',\n country,\n national: '',\n valid: false,\n display: text.startsWith('+') ? '+' : '',\n }\n }\n\n // an explicit \"+code…\" (typed or pasted) — the calling code decides the country\n if (text.startsWith('+')) {\n const typer = new (lib().AsYouType)()\n const display = typer.input(`+${digits}`)\n const code = typer.getCallingCode()\n const parsed = lib().parsePhoneNumberFromString(`+${digits}`)\n const next = code\n ? countryForCode(code, country, parsed?.country ?? typer.getCountry(), allowed)\n : country\n const e164 = `+${digits}`\n return {\n e164,\n country: next,\n national: code ? digits.slice(code.length) : '',\n valid: lib().isValidPhoneNumber(e164),\n display,\n }\n }\n\n // national digits under the selected country (a leading trunk \"0\" is dropped from the value)\n const code = callingCodeOf(country)\n const parsed = lib().parsePhoneNumberFromString(digits, country)\n const national = parsed?.nationalNumber ?? digits.replace(/^0+/, '')\n const e164 = national ? `+${code}${national}` : ''\n const display =\n format === 'international'\n ? new (lib().AsYouType)(country).input(`+${code}${national}`)\n : new (lib().AsYouType)(country).input(digits)\n return {\n e164,\n country,\n national,\n valid: e164 !== '' && lib().isValidPhoneNumber(e164),\n display,\n }\n}\n\n/** Derive the country + display from an E.164 value (initial / external value changes). */\nexport function phoneFromValue(\n value: string,\n fallback: PhoneCountry,\n format: PhoneFormat,\n allowed: readonly PhoneCountry[],\n): { country: PhoneCountry; display: string } {\n if (!value) return { country: fallback, display: '' }\n const parsed = lib().parsePhoneNumberFromString(value)\n if (parsed) {\n const country = countryForCode(parsed.countryCallingCode, fallback, parsed.country, allowed)\n return {\n country,\n display: format === 'national' ? parsed.formatNational() : parsed.formatInternational(),\n }\n }\n const reading = readPhoneInput(value, fallback, 'international', allowed)\n const display =\n format === 'national' && reading.national\n ? new (lib().AsYouType)(reading.country).input(reading.national)\n : reading.display\n return { country: reading.country, display }\n}\n\n/** Caret index in `display` right after its `n`-th digit — keeps the caret put while reformatting. */\nexport function caretAfterDigits(display: string, n: number): number {\n if (n <= 0) return display.startsWith('+') ? 1 : 0\n let seen = 0\n for (let i = 0; i < display.length; i++) {\n if (/\\d/.test(display[i])) seen++\n if (seen === n) return i + 1\n }\n return display.length\n}\n","import {\n forwardRef,\n useCallback,\n useId,\n useLayoutEffect,\n useMemo,\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 { useLanguage, useT } from '../../theme'\nimport { useOptionalPeer } from '../../hooks/useOptionalPeer'\nimport { useFormContext } from '../../form/formContext'\nimport { Icon } from '../Icon'\nimport { TextField } from '../TextField'\nimport { OptionMenu } from '../OptionMenu/OptionMenu'\nimport { useOptionMenu, type SelectOption } from '../OptionMenu/useOptionMenu'\nimport { Typography } from '../Typography'\nimport fieldStyles from '../TextField/TextField.module.css'\nimport {\n callingCodeOf,\n getPhoneCountries,\n caretAfterDigits,\n countryName,\n detectCountry,\n flagEmoji,\n phoneFromValue,\n phonePeer,\n readPhoneInput,\n type PhoneCountry,\n type PhoneFormat,\n} from './phone'\nimport styles from './PhoneField.module.css'\n\nexport type PhoneFieldSize = 'sm' | 'md' | 'lg'\n\n/** Extra details handed to `onChange` alongside the E.164 value. */\nexport interface PhoneFieldChangeMeta {\n /** The number's country (ISO alpha-2). */\n country: PhoneCountry\n /** The national significant number — digits only, no trunk `0`. */\n national: string\n /** A complete, valid number for that country. */\n valid: boolean\n}\n\nexport interface PhoneFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'value' | 'defaultValue' | 'onChange' | 'type' | 'size' | 'color'\n> {\n /** The number in **E.164** (`'+995555123456'`) — the only form the field emits. `''` when empty. */\n value?: string\n /** Initial E.164 value for uncontrolled use. */\n defaultValue?: string\n /** Fires with the E.164 value (`''` when cleared) and `{ country, national, valid }`. */\n onChange?: (value: string, meta: PhoneFieldChangeMeta) => void\n /** The country to start with. Defaults to one derived from the UI language / browser locale. */\n defaultCountry?: PhoneCountry\n /** Restrict the selectable countries (e.g. only where you operate). Defaults to all. */\n countries?: readonly PhoneCountry[]\n /** Countries pinned to the top of the list, in this order. */\n preferredCountries?: readonly PhoneCountry[]\n /**\n * How the number reads while typing — `national` (default: `555 12 34 56`, the calling code lives in\n * the country button) or `international` (`+995 555 12 34 56`). The value is E.164 either way.\n */\n format?: PhoneFormat\n /** Field label. */\n label?: ReactNode\n /** Helper / validation text under the field. */\n helperText?: ReactNode\n /** Error state (red border + helper). */\n error?: boolean\n /** Shows a required asterisk. */\n required?: boolean\n /** `sm` / `md` / `lg` — control height + type. Defaults to `md`. */\n size?: PhoneFieldSize\n /** Stretch to the container. Defaults to `true`. */\n fullWidth?: boolean\n}\n\n/** The field itself — rendered once `libphonenumber-js` has loaded. */\nconst PhoneFieldInner = forwardRef<HTMLInputElement, PhoneFieldProps>(function PhoneFieldInner(\n {\n value,\n defaultValue,\n onChange,\n defaultCountry,\n countries: countriesProp,\n preferredCountries = [],\n format = 'national',\n label,\n helperText,\n error,\n required,\n size = 'md',\n fullWidth = true,\n name,\n disabled = false,\n id: idProp,\n className,\n style,\n onBlur,\n placeholder,\n ...props\n },\n ref,\n) {\n const t = useT()\n const { language } = useLanguage()\n const countries = countriesProp ?? getPhoneCountries()\n const reactId = useId()\n const id = idProp ?? reactId\n const helperId = `${id}-helper`\n\n // ── value: controlled / form-bound / uncontrolled — always E.164 ──\n const form = useFormContext()\n const isFormBound = Boolean(form && name)\n const bound = isFormBound ? form!.field(name!) : undefined\n const [internal, setInternal] = useState(defaultValue ?? '')\n const currentValue =\n value !== undefined\n ? value\n : isFormBound\n ? ((form!.values[name!] as string | undefined) ?? '')\n : internal\n const resolvedError = error ?? bound?.error ?? false\n const resolvedHelperText = helperText ?? bound?.helperText\n\n const fallbackCountry = useMemo<PhoneCountry>(\n () =>\n defaultCountry && countries.includes(defaultCountry)\n ? defaultCountry\n : detectCountry(language, countries),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [defaultCountry, language, countries.join()],\n )\n\n const [country, setCountry] = useState<PhoneCountry>(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).country,\n )\n const [display, setDisplay] = useState(\n () => phoneFromValue(currentValue, fallbackCountry, format, countries).display,\n )\n\n // re-derive the display when the value changes from OUTSIDE (a reset / a controlled update) — the\n // values we emit ourselves are skipped, so formatting never fights the user mid-typing\n const lastEmitted = useRef(currentValue)\n if (lastEmitted.current !== currentValue) {\n lastEmitted.current = currentValue\n const next = phoneFromValue(currentValue, country, format, countries)\n setCountry(next.country)\n setDisplay(next.display)\n }\n\n // caret restore after reformatting\n const innerRef = useRef<HTMLInputElement | 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 as { current: HTMLInputElement | null }).current = node\n },\n [ref],\n )\n const pendingCaret = useRef<number | null>(null)\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 emit = (reading: ReturnType<typeof readPhoneInput>) => {\n lastEmitted.current = reading.e164\n setDisplay(reading.display)\n if (reading.country !== country) setCountry(reading.country)\n if (value === undefined && !isFormBound) setInternal(reading.e164)\n if (isFormBound) form!.setValue(name!, reading.e164)\n onChange?.(reading.e164, {\n country: reading.country,\n national: reading.national,\n valid: reading.valid,\n })\n }\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const el = event.target\n let raw = el.value\n const caret = el.selectionStart ?? raw.length\n let digitsBefore = raw.slice(0, caret).replace(/\\D/g, '').length\n // backspace over a formatting char (space / paren / dash) would be re-added by the formatter —\n // treat it as deleting the digit before it instead\n const prevDigits = display.replace(/\\D/g, '')\n if (raw.length < display.length && raw.replace(/\\D/g, '') === prevDigits && digitsBefore > 0) {\n let seen = 0\n let cut = -1\n for (let i = 0; i < raw.length; i++) {\n if (/\\d/.test(raw[i]) && ++seen === digitsBefore) {\n cut = i\n break\n }\n }\n if (cut >= 0) raw = raw.slice(0, cut) + raw.slice(cut + 1)\n digitsBefore -= 1\n }\n const reading = readPhoneInput(raw, country, format, countries)\n pendingCaret.current =\n caret >= el.value.length\n ? reading.display.length\n : caretAfterDigits(reading.display, digitsBefore)\n emit(reading)\n }\n\n // ── country picker — the shared option menu (search matches name, ISO code, calling code) ──\n const controlRef = useRef<HTMLDivElement | null>(null)\n const countryOptions = useMemo<SelectOption[]>(() => {\n const toOption = (c: PhoneCountry): SelectOption => {\n const dial = callingCodeOf(c)\n return {\n value: c,\n label: countryName(c, language),\n icon: (\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(c)}\n </span>\n ),\n keywords: [c, dial, `+${dial}`],\n trailing: <span className={styles.dial}>+{dial}</span>,\n }\n }\n // preferred countries first (in the given order), then the rest A→Z by their localized name —\n // as two groups (\"Suggested\" / \"All Countries\") when there are preferred ones\n const pinned = preferredCountries.filter((c) => countries.includes(c)).map(toOption)\n const rest = countries\n .filter((c) => !preferredCountries.includes(c))\n .map(toOption)\n .sort((a, b) => a.label.localeCompare(b.label, language))\n if (pinned.length === 0) return rest\n return [\n ...pinned.map((o) => ({ ...o, group: t('phoneField.suggested') })),\n ...rest.map((o) => ({ ...o, group: t('phoneField.allCountries') })),\n ]\n }, [countries, preferredCountries, language, t])\n\n const pickCountry = (next: PhoneCountry) => {\n // keep the typed national digits, re-read under the new calling code\n const national = readPhoneInput(display, country, format, countries).national\n setCountry(next)\n emit({ ...readPhoneInput(national, next, format, countries), country: next })\n }\n\n const menu = useOptionMenu({\n idBase: `${id}-country`,\n options: countryOptions,\n isSelected: (o) => o.value === country,\n onPick: (o) => pickCountry(o.value as PhoneCountry),\n searchable: true,\n disabled,\n // after a pick / Esc, typing continues in the number\n focusRef: innerRef,\n })\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\n bound?.onBlur(event)\n onBlur?.(event)\n }\n\n const describedBy = resolvedHelperText != null ? helperId : undefined\n const chevronPx = size === 'sm' ? 16 : size === 'md' ? 14 : 12\n const code = callingCodeOf(country)\n const name_ = countryName(country, language)\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 styles.phoneField,\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 ref={controlRef} className={clsx(fieldStyles.control, styles.control)}>\n <button\n type=\"button\"\n className={styles.country}\n aria-haspopup=\"listbox\"\n aria-expanded={menu.open}\n aria-controls={menu.open ? menu.listboxId : undefined}\n aria-label={`${t('phoneField.country')}: ${name_} (+${code})`}\n disabled={disabled}\n onClick={menu.toggleMenu}\n onKeyDown={(e) => {\n // ↓ / ↑ open the list (Enter / Space already click the button)\n if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !menu.open) {\n e.preventDefault()\n menu.openMenu()\n }\n }}\n >\n <span className={styles.flag} aria-hidden=\"true\">\n {flagEmoji(country)}\n </span>\n {format === 'national' && <span className={styles.code}>+{code}</span>}\n {/* the same chevron as Select / MultiSelect (ArrowDown4, sized per field size: sm 16 · md 14 · lg 12) */}\n <Icon\n name=\"ArrowDown4\"\n className={clsx(styles.chevron, menu.open && styles.chevronOpen)}\n style={{ width: chevronPx, height: chevronPx }}\n aria-hidden=\"true\"\n />\n </button>\n <input\n ref={setInputRef}\n id={id}\n name={name}\n type=\"tel\"\n inputMode=\"tel\"\n autoComplete=\"tel\"\n className={fieldStyles.input}\n value={display}\n placeholder={placeholder}\n onChange={handleChange}\n onBlur={handleBlur}\n disabled={disabled}\n aria-invalid={resolvedError || undefined}\n aria-describedby={describedBy}\n {...props}\n />\n </div>\n\n <OptionMenu\n menu={menu}\n anchorRef={controlRef}\n size={size}\n searchPlaceholder={t('phoneField.search')}\n ariaLabel={t('phoneField.country')}\n />\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\n/**\n * A phone-number field: a **country button** (flag + `+code`, opening a searchable, localized country\n * list) inside the input frame, and the number **formatted as you type** for that country. The value is\n * always **E.164** (`'+995555123456'`) — one canonical form for the backend. Typing or pasting `+44…`\n * switches the country by its calling code. `onChange(value, { country, national, valid })`; binds to a\n * `<Form>` by `name` (the form value is the E.164 string — validate with `isValidPhone`). Country names\n * come from `Intl.DisplayNames` in the active UI language; flags are emoji. Needs the optional peer\n * **`libphonenumber-js`** (formatting, parsing, validation metadata), loaded lazily on first mount — until\n * it's ready (or if it isn't installed) a disabled look-alike field renders. Reuses the `TextField` look.\n */\nexport const PhoneField = forwardRef<HTMLInputElement, PhoneFieldProps>(\n function PhoneField(props, ref) {\n const { module } = useOptionalPeer(phonePeer)\n if (module) return <PhoneFieldInner ref={ref} {...props} />\n // loading (a tick, first mount only) or the peer is missing: the same frame, disabled — never bound\n // to a <Form> (no `name`) so it can't write a value\n const {\n label,\n helperText,\n error,\n required,\n size,\n fullWidth = true,\n className,\n style,\n placeholder,\n } = props\n return (\n <TextField\n ref={ref}\n type=\"tel\"\n label={label}\n helperText={helperText}\n error={error}\n required={required}\n size={size}\n fullWidth={fullWidth}\n className={className}\n style={style}\n placeholder={placeholder}\n value={props.value ?? props.defaultValue ?? ''}\n readOnly\n disabled\n />\n )\n },\n)\n"],"names":["phonePeer","optionalPeer","lib","allCountries","getPhoneCountries","callingCodeOf","country","isValidPhone","value","loaded","flagEmoji","c","displayNamesCache","countryName","locale","_a","MAIN_FOR_CODE","LANGUAGE_COUNTRY","detectCountry","allowed","base","region","browser","_b","digitsOf","s","countryForCode","code","current","detected","readPhoneInput","raw","format","text","digits","typer","display","parsed","next","e164","national","phoneFromValue","fallback","reading","caretAfterDigits","n","seen","i","PhoneFieldInner","forwardRef","defaultValue","onChange","defaultCountry","countriesProp","preferredCountries","label","helperText","error","required","size","fullWidth","name","disabled","idProp","className","style","onBlur","placeholder","props","ref","t","useT","language","useLanguage","countries","reactId","useId","id","helperId","form","useFormContext","isFormBound","bound","internal","setInternal","useState","currentValue","resolvedError","resolvedHelperText","fallbackCountry","useMemo","setCountry","setDisplay","lastEmitted","useRef","innerRef","setInputRef","useCallback","node","pendingCaret","useLayoutEffect","pos","emit","handleChange","event","el","caret","digitsBefore","prevDigits","cut","controlRef","countryOptions","toOption","dial","jsx","styles","jsxs","pinned","rest","a","b","o","pickCountry","menu","useOptionMenu","handleBlur","describedBy","chevronPx","name_","clsx","fieldStyles","Typography","e","Icon","OptionMenu","PhoneField","module","useOptionalPeer","TextField"],"mappings":"63BASaA,EAAYC,GAAAA,aACvB,oBACA,aACA,IAAM,OAAO,mBAAmB,CAClC,EACMC,EAAM,IAAMF,EAAU,IAAA,EAO5B,IAAIG,GAEG,SAASC,IAA6C,CAC3D,OAAQD,QAAiBD,EAAA,EAAM,aAAA,EACjC,CAGO,MAAMG,EAAiBC,GAAkCJ,EAAA,EAAM,sBAAsBI,CAAO,EAO5F,SAASC,GAAaC,EAAyB,CACpD,MAAMC,EAAST,EAAU,IAAA,EAEzB,OAAKS,EAIE,OAAOD,GAAU,UAAYA,EAAM,SAAW,IAAMC,EAAO,mBAAmBD,CAAK,GAHnFR,EAAU,KAAA,EACR,GAGX,CA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AkBuC,GACjB,GAAG1D,EAAA,CAAA,CACN,EACF,EAEA8C,EAAAA,IAACoB,GAAAA,WAAA,CACC,KAAAX,EACA,UAAWb,GACX,KAAAnD,EACA,kBAAmBW,EAAE,mBAAmB,EACxC,UAAWA,EAAE,oBAAoB,CAAA,CAAA,EAGlCkB,GAAsB,MACrB0B,EAAAA,IAACiB,GAAAA,WAAA,CACC,GAAG,OACH,GAAIrD,GACJ,QAAQ,YACR,MAAOS,EAAgB,QAAU,QACjC,UAAW2C,EAAAA,YAAY,OAEtB,SAAA1C,CAAA,CAAA,CACH,CAAA,CAAA,CAIR,CAAC,EAYY+C,GAAatF,EAAAA,WACxB,SAAoBmB,EAAOC,EAAK,CAC9B,KAAM,CAAE,OAAAmE,CAAA,EAAWC,GAAAA,gBAAgBzI,CAAS,EAC5C,GAAIwI,EAAQ,OAAOtB,MAAClE,GAAA,CAAgB,IAAAqB,EAAW,GAAGD,EAAO,EAGzD,KAAM,CACJ,MAAAb,EACA,WAAAC,EACA,MAAAC,EACA,SAAAC,EACA,KAAAC,EACA,UAAAC,EAAY,GACZ,UAAAI,EACA,MAAAC,EACA,YAAAE,CAAA,EACEC,EACJ,OACE8C,EAAAA,IAACwB,GAAAA,UAAA,CACC,IAAArE,EACA,KAAK,MACL,MAAAd,EACA,WAAAC,EACA,MAAAC,EACA,SAAAC,EACA,KAAAC,EACA,UAAAC,EACA,UAAAI,EACA,MAAAC,EACA,YAAAE,EACA,MAAOC,EAAM,OAASA,EAAM,cAAgB,GAC5C,SAAQ,GACR,SAAQ,EAAA,CAAA,CAGd,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const t=require("react/jsx-runtime"),n=require("react"),G=require("clsx"),H=require("./names-YOCJ4B5J.cjs"),R=require("./Button-
|
|
2
|
-
//# sourceMappingURL=Popconfirm-
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),n=require("react"),G=require("clsx"),H=require("./names-YOCJ4B5J.cjs"),R=require("./Button-Cm64ROip.cjs"),J=require("./FloatingPanel-tGCG2nhA.cjs"),K=require("./Icon-BUP5_kRs.cjs"),Q=require("./ConfigProvider-th4GYhcU.cjs"),U="_popconfirm_ztpne_5",V="_body_ztpne_12",W="_icon_ztpne_21",X="_text_ztpne_33",Y="_title_ztpne_43",Z="_description_ztpne_50",ee="_footer_ztpne_58",r={popconfirm:U,body:V,icon:W,text:X,title:Y,description:Z,footer:ee},te=new Set(H.ICON_NAMES);function se({title:E,description:u,onConfirm:S,onCancel:f,confirmLabel:k,cancelLabel:A,color:j="error",icon:c="Danger",align:P="start",open:v,onOpenChange:d,disabled:$=!1,width:w=300,className:D,style:M,children:b}){const z=Q.useT(),p=n.useId(),N=`${p}-panel`,g=`${p}-title`,h=`${p}-desc`,m=n.useRef(null),I=n.useRef(null),[i,_]=n.useState(!1),q=v!==void 0,[O,T]=n.useState(!1),o=q?v:O,B=e=>{q||T(e),d==null||d(e)};n.useEffect(()=>{if(!o)return;const e=requestAnimationFrame(()=>{var s;return(s=I.current)==null?void 0:s.focus()});return()=>cancelAnimationFrame(e)},[o]);const x=e=>{var s;B(!1),e&&((s=m.current)==null||s.focus())},y=(e=!0)=>{i||(f==null||f(),x(e))},C=async()=>{const e=S();if(!e||typeof e.then!="function"){x(!0);return}_(!0);try{await e,_(!1),x(!0)}catch{_(!1)}},l=b.props,a=l.ref,L=n.cloneElement(b,{ref:e=>{m.current=e,typeof a=="function"?a(e):a&&(a.current=e)},onClick:e=>{var s;(s=l.onClick)==null||s.call(l,e),!($||i)&&(o?y(!1):B(!0))},"aria-haspopup":"dialog","aria-expanded":o,"aria-controls":o?N:void 0}),F=c===!1?null:typeof c=="string"&&te.has(c)?t.jsx(K.Icon,{name:c}):c;return t.jsxs(t.Fragment,{children:[L,t.jsxs(J.FloatingPanel,{open:o,triggerRef:m,align:P,onClose:e=>y(e),id:N,role:"alertdialog",ariaLabelledBy:g,ariaDescribedBy:u!=null?h:void 0,trapFocus:!0,width:w,className:G.clsx(r.popconfirm,D),style:{"--tz-btn-rgb":`var(--tz-color-${j}-rgb)`,...M},children:[t.jsxs("div",{className:r.body,children:[F!=null&&t.jsx("span",{className:r.icon,"aria-hidden":"true",children:F}),t.jsxs("div",{className:r.text,children:[t.jsx("div",{id:g,className:r.title,children:E}),u!=null&&t.jsx("div",{id:h,className:r.description,children:u})]})]}),t.jsxs("div",{className:r.footer,children:[t.jsx(R.Button,{ref:I,variant:"text",size:"sm",onClick:()=>y(),disabled:i,children:A??z("common.cancel")}),t.jsx(R.Button,{variant:"contained",color:j,size:"sm",loading:i,onClick:C,children:k??z("common.confirm")})]})]})]})}exports.Popconfirm=se;
|
|
2
|
+
//# sourceMappingURL=Popconfirm-l9au66oY.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popconfirm-bEoOPmZY.cjs","sources":["../src/components/Popconfirm/Popconfirm.tsx"],"sourcesContent":["import {\n cloneElement,\n useEffect,\n useId,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { ICON_NAMES, type IconName } from '../../icons/names'\nimport { Button } from '../Button'\nimport { FloatingPanel } from '../FloatingPanel/FloatingPanel'\nimport { Icon } from '../Icon'\nimport type { PopoverAlign } from '../Popover'\nimport styles from './Popconfirm.module.css'\n\nconst ICON_NAME_SET = new Set<string>(ICON_NAMES)\n\nexport interface PopconfirmProps {\n /** The question — \"Delete this item?\". Labels the dialog. */\n title: ReactNode\n /** Optional muted line under the title (the consequence). Describes the dialog. */\n description?: ReactNode\n /**\n * Runs on confirm. Return a Promise to keep the popover open with the confirm button **loading** until\n * it settles — it closes on success and **stays open on rejection** (show your own toast).\n */\n // `unknown` (not `void | Promise`) so `() => toast.success(…)` — which returns an id — still fits\n onConfirm: () => unknown\n /** Runs on Cancel, `Escape` or an outside click. */\n onCancel?: () => void\n /** Confirm button label. Defaults to the localized \"Confirm\". */\n confirmLabel?: ReactNode\n /** Cancel button label. Defaults to the localized \"Cancel\". */\n cancelLabel?: ReactNode\n /** Tints the confirm button and the icon. Defaults to `error` (a destructive action). */\n color?: ThemeColor\n /** Leading icon — a known `IconName`, any node, or `false`. Defaults to `Danger` in the `color`. */\n icon?: IconName | ReactNode | false\n /** Horizontal alignment to the trigger (`start` default, `end` for a trigger near the right edge). */\n align?: PopoverAlign\n /** Controlled open state. */\n open?: boolean\n /** Fires with the next open state. */\n onOpenChange?: (open: boolean) => void\n /** Clicking the trigger does nothing (no popover). */\n disabled?: boolean\n /** Panel width (px number or CSS width). Defaults to `300px`. */\n width?: number | string\n /** Class on the floating panel. */\n className?: string\n /** Style on the floating panel. */\n style?: CSSProperties\n /** The trigger — usually a `Button` / `IconButton`. Cloned to wire the click + ARIA. */\n children: ReactElement\n}\n\n/**\n * An **inline confirm** for quick, low-risk actions (a row's delete / archive) — a small anchored popover\n * with a question, an optional description and **Cancel** / **Confirm**, where a `RemoveDialog` modal\n * would be too heavy and a bare `onClick` too dangerous. Wraps its trigger (`children`), which it clones\n * to toggle the panel. Built on the shared `FloatingPanel` (portaled, flips, clamps to the viewport,\n * dismisses on outside click / `Escape` = cancel). A11y: `role=\"alertdialog\"` labelled by the title and\n * described by the description, focus trapped and **placed on Cancel** (never the destructive button —\n * the `RemoveDialog` rule), focus returns to the trigger. An async `onConfirm` shows a loading confirm\n * button (Cancel + dismiss locked meanwhile), closes on success, stays open on failure. The icon sits in a\n * tinted box, the buttons (`sm`; confirm `contained` in `color`, default `error`) in a Card-style footer. Use `RemoveDialog` for high-risk, context-heavy deletes.\n */\nexport function Popconfirm({\n title,\n description,\n onConfirm,\n onCancel,\n confirmLabel,\n cancelLabel,\n color = 'error',\n icon = 'Danger',\n align = 'start',\n open,\n onOpenChange,\n disabled = false,\n width = 300,\n className,\n style,\n children,\n}: PopconfirmProps) {\n const t = useT()\n const id = useId()\n const panelId = `${id}-panel`\n const titleId = `${id}-title`\n const descId = `${id}-desc`\n const triggerRef = useRef<HTMLElement | null>(null)\n const cancelRef = useRef<HTMLButtonElement | null>(null)\n const [busy, setBusy] = useState(false)\n\n const isControlled = open !== undefined\n const [internalOpen, setInternalOpen] = useState(false)\n const isOpen = isControlled ? open : internalOpen\n const setOpen = (next: boolean) => {\n if (!isControlled) setInternalOpen(next)\n onOpenChange?.(next)\n }\n\n // focus Cancel once the panel is positioned + visible (a hidden element can't take focus)\n useEffect(() => {\n if (!isOpen) return\n const raf = requestAnimationFrame(() => cancelRef.current?.focus())\n return () => cancelAnimationFrame(raf)\n }, [isOpen])\n\n const close = (refocus: boolean) => {\n setOpen(false)\n if (refocus) triggerRef.current?.focus()\n }\n\n const cancel = (refocus = true) => {\n if (busy) return\n onCancel?.()\n close(refocus)\n }\n\n const confirm = async () => {\n const result = onConfirm()\n // any thenable counts as async (not just native Promises)\n if (!result || typeof (result as PromiseLike<unknown>).then !== 'function') {\n close(true)\n return\n }\n setBusy(true)\n try {\n await result\n setBusy(false)\n close(true)\n } catch {\n // stays open so the user can retry or cancel; surfacing the error (a toast) is the consumer's job\n setBusy(false)\n }\n }\n\n const triggerProps = children.props as {\n onClick?: (event: ReactMouseEvent) => void\n ref?: Ref<HTMLElement>\n }\n const originalRef = triggerProps.ref\n const trigger = cloneElement(children as ReactElement<Record<string, unknown>>, {\n ref: (node: HTMLElement | null) => {\n triggerRef.current = node\n if (typeof originalRef === 'function') originalRef(node)\n else if (originalRef) (originalRef as { current: HTMLElement | null }).current = node\n },\n onClick: (event: ReactMouseEvent) => {\n triggerProps.onClick?.(event)\n if (disabled || busy) return\n if (isOpen) cancel(false)\n else setOpen(true)\n },\n 'aria-haspopup': 'dialog',\n 'aria-expanded': isOpen,\n 'aria-controls': isOpen ? panelId : undefined,\n })\n\n const renderedIcon =\n icon === false ? null : typeof icon === 'string' && ICON_NAME_SET.has(icon) ? (\n <Icon name={icon as IconName} />\n ) : (\n icon\n )\n\n return (\n <>\n {trigger}\n <FloatingPanel\n open={isOpen}\n triggerRef={triggerRef}\n align={align}\n onClose={(refocus) => cancel(refocus)}\n id={panelId}\n role=\"alertdialog\"\n ariaLabelledBy={titleId}\n ariaDescribedBy={description != null ? descId : undefined}\n trapFocus\n width={width}\n className={clsx(styles.popconfirm, className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n >\n <div className={styles.body}>\n {renderedIcon != null && (\n <span className={styles.icon} aria-hidden=\"true\">\n {renderedIcon}\n </span>\n )}\n <div className={styles.text}>\n <div id={titleId} className={styles.title}>\n {title}\n </div>\n {description != null && (\n <div id={descId} className={styles.description}>\n {description}\n </div>\n )}\n </div>\n </div>\n <div className={styles.footer}>\n <Button ref={cancelRef} variant=\"text\" size=\"sm\" onClick={() => cancel()} disabled={busy}>\n {cancelLabel ?? t('common.cancel')}\n </Button>\n <Button variant=\"contained\" color={color} size=\"sm\" loading={busy} onClick={confirm}>\n {confirmLabel ?? t('common.confirm')}\n </Button>\n </div>\n </FloatingPanel>\n </>\n )\n}\n"],"names":["ICON_NAME_SET","ICON_NAMES","Popconfirm","title","description","onConfirm","onCancel","confirmLabel","cancelLabel","color","icon","align","open","onOpenChange","disabled","width","className","style","children","t","useT","id","useId","panelId","titleId","descId","triggerRef","useRef","cancelRef","busy","setBusy","useState","isControlled","internalOpen","setInternalOpen","isOpen","setOpen","next","useEffect","raf","_a","close","refocus","cancel","confirm","result","triggerProps","originalRef","trigger","cloneElement","node","event","renderedIcon","jsx","Icon","jsxs","Fragment","FloatingPanel","clsx","styles","Button"],"mappings":"6eAqBMA,GAAgB,IAAI,IAAYC,YAAU,EAoDzC,SAASC,GAAW,CACzB,MAAAC,EACA,YAAAC,EACA,UAAAC,EACA,SAAAC,EACA,aAAAC,EACA,YAAAC,EACA,MAAAC,EAAQ,QACR,KAAAC,EAAO,SACP,MAAAC,EAAQ,QACR,KAAAC,EACA,aAAAC,EACA,SAAAC,EAAW,GACX,MAAAC,EAAQ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AA,KAAC,MAAA,CAAI,UAAWI,EAAO,OACrB,SAAA,CAAAN,MAACO,EAAAA,QAAO,IAAKhC,EAAW,QAAQ,OAAO,KAAK,KAAK,QAAS,IAAMe,EAAA,EAAU,SAAUd,EACjF,SAAArB,GAAeW,EAAE,eAAe,EACnC,EACAkC,EAAAA,IAACO,EAAAA,OAAA,CAAO,QAAQ,YAAY,MAAAnD,EAAc,KAAK,KAAK,QAASoB,EAAM,QAASe,EACzE,SAAArC,GAAgBY,EAAE,gBAAgB,CAAA,CACrC,CAAA,CAAA,CACF,CAAA,CAAA,CAAA,CACF,EACF,CAEJ"}
|
|
1
|
+
{"version":3,"file":"Popconfirm-l9au66oY.cjs","sources":["../src/components/Popconfirm/Popconfirm.tsx"],"sourcesContent":["import {\n cloneElement,\n useEffect,\n useId,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { ICON_NAMES, type IconName } from '../../icons/names'\nimport { Button } from '../Button'\nimport { FloatingPanel } from '../FloatingPanel/FloatingPanel'\nimport { Icon } from '../Icon'\nimport type { PopoverAlign } from '../Popover'\nimport styles from './Popconfirm.module.css'\n\nconst ICON_NAME_SET = new Set<string>(ICON_NAMES)\n\nexport interface PopconfirmProps {\n /** The question — \"Delete this item?\". Labels the dialog. */\n title: ReactNode\n /** Optional muted line under the title (the consequence). Describes the dialog. */\n description?: ReactNode\n /**\n * Runs on confirm. Return a Promise to keep the popover open with the confirm button **loading** until\n * it settles — it closes on success and **stays open on rejection** (show your own toast).\n */\n // `unknown` (not `void | Promise`) so `() => toast.success(…)` — which returns an id — still fits\n onConfirm: () => unknown\n /** Runs on Cancel, `Escape` or an outside click. */\n onCancel?: () => void\n /** Confirm button label. Defaults to the localized \"Confirm\". */\n confirmLabel?: ReactNode\n /** Cancel button label. Defaults to the localized \"Cancel\". */\n cancelLabel?: ReactNode\n /** Tints the confirm button and the icon. Defaults to `error` (a destructive action). */\n color?: ThemeColor\n /** Leading icon — a known `IconName`, any node, or `false`. Defaults to `Danger` in the `color`. */\n icon?: IconName | ReactNode | false\n /** Horizontal alignment to the trigger (`start` default, `end` for a trigger near the right edge). */\n align?: PopoverAlign\n /** Controlled open state. */\n open?: boolean\n /** Fires with the next open state. */\n onOpenChange?: (open: boolean) => void\n /** Clicking the trigger does nothing (no popover). */\n disabled?: boolean\n /** Panel width (px number or CSS width). Defaults to `300px`. */\n width?: number | string\n /** Class on the floating panel. */\n className?: string\n /** Style on the floating panel. */\n style?: CSSProperties\n /** The trigger — usually a `Button` / `IconButton`. Cloned to wire the click + ARIA. */\n children: ReactElement\n}\n\n/**\n * An **inline confirm** for quick, low-risk actions (a row's delete / archive) — a small anchored popover\n * with a question, an optional description and **Cancel** / **Confirm**, where a `RemoveDialog` modal\n * would be too heavy and a bare `onClick` too dangerous. Wraps its trigger (`children`), which it clones\n * to toggle the panel. Built on the shared `FloatingPanel` (portaled, flips, clamps to the viewport,\n * dismisses on outside click / `Escape` = cancel). A11y: `role=\"alertdialog\"` labelled by the title and\n * described by the description, focus trapped and **placed on Cancel** (never the destructive button —\n * the `RemoveDialog` rule), focus returns to the trigger. An async `onConfirm` shows a loading confirm\n * button (Cancel + dismiss locked meanwhile), closes on success, stays open on failure. The icon sits in a\n * tinted box, the buttons (`sm`; confirm `contained` in `color`, default `error`) in a Card-style footer. Use `RemoveDialog` for high-risk, context-heavy deletes.\n */\nexport function Popconfirm({\n title,\n description,\n onConfirm,\n onCancel,\n confirmLabel,\n cancelLabel,\n color = 'error',\n icon = 'Danger',\n align = 'start',\n open,\n onOpenChange,\n disabled = false,\n width = 300,\n className,\n style,\n children,\n}: PopconfirmProps) {\n const t = useT()\n const id = useId()\n const panelId = `${id}-panel`\n const titleId = `${id}-title`\n const descId = `${id}-desc`\n const triggerRef = useRef<HTMLElement | null>(null)\n const cancelRef = useRef<HTMLButtonElement | null>(null)\n const [busy, setBusy] = useState(false)\n\n const isControlled = open !== undefined\n const [internalOpen, setInternalOpen] = useState(false)\n const isOpen = isControlled ? open : internalOpen\n const setOpen = (next: boolean) => {\n if (!isControlled) setInternalOpen(next)\n onOpenChange?.(next)\n }\n\n // focus Cancel once the panel is positioned + visible (a hidden element can't take focus)\n useEffect(() => {\n if (!isOpen) return\n const raf = requestAnimationFrame(() => cancelRef.current?.focus())\n return () => cancelAnimationFrame(raf)\n }, [isOpen])\n\n const close = (refocus: boolean) => {\n setOpen(false)\n if (refocus) triggerRef.current?.focus()\n }\n\n const cancel = (refocus = true) => {\n if (busy) return\n onCancel?.()\n close(refocus)\n }\n\n const confirm = async () => {\n const result = onConfirm()\n // any thenable counts as async (not just native Promises)\n if (!result || typeof (result as PromiseLike<unknown>).then !== 'function') {\n close(true)\n return\n }\n setBusy(true)\n try {\n await result\n setBusy(false)\n close(true)\n } catch {\n // stays open so the user can retry or cancel; surfacing the error (a toast) is the consumer's job\n setBusy(false)\n }\n }\n\n const triggerProps = children.props as {\n onClick?: (event: ReactMouseEvent) => void\n ref?: Ref<HTMLElement>\n }\n const originalRef = triggerProps.ref\n const trigger = cloneElement(children as ReactElement<Record<string, unknown>>, {\n ref: (node: HTMLElement | null) => {\n triggerRef.current = node\n if (typeof originalRef === 'function') originalRef(node)\n else if (originalRef) (originalRef as { current: HTMLElement | null }).current = node\n },\n onClick: (event: ReactMouseEvent) => {\n triggerProps.onClick?.(event)\n if (disabled || busy) return\n if (isOpen) cancel(false)\n else setOpen(true)\n },\n 'aria-haspopup': 'dialog',\n 'aria-expanded': isOpen,\n 'aria-controls': isOpen ? panelId : undefined,\n })\n\n const renderedIcon =\n icon === false ? null : typeof icon === 'string' && ICON_NAME_SET.has(icon) ? (\n <Icon name={icon as IconName} />\n ) : (\n icon\n )\n\n return (\n <>\n {trigger}\n <FloatingPanel\n open={isOpen}\n triggerRef={triggerRef}\n align={align}\n onClose={(refocus) => cancel(refocus)}\n id={panelId}\n role=\"alertdialog\"\n ariaLabelledBy={titleId}\n ariaDescribedBy={description != null ? descId : undefined}\n trapFocus\n width={width}\n className={clsx(styles.popconfirm, className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n >\n <div className={styles.body}>\n {renderedIcon != null && (\n <span className={styles.icon} aria-hidden=\"true\">\n {renderedIcon}\n </span>\n )}\n <div className={styles.text}>\n <div id={titleId} className={styles.title}>\n {title}\n </div>\n {description != null && (\n <div id={descId} className={styles.description}>\n {description}\n </div>\n )}\n </div>\n </div>\n <div className={styles.footer}>\n <Button ref={cancelRef} variant=\"text\" size=\"sm\" onClick={() => cancel()} disabled={busy}>\n {cancelLabel ?? t('common.cancel')}\n </Button>\n <Button variant=\"contained\" color={color} size=\"sm\" loading={busy} onClick={confirm}>\n {confirmLabel ?? t('common.confirm')}\n </Button>\n </div>\n </FloatingPanel>\n </>\n )\n}\n"],"names":["ICON_NAME_SET","ICON_NAMES","Popconfirm","title","description","onConfirm","onCancel","confirmLabel","cancelLabel","color","icon","align","open","onOpenChange","disabled","width","className","style","children","t","useT","id","useId","panelId","titleId","descId","triggerRef","useRef","cancelRef","busy","setBusy","useState","isControlled","internalOpen","setInternalOpen","isOpen","setOpen","next","useEffect","raf","_a","close","refocus","cancel","confirm","result","triggerProps","originalRef","trigger","cloneElement","node","event","renderedIcon","jsx","Icon","jsxs","Fragment","FloatingPanel","clsx","styles","Button"],"mappings":"6eAqBMA,GAAgB,IAAI,IAAYC,YAAU,EAoDzC,SAASC,GAAW,CACzB,MAAAC,EACA,YAAAC,EACA,UAAAC,EACA,SAAAC,EACA,aAAAC,EACA,YAAAC,EACA,MAAAC,EAAQ,QACR,KAAAC,EAAO,SACP,MAAAC,EAAQ,QACR,KAAAC,EACA,aAAAC,EACA,SAAAC,EAAW,GACX,MAAAC,EAAQ,IACR,UAAAC,EACA,MAAAC,EACA,SAAAC,CACF,EAAoB,CAClB,MAAMC,EAAIC,EAAAA,KAAA,EACJC,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AAQ,OAAO,KAAK,KAAK,QAAS,IAAMe,EAAA,EAAU,SAAUd,EACjF,SAAArB,GAAeW,EAAE,eAAe,EACnC,EACAkC,EAAAA,IAACO,EAAAA,OAAA,CAAO,QAAQ,YAAY,MAAAnD,EAAc,KAAK,KAAK,QAASoB,EAAM,QAASe,EACzE,SAAArC,GAAgBY,EAAE,gBAAgB,CAAA,CACrC,CAAA,CAAA,CACF,CAAA,CAAA,CAAA,CACF,EACF,CAEJ"}
|
|
@@ -2,10 +2,10 @@ import { jsx as o, jsxs as i, Fragment as J } from "react/jsx-runtime";
|
|
|
2
2
|
import { useId as K, useRef as A, useState as R, useEffect as Q, cloneElement as U } from "react";
|
|
3
3
|
import { clsx as V } from "clsx";
|
|
4
4
|
import { a as W } from "./names-BR1uJs0-.js";
|
|
5
|
-
import { B as S } from "./Button-
|
|
5
|
+
import { B as S } from "./Button-BQ7jsm5P.js";
|
|
6
6
|
import { F as X } from "./FloatingPanel-C5c_eMQ0.js";
|
|
7
7
|
import { I as Y } from "./Icon-CGQ5yGSZ.js";
|
|
8
|
-
import { a as Z } from "./ConfigProvider-
|
|
8
|
+
import { a as Z } from "./ConfigProvider-DZMtq2Fz.js";
|
|
9
9
|
const tt = "_popconfirm_ztpne_5", et = "_body_ztpne_12", nt = "_icon_ztpne_21", rt = "_text_ztpne_33", ot = "_title_ztpne_43", st = "_description_ztpne_50", it = "_footer_ztpne_58", n = {
|
|
10
10
|
popconfirm: tt,
|
|
11
11
|
body: et,
|
|
@@ -110,4 +110,4 @@ function yt({
|
|
|
110
110
|
export {
|
|
111
111
|
yt as P
|
|
112
112
|
};
|
|
113
|
-
//# sourceMappingURL=Popconfirm-
|
|
113
|
+
//# sourceMappingURL=Popconfirm-p2O8Vmz0.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popconfirm-D4J7tlk_.js","sources":["../src/components/Popconfirm/Popconfirm.tsx"],"sourcesContent":["import {\n cloneElement,\n useEffect,\n useId,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { ICON_NAMES, type IconName } from '../../icons/names'\nimport { Button } from '../Button'\nimport { FloatingPanel } from '../FloatingPanel/FloatingPanel'\nimport { Icon } from '../Icon'\nimport type { PopoverAlign } from '../Popover'\nimport styles from './Popconfirm.module.css'\n\nconst ICON_NAME_SET = new Set<string>(ICON_NAMES)\n\nexport interface PopconfirmProps {\n /** The question — \"Delete this item?\". Labels the dialog. */\n title: ReactNode\n /** Optional muted line under the title (the consequence). Describes the dialog. */\n description?: ReactNode\n /**\n * Runs on confirm. Return a Promise to keep the popover open with the confirm button **loading** until\n * it settles — it closes on success and **stays open on rejection** (show your own toast).\n */\n // `unknown` (not `void | Promise`) so `() => toast.success(…)` — which returns an id — still fits\n onConfirm: () => unknown\n /** Runs on Cancel, `Escape` or an outside click. */\n onCancel?: () => void\n /** Confirm button label. Defaults to the localized \"Confirm\". */\n confirmLabel?: ReactNode\n /** Cancel button label. Defaults to the localized \"Cancel\". */\n cancelLabel?: ReactNode\n /** Tints the confirm button and the icon. Defaults to `error` (a destructive action). */\n color?: ThemeColor\n /** Leading icon — a known `IconName`, any node, or `false`. Defaults to `Danger` in the `color`. */\n icon?: IconName | ReactNode | false\n /** Horizontal alignment to the trigger (`start` default, `end` for a trigger near the right edge). */\n align?: PopoverAlign\n /** Controlled open state. */\n open?: boolean\n /** Fires with the next open state. */\n onOpenChange?: (open: boolean) => void\n /** Clicking the trigger does nothing (no popover). */\n disabled?: boolean\n /** Panel width (px number or CSS width). Defaults to `300px`. */\n width?: number | string\n /** Class on the floating panel. */\n className?: string\n /** Style on the floating panel. */\n style?: CSSProperties\n /** The trigger — usually a `Button` / `IconButton`. Cloned to wire the click + ARIA. */\n children: ReactElement\n}\n\n/**\n * An **inline confirm** for quick, low-risk actions (a row's delete / archive) — a small anchored popover\n * with a question, an optional description and **Cancel** / **Confirm**, where a `RemoveDialog` modal\n * would be too heavy and a bare `onClick` too dangerous. Wraps its trigger (`children`), which it clones\n * to toggle the panel. Built on the shared `FloatingPanel` (portaled, flips, clamps to the viewport,\n * dismisses on outside click / `Escape` = cancel). A11y: `role=\"alertdialog\"` labelled by the title and\n * described by the description, focus trapped and **placed on Cancel** (never the destructive button —\n * the `RemoveDialog` rule), focus returns to the trigger. An async `onConfirm` shows a loading confirm\n * button (Cancel + dismiss locked meanwhile), closes on success, stays open on failure. The icon sits in a\n * tinted box, the buttons (`sm`; confirm `contained` in `color`, default `error`) in a Card-style footer. Use `RemoveDialog` for high-risk, context-heavy deletes.\n */\nexport function Popconfirm({\n title,\n description,\n onConfirm,\n onCancel,\n confirmLabel,\n cancelLabel,\n color = 'error',\n icon = 'Danger',\n align = 'start',\n open,\n onOpenChange,\n disabled = false,\n width = 300,\n className,\n style,\n children,\n}: PopconfirmProps) {\n const t = useT()\n const id = useId()\n const panelId = `${id}-panel`\n const titleId = `${id}-title`\n const descId = `${id}-desc`\n const triggerRef = useRef<HTMLElement | null>(null)\n const cancelRef = useRef<HTMLButtonElement | null>(null)\n const [busy, setBusy] = useState(false)\n\n const isControlled = open !== undefined\n const [internalOpen, setInternalOpen] = useState(false)\n const isOpen = isControlled ? open : internalOpen\n const setOpen = (next: boolean) => {\n if (!isControlled) setInternalOpen(next)\n onOpenChange?.(next)\n }\n\n // focus Cancel once the panel is positioned + visible (a hidden element can't take focus)\n useEffect(() => {\n if (!isOpen) return\n const raf = requestAnimationFrame(() => cancelRef.current?.focus())\n return () => cancelAnimationFrame(raf)\n }, [isOpen])\n\n const close = (refocus: boolean) => {\n setOpen(false)\n if (refocus) triggerRef.current?.focus()\n }\n\n const cancel = (refocus = true) => {\n if (busy) return\n onCancel?.()\n close(refocus)\n }\n\n const confirm = async () => {\n const result = onConfirm()\n // any thenable counts as async (not just native Promises)\n if (!result || typeof (result as PromiseLike<unknown>).then !== 'function') {\n close(true)\n return\n }\n setBusy(true)\n try {\n await result\n setBusy(false)\n close(true)\n } catch {\n // stays open so the user can retry or cancel; surfacing the error (a toast) is the consumer's job\n setBusy(false)\n }\n }\n\n const triggerProps = children.props as {\n onClick?: (event: ReactMouseEvent) => void\n ref?: Ref<HTMLElement>\n }\n const originalRef = triggerProps.ref\n const trigger = cloneElement(children as ReactElement<Record<string, unknown>>, {\n ref: (node: HTMLElement | null) => {\n triggerRef.current = node\n if (typeof originalRef === 'function') originalRef(node)\n else if (originalRef) (originalRef as { current: HTMLElement | null }).current = node\n },\n onClick: (event: ReactMouseEvent) => {\n triggerProps.onClick?.(event)\n if (disabled || busy) return\n if (isOpen) cancel(false)\n else setOpen(true)\n },\n 'aria-haspopup': 'dialog',\n 'aria-expanded': isOpen,\n 'aria-controls': isOpen ? panelId : undefined,\n })\n\n const renderedIcon =\n icon === false ? null : typeof icon === 'string' && ICON_NAME_SET.has(icon) ? (\n <Icon name={icon as IconName} />\n ) : (\n icon\n )\n\n return (\n <>\n {trigger}\n <FloatingPanel\n open={isOpen}\n triggerRef={triggerRef}\n align={align}\n onClose={(refocus) => cancel(refocus)}\n id={panelId}\n role=\"alertdialog\"\n ariaLabelledBy={titleId}\n ariaDescribedBy={description != null ? descId : undefined}\n trapFocus\n width={width}\n className={clsx(styles.popconfirm, className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n >\n <div className={styles.body}>\n {renderedIcon != null && (\n <span className={styles.icon} aria-hidden=\"true\">\n {renderedIcon}\n </span>\n )}\n <div className={styles.text}>\n <div id={titleId} className={styles.title}>\n {title}\n </div>\n {description != null && (\n <div id={descId} className={styles.description}>\n {description}\n </div>\n )}\n </div>\n </div>\n <div className={styles.footer}>\n <Button ref={cancelRef} variant=\"text\" size=\"sm\" onClick={() => cancel()} disabled={busy}>\n {cancelLabel ?? t('common.cancel')}\n </Button>\n <Button variant=\"contained\" color={color} size=\"sm\" loading={busy} onClick={confirm}>\n {confirmLabel ?? t('common.confirm')}\n </Button>\n </div>\n </FloatingPanel>\n </>\n )\n}\n"],"names":["ICON_NAME_SET","ICON_NAMES","Popconfirm","title","description","onConfirm","onCancel","confirmLabel","cancelLabel","color","icon","align","open","onOpenChange","disabled","width","className","style","children","t","useT","id","useId","panelId","titleId","descId","triggerRef","useRef","cancelRef","busy","setBusy","useState","isControlled","internalOpen","setInternalOpen","isOpen","setOpen","next","useEffect","raf","_a","close","refocus","cancel","confirm","result","triggerProps","originalRef","trigger","cloneElement","node","event","renderedIcon","jsx","Icon","jsxs","Fragment","FloatingPanel","clsx","styles","Button"],"mappings":";;;;;;;;;;;;;;;;GAqBMA,KAAgB,IAAI,IAAYC,CAAU;AAoDzC,SAASC,GAAW;AAAA,EACzB,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,MAAAC,IAAO;AAAA,EACP,OAAAC,IAAQ;AAAA,EACR,MAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC,IAAQ;AAAA,EACR,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AACF,GAAoB;AAClB,QAAMC,IAAIC,EAAA,GACJC,IAAKC,EAAA,GACLC,IAAU,GAAGF,CAAE,UACfG,IAAU,GAAGH,CAAE,UACfI,IAAS,GAAGJ,CAAE,SACdK,IAAaC,EAA2B,IAAI,GAC5CC,IAAYD,EAAiC,IAAI,GACjD,CAACE,GAAMC,CAAO,IAAIC,EAAS,EAAK,GAEhCC,IAAepB,MAAS,QACxB,CAACqB,GAAcC,CAAe,IAAIH,EAAS,EAAK,GAChDI,IAASH,IAAepB,IAAOqB,GAC/BG,IAAU,CAACC,MAAkB;AACjC,IAAKL,KAAcE,EAAgBG,CAAI,GACvCxB,KAAA,QAAAA,EAAewB;AAAA,EACjB;AAGA,EAAA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kC,EAACO,GAAA,EAAO,SAAQ,aAAY,OAAAnD,GAAc,MAAK,MAAK,SAASoB,GAAM,SAASe,GACzE,UAAArC,KAAgBY,EAAE,gBAAgB,EAAA,CACrC;AAAA,UAAA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Popconfirm-p2O8Vmz0.js","sources":["../src/components/Popconfirm/Popconfirm.tsx"],"sourcesContent":["import {\n cloneElement,\n useEffect,\n useId,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { ICON_NAMES, type IconName } from '../../icons/names'\nimport { Button } from '../Button'\nimport { FloatingPanel } from '../FloatingPanel/FloatingPanel'\nimport { Icon } from '../Icon'\nimport type { PopoverAlign } from '../Popover'\nimport styles from './Popconfirm.module.css'\n\nconst ICON_NAME_SET = new Set<string>(ICON_NAMES)\n\nexport interface PopconfirmProps {\n /** The question — \"Delete this item?\". Labels the dialog. */\n title: ReactNode\n /** Optional muted line under the title (the consequence). Describes the dialog. */\n description?: ReactNode\n /**\n * Runs on confirm. Return a Promise to keep the popover open with the confirm button **loading** until\n * it settles — it closes on success and **stays open on rejection** (show your own toast).\n */\n // `unknown` (not `void | Promise`) so `() => toast.success(…)` — which returns an id — still fits\n onConfirm: () => unknown\n /** Runs on Cancel, `Escape` or an outside click. */\n onCancel?: () => void\n /** Confirm button label. Defaults to the localized \"Confirm\". */\n confirmLabel?: ReactNode\n /** Cancel button label. Defaults to the localized \"Cancel\". */\n cancelLabel?: ReactNode\n /** Tints the confirm button and the icon. Defaults to `error` (a destructive action). */\n color?: ThemeColor\n /** Leading icon — a known `IconName`, any node, or `false`. Defaults to `Danger` in the `color`. */\n icon?: IconName | ReactNode | false\n /** Horizontal alignment to the trigger (`start` default, `end` for a trigger near the right edge). */\n align?: PopoverAlign\n /** Controlled open state. */\n open?: boolean\n /** Fires with the next open state. */\n onOpenChange?: (open: boolean) => void\n /** Clicking the trigger does nothing (no popover). */\n disabled?: boolean\n /** Panel width (px number or CSS width). Defaults to `300px`. */\n width?: number | string\n /** Class on the floating panel. */\n className?: string\n /** Style on the floating panel. */\n style?: CSSProperties\n /** The trigger — usually a `Button` / `IconButton`. Cloned to wire the click + ARIA. */\n children: ReactElement\n}\n\n/**\n * An **inline confirm** for quick, low-risk actions (a row's delete / archive) — a small anchored popover\n * with a question, an optional description and **Cancel** / **Confirm**, where a `RemoveDialog` modal\n * would be too heavy and a bare `onClick` too dangerous. Wraps its trigger (`children`), which it clones\n * to toggle the panel. Built on the shared `FloatingPanel` (portaled, flips, clamps to the viewport,\n * dismisses on outside click / `Escape` = cancel). A11y: `role=\"alertdialog\"` labelled by the title and\n * described by the description, focus trapped and **placed on Cancel** (never the destructive button —\n * the `RemoveDialog` rule), focus returns to the trigger. An async `onConfirm` shows a loading confirm\n * button (Cancel + dismiss locked meanwhile), closes on success, stays open on failure. The icon sits in a\n * tinted box, the buttons (`sm`; confirm `contained` in `color`, default `error`) in a Card-style footer. Use `RemoveDialog` for high-risk, context-heavy deletes.\n */\nexport function Popconfirm({\n title,\n description,\n onConfirm,\n onCancel,\n confirmLabel,\n cancelLabel,\n color = 'error',\n icon = 'Danger',\n align = 'start',\n open,\n onOpenChange,\n disabled = false,\n width = 300,\n className,\n style,\n children,\n}: PopconfirmProps) {\n const t = useT()\n const id = useId()\n const panelId = `${id}-panel`\n const titleId = `${id}-title`\n const descId = `${id}-desc`\n const triggerRef = useRef<HTMLElement | null>(null)\n const cancelRef = useRef<HTMLButtonElement | null>(null)\n const [busy, setBusy] = useState(false)\n\n const isControlled = open !== undefined\n const [internalOpen, setInternalOpen] = useState(false)\n const isOpen = isControlled ? open : internalOpen\n const setOpen = (next: boolean) => {\n if (!isControlled) setInternalOpen(next)\n onOpenChange?.(next)\n }\n\n // focus Cancel once the panel is positioned + visible (a hidden element can't take focus)\n useEffect(() => {\n if (!isOpen) return\n const raf = requestAnimationFrame(() => cancelRef.current?.focus())\n return () => cancelAnimationFrame(raf)\n }, [isOpen])\n\n const close = (refocus: boolean) => {\n setOpen(false)\n if (refocus) triggerRef.current?.focus()\n }\n\n const cancel = (refocus = true) => {\n if (busy) return\n onCancel?.()\n close(refocus)\n }\n\n const confirm = async () => {\n const result = onConfirm()\n // any thenable counts as async (not just native Promises)\n if (!result || typeof (result as PromiseLike<unknown>).then !== 'function') {\n close(true)\n return\n }\n setBusy(true)\n try {\n await result\n setBusy(false)\n close(true)\n } catch {\n // stays open so the user can retry or cancel; surfacing the error (a toast) is the consumer's job\n setBusy(false)\n }\n }\n\n const triggerProps = children.props as {\n onClick?: (event: ReactMouseEvent) => void\n ref?: Ref<HTMLElement>\n }\n const originalRef = triggerProps.ref\n const trigger = cloneElement(children as ReactElement<Record<string, unknown>>, {\n ref: (node: HTMLElement | null) => {\n triggerRef.current = node\n if (typeof originalRef === 'function') originalRef(node)\n else if (originalRef) (originalRef as { current: HTMLElement | null }).current = node\n },\n onClick: (event: ReactMouseEvent) => {\n triggerProps.onClick?.(event)\n if (disabled || busy) return\n if (isOpen) cancel(false)\n else setOpen(true)\n },\n 'aria-haspopup': 'dialog',\n 'aria-expanded': isOpen,\n 'aria-controls': isOpen ? panelId : undefined,\n })\n\n const renderedIcon =\n icon === false ? null : typeof icon === 'string' && ICON_NAME_SET.has(icon) ? (\n <Icon name={icon as IconName} />\n ) : (\n icon\n )\n\n return (\n <>\n {trigger}\n <FloatingPanel\n open={isOpen}\n triggerRef={triggerRef}\n align={align}\n onClose={(refocus) => cancel(refocus)}\n id={panelId}\n role=\"alertdialog\"\n ariaLabelledBy={titleId}\n ariaDescribedBy={description != null ? descId : undefined}\n trapFocus\n width={width}\n className={clsx(styles.popconfirm, className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n >\n <div className={styles.body}>\n {renderedIcon != null && (\n <span className={styles.icon} aria-hidden=\"true\">\n {renderedIcon}\n </span>\n )}\n <div className={styles.text}>\n <div id={titleId} className={styles.title}>\n {title}\n </div>\n {description != null && (\n <div id={descId} className={styles.description}>\n {description}\n </div>\n )}\n </div>\n </div>\n <div className={styles.footer}>\n <Button ref={cancelRef} variant=\"text\" size=\"sm\" onClick={() => cancel()} disabled={busy}>\n {cancelLabel ?? t('common.cancel')}\n </Button>\n <Button variant=\"contained\" color={color} size=\"sm\" loading={busy} onClick={confirm}>\n {confirmLabel ?? t('common.confirm')}\n </Button>\n </div>\n </FloatingPanel>\n </>\n )\n}\n"],"names":["ICON_NAME_SET","ICON_NAMES","Popconfirm","title","description","onConfirm","onCancel","confirmLabel","cancelLabel","color","icon","align","open","onOpenChange","disabled","width","className","style","children","t","useT","id","useId","panelId","titleId","descId","triggerRef","useRef","cancelRef","busy","setBusy","useState","isControlled","internalOpen","setInternalOpen","isOpen","setOpen","next","useEffect","raf","_a","close","refocus","cancel","confirm","result","triggerProps","originalRef","trigger","cloneElement","node","event","renderedIcon","jsx","Icon","jsxs","Fragment","FloatingPanel","clsx","styles","Button"],"mappings":";;;;;;;;;;;;;;;;GAqBMA,KAAgB,IAAI,IAAYC,CAAU;AAoDzC,SAASC,GAAW;AAAA,EACzB,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,MAAAC,IAAO;AAAA,EACP,OAAAC,IAAQ;AAAA,EACR,MAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC,IAAQ;AAAA,EACR,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AACF,GAAoB;AAClB,QAAMC,IAAIC,EAAA,GACJC,IAAKC,EAAA,GACLC,IAAU,GAAGF,CAAE,UACfG,IAAU,GAAGH,CAAE,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