@alfalab/core-components-international-phone-input 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Component-4cd3936b.d.ts +19 -0
- package/Component-63dec22f.d.ts +184 -0
- package/Component-8b2c2707.d.ts +71 -0
- package/Component-9211a437.d.ts +38 -0
- package/Component-bdb4c6b9.d.ts +12 -0
- package/Component-c76d6398.d.ts +5 -0
- package/Component-d078a845.d.ts +7 -0
- package/Component-dd8ca091.d.ts +72 -0
- package/Component-ebda875c.d.ts +12 -0
- package/Component.desktop-2e2b2125.d.ts +6 -0
- package/Component.desktop-785df74d.d.ts +6 -0
- package/Component.desktop-d078a845.d.ts +73 -0
- package/Component.desktop-d873d97d.d.ts +6 -0
- package/Component.desktop.d.ts +5 -0
- package/Component.desktop.js +47 -0
- package/Component.mobile-4cd3936b.d.ts +98 -0
- package/Component.mobile-755fbaa3.d.ts +6 -0
- package/Component.mobile-ade26e99.d.ts +41 -0
- package/Component.mobile-d7e9f69d.d.ts +6 -0
- package/Component.mobile-ebda875c.d.ts +6 -0
- package/Component.mobile-f1f15074.d.ts +34 -0
- package/Component.mobile.d.ts +5 -0
- package/Component.mobile.js +82 -0
- package/Component.modal.mobile-4cd3936b.d.ts +91 -0
- package/Component.modal.mobile-dd8ca091.d.ts +60 -0
- package/Component.responsive-785df74d.d.ts +26 -0
- package/Component.responsive.d.ts +46 -0
- package/Component.responsive.js +43 -0
- package/Context-bdb4c6b9.d.ts +4 -0
- package/ResponsiveContext-baf4875b.d.ts +5 -0
- package/components/base-international-phone-input/Component.d.ts +26 -0
- package/components/base-international-phone-input/Component.js +98 -0
- package/components/base-international-phone-input/index.css +5 -0
- package/components/base-international-phone-input/index.d.ts +1 -0
- package/components/base-international-phone-input/index.js +26 -0
- package/components/country-select/Component.d.ts +21 -0
- package/components/country-select/Component.js +60 -0
- package/components/country-select/index.css +47 -0
- package/components/country-select/index.d.ts +1 -0
- package/components/country-select/index.js +20 -0
- package/components/flag-icon/component.d.ts +16 -0
- package/components/flag-icon/component.js +27 -0
- package/components/flag-icon/flagSprite.d.ts +2 -0
- package/components/flag-icon/flagSprite.js +233 -0
- package/components/flag-icon/index.css +30 -0
- package/components/flag-icon/index.d.ts +1 -0
- package/components/flag-icon/index.js +12 -0
- package/components/select-field/component.d.ts +8 -0
- package/components/select-field/component.js +43 -0
- package/components/select-field/index.css +53 -0
- package/components/select-field/index.d.ts +1 -0
- package/components/select-field/index.js +18 -0
- package/consts-f777ba1a.d.ts +2 -0
- package/consts.d.ts +2 -0
- package/consts.js +7 -0
- package/cssm/Component-4cd3936b.d.ts +7 -0
- package/cssm/Component-8b2c2707.d.ts +71 -0
- package/cssm/Component-9211a437.d.ts +38 -0
- package/cssm/Component-96988a65.d.ts +9 -0
- package/cssm/Component-aed0af6e.d.ts +11 -0
- package/cssm/Component-bdb4c6b9.d.ts +12 -0
- package/cssm/Component-c76d6398.d.ts +5 -0
- package/cssm/Component-dd8ca091.d.ts +5 -0
- package/cssm/Component-ebda875c.d.ts +101 -0
- package/cssm/Component-f12ee135.d.ts +72 -0
- package/cssm/Component.desktop-2e2b2125.d.ts +6 -0
- package/cssm/Component.desktop-4cd3936b.d.ts +73 -0
- package/cssm/Component.desktop-785df74d.d.ts +6 -0
- package/cssm/Component.desktop-d873d97d.d.ts +6 -0
- package/cssm/Component.desktop-ebda875c.d.ts +18 -0
- package/cssm/Component.desktop.d.ts +5 -0
- package/cssm/Component.desktop.js +51 -0
- package/cssm/Component.mobile-755fbaa3.d.ts +6 -0
- package/cssm/Component.mobile-ade26e99.d.ts +41 -0
- package/cssm/Component.mobile-d7e9f69d.d.ts +6 -0
- package/cssm/Component.mobile-f1f15074.d.ts +34 -0
- package/cssm/Component.mobile.d.ts +5 -0
- package/cssm/Component.mobile.js +86 -0
- package/cssm/Component.responsive-d7e9f69d.d.ts +26 -0
- package/cssm/Component.responsive.d.ts +46 -0
- package/cssm/Component.responsive.js +47 -0
- package/cssm/Context-bdb4c6b9.d.ts +4 -0
- package/cssm/ResponsiveContext-baf4875b.d.ts +5 -0
- package/cssm/components/base-international-phone-input/Component.d.ts +26 -0
- package/cssm/components/base-international-phone-input/Component.js +100 -0
- package/cssm/components/base-international-phone-input/index.d.ts +1 -0
- package/cssm/components/base-international-phone-input/index.js +30 -0
- package/cssm/components/base-international-phone-input/index.module.css +4 -0
- package/cssm/components/country-select/Component.d.ts +21 -0
- package/cssm/components/country-select/Component.js +61 -0
- package/cssm/components/country-select/index.d.ts +1 -0
- package/cssm/components/country-select/index.js +23 -0
- package/cssm/components/country-select/index.module.css +47 -0
- package/cssm/components/flag-icon/component.d.ts +16 -0
- package/cssm/components/flag-icon/component.js +26 -0
- package/cssm/components/flag-icon/flagSprite.d.ts +2 -0
- package/cssm/components/flag-icon/flagSprite.js +233 -0
- package/cssm/components/flag-icon/index.d.ts +1 -0
- package/cssm/components/flag-icon/index.js +13 -0
- package/cssm/components/flag-icon/index.module.css +29 -0
- package/cssm/components/select-field/component.d.ts +8 -0
- package/cssm/components/select-field/component.js +43 -0
- package/cssm/components/select-field/index.d.ts +1 -0
- package/cssm/components/select-field/index.js +20 -0
- package/cssm/components/select-field/index.module.css +52 -0
- package/cssm/consts-f777ba1a.d.ts +2 -0
- package/cssm/consts.d.ts +2 -0
- package/cssm/consts.js +7 -0
- package/cssm/data/country-data.d.ts +3 -0
- package/cssm/data/country-data.js +587 -0
- package/cssm/desktop-232828f7.d.ts +2 -0
- package/cssm/desktop-2e2b2125.d.ts +2 -0
- package/cssm/desktop-63dec22f.d.ts +2 -0
- package/cssm/desktop-785df74d.d.ts +2 -0
- package/cssm/desktop.d.ts +2 -0
- package/cssm/desktop.js +34 -0
- package/cssm/hook-8abfea97.d.ts +90 -0
- package/cssm/hook-ebda875c.d.ts +48 -0
- package/cssm/index-136acbb1.d.ts +28 -0
- package/cssm/index-72dda473.d.ts +12 -0
- package/cssm/index-8b2c2707.d.ts +6 -0
- package/cssm/index-bdb4c6b9.d.ts +180 -0
- package/cssm/index-c76d6398.d.ts +319 -0
- package/cssm/index-ebda875c.d.ts +3 -0
- package/cssm/index-f12ee135.d.ts +52 -0
- package/cssm/index.d.ts +2 -0
- package/cssm/index.js +40 -0
- package/cssm/mobile-45dc17c6.d.ts +47 -0
- package/cssm/mobile-4c19bc40.d.ts +121 -0
- package/cssm/mobile-96988a65.d.ts +3 -0
- package/cssm/mobile.d.ts +2 -0
- package/cssm/mobile.js +34 -0
- package/cssm/shared-4cd3936b.d.ts +7 -0
- package/cssm/types-1b036d4b.d.ts +13 -0
- package/cssm/types-72dda473.d.ts +276 -0
- package/cssm/types.d.ts +100 -0
- package/cssm/types.js +2 -0
- package/cssm/typings-9211a437.d.ts +95 -0
- package/cssm/typings-bdb4c6b9.d.ts +52 -0
- package/cssm/typings-dd8ca091.d.ts +572 -0
- package/cssm/useSkeleton-1b036d4b.d.ts +12 -0
- package/cssm/utils/index.d.ts +18 -0
- package/cssm/utils/index.js +201 -0
- package/cssm/utils-dd8ca091.d.ts +41 -0
- package/data/country-data.d.ts +3 -0
- package/data/country-data.js +587 -0
- package/desktop-232828f7.d.ts +2 -0
- package/desktop-2e2b2125.d.ts +2 -0
- package/desktop-63dec22f.d.ts +2 -0
- package/desktop.d.ts +2 -0
- package/desktop.js +30 -0
- package/esm/Component-4cd3936b.d.ts +19 -0
- package/esm/Component-63dec22f.d.ts +184 -0
- package/esm/Component-8b2c2707.d.ts +71 -0
- package/esm/Component-9211a437.d.ts +38 -0
- package/esm/Component-bdb4c6b9.d.ts +12 -0
- package/esm/Component-c76d6398.d.ts +5 -0
- package/esm/Component-d078a845.d.ts +7 -0
- package/esm/Component-dd8ca091.d.ts +72 -0
- package/esm/Component-ebda875c.d.ts +12 -0
- package/esm/Component.desktop-2e2b2125.d.ts +6 -0
- package/esm/Component.desktop-785df74d.d.ts +6 -0
- package/esm/Component.desktop-d078a845.d.ts +73 -0
- package/esm/Component.desktop-d873d97d.d.ts +6 -0
- package/esm/Component.desktop.d.ts +5 -0
- package/esm/Component.desktop.js +39 -0
- package/esm/Component.mobile-4cd3936b.d.ts +98 -0
- package/esm/Component.mobile-755fbaa3.d.ts +6 -0
- package/esm/Component.mobile-ade26e99.d.ts +41 -0
- package/esm/Component.mobile-d7e9f69d.d.ts +6 -0
- package/esm/Component.mobile-ebda875c.d.ts +6 -0
- package/esm/Component.mobile-f1f15074.d.ts +34 -0
- package/esm/Component.mobile.d.ts +5 -0
- package/esm/Component.mobile.js +74 -0
- package/esm/Component.modal.mobile-4cd3936b.d.ts +91 -0
- package/esm/Component.modal.mobile-dd8ca091.d.ts +60 -0
- package/esm/Component.responsive-785df74d.d.ts +26 -0
- package/esm/Component.responsive.d.ts +46 -0
- package/esm/Component.responsive.js +35 -0
- package/esm/Context-bdb4c6b9.d.ts +4 -0
- package/esm/ResponsiveContext-baf4875b.d.ts +5 -0
- package/esm/components/base-international-phone-input/Component.d.ts +26 -0
- package/esm/components/base-international-phone-input/Component.js +89 -0
- package/esm/components/base-international-phone-input/index.css +5 -0
- package/esm/components/base-international-phone-input/index.d.ts +1 -0
- package/esm/components/base-international-phone-input/index.js +18 -0
- package/esm/components/country-select/Component.d.ts +21 -0
- package/esm/components/country-select/Component.js +52 -0
- package/esm/components/country-select/index.css +47 -0
- package/esm/components/country-select/index.d.ts +1 -0
- package/esm/components/country-select/index.js +12 -0
- package/esm/components/flag-icon/component.d.ts +16 -0
- package/esm/components/flag-icon/component.js +18 -0
- package/esm/components/flag-icon/flagSprite.d.ts +2 -0
- package/esm/components/flag-icon/flagSprite.js +229 -0
- package/esm/components/flag-icon/index.css +30 -0
- package/esm/components/flag-icon/index.d.ts +1 -0
- package/esm/components/flag-icon/index.js +4 -0
- package/esm/components/select-field/component.d.ts +8 -0
- package/esm/components/select-field/component.js +32 -0
- package/esm/components/select-field/index.css +53 -0
- package/esm/components/select-field/index.d.ts +1 -0
- package/esm/components/select-field/index.js +9 -0
- package/esm/consts-f777ba1a.d.ts +2 -0
- package/esm/consts.d.ts +2 -0
- package/esm/consts.js +3 -0
- package/esm/data/country-data.d.ts +3 -0
- package/esm/data/country-data.js +583 -0
- package/esm/desktop-232828f7.d.ts +2 -0
- package/esm/desktop-2e2b2125.d.ts +2 -0
- package/esm/desktop-63dec22f.d.ts +2 -0
- package/esm/desktop.d.ts +2 -0
- package/esm/desktop.js +22 -0
- package/esm/hook-8abfea97.d.ts +90 -0
- package/esm/index-136acbb1.d.ts +28 -0
- package/esm/index-72dda473.d.ts +12 -0
- package/esm/index-8b2c2707.d.ts +6 -0
- package/esm/index-bdb4c6b9.d.ts +2 -0
- package/esm/index-c76d6398.d.ts +141 -0
- package/esm/index-ebda875c.d.ts +3 -0
- package/esm/index-f12ee135.d.ts +52 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +28 -0
- package/esm/mobile-4c19bc40.d.ts +3 -0
- package/esm/mobile-755fbaa3.d.ts +2 -0
- package/esm/mobile-96988a65.d.ts +2 -0
- package/esm/mobile-ade26e99.d.ts +5 -0
- package/esm/mobile-d7e9f69d.d.ts +2 -0
- package/esm/mobile.d.ts +2 -0
- package/esm/mobile.js +22 -0
- package/esm/shared-4cd3936b.d.ts +65 -0
- package/esm/types-1b036d4b.d.ts +13 -0
- package/esm/types-72dda473.d.ts +276 -0
- package/esm/types.d.ts +100 -0
- package/esm/types.js +1 -0
- package/esm/typings-9211a437.d.ts +95 -0
- package/esm/typings-bdb4c6b9.d.ts +52 -0
- package/esm/typings-dd8ca091.d.ts +572 -0
- package/esm/useSkeleton-ebda875c.d.ts +12 -0
- package/esm/utils/index.d.ts +18 -0
- package/esm/utils/index.js +189 -0
- package/esm/utils-1574ad8b.d.ts +29 -0
- package/esm/utils-dd8ca091.d.ts +41 -0
- package/hook-8abfea97.d.ts +90 -0
- package/index-136acbb1.d.ts +28 -0
- package/index-72dda473.d.ts +12 -0
- package/index-8b2c2707.d.ts +6 -0
- package/index-bdb4c6b9.d.ts +2 -0
- package/index-c76d6398.d.ts +141 -0
- package/index-ebda875c.d.ts +3 -0
- package/index-f12ee135.d.ts +52 -0
- package/index.d.ts +2 -0
- package/index.js +36 -0
- package/mobile-4c19bc40.d.ts +3 -0
- package/mobile-755fbaa3.d.ts +2 -0
- package/mobile-96988a65.d.ts +2 -0
- package/mobile-ade26e99.d.ts +5 -0
- package/mobile-d7e9f69d.d.ts +2 -0
- package/mobile.d.ts +2 -0
- package/mobile.js +30 -0
- package/modern/Component-4cd3936b.d.ts +19 -0
- package/modern/Component-63dec22f.d.ts +184 -0
- package/modern/Component-8b2c2707.d.ts +71 -0
- package/modern/Component-9211a437.d.ts +38 -0
- package/modern/Component-bdb4c6b9.d.ts +12 -0
- package/modern/Component-c76d6398.d.ts +5 -0
- package/modern/Component-d078a845.d.ts +7 -0
- package/modern/Component-dd8ca091.d.ts +72 -0
- package/modern/Component-ebda875c.d.ts +12 -0
- package/modern/Component.desktop-2e2b2125.d.ts +6 -0
- package/modern/Component.desktop-785df74d.d.ts +6 -0
- package/modern/Component.desktop-d078a845.d.ts +73 -0
- package/modern/Component.desktop-d873d97d.d.ts +6 -0
- package/modern/Component.desktop.d.ts +5 -0
- package/modern/Component.desktop.js +35 -0
- package/modern/Component.mobile-4cd3936b.d.ts +98 -0
- package/modern/Component.mobile-755fbaa3.d.ts +6 -0
- package/modern/Component.mobile-ade26e99.d.ts +41 -0
- package/modern/Component.mobile-d7e9f69d.d.ts +6 -0
- package/modern/Component.mobile-ebda875c.d.ts +6 -0
- package/modern/Component.mobile-f1f15074.d.ts +34 -0
- package/modern/Component.mobile.d.ts +5 -0
- package/modern/Component.mobile.js +77 -0
- package/modern/Component.modal.mobile-4cd3936b.d.ts +91 -0
- package/modern/Component.modal.mobile-dd8ca091.d.ts +60 -0
- package/modern/Component.responsive-785df74d.d.ts +26 -0
- package/modern/Component.responsive.d.ts +46 -0
- package/modern/Component.responsive.js +33 -0
- package/modern/Context-bdb4c6b9.d.ts +4 -0
- package/modern/ResponsiveContext-baf4875b.d.ts +5 -0
- package/modern/components/base-international-phone-input/Component.d.ts +26 -0
- package/modern/components/base-international-phone-input/Component.js +91 -0
- package/modern/components/base-international-phone-input/index.css +5 -0
- package/modern/components/base-international-phone-input/index.d.ts +1 -0
- package/modern/components/base-international-phone-input/index.js +17 -0
- package/modern/components/country-select/Component.d.ts +21 -0
- package/modern/components/country-select/Component.js +47 -0
- package/modern/components/country-select/index.css +47 -0
- package/modern/components/country-select/index.d.ts +1 -0
- package/modern/components/country-select/index.js +11 -0
- package/modern/components/flag-icon/component.d.ts +16 -0
- package/modern/components/flag-icon/component.js +15 -0
- package/modern/components/flag-icon/flagSprite.d.ts +2 -0
- package/modern/components/flag-icon/flagSprite.js +229 -0
- package/modern/components/flag-icon/index.css +30 -0
- package/modern/components/flag-icon/index.d.ts +1 -0
- package/modern/components/flag-icon/index.js +4 -0
- package/modern/components/select-field/component.d.ts +8 -0
- package/modern/components/select-field/component.js +29 -0
- package/modern/components/select-field/index.css +53 -0
- package/modern/components/select-field/index.d.ts +1 -0
- package/modern/components/select-field/index.js +8 -0
- package/modern/consts-f777ba1a.d.ts +2 -0
- package/modern/consts.d.ts +2 -0
- package/modern/consts.js +3 -0
- package/modern/data/country-data.d.ts +3 -0
- package/modern/data/country-data.js +583 -0
- package/modern/desktop-232828f7.d.ts +2 -0
- package/modern/desktop-2e2b2125.d.ts +2 -0
- package/modern/desktop-63dec22f.d.ts +2 -0
- package/modern/desktop.d.ts +2 -0
- package/modern/desktop.js +21 -0
- package/modern/hook-8abfea97.d.ts +90 -0
- package/modern/index-136acbb1.d.ts +28 -0
- package/modern/index-72dda473.d.ts +12 -0
- package/modern/index-8b2c2707.d.ts +6 -0
- package/modern/index-bdb4c6b9.d.ts +2 -0
- package/modern/index-c76d6398.d.ts +141 -0
- package/modern/index-ebda875c.d.ts +3 -0
- package/modern/index-f12ee135.d.ts +52 -0
- package/modern/index.d.ts +2 -0
- package/modern/index.js +27 -0
- package/modern/mobile-4c19bc40.d.ts +3 -0
- package/modern/mobile-755fbaa3.d.ts +2 -0
- package/modern/mobile-96988a65.d.ts +2 -0
- package/modern/mobile-ade26e99.d.ts +5 -0
- package/modern/mobile-d7e9f69d.d.ts +2 -0
- package/modern/mobile.d.ts +2 -0
- package/modern/mobile.js +21 -0
- package/modern/shared-4cd3936b.d.ts +65 -0
- package/modern/types-1b036d4b.d.ts +13 -0
- package/modern/types-72dda473.d.ts +276 -0
- package/modern/types.d.ts +100 -0
- package/modern/types.js +1 -0
- package/modern/typings-9211a437.d.ts +95 -0
- package/modern/typings-bdb4c6b9.d.ts +52 -0
- package/modern/typings-dd8ca091.d.ts +572 -0
- package/modern/useSkeleton-ebda875c.d.ts +12 -0
- package/modern/utils/index.d.ts +18 -0
- package/modern/utils/index.js +183 -0
- package/modern/utils-1574ad8b.d.ts +29 -0
- package/modern/utils-dd8ca091.d.ts +41 -0
- package/package.json +30 -0
- package/shared-4cd3936b.d.ts +65 -0
- package/src/Component.desktop.tsx +68 -0
- package/src/Component.mobile.tsx +132 -0
- package/src/Component.responsive.tsx +20 -0
- package/src/components/base-international-phone-input/Component.tsx +174 -0
- package/src/components/base-international-phone-input/index.module.css +5 -0
- package/src/components/base-international-phone-input/index.ts +1 -0
- package/src/components/country-select/Component.tsx +120 -0
- package/src/components/country-select/index.module.css +40 -0
- package/src/components/country-select/index.ts +1 -0
- package/src/components/flag-icon/component.tsx +33 -0
- package/src/components/flag-icon/flagSprite.ts +228 -0
- package/src/components/flag-icon/index.module.css +15 -0
- package/src/components/flag-icon/index.ts +1 -0
- package/src/components/select-field/component.tsx +51 -0
- package/src/components/select-field/index.module.css +43 -0
- package/src/components/select-field/index.ts +1 -0
- package/src/consts.ts +1 -0
- package/src/data/country-data.ts +584 -0
- package/src/desktop.ts +2 -0
- package/src/index.ts +2 -0
- package/src/mobile.ts +2 -0
- package/src/types.ts +132 -0
- package/src/utils/index.ts +246 -0
- package/types-1b036d4b.d.ts +13 -0
- package/types-72dda473.d.ts +276 -0
- package/types.d.ts +100 -0
- package/types.js +2 -0
- package/typings-9211a437.d.ts +95 -0
- package/typings-bdb4c6b9.d.ts +52 -0
- package/typings-dd8ca091.d.ts +572 -0
- package/useSkeleton-ebda875c.d.ts +12 -0
- package/utils/index.d.ts +18 -0
- package/utils/index.js +201 -0
- package/utils-1574ad8b.d.ts +29 -0
- package/utils-dd8ca091.d.ts +41 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { isGroup } from '@alfalab/core-components-select/modern/shared';
|
|
2
|
+
import { maskUtils } from '@alfalab/core-components-shared/modern';
|
|
3
|
+
import { DEFAULT_PHONE_FORMAT } from '../consts.js';
|
|
4
|
+
import { countriesData } from '../data/country-data.js';
|
|
5
|
+
|
|
6
|
+
function initCountries(iso2s) {
|
|
7
|
+
const filteredCountriesData = Array.isArray(iso2s)
|
|
8
|
+
? countriesData.filter((country) => iso2s.includes(country[2]))
|
|
9
|
+
: countriesData;
|
|
10
|
+
return filteredCountriesData.map((country) => {
|
|
11
|
+
const countryItem = {
|
|
12
|
+
name: country[0],
|
|
13
|
+
regions: country[1],
|
|
14
|
+
iso2: country[2],
|
|
15
|
+
countryCode: country[3],
|
|
16
|
+
dialCode: country[3],
|
|
17
|
+
format: country[4],
|
|
18
|
+
priority: country[5] || 0,
|
|
19
|
+
};
|
|
20
|
+
const areaItems = [];
|
|
21
|
+
if (country[6]) {
|
|
22
|
+
country[6]?.forEach((areaCode) => {
|
|
23
|
+
const areaItem = { ...countryItem };
|
|
24
|
+
areaItem.dialCode = country[3] + areaCode;
|
|
25
|
+
areaItem.isAreaCode = true;
|
|
26
|
+
areaItem.areaCodeLength = areaCode.length;
|
|
27
|
+
areaItems.push(areaItem);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (areaItems.length > 0) {
|
|
31
|
+
countryItem.mainCode = true;
|
|
32
|
+
return [countryItem, ...areaItems];
|
|
33
|
+
}
|
|
34
|
+
return [countryItem];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function findCountry(countries, value, iso2, country) {
|
|
38
|
+
if (country)
|
|
39
|
+
return country;
|
|
40
|
+
if (value) {
|
|
41
|
+
const inputNumber = clearMask(value);
|
|
42
|
+
const nextCountry = guessCountry(inputNumber, countries);
|
|
43
|
+
if (nextCountry)
|
|
44
|
+
return nextCountry;
|
|
45
|
+
}
|
|
46
|
+
if (!iso2)
|
|
47
|
+
return undefined;
|
|
48
|
+
return countries.find((c) => c[0].iso2 === iso2)?.[0];
|
|
49
|
+
}
|
|
50
|
+
function guessCountry(inputNumber, data) {
|
|
51
|
+
const inputNumberDialCode = inputNumber.slice(0, 6);
|
|
52
|
+
const result = data.reduce((selectedCountry, countryData) => {
|
|
53
|
+
let guess;
|
|
54
|
+
countryData.forEach((country) => {
|
|
55
|
+
if (inputNumberDialCode.startsWith(country.dialCode)) {
|
|
56
|
+
const selectedCountryDialCode = selectedCountry?.dialCode || '';
|
|
57
|
+
const selectedCountryPriority = selectedCountry?.priority || 100;
|
|
58
|
+
if (country.dialCode.length > selectedCountryDialCode.length) {
|
|
59
|
+
guess = country;
|
|
60
|
+
}
|
|
61
|
+
if (country.dialCode.length === selectedCountryDialCode.length &&
|
|
62
|
+
country.priority < selectedCountryPriority) {
|
|
63
|
+
guess = country;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return guess || selectedCountry;
|
|
68
|
+
}, undefined);
|
|
69
|
+
if (!result && inputNumber.length > 5 && inputNumber.startsWith('8'))
|
|
70
|
+
return data.find((countryData) => countryData[0].iso2 === 'ru')?.[0];
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function clearMask(value) {
|
|
74
|
+
return value.replace(/\D/g, '');
|
|
75
|
+
}
|
|
76
|
+
function itemToMask(item) {
|
|
77
|
+
return item === '.' ? /\d/ : item;
|
|
78
|
+
}
|
|
79
|
+
function prepareDefaultFormat(countryCode, clearableCountryCode) {
|
|
80
|
+
if (!countryCode)
|
|
81
|
+
return ['+', ...DEFAULT_PHONE_FORMAT.split('').map(itemToMask)];
|
|
82
|
+
const removeDots = (count) => {
|
|
83
|
+
let removed = 0;
|
|
84
|
+
let res = DEFAULT_PHONE_FORMAT;
|
|
85
|
+
while (removed < count) {
|
|
86
|
+
res = res.replace(/\./, '');
|
|
87
|
+
removed += 1;
|
|
88
|
+
}
|
|
89
|
+
return res.trim();
|
|
90
|
+
};
|
|
91
|
+
if (clearableCountryCode) {
|
|
92
|
+
return [
|
|
93
|
+
'+',
|
|
94
|
+
...countryCode.split('').map(() => /\d/),
|
|
95
|
+
' ',
|
|
96
|
+
...removeDots(countryCode.length).split('').map(itemToMask).reverse(),
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
return [
|
|
100
|
+
'+',
|
|
101
|
+
...countryCode.split(''),
|
|
102
|
+
' ',
|
|
103
|
+
...removeDots(countryCode.length).split('').map(itemToMask).reverse(),
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
function createPhoneMaskExpression(country, clearableCountryCode) {
|
|
107
|
+
const { countryCode, format } = country || {};
|
|
108
|
+
if (!countryCode || !format) {
|
|
109
|
+
return prepareDefaultFormat(countryCode, clearableCountryCode);
|
|
110
|
+
}
|
|
111
|
+
return [
|
|
112
|
+
'+',
|
|
113
|
+
...(clearableCountryCode ? countryCode.split('').map(() => /\d/) : countryCode.split('')),
|
|
114
|
+
' ',
|
|
115
|
+
...format.split('').map((item) => (item === '.' ? /\d/ : item)),
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
function createMaskOptions(country, clearableCountryCode) {
|
|
119
|
+
const prefixLen = !clearableCountryCode && country?.countryCode ? country.countryCode.length + 1 : 0;
|
|
120
|
+
const mask = createPhoneMaskExpression(country, clearableCountryCode);
|
|
121
|
+
return {
|
|
122
|
+
mask,
|
|
123
|
+
preprocessors: [
|
|
124
|
+
maskUtils.insertionPhonePreprocessor(mask, country?.countryCode, clearableCountryCode),
|
|
125
|
+
],
|
|
126
|
+
postprocessors: [
|
|
127
|
+
maskUtils.prefixPostprocessor(prefixLen ? `+${country?.countryCode}` : ''),
|
|
128
|
+
],
|
|
129
|
+
plugins: [
|
|
130
|
+
maskUtils.caretGuard((value, [from, to]) => [
|
|
131
|
+
from === to ? prefixLen : 0,
|
|
132
|
+
value.length,
|
|
133
|
+
]),
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function defaultFilterFn(value = '', option) {
|
|
138
|
+
return clearMask(option.key).includes(clearMask(value));
|
|
139
|
+
}
|
|
140
|
+
const filterPhones = (value = '', options, filterFn = defaultFilterFn) => {
|
|
141
|
+
if (!options || options.length === 0)
|
|
142
|
+
return options;
|
|
143
|
+
const filteredOptions = [];
|
|
144
|
+
options.forEach((option) => {
|
|
145
|
+
if (isGroup(option)) {
|
|
146
|
+
const group = {
|
|
147
|
+
...option,
|
|
148
|
+
options: [],
|
|
149
|
+
};
|
|
150
|
+
option.options.forEach((groupOption) => {
|
|
151
|
+
if (filterFn(value, groupOption))
|
|
152
|
+
group.options.push(groupOption);
|
|
153
|
+
});
|
|
154
|
+
if (group.options.length)
|
|
155
|
+
filteredOptions.push(group);
|
|
156
|
+
}
|
|
157
|
+
else if (filterFn(value, option))
|
|
158
|
+
filteredOptions.push(option);
|
|
159
|
+
});
|
|
160
|
+
return filteredOptions;
|
|
161
|
+
};
|
|
162
|
+
function getPhoneData(phone, countries, defaultIso2) {
|
|
163
|
+
let nextPhone = phone;
|
|
164
|
+
const inputNumber = clearMask(nextPhone);
|
|
165
|
+
const nextCountry = findCountry(countries, phone, defaultIso2);
|
|
166
|
+
if (nextCountry?.iso2 === 'ru' && inputNumber.length > 5 && inputNumber.startsWith('8')) {
|
|
167
|
+
nextPhone = phone.replace(/\+?8/, '+7');
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
nextPhone,
|
|
171
|
+
nextCountry,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function getClear(clear, clearableCountryCode, value = '', countryCode = '') {
|
|
175
|
+
if (!clear)
|
|
176
|
+
return clear;
|
|
177
|
+
const trimmedValue = value.trim();
|
|
178
|
+
return clearableCountryCode
|
|
179
|
+
? trimmedValue !== '' && trimmedValue !== '+'
|
|
180
|
+
: trimmedValue.length > countryCode.length + 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export { clearMask, createMaskOptions, createPhoneMaskExpression, filterPhones, findCountry, getClear, getPhoneData, guessCountry, initCountries };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type SavedStyle = {
|
|
2
|
+
value: string;
|
|
3
|
+
key: string;
|
|
4
|
+
el: HTMLElement;
|
|
5
|
+
};
|
|
6
|
+
type RestoreStyle = {
|
|
7
|
+
container: HTMLElement;
|
|
8
|
+
modals: number;
|
|
9
|
+
styles: SavedStyle[];
|
|
10
|
+
};
|
|
11
|
+
declare class ModalStore {
|
|
12
|
+
private readonly restoreStyles;
|
|
13
|
+
constructor();
|
|
14
|
+
getRestoreStyles: () => RestoreStyle[];
|
|
15
|
+
}
|
|
16
|
+
declare const getModalStore: () => ModalStore;
|
|
17
|
+
declare class GlobalStore {
|
|
18
|
+
private readonly modalStore;
|
|
19
|
+
constructor();
|
|
20
|
+
getModalStore: () => ModalStore;
|
|
21
|
+
}
|
|
22
|
+
declare function isScrolledToTop(target: HTMLElement): boolean;
|
|
23
|
+
declare function isScrolledToBottom(target: HTMLElement): boolean;
|
|
24
|
+
declare function hasScrollbar(target: HTMLElement): boolean;
|
|
25
|
+
declare const getScrollbarSize: () => number;
|
|
26
|
+
declare const restoreContainerStyles: (container: HTMLElement) => void;
|
|
27
|
+
declare const handleContainer: (container?: HTMLElement) => void;
|
|
28
|
+
export type { SavedStyle };
|
|
29
|
+
export { getModalStore, GlobalStore, isScrolledToTop, isScrolledToBottom, hasScrollbar, getScrollbarSize, restoreContainerStyles, handleContainer };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
|
+
import { BaseSelectProps, GroupShape, OptionShape } from "./typings-dd8ca091";
|
|
3
|
+
declare const isGroup: (item: OptionShape | GroupShape) => item is GroupShape;
|
|
4
|
+
declare const isOptionShape: (item: OptionShape | string | null) => item is OptionShape;
|
|
5
|
+
declare const joinOptions: ({ selected, selectedMultiple, }: {
|
|
6
|
+
selected?: OptionShape | undefined;
|
|
7
|
+
selectedMultiple?: OptionShape[] | undefined;
|
|
8
|
+
}) => ReactNode[] | null;
|
|
9
|
+
declare function processOptions(options: BaseSelectProps['options'], selected?: BaseSelectProps['selected'], filterFn?: (option: OptionShape) => boolean): {
|
|
10
|
+
filteredOptions: (OptionShape | GroupShape)[];
|
|
11
|
+
flatOptions: OptionShape[];
|
|
12
|
+
selectedOptions: OptionShape[];
|
|
13
|
+
};
|
|
14
|
+
type useVisibleOptionsArgs = {
|
|
15
|
+
/**
|
|
16
|
+
* Количество видимых пунктов
|
|
17
|
+
*/
|
|
18
|
+
visibleOptions: number;
|
|
19
|
+
/**
|
|
20
|
+
* Реф на контейнер с пунтами меню
|
|
21
|
+
*/
|
|
22
|
+
listRef: RefObject<HTMLElement>;
|
|
23
|
+
/**
|
|
24
|
+
* Реф на контейнер, которому нужно установить высоту
|
|
25
|
+
*/
|
|
26
|
+
styleTargetRef?: RefObject<HTMLElement>;
|
|
27
|
+
/**
|
|
28
|
+
* Флаг открытия меню
|
|
29
|
+
*/
|
|
30
|
+
open?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Позволяет вызвать пересчет высоты
|
|
33
|
+
*/
|
|
34
|
+
invalidate?: unknown;
|
|
35
|
+
};
|
|
36
|
+
declare function useVisibleOptions({ visibleOptions, listRef, styleTargetRef, open, invalidate, }: useVisibleOptionsArgs): void;
|
|
37
|
+
declare function defaultFilterFn(optionText: string, search: string): boolean;
|
|
38
|
+
declare function defaultAccessor(option: OptionShape): string;
|
|
39
|
+
declare function usePrevious<T>(value: T): T | undefined;
|
|
40
|
+
declare const lastIndexOf: <T>(array: T[], predicate: (item: T) => boolean) => number;
|
|
41
|
+
export { isGroup, isOptionShape, joinOptions, processOptions, useVisibleOptions, defaultFilterFn, defaultAccessor, usePrevious, lastIndexOf };
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alfalab/core-components-international-phone-input",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"module": "./esm/index.js",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"directory": "dist"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^16.9.0 || ^17.0.1 || ^18.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@alfalab/core-components-input-autocomplete": "10.1.6",
|
|
18
|
+
"@alfalab/core-components-input": "^12.1.4",
|
|
19
|
+
"@alfalab/core-components-select": "^15.1.6",
|
|
20
|
+
"@alfalab/core-components-shared": "^0.5.0",
|
|
21
|
+
"@alfalab/core-components-mq": "^4.2.0",
|
|
22
|
+
"@alfalab/hooks": "^1.13.0",
|
|
23
|
+
"@alfalab/icons-glyph": "^2.108.0",
|
|
24
|
+
"@maskito/core": "^1.4.0",
|
|
25
|
+
"@maskito/react": "^1.4.0",
|
|
26
|
+
"classnames": "^2.3.1",
|
|
27
|
+
"react-merge-refs": "^1.1.0",
|
|
28
|
+
"tslib": "^2.4.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { BaseSelectProps, OptionProps, OptionShape } from "./typings-dd8ca091";
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
+
type useSelectWithLoadingProps = {
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
visibleOptions?: BaseSelectProps["visibleOptions"];
|
|
8
|
+
Option?: React.FC<OptionProps>;
|
|
9
|
+
};
|
|
10
|
+
declare function useSelectWithLoading({ loading, visibleOptions, Option }: useSelectWithLoadingProps): {
|
|
11
|
+
Option: (props: OptionProps) => React.JSX.Element;
|
|
12
|
+
options: OptionShape[];
|
|
13
|
+
} | null;
|
|
14
|
+
type OptionsFetcherResponse = {
|
|
15
|
+
options: OptionShape[];
|
|
16
|
+
hasMore: boolean;
|
|
17
|
+
};
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
|
+
type useLazyLoadingProps = {
|
|
20
|
+
/** Количество элементов на "странице" */
|
|
21
|
+
limit?: number;
|
|
22
|
+
/** Начальный номер "страницы" */
|
|
23
|
+
initialOffset?: number;
|
|
24
|
+
/** Скелетон загружаемых элементов */
|
|
25
|
+
skeleton?: React.ReactNode;
|
|
26
|
+
/** Компонент пункта меню */
|
|
27
|
+
Option?: React.FC<OptionProps>;
|
|
28
|
+
/**
|
|
29
|
+
* Функция-загрузчик опций.
|
|
30
|
+
* @param offset - текущая страница
|
|
31
|
+
* @param limit - количество элементов на странице
|
|
32
|
+
* @param queryString - строчные данные, пробрасываемые для поиска из кастомного инпута, расположенного в заголовке OptionsList
|
|
33
|
+
* @returns Promise<{
|
|
34
|
+
* options - список опций следующей "страницы". Они аппендятся к предыдущим
|
|
35
|
+
* hasMore - указывает, есть ли еще незагруженные элементы (в случае false перестает загружать "следующую страницу")
|
|
36
|
+
* }>
|
|
37
|
+
*/
|
|
38
|
+
optionsFetcher(offset: number, limit: number, queryString?: string): Promise<OptionsFetcherResponse>;
|
|
39
|
+
};
|
|
40
|
+
declare function useLazyLoading({ limit, initialOffset, optionsFetcher, skeleton, Option }: useLazyLoadingProps): {
|
|
41
|
+
optionsProps: {
|
|
42
|
+
Option: (props: OptionProps) => React.JSX.Element;
|
|
43
|
+
options: OptionShape[];
|
|
44
|
+
optionsListProps: {
|
|
45
|
+
ref: React.RefObject<HTMLDivElement>;
|
|
46
|
+
inputProps: {
|
|
47
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
48
|
+
value: string;
|
|
49
|
+
}) => void;
|
|
50
|
+
value: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
onOpen: (payload: {
|
|
54
|
+
open?: boolean;
|
|
55
|
+
}) => void;
|
|
56
|
+
};
|
|
57
|
+
reset: () => void;
|
|
58
|
+
};
|
|
59
|
+
export * from "./index-ebda875c";
|
|
60
|
+
export * from "./Component-dd8ca091";
|
|
61
|
+
export { useSelectWithLoading, useLazyLoading };
|
|
62
|
+
export * from "./hook-8abfea97";
|
|
63
|
+
export * from "./typings-dd8ca091";
|
|
64
|
+
export * from "./utils-dd8ca091";
|
|
65
|
+
export type { AdditionalMobileProps } from "./Component.mobile-ade26e99";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { InputDesktop } from '@alfalab/core-components-input/Component.desktop';
|
|
4
|
+
import { InputAutocompleteDesktop } from '@alfalab/core-components-input-autocomplete/desktop';
|
|
5
|
+
import { SelectDesktop } from '@alfalab/core-components-select/desktop';
|
|
6
|
+
|
|
7
|
+
import { BaseInternationalPhoneInput } from './components/base-international-phone-input';
|
|
8
|
+
import type {
|
|
9
|
+
BaseInternationalPhoneInputProps,
|
|
10
|
+
InternationalPhoneInputDesktopProps,
|
|
11
|
+
} from './types';
|
|
12
|
+
import { Country } from './types';
|
|
13
|
+
import { filterPhones, findCountry, getClear, initCountries } from './utils';
|
|
14
|
+
|
|
15
|
+
export const InternationalPhoneInputDesktop = forwardRef<
|
|
16
|
+
HTMLInputElement,
|
|
17
|
+
InternationalPhoneInputDesktopProps
|
|
18
|
+
>(
|
|
19
|
+
(
|
|
20
|
+
{
|
|
21
|
+
options,
|
|
22
|
+
country: countryProp,
|
|
23
|
+
countries,
|
|
24
|
+
onCountryChange,
|
|
25
|
+
value,
|
|
26
|
+
filterFn,
|
|
27
|
+
defaultIso2,
|
|
28
|
+
clear,
|
|
29
|
+
clearableCountryCode = true,
|
|
30
|
+
...restProps
|
|
31
|
+
},
|
|
32
|
+
ref,
|
|
33
|
+
) => {
|
|
34
|
+
const countriesData = useMemo(() => initCountries(countries), [countries]);
|
|
35
|
+
const [selectedCountry, setSelectedCountry] = useState<Country | undefined>(() =>
|
|
36
|
+
findCountry(countriesData, value, defaultIso2, countryProp),
|
|
37
|
+
);
|
|
38
|
+
const filteredOptions = filterPhones(value, options, filterFn);
|
|
39
|
+
const country = countryProp ?? selectedCountry;
|
|
40
|
+
|
|
41
|
+
const handleCountryChange = (nextCountry?: Country) => {
|
|
42
|
+
if (countryProp === undefined) setSelectedCountry(nextCountry);
|
|
43
|
+
onCountryChange?.(nextCountry);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<BaseInternationalPhoneInput
|
|
48
|
+
countriesData={countriesData}
|
|
49
|
+
selected={value}
|
|
50
|
+
{...restProps}
|
|
51
|
+
clear={getClear(clear, clearableCountryCode, value, country?.countryCode)}
|
|
52
|
+
clearableCountryCode={clearableCountryCode}
|
|
53
|
+
country={country}
|
|
54
|
+
onCountryChange={handleCountryChange}
|
|
55
|
+
defaultIso2={defaultIso2}
|
|
56
|
+
value={value}
|
|
57
|
+
view='desktop'
|
|
58
|
+
options={filteredOptions}
|
|
59
|
+
ref={ref}
|
|
60
|
+
SelectComponent={SelectDesktop}
|
|
61
|
+
Input={InputDesktop}
|
|
62
|
+
InputAutocomplete={
|
|
63
|
+
InputAutocompleteDesktop as BaseInternationalPhoneInputProps['InputAutocomplete']
|
|
64
|
+
}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { ChangeEvent, forwardRef, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { InputMobile } from '@alfalab/core-components-input/mobile';
|
|
4
|
+
import {
|
|
5
|
+
InputAutocompleteMobile,
|
|
6
|
+
InputAutocompleteMobileProps,
|
|
7
|
+
} from '@alfalab/core-components-input-autocomplete/mobile';
|
|
8
|
+
import { SelectMobile } from '@alfalab/core-components-select/mobile';
|
|
9
|
+
|
|
10
|
+
import { BaseInternationalPhoneInput } from './components/base-international-phone-input';
|
|
11
|
+
import { CountrySelect } from './components/country-select';
|
|
12
|
+
import type {
|
|
13
|
+
BaseInternationalPhoneInputProps,
|
|
14
|
+
Country,
|
|
15
|
+
InternationalPhoneInputMobileProps,
|
|
16
|
+
} from './types';
|
|
17
|
+
import { filterPhones, findCountry, getClear, getPhoneData, initCountries } from './utils';
|
|
18
|
+
|
|
19
|
+
export const InternationalPhoneInputMobile = forwardRef<
|
|
20
|
+
HTMLInputElement,
|
|
21
|
+
InternationalPhoneInputMobileProps
|
|
22
|
+
>(
|
|
23
|
+
(
|
|
24
|
+
{
|
|
25
|
+
options,
|
|
26
|
+
country: countryProp,
|
|
27
|
+
onCountryChange,
|
|
28
|
+
value,
|
|
29
|
+
filterFn,
|
|
30
|
+
countries,
|
|
31
|
+
defaultIso2,
|
|
32
|
+
clear: clearProp,
|
|
33
|
+
clearableCountryCode = true,
|
|
34
|
+
...restProps
|
|
35
|
+
},
|
|
36
|
+
ref,
|
|
37
|
+
) => {
|
|
38
|
+
const typedRestProps = restProps as Partial<InputAutocompleteMobileProps>;
|
|
39
|
+
const countriesData = useMemo(() => initCountries(countries), [countries]);
|
|
40
|
+
const [filter, setFilter] = useState('');
|
|
41
|
+
const [filterCountry, setFilterCountry] = useState<Country>();
|
|
42
|
+
const [selectedCountry, setSelectedCountry] = useState<Country | undefined>(() =>
|
|
43
|
+
findCountry(countriesData, value, defaultIso2, countryProp),
|
|
44
|
+
);
|
|
45
|
+
const filteredOptions = filterPhones(filter, options, filterFn);
|
|
46
|
+
const country = countryProp ?? selectedCountry;
|
|
47
|
+
const countryCode = country?.countryCode;
|
|
48
|
+
|
|
49
|
+
const handleCountryChange = (nextCountry?: Country) => {
|
|
50
|
+
if (countryProp === undefined) setSelectedCountry(nextCountry);
|
|
51
|
+
onCountryChange?.(nextCountry);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleFilter = (event: ChangeEvent<HTMLInputElement>) => {
|
|
55
|
+
const { nextPhone, nextCountry } = getPhoneData(
|
|
56
|
+
event.target.value,
|
|
57
|
+
countriesData,
|
|
58
|
+
defaultIso2,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
setFilter(nextPhone);
|
|
62
|
+
setFilterCountry(nextCountry);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleFilterClear = () => {
|
|
66
|
+
const withCountryCode = !clearableCountryCode && filterCountry?.countryCode;
|
|
67
|
+
|
|
68
|
+
setFilter(withCountryCode ? `+${filterCountry.countryCode}` : '');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleEnter = (node: HTMLElement, isAppearing: boolean) => {
|
|
72
|
+
typedRestProps.bottomSheetProps?.transitionProps?.onEnter?.(node, isAppearing);
|
|
73
|
+
setFilterCountry(country);
|
|
74
|
+
setFilter(countryCode ? `+${country.countryCode}` : '');
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const isAutocomplete = Array.isArray(options);
|
|
78
|
+
|
|
79
|
+
const props = isAutocomplete
|
|
80
|
+
? (() => {
|
|
81
|
+
const clear = getClear(clearProp, clearableCountryCode, filter, countryCode);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
filter,
|
|
85
|
+
onFilter: handleFilter,
|
|
86
|
+
onClearFilter: clear ? handleFilterClear : undefined,
|
|
87
|
+
bottomSheetHeaderAddonsProps: {
|
|
88
|
+
...typedRestProps.bottomSheetHeaderAddonsProps,
|
|
89
|
+
leftAddons: (
|
|
90
|
+
<CountrySelect
|
|
91
|
+
SelectComponent={SelectMobile}
|
|
92
|
+
view='mobile'
|
|
93
|
+
country={filterCountry}
|
|
94
|
+
/>
|
|
95
|
+
),
|
|
96
|
+
},
|
|
97
|
+
bottomSheetProps: {
|
|
98
|
+
...typedRestProps.bottomSheetProps,
|
|
99
|
+
transitionProps: {
|
|
100
|
+
...typedRestProps.bottomSheetProps?.transitionProps,
|
|
101
|
+
onEnter: handleEnter,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
})()
|
|
106
|
+
: {
|
|
107
|
+
clear: getClear(clearProp, clearableCountryCode, value, countryCode),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<BaseInternationalPhoneInput
|
|
112
|
+
selected={value}
|
|
113
|
+
{...restProps}
|
|
114
|
+
{...props}
|
|
115
|
+
clearableCountryCode={clearableCountryCode}
|
|
116
|
+
onCountryChange={handleCountryChange}
|
|
117
|
+
country={country}
|
|
118
|
+
defaultIso2={defaultIso2}
|
|
119
|
+
countriesData={countriesData}
|
|
120
|
+
value={value}
|
|
121
|
+
options={filteredOptions}
|
|
122
|
+
view='mobile'
|
|
123
|
+
ref={ref}
|
|
124
|
+
SelectComponent={SelectMobile}
|
|
125
|
+
Input={InputMobile}
|
|
126
|
+
InputAutocomplete={
|
|
127
|
+
InputAutocompleteMobile as BaseInternationalPhoneInputProps['InputAutocomplete']
|
|
128
|
+
}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { useMatchMedia } from '@alfalab/core-components-mq';
|
|
4
|
+
|
|
5
|
+
import { InternationalPhoneInputDesktop } from './Component.desktop';
|
|
6
|
+
import { InternationalPhoneInputMobile } from './Component.mobile';
|
|
7
|
+
import { InternationalPhoneInputProps } from './types';
|
|
8
|
+
|
|
9
|
+
export const InternationalPhoneInput = React.forwardRef<
|
|
10
|
+
HTMLInputElement,
|
|
11
|
+
InternationalPhoneInputProps
|
|
12
|
+
>(({ breakpoint = 1024, defaultMatchMediaValue, ...restProps }, ref) => {
|
|
13
|
+
const [isDesktop] = useMatchMedia(`(min-width: ${breakpoint}px)`, defaultMatchMediaValue);
|
|
14
|
+
|
|
15
|
+
return isDesktop ? (
|
|
16
|
+
<InternationalPhoneInputDesktop {...restProps} ref={ref} />
|
|
17
|
+
) : (
|
|
18
|
+
<InternationalPhoneInputMobile {...restProps} ref={ref} />
|
|
19
|
+
);
|
|
20
|
+
});
|