@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,178 @@
|
|
|
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 { FieldError as AriaFieldError, FieldErrorContext, Label, Text, useLocale } from "react-aria-components";
|
|
5
|
+
import { IconGlyph } from "../display/icon.js";
|
|
6
|
+
import { optionalLabel } from "../i18n.js";
|
|
7
|
+
import { DESCRIPTION, ERROR, LABEL, OPTIONAL_MARK, REQUIRED_MARK } from "./styles.js";
|
|
8
|
+
/**
|
|
9
|
+
* The visible label above a field. Inside a React Aria field it is wired to
|
|
10
|
+
* the control automatically (`aria-labelledby` / `for`).
|
|
11
|
+
*/
|
|
12
|
+
export function FieldLabel({ children, isRequired, isOptional }) {
|
|
13
|
+
const { locale } = useLocale();
|
|
14
|
+
return (_jsxs(Label, { "data-slot": "field-label", className: LABEL, children: [children, isRequired && (_jsx("span", { "aria-hidden": "true", "data-slot": "field-required", className: REQUIRED_MARK, children: "*" })), isOptional && !isRequired && (_jsx("span", { "data-slot": "field-optional", className: OPTIONAL_MARK, children: optionalLabel(locale) }))] }));
|
|
15
|
+
}
|
|
16
|
+
/** `aria-invalid` as a form row hands it down (`true` or `"true"`); anything else leaves the field as it is. */
|
|
17
|
+
export function isAriaInvalid(value) {
|
|
18
|
+
return value === true || value === "true";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A form row's `aria-invalid` (the shared `Field` hands it down) is the row's verdict, not the field's own: it
|
|
22
|
+
* marks the field for assistive tech and draws it invalid, and stays out of React Aria's validation state
|
|
23
|
+
*. As React Aria's `isInvalid` it became the field's custom validity ("Invalid value.") under
|
|
24
|
+
* `validationBehavior="native"`, React Aria's default outside a DS Form, so a form without `noValidate` silently
|
|
25
|
+
* refused every submit until the row's error went away. The field's own validation (`isRequired`, `validate`,
|
|
26
|
+
* `requiredValidation`) and an explicit `isInvalid` are untouched and keep their own native behaviour.
|
|
27
|
+
*
|
|
28
|
+
* The control spreads `fieldProps` on its React Aria field (after its own props; a consumer's `render` is kept),
|
|
29
|
+
* draws its frame and input invalid when `invalid` is set, and renders its error row through
|
|
30
|
+
* {@link ControlFieldError}; together they give the DOM `isInvalid` gave.
|
|
31
|
+
*/
|
|
32
|
+
export function forwardedInvalid(ariaInvalid, render) {
|
|
33
|
+
const invalid = isAriaInvalid(ariaInvalid);
|
|
34
|
+
if (!invalid)
|
|
35
|
+
return { invalid, fieldProps: null };
|
|
36
|
+
// The root's `data-invalid` (the `group-data-[invalid]` styles), set where React Aria sets it from its own state.
|
|
37
|
+
const markInvalid = (props, values) => {
|
|
38
|
+
const marked = { ...props, "data-invalid": true };
|
|
39
|
+
return render ? render(marked, values) : _jsx("div", { ...marked });
|
|
40
|
+
};
|
|
41
|
+
// The error row it shows or hides is linked by {@link useErrorRowLink}, which the control spreads after these.
|
|
42
|
+
return { invalid, fieldProps: { render: markInvalid } };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Keeps the control's own error row in `aria-describedby` whenever it shows (,
|
|
46
|
+
*). React Aria re-reads which description and error ids are in the DOM (useField → useSlotId) only when
|
|
47
|
+
* its `description`, `errorMessage` or own invalid state changes. The DS draws the error row itself, from its
|
|
48
|
+
* `errorMessage` prop and a forwarded `aria-invalid`, neither of which React Aria sees (its `errorMessage` flag is
|
|
49
|
+
* always set, by its own empty error list), so a message that came or went while the field stayed invalid (a
|
|
50
|
+
* forwarded `aria-invalid`, or `isInvalid`) was shown unlinked, never read. The control spreads the result on its
|
|
51
|
+
* React Aria field: `description` flips each time the forwarded state or the presence of a message changes, which
|
|
52
|
+
* makes React Aria re-read the ids. React Aria renders nothing from `description` (the DS draws its own) and only
|
|
53
|
+
* its truth is read, so the DOM is the one React Aria gives for the row as it stands.
|
|
54
|
+
*/
|
|
55
|
+
export function useErrorRowLink(forwarded, errorMessage) {
|
|
56
|
+
const signature = `${forwarded}:${hasContent(errorMessage)}`;
|
|
57
|
+
const seen = React.useRef({ signature, flip: false });
|
|
58
|
+
if (seen.current.signature !== signature)
|
|
59
|
+
seen.current = { signature, flip: !seen.current.flip };
|
|
60
|
+
return { description: seen.current.flip };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Content worth rendering (a message, a description, an icon): `0` counts; `null`, `undefined`, a boolean,
|
|
64
|
+
* `""`, and an array or fragment holding only those (`<></>`) do not. The one check FieldError and the
|
|
65
|
+
* choice rows, list items and tags share.
|
|
66
|
+
*/
|
|
67
|
+
export function hasContent(node) {
|
|
68
|
+
if (node === undefined || node === null || typeof node === "boolean" || node === "")
|
|
69
|
+
return false;
|
|
70
|
+
if (Array.isArray(node))
|
|
71
|
+
return node.some(hasContent);
|
|
72
|
+
if (React.isValidElement(node) && node.type === React.Fragment)
|
|
73
|
+
return hasContent(node.props.children);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The text a label shows a screen reader: its text without what is hidden from one (an `aria-hidden` required
|
|
78
|
+
* mark, a `hidden` or `display: none` / `visibility: hidden` part), so "Country <span aria-hidden>*</span>" names
|
|
79
|
+
* the field "Country".
|
|
80
|
+
*/
|
|
81
|
+
function visibleText(node) {
|
|
82
|
+
if (node.nodeType === Node.TEXT_NODE)
|
|
83
|
+
return node.textContent ?? "";
|
|
84
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
85
|
+
return "";
|
|
86
|
+
const element = node;
|
|
87
|
+
if (element.getAttribute("aria-hidden") === "true" || element.hidden)
|
|
88
|
+
return "";
|
|
89
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
90
|
+
if (style && (style.display === "none" || style.visibility === "hidden"))
|
|
91
|
+
return "";
|
|
92
|
+
let text = "";
|
|
93
|
+
for (const child of element.childNodes)
|
|
94
|
+
text += visibleText(child);
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The field's name, as Select does it: a non-empty `aria-label` names the input and no
|
|
99
|
+
* visible label renders; an empty one counts as absent (no empty attribute), so a given `label` shows.
|
|
100
|
+
* With no name at all a development warning says so. With a visible label the DOM is as before.
|
|
101
|
+
* Neither of them but an `id`: an external `<label htmlFor={id}>` names the input, so no label
|
|
102
|
+
* of the field's own renders (an empty one would take over the name through aria-labelledby). React Aria only
|
|
103
|
+
* knows a name from its own label, aria-label or aria-labelledby (and warns otherwise), so the input also gets
|
|
104
|
+
* that name in React Aria's terms: aria-labelledby the external label when it has an id, else an aria-label of
|
|
105
|
+
* the label's text. The app's label is never changed. Before the label is read (the server render) the input
|
|
106
|
+
* points at `{id}-label`, which names nothing, so the native `for` binding names it until then. The warning
|
|
107
|
+
* comes only when nothing on the page labels the input.
|
|
108
|
+
*
|
|
109
|
+
* Shared by the DS controls that a form row may name from outside: ComboBox and PhoneField. `component` names the control in the warning. Not a public export.
|
|
110
|
+
*/
|
|
111
|
+
export function useFieldName(component, label, ariaLabel, labelledBy, id, input) {
|
|
112
|
+
const named = ariaLabel ? ariaLabel : undefined;
|
|
113
|
+
const external = named === undefined && label == null && !labelledBy && id !== undefined;
|
|
114
|
+
const showLabel = named === undefined && (ariaLabel === undefined || label != null) && !external;
|
|
115
|
+
const unnamed = named === undefined && label == null && !labelledBy;
|
|
116
|
+
// The external label's name for React Aria, read after render; `{id}-label` until it is known.
|
|
117
|
+
const [externalName, setExternalName] = React.useState();
|
|
118
|
+
React.useLayoutEffect(() => {
|
|
119
|
+
if (!external)
|
|
120
|
+
return;
|
|
121
|
+
const labels = [...(input.current?.labels ?? [])];
|
|
122
|
+
const next = labels.length === 0
|
|
123
|
+
? undefined
|
|
124
|
+
: labels.every((element) => element.id)
|
|
125
|
+
? { "aria-labelledby": labels.map((element) => element.id).join(" ") }
|
|
126
|
+
: { "aria-label": labels.map((element) => visibleText(element).replace(/\s+/g, " ").trim()).filter(Boolean).join(" ") || undefined };
|
|
127
|
+
setExternalName((current) => current?.["aria-labelledby"] === next?.["aria-labelledby"] && current?.["aria-label"] === next?.["aria-label"] ? current : next);
|
|
128
|
+
});
|
|
129
|
+
React.useEffect(() => {
|
|
130
|
+
if (process.env.NODE_ENV === "production" || !unnamed)
|
|
131
|
+
return;
|
|
132
|
+
if (external && (input.current?.labels?.length ?? 0) > 0)
|
|
133
|
+
return;
|
|
134
|
+
console.warn(`${component}: no accessible name. Give a label, or a non-empty aria-label where the context names the field.`);
|
|
135
|
+
}, [component, unnamed, external]);
|
|
136
|
+
const externalNameProps = external ? (externalName ?? { "aria-labelledby": `${id}-label` }) : {};
|
|
137
|
+
return { named, showLabel, externalNameProps };
|
|
138
|
+
}
|
|
139
|
+
/** Help text under a field; React Aria adds it to the control's `aria-describedby`. */
|
|
140
|
+
export function FieldDescription({ children }) {
|
|
141
|
+
return (_jsx(Text, { slot: "description", "data-slot": "field-description", className: DESCRIPTION, children: children }));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The inline error: what happened and what to do. Renders only while the
|
|
145
|
+
* field is invalid; React Aria adds it to `aria-describedby`. A specific
|
|
146
|
+
* message from `validate`, `isRequired` or the server wins over the field's
|
|
147
|
+
* static `errorMessage`, which is the fallback for `isInvalid`.
|
|
148
|
+
*
|
|
149
|
+
* Invalid with no message at all (`isInvalid`, or a form row's `aria-invalid`, whose own error text sits
|
|
150
|
+
* outside the field) renders no row: no lone icon, and nothing for `aria-describedby` to point at
|
|
151
|
+
*. With a message it renders and is announced as before.
|
|
152
|
+
*/
|
|
153
|
+
export function FieldError({ children }) {
|
|
154
|
+
const validation = React.useContext(FieldErrorContext);
|
|
155
|
+
const hasMessage = Boolean(validation?.validationErrors.length) || hasContent(children);
|
|
156
|
+
if (validation?.isInvalid && !hasMessage)
|
|
157
|
+
return null;
|
|
158
|
+
return (_jsx(AriaFieldError, { "data-slot": "field-error", className: ERROR, children: (validation) => _jsx(FieldErrorContent, { children: validation.validationErrors.length ? validation.validationErrors.join(" ") : children }) }));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The error row's content: the circle-alert icon (hidden from screen readers) and the message. FieldError and a lone
|
|
162
|
+
* Checkbox's error row (choice-text.tsx) draw it the same way. Not a public export.
|
|
163
|
+
*/
|
|
164
|
+
export function FieldErrorContent({ children }) {
|
|
165
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconGlyph, { name: "circle-alert", "data-slot": "field-error-icon" }), _jsx("span", { children: children })] }));
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* A control's own error row ({@link FieldError}) that a form row's forwarded `aria-invalid` also shows, as
|
|
169
|
+
* `isInvalid` would, without entering React Aria's validation state.
|
|
170
|
+
* Not a public export: the DS controls that honour the forwarded state use it.
|
|
171
|
+
*/
|
|
172
|
+
export function ControlFieldError({ forwardedInvalid, children }) {
|
|
173
|
+
const validation = React.useContext(FieldErrorContext);
|
|
174
|
+
if (!forwardedInvalid || !validation || validation.isInvalid)
|
|
175
|
+
return _jsx(FieldError, { children: children });
|
|
176
|
+
return (_jsx(FieldErrorContext.Provider, { value: { ...validation, isInvalid: true }, children: _jsx(FieldError, { children: children }) }));
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=field-parts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-parts.js","sourceRoot":"","sources":["../../src/form/field-parts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KA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CAAC,EAAE,QAAQ,EAAkC;IAC5E,OAAO,CACL,8BACE,KAAC,SAAS,IAAC,IAAI,EAAC,cAAc,eAAW,kBAAkB,GAAG,EAC9D,yBAAO,QAAQ,GAAQ,IACtB,CACJ,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAA6D;IACzH,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IACvD,IAAI,CAAC,gBAAgB,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,SAAS;QAAE,OAAO,KAAC,UAAU,cAAE,QAAQ,GAAc,CAAC;IACzG,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,YACnE,KAAC,UAAU,cAAE,QAAQ,GAAc,GACR,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { FieldError as AriaFieldError, FieldErrorContext, Label, Text, useLocale } from \"react-aria-components\";\nimport { IconGlyph } from \"../display/icon\";\n\nimport { optionalLabel } from \"../i18n\";\nimport { DESCRIPTION, ERROR, LABEL, OPTIONAL_MARK, REQUIRED_MARK } from \"./styles\";\n\nexport type FieldLabelProps = {\n children: React.ReactNode;\n /** Shows `*` in `ds-text-danger` (hidden from screen readers: the control is `aria-required`). */\n isRequired?: boolean;\n /** Shows \"(optional)\" in the provider locale; use it when most fields of the form are required. */\n isOptional?: boolean;\n};\n\n/**\n * The visible label above a field. Inside a React Aria field it is wired to\n * the control automatically (`aria-labelledby` / `for`).\n */\nexport function FieldLabel({ children, isRequired, isOptional }: FieldLabelProps) {\n const { locale } = useLocale();\n return (\n <Label data-slot=\"field-label\" className={LABEL}>\n {children}\n {isRequired && (\n <span aria-hidden=\"true\" data-slot=\"field-required\" className={REQUIRED_MARK}>\n *\n </span>\n )}\n {isOptional && !isRequired && (\n <span data-slot=\"field-optional\" className={OPTIONAL_MARK}>\n {optionalLabel(locale)}\n </span>\n )}\n </Label>\n );\n}\n\n/** `aria-invalid` as a form row hands it down (`true` or `\"true\"`); anything else leaves the field as it is. */\nexport function isAriaInvalid(value: unknown): boolean {\n return value === true || value === \"true\";\n}\n\ntype RootRender<V> = (props: React.JSX.IntrinsicElements[\"div\"], values: V) => React.ReactElement;\n\n/**\n * A form row's `aria-invalid` (the shared `Field` hands it down) is the row's verdict, not the field's own: it\n * marks the field for assistive tech and draws it invalid, and stays out of React Aria's validation state\n *. As React Aria's `isInvalid` it became the field's custom validity (\"Invalid value.\") under\n * `validationBehavior=\"native\"`, React Aria's default outside a DS Form, so a form without `noValidate` silently\n * refused every submit until the row's error went away. The field's own validation (`isRequired`, `validate`,\n * `requiredValidation`) and an explicit `isInvalid` are untouched and keep their own native behaviour.\n *\n * The control spreads `fieldProps` on its React Aria field (after its own props; a consumer's `render` is kept),\n * draws its frame and input invalid when `invalid` is set, and renders its error row through\n * {@link ControlFieldError}; together they give the DOM `isInvalid` gave.\n */\nexport function forwardedInvalid<V>(ariaInvalid: unknown, render?: RootRender<V>) {\n const invalid = isAriaInvalid(ariaInvalid);\n if (!invalid) return { invalid, fieldProps: null };\n // The root's `data-invalid` (the `group-data-[invalid]` styles), set where React Aria sets it from its own state.\n const markInvalid: RootRender<V> = (props, values) => {\n const marked = { ...props, \"data-invalid\": true };\n return render ? render(marked, values) : <div {...marked} />;\n };\n // The error row it shows or hides is linked by {@link useErrorRowLink}, which the control spreads after these.\n return { invalid, fieldProps: { render: markInvalid } };\n}\n\n/**\n * Keeps the control's own error row in `aria-describedby` whenever it shows (,\n *). React Aria re-reads which description and error ids are in the DOM (useField → useSlotId) only when\n * its `description`, `errorMessage` or own invalid state changes. The DS draws the error row itself, from its\n * `errorMessage` prop and a forwarded `aria-invalid`, neither of which React Aria sees (its `errorMessage` flag is\n * always set, by its own empty error list), so a message that came or went while the field stayed invalid (a\n * forwarded `aria-invalid`, or `isInvalid`) was shown unlinked, never read. The control spreads the result on its\n * React Aria field: `description` flips each time the forwarded state or the presence of a message changes, which\n * makes React Aria re-read the ids. React Aria renders nothing from `description` (the DS draws its own) and only\n * its truth is read, so the DOM is the one React Aria gives for the row as it stands.\n */\nexport function useErrorRowLink(forwarded: boolean, errorMessage: React.ReactNode) {\n const signature = `${forwarded}:${hasContent(errorMessage)}`;\n const seen = React.useRef({ signature, flip: false });\n if (seen.current.signature !== signature) seen.current = { signature, flip: !seen.current.flip };\n return { description: seen.current.flip };\n}\n\n/**\n * Content worth rendering (a message, a description, an icon): `0` counts; `null`, `undefined`, a boolean,\n * `\"\"`, and an array or fragment holding only those (`<></>`) do not. The one check FieldError and the\n * choice rows, list items and tags share.\n */\nexport function hasContent(node: React.ReactNode): boolean {\n if (node === undefined || node === null || typeof node === \"boolean\" || node === \"\") return false;\n if (Array.isArray(node)) return node.some(hasContent);\n if (React.isValidElement<{ children?: React.ReactNode }>(node) && node.type === React.Fragment) return hasContent(node.props.children);\n return true;\n}\n\n/**\n * The text a label shows a screen reader: its text without what is hidden from one (an `aria-hidden` required\n * mark, a `hidden` or `display: none` / `visibility: hidden` part), so \"Country <span aria-hidden>*</span>\" names\n * the field \"Country\".\n */\nfunction visibleText(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? \"\";\n if (node.nodeType !== Node.ELEMENT_NODE) return \"\";\n const element = node as HTMLElement;\n if (element.getAttribute(\"aria-hidden\") === \"true\" || element.hidden) return \"\";\n const style = element.ownerDocument.defaultView?.getComputedStyle(element);\n if (style && (style.display === \"none\" || style.visibility === \"hidden\")) return \"\";\n let text = \"\";\n for (const child of element.childNodes) text += visibleText(child);\n return text;\n}\n\n/**\n * The field's name, as Select does it: a non-empty `aria-label` names the input and no\n * visible label renders; an empty one counts as absent (no empty attribute), so a given `label` shows.\n * With no name at all a development warning says so. With a visible label the DOM is as before.\n * Neither of them but an `id`: an external `<label htmlFor={id}>` names the input, so no label\n * of the field's own renders (an empty one would take over the name through aria-labelledby). React Aria only\n * knows a name from its own label, aria-label or aria-labelledby (and warns otherwise), so the input also gets\n * that name in React Aria's terms: aria-labelledby the external label when it has an id, else an aria-label of\n * the label's text. The app's label is never changed. Before the label is read (the server render) the input\n * points at `{id}-label`, which names nothing, so the native `for` binding names it until then. The warning\n * comes only when nothing on the page labels the input.\n *\n * Shared by the DS controls that a form row may name from outside: ComboBox and PhoneField. `component` names the control in the warning. Not a public export.\n */\nexport function useFieldName(\n component: string,\n label: React.ReactNode,\n ariaLabel: string | undefined,\n labelledBy: string | undefined,\n id: string | undefined,\n input: React.RefObject<HTMLInputElement | null>,\n) {\n const named = ariaLabel ? ariaLabel : undefined;\n const external = named === undefined && label == null && !labelledBy && id !== undefined;\n const showLabel = named === undefined && (ariaLabel === undefined || label != null) && !external;\n const unnamed = named === undefined && label == null && !labelledBy;\n // The external label's name for React Aria, read after render; `{id}-label` until it is known.\n const [externalName, setExternalName] = React.useState<{ \"aria-labelledby\"?: string; \"aria-label\"?: string } | undefined>();\n React.useLayoutEffect(() => {\n if (!external) return;\n const labels = [...(input.current?.labels ?? [])];\n const next = labels.length === 0\n ? undefined\n : labels.every((element) => element.id)\n ? { \"aria-labelledby\": labels.map((element) => element.id).join(\" \") }\n : { \"aria-label\": labels.map((element) => visibleText(element).replace(/\\s+/g, \" \").trim()).filter(Boolean).join(\" \") || undefined };\n setExternalName((current) =>\n current?.[\"aria-labelledby\"] === next?.[\"aria-labelledby\"] && current?.[\"aria-label\"] === next?.[\"aria-label\"] ? current : next,\n );\n });\n React.useEffect(() => {\n if (process.env.NODE_ENV === \"production\" || !unnamed) return;\n if (external && (input.current?.labels?.length ?? 0) > 0) return;\n console.warn(`${component}: no accessible name. Give a label, or a non-empty aria-label where the context names the field.`);\n }, [component, unnamed, external]);\n const externalNameProps = external ? (externalName ?? { \"aria-labelledby\": `${id}-label` }) : {};\n return { named, showLabel, externalNameProps };\n}\n\n/** Help text under a field; React Aria adds it to the control's `aria-describedby`. */\nexport function FieldDescription({ children }: { children: React.ReactNode }) {\n return (\n <Text slot=\"description\" data-slot=\"field-description\" className={DESCRIPTION}>\n {children}\n </Text>\n );\n}\n\n/**\n * The inline error: what happened and what to do. Renders only while the\n * field is invalid; React Aria adds it to `aria-describedby`. A specific\n * message from `validate`, `isRequired` or the server wins over the field's\n * static `errorMessage`, which is the fallback for `isInvalid`.\n *\n * Invalid with no message at all (`isInvalid`, or a form row's `aria-invalid`, whose own error text sits\n * outside the field) renders no row: no lone icon, and nothing for `aria-describedby` to point at\n *. With a message it renders and is announced as before.\n */\nexport function FieldError({ children }: { children?: React.ReactNode }) {\n const validation = React.useContext(FieldErrorContext);\n const hasMessage = Boolean(validation?.validationErrors.length) || hasContent(children);\n if (validation?.isInvalid && !hasMessage) return null;\n return (\n <AriaFieldError data-slot=\"field-error\" className={ERROR}>\n {(validation) => <FieldErrorContent>{validation.validationErrors.length ? validation.validationErrors.join(\" \") : children}</FieldErrorContent>}\n </AriaFieldError>\n );\n}\n\n/**\n * The error row's content: the circle-alert icon (hidden from screen readers) and the message. FieldError and a lone\n * Checkbox's error row (choice-text.tsx) draw it the same way. Not a public export.\n */\nexport function FieldErrorContent({ children }: { children?: React.ReactNode }) {\n return (\n <>\n <IconGlyph name=\"circle-alert\" data-slot=\"field-error-icon\" />\n <span>{children}</span>\n </>\n );\n}\n\n/**\n * A control's own error row ({@link FieldError}) that a form row's forwarded `aria-invalid` also shows, as\n * `isInvalid` would, without entering React Aria's validation state.\n * Not a public export: the DS controls that honour the forwarded state use it.\n */\nexport function ControlFieldError({ forwardedInvalid, children }: { forwardedInvalid: boolean; children?: React.ReactNode }) {\n const validation = React.useContext(FieldErrorContext);\n if (!forwardedInvalid || !validation || validation.isInvalid) return <FieldError>{children}</FieldError>;\n return (\n <FieldErrorContext.Provider value={{ ...validation, isInvalid: true }}>\n <FieldError>{children}</FieldError>\n </FieldErrorContext.Provider>\n );\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Form field wrapper: consistent label + control spacing, optional hint and
|
|
4
|
+
* error message, around a control the app brings (a native input or a
|
|
5
|
+
* library control).
|
|
6
|
+
*
|
|
7
|
+
* Wires label↔control (`htmlFor` / `id`) and hint/error copy onto the control
|
|
8
|
+
* via `aria-describedby` / `aria-invalid` so screen readers hear validation.
|
|
9
|
+
* Prefer passing `htmlFor` (and matching control `id`) for native inputs; when
|
|
10
|
+
* omitted, Field generates an id and injects it onto a single-element child.
|
|
11
|
+
* The label's own id is `{controlId}-label`, so a composite control can point
|
|
12
|
+
* `aria-labelledby` at it (the DS ComboBox does with an external label); a DS
|
|
13
|
+
* control handed `aria-invalid` shows its invalid state, and with no
|
|
14
|
+
* `errorMessage` of its own no second error row. That state is
|
|
15
|
+
* for assistive tech and styling only: it never becomes the control's native
|
|
16
|
+
* validity, so a form without `noValidate` still submits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Field({ label, htmlFor, errorMessage: error, description: hint, isRequired: required, requiredClassName, children, className, }: {
|
|
19
|
+
label?: ReactNode;
|
|
20
|
+
/** Control id for the label. Optional: when omitted, Field generates one and
|
|
21
|
+
* injects it onto a single-element child. Field is for a control the library does not
|
|
22
|
+
* provide (a native input, a third-party widget) and for `InputGroup` with `InputGroupInput`,
|
|
23
|
+
* which forwards it to its input. The library's own fields (TextField, Select…) carry their
|
|
24
|
+
* own label, hint and error, so they do not go inside a Field. */
|
|
25
|
+
htmlFor?: string;
|
|
26
|
+
/** What went wrong and what to do; shown under the control and announced. */
|
|
27
|
+
errorMessage?: ReactNode;
|
|
28
|
+
/** A line of help under the control (hidden while there is an error). */
|
|
29
|
+
description?: ReactNode;
|
|
30
|
+
isRequired?: boolean;
|
|
31
|
+
/** Class for the required "*" asterisk. Defaults to the danger text token; a brand
|
|
32
|
+
* marketing form can override it without forking this component. */
|
|
33
|
+
requiredClassName?: string;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
className?: string;
|
|
36
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Children, cloneElement, isValidElement, useId, } from "react";
|
|
4
|
+
import { cn } from "../utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Form field wrapper: consistent label + control spacing, optional hint and
|
|
7
|
+
* error message, around a control the app brings (a native input or a
|
|
8
|
+
* library control).
|
|
9
|
+
*
|
|
10
|
+
* Wires label↔control (`htmlFor` / `id`) and hint/error copy onto the control
|
|
11
|
+
* via `aria-describedby` / `aria-invalid` so screen readers hear validation.
|
|
12
|
+
* Prefer passing `htmlFor` (and matching control `id`) for native inputs; when
|
|
13
|
+
* omitted, Field generates an id and injects it onto a single-element child.
|
|
14
|
+
* The label's own id is `{controlId}-label`, so a composite control can point
|
|
15
|
+
* `aria-labelledby` at it (the DS ComboBox does with an external label); a DS
|
|
16
|
+
* control handed `aria-invalid` shows its invalid state, and with no
|
|
17
|
+
* `errorMessage` of its own no second error row. That state is
|
|
18
|
+
* for assistive tech and styling only: it never becomes the control's native
|
|
19
|
+
* validity, so a form without `noValidate` still submits.
|
|
20
|
+
*/
|
|
21
|
+
export function Field({ label, htmlFor, errorMessage: error, description: hint, isRequired: required, requiredClassName, children, className, }) {
|
|
22
|
+
const autoId = useId();
|
|
23
|
+
const controlId = htmlFor ?? (label ? autoId : undefined);
|
|
24
|
+
const hintId = hint && !error ? `${autoId}-hint` : undefined;
|
|
25
|
+
const errorId = error ? `${autoId}-error` : undefined;
|
|
26
|
+
const describedBy = [hintId, errorId].filter(Boolean).join(" ") || undefined;
|
|
27
|
+
return (_jsxs("div", { className: cn("space-y-ds-075", className), children: [label && (
|
|
28
|
+
// `{controlId}-label`, so a control can name itself by the label with aria-labelledby.
|
|
29
|
+
_jsxs(FieldRowLabel, { htmlFor: controlId, id: controlId ? `${controlId}-label` : undefined, children: [label, required && (_jsx("span", { className: cn("ms-0.5", requiredClassName ?? "text-ds-text-danger"), children: "*" }))] })), enhanceControl(children, {
|
|
30
|
+
controlId,
|
|
31
|
+
describedBy,
|
|
32
|
+
invalid: Boolean(error),
|
|
33
|
+
}), hint && !error && hintId ? (_jsx("p", { id: hintId, className: "text-body-small text-ds-text-subtle", children: hint })) : null, error && errorId ? (_jsx("p", { id: errorId, className: "text-body-small text-ds-text-danger", children: error })) : null] }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Field's label. A double click on the label text does not select it (a click
|
|
37
|
+
* on a control inside the label is left alone).
|
|
38
|
+
*/
|
|
39
|
+
const FIELD_LABEL_CLASS = "flex items-center gap-ds-100 text-body-strong text-ds-text select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50";
|
|
40
|
+
function FieldRowLabel({ htmlFor, id, children }) {
|
|
41
|
+
return (_jsx("label", { "data-slot": "label", className: cn(FIELD_LABEL_CLASS), htmlFor: htmlFor, id: id, onMouseDown: (event) => {
|
|
42
|
+
if (event.target.closest("button, input, select, textarea"))
|
|
43
|
+
return;
|
|
44
|
+
if (!event.defaultPrevented && event.detail > 1)
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
}, children: children }));
|
|
47
|
+
}
|
|
48
|
+
function enhanceControl(children, { controlId, describedBy, invalid, }) {
|
|
49
|
+
const child = Children.count(children) === 1 ? Children.only(children) : null;
|
|
50
|
+
if (!isValidElement(child))
|
|
51
|
+
return children;
|
|
52
|
+
const element = child;
|
|
53
|
+
const existingDescribedBy = typeof element.props["aria-describedby"] === "string"
|
|
54
|
+
? element.props["aria-describedby"]
|
|
55
|
+
: undefined;
|
|
56
|
+
const mergedDescribedBy = [existingDescribedBy, describedBy]
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(" ") || undefined;
|
|
59
|
+
return cloneElement(element, {
|
|
60
|
+
...(controlId && element.props.id == null ? { id: controlId } : null),
|
|
61
|
+
...(mergedDescribedBy ? { "aria-describedby": mergedDescribedBy } : null),
|
|
62
|
+
...(invalid ? { "aria-invalid": true } : null),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/form/field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,KAAK,GAIN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,KAAK,CAAC,EACpB,KAAK,EACL,OAAO,EACP,YAAY,EAAE,KAAK,EACnB,WAAW,EAAE,IAAI,EACjB,UAAU,EAAE,QAAQ,EACpB,iBAAiB,EACjB,QAAQ,EACR,SAAS,GAmBV;IACC,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;IACvB,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IAE7E,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,aAC5C,KAAK,IAAI;YACR,uFAAuF;YAC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;AAED,SAAS,cAAc,CACrB,QAAmB,EACnB,EACE,SAAS,EACT,WAAW,EACX,OAAO,GAKR;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9E,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAE5C,MAAM,OAAO,GAAG,KAA8C,CAAC;IAC/D,MAAM,mBAAmB,GACvB,OAAO,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,KAAK,QAAQ;QACnD,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC;QACnC,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,iBAAiB,GAAG,CAAC,mBAAmB,EAAE,WAAW,CAAC;SACzD,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IAE1B,OAAO,YAAY,CAAC,OAAO,EAAE;QAC3B,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACrE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACzE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;KAC/C,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\nimport {\n Children,\n cloneElement,\n isValidElement,\n useId,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { cn } from \"../utils\";\n\n/**\n * Form field wrapper: consistent label + control spacing, optional hint and\n * error message, around a control the app brings (a native input or a\n * library control).\n *\n * Wires label↔control (`htmlFor` / `id`) and hint/error copy onto the control\n * via `aria-describedby` / `aria-invalid` so screen readers hear validation.\n * Prefer passing `htmlFor` (and matching control `id`) for native inputs; when\n * omitted, Field generates an id and injects it onto a single-element child.\n * The label's own id is `{controlId}-label`, so a composite control can point\n * `aria-labelledby` at it (the DS ComboBox does with an external label); a DS\n * control handed `aria-invalid` shows its invalid state, and with no\n * `errorMessage` of its own no second error row. That state is\n * for assistive tech and styling only: it never becomes the control's native\n * validity, so a form without `noValidate` still submits.\n */\nexport function Field({\n label,\n htmlFor,\n errorMessage: error,\n description: hint,\n isRequired: required,\n requiredClassName,\n children,\n className,\n}: {\n label?: ReactNode;\n /** Control id for the label. Optional: when omitted, Field generates one and\n * injects it onto a single-element child. Field is for a control the library does not\n * provide (a native input, a third-party widget) and for `InputGroup` with `InputGroupInput`,\n * which forwards it to its input. The library's own fields (TextField, Select…) carry their\n * own label, hint and error, so they do not go inside a Field. */\n htmlFor?: string;\n /** What went wrong and what to do; shown under the control and announced. */\n errorMessage?: ReactNode;\n /** A line of help under the control (hidden while there is an error). */\n description?: ReactNode;\n isRequired?: boolean;\n /** Class for the required \"*\" asterisk. Defaults to the danger text token; a brand\n * marketing form can override it without forking this component. */\n requiredClassName?: string;\n children: ReactNode;\n className?: string;\n}) {\n const autoId = useId();\n const controlId = htmlFor ?? (label ? autoId : undefined);\n const hintId = hint && !error ? `${autoId}-hint` : undefined;\n const errorId = error ? `${autoId}-error` : undefined;\n const describedBy = [hintId, errorId].filter(Boolean).join(\" \") || undefined;\n\n return (\n <div className={cn(\"space-y-ds-075\", className)}>\n {label && (\n // `{controlId}-label`, so a control can name itself by the label with aria-labelledby.\n <FieldRowLabel htmlFor={controlId} id={controlId ? `${controlId}-label` : undefined}>\n {label}\n {required && (\n <span className={cn(\"ms-0.5\", requiredClassName ?? \"text-ds-text-danger\")}>*</span>\n )}\n </FieldRowLabel>\n )}\n {enhanceControl(children, {\n controlId,\n describedBy,\n invalid: Boolean(error),\n })}\n {hint && !error && hintId ? (\n <p id={hintId} className=\"text-body-small text-ds-text-subtle\">\n {hint}\n </p>\n ) : null}\n {error && errorId ? (\n <p id={errorId} className=\"text-body-small text-ds-text-danger\">\n {error}\n </p>\n ) : null}\n </div>\n );\n}\n\n/**\n * Field's label. A double click on the label text does not select it (a click\n * on a control inside the label is left alone).\n */\nconst FIELD_LABEL_CLASS =\n \"flex items-center gap-ds-100 text-body-strong text-ds-text select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50\";\n\nfunction FieldRowLabel({ htmlFor, id, children }: { htmlFor?: string; id?: string; children: ReactNode }) {\n return (\n <label\n data-slot=\"label\"\n className={cn(FIELD_LABEL_CLASS)}\n htmlFor={htmlFor}\n id={id}\n onMouseDown={(event: MouseEvent<HTMLLabelElement>) => {\n if ((event.target as HTMLElement).closest(\"button, input, select, textarea\")) return;\n if (!event.defaultPrevented && event.detail > 1) event.preventDefault();\n }}\n >\n {children}\n </label>\n );\n}\n\nfunction enhanceControl(\n children: ReactNode,\n {\n controlId,\n describedBy,\n invalid,\n }: {\n controlId?: string;\n describedBy?: string;\n invalid: boolean;\n },\n): ReactNode {\n const child = Children.count(children) === 1 ? Children.only(children) : null;\n if (!isValidElement(child)) return children;\n\n const element = child as ReactElement<Record<string, unknown>>;\n const existingDescribedBy =\n typeof element.props[\"aria-describedby\"] === \"string\"\n ? element.props[\"aria-describedby\"]\n : undefined;\n const mergedDescribedBy = [existingDescribedBy, describedBy]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n return cloneElement(element, {\n ...(controlId && element.props.id == null ? { id: controlId } : null),\n ...(mergedDescribedBy ? { \"aria-describedby\": mergedDescribedBy } : null),\n ...(invalid ? { \"aria-invalid\": true } : null),\n });\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type DropItem, type FileTriggerProps as AriaFileTriggerProps } from "react-aria-components";
|
|
3
|
+
/** Bytes as the locale writes them: "2.4 MB", "980 kB". */
|
|
4
|
+
export declare function formatFileSize(bytes: number, locale: string): string;
|
|
5
|
+
export type FileRules = {
|
|
6
|
+
/** MIME types or extensions: "image/jpeg", "image/*", ".heic", "application/pdf". */
|
|
7
|
+
acceptedFileTypes?: readonly string[];
|
|
8
|
+
/** Bytes. */
|
|
9
|
+
maxSize?: number;
|
|
10
|
+
};
|
|
11
|
+
export type RejectedFile = {
|
|
12
|
+
file: File;
|
|
13
|
+
reason: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Checks each file on its own: a wrong type or a file over `maxSize` is
|
|
17
|
+
* rejected with the reason, and the others are kept (design rule).
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateFiles(files: readonly File[], rules: FileRules, locale: string): {
|
|
20
|
+
accepted: File[];
|
|
21
|
+
rejected: RejectedFile[];
|
|
22
|
+
};
|
|
23
|
+
export type FileTriggerProps = Omit<AriaFileTriggerProps, "onSelect" | "acceptedFileTypes"> & FileRules & {
|
|
24
|
+
/** Files that passed the rules. */
|
|
25
|
+
onSelect?: (files: File[]) => void;
|
|
26
|
+
/** Files that did not, each with its reason. */
|
|
27
|
+
onReject?: (rejected: RejectedFile[]) => void;
|
|
28
|
+
/** The control that opens the picker: a DS Button or Link. */
|
|
29
|
+
children: React.ReactElement;
|
|
30
|
+
};
|
|
31
|
+
/** Opens the system file picker from any button. */
|
|
32
|
+
export declare function FileTrigger({ onSelect, onReject, acceptedFileTypes, maxSize, children, ...rest }: FileTriggerProps): React.JSX.Element;
|
|
33
|
+
export type DropZoneProps = FileRules & {
|
|
34
|
+
/** What to drop, as a call to action: "Drag your photos here". */
|
|
35
|
+
label: string;
|
|
36
|
+
/** The accepted types as people read them ("JPG, PNG, HEIC"); the size limit is added. */
|
|
37
|
+
typesLabel?: string;
|
|
38
|
+
allowsMultiple?: boolean;
|
|
39
|
+
onSelect?: (files: File[]) => void;
|
|
40
|
+
onReject?: (rejected: RejectedFile[]) => void;
|
|
41
|
+
isDisabled?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** The files among dropped items; folders, text and files the browser cannot read are skipped. */
|
|
44
|
+
export declare function filesFrom(items: readonly DropItem[]): Promise<File[]>;
|
|
45
|
+
/**
|
|
46
|
+
* A drop target with the picker inside: states the accepted types and the
|
|
47
|
+
* size limit before the user picks; while a file is over it the zone takes
|
|
48
|
+
* the selected fill and border.
|
|
49
|
+
*/
|
|
50
|
+
export declare function DropZone({ label, typesLabel, allowsMultiple, acceptedFileTypes, maxSize, onSelect, onReject, isDisabled }: DropZoneProps): React.JSX.Element;
|
|
51
|
+
export type FileRowProps = {
|
|
52
|
+
/** The picked file; photos get a thumbnail at once, before upload ends. */
|
|
53
|
+
file?: File;
|
|
54
|
+
/** Shown name and size when there is no File object (a stored document). */
|
|
55
|
+
name?: string;
|
|
56
|
+
size?: number;
|
|
57
|
+
/** 0–1 while uploading; omit when done. */
|
|
58
|
+
progress?: number;
|
|
59
|
+
error?: string;
|
|
60
|
+
onCancel?: () => void;
|
|
61
|
+
onRemove?: () => void;
|
|
62
|
+
onReplace?: () => void;
|
|
63
|
+
};
|
|
64
|
+
/** One picked or stored file: thumbnail, name, progress or size, per-file error, one trailing action. */
|
|
65
|
+
export declare function FileRow({ file, name, size, progress, error, onCancel, onRemove, onReplace }: FileRowProps): React.JSX.Element;
|
|
66
|
+
/** The list of picked or stored files. */
|
|
67
|
+
export declare function FileUploadList({ children, "aria-label": ariaLabel }: {
|
|
68
|
+
children: React.ReactNode;
|
|
69
|
+
"aria-label"?: string;
|
|
70
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Button as AriaButton, DropZone as AriaDropZone, FileTrigger as AriaFileTrigger, useLocale, } from "react-aria-components";
|
|
5
|
+
import { IconGlyph } from "../display/icon.js";
|
|
6
|
+
import { cn } from "../utils.js";
|
|
7
|
+
import { cancelUploadLabel, chooseFilesLabel, onlyOneLabel, orChooseTemplate, removeFileLabel, replaceLabel, tooLargeLabel, upToLabel, uploadedLabel, wrongTypeLabel, } from "../i18n.js";
|
|
8
|
+
import { Button } from "../action/button.js";
|
|
9
|
+
import { LINK_FOCUS } from "../action/styles.js";
|
|
10
|
+
/** Bytes as the locale writes them: "2.4 MB", "980 kB". */
|
|
11
|
+
export function formatFileSize(bytes, locale) {
|
|
12
|
+
const units = ["byte", "kilobyte", "megabyte", "gigabyte"];
|
|
13
|
+
let value = bytes;
|
|
14
|
+
let unit = 0;
|
|
15
|
+
// Round the way the unit will print before choosing it, so 999,600 bytes is "1 MB", not "1.000 kB".
|
|
16
|
+
const rounded = () => (unit < 2 ? Math.round(value) : Math.round(value * 10) / 10);
|
|
17
|
+
while (rounded() >= 1000 && unit < units.length - 1) {
|
|
18
|
+
value /= 1000;
|
|
19
|
+
unit += 1;
|
|
20
|
+
}
|
|
21
|
+
return new Intl.NumberFormat(locale, {
|
|
22
|
+
style: "unit",
|
|
23
|
+
unit: units[unit],
|
|
24
|
+
unitDisplay: "short",
|
|
25
|
+
maximumFractionDigits: unit < 2 ? 0 : 1,
|
|
26
|
+
}).format(value);
|
|
27
|
+
}
|
|
28
|
+
function accepts(file, types) {
|
|
29
|
+
if (!types || types.length === 0)
|
|
30
|
+
return true;
|
|
31
|
+
const name = file.name.toLowerCase();
|
|
32
|
+
const type = file.type.toLowerCase();
|
|
33
|
+
return types.some((rule) => {
|
|
34
|
+
const pattern = rule.toLowerCase().trim();
|
|
35
|
+
if (pattern.startsWith("."))
|
|
36
|
+
return name.endsWith(pattern);
|
|
37
|
+
if (pattern.endsWith("/*"))
|
|
38
|
+
return type.startsWith(pattern.slice(0, -1));
|
|
39
|
+
return type === pattern;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks each file on its own: a wrong type or a file over `maxSize` is
|
|
44
|
+
* rejected with the reason, and the others are kept (design rule).
|
|
45
|
+
*/
|
|
46
|
+
export function validateFiles(files, rules, locale) {
|
|
47
|
+
const accepted = [];
|
|
48
|
+
const rejected = [];
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
if (!accepts(file, rules.acceptedFileTypes))
|
|
51
|
+
rejected.push({ file, reason: wrongTypeLabel(locale) });
|
|
52
|
+
else if (rules.maxSize !== undefined && file.size > rules.maxSize) {
|
|
53
|
+
rejected.push({ file, reason: tooLargeLabel(locale, formatFileSize(rules.maxSize, locale)) });
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
accepted.push(file);
|
|
57
|
+
}
|
|
58
|
+
return { accepted, rejected };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Hands the picked files on, then empties the picker's hidden input, so the same file picked again is
|
|
62
|
+
* a change and reaches the app again, however the input was filled. The files are copied
|
|
63
|
+
* out of the FileList before the callbacks run; clearing the input empties that list, not the copies.
|
|
64
|
+
*/
|
|
65
|
+
function pickThenClear(input, list, handle) {
|
|
66
|
+
const files = Array.from(list ?? []);
|
|
67
|
+
try {
|
|
68
|
+
handle(files);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
if (input.current)
|
|
72
|
+
input.current.value = "";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Opens the system file picker from any button. */
|
|
76
|
+
export function FileTrigger({ onSelect, onReject, acceptedFileTypes, maxSize, children, ...rest }) {
|
|
77
|
+
const { locale } = useLocale();
|
|
78
|
+
const inputRef = React.useRef(null);
|
|
79
|
+
return (_jsx(AriaFileTrigger, { ...rest, ref: inputRef, acceptedFileTypes: acceptedFileTypes ? [...acceptedFileTypes] : undefined, onSelect: (list) => pickThenClear(inputRef, list, (files) => {
|
|
80
|
+
const { accepted, rejected } = validateFiles(files, { acceptedFileTypes, maxSize }, locale);
|
|
81
|
+
if (accepted.length)
|
|
82
|
+
onSelect?.(accepted);
|
|
83
|
+
if (rejected.length)
|
|
84
|
+
onReject?.(rejected);
|
|
85
|
+
}), children: children }));
|
|
86
|
+
}
|
|
87
|
+
/** The files among dropped items; folders, text and files the browser cannot read are skipped. */
|
|
88
|
+
export async function filesFrom(items) {
|
|
89
|
+
const reads = items.flatMap((item) => (item.kind === "file" ? [item.getFile()] : []));
|
|
90
|
+
const results = await Promise.allSettled(reads);
|
|
91
|
+
return results.flatMap((result) => (result.status === "fulfilled" ? [result.value] : []));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A drop target with the picker inside: states the accepted types and the
|
|
95
|
+
* size limit before the user picks; while a file is over it the zone takes
|
|
96
|
+
* the selected fill and border.
|
|
97
|
+
*/
|
|
98
|
+
export function DropZone({ label, typesLabel, allowsMultiple, acceptedFileTypes, maxSize, onSelect, onReject, isDisabled }) {
|
|
99
|
+
const { locale } = useLocale();
|
|
100
|
+
const inputRef = React.useRef(null);
|
|
101
|
+
const handle = (files) => {
|
|
102
|
+
const list = allowsMultiple ? files : files.slice(0, 1);
|
|
103
|
+
const { accepted, rejected } = validateFiles(list, { acceptedFileTypes, maxSize }, locale);
|
|
104
|
+
// Extra files on a single-file zone are rejected with a reason, never dropped silently.
|
|
105
|
+
if (!allowsMultiple)
|
|
106
|
+
for (const file of files.slice(1))
|
|
107
|
+
rejected.push({ file, reason: onlyOneLabel(locale) });
|
|
108
|
+
if (accepted.length)
|
|
109
|
+
onSelect?.(accepted);
|
|
110
|
+
if (rejected.length)
|
|
111
|
+
onReject?.(rejected);
|
|
112
|
+
};
|
|
113
|
+
const [before, after] = orChooseTemplate(locale).split("{choose}");
|
|
114
|
+
const details = [typesLabel, maxSize !== undefined ? upToLabel(locale, formatFileSize(maxSize, locale)) : undefined]
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join(" · ");
|
|
117
|
+
return (_jsxs(AriaDropZone
|
|
118
|
+
// Names the zone's keyboard and paste target (React Aria's own fallback is the untranslated "DropZone").
|
|
119
|
+
, { "aria-label": label, isDisabled: isDisabled, onDrop: async (event) => handle(await filesFrom(event.items)), "data-slot": "drop-zone", className: cn("flex flex-col items-center justify-center gap-ds-100 rounded-ds-large border-[1.5px] border-dashed border-ds-border-bold bg-ds-surface-sunken p-ds-400 text-center outline-hidden", "data-[drop-target]:border-ds-border-selected data-[drop-target]:bg-ds-background-selected",
|
|
120
|
+
// Keyboard focus: the 2px inner border every DS control uses.
|
|
121
|
+
"data-[focus-visible]:inset-ring-2 data-[focus-visible]:inset-ring-ds-border-focused", "data-[disabled]:cursor-not-allowed data-[disabled]:border-ds-border data-[disabled]:bg-ds-background-disabled"), children: [_jsx(IconGlyph, { name: "image-up", size: "large", color: "subtle", "data-slot": "drop-zone-icon" }), _jsx("span", { "data-slot": "drop-zone-label", className: "text-body-strong text-ds-text", children: label }), _jsxs("span", { "data-slot": "drop-zone-help", className: "text-body-small text-ds-text-subtlest", children: [before, _jsx(AriaFileTrigger, { ref: inputRef, allowsMultiple: allowsMultiple, acceptedFileTypes: acceptedFileTypes ? [...acceptedFileTypes] : undefined, onSelect: (list) => pickThenClear(inputRef, list, handle), children: _jsx(AriaButton, { isDisabled: isDisabled, "data-slot": "drop-zone-choose", className: cn("cursor-pointer text-ds-link underline-offset-3 data-[hovered]:underline", "data-[disabled]:cursor-not-allowed data-[disabled]:text-ds-text-disabled data-[disabled]:no-underline", LINK_FOCUS), children: chooseFilesLabel(locale) }) }), after, details && ` · ${details}`] })] }));
|
|
122
|
+
}
|
|
123
|
+
/** A thumbnail URL for an image file, created in an effect and revoked on change or unmount. */
|
|
124
|
+
function useObjectUrl(file) {
|
|
125
|
+
const [url, setUrl] = React.useState();
|
|
126
|
+
React.useEffect(() => {
|
|
127
|
+
if (!file || !file.type.startsWith("image/") || typeof URL.createObjectURL !== "function") {
|
|
128
|
+
setUrl(undefined);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const next = URL.createObjectURL(file);
|
|
132
|
+
setUrl(next);
|
|
133
|
+
return () => URL.revokeObjectURL(next);
|
|
134
|
+
}, [file]);
|
|
135
|
+
return url;
|
|
136
|
+
}
|
|
137
|
+
/** One picked or stored file: thumbnail, name, progress or size, per-file error, one trailing action. */
|
|
138
|
+
export function FileRow({ file, name, size, progress, error, onCancel, onRemove, onReplace }) {
|
|
139
|
+
const { locale } = useLocale();
|
|
140
|
+
const url = useObjectUrl(file);
|
|
141
|
+
// A type the browser cannot draw (HEIC on most browsers) falls back to the file icon.
|
|
142
|
+
const [broken, setBroken] = React.useState();
|
|
143
|
+
const thumbnail = url && url !== broken ? url : undefined;
|
|
144
|
+
const total = size ?? file?.size;
|
|
145
|
+
const uploading = progress !== undefined && progress < 1 && !error;
|
|
146
|
+
return (_jsxs("li", { "data-slot": "file-row", "data-state": error ? "error" : uploading ? "uploading" : "done", className: "flex items-center gap-ds-150 rounded-ds-large bg-ds-surface-raised p-ds-100 pe-ds-150 shadow-ds-raised", children: [_jsx("span", { "data-slot": "file-thumbnail", className: "grid size-10 shrink-0 place-items-center overflow-hidden rounded-ds-medium bg-ds-surface-sunken", children: thumbnail ? _jsx("img", { src: thumbnail, alt: "", onError: () => setBroken(thumbnail), className: "size-full object-cover" }) : _jsx(IconGlyph, { name: error ? "file-exclamation-point" : "file", color: "subtle", "data-slot": "file-row-icon" }) }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-ds-050", children: [_jsx("span", { "data-slot": "file-name", className: "truncate text-body text-ds-text", children: name ?? file?.name }), uploading && (_jsx("span", { role: "progressbar", "aria-label": name ?? file?.name, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round((progress ?? 0) * 100), "aria-valuetext": total !== undefined ? `${formatFileSize(total * (progress ?? 0), locale)} / ${formatFileSize(total, locale)}` : undefined, "data-slot": "file-progress", className: "h-1 overflow-hidden rounded-ds-full bg-ds-background-neutral", children: _jsx("span", { className: "block h-full rounded-ds-full bg-ds-background-brand-bold", style: { width: `${Math.round((progress ?? 0) * 100)}%` } }) })), error ? (_jsx("span", { role: "status", "data-slot": "file-error", className: "text-body-small text-ds-text-danger", children: error })) : total !== undefined ? (_jsx("span", { "data-slot": "file-meta", className: "text-body-small tabular-nums text-ds-text-subtlest", children: uploading
|
|
147
|
+
? `${formatFileSize(total * (progress ?? 0), locale)} / ${formatFileSize(total, locale)}`
|
|
148
|
+
: `${formatFileSize(total, locale)} · ${uploadedLabel(locale)}` })) : null] }), error && onReplace ? (_jsx(Button, { variant: "link", size: "small", onPress: onReplace, children: replaceLabel(locale) })) : uploading && onCancel ? (_jsx(Button, { variant: "subtle", size: "small", iconOnly: true, iconBefore: "x", "aria-label": cancelUploadLabel(locale), onPress: onCancel })) : onRemove ? (_jsx(Button, { variant: "subtle", size: "small", iconOnly: true, iconBefore: "trash-2", "aria-label": removeFileLabel(locale), onPress: onRemove })) : null] }));
|
|
149
|
+
}
|
|
150
|
+
/** The list of picked or stored files. */
|
|
151
|
+
export function FileUploadList({ children, "aria-label": ariaLabel }) {
|
|
152
|
+
return (
|
|
153
|
+
// role="list": Safari drops the list role from a `list-none` list.
|
|
154
|
+
_jsx("ul", { role: "list", "aria-label": ariaLabel, "data-slot": "file-list", className: "m-0 flex list-none flex-col gap-ds-100 p-0", children: children }));
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=files.js.map
|