@senvenli/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/action/button-group.d.ts +26 -0
- package/dist/action/button-group.js +12 -0
- package/dist/action/button-group.js.map +1 -0
- package/dist/action/button.d.ts +42 -0
- package/dist/action/button.js +58 -0
- package/dist/action/button.js.map +1 -0
- package/dist/action/close-button.d.ts +12 -0
- package/dist/action/close-button.js +13 -0
- package/dist/action/close-button.js.map +1 -0
- package/dist/action/copy-button.d.ts +21 -0
- package/dist/action/copy-button.js +38 -0
- package/dist/action/copy-button.js.map +1 -0
- package/dist/action/fab.d.ts +29 -0
- package/dist/action/fab.js +57 -0
- package/dist/action/fab.js.map +1 -0
- package/dist/action/files.d.ts +70 -0
- package/dist/action/files.js +156 -0
- package/dist/action/files.js.map +1 -0
- package/dist/action/index.d.ts +23 -0
- package/dist/action/index.js +16 -0
- package/dist/action/index.js.map +1 -0
- package/dist/action/language-names.d.ts +19 -0
- package/dist/action/language-names.js +79 -0
- package/dist/action/language-names.js.map +1 -0
- package/dist/action/language-switcher.d.ts +57 -0
- package/dist/action/language-switcher.js +53 -0
- package/dist/action/language-switcher.js.map +1 -0
- package/dist/action/link-button.d.ts +57 -0
- package/dist/action/link-button.js +48 -0
- package/dist/action/link-button.js.map +1 -0
- package/dist/action/link.d.ts +24 -0
- package/dist/action/link.js +18 -0
- package/dist/action/link.js.map +1 -0
- package/dist/action/pressable.d.ts +40 -0
- package/dist/action/pressable.js +65 -0
- package/dist/action/pressable.js.map +1 -0
- package/dist/action/styles.d.ts +60 -0
- package/dist/action/styles.js +109 -0
- package/dist/action/styles.js.map +1 -0
- package/dist/action/theme-script.d.ts +12 -0
- package/dist/action/theme-script.js +23 -0
- package/dist/action/theme-script.js.map +1 -0
- package/dist/action/theme-switcher.d.ts +43 -0
- package/dist/action/theme-switcher.js +260 -0
- package/dist/action/theme-switcher.js.map +1 -0
- package/dist/action/theme-toggle.d.ts +43 -0
- package/dist/action/theme-toggle.js +259 -0
- package/dist/action/theme-toggle.js.map +1 -0
- package/dist/action/toggle.d.ts +44 -0
- package/dist/action/toggle.js +28 -0
- package/dist/action/toggle.js.map +1 -0
- package/dist/action/touch-target.d.ts +9 -0
- package/dist/action/touch-target.js +14 -0
- package/dist/action/touch-target.js.map +1 -0
- package/dist/charts/axis-width.d.ts +186 -0
- package/dist/charts/axis-width.js +1262 -0
- package/dist/charts/axis-width.js.map +1 -0
- package/dist/charts/bar-public.d.ts +16 -0
- package/dist/charts/bar-public.js +16 -0
- package/dist/charts/bar-public.js.map +1 -0
- package/dist/charts/chart-parts.d.ts +136 -0
- package/dist/charts/chart-parts.js +160 -0
- package/dist/charts/chart-parts.js.map +1 -0
- package/dist/charts/core-charts.d.ts +157 -0
- package/dist/charts/core-charts.js +505 -0
- package/dist/charts/core-charts.js.map +1 -0
- package/dist/charts/index.d.ts +12 -0
- package/dist/charts/index.js +8 -0
- package/dist/charts/index.js.map +1 -0
- package/dist/charts/list-charts.d.ts +124 -0
- package/dist/charts/list-charts.js +308 -0
- package/dist/charts/list-charts.js.map +1 -0
- package/dist/charts/more-charts.d.ts +138 -0
- package/dist/charts/more-charts.js +284 -0
- package/dist/charts/more-charts.js.map +1 -0
- package/dist/charts/report-charts.d.ts +138 -0
- package/dist/charts/report-charts.js +370 -0
- package/dist/charts/report-charts.js.map +1 -0
- package/dist/charts/value-tick.d.ts +178 -0
- package/dist/charts/value-tick.js +240 -0
- package/dist/charts/value-tick.js.map +1 -0
- package/dist/collection/data-table-url-hook.d.ts +34 -0
- package/dist/collection/data-table-url-hook.js +70 -0
- package/dist/collection/data-table-url-hook.js.map +1 -0
- package/dist/collection/data-table-url.d.ts +30 -0
- package/dist/collection/data-table-url.js +48 -0
- package/dist/collection/data-table-url.js.map +1 -0
- package/dist/collection/data-table.d.ts +112 -0
- package/dist/collection/data-table.js +188 -0
- package/dist/collection/data-table.js.map +1 -0
- package/dist/collection/grid-list-public.d.ts +18 -0
- package/dist/collection/grid-list-public.js +19 -0
- package/dist/collection/grid-list-public.js.map +1 -0
- package/dist/collection/grid-list.d.ts +73 -0
- package/dist/collection/grid-list.js +46 -0
- package/dist/collection/grid-list.js.map +1 -0
- package/dist/collection/index.d.ts +14 -0
- package/dist/collection/index.js +8 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/list.d.ts +61 -0
- package/dist/collection/list.js +38 -0
- package/dist/collection/list.js.map +1 -0
- package/dist/collection/selection-checkbox.d.ts +5 -0
- package/dist/collection/selection-checkbox.js +13 -0
- package/dist/collection/selection-checkbox.js.map +1 -0
- package/dist/collection/table.d.ts +91 -0
- package/dist/collection/table.js +183 -0
- package/dist/collection/table.js.map +1 -0
- package/dist/collection/tree.d.ts +31 -0
- package/dist/collection/tree.js +22 -0
- package/dist/collection/tree.js.map +1 -0
- package/dist/color/color.d.ts +87 -0
- package/dist/color/color.js +200 -0
- package/dist/color/color.js.map +1 -0
- package/dist/color/contrast.d.ts +34 -0
- package/dist/color/contrast.js +44 -0
- package/dist/color/contrast.js.map +1 -0
- package/dist/color/index.d.ts +4 -0
- package/dist/color/index.js +5 -0
- package/dist/color/index.js.map +1 -0
- package/dist/date/calendar.d.ts +71 -0
- package/dist/date/calendar.js +291 -0
- package/dist/date/calendar.js.map +1 -0
- package/dist/date/fields.d.ts +174 -0
- package/dist/date/fields.js +250 -0
- package/dist/date/fields.js.map +1 -0
- package/dist/date/index.d.ts +7 -0
- package/dist/date/index.js +6 -0
- package/dist/date/index.js.map +1 -0
- package/dist/date/month-grid.d.ts +31 -0
- package/dist/date/month-grid.js +115 -0
- package/dist/date/month-grid.js.map +1 -0
- package/dist/date/pickers.d.ts +118 -0
- package/dist/date/pickers.js +176 -0
- package/dist/date/pickers.js.map +1 -0
- package/dist/date/public.d.ts +25 -0
- package/dist/date/public.js +24 -0
- package/dist/date/public.js.map +1 -0
- package/dist/date/segments.d.ts +153 -0
- package/dist/date/segments.js +433 -0
- package/dist/date/segments.js.map +1 -0
- package/dist/defaults.d.ts +74 -0
- package/dist/defaults.js +100 -0
- package/dist/defaults.js.map +1 -0
- package/dist/density.d.ts +2 -0
- package/dist/density.js +2 -0
- package/dist/density.js.map +1 -0
- package/dist/display/avatar.d.ts +29 -0
- package/dist/display/avatar.js +71 -0
- package/dist/display/avatar.js.map +1 -0
- package/dist/display/badge.d.ts +65 -0
- package/dist/display/badge.js +99 -0
- package/dist/display/badge.js.map +1 -0
- package/dist/display/card.d.ts +72 -0
- package/dist/display/card.js +91 -0
- package/dist/display/card.js.map +1 -0
- package/dist/display/carousel.d.ts +47 -0
- package/dist/display/carousel.js +214 -0
- package/dist/display/carousel.js.map +1 -0
- package/dist/display/description-list.d.ts +25 -0
- package/dist/display/description-list.js +36 -0
- package/dist/display/description-list.js.map +1 -0
- package/dist/display/icon-aliases.d.ts +1 -0
- package/dist/display/icon-aliases.js +259 -0
- package/dist/display/icon-aliases.js.map +1 -0
- package/dist/display/icon-names.d.ts +4 -0
- package/dist/display/icon-names.js +2 -0
- package/dist/display/icon-names.js.map +1 -0
- package/dist/display/icon.d.ts +51 -0
- package/dist/display/icon.js +96 -0
- package/dist/display/icon.js.map +1 -0
- package/dist/display/image-crop.d.ts +106 -0
- package/dist/display/image-crop.js +117 -0
- package/dist/display/image-crop.js.map +1 -0
- package/dist/display/image-cropper.d.ts +68 -0
- package/dist/display/image-cropper.js +284 -0
- package/dist/display/image-cropper.js.map +1 -0
- package/dist/display/image-viewer.d.ts +54 -0
- package/dist/display/image-viewer.js +84 -0
- package/dist/display/image-viewer.js.map +1 -0
- package/dist/display/image.d.ts +26 -0
- package/dist/display/image.js +17 -0
- package/dist/display/image.js.map +1 -0
- package/dist/display/index.d.ts +29 -0
- package/dist/display/index.js +16 -0
- package/dist/display/index.js.map +1 -0
- package/dist/display/iso-chip.d.ts +19 -0
- package/dist/display/iso-chip.js +21 -0
- package/dist/display/iso-chip.js.map +1 -0
- package/dist/display/kbd.d.ts +11 -0
- package/dist/display/kbd.js +33 -0
- package/dist/display/kbd.js.map +1 -0
- package/dist/display/lozenge.d.ts +30 -0
- package/dist/display/lozenge.js +55 -0
- package/dist/display/lozenge.js.map +1 -0
- package/dist/display/scroll-area.d.ts +29 -0
- package/dist/display/scroll-area.js +95 -0
- package/dist/display/scroll-area.js.map +1 -0
- package/dist/display/separator.d.ts +13 -0
- package/dist/display/separator.js +24 -0
- package/dist/display/separator.js.map +1 -0
- package/dist/display/stat.d.ts +35 -0
- package/dist/display/stat.js +41 -0
- package/dist/display/stat.js.map +1 -0
- package/dist/display/timeline.d.ts +44 -0
- package/dist/display/timeline.js +111 -0
- package/dist/display/timeline.js.map +1 -0
- package/dist/display/typography.d.ts +37 -0
- package/dist/display/typography.js +53 -0
- package/dist/display/typography.js.map +1 -0
- package/dist/display/visually-hidden.d.ts +14 -0
- package/dist/display/visually-hidden.js +10 -0
- package/dist/display/visually-hidden.js.map +1 -0
- package/dist/feedback/banner.d.ts +46 -0
- package/dist/feedback/banner.js +157 -0
- package/dist/feedback/banner.js.map +1 -0
- package/dist/feedback/cooldown.d.ts +17 -0
- package/dist/feedback/cooldown.js +59 -0
- package/dist/feedback/cooldown.js.map +1 -0
- package/dist/feedback/empty-state.d.ts +35 -0
- package/dist/feedback/empty-state.js +39 -0
- package/dist/feedback/empty-state.js.map +1 -0
- package/dist/feedback/index.d.ts +12 -0
- package/dist/feedback/index.js +11 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/feedback/meter.d.ts +33 -0
- package/dist/feedback/meter.js +42 -0
- package/dist/feedback/meter.js.map +1 -0
- package/dist/feedback/motion.d.ts +9 -0
- package/dist/feedback/motion.js +57 -0
- package/dist/feedback/motion.js.map +1 -0
- package/dist/feedback/progress.d.ts +39 -0
- package/dist/feedback/progress.js +68 -0
- package/dist/feedback/progress.js.map +1 -0
- package/dist/feedback/skeleton.d.ts +48 -0
- package/dist/feedback/skeleton.js +61 -0
- package/dist/feedback/skeleton.js.map +1 -0
- package/dist/feedback/spinner.d.ts +19 -0
- package/dist/feedback/spinner.js +29 -0
- package/dist/feedback/spinner.js.map +1 -0
- package/dist/feedback/status-dot.d.ts +23 -0
- package/dist/feedback/status-dot.js +37 -0
- package/dist/feedback/status-dot.js.map +1 -0
- package/dist/form/countries.d.ts +34 -0
- package/dist/form/countries.js +273 -0
- package/dist/form/countries.js.map +1 -0
- package/dist/form/data-attributes.d.ts +11 -0
- package/dist/form/data-attributes.js +22 -0
- package/dist/form/data-attributes.js.map +1 -0
- package/dist/form/field-parts.d.ts +113 -0
- package/dist/form/field-parts.js +178 -0
- package/dist/form/field-parts.js.map +1 -0
- package/dist/form/field.d.ts +36 -0
- package/dist/form/field.js +65 -0
- package/dist/form/field.js.map +1 -0
- package/dist/form/files.d.ts +70 -0
- package/dist/form/files.js +156 -0
- package/dist/form/files.js.map +1 -0
- package/dist/form/form.d.ts +40 -0
- package/dist/form/form.js +74 -0
- package/dist/form/form.js.map +1 -0
- package/dist/form/image-crop.d.ts +106 -0
- package/dist/form/image-crop.js +117 -0
- package/dist/form/image-crop.js.map +1 -0
- package/dist/form/image-cropper.d.ts +68 -0
- package/dist/form/image-cropper.js +284 -0
- package/dist/form/image-cropper.js.map +1 -0
- package/dist/form/index.d.ts +24 -0
- package/dist/form/index.js +15 -0
- package/dist/form/index.js.map +1 -0
- package/dist/form/input-group.d.ts +63 -0
- package/dist/form/input-group.js +63 -0
- package/dist/form/input-group.js.map +1 -0
- package/dist/form/input-otp.d.ts +35 -0
- package/dist/form/input-otp.js +83 -0
- package/dist/form/input-otp.js.map +1 -0
- package/dist/form/input.d.ts +36 -0
- package/dist/form/input.js +41 -0
- package/dist/form/input.js.map +1 -0
- package/dist/form/number-field.d.ts +84 -0
- package/dist/form/number-field.js +81 -0
- package/dist/form/number-field.js.map +1 -0
- package/dist/form/otp-field.d.ts +37 -0
- package/dist/form/otp-field.js +116 -0
- package/dist/form/otp-field.js.map +1 -0
- package/dist/form/password-field.d.ts +61 -0
- package/dist/form/password-field.js +61 -0
- package/dist/form/password-field.js.map +1 -0
- package/dist/form/phone-field.d.ts +104 -0
- package/dist/form/phone-field.js +275 -0
- package/dist/form/phone-field.js.map +1 -0
- package/dist/form/phone-paste.d.ts +24 -0
- package/dist/form/phone-paste.js +40 -0
- package/dist/form/phone-paste.js.map +1 -0
- package/dist/form/phone.d.ts +159 -0
- package/dist/form/phone.js +309 -0
- package/dist/form/phone.js.map +1 -0
- package/dist/form/search-field.d.ts +29 -0
- package/dist/form/search-field.js +23 -0
- package/dist/form/search-field.js.map +1 -0
- package/dist/form/styles.d.ts +31 -0
- package/dist/form/styles.js +43 -0
- package/dist/form/styles.js.map +1 -0
- package/dist/form/text-area.d.ts +70 -0
- package/dist/form/text-area.js +93 -0
- package/dist/form/text-area.js.map +1 -0
- package/dist/form/text-field.d.ts +131 -0
- package/dist/form/text-field.js +59 -0
- package/dist/form/text-field.js.map +1 -0
- package/dist/form/validation.d.ts +145 -0
- package/dist/form/validation.js +136 -0
- package/dist/form/validation.js.map +1 -0
- package/dist/i18n.d.ts +438 -0
- package/dist/i18n.js +948 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/intl-locale.d.ts +30 -0
- package/dist/intl-locale.js +83 -0
- package/dist/intl-locale.js.map +1 -0
- package/dist/layers.d.ts +32 -0
- package/dist/layers.js +33 -0
- package/dist/layers.js.map +1 -0
- package/dist/layout/auth-form-layout.d.ts +71 -0
- package/dist/layout/auth-form-layout.js +61 -0
- package/dist/layout/auth-form-layout.js.map +1 -0
- package/dist/layout/auth-layout.d.ts +59 -0
- package/dist/layout/auth-layout.js +26 -0
- package/dist/layout/auth-layout.js.map +1 -0
- package/dist/layout/box.d.ts +26 -0
- package/dist/layout/box.js +16 -0
- package/dist/layout/box.js.map +1 -0
- package/dist/layout/grid.d.ts +27 -0
- package/dist/layout/grid.js +26 -0
- package/dist/layout/grid.js.map +1 -0
- package/dist/layout/index.d.ts +16 -0
- package/dist/layout/index.js +12 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/pressable.d.ts +40 -0
- package/dist/layout/pressable.js +65 -0
- package/dist/layout/pressable.js.map +1 -0
- package/dist/layout/reset-sent-card.d.ts +39 -0
- package/dist/layout/reset-sent-card.js +22 -0
- package/dist/layout/reset-sent-card.js.map +1 -0
- package/dist/layout/scroll-area.d.ts +29 -0
- package/dist/layout/scroll-area.js +95 -0
- package/dist/layout/scroll-area.js.map +1 -0
- package/dist/layout/section.d.ts +41 -0
- package/dist/layout/section.js +22 -0
- package/dist/layout/section.js.map +1 -0
- package/dist/layout/split.d.ts +50 -0
- package/dist/layout/split.js +35 -0
- package/dist/layout/split.js.map +1 -0
- package/dist/layout/stack.d.ts +44 -0
- package/dist/layout/stack.js +36 -0
- package/dist/layout/stack.js.map +1 -0
- package/dist/layout/tokens.d.ts +33 -0
- package/dist/layout/tokens.js +85 -0
- package/dist/layout/tokens.js.map +1 -0
- package/dist/layout/toolbar.d.ts +37 -0
- package/dist/layout/toolbar.js +334 -0
- package/dist/layout/toolbar.js.map +1 -0
- package/dist/navigate-context.d.ts +12 -0
- package/dist/navigate-context.js +13 -0
- package/dist/navigate-context.js.map +1 -0
- package/dist/navigation/accordion.d.ts +40 -0
- package/dist/navigation/accordion.js +33 -0
- package/dist/navigation/accordion.js.map +1 -0
- package/dist/navigation/bottom-nav.d.ts +29 -0
- package/dist/navigation/bottom-nav.js +48 -0
- package/dist/navigation/bottom-nav.js.map +1 -0
- package/dist/navigation/brand-link-context.d.ts +8 -0
- package/dist/navigation/brand-link-context.js +9 -0
- package/dist/navigation/brand-link-context.js.map +1 -0
- package/dist/navigation/breadcrumbs.d.ts +36 -0
- package/dist/navigation/breadcrumbs.js +51 -0
- package/dist/navigation/breadcrumbs.js.map +1 -0
- package/dist/navigation/dock.d.ts +27 -0
- package/dist/navigation/dock.js +47 -0
- package/dist/navigation/dock.js.map +1 -0
- package/dist/navigation/footer.d.ts +43 -0
- package/dist/navigation/footer.js +43 -0
- package/dist/navigation/footer.js.map +1 -0
- package/dist/navigation/index.d.ts +22 -0
- package/dist/navigation/index.js +17 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/language-names.d.ts +19 -0
- package/dist/navigation/language-names.js +79 -0
- package/dist/navigation/language-names.js.map +1 -0
- package/dist/navigation/language-switcher.d.ts +55 -0
- package/dist/navigation/language-switcher.js +53 -0
- package/dist/navigation/language-switcher.js.map +1 -0
- package/dist/navigation/nav-panel.d.ts +18 -0
- package/dist/navigation/nav-panel.js +51 -0
- package/dist/navigation/nav-panel.js.map +1 -0
- package/dist/navigation/navbar.d.ts +73 -0
- package/dist/navigation/navbar.js +64 -0
- package/dist/navigation/navbar.js.map +1 -0
- package/dist/navigation/page-header.d.ts +37 -0
- package/dist/navigation/page-header.js +50 -0
- package/dist/navigation/page-header.js.map +1 -0
- package/dist/navigation/pagination.d.ts +25 -0
- package/dist/navigation/pagination.js +51 -0
- package/dist/navigation/pagination.js.map +1 -0
- package/dist/navigation/panel-header.d.ts +37 -0
- package/dist/navigation/panel-header.js +50 -0
- package/dist/navigation/panel-header.js.map +1 -0
- package/dist/navigation/sidebar-script.d.ts +12 -0
- package/dist/navigation/sidebar-script.js +20 -0
- package/dist/navigation/sidebar-script.js.map +1 -0
- package/dist/navigation/sidebar.d.ts +149 -0
- package/dist/navigation/sidebar.js +332 -0
- package/dist/navigation/sidebar.js.map +1 -0
- package/dist/navigation/skip-link.d.ts +12 -0
- package/dist/navigation/skip-link.js +30 -0
- package/dist/navigation/skip-link.js.map +1 -0
- package/dist/navigation/stepper.d.ts +50 -0
- package/dist/navigation/stepper.js +96 -0
- package/dist/navigation/stepper.js.map +1 -0
- package/dist/navigation/tabs.d.ts +84 -0
- package/dist/navigation/tabs.js +118 -0
- package/dist/navigation/tabs.js.map +1 -0
- package/dist/navigation/toolbar.d.ts +37 -0
- package/dist/navigation/toolbar.js +334 -0
- package/dist/navigation/toolbar.js.map +1 -0
- package/dist/overlay/alert-dialog.d.ts +63 -0
- package/dist/overlay/alert-dialog.js +76 -0
- package/dist/overlay/alert-dialog.js.map +1 -0
- package/dist/overlay/command-palette.d.ts +53 -0
- package/dist/overlay/command-palette.js +130 -0
- package/dist/overlay/command-palette.js.map +1 -0
- package/dist/overlay/command.d.ts +53 -0
- package/dist/overlay/command.js +129 -0
- package/dist/overlay/command.js.map +1 -0
- package/dist/overlay/context-menu.d.ts +29 -0
- package/dist/overlay/context-menu.js +58 -0
- package/dist/overlay/context-menu.js.map +1 -0
- package/dist/overlay/dialog.d.ts +162 -0
- package/dist/overlay/dialog.js +174 -0
- package/dist/overlay/dialog.js.map +1 -0
- package/dist/overlay/drawer.d.ts +41 -0
- package/dist/overlay/drawer.js +114 -0
- package/dist/overlay/drawer.js.map +1 -0
- package/dist/overlay/floating.d.ts +142 -0
- package/dist/overlay/floating.js +226 -0
- package/dist/overlay/floating.js.map +1 -0
- package/dist/overlay/hover-card.d.ts +19 -0
- package/dist/overlay/hover-card.js +31 -0
- package/dist/overlay/hover-card.js.map +1 -0
- package/dist/overlay/index.d.ts +18 -0
- package/dist/overlay/index.js +12 -0
- package/dist/overlay/index.js.map +1 -0
- package/dist/overlay/overlay-base.d.ts +105 -0
- package/dist/overlay/overlay-base.js +250 -0
- package/dist/overlay/overlay-base.js.map +1 -0
- package/dist/overlay/overlay.d.ts +299 -0
- package/dist/overlay/overlay.js +558 -0
- package/dist/overlay/overlay.js.map +1 -0
- package/dist/overlay/toast.d.ts +58 -0
- package/dist/overlay/toast.js +145 -0
- package/dist/overlay/toast.js.map +1 -0
- package/dist/provider.d.ts +26 -0
- package/dist/provider.js +30 -0
- package/dist/provider.js.map +1 -0
- package/dist/selection/autocomplete.d.ts +54 -0
- package/dist/selection/autocomplete.js +122 -0
- package/dist/selection/autocomplete.js.map +1 -0
- package/dist/selection/checkbox.d.ts +56 -0
- package/dist/selection/checkbox.js +49 -0
- package/dist/selection/checkbox.js.map +1 -0
- package/dist/selection/choice-size.d.ts +26 -0
- package/dist/selection/choice-size.js +50 -0
- package/dist/selection/choice-size.js.map +1 -0
- package/dist/selection/choice-text.d.ts +21 -0
- package/dist/selection/choice-text.js +33 -0
- package/dist/selection/choice-text.js.map +1 -0
- package/dist/selection/combobox.d.ts +173 -0
- package/dist/selection/combobox.js +410 -0
- package/dist/selection/combobox.js.map +1 -0
- package/dist/selection/index.d.ts +20 -0
- package/dist/selection/index.js +13 -0
- package/dist/selection/index.js.map +1 -0
- package/dist/selection/list-box.d.ts +30 -0
- package/dist/selection/list-box.js +16 -0
- package/dist/selection/list-box.js.map +1 -0
- package/dist/selection/listbox.d.ts +44 -0
- package/dist/selection/listbox.js +49 -0
- package/dist/selection/listbox.js.map +1 -0
- package/dist/selection/match.d.ts +20 -0
- package/dist/selection/match.js +57 -0
- package/dist/selection/match.js.map +1 -0
- package/dist/selection/multi-select.d.ts +72 -0
- package/dist/selection/multi-select.js +138 -0
- package/dist/selection/multi-select.js.map +1 -0
- package/dist/selection/radio-card.d.ts +31 -0
- package/dist/selection/radio-card.js +29 -0
- package/dist/selection/radio-card.js.map +1 -0
- package/dist/selection/radio.d.ts +72 -0
- package/dist/selection/radio.js +64 -0
- package/dist/selection/radio.js.map +1 -0
- package/dist/selection/select-public.d.ts +19 -0
- package/dist/selection/select-public.js +24 -0
- package/dist/selection/select-public.js.map +1 -0
- package/dist/selection/select.d.ts +72 -0
- package/dist/selection/select.js +69 -0
- package/dist/selection/select.js.map +1 -0
- package/dist/selection/slider.d.ts +16 -0
- package/dist/selection/slider.js +44 -0
- package/dist/selection/slider.js.map +1 -0
- package/dist/selection/styles.d.ts +26 -0
- package/dist/selection/styles.js +78 -0
- package/dist/selection/styles.js.map +1 -0
- package/dist/selection/switch.d.ts +24 -0
- package/dist/selection/switch.js +27 -0
- package/dist/selection/switch.js.map +1 -0
- package/dist/selection/tag-group.d.ts +38 -0
- package/dist/selection/tag-group.js +45 -0
- package/dist/selection/tag-group.js.map +1 -0
- package/dist/tone.d.ts +6 -0
- package/dist/tone.js +2 -0
- package/dist/tone.js.map +1 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +42 -0
- package/dist/utils.js.map +1 -0
- package/manifest/component.full.schema.json +391 -0
- package/manifest/component.schema.json +279 -0
- package/manifests/accordion.json +299 -0
- package/manifests/alert-dialog.json +261 -0
- package/manifests/area-chart.json +338 -0
- package/manifests/autocomplete.json +299 -0
- package/manifests/avatar.json +253 -0
- package/manifests/badge.json +288 -0
- package/manifests/banner.json +185 -0
- package/manifests/bar-chart.json +454 -0
- package/manifests/bar-list.json +262 -0
- package/manifests/bottom-nav.json +139 -0
- package/manifests/box.json +3450 -0
- package/manifests/breadcrumbs.json +199 -0
- package/manifests/button-group.json +2294 -0
- package/manifests/button.json +1211 -0
- package/manifests/calendar-heatmap.json +218 -0
- package/manifests/calendar.json +299 -0
- package/manifests/card.json +308 -0
- package/manifests/carousel.json +263 -0
- package/manifests/chart-parts.json +309 -0
- package/manifests/checkbox.json +998 -0
- package/manifests/close-button.json +1000 -0
- package/manifests/color-field.json +276 -0
- package/manifests/color-picker.json +161 -0
- package/manifests/color-swatch-picker.json +220 -0
- package/manifests/color-swatch.json +140 -0
- package/manifests/combobox.json +581 -0
- package/manifests/command.json +275 -0
- package/manifests/composed-chart.json +287 -0
- package/manifests/context-menu.json +148 -0
- package/manifests/copy-button.json +192 -0
- package/manifests/data-table.json +334 -0
- package/manifests/date-field.json +302 -0
- package/manifests/date-picker.json +472 -0
- package/manifests/description-list.json +201 -0
- package/manifests/dialog.json +322 -0
- package/manifests/donut-chart.json +264 -0
- package/manifests/drawer.json +211 -0
- package/manifests/empty-state.json +185 -0
- package/manifests/fab.json +172 -0
- package/manifests/field.json +209 -0
- package/manifests/file-upload.json +791 -0
- package/manifests/form.json +829 -0
- package/manifests/funnel-chart.json +223 -0
- package/manifests/gauge-chart.json +252 -0
- package/manifests/grid-list.json +335 -0
- package/manifests/grid.json +3482 -0
- package/manifests/heading.json +183 -0
- package/manifests/heatmap.json +265 -0
- package/manifests/hover-card.json +172 -0
- package/manifests/icon.json +201 -0
- package/manifests/image-cropper.json +295 -0
- package/manifests/image-viewer.json +198 -0
- package/manifests/image.json +193 -0
- package/manifests/index.json +2035 -0
- package/manifests/input-group.json +3571 -0
- package/manifests/input.json +1557 -0
- package/manifests/kbd.json +98 -0
- package/manifests/language-switcher.json +274 -0
- package/manifests/line-chart.json +342 -0
- package/manifests/link.json +867 -0
- package/manifests/list-box.json +213 -0
- package/manifests/menu.json +453 -0
- package/manifests/meter.json +145 -0
- package/manifests/navbar.json +281 -0
- package/manifests/otp-field.json +1029 -0
- package/manifests/page-header.json +164 -0
- package/manifests/pagination.json +181 -0
- package/manifests/popover.json +205 -0
- package/manifests/pressable.json +367 -0
- package/manifests/progress.json +282 -0
- package/manifests/radar-chart.json +229 -0
- package/manifests/radial-chart.json +195 -0
- package/manifests/radio.json +975 -0
- package/manifests/scatter-chart.json +277 -0
- package/manifests/scroll-area.json +127 -0
- package/manifests/section.json +169 -0
- package/manifests/select.json +474 -0
- package/manifests/separator.json +119 -0
- package/manifests/sidebar.json +584 -0
- package/manifests/skeleton.json +235 -0
- package/manifests/skip-link.json +89 -0
- package/manifests/slider.json +706 -0
- package/manifests/sparkline.json +208 -0
- package/manifests/spinner.json +105 -0
- package/manifests/split.json +6618 -0
- package/manifests/stack.json +3541 -0
- package/manifests/stat.json +192 -0
- package/manifests/stepper.json +279 -0
- package/manifests/switch.json +205 -0
- package/manifests/table.json +375 -0
- package/manifests/tabs.json +438 -0
- package/manifests/tag-group.json +264 -0
- package/manifests/text-area.json +1136 -0
- package/manifests/text.json +244 -0
- package/manifests/theme-switcher.json +152 -0
- package/manifests/time-field.json +284 -0
- package/manifests/timeline.json +196 -0
- package/manifests/toast.json +87 -0
- package/manifests/toggle-button.json +1489 -0
- package/manifests/toolbar.json +145 -0
- package/manifests/tooltip.json +181 -0
- package/manifests/tracker.json +192 -0
- package/manifests/tree.json +245 -0
- package/manifests/visually-hidden.json +114 -0
- package/package.json +117 -3
- package/styles/base.css +56 -0
- package/styles/theme.css +154 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-field.js","sourceRoot":"","sources":["../../src/form/otp-field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,KAAK,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAsB3E;;;;GAIG;AACH;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAY,EAAE,QAAgB,EAAE,MAAc;IAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IACtG,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAkC,SAAS,YAAY,CAC1F,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAA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,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAc,2CAA2C,MAAM,IAAI,CAAC,CAAC;YACtG,IAAI,GAAG;gBAAE,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC;QACF,OAAO,EAAE,CAAC;QACV,IAAI,OAAO,cAAc,KAAK,WAAW;YAAE,OAAO;QAClD,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACrB,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AACpB,CAAC;AAED,+GAA+G;AAC/G,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAA+C,SAAS,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG;IAChI,OAAO,CACL,KAAC,WAAW,IAAC,MAAM,EAAE,MAAM,YACzB,KAAC,YAAY,IAAC,GAAG,EAAE,GAAG,KAAM,KAAK,GAAI,GACzB,CACf,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Input,\n TextField as AriaTextField,\n type TextFieldProps as AriaTextFieldProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../utils\";\nimport { MotionScope, type WithMotion } from \"../defaults\";\nimport { FieldDescription, FieldError, FieldLabel } from \"./field-parts\";\nimport { FIELD_STACK } from \"./styles\";\nimport { useFieldValidation, type RequiredValidation } from \"./validation\";\n\nexport type OtpFieldProps = Omit<\n AriaTextFieldProps,\n \"className\" | \"style\" | \"children\" | \"type\" | \"inputMode\" | \"autoComplete\" | \"maxLength\"\n> & {\n label: React.ReactNode;\n /** 4 or 6 digits; 6 splits 3 + 3 with a dash. */\n length?: 4 | 6;\n description?: React.ReactNode;\n /** Say what to do: \"Wrong code. Enter the latest code from your phone.\" */\n errorMessage?: React.ReactNode;\n /** Called once the last digit is entered (submit there). */\n onComplete?: (code: string) => void;\n /**\n * Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS\n * Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See\n * {@link RequiredValidation} for the whole contract.\n */\n requiredValidation?: RequiredValidation;\n};\n\n/**\n * A one-time code: one real input with `autocomplete=\"one-time-code\"` and a\n * numeric keypad, so SMS autofill and paste fill every box at once; the\n * boxes are only its picture. React Aria has no OTP primitive, so this is a TextField with a visual layer.\n */\n/**\n * The digits to keep from the input's text. The caret is pinned to the end,\n * so a full code pasted or autofilled over an old one arrives appended\n * (\"111111\" + \"222222\"): when a whole code was added, the new one wins.\n */\nfunction takeCode(text: string, previous: string, length: number) {\n const digits = text.replace(/\\D/g, \"\");\n if (digits.length > length && digits.length - previous.length >= length) return digits.slice(-length);\n return digits.slice(0, length);\n}\n\nconst OtpFieldBody = React.forwardRef<HTMLInputElement, OtpFieldProps>(function OtpFieldBody(\n { label, length = 6, description, errorMessage, onComplete, value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? \"\");\n const code = (value ?? uncontrolled).replace(/\\D/g, \"\").slice(0, length);\n const [focused, setFocused] = React.useState(false);\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n\n const setRefs = (node: HTMLInputElement | null) => {\n inputRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n };\n\n const active = Math.min(code.length, length - 1);\n const caret = useCaretOffset(active, length);\n // The last code passed to onComplete: a new full code (pasted over an old one) completes again.\n const completed = React.useRef<string | null>(code.length === length ? code : null);\n const timing = useFieldValidation<string>({\n validate,\n value: value === undefined ? undefined : code,\n initialValue: defaultValue ?? \"\",\n isRequired: rest.isRequired,\n requiredValidation,\n onBlur: onBlur as ((event: React.FocusEvent) => void) | undefined,\n onChange: (digits) => {\n if (value === undefined) setUncontrolled(digits);\n onChange?.(digits);\n if (digits.length === length) {\n if (completed.current !== digits) {\n completed.current = digits;\n onComplete?.(digits);\n }\n } else completed.current = null;\n },\n validationBehavior: rest.validationBehavior,\n });\n const pinCaret = (input: HTMLInputElement) => {\n const end = input.value.length;\n if (input.selectionStart !== end || input.selectionEnd !== end) input.setSelectionRange(end, end);\n };\n return (\n <AriaTextField\n {...rest}\n value={code}\n validationBehavior={timing.validationBehavior}\n validate={timing.validate}\n onBlur={timing.onBlur}\n onChange={(next) => timing.onChange?.(takeCode(next, code, length))}\n data-slot=\"otp-field\"\n className={FIELD_STACK}\n >\n {({ isInvalid, isDisabled }) => (\n <>\n <FieldLabel isRequired={rest.isRequired}>{label}</FieldLabel>\n <div\n data-slot=\"otp-field-boxes\"\n // As wide as its cells, never wider than its column: on a narrow phone the cells shrink instead\n // of pushing the field (and the page) sideways. Codes read left to right in every locale, so the row\n // (cells, separator and the hidden input) stays LTR on an RTL page: \"1234\" never shows as \"4 3 2 1\".\n dir=\"ltr\"\n ref={caret.row}\n className=\"relative flex w-full max-w-fit items-center gap-ds-100\"\n onMouseDown={(event) => {\n event.preventDefault();\n inputRef.current?.focus();\n }}\n >\n <Input\n ref={setRefs}\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n // No maxLength: the browser would cut \"482 917\" to six characters before the digits are picked out.\n pattern=\"\\d*\"\n data-slot=\"otp-field-input\"\n onFocus={(event) => {\n setFocused(true);\n pinCaret(event.currentTarget);\n }}\n // Boxes fill left to right: arrows, Home and clicks never move the caret off the end.\n onSelect={(event) => pinCaret(event.currentTarget)}\n onKeyUp={(event) => pinCaret(event.currentTarget)}\n onBlur={() => setFocused(false)}\n className=\"absolute inset-0 z-10 h-full w-full cursor-text bg-transparent text-transparent caret-transparent outline-hidden selection:bg-transparent\"\n />\n {Array.from({ length }, (_, index) => (\n <React.Fragment key={index}>\n {length === 6 && index === 3 && (\n <span aria-hidden=\"true\" data-slot=\"otp-field-separator\" className=\"h-0.5 w-ds-100 shrink-0 rounded-ds-full bg-ds-border-bold\" />\n )}\n <span\n aria-hidden=\"true\"\n data-slot=\"otp-field-box\"\n data-index={index}\n data-active={focused && index === active ? true : undefined}\n className={cn(\n \"relative inline-flex h-13 w-11 min-w-0 items-center justify-center rounded-ds-medium border bg-ds-background-input\",\n \"transition-[border-color,outline-color] duration-(--ds-duration-fast) motion-reduce:transition-none\",\n \"text-metric-medium tabular-nums text-ds-text\",\n isInvalid ? \"border-ds-border-danger\" : \"border-ds-border-bold\",\n focused && index === active && \"border-ds-border-focused outline-1 outline-solid -outline-offset-2 outline-ds-border-focused\",\n isDisabled && \"border-transparent bg-ds-background-disabled text-ds-text-disabled\",\n )}\n >\n {code[index] !== undefined && (\n // A typed digit pops into its box (no pop under reduced motion).\n <span\n key={code[index]}\n data-slot=\"otp-field-digit\"\n className=\"transition-[scale,opacity] duration-(--ds-duration-fast) ease-ds-enter starting:scale-75 starting:opacity-0 motion-reduce:transition-none\"\n >\n {code[index]}\n </span>\n )}\n </span>\n </React.Fragment>\n ))}\n {/*\n One caret for the row: it slides to the next box as digits arrive and back as they are deleted, and\n blinks while it waits. It stays mounted (hidden when the field is not focused or the code is full),\n so focusing never slides it in from the first box. Under reduced motion it jumps and does not blink.\n */}\n <span\n aria-hidden=\"true\"\n data-slot=\"otp-field-caret\"\n data-index={active}\n data-visible={focused && code.length < length && !isDisabled ? true : undefined}\n style={{ translate: `${caret.x}px -50%` }}\n className={cn(\n \"pointer-events-none absolute start-0 top-1/2 h-5 w-px -ms-px bg-ds-text opacity-0\",\n \"transition-[translate] duration-(--ds-duration-fast) ease-ds-standard motion-reduce:transition-none\",\n \"data-[visible]:opacity-100 data-[visible]:animate-pulse motion-reduce:data-[visible]:animate-none\",\n )}\n />\n </div>\n {description && <FieldDescription>{description}</FieldDescription>}\n <FieldError>{errorMessage}</FieldError>\n </>\n )}\n </AriaTextField>\n );\n});\n\n/**\n * Where the caret goes: the centre of the active box, in px from the row's start (the row is always LTR). Measured\n * after layout and again when the row resizes, since the boxes shrink on a narrow phone.\n */\nfunction useCaretOffset(active: number, length: number) {\n const row = React.useRef<HTMLDivElement | null>(null);\n const [x, setX] = React.useState(0);\n React.useLayoutEffect(() => {\n const element = row.current;\n if (!element) return;\n const measure = () => {\n const box = element.querySelector<HTMLElement>(`[data-slot=\"otp-field-box\"][data-index=\"${active}\"]`);\n if (box) setX(box.offsetLeft + box.offsetWidth / 2);\n };\n measure();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(element);\n return () => observer.disconnect();\n }, [active, length]);\n return { row, x };\n}\n\n/** OtpField with its own `motion` (auto, reduce or none) for the sliding, blinking caret and the digit pop. */\nexport const OtpField = React.forwardRef<HTMLInputElement, OtpFieldProps & WithMotion>(function OtpField({ motion, ...props }, ref) {\n return (\n <MotionScope motion={motion}>\n <OtpFieldBody ref={ref} {...props} />\n </MotionScope>\n );\n});\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type TextFieldProps as AriaTextFieldProps } from "react-aria-components";
|
|
3
|
+
import { type RequiredValidation } from "./validation.js";
|
|
4
|
+
export type PasswordStrength = 0 | 1 | 2 | 3;
|
|
5
|
+
/**
|
|
6
|
+
* A simple, explainable score: 1 weak, 2 fair (8+ characters, two kinds),
|
|
7
|
+
* 3 strong (10+ characters, three kinds of lower, upper, digit, symbol).
|
|
8
|
+
* 0 is an empty value.
|
|
9
|
+
*/
|
|
10
|
+
export declare function passwordStrength(value: string): PasswordStrength;
|
|
11
|
+
export type PasswordFieldProps = Omit<AriaTextFieldProps, "className" | "style" | "children" | "type"> & {
|
|
12
|
+
label: React.ReactNode;
|
|
13
|
+
/** `current-password` to sign in, `new-password` to create or reset. */
|
|
14
|
+
autoComplete: "current-password" | "new-password";
|
|
15
|
+
/** The requirements, stated up front ("At least 10 characters"). */
|
|
16
|
+
description?: React.ReactNode;
|
|
17
|
+
errorMessage?: React.ReactNode;
|
|
18
|
+
/** Four-segment meter with a word under it (create and reset only). */
|
|
19
|
+
showStrength?: boolean;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Controlled visibility: `true` shows the value as text. Leave it out for the
|
|
23
|
+
* default, where the show / hide button alone decides; set it when the app
|
|
24
|
+
* writes a value the person should see (a "Generate" button).
|
|
25
|
+
*/
|
|
26
|
+
isRevealed?: boolean;
|
|
27
|
+
/** Called with the next visibility when the show / hide button is pressed. */
|
|
28
|
+
onRevealChange?: (revealed: boolean) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
31
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
32
|
+
* {@link RequiredValidation} for the whole contract.
|
|
33
|
+
*/
|
|
34
|
+
requiredValidation?: RequiredValidation;
|
|
35
|
+
};
|
|
36
|
+
/** A password with a show / hide toggle; never blocks paste and never clears itself. */
|
|
37
|
+
export declare const PasswordField: React.ForwardRefExoticComponent<Omit<AriaTextFieldProps, "children" | "style" | "type" | "className"> & {
|
|
38
|
+
label: React.ReactNode;
|
|
39
|
+
/** `current-password` to sign in, `new-password` to create or reset. */
|
|
40
|
+
autoComplete: "current-password" | "new-password";
|
|
41
|
+
/** The requirements, stated up front ("At least 10 characters"). */
|
|
42
|
+
description?: React.ReactNode;
|
|
43
|
+
errorMessage?: React.ReactNode;
|
|
44
|
+
/** Four-segment meter with a word under it (create and reset only). */
|
|
45
|
+
showStrength?: boolean;
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Controlled visibility: `true` shows the value as text. Leave it out for the
|
|
49
|
+
* default, where the show / hide button alone decides; set it when the app
|
|
50
|
+
* writes a value the person should see (a "Generate" button).
|
|
51
|
+
*/
|
|
52
|
+
isRevealed?: boolean;
|
|
53
|
+
/** Called with the next visibility when the show / hide button is pressed. */
|
|
54
|
+
onRevealChange?: (revealed: boolean) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
57
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
58
|
+
* {@link RequiredValidation} for the whole contract.
|
|
59
|
+
*/
|
|
60
|
+
requiredValidation?: RequiredValidation;
|
|
61
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Input, TextField as AriaTextField, useLocale } from "react-aria-components";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
import { hidePasswordLabel, showPasswordLabel, strengthLabels } from "../i18n.js";
|
|
7
|
+
import { FieldDescription, FieldError, FieldLabel } from "./field-parts.js";
|
|
8
|
+
import { InputAction, InputGroup } from "./input-group.js";
|
|
9
|
+
import { FIELD_STACK, INPUT } from "./styles.js";
|
|
10
|
+
import { useFieldValidation } from "./validation.js";
|
|
11
|
+
import { splitDataAttributes } from "./data-attributes.js";
|
|
12
|
+
/**
|
|
13
|
+
* A simple, explainable score: 1 weak, 2 fair (8+ characters, two kinds),
|
|
14
|
+
* 3 strong (10+ characters, three kinds of lower, upper, digit, symbol).
|
|
15
|
+
* 0 is an empty value.
|
|
16
|
+
*/
|
|
17
|
+
export function passwordStrength(value) {
|
|
18
|
+
if (!value)
|
|
19
|
+
return 0;
|
|
20
|
+
const kinds = [/\p{Ll}/u, /\p{Lu}/u, /\p{Nd}/u, /[^\p{L}\p{Nd}]/u].filter((pattern) => pattern.test(value)).length;
|
|
21
|
+
if (value.length >= 10 && kinds >= 3)
|
|
22
|
+
return 3;
|
|
23
|
+
if (value.length >= 8 && kinds >= 2)
|
|
24
|
+
return 2;
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
const FILLED = { 1: 2, 2: 3, 3: 4 };
|
|
28
|
+
/** A password with a show / hide toggle; never blocks paste and never clears itself. */
|
|
29
|
+
export const PasswordField = React.forwardRef(function PasswordField({ label, description, errorMessage, showStrength, autoComplete, placeholder, isRevealed, onRevealChange, value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest }, ref) {
|
|
30
|
+
const { locale } = useLocale();
|
|
31
|
+
const [ownVisible, setOwnVisible] = React.useState(false);
|
|
32
|
+
const visible = isRevealed ?? ownVisible;
|
|
33
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? "");
|
|
34
|
+
const text = value ?? uncontrolled;
|
|
35
|
+
const score = passwordStrength(text);
|
|
36
|
+
const words = strengthLabels(locale);
|
|
37
|
+
const timing = useFieldValidation({
|
|
38
|
+
validate,
|
|
39
|
+
value: value,
|
|
40
|
+
initialValue: value ?? defaultValue ?? "",
|
|
41
|
+
isRequired: rest.isRequired,
|
|
42
|
+
requiredValidation,
|
|
43
|
+
onBlur: onBlur,
|
|
44
|
+
onChange,
|
|
45
|
+
validationBehavior: rest.validationBehavior,
|
|
46
|
+
});
|
|
47
|
+
const { wrapperProps, controlData } = splitDataAttributes(rest);
|
|
48
|
+
return (_jsx(AriaTextField, { ...wrapperProps, value: text, onChange: (next) => {
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
setUncontrolled(next);
|
|
51
|
+
timing.onChange?.(next);
|
|
52
|
+
}, validationBehavior: timing.validationBehavior, validate: timing.validate, onBlur: timing.onBlur, type: visible ? "text" : "password", autoComplete: autoComplete, "data-slot": "password-field", className: FIELD_STACK, children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { isRequired: rest.isRequired, children: label }), _jsxs(InputGroup, { isDisabled: isDisabled, isInvalid: isInvalid, children: [_jsx(Input, { ...controlData, ref: ref, placeholder: placeholder, "data-slot": "password-field-input", className: cn(INPUT, "text-body") }), _jsx(InputAction, { icon: visible ? "eye-off" : "eye", "aria-label": visible ? hidePasswordLabel(locale) : showPasswordLabel(locale), onPress: () => {
|
|
53
|
+
if (isRevealed === undefined)
|
|
54
|
+
setOwnVisible(!visible);
|
|
55
|
+
onRevealChange?.(!visible);
|
|
56
|
+
}, isDisabled: isDisabled })] }), description && _jsx(FieldDescription, { children: description }), showStrength && (_jsxs("div", { "data-slot": "password-strength", className: "flex flex-col gap-ds-050", children: [score > 0 && (
|
|
57
|
+
// Slides in as the first character is typed; segments fill with a colour transition (still under
|
|
58
|
+
// reduced motion: no movement).
|
|
59
|
+
_jsx("div", { "aria-hidden": "true", "data-slot": "password-strength-meter", className: "grid grid-cols-4 gap-ds-050 transition-[translate,opacity] duration-(--ds-duration-medium) ease-ds-enter starting:-translate-y-1 starting:opacity-0 motion-reduce:transition-none", children: [0, 1, 2, 3].map((index) => (_jsx("span", { "data-filled": index < FILLED[score] || undefined, className: cn("h-1 rounded-ds-full bg-ds-background-neutral transition-colors duration-(--ds-duration-medium) motion-reduce:transition-none", index < FILLED[score] && (score === 3 ? "bg-ds-icon-success" : "bg-ds-icon-warning")) }, index))) })), _jsx("span", { "aria-live": "polite", "data-slot": "password-strength-label", className: cn("text-body-small", score === 3 ? "text-ds-text-success" : "text-ds-text-warning"), children: score > 0 ? words[score - 1] : "" })] })), _jsx(FieldError, { children: errorMessage })] })) }));
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=password-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-field.js","sourceRoot":"","sources":["../../src/form/password-field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B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R,yBAAyB,EACnC,SAAS,EAAC,mLAAmL,YAE5L,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAC3B,8BAEe,KAAK,GAAG,MAAM,CAAC,KAAkB,CAAC,IAAI,SAAS,EAC5D,SAAS,EAAE,EAAE,CACX,8HAA8H,EAC9H,KAAK,GAAG,MAAM,CAAC,KAAkB,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAClG,IALI,KAAK,CAMV,CACH,CAAC,GACE,CACP,EAED,4BACY,QAAQ,eACR,yBAAyB,EACnC,SAAS,EAAE,EAAE,CAAC,iBAAiB,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,sBAAsB,CAAC,YAE9F,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAC7B,IACH,CACP,EACD,KAAC,UAAU,cAAE,YAAY,GAAc,IACtC,CACJ,GACa,CACjB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Input, TextField as AriaTextField, useLocale, type TextFieldProps as AriaTextFieldProps } from \"react-aria-components\";\n\nimport { cn } from \"../utils\";\nimport { hidePasswordLabel, showPasswordLabel, strengthLabels } from \"../i18n\";\nimport { FieldDescription, FieldError, FieldLabel } from \"./field-parts\";\nimport { InputAction, InputGroup } from \"./input-group\";\nimport { FIELD_STACK, INPUT } from \"./styles\";\nimport { useFieldValidation, type RequiredValidation } from \"./validation\";\nimport { splitDataAttributes } from \"./data-attributes\";\n\nexport type PasswordStrength = 0 | 1 | 2 | 3;\n\n/**\n * A simple, explainable score: 1 weak, 2 fair (8+ characters, two kinds),\n * 3 strong (10+ characters, three kinds of lower, upper, digit, symbol).\n * 0 is an empty value.\n */\nexport function passwordStrength(value: string): PasswordStrength {\n if (!value) return 0;\n const kinds = [/\\p{Ll}/u, /\\p{Lu}/u, /\\p{Nd}/u, /[^\\p{L}\\p{Nd}]/u].filter((pattern) => pattern.test(value)).length;\n if (value.length >= 10 && kinds >= 3) return 3;\n if (value.length >= 8 && kinds >= 2) return 2;\n return 1;\n}\n\nconst FILLED = { 1: 2, 2: 3, 3: 4 } as const;\n\nexport type PasswordFieldProps = Omit<AriaTextFieldProps, \"className\" | \"style\" | \"children\" | \"type\"> & {\n label: React.ReactNode;\n /** `current-password` to sign in, `new-password` to create or reset. */\n autoComplete: \"current-password\" | \"new-password\";\n /** The requirements, stated up front (\"At least 10 characters\"). */\n description?: React.ReactNode;\n errorMessage?: React.ReactNode;\n /** Four-segment meter with a word under it (create and reset only). */\n showStrength?: boolean;\n placeholder?: string;\n /**\n * Controlled visibility: `true` shows the value as text. Leave it out for the\n * default, where the show / hide button alone decides; set it when the app\n * writes a value the person should see (a \"Generate\" button).\n */\n isRevealed?: boolean;\n /** Called with the next visibility when the show / hide button is pressed. */\n onRevealChange?: (revealed: boolean) => void;\n /**\n * Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS\n * Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See\n * {@link RequiredValidation} for the whole contract.\n */\n requiredValidation?: RequiredValidation;\n};\n\n/** A password with a show / hide toggle; never blocks paste and never clears itself. */\nexport const PasswordField = React.forwardRef<HTMLInputElement, PasswordFieldProps>(function PasswordField(\n {\n label, description, errorMessage, showStrength, autoComplete, placeholder, isRevealed, onRevealChange,\n value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest\n },\n ref,\n) {\n const { locale } = useLocale();\n const [ownVisible, setOwnVisible] = React.useState(false);\n const visible = isRevealed ?? ownVisible;\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? \"\");\n const text = value ?? uncontrolled;\n const score = passwordStrength(text);\n const words = strengthLabels(locale);\n const timing = useFieldValidation({\n validate,\n value: value,\n initialValue: value ?? defaultValue ?? \"\",\n isRequired: rest.isRequired,\n requiredValidation,\n onBlur: onBlur as ((event: React.FocusEvent) => void) | undefined,\n onChange,\n validationBehavior: rest.validationBehavior,\n });\n\n const { wrapperProps, controlData } = splitDataAttributes(rest);\n return (\n <AriaTextField\n {...wrapperProps}\n value={text}\n onChange={(next) => {\n if (value === undefined) setUncontrolled(next);\n timing.onChange?.(next);\n }}\n validationBehavior={timing.validationBehavior}\n validate={timing.validate}\n onBlur={timing.onBlur}\n type={visible ? \"text\" : \"password\"}\n autoComplete={autoComplete}\n data-slot=\"password-field\"\n className={FIELD_STACK}\n >\n {({ isInvalid, isDisabled }) => (\n <>\n <FieldLabel isRequired={rest.isRequired}>{label}</FieldLabel>\n <InputGroup isDisabled={isDisabled} isInvalid={isInvalid}>\n <Input {...controlData} ref={ref} placeholder={placeholder} data-slot=\"password-field-input\" className={cn(INPUT, \"text-body\")} />\n <InputAction\n icon={visible ? \"eye-off\" : \"eye\"}\n aria-label={visible ? hidePasswordLabel(locale) : showPasswordLabel(locale)}\n onPress={() => {\n if (isRevealed === undefined) setOwnVisible(!visible);\n onRevealChange?.(!visible);\n }}\n isDisabled={isDisabled}\n />\n </InputGroup>\n {description && <FieldDescription>{description}</FieldDescription>}\n {showStrength && (\n <div data-slot=\"password-strength\" className=\"flex flex-col gap-ds-050\">\n {score > 0 && (\n // Slides in as the first character is typed; segments fill with a colour transition (still under\n // reduced motion: no movement).\n <div\n aria-hidden=\"true\"\n data-slot=\"password-strength-meter\"\n className=\"grid grid-cols-4 gap-ds-050 transition-[translate,opacity] duration-(--ds-duration-medium) ease-ds-enter starting:-translate-y-1 starting:opacity-0 motion-reduce:transition-none\"\n >\n {[0, 1, 2, 3].map((index) => (\n <span\n key={index}\n data-filled={index < FILLED[score as 1 | 2 | 3] || undefined}\n className={cn(\n \"h-1 rounded-ds-full bg-ds-background-neutral transition-colors duration-(--ds-duration-medium) motion-reduce:transition-none\",\n index < FILLED[score as 1 | 2 | 3] && (score === 3 ? \"bg-ds-icon-success\" : \"bg-ds-icon-warning\"),\n )}\n />\n ))}\n </div>\n )}\n {/* Mounted empty so the first word is announced too. */}\n <span\n aria-live=\"polite\"\n data-slot=\"password-strength-label\"\n className={cn(\"text-body-small\", score === 3 ? \"text-ds-text-success\" : \"text-ds-text-warning\")}\n >\n {score > 0 ? words[score - 1] : \"\"}\n </span>\n </div>\n )}\n <FieldError>{errorMessage}</FieldError>\n </>\n )}\n </AriaTextField>\n );\n});\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type FieldSize } from "./styles.js";
|
|
3
|
+
import { type RequiredValidation } from "./validation.js";
|
|
4
|
+
export type PhoneFieldProps = {
|
|
5
|
+
/**
|
|
6
|
+
* The visible label above the field. Leave it out only where something else names the number: a non-empty `aria-label`, `aria-labelledby`, or a form row's `<label htmlFor={id}>`. Inside
|
|
7
|
+
* the DS `Field`, which gives its control the id, the Field's label is then the field's only label and its name
|
|
8
|
+
* (`aria-labelledby` its `{id}-label`). A development warning says so when nothing names it.
|
|
9
|
+
*/
|
|
10
|
+
label?: React.ReactNode;
|
|
11
|
+
/** Names the number where no visible label is shown (a table cell, a context that already says it). */
|
|
12
|
+
"aria-label"?: string;
|
|
13
|
+
/** Ids of the elements that name the number, where no visible label of its own is shown. */
|
|
14
|
+
"aria-labelledby"?: string;
|
|
15
|
+
/** The number in E.164 ("+38267123456"), or "" when empty. Controlled with `onChange`. */
|
|
16
|
+
value?: string;
|
|
17
|
+
defaultValue?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The new E.164 value and the ISO country, together: an empty number still carries the chosen country,
|
|
20
|
+
* so a form can keep both (the old shared field's contract, unchanged).
|
|
21
|
+
*/
|
|
22
|
+
onChange?: (value: string, country: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Controlled ISO country. Left out, it is read from the value, then `defaultCountry`. A shared calling
|
|
25
|
+
* code reads back as the table's first country for it (+1 → US): pass `country` to keep Canada.
|
|
26
|
+
*/
|
|
27
|
+
country?: string;
|
|
28
|
+
/** The country an empty field opens on; by default the locale's region ("de-AT" → AT, "en" → US). */
|
|
29
|
+
defaultCountry?: string;
|
|
30
|
+
/** ISO codes shown first, above "All countries" (the markets this form expects). */
|
|
31
|
+
suggestedCountries?: readonly string[];
|
|
32
|
+
description?: React.ReactNode;
|
|
33
|
+
/** What happened and what to do. Wins over the field's own required and length checks. */
|
|
34
|
+
errorMessage?: React.ReactNode;
|
|
35
|
+
isInvalid?: boolean;
|
|
36
|
+
isRequired?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Who says an empty required PhoneField is missing: `field` (default) shows "Fill in this field."
|
|
39
|
+
* on blur and on a DS Form submit, which it then blocks, inside a DS Form of either `validationBehavior`; `app`
|
|
40
|
+
* only marks the field. Outside a DS Form an empty value shows nothing either way. The app's `isInvalid` (or
|
|
41
|
+
* `errorMessage`) wins over this message, and `isInvalid={false}` turns the check off. A disabled, empty, required
|
|
42
|
+
* field still blocks a DS Form's submit and cannot take focus. See {@link RequiredValidation}.
|
|
43
|
+
*/
|
|
44
|
+
requiredValidation?: RequiredValidation;
|
|
45
|
+
isDisabled?: boolean;
|
|
46
|
+
isReadOnly?: boolean;
|
|
47
|
+
/** Shows "(optional)" when most of the form is required. */
|
|
48
|
+
isOptional?: boolean;
|
|
49
|
+
/** Submits the E.164 value under this name in a native form. */
|
|
50
|
+
name?: string;
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
autoFocus?: boolean;
|
|
53
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
54
|
+
size?: FieldSize;
|
|
55
|
+
/** A pasted international number whose country is not offered; the value stays unchanged. */
|
|
56
|
+
onUnsupportedInternationalPaste?: (pasted: string) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The number input's id: an app's `<label htmlFor>` and a focus-on-error reach the input, the
|
|
59
|
+
* element that takes typing. The shared `Field` hands its control one. Left out, React Aria's own id stays.
|
|
60
|
+
*/
|
|
61
|
+
id?: string;
|
|
62
|
+
/** Ids of text outside the field that describes the number (a form row's hint or error), added to its own. */
|
|
63
|
+
"aria-describedby"?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Set by a form row that owns the error text (the shared `Field` hands its control `aria-invalid`): the number is
|
|
66
|
+
* marked invalid for assistive tech and drawn invalid, as with `isInvalid`; the row's message is the one shown,
|
|
67
|
+
* since the field draws an error row only for its own `errorMessage` or length check. This field never uses
|
|
68
|
+
* native validity, so it never blocks a form's submit.
|
|
69
|
+
*/
|
|
70
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
71
|
+
/**
|
|
72
|
+
* The field's words, already localized; the DS strings in the provider locale by default:
|
|
73
|
+
* - `country`: the country button's name, from the country's name and calling code ("Country: Germany, +49");
|
|
74
|
+
* - `countryList`: the country list's name, also its popover's ("Country");
|
|
75
|
+
* - `countrySearch`: the country search box's name ("Search countries");
|
|
76
|
+
* - `countryEmpty`: the list's empty result for the typed search ("No results for “{query}”.");
|
|
77
|
+
* - `suggestedCountries`: the first section's name, the `suggestedCountries` ("Suggested countries");
|
|
78
|
+
* - `allCountries`: the header above the rest when suggestions show ("All countries").
|
|
79
|
+
*/
|
|
80
|
+
labels?: {
|
|
81
|
+
country?: (country: string, callingCode: string) => string;
|
|
82
|
+
countryList?: string;
|
|
83
|
+
countrySearch?: string;
|
|
84
|
+
countryEmpty?: (query: string) => React.ReactNode;
|
|
85
|
+
suggestedCountries?: string;
|
|
86
|
+
allCountries?: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* `data-*` attributes: `data-testid` on the field's wrapper, as on TextField; every other one on the
|
|
90
|
+
* number input, where password managers and autofill read theirs (`data-1p-ignore`, `data-lpignore`).
|
|
91
|
+
*/
|
|
92
|
+
[data: `data-${string}`]: string | number | boolean | undefined;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* A phone number as a country picker plus the national number, given to the form as one E.164 value.
|
|
96
|
+
* The country button shows the ISO chip and the calling code; its list is a searchable menu exactly as
|
|
97
|
+
* wide as the whole field (localized name, English name, ISO code or calling code, diacritics folded),
|
|
98
|
+
* suggested countries first. The number groups as it is typed and pasting an international number
|
|
99
|
+
* switches the country. Label, description and error belong to the number input, also inside a
|
|
100
|
+
* Dialog or Drawer; inside the DS `Field`, leave `label` out and the Field's label names it. Typing, pasting and switching the country stop the number at the country's
|
|
101
|
+
* longest length; a number too short is said on blur, with
|
|
102
|
+
* what to do. An over-long number set from outside (a stored one) is kept as it is until it is edited.
|
|
103
|
+
*/
|
|
104
|
+
export declare const PhoneField: React.ForwardRefExoticComponent<PhoneFieldProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Autocomplete, Button as AriaButton, Dialog, DialogTrigger, Header, Input, ListBox, ListBoxItem, ListBoxSection, Popover, SearchField as AriaSearchField, Text, TextField as AriaTextField, useLocale, } from "react-aria-components";
|
|
5
|
+
import { IconGlyph } from "../display/icon.js";
|
|
6
|
+
import { IsoChipMark } from "../display/iso-chip.js";
|
|
7
|
+
import { cn } from "../utils.js";
|
|
8
|
+
import { useFieldSize } from "../defaults.js";
|
|
9
|
+
import { COUNTRIES } from "./countries.js";
|
|
10
|
+
import { internationalPasteDigits, stripTrunkPrefix } from "./phone-paste.js";
|
|
11
|
+
import { caretAfterDigits, digitCountBefore, digitIndexForSeparatorKey, digitsOf, findCountry, localeCountry, formatNational, parsePhone, PHONE_COUNTRIES, toE164, } from "./phone.js";
|
|
12
|
+
import { regionNames } from "../intl-locale.js";
|
|
13
|
+
import { intlLocale, noMatchLabel, phoneAllCountriesLabel, phoneCountryLabel, phoneCountryListLabel, phoneCountrySearchLabel, phoneSuggestedCountriesLabel, phoneTooLongLabel, phoneTooShortLabel, } from "../i18n.js";
|
|
14
|
+
import { Highlight, matchesQuery } from "../selection/match.js";
|
|
15
|
+
import { LISTBOX, OPTION, POPOVER } from "../selection/listbox.js";
|
|
16
|
+
import { FieldDescription, FieldError, FieldLabel, isAriaInvalid, useErrorRowLink, useFieldName } from "./field-parts.js";
|
|
17
|
+
import { InputGroup } from "./input-group.js";
|
|
18
|
+
import { FIELD_ICON, FIELD_SIZE, FIELD_STACK, FIELD_FRAME, INPUT } from "./styles.js";
|
|
19
|
+
import { splitDataAttributes } from "./data-attributes.js";
|
|
20
|
+
import { FormSubmittedContext, useRequiredChoice } from "./validation.js";
|
|
21
|
+
/** Every country with a calling code, named and sorted in the locale (one formatter for the whole list). */
|
|
22
|
+
function useCountryOptions(locale) {
|
|
23
|
+
return React.useMemo(() => {
|
|
24
|
+
const tag = intlLocale(locale);
|
|
25
|
+
const names = regionNames(tag);
|
|
26
|
+
let collator;
|
|
27
|
+
try {
|
|
28
|
+
collator = new Intl.Collator(tag);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
collator = new Intl.Collator();
|
|
32
|
+
}
|
|
33
|
+
return COUNTRIES.flatMap((country) => {
|
|
34
|
+
const shape = findCountry(country.code);
|
|
35
|
+
return shape ? [{ iso: country.code, dial: shape.dial, name: names(country.code) ?? country.name, english: country.name }] : [];
|
|
36
|
+
}).sort((a, b) => collator.compare(a.name, b.name));
|
|
37
|
+
}, [locale]);
|
|
38
|
+
}
|
|
39
|
+
/** The two-letter ISO code as a chip: the design never shows an emoji flag, nor a color alone (display's IsoChip). */
|
|
40
|
+
function IsoChip({ iso }) {
|
|
41
|
+
return _jsx(IsoChipMark, { code: iso, slot: "phone-field-iso" });
|
|
42
|
+
}
|
|
43
|
+
/** "+382", kept in that order in RTL. */
|
|
44
|
+
function CallingCode({ dial }) {
|
|
45
|
+
return (_jsxs("span", { dir: "ltr", "data-slot": "phone-field-code", className: "tabular-nums text-ds-text-subtle", children: ["+", dial] }));
|
|
46
|
+
}
|
|
47
|
+
/** The national number's length, as the error says it: "10" or "8–9". */
|
|
48
|
+
const digitsText = (shape) => (shape.min === shape.max ? String(shape.min) : `${shape.min}–${shape.max}`);
|
|
49
|
+
const COUNTRY_BUTTON = "-ms-(--field-pad) flex shrink-0 cursor-pointer items-center gap-ds-075 self-stretch rounded-s-[max(0px,calc(var(--ds-field-radius,var(--ds-radius-medium))-1px))] border-e border-ds-border px-ds-100 text-body outline-hidden " +
|
|
50
|
+
"data-[hovered]:bg-ds-background-neutral-subtle-hovered data-[pressed]:bg-ds-background-neutral-pressed " +
|
|
51
|
+
"data-[focus-visible]:inset-ring-2 data-[focus-visible]:inset-ring-ds-border-focused " +
|
|
52
|
+
"data-[disabled]:cursor-not-allowed";
|
|
53
|
+
/**
|
|
54
|
+
* A phone number as a country picker plus the national number, given to the form as one E.164 value.
|
|
55
|
+
* The country button shows the ISO chip and the calling code; its list is a searchable menu exactly as
|
|
56
|
+
* wide as the whole field (localized name, English name, ISO code or calling code, diacritics folded),
|
|
57
|
+
* suggested countries first. The number groups as it is typed and pasting an international number
|
|
58
|
+
* switches the country. Label, description and error belong to the number input, also inside a
|
|
59
|
+
* Dialog or Drawer; inside the DS `Field`, leave `label` out and the Field's label names it. Typing, pasting and switching the country stop the number at the country's
|
|
60
|
+
* longest length; a number too short is said on blur, with
|
|
61
|
+
* what to do. An over-long number set from outside (a stored one) is kept as it is until it is edited.
|
|
62
|
+
*/
|
|
63
|
+
export const PhoneField = React.forwardRef(function PhoneField({ label, value: valueProp, defaultValue, onChange, country: countryProp, defaultCountry: defaultCountryProp, suggestedCountries = [], description, errorMessage, isInvalid: isInvalidProp, isRequired, requiredValidation, isDisabled, isReadOnly, isOptional, name, placeholder, autoFocus, onBlur, size: fieldSize, onUnsupportedInternationalPaste, id, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, labels, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...data }, forwardedRef) {
|
|
64
|
+
const size = useFieldSize(fieldSize);
|
|
65
|
+
const { wrapperProps: wrapperData, controlData } = splitDataAttributes(data);
|
|
66
|
+
const { locale } = useLocale();
|
|
67
|
+
const defaultCountry = defaultCountryProp ?? localeCountry(locale);
|
|
68
|
+
const options = useCountryOptions(locale);
|
|
69
|
+
const byIso = React.useMemo(() => new Map(options.map((option) => [option.iso, option])), [options]);
|
|
70
|
+
// Value and country: controlled when given, otherwise owned here. The country of a stored number is read from it.
|
|
71
|
+
const [ownValue, setOwnValue] = React.useState(defaultValue ?? "");
|
|
72
|
+
const value = valueProp ?? ownValue;
|
|
73
|
+
const [ownCountry, setOwnCountry] = React.useState(() => parsePhone(valueProp ?? defaultValue ?? "").country?.iso ?? defaultCountry);
|
|
74
|
+
let country = countryProp ?? ownCountry;
|
|
75
|
+
const digits = digitsOf(value);
|
|
76
|
+
const known = findCountry(country);
|
|
77
|
+
// A value set from outside with another country's code moves an uncontrolled picker to it.
|
|
78
|
+
if (countryProp === undefined && value.startsWith("+") && known && !digits.startsWith(known.dial)) {
|
|
79
|
+
const inferred = parsePhone(value).country?.iso;
|
|
80
|
+
if (inferred && inferred !== ownCountry) {
|
|
81
|
+
setOwnCountry(inferred);
|
|
82
|
+
country = inferred;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const shape = findCountry(country) ?? findCountry(defaultCountry) ?? findCountry(localeCountry(locale)) ?? findCountry("US");
|
|
86
|
+
const national = value.startsWith("+") && digits.startsWith(shape.dial) ? digits.slice(shape.dial.length) : digits;
|
|
87
|
+
const display = formatNational(national, shape);
|
|
88
|
+
const countryName = byIso.get(shape.iso)?.name ?? shape.iso;
|
|
89
|
+
// The caret stays after the same digit while spaces come and go.
|
|
90
|
+
const inputRef = React.useRef(null);
|
|
91
|
+
React.useImperativeHandle(forwardedRef, () => inputRef.current, []);
|
|
92
|
+
// Named by its own label, or from outside (aria-label, aria-labelledby, a form row's label for its id) with no
|
|
93
|
+
// label of its own: one label and one name either way. With a `label` the DOM is as before.
|
|
94
|
+
const { named, showLabel, externalNameProps } = useFieldName("PhoneField", label, ariaLabel, ariaLabelledBy, id, inputRef);
|
|
95
|
+
const caret = React.useRef(null);
|
|
96
|
+
const [revision, setRevision] = React.useState(0);
|
|
97
|
+
React.useLayoutEffect(() => {
|
|
98
|
+
if (caret.current === null || !inputRef.current || document.activeElement !== inputRef.current)
|
|
99
|
+
return;
|
|
100
|
+
const position = caretAfterDigits(display, caret.current);
|
|
101
|
+
inputRef.current.setSelectionRange(position, position);
|
|
102
|
+
caret.current = null;
|
|
103
|
+
}, [display, revision]);
|
|
104
|
+
// The length check runs on blur, never per keystroke: typing can only clear an error (and a country switch
|
|
105
|
+
// re-words it for the new country), a new one waits for the next blur. A value set from outside (a form
|
|
106
|
+
// reset, a loaded draft) is unchecked again until then. Edits never make a number too long (see `emit`), so
|
|
107
|
+
// "too long" is only ever said of a number set from outside.
|
|
108
|
+
const [checked, setChecked] = React.useState(false);
|
|
109
|
+
const emitted = React.useRef(value);
|
|
110
|
+
React.useEffect(() => {
|
|
111
|
+
if (value !== emitted.current) {
|
|
112
|
+
emitted.current = value;
|
|
113
|
+
setChecked(false);
|
|
114
|
+
}
|
|
115
|
+
}, [value]);
|
|
116
|
+
const check = (nationalDigits, of) => {
|
|
117
|
+
if (!nationalDigits)
|
|
118
|
+
return null;
|
|
119
|
+
const name = byIso.get(of.iso)?.name ?? of.iso;
|
|
120
|
+
if (nationalDigits.length < of.min)
|
|
121
|
+
return phoneTooShortLabel(locale, name, digitsText(of));
|
|
122
|
+
if (nationalDigits.length > of.max)
|
|
123
|
+
return phoneTooLongLabel(locale, name, digitsText(of));
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
126
|
+
const emit = (typedNational, iso, digitPosition) => {
|
|
127
|
+
const nextShape = findCountry(iso) ?? shape;
|
|
128
|
+
// A number typed or pasted with the country's trunk prefix ("068 555 444" for Montenegro) loses it, and only
|
|
129
|
+
// that recorded prefix: never for a country with none (Italy's 06 stays) or one not known (./phone-paste). The caret stays after the same digit.
|
|
130
|
+
const unprefixed = stripTrunkPrefix(typedNational, nextShape);
|
|
131
|
+
const removed = typedNational.length - unprefixed.length;
|
|
132
|
+
// Every edit (typing, a paste, a country switch) stops at the country's longest number: the digits past it
|
|
133
|
+
// are dropped as they come, so no "too long" is left for blur.
|
|
134
|
+
const nextNational = unprefixed.slice(0, nextShape.max);
|
|
135
|
+
const next = toE164(nextNational, nextShape);
|
|
136
|
+
caret.current = Math.min(Math.max(0, digitPosition - removed), nextNational.length);
|
|
137
|
+
setRevision((n) => n + 1);
|
|
138
|
+
if (valueProp === undefined)
|
|
139
|
+
setOwnValue(next);
|
|
140
|
+
if (countryProp === undefined)
|
|
141
|
+
setOwnCountry(nextShape.iso);
|
|
142
|
+
emitted.current = next;
|
|
143
|
+
// Typing clears a shown error once the number is right; it never raises one before the next blur.
|
|
144
|
+
if (checked && !check(nextNational, nextShape))
|
|
145
|
+
setChecked(false);
|
|
146
|
+
onChange?.(next, nextShape.iso);
|
|
147
|
+
};
|
|
148
|
+
// While an input method composes (a CJK or some Android keyboards), the text is left as typed: reformatting it
|
|
149
|
+
// mid-composition would break the composition. When it ends, the composed text is taken as one edit.
|
|
150
|
+
const composing = React.useRef(false);
|
|
151
|
+
const [composed, setComposed] = React.useState(null);
|
|
152
|
+
const lengthError = checked ? check(national, shape) : null;
|
|
153
|
+
// React Aria never finds an empty required field missing under `aria` validation (which this field always uses
|
|
154
|
+
// with React Aria); the DS does, as TextField does, inside a DS Form of either behaviour, since the
|
|
155
|
+
// browser never sees this field's required. Outside a DS Form nothing is shown for an empty value, as before.
|
|
156
|
+
// The app's error (`isInvalid`, or an `errorMessage`, which makes this field invalid) owns the field and its
|
|
157
|
+
// message wins; `isInvalid={false}` turns the required check off. A number too short or too long is not empty,
|
|
158
|
+
// so the required and length checks never meet.
|
|
159
|
+
const { inForm } = React.useContext(FormSubmittedContext);
|
|
160
|
+
const required = useRequiredChoice({
|
|
161
|
+
filled: national !== "", isRequired, requiredValidation, isInvalid: isInvalidProp ?? (errorMessage ? true : undefined), errorMessage,
|
|
162
|
+
validationBehavior: inForm ? "aria" : "native",
|
|
163
|
+
});
|
|
164
|
+
const shownError = required.errorMessage ?? lengthError;
|
|
165
|
+
// A Form's server errors for `name` are React Aria's, as in every DS field: shown until the number is
|
|
166
|
+
// edited, shown again by the next submit. Only this field's own reasons force the invalid state.
|
|
167
|
+
const isInvalid = Boolean(isInvalidProp || required.isInvalid || errorMessage || lengthError || isAriaInvalid(ariaInvalid));
|
|
168
|
+
const errorRowLink = useErrorRowLink(isAriaInvalid(ariaInvalid), shownError);
|
|
169
|
+
// The country menu: anchored to the whole field and exactly as wide.
|
|
170
|
+
const frameRef = React.useRef(null);
|
|
171
|
+
const [isOpen, setOpen] = React.useState(false);
|
|
172
|
+
const [query, setQuery] = React.useState("");
|
|
173
|
+
const suggested = suggestedCountries.flatMap((iso) => byIso.get(iso) ?? []);
|
|
174
|
+
const rest = options.filter((option) => !suggestedCountries.includes(option.iso));
|
|
175
|
+
const searchText = (option) => [option.name, option.english, option.iso, option.dial, `+${option.dial}`];
|
|
176
|
+
const matches = (option) => matchesQuery(query, ...searchText(option));
|
|
177
|
+
const shownSuggested = suggested.filter(matches);
|
|
178
|
+
const shownRest = rest.filter(matches);
|
|
179
|
+
const choose = (key) => {
|
|
180
|
+
const iso = String(key);
|
|
181
|
+
setOpen(false);
|
|
182
|
+
setQuery("");
|
|
183
|
+
if (iso !== shape.iso)
|
|
184
|
+
emit(national, iso, national.length);
|
|
185
|
+
};
|
|
186
|
+
const option = (item) => (_jsx(ListBoxItem, { id: item.iso, textValue: item.name, "data-slot": "phone-field-option", className: OPTION, children: ({ isSelected }) => (_jsxs(_Fragment, { children: [_jsx(IsoChip, { iso: item.iso }), _jsx(Text, { slot: "label", className: "min-w-0 flex-1 truncate", children: _jsx(Highlight, { text: item.name, query: query }) }), _jsx("span", { className: "shrink-0 text-body-small text-ds-text-subtlest", children: _jsx(CallingCode, { dial: item.dial }) }), isSelected && _jsx(IconGlyph, { name: "check", color: "brand", "data-slot": "phone-field-option-check" })] })) }, item.iso));
|
|
187
|
+
const sectionHeader = "px-ds-100 pt-ds-100 pb-ds-050 text-body-small font-medium text-ds-text-subtle";
|
|
188
|
+
const countryLabelProp = labels?.country;
|
|
189
|
+
const countryListLabel = labels?.countryList;
|
|
190
|
+
const countrySearchLabel = labels?.countrySearch;
|
|
191
|
+
const countryEmptyMessage = labels?.countryEmpty;
|
|
192
|
+
const suggestedCountriesLabel = labels?.suggestedCountries;
|
|
193
|
+
const allCountriesLabel = labels?.allCountries;
|
|
194
|
+
const countryLabel = countryLabelProp ? countryLabelProp(countryName, `+${shape.dial}`) : phoneCountryLabel(locale, countryName, `+${shape.dial}`);
|
|
195
|
+
const listLabel = countryListLabel ?? phoneCountryListLabel(locale);
|
|
196
|
+
const locked = isDisabled || isReadOnly;
|
|
197
|
+
return (_jsxs(AriaTextField, { ...wrapperData, ...(id !== undefined ? { id } : null), ...(ariaDescribedBy ? { "aria-describedby": ariaDescribedBy } : null), ...(named !== undefined ? { "aria-label": named } : null), ...(ariaLabelledBy ? { "aria-labelledby": ariaLabelledBy } : null), ...externalNameProps, ...errorRowLink, value: composed ?? display, onChange: (typed) => {
|
|
198
|
+
if (composing.current) {
|
|
199
|
+
setComposed(typed);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const position = inputRef.current?.selectionStart ?? typed.length;
|
|
203
|
+
emit(digitsOf(typed), shape.iso, digitCountBefore(typed, position));
|
|
204
|
+
}, onBlur: (event) => {
|
|
205
|
+
// Only an error found on blur is shown; a right number leaves nothing for typing to raise later.
|
|
206
|
+
setChecked(Boolean(check(national, shape)));
|
|
207
|
+
required.onBlur?.(event);
|
|
208
|
+
onBlur?.(event);
|
|
209
|
+
}, isInvalid: isInvalid || undefined, name: name, isRequired: isRequired, isDisabled: isDisabled, isReadOnly: isReadOnly, autoFocus: autoFocus,
|
|
210
|
+
// React Aria's own check stays out of the way: this field says what is wrong on blur.
|
|
211
|
+
validationBehavior: "aria", "data-slot": "phone-field", className: FIELD_STACK, children: [showLabel && label != null && (_jsx(FieldLabel, { isRequired: isRequired, isOptional: isOptional, children: label })), _jsx("div", { ref: frameRef, "data-slot": "phone-field-frame", children: _jsxs(InputGroup, { size: size, isDisabled: isDisabled, isInvalid: isInvalid, children: [locked ? (_jsxs("span", { "data-slot": "phone-field-country", "aria-label": countryLabel, role: "img", className: cn(COUNTRY_BUTTON, "cursor-default"), children: [_jsx(IsoChip, { iso: shape.iso }), _jsx(CallingCode, { dial: shape.dial })] })) : (_jsxs(DialogTrigger, { isOpen: isOpen, onOpenChange: (open) => {
|
|
212
|
+
setOpen(open);
|
|
213
|
+
if (!open)
|
|
214
|
+
setQuery("");
|
|
215
|
+
}, children: [_jsxs(AriaButton, { "aria-label": countryLabel, "data-slot": "phone-field-country", className: COUNTRY_BUTTON, children: [_jsx(IsoChip, { iso: shape.iso }), _jsx(CallingCode, { dial: shape.dial }), _jsx(IconGlyph, { name: isOpen ? "chevron-up" : "chevron-down", className: FIELD_ICON })] }), _jsx(Popover, { triggerRef: frameRef, placement: "bottom start", offset: 4, "data-slot": "phone-field-popover", className: cn(POPOVER, "w-(--trigger-width) max-h-80"), children: _jsx(Dialog, { "aria-label": listLabel, className: "flex min-h-0 flex-col outline-hidden", children: _jsxs(Autocomplete, { inputValue: query, onInputChange: setQuery, filter: () => true, children: [_jsx(AriaSearchField, { autoFocus: true, "aria-label": countrySearchLabel ?? phoneCountrySearchLabel(locale), className: "mb-ds-050", children: _jsxs("div", { className: cn(FIELD_FRAME, FIELD_SIZE.small, "focus-within:border-ds-border-focused"), children: [_jsx(IconGlyph, { name: "search", className: FIELD_ICON }), _jsx(Input, { "data-slot": "phone-field-search", className: cn(INPUT, "text-body [&::-webkit-search-cancel-button]:hidden") })] }) }), _jsxs(ListBox, { "aria-label": listLabel, selectionMode: "single", selectedKeys: [shape.iso],
|
|
216
|
+
// Pressing the current country toggles it off: that empty selection means "keep it" and closes,
|
|
217
|
+
// so confirming the country never leaves the list open.
|
|
218
|
+
onSelectionChange: (keys) => {
|
|
219
|
+
const [key] = [...keys];
|
|
220
|
+
choose(key ?? shape.iso);
|
|
221
|
+
}, "data-slot": "phone-field-listbox", className: LISTBOX, renderEmptyState: () => (_jsx("div", { "data-slot": "phone-field-empty", className: "px-ds-100 py-ds-150 text-body-small text-ds-text-subtle", children: countryEmptyMessage ? countryEmptyMessage(query) : noMatchLabel(locale, query) })), children: [shownSuggested.length > 0 && (_jsx(ListBoxSection, { "aria-label": suggestedCountriesLabel ?? phoneSuggestedCountriesLabel(locale), "data-slot": "phone-field-suggested", className: "flex flex-col", children: shownSuggested.map(option) })), shownRest.length > 0 && (_jsxs(ListBoxSection, { "data-slot": "phone-field-all", className: "flex flex-col", children: [shownSuggested.length > 0 && _jsx(Header, { className: sectionHeader, children: allCountriesLabel ?? phoneAllCountriesLabel(locale) }), shownRest.map(option)] }))] })] }) }) })] })), _jsx(Input, { ...controlData, ref: inputRef, type: "tel", inputMode: "tel", autoComplete: "tel-national",
|
|
222
|
+
// Digits and spaces read left to right in every language; the text still sits at the inline start.
|
|
223
|
+
dir: "ltr", placeholder: placeholder,
|
|
224
|
+
// The field's `name` is for its server errors; the form gets the E.164 value from the hidden input.
|
|
225
|
+
name: "", "data-slot": "phone-field-input", className: cn(INPUT, "text-body tabular-nums rtl:text-end"), onCompositionStart: () => {
|
|
226
|
+
composing.current = true;
|
|
227
|
+
}, onCompositionEnd: (event) => {
|
|
228
|
+
composing.current = false;
|
|
229
|
+
setComposed(null);
|
|
230
|
+
const typed = event.currentTarget.value;
|
|
231
|
+
emit(digitsOf(typed), shape.iso, digitCountBefore(typed, event.currentTarget.selectionStart ?? typed.length));
|
|
232
|
+
}, onPaste: (event) => {
|
|
233
|
+
if (isReadOnly)
|
|
234
|
+
return;
|
|
235
|
+
// A plus of any form ("+" from a Japanese IME) or two zeros of any script start an international number;
|
|
236
|
+
// its digits are digitsOf's, so "²" or "①" never count (./phone-paste).
|
|
237
|
+
const pasted = event.clipboardData.getData("text").trim();
|
|
238
|
+
const pastedDigits = internationalPasteDigits(pasted);
|
|
239
|
+
if (pastedDigits === null)
|
|
240
|
+
return;
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
// Longest calling code first (+38 is a prefix of +380, +381, +382…); the current country wins a tie (+1).
|
|
243
|
+
// On a shared code (+1 for the US, Canada and the Caribbean) the current country wins, then the phone
|
|
244
|
+
// table (the US for +1), as when a stored number is read back.
|
|
245
|
+
const rank = (iso) => {
|
|
246
|
+
const at = PHONE_COUNTRIES.findIndex((item) => item.iso === iso);
|
|
247
|
+
return at < 0 ? PHONE_COUNTRIES.length : at;
|
|
248
|
+
};
|
|
249
|
+
const candidates = options
|
|
250
|
+
.filter((item) => pastedDigits.startsWith(item.dial))
|
|
251
|
+
.sort((a, b) => b.dial.length - a.dial.length || Number(b.iso === shape.iso) - Number(a.iso === shape.iso) || rank(a.iso) - rank(b.iso));
|
|
252
|
+
const matched = candidates[0];
|
|
253
|
+
if (!matched) {
|
|
254
|
+
onUnsupportedInternationalPaste?.(pasted);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const next = pastedDigits.slice(matched.dial.length);
|
|
258
|
+
emit(next, matched.iso, next.length);
|
|
259
|
+
}, onKeyDown: (event) => {
|
|
260
|
+
// Backspace or Delete beside a group space removes the digit, not just the space.
|
|
261
|
+
if (event.ctrlKey || event.metaKey || event.altKey || event.nativeEvent.isComposing || isReadOnly)
|
|
262
|
+
return;
|
|
263
|
+
if (event.key !== "Backspace" && event.key !== "Delete")
|
|
264
|
+
return;
|
|
265
|
+
const start = event.currentTarget.selectionStart ?? 0;
|
|
266
|
+
if (start !== event.currentTarget.selectionEnd)
|
|
267
|
+
return;
|
|
268
|
+
const index = digitIndexForSeparatorKey(display, start, event.key);
|
|
269
|
+
if (index === null)
|
|
270
|
+
return;
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
emit(national.slice(0, index) + national.slice(index + 1), shape.iso, index);
|
|
273
|
+
} })] }) }), description && _jsx(FieldDescription, { children: description }), _jsx(FieldError, { children: shownError }), name && !isDisabled && _jsx("input", { type: "hidden", name: name, value: value, "data-slot": "phone-field-value" })] }));
|
|
274
|
+
});
|
|
275
|
+
//# sourceMappingURL=phone-field.js.map
|