@senvenli/react 0.0.0-stage → 0.2.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,35 @@
|
|
|
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 InputOTPProps = Omit<AriaTextFieldProps, "className" | "style" | "children" | "type" | "inputMode" | "autoComplete" | "maxLength"> & {
|
|
5
|
+
label: React.ReactNode;
|
|
6
|
+
/** 4 or 6 digits; 6 splits 3 + 3 with a dash. */
|
|
7
|
+
length?: 4 | 6;
|
|
8
|
+
description?: React.ReactNode;
|
|
9
|
+
/** Say what to do: "Wrong code. Enter the latest code from your phone." */
|
|
10
|
+
errorMessage?: React.ReactNode;
|
|
11
|
+
/** Called once the last digit is entered (submit there). */
|
|
12
|
+
onComplete?: (code: string) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
15
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
16
|
+
* {@link RequiredValidation} for the whole contract.
|
|
17
|
+
*/
|
|
18
|
+
requiredValidation?: RequiredValidation;
|
|
19
|
+
};
|
|
20
|
+
export declare const InputOTP: React.ForwardRefExoticComponent<Omit<AriaTextFieldProps, "style" | "type" | "className" | "children" | "inputMode" | "autoComplete" | "maxLength"> & {
|
|
21
|
+
label: React.ReactNode;
|
|
22
|
+
/** 4 or 6 digits; 6 splits 3 + 3 with a dash. */
|
|
23
|
+
length?: 4 | 6;
|
|
24
|
+
description?: React.ReactNode;
|
|
25
|
+
/** Say what to do: "Wrong code. Enter the latest code from your phone." */
|
|
26
|
+
errorMessage?: React.ReactNode;
|
|
27
|
+
/** Called once the last digit is entered (submit there). */
|
|
28
|
+
onComplete?: (code: string) => 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
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,83 @@
|
|
|
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, } from "react-aria-components";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
import { FieldDescription, FieldError, FieldLabel } from "./field-parts.js";
|
|
7
|
+
import { FIELD_STACK } from "./styles.js";
|
|
8
|
+
import { useFieldValidation } from "./validation.js";
|
|
9
|
+
/**
|
|
10
|
+
* A one-time code: one real input with `autocomplete="one-time-code"` and a
|
|
11
|
+
* numeric keypad, so SMS autofill and paste fill every box at once; the
|
|
12
|
+
* boxes are only its picture. React Aria has no OTP primitive, so this is a TextField with a visual layer.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The digits to keep from the input's text. The caret is pinned to the end,
|
|
16
|
+
* so a full code pasted or autofilled over an old one arrives appended
|
|
17
|
+
* ("111111" + "222222"): when a whole code was added, the new one wins.
|
|
18
|
+
*/
|
|
19
|
+
function takeCode(text, previous, length) {
|
|
20
|
+
const digits = text.replace(/\D/g, "");
|
|
21
|
+
if (digits.length > length && digits.length - previous.length >= length)
|
|
22
|
+
return digits.slice(-length);
|
|
23
|
+
return digits.slice(0, length);
|
|
24
|
+
}
|
|
25
|
+
export const InputOTP = React.forwardRef(function InputOTP({ label, length = 6, description, errorMessage, onComplete, value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest }, ref) {
|
|
26
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? "");
|
|
27
|
+
const code = (value ?? uncontrolled).replace(/\D/g, "").slice(0, length);
|
|
28
|
+
const [focused, setFocused] = React.useState(false);
|
|
29
|
+
const inputRef = React.useRef(null);
|
|
30
|
+
const setRefs = (node) => {
|
|
31
|
+
inputRef.current = node;
|
|
32
|
+
if (typeof ref === "function")
|
|
33
|
+
ref(node);
|
|
34
|
+
else if (ref)
|
|
35
|
+
ref.current = node;
|
|
36
|
+
};
|
|
37
|
+
const active = Math.min(code.length, length - 1);
|
|
38
|
+
// The last code passed to onComplete: a new full code (pasted over an old one) completes again.
|
|
39
|
+
const completed = React.useRef(code.length === length ? code : null);
|
|
40
|
+
const timing = useFieldValidation({
|
|
41
|
+
validate,
|
|
42
|
+
value: value === undefined ? undefined : code,
|
|
43
|
+
initialValue: defaultValue ?? "",
|
|
44
|
+
isRequired: rest.isRequired,
|
|
45
|
+
requiredValidation,
|
|
46
|
+
onBlur: onBlur,
|
|
47
|
+
onChange: (digits) => {
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
setUncontrolled(digits);
|
|
50
|
+
onChange?.(digits);
|
|
51
|
+
if (digits.length === length) {
|
|
52
|
+
if (completed.current !== digits) {
|
|
53
|
+
completed.current = digits;
|
|
54
|
+
onComplete?.(digits);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
completed.current = null;
|
|
59
|
+
},
|
|
60
|
+
validationBehavior: rest.validationBehavior,
|
|
61
|
+
});
|
|
62
|
+
const pinCaret = (input) => {
|
|
63
|
+
const end = input.value.length;
|
|
64
|
+
if (input.selectionStart !== end || input.selectionEnd !== end)
|
|
65
|
+
input.setSelectionRange(end, end);
|
|
66
|
+
};
|
|
67
|
+
return (_jsx(AriaTextField, { ...rest, value: code, validationBehavior: timing.validationBehavior, validate: timing.validate, onBlur: timing.onBlur, onChange: (next) => timing.onChange?.(takeCode(next, code, length)), "data-slot": "input-otp", className: FIELD_STACK, children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { isRequired: rest.isRequired, children: label }), _jsxs("div", { "data-slot": "input-otp-boxes",
|
|
68
|
+
// As wide as its cells, never wider than its column: on a narrow phone the cells shrink instead
|
|
69
|
+
// of pushing the field (and the page) sideways. Codes read left to right in every locale, so the row
|
|
70
|
+
// (cells, separator and the hidden input) stays LTR on an RTL page: "1234" never shows as "4 3 2 1".
|
|
71
|
+
dir: "ltr", className: "relative flex w-full max-w-fit items-center gap-ds-100", onMouseDown: (event) => {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
inputRef.current?.focus();
|
|
74
|
+
}, children: [_jsx(Input, { ref: setRefs, inputMode: "numeric", autoComplete: "one-time-code",
|
|
75
|
+
// No maxLength: the browser would cut "482 917" to six characters before the digits are picked out.
|
|
76
|
+
pattern: "\\d*", "data-slot": "input-otp-input", onFocus: (event) => {
|
|
77
|
+
setFocused(true);
|
|
78
|
+
pinCaret(event.currentTarget);
|
|
79
|
+
},
|
|
80
|
+
// Boxes fill left to right: arrows, Home and clicks never move the caret off the end.
|
|
81
|
+
onSelect: (event) => pinCaret(event.currentTarget), onKeyUp: (event) => pinCaret(event.currentTarget), onBlur: () => setFocused(false), className: "absolute inset-0 z-10 h-full w-full cursor-text bg-transparent text-transparent caret-transparent outline-hidden selection:bg-transparent" }), Array.from({ length }, (_, index) => (_jsxs(React.Fragment, { children: [length === 6 && index === 3 && (_jsx("span", { "aria-hidden": "true", "data-slot": "input-otp-separator", className: "h-0.5 w-ds-100 shrink-0 rounded-ds-full bg-ds-border-bold" })), _jsxs("span", { "aria-hidden": "true", "data-slot": "input-otp-box", "data-active": focused && index === active ? true : undefined, className: cn("relative inline-flex h-13 w-11 min-w-0 items-center justify-center rounded-ds-medium border bg-ds-background-input", "text-metric-medium tabular-nums text-ds-text", isInvalid ? "border-ds-border-danger" : "border-ds-border-bold", focused && index === active && "border-ds-border-focused outline-1 outline-solid -outline-offset-2 outline-ds-border-focused", isDisabled && "border-transparent bg-ds-background-disabled text-ds-text-disabled"), children: [code[index] ?? "", focused && index === active && code.length < length && (_jsx("span", { className: "h-5 w-px animate-pulse bg-ds-text motion-reduce:animate-none" }))] })] }, index)))] }), description && _jsx(FieldDescription, { children: description }), _jsx(FieldError, { children: errorMessage })] })) }));
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=input-otp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-otp.js","sourceRoot":"","sources":["../../src/form/input-otp.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,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,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAkC,SAAS,QAAQ,CACzF,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,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D,SAAS,EAAE,EAAE,CACX,oHAAoH,EACpH,8CAA8C,EAC9C,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,uBAAuB,EAC/D,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,8FAA8F,EAC7H,UAAU,IAAI,oEAAoE,CACnF,aAEA,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACjB,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CACtD,eAAM,SAAS,EAAC,8DAA8D,GAAG,CAClF,IACI,KApBY,KAAK,CAqBT,CAClB,CAAC,IACE,EACL,WAAW,IAAI,KAAC,gBAAgB,cAAE,WAAW,GAAoB,EAClE,KAAC,UAAU,cAAE,YAAY,GAAc,IACtC,CACJ,GACa,CACjB,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 { FieldDescription, FieldError, FieldLabel } from \"./field-parts\";\nimport { FIELD_STACK } from \"./styles\";\nimport { useFieldValidation, type RequiredValidation } from \"./validation\";\n\nexport type InputOTPProps = 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\nexport const InputOTP = React.forwardRef<HTMLInputElement, InputOTPProps>(function InputOTP(\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 // 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=\"input-otp\"\n className={FIELD_STACK}\n >\n {({ isInvalid, isDisabled }) => (\n <>\n <FieldLabel isRequired={rest.isRequired}>{label}</FieldLabel>\n <div\n data-slot=\"input-otp-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 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=\"input-otp-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=\"input-otp-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=\"input-otp-box\"\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 \"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] ?? \"\"}\n {focused && index === active && code.length < length && (\n <span className=\"h-5 w-px animate-pulse bg-ds-text motion-reduce:animate-none\" />\n )}\n </span>\n </React.Fragment>\n ))}\n </div>\n {description && <FieldDescription>{description}</FieldDescription>}\n <FieldError>{errorMessage}</FieldError>\n </>\n )}\n </AriaTextField>\n );\n});\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type WithRadius } from "../defaults.js";
|
|
3
|
+
import { type NumberFieldProps } from "./number-field.js";
|
|
4
|
+
import { type PasswordFieldProps } from "./password-field.js";
|
|
5
|
+
import { type PhoneFieldProps } from "./phone-field.js";
|
|
6
|
+
import { type SearchFieldProps } from "./search-field.js";
|
|
7
|
+
import { type TextFieldProps } from "./text-field.js";
|
|
8
|
+
/** What the field holds; it picks the keyboard, the behaviour and the props that apply. */
|
|
9
|
+
export type InputType = "text" | "email" | "url" | "password" | "search" | "number" | "tel";
|
|
10
|
+
export type InputTextProps = Omit<TextFieldProps, "type"> & {
|
|
11
|
+
/** `text` (default), `email` or `url`: the matching keyboard and autofill on phones. */
|
|
12
|
+
type?: "text" | "email" | "url";
|
|
13
|
+
};
|
|
14
|
+
export type InputPasswordProps = PasswordFieldProps & {
|
|
15
|
+
/** A password: hidden while typed, a show/hide button, and an optional strength meter. */
|
|
16
|
+
type: "password";
|
|
17
|
+
};
|
|
18
|
+
export type InputSearchProps = SearchFieldProps & {
|
|
19
|
+
/** A search box: a search icon, a clear button and Esc to clear. */
|
|
20
|
+
type: "search";
|
|
21
|
+
};
|
|
22
|
+
export type InputNumberProps = NumberFieldProps & {
|
|
23
|
+
/** A number (the value is a number): locale formatting, currency or units, min/max and optional steppers. */
|
|
24
|
+
type: "number";
|
|
25
|
+
};
|
|
26
|
+
export type InputTelProps = PhoneFieldProps & {
|
|
27
|
+
/** A phone number: a country picker and the value as E.164 ("+38267123456"). */
|
|
28
|
+
type: "tel";
|
|
29
|
+
};
|
|
30
|
+
export type InputProps = (InputTextProps | InputPasswordProps | InputSearchProps | InputNumberProps | InputTelProps) & WithRadius;
|
|
31
|
+
/**
|
|
32
|
+
* The one text-entry field, with a label, description and error: `type` picks what it holds (text, email, url,
|
|
33
|
+
* password, search, number or tel) and the props that go with it, as an `<input type>` does. For several lines
|
|
34
|
+
* use TextArea; for a one-time code, OtpField.
|
|
35
|
+
*/
|
|
36
|
+
export declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { ComponentDefaultsProvider, splitRadius } from "../defaults.js";
|
|
5
|
+
import { NumberField } from "./number-field.js";
|
|
6
|
+
import { PasswordField } from "./password-field.js";
|
|
7
|
+
import { PhoneField } from "./phone-field.js";
|
|
8
|
+
import { SearchField } from "./search-field.js";
|
|
9
|
+
import { TextField } from "./text-field.js";
|
|
10
|
+
/**
|
|
11
|
+
* The one text-entry field, with a label, description and error: `type` picks what it holds (text, email, url,
|
|
12
|
+
* password, search, number or tel) and the props that go with it, as an `<input type>` does. For several lines
|
|
13
|
+
* use TextArea; for a one-time code, OtpField.
|
|
14
|
+
*/
|
|
15
|
+
export const Input = React.forwardRef(function Input(allProps, ref) {
|
|
16
|
+
const [radius, props] = splitRadius(allProps);
|
|
17
|
+
return _jsx(ComponentDefaultsProvider, { value: { radius }, children: field(props, ref) });
|
|
18
|
+
});
|
|
19
|
+
function field(props, ref) {
|
|
20
|
+
switch (props.type) {
|
|
21
|
+
case "password": {
|
|
22
|
+
const { type: _type, ...rest } = props;
|
|
23
|
+
return _jsx(PasswordField, { ...rest, ref: ref });
|
|
24
|
+
}
|
|
25
|
+
case "search": {
|
|
26
|
+
const { type: _type, ...rest } = props;
|
|
27
|
+
return _jsx(SearchField, { ...rest, ref: ref });
|
|
28
|
+
}
|
|
29
|
+
case "number": {
|
|
30
|
+
const { type: _type, ...rest } = props;
|
|
31
|
+
return _jsx(NumberField, { ...rest, ref: ref });
|
|
32
|
+
}
|
|
33
|
+
case "tel": {
|
|
34
|
+
const { type: _type, ...rest } = props;
|
|
35
|
+
return _jsx(PhoneField, { ...rest, ref: ref });
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
return _jsx(TextField, { ...props, ref: ref });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/form/input.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,aAAa,EAA2B,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAwB,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAuB,MAAM,cAAc,CAAC;AA4B9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAA+B,SAAS,KAAK,CAAC,QAAQ,EAAE,GAAG;IAC9F,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAuD,CAAC;IACpG,OAAO,KAAC,yBAAyB,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,YAAG,KAAK,CAAC,KAAmB,EAAE,GAAG,CAAC,GAA6B,CAAC;AACrH,CAAC,CAAC,CAAC;AAEH,SAAS,KAAK,CAAC,KAAiB,EAAE,GAAyC;IACzE,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACvC,OAAO,KAAC,aAAa,OAAK,IAAI,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;QAC/C,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACvC,OAAO,KAAC,WAAW,OAAK,IAAI,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;QAC7C,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACvC,OAAO,KAAC,WAAW,OAAK,IAAI,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;QAC7C,CAAC;QACD,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACvC,OAAO,KAAC,UAAU,OAAK,IAAI,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;QAC5C,CAAC;QACD;YACE,OAAO,KAAC,SAAS,OAAK,KAAK,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;IAC9C,CAAC;AACH,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { ComponentDefaultsProvider, splitRadius, type WithRadius } from \"../defaults\";\nimport { NumberField, type NumberFieldProps } from \"./number-field\";\nimport { PasswordField, type PasswordFieldProps } from \"./password-field\";\nimport { PhoneField, type PhoneFieldProps } from \"./phone-field\";\nimport { SearchField, type SearchFieldProps } from \"./search-field\";\nimport { TextField, type TextFieldProps } from \"./text-field\";\n\n/** What the field holds; it picks the keyboard, the behaviour and the props that apply. */\nexport type InputType = \"text\" | \"email\" | \"url\" | \"password\" | \"search\" | \"number\" | \"tel\";\n\nexport type InputTextProps = Omit<TextFieldProps, \"type\"> & {\n /** `text` (default), `email` or `url`: the matching keyboard and autofill on phones. */\n type?: \"text\" | \"email\" | \"url\";\n};\nexport type InputPasswordProps = PasswordFieldProps & {\n /** A password: hidden while typed, a show/hide button, and an optional strength meter. */\n type: \"password\";\n};\nexport type InputSearchProps = SearchFieldProps & {\n /** A search box: a search icon, a clear button and Esc to clear. */\n type: \"search\";\n};\nexport type InputNumberProps = NumberFieldProps & {\n /** A number (the value is a number): locale formatting, currency or units, min/max and optional steppers. */\n type: \"number\";\n};\nexport type InputTelProps = PhoneFieldProps & {\n /** A phone number: a country picker and the value as E.164 (\"+38267123456\"). */\n type: \"tel\";\n};\n\nexport type InputProps = (InputTextProps | InputPasswordProps | InputSearchProps | InputNumberProps | InputTelProps) & WithRadius;\n\n/**\n * The one text-entry field, with a label, description and error: `type` picks what it holds (text, email, url,\n * password, search, number or tel) and the props that go with it, as an `<input type>` does. For several lines\n * use TextArea; for a one-time code, OtpField.\n */\nexport const Input = React.forwardRef<HTMLInputElement, InputProps>(function Input(allProps, ref) {\n const [radius, props] = splitRadius(allProps) as [InputProps[\"radius\"], Omit<InputProps, \"radius\">];\n return <ComponentDefaultsProvider value={{ radius }}>{field(props as InputProps, ref)}</ComponentDefaultsProvider>;\n});\n\nfunction field(props: InputProps, ref: React.ForwardedRef<HTMLInputElement>) {\n switch (props.type) {\n case \"password\": {\n const { type: _type, ...rest } = props;\n return <PasswordField {...rest} ref={ref} />;\n }\n case \"search\": {\n const { type: _type, ...rest } = props;\n return <SearchField {...rest} ref={ref} />;\n }\n case \"number\": {\n const { type: _type, ...rest } = props;\n return <NumberField {...rest} ref={ref} />;\n }\n case \"tel\": {\n const { type: _type, ...rest } = props;\n return <PhoneField {...rest} ref={ref} />;\n }\n default:\n return <TextField {...props} ref={ref} />;\n }\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type NumberFieldProps as AriaNumberFieldProps } from "react-aria-components";
|
|
3
|
+
import { type FieldSize } from "./styles.js";
|
|
4
|
+
import { type RequiredValidation } from "./validation.js";
|
|
5
|
+
export type NumberFieldProps = Omit<AriaNumberFieldProps, "className" | "style" | "children"> & {
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
description?: React.ReactNode;
|
|
8
|
+
/** State the range here too, not only in the error ("1–50"). */
|
|
9
|
+
errorMessage?: React.ReactNode;
|
|
10
|
+
isOptional?: boolean;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
/** A unit or currency addon when `formatOptions` does not print it ("km", "days"). */
|
|
13
|
+
/** Before the value, inside the frame: text, a unit or currency ("€", "https://"), or `<Icon name="search" />`. */
|
|
14
|
+
leading?: React.ReactNode;
|
|
15
|
+
/** After the value, inside the frame: a unit ("kg"), a domain, an icon. */
|
|
16
|
+
trailing?: React.ReactNode;
|
|
17
|
+
/** The stepper on the end, for small integers. */
|
|
18
|
+
showStepper?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Money: an ISO 4217 code ("EUR"). The symbol becomes a leading addon and the
|
|
21
|
+
* amount keeps two decimals, which reads as the design's "€ 248,00" (symbol
|
|
22
|
+
* first, with a space); Intl's own currency style has no space in tr / me.
|
|
23
|
+
*/
|
|
24
|
+
currency?: string;
|
|
25
|
+
/** Formats and parses in this locale instead of the provider's (the branch locale). */
|
|
26
|
+
locale?: string;
|
|
27
|
+
size?: FieldSize;
|
|
28
|
+
/**
|
|
29
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
30
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
31
|
+
* {@link RequiredValidation} for the whole contract.
|
|
32
|
+
*/
|
|
33
|
+
requiredValidation?: RequiredValidation;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* How the locale writes a currency: its narrow symbol, which side of the
|
|
37
|
+
* amount it goes on ("€ 248,00" in tr, "248,00 €" in de) and how many
|
|
38
|
+
* decimals the currency has (2 for EUR, 0 for JPY).
|
|
39
|
+
*/
|
|
40
|
+
export declare function currencyLayout(locale: string, currency: string): {
|
|
41
|
+
symbol: string;
|
|
42
|
+
position: "end" | "start";
|
|
43
|
+
fractionDigits: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Counts, money and percentages, formatted to the locale while typing.
|
|
47
|
+
* `value` is a number, never a formatted string; money uses `currency` (symbol
|
|
48
|
+
* on the side the locale puts it, the currency's own decimals), and
|
|
49
|
+
* `formatOptions` takes other Intl options (percent, unit). React Aria parses the locale's own
|
|
50
|
+
* separators: only the decimal separator starts a fraction, the grouping
|
|
51
|
+
* separator stays grouping. Focusing selects the value, so
|
|
52
|
+
* typing over a default 0 replaces it. A controlled value that
|
|
53
|
+
* changes while the field is focused shows at once.
|
|
54
|
+
*/
|
|
55
|
+
export declare const NumberField: React.ForwardRefExoticComponent<Omit<AriaNumberFieldProps, "children" | "style" | "className"> & {
|
|
56
|
+
label: React.ReactNode;
|
|
57
|
+
description?: React.ReactNode;
|
|
58
|
+
/** State the range here too, not only in the error ("1–50"). */
|
|
59
|
+
errorMessage?: React.ReactNode;
|
|
60
|
+
isOptional?: boolean;
|
|
61
|
+
placeholder?: string;
|
|
62
|
+
/** A unit or currency addon when `formatOptions` does not print it ("km", "days"). */
|
|
63
|
+
/** Before the value, inside the frame: text, a unit or currency ("€", "https://"), or `<Icon name="search" />`. */
|
|
64
|
+
leading?: React.ReactNode;
|
|
65
|
+
/** After the value, inside the frame: a unit ("kg"), a domain, an icon. */
|
|
66
|
+
trailing?: React.ReactNode;
|
|
67
|
+
/** The stepper on the end, for small integers. */
|
|
68
|
+
showStepper?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Money: an ISO 4217 code ("EUR"). The symbol becomes a leading addon and the
|
|
71
|
+
* amount keeps two decimals, which reads as the design's "€ 248,00" (symbol
|
|
72
|
+
* first, with a space); Intl's own currency style has no space in tr / me.
|
|
73
|
+
*/
|
|
74
|
+
currency?: string;
|
|
75
|
+
/** Formats and parses in this locale instead of the provider's (the branch locale). */
|
|
76
|
+
locale?: string;
|
|
77
|
+
size?: FieldSize;
|
|
78
|
+
/**
|
|
79
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
80
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
81
|
+
* {@link RequiredValidation} for the whole contract.
|
|
82
|
+
*/
|
|
83
|
+
requiredValidation?: RequiredValidation;
|
|
84
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { Button as AriaButton, I18nProvider, Input, NumberField as AriaNumberField, useLocale, } from "react-aria-components";
|
|
5
|
+
import { IconGlyph } from "../display/icon.js";
|
|
6
|
+
import { cn } from "../utils.js";
|
|
7
|
+
import { useFieldSize } from "../defaults.js";
|
|
8
|
+
import { decreaseLabel, increaseLabel } from "../i18n.js";
|
|
9
|
+
import { FieldDescription, FieldError, FieldLabel } from "./field-parts.js";
|
|
10
|
+
import { InputAddon, InputGroup } from "./input-group.js";
|
|
11
|
+
import { FIELD_STACK, INPUT } from "./styles.js";
|
|
12
|
+
import { useFieldValidation } from "./validation.js";
|
|
13
|
+
import { splitDataAttributes } from "./data-attributes.js";
|
|
14
|
+
/**
|
|
15
|
+
* How the locale writes a currency: its narrow symbol, which side of the
|
|
16
|
+
* amount it goes on ("€ 248,00" in tr, "248,00 €" in de) and how many
|
|
17
|
+
* decimals the currency has (2 for EUR, 0 for JPY).
|
|
18
|
+
*/
|
|
19
|
+
export function currencyLayout(locale, currency) {
|
|
20
|
+
const format = new Intl.NumberFormat(locale, { style: "currency", currency, currencyDisplay: "narrowSymbol" });
|
|
21
|
+
const parts = format.formatToParts(1);
|
|
22
|
+
const symbolAt = parts.findIndex((part) => part.type === "currency");
|
|
23
|
+
const numberAt = parts.findIndex((part) => part.type === "integer");
|
|
24
|
+
const { maximumFractionDigits = 2 } = format.resolvedOptions();
|
|
25
|
+
return {
|
|
26
|
+
symbol: parts[symbolAt]?.value ?? currency,
|
|
27
|
+
position: symbolAt > numberAt ? "end" : "start",
|
|
28
|
+
fractionDigits: maximumFractionDigits,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function Stepper() {
|
|
32
|
+
const { locale } = useLocale();
|
|
33
|
+
const cell = "inline-flex h-1/2 w-8 items-center justify-center text-ds-icon-subtle outline-hidden cursor-pointer " +
|
|
34
|
+
"data-[hovered]:bg-ds-background-neutral-subtle-hovered data-[pressed]:bg-ds-background-neutral-pressed " +
|
|
35
|
+
"data-[disabled]:cursor-not-allowed data-[disabled]:text-ds-text-disabled";
|
|
36
|
+
return (_jsxs("span", { "data-slot": "number-field-stepper", className: "-me-(--field-pad) flex flex-col self-stretch border-s border-ds-border", children: [_jsx(AriaButton, { slot: "increment", "aria-label": increaseLabel(locale), className: cn(cell, "rounded-se-[max(0px,calc(var(--ds-field-radius,var(--ds-radius-medium))-1px))] border-b border-ds-border"), children: _jsx(IconGlyph, { name: "chevron-up", size: "small", "data-slot": "number-field-stepper-icon" }) }), _jsx(AriaButton, { slot: "decrement", "aria-label": decreaseLabel(locale), className: cn(cell, "rounded-ee-[max(0px,calc(var(--ds-field-radius,var(--ds-radius-medium))-1px))]"), children: _jsx(IconGlyph, { name: "chevron-down", size: "small", "data-slot": "number-field-stepper-icon" }) })] }));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Counts, money and percentages, formatted to the locale while typing.
|
|
40
|
+
* `value` is a number, never a formatted string; money uses `currency` (symbol
|
|
41
|
+
* on the side the locale puts it, the currency's own decimals), and
|
|
42
|
+
* `formatOptions` takes other Intl options (percent, unit). React Aria parses the locale's own
|
|
43
|
+
* separators: only the decimal separator starts a fraction, the grouping
|
|
44
|
+
* separator stays grouping. Focusing selects the value, so
|
|
45
|
+
* typing over a default 0 replaces it. A controlled value that
|
|
46
|
+
* changes while the field is focused shows at once.
|
|
47
|
+
*/
|
|
48
|
+
export const NumberField = React.forwardRef(function NumberField({ label, description, errorMessage, isOptional, placeholder, leading: prefix, trailing: suffix, showStepper, locale, size: fieldSize, currency, formatOptions, validate, onBlur, onChange, requiredValidation, ...rest }, ref) {
|
|
49
|
+
const size = useFieldSize(fieldSize);
|
|
50
|
+
const selectedOnFocus = React.useRef(false);
|
|
51
|
+
const timing = useFieldValidation({
|
|
52
|
+
validate,
|
|
53
|
+
value: rest.value,
|
|
54
|
+
initialValue: rest.value ?? rest.defaultValue,
|
|
55
|
+
isRequired: rest.isRequired,
|
|
56
|
+
requiredValidation,
|
|
57
|
+
onBlur: onBlur,
|
|
58
|
+
onChange,
|
|
59
|
+
validationBehavior: rest.validationBehavior,
|
|
60
|
+
});
|
|
61
|
+
const { locale: providerLocale } = useLocale();
|
|
62
|
+
const money = currency ? currencyLayout(locale ?? providerLocale, currency) : undefined;
|
|
63
|
+
// The symbol is an addon, so the number itself is a plain decimal with the currency's decimals.
|
|
64
|
+
const options = money
|
|
65
|
+
? { ...formatOptions, style: "decimal", currency: undefined, minimumFractionDigits: money.fractionDigits, maximumFractionDigits: money.fractionDigits }
|
|
66
|
+
: formatOptions;
|
|
67
|
+
const lead = prefix ?? (money?.position === "start" ? money.symbol : undefined);
|
|
68
|
+
const trail = suffix ?? (money?.position === "end" ? money.symbol : undefined);
|
|
69
|
+
const { wrapperProps, controlData } = splitDataAttributes(rest);
|
|
70
|
+
const field = (_jsx(AriaNumberField, { ...wrapperProps, formatOptions: options, validationBehavior: timing.validationBehavior, validate: timing.validate, onBlur: timing.onBlur, onChange: timing.onChange, "data-slot": "number-field", className: FIELD_STACK, children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsxs(FieldLabel, { isRequired: rest.isRequired, isOptional: isOptional, children: [label, currency && _jsxs("span", { className: "sr-only", children: [" (", currency, ")"] })] }), _jsxs(InputGroup, { size: size, isDisabled: isDisabled, isInvalid: isInvalid, children: [lead !== undefined && (_jsx(InputAddon, { position: "start", children: _jsx("span", { "aria-hidden": money ? true : undefined, children: lead }) })), _jsx(Input, { ...controlData, ref: ref, placeholder: placeholder, "data-slot": "number-field-input", className: cn(INPUT, "text-body tabular-nums"), onMouseDown: (event) => {
|
|
71
|
+
// Only a click that focuses the field needs its release kept from collapsing the selection.
|
|
72
|
+
selectedOnFocus.current = document.activeElement !== event.currentTarget;
|
|
73
|
+
}, onFocus: (event) => event.currentTarget.select(), onMouseUp: (event) => {
|
|
74
|
+
// A click focuses then releases; the release would collapse the selection (Safari).
|
|
75
|
+
if (selectedOnFocus.current)
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
selectedOnFocus.current = false;
|
|
78
|
+
} }), trail !== undefined && (_jsx(InputAddon, { position: "end", flush: !showStepper, children: _jsx("span", { "aria-hidden": money ? true : undefined, children: trail }) })), showStepper && _jsx(Stepper, {})] }), description && _jsx(FieldDescription, { children: description }), _jsx(FieldError, { children: errorMessage })] })) }));
|
|
79
|
+
return locale ? _jsx(I18nProvider, { locale: locale, children: field }) : field;
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=number-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-field.js","sourceRoot":"","sources":["../../src/form/number-field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,MAAM,IAAI,UAAU,EACpB,YAAY,EACZ,KAAK,EACL,WAAW,IAAI,eAAe,EAC9B,SAAS,GAEV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OA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AAC,QAAQ,EAAC,KAAK,EAAC,KAAK,EAAE,CAAC,WAAW,YAC5C,8BAAmB,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,YAAG,KAAK,GAAQ,GAChD,CACd,EACA,WAAW,IAAI,KAAC,OAAO,KAAG,IAChB,EACZ,WAAW,IAAI,KAAC,gBAAgB,cAAE,WAAW,GAAoB,EAClE,KAAC,UAAU,cAAE,YAAY,GAAc,IACtC,CACJ,GACe,CACnB,CAAC;IAEF,OAAO,MAAM,CAAC,CAAC,CAAC,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,YAAG,KAAK,GAAgB,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/E,CAAC,CAAC,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Button as AriaButton,\n I18nProvider,\n Input,\n NumberField as AriaNumberField,\n useLocale,\n type NumberFieldProps as AriaNumberFieldProps,\n} from \"react-aria-components\";\nimport { IconGlyph } from \"../display/icon\";\n\nimport { cn } from \"../utils\";\nimport { useFieldSize } from \"../defaults\";\nimport { decreaseLabel, increaseLabel } from \"../i18n\";\nimport { FieldDescription, FieldError, FieldLabel } from \"./field-parts\";\nimport { InputAddon, InputGroup } from \"./input-group\";\nimport { FIELD_STACK, INPUT, type FieldSize } from \"./styles\";\nimport { useFieldValidation, type RequiredValidation } from \"./validation\";\nimport { splitDataAttributes } from \"./data-attributes\";\n\nexport type NumberFieldProps = Omit<AriaNumberFieldProps, \"className\" | \"style\" | \"children\"> & {\n label: React.ReactNode;\n description?: React.ReactNode;\n /** State the range here too, not only in the error (\"1–50\"). */\n errorMessage?: React.ReactNode;\n isOptional?: boolean;\n placeholder?: string;\n /** A unit or currency addon when `formatOptions` does not print it (\"km\", \"days\"). */\n /** Before the value, inside the frame: text, a unit or currency (\"€\", \"https://\"), or `<Icon name=\"search\" />`. */\n leading?: React.ReactNode;\n /** After the value, inside the frame: a unit (\"kg\"), a domain, an icon. */\n trailing?: React.ReactNode;\n /** The stepper on the end, for small integers. */\n showStepper?: boolean;\n /**\n * Money: an ISO 4217 code (\"EUR\"). The symbol becomes a leading addon and the\n * amount keeps two decimals, which reads as the design's \"€ 248,00\" (symbol\n * first, with a space); Intl's own currency style has no space in tr / me.\n */\n currency?: string;\n /** Formats and parses in this locale instead of the provider's (the branch locale). */\n locale?: string;\n size?: FieldSize;\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 * How the locale writes a currency: its narrow symbol, which side of the\n * amount it goes on (\"€ 248,00\" in tr, \"248,00 €\" in de) and how many\n * decimals the currency has (2 for EUR, 0 for JPY).\n */\nexport function currencyLayout(locale: string, currency: string) {\n const format = new Intl.NumberFormat(locale, { style: \"currency\", currency, currencyDisplay: \"narrowSymbol\" });\n const parts = format.formatToParts(1);\n const symbolAt = parts.findIndex((part) => part.type === \"currency\");\n const numberAt = parts.findIndex((part) => part.type === \"integer\");\n const { maximumFractionDigits = 2 } = format.resolvedOptions();\n return {\n symbol: parts[symbolAt]?.value ?? currency,\n position: symbolAt > numberAt ? (\"end\" as const) : (\"start\" as const),\n fractionDigits: maximumFractionDigits,\n };\n}\n\nfunction Stepper() {\n const { locale } = useLocale();\n const cell =\n \"inline-flex h-1/2 w-8 items-center justify-center text-ds-icon-subtle outline-hidden cursor-pointer \" +\n \"data-[hovered]:bg-ds-background-neutral-subtle-hovered data-[pressed]:bg-ds-background-neutral-pressed \" +\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-ds-text-disabled\";\n return (\n <span data-slot=\"number-field-stepper\" className=\"-me-(--field-pad) flex flex-col self-stretch border-s border-ds-border\">\n <AriaButton slot=\"increment\" aria-label={increaseLabel(locale)} className={cn(cell, \"rounded-se-[max(0px,calc(var(--ds-field-radius,var(--ds-radius-medium))-1px))] border-b border-ds-border\")}>\n <IconGlyph name=\"chevron-up\" size=\"small\" data-slot=\"number-field-stepper-icon\" />\n </AriaButton>\n <AriaButton slot=\"decrement\" aria-label={decreaseLabel(locale)} className={cn(cell, \"rounded-ee-[max(0px,calc(var(--ds-field-radius,var(--ds-radius-medium))-1px))]\")}>\n <IconGlyph name=\"chevron-down\" size=\"small\" data-slot=\"number-field-stepper-icon\" />\n </AriaButton>\n </span>\n );\n}\n\n/**\n * Counts, money and percentages, formatted to the locale while typing.\n * `value` is a number, never a formatted string; money uses `currency` (symbol\n * on the side the locale puts it, the currency's own decimals), and\n * `formatOptions` takes other Intl options (percent, unit). React Aria parses the locale's own\n * separators: only the decimal separator starts a fraction, the grouping\n * separator stays grouping. Focusing selects the value, so\n * typing over a default 0 replaces it. A controlled value that\n * changes while the field is focused shows at once.\n */\nexport const NumberField = React.forwardRef<HTMLInputElement, NumberFieldProps>(function NumberField(\n {\n label, description, errorMessage, isOptional, placeholder, leading: prefix, trailing: suffix, showStepper, locale, size: fieldSize,\n currency, formatOptions, validate, onBlur, onChange, requiredValidation, ...rest\n },\n ref,\n) {\n const size = useFieldSize(fieldSize);\n const selectedOnFocus = React.useRef(false);\n const timing = useFieldValidation<number>({\n validate,\n value: rest.value,\n initialValue: rest.value ?? rest.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 { locale: providerLocale } = useLocale();\n const money = currency ? currencyLayout(locale ?? providerLocale, currency) : undefined;\n // The symbol is an addon, so the number itself is a plain decimal with the currency's decimals.\n const options = money\n ? { ...formatOptions, style: \"decimal\" as const, currency: undefined, minimumFractionDigits: money.fractionDigits, maximumFractionDigits: money.fractionDigits }\n : formatOptions;\n const lead = prefix ?? (money?.position === \"start\" ? money.symbol : undefined);\n const trail = suffix ?? (money?.position === \"end\" ? money.symbol : undefined);\n\n const { wrapperProps, controlData } = splitDataAttributes(rest);\n const field = (\n <AriaNumberField\n {...wrapperProps}\n formatOptions={options}\n validationBehavior={timing.validationBehavior}\n validate={timing.validate}\n onBlur={timing.onBlur}\n onChange={timing.onChange}\n data-slot=\"number-field\"\n className={FIELD_STACK}\n >\n {({ isInvalid, isDisabled }) => (\n <>\n <FieldLabel isRequired={rest.isRequired} isOptional={isOptional}>\n {label}\n {/* The symbol addon is visual; screen readers get the currency in the name. */}\n {currency && <span className=\"sr-only\"> ({currency})</span>}\n </FieldLabel>\n <InputGroup size={size} isDisabled={isDisabled} isInvalid={isInvalid}>\n {lead !== undefined && (\n <InputAddon position=\"start\">\n <span aria-hidden={money ? true : undefined}>{lead}</span>\n </InputAddon>\n )}\n <Input\n {...controlData}\n ref={ref}\n placeholder={placeholder}\n data-slot=\"number-field-input\"\n className={cn(INPUT, \"text-body tabular-nums\")}\n onMouseDown={(event) => {\n // Only a click that focuses the field needs its release kept from collapsing the selection.\n selectedOnFocus.current = document.activeElement !== event.currentTarget;\n }}\n onFocus={(event) => event.currentTarget.select()}\n onMouseUp={(event) => {\n // A click focuses then releases; the release would collapse the selection (Safari).\n if (selectedOnFocus.current) event.preventDefault();\n selectedOnFocus.current = false;\n }}\n />\n {trail !== undefined && (\n <InputAddon position=\"end\" flush={!showStepper}>\n <span aria-hidden={money ? true : undefined}>{trail}</span>\n </InputAddon>\n )}\n {showStepper && <Stepper />}\n </InputGroup>\n {description && <FieldDescription>{description}</FieldDescription>}\n <FieldError>{errorMessage}</FieldError>\n </>\n )}\n </AriaNumberField>\n );\n\n return locale ? <I18nProvider locale={locale}>{field}</I18nProvider> : field;\n});\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type TextFieldProps as AriaTextFieldProps } from "react-aria-components";
|
|
3
|
+
import { type WithMotion } from "../defaults.js";
|
|
4
|
+
import { type RequiredValidation } from "./validation.js";
|
|
5
|
+
export type OtpFieldProps = Omit<AriaTextFieldProps, "className" | "style" | "children" | "type" | "inputMode" | "autoComplete" | "maxLength"> & {
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
/** 4 or 6 digits; 6 splits 3 + 3 with a dash. */
|
|
8
|
+
length?: 4 | 6;
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
/** Say what to do: "Wrong code. Enter the latest code from your phone." */
|
|
11
|
+
errorMessage?: React.ReactNode;
|
|
12
|
+
/** Called once the last digit is entered (submit there). */
|
|
13
|
+
onComplete?: (code: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
16
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
17
|
+
* {@link RequiredValidation} for the whole contract.
|
|
18
|
+
*/
|
|
19
|
+
requiredValidation?: RequiredValidation;
|
|
20
|
+
};
|
|
21
|
+
/** OtpField with its own `motion` (auto, reduce or none) for the sliding, blinking caret and the digit pop. */
|
|
22
|
+
export declare const OtpField: React.ForwardRefExoticComponent<Omit<AriaTextFieldProps, "children" | "style" | "type" | "className" | "inputMode" | "autoComplete" | "maxLength"> & {
|
|
23
|
+
label: React.ReactNode;
|
|
24
|
+
/** 4 or 6 digits; 6 splits 3 + 3 with a dash. */
|
|
25
|
+
length?: 4 | 6;
|
|
26
|
+
description?: React.ReactNode;
|
|
27
|
+
/** Say what to do: "Wrong code. Enter the latest code from your phone." */
|
|
28
|
+
errorMessage?: React.ReactNode;
|
|
29
|
+
/** Called once the last digit is entered (submit there). */
|
|
30
|
+
onComplete?: (code: string) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
33
|
+
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
34
|
+
* {@link RequiredValidation} for the whole contract.
|
|
35
|
+
*/
|
|
36
|
+
requiredValidation?: RequiredValidation;
|
|
37
|
+
} & WithMotion & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,116 @@
|
|
|
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, } from "react-aria-components";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
import { MotionScope } from "../defaults.js";
|
|
7
|
+
import { FieldDescription, FieldError, FieldLabel } from "./field-parts.js";
|
|
8
|
+
import { FIELD_STACK } from "./styles.js";
|
|
9
|
+
import { useFieldValidation } from "./validation.js";
|
|
10
|
+
/**
|
|
11
|
+
* A one-time code: one real input with `autocomplete="one-time-code"` and a
|
|
12
|
+
* numeric keypad, so SMS autofill and paste fill every box at once; the
|
|
13
|
+
* boxes are only its picture. React Aria has no OTP primitive, so this is a TextField with a visual layer.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The digits to keep from the input's text. The caret is pinned to the end,
|
|
17
|
+
* so a full code pasted or autofilled over an old one arrives appended
|
|
18
|
+
* ("111111" + "222222"): when a whole code was added, the new one wins.
|
|
19
|
+
*/
|
|
20
|
+
function takeCode(text, previous, length) {
|
|
21
|
+
const digits = text.replace(/\D/g, "");
|
|
22
|
+
if (digits.length > length && digits.length - previous.length >= length)
|
|
23
|
+
return digits.slice(-length);
|
|
24
|
+
return digits.slice(0, length);
|
|
25
|
+
}
|
|
26
|
+
const OtpFieldBody = React.forwardRef(function OtpFieldBody({ label, length = 6, description, errorMessage, onComplete, value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest }, ref) {
|
|
27
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? "");
|
|
28
|
+
const code = (value ?? uncontrolled).replace(/\D/g, "").slice(0, length);
|
|
29
|
+
const [focused, setFocused] = React.useState(false);
|
|
30
|
+
const inputRef = React.useRef(null);
|
|
31
|
+
const setRefs = (node) => {
|
|
32
|
+
inputRef.current = node;
|
|
33
|
+
if (typeof ref === "function")
|
|
34
|
+
ref(node);
|
|
35
|
+
else if (ref)
|
|
36
|
+
ref.current = node;
|
|
37
|
+
};
|
|
38
|
+
const active = Math.min(code.length, length - 1);
|
|
39
|
+
const caret = useCaretOffset(active, length);
|
|
40
|
+
// The last code passed to onComplete: a new full code (pasted over an old one) completes again.
|
|
41
|
+
const completed = React.useRef(code.length === length ? code : null);
|
|
42
|
+
const timing = useFieldValidation({
|
|
43
|
+
validate,
|
|
44
|
+
value: value === undefined ? undefined : code,
|
|
45
|
+
initialValue: defaultValue ?? "",
|
|
46
|
+
isRequired: rest.isRequired,
|
|
47
|
+
requiredValidation,
|
|
48
|
+
onBlur: onBlur,
|
|
49
|
+
onChange: (digits) => {
|
|
50
|
+
if (value === undefined)
|
|
51
|
+
setUncontrolled(digits);
|
|
52
|
+
onChange?.(digits);
|
|
53
|
+
if (digits.length === length) {
|
|
54
|
+
if (completed.current !== digits) {
|
|
55
|
+
completed.current = digits;
|
|
56
|
+
onComplete?.(digits);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
completed.current = null;
|
|
61
|
+
},
|
|
62
|
+
validationBehavior: rest.validationBehavior,
|
|
63
|
+
});
|
|
64
|
+
const pinCaret = (input) => {
|
|
65
|
+
const end = input.value.length;
|
|
66
|
+
if (input.selectionStart !== end || input.selectionEnd !== end)
|
|
67
|
+
input.setSelectionRange(end, end);
|
|
68
|
+
};
|
|
69
|
+
return (_jsx(AriaTextField, { ...rest, value: code, validationBehavior: timing.validationBehavior, validate: timing.validate, onBlur: timing.onBlur, onChange: (next) => timing.onChange?.(takeCode(next, code, length)), "data-slot": "otp-field", className: FIELD_STACK, children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { isRequired: rest.isRequired, children: label }), _jsxs("div", { "data-slot": "otp-field-boxes",
|
|
70
|
+
// As wide as its cells, never wider than its column: on a narrow phone the cells shrink instead
|
|
71
|
+
// of pushing the field (and the page) sideways. Codes read left to right in every locale, so the row
|
|
72
|
+
// (cells, separator and the hidden input) stays LTR on an RTL page: "1234" never shows as "4 3 2 1".
|
|
73
|
+
dir: "ltr", ref: caret.row, className: "relative flex w-full max-w-fit items-center gap-ds-100", onMouseDown: (event) => {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
inputRef.current?.focus();
|
|
76
|
+
}, children: [_jsx(Input, { ref: setRefs, inputMode: "numeric", autoComplete: "one-time-code",
|
|
77
|
+
// No maxLength: the browser would cut "482 917" to six characters before the digits are picked out.
|
|
78
|
+
pattern: "\\d*", "data-slot": "otp-field-input", onFocus: (event) => {
|
|
79
|
+
setFocused(true);
|
|
80
|
+
pinCaret(event.currentTarget);
|
|
81
|
+
},
|
|
82
|
+
// Boxes fill left to right: arrows, Home and clicks never move the caret off the end.
|
|
83
|
+
onSelect: (event) => pinCaret(event.currentTarget), onKeyUp: (event) => pinCaret(event.currentTarget), onBlur: () => setFocused(false), className: "absolute inset-0 z-10 h-full w-full cursor-text bg-transparent text-transparent caret-transparent outline-hidden selection:bg-transparent" }), Array.from({ length }, (_, index) => (_jsxs(React.Fragment, { children: [length === 6 && index === 3 && (_jsx("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" })), _jsx("span", { "aria-hidden": "true", "data-slot": "otp-field-box", "data-index": index, "data-active": focused && index === active ? true : undefined, className: cn("relative inline-flex h-13 w-11 min-w-0 items-center justify-center rounded-ds-medium border bg-ds-background-input", "transition-[border-color,outline-color] duration-(--ds-duration-fast) motion-reduce:transition-none", "text-metric-medium tabular-nums text-ds-text", isInvalid ? "border-ds-border-danger" : "border-ds-border-bold", focused && index === active && "border-ds-border-focused outline-1 outline-solid -outline-offset-2 outline-ds-border-focused", isDisabled && "border-transparent bg-ds-background-disabled text-ds-text-disabled"), children: code[index] !== undefined && (
|
|
84
|
+
// A typed digit pops into its box (no pop under reduced motion).
|
|
85
|
+
_jsx("span", { "data-slot": "otp-field-digit", className: "transition-[scale,opacity] duration-(--ds-duration-fast) ease-ds-enter starting:scale-75 starting:opacity-0 motion-reduce:transition-none", children: code[index] }, code[index])) })] }, index))), _jsx("span", { "aria-hidden": "true", "data-slot": "otp-field-caret", "data-index": active, "data-visible": focused && code.length < length && !isDisabled ? true : undefined, style: { translate: `${caret.x}px -50%` }, className: cn("pointer-events-none absolute start-0 top-1/2 h-5 w-px -ms-px bg-ds-text opacity-0", "transition-[translate] duration-(--ds-duration-fast) ease-ds-standard motion-reduce:transition-none", "data-[visible]:opacity-100 data-[visible]:animate-pulse motion-reduce:data-[visible]:animate-none") })] }), description && _jsx(FieldDescription, { children: description }), _jsx(FieldError, { children: errorMessage })] })) }));
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Where the caret goes: the centre of the active box, in px from the row's start (the row is always LTR). Measured
|
|
89
|
+
* after layout and again when the row resizes, since the boxes shrink on a narrow phone.
|
|
90
|
+
*/
|
|
91
|
+
function useCaretOffset(active, length) {
|
|
92
|
+
const row = React.useRef(null);
|
|
93
|
+
const [x, setX] = React.useState(0);
|
|
94
|
+
React.useLayoutEffect(() => {
|
|
95
|
+
const element = row.current;
|
|
96
|
+
if (!element)
|
|
97
|
+
return;
|
|
98
|
+
const measure = () => {
|
|
99
|
+
const box = element.querySelector(`[data-slot="otp-field-box"][data-index="${active}"]`);
|
|
100
|
+
if (box)
|
|
101
|
+
setX(box.offsetLeft + box.offsetWidth / 2);
|
|
102
|
+
};
|
|
103
|
+
measure();
|
|
104
|
+
if (typeof ResizeObserver === "undefined")
|
|
105
|
+
return;
|
|
106
|
+
const observer = new ResizeObserver(measure);
|
|
107
|
+
observer.observe(element);
|
|
108
|
+
return () => observer.disconnect();
|
|
109
|
+
}, [active, length]);
|
|
110
|
+
return { row, x };
|
|
111
|
+
}
|
|
112
|
+
/** OtpField with its own `motion` (auto, reduce or none) for the sliding, blinking caret and the digit pop. */
|
|
113
|
+
export const OtpField = React.forwardRef(function OtpField({ motion, ...props }, ref) {
|
|
114
|
+
return (_jsx(MotionScope, { motion: motion, children: _jsx(OtpFieldBody, { ref: ref, ...props }) }));
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=otp-field.js.map
|