@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,173 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type Key } from "react-aria-components";
|
|
3
|
+
import { type WithRadius } from "../defaults.js";
|
|
4
|
+
import { type FieldSize } from "../form/styles.js";
|
|
5
|
+
import { type RequiredValidation } from "../form/validation.js";
|
|
6
|
+
import type { SelectLabelProps } from "./select.js";
|
|
7
|
+
export type ComboBoxItem = {
|
|
8
|
+
id: Key;
|
|
9
|
+
label: string;
|
|
10
|
+
/** Secondary line (an ID, e-mail); searched like the label. */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** A trailing mark such as a status Badge. */
|
|
13
|
+
badge?: React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* A small decorative mark before the label (a country's `IsoChip`, the app's own node): in the option row,
|
|
16
|
+
* before the chosen label in the field and in a multiple selection's tags. Hidden from assistive technology;
|
|
17
|
+
* the label alone names the option. Left out, the DOM is as before.
|
|
18
|
+
*/
|
|
19
|
+
icon?: React.ReactNode;
|
|
20
|
+
/** Shown but skipped by the keyboard and not selectable. */
|
|
21
|
+
isDisabled?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Server search: called with the typed text and, for the next page, the
|
|
25
|
+
* cursor the previous page returned. `signal` aborts superseded requests.
|
|
26
|
+
*/
|
|
27
|
+
export type ComboBoxLoader = (filterText: string, cursor: string | undefined, signal: AbortSignal) => Promise<{
|
|
28
|
+
items: ComboBoxItem[];
|
|
29
|
+
cursor?: string;
|
|
30
|
+
}>;
|
|
31
|
+
type BaseProps = {
|
|
32
|
+
/** The whole list, filtered here as the user types. */
|
|
33
|
+
items?: readonly ComboBoxItem[];
|
|
34
|
+
/** Or load matches from the server (with paging when it returns a cursor). */
|
|
35
|
+
loadItems?: ComboBoxLoader;
|
|
36
|
+
description?: React.ReactNode;
|
|
37
|
+
errorMessage?: React.ReactNode;
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
isRequired?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Who says an empty required ComboBox is missing: `field` (default) shows "Fill in this field."
|
|
42
|
+
* on blur and on a DS Form submit, which it then blocks; `app` only marks the field. Empty is no chosen item
|
|
43
|
+
* (multiple: no tag); with `allowsCustomValue`, typed text counts as a value. See {@link RequiredValidation}.
|
|
44
|
+
* The app's `isInvalid` (`true` with its `errorMessage`, or `false`) overrides the check, as on TextField. Disabled,
|
|
45
|
+
* empty and required, it still blocks a DS Form's submit and cannot take focus (as TextField).
|
|
46
|
+
*/
|
|
47
|
+
requiredValidation?: RequiredValidation;
|
|
48
|
+
isDisabled?: boolean;
|
|
49
|
+
isInvalid?: boolean;
|
|
50
|
+
name?: string;
|
|
51
|
+
/** `input` (default) opens on typing; `focus` also on focus. The chevron always opens the full list. */
|
|
52
|
+
menuTrigger?: "input" | "focus";
|
|
53
|
+
/**
|
|
54
|
+
* The empty result: a node, or a function of the typed text for a message that quotes it. Defaults to
|
|
55
|
+
* "No results for “{query}”." in the provider locale.
|
|
56
|
+
*/
|
|
57
|
+
emptyState?: React.ReactNode | ((query: string) => React.ReactNode);
|
|
58
|
+
/** Adds a create row for the typed text when nothing matches it exactly. */
|
|
59
|
+
onCreate?: (text: string) => void;
|
|
60
|
+
/** The create row's text; defaults to "Add “{query}”". */
|
|
61
|
+
createLabel?: (text: string) => string;
|
|
62
|
+
/** The typed text, for consumers that need it (custom values, analytics). */
|
|
63
|
+
onInputChange?: (text: string) => void;
|
|
64
|
+
size?: FieldSize;
|
|
65
|
+
/**
|
|
66
|
+
* The app is fetching items itself (with `items`, not `loadItems`): a spinner
|
|
67
|
+
* shows in the field and at the end of the list, and the change is announced.
|
|
68
|
+
* Items already shown stay selectable by keyboard and pointer. Together with
|
|
69
|
+
* `loadItems`, the field's own loading status is the one announced, so there
|
|
70
|
+
* is a single status region.
|
|
71
|
+
*/
|
|
72
|
+
isLoading?: boolean;
|
|
73
|
+
/** What is announced and shown while loading; defaults to "Loading…" in the provider locale. */
|
|
74
|
+
loadingText?: string;
|
|
75
|
+
/**
|
|
76
|
+
* The app searches on the server itself (with `items`, not `loadItems`;): told the text to search for,
|
|
77
|
+
* the typed text, or `""` when the list opens in full (the chevron, focus with `menuTrigger="focus"`) or the field
|
|
78
|
+
* just shows the chosen item's label. Debounce it on the app side. With it, `items` are the app's results and are
|
|
79
|
+
* shown as given, not filtered again here; the match in each row is still in bold. Not called on mount.
|
|
80
|
+
*
|
|
81
|
+
* The field hides rows found for another text itself: from the moment the text changes until the app's answer
|
|
82
|
+
* arrives, the list shows its loading row, the field its spinner, and the loading is announced politely, whatever the
|
|
83
|
+
* app does while it debounces. The answer has arrived when the rows change (ids, labels, second lines), when
|
|
84
|
+
* `isLoading` is set and cleared again (also for a server that finds the same rows), or, if neither, once the same
|
|
85
|
+
* rows have stood for a second with no new render. Nothing is asked of the app for it; `isLoading` is still the way to
|
|
86
|
+
* say a fetch is running.
|
|
87
|
+
*
|
|
88
|
+
* It is for a search that answers later. Filtering the rows the app already holds, synchronously, is the local filter's
|
|
89
|
+
* job (pass `items` without `onSearchChange`): here an answer with the very same rows and no `isLoading` stays hidden
|
|
90
|
+
* for that second. The field tells answers apart by when they arrive, not by the text they were asked for: an earlier
|
|
91
|
+
* request that answers after the next keystroke counts as the answer to the newer text. Abort superseded requests, or
|
|
92
|
+
* keep each answer under its own text (react-query's query key, without `placeholderData`).
|
|
93
|
+
*/
|
|
94
|
+
onSearchChange?: (search: string) => void;
|
|
95
|
+
/**
|
|
96
|
+
* The next page of the app's own `items`, for an app that pages with its own query (react-query's
|
|
97
|
+
* infinite query): called when the list is scrolled near its end. Pass it only while there is another page
|
|
98
|
+
* (`hasNextPage ? fetchNextPage : undefined`), and set `isLoading` while the page loads: the list then ends in a
|
|
99
|
+
* loading row, the field shows its spinner and the loading is announced (politely). It is not called again while
|
|
100
|
+
* `isLoading` is set, nor twice before the app answers (a new page, `isLoading`, or a new search). The app's error
|
|
101
|
+
* stays the app's (`errorMessage`, `description`); after it, a scroll to the end asks again. With `loadItems`, which
|
|
102
|
+
* pages by itself, it is not used.
|
|
103
|
+
*/
|
|
104
|
+
onLoadMore?: () => void;
|
|
105
|
+
/**
|
|
106
|
+
* The input's id, so a label outside the component (`<label htmlFor={id}>`, an app's form field) names it.
|
|
107
|
+
* With neither `label` nor `aria-label`, that external label is the field's name and no label of its own
|
|
108
|
+
* renders.
|
|
109
|
+
*/
|
|
110
|
+
id?: string;
|
|
111
|
+
/** Ids of text outside the component that describes the input (an app's hint or error), added to its own. */
|
|
112
|
+
"aria-describedby"?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Set by a form row that owns the error text (the shared `Field` hands its control `aria-invalid`): the field
|
|
115
|
+
* shows its invalid state as with `isInvalid`, and without an `errorMessage` of its own draws no error row,
|
|
116
|
+
* so the row's message is the only one. It marks the input for assistive tech and draws it
|
|
117
|
+
* invalid only: unlike `isInvalid` it never becomes the input's native validity (React Aria's default outside a
|
|
118
|
+
* DS Form), so it never blocks a form's submit.
|
|
119
|
+
*/
|
|
120
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* How the field is named: Select's visible `label` or `aria-label` (SelectLabelProps), or, for a form that
|
|
124
|
+
* renders its own label, neither of them and an `id` that the external `<label htmlFor>` points at.
|
|
125
|
+
*/
|
|
126
|
+
type ComboBoxLabelProps = SelectLabelProps | {
|
|
127
|
+
label?: never;
|
|
128
|
+
"aria-label"?: never;
|
|
129
|
+
/** The id an external `<label htmlFor>` points at; that label names the field. */
|
|
130
|
+
id: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Either a visible `label` above the field or, where the context already names it (a toolbar filter next
|
|
134
|
+
* to its heading, a table cell), an `aria-label` instead.
|
|
135
|
+
*/
|
|
136
|
+
export type ComboBoxSingleProps = ComboBoxLabelProps & BaseProps & {
|
|
137
|
+
selectionMode?: "single";
|
|
138
|
+
/** Controlled; may start undefined and become set later (never flips control). */
|
|
139
|
+
selectedKey?: Key | null;
|
|
140
|
+
defaultSelectedKey?: Key | null;
|
|
141
|
+
onSelectionChange?: (key: Key | null) => void;
|
|
142
|
+
/** The chosen item when it is not on the loaded page (server search), so its label still shows. */
|
|
143
|
+
selectedItem?: ComboBoxItem;
|
|
144
|
+
/**
|
|
145
|
+
* Typed text that matches no item is kept as the field's text; the key
|
|
146
|
+
* becomes `null` and `onInputChange` reports the text.
|
|
147
|
+
*/
|
|
148
|
+
allowsCustomValue?: boolean;
|
|
149
|
+
};
|
|
150
|
+
export type ComboBoxMultipleProps = ComboBoxLabelProps & BaseProps & {
|
|
151
|
+
selectionMode: "multiple";
|
|
152
|
+
selectedKeys?: readonly Key[];
|
|
153
|
+
defaultSelectedKeys?: readonly Key[];
|
|
154
|
+
onSelectionChange?: (keys: Key[]) => void;
|
|
155
|
+
/** Chosen items that are not on the loaded page, so their tags show their labels. */
|
|
156
|
+
selectedItems?: readonly ComboBoxItem[];
|
|
157
|
+
};
|
|
158
|
+
export type ComboBoxProps = (ComboBoxSingleProps | ComboBoxMultipleProps) & WithRadius;
|
|
159
|
+
/** The 16px spinner used while results load (the Spinner component's look). */
|
|
160
|
+
export declare function FieldSpinner(): React.JSX.Element;
|
|
161
|
+
/** How long the same rows must stand, with no loading said, before they count as the answer to a new search. */
|
|
162
|
+
export declare const APP_RESULTS_QUIET_MS = 1000;
|
|
163
|
+
/**
|
|
164
|
+
* One item (or several) from a long list by typing to filter: products,
|
|
165
|
+
* customers, countries, locations. Matching is anywhere in the label and the
|
|
166
|
+
* secondary line, case- and diacritic-insensitive, with the match in bold.
|
|
167
|
+
* A visible `label`, or an `aria-label` where the context already names the
|
|
168
|
+
* field; an empty `aria-label` counts as none. In a form that
|
|
169
|
+
* renders its own label, give neither and pass `id` for its `<label htmlFor>`;
|
|
170
|
+
* `aria-describedby` adds the form's hint or error.
|
|
171
|
+
*/
|
|
172
|
+
export declare function ComboBox(allProps: ComboBoxProps): React.JSX.Element;
|
|
173
|
+
export {};
|
|
@@ -0,0 +1,410 @@
|
|
|
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, ButtonContext, Collection, ComboBox as AriaComboBox, ComboBoxStateContext, Group, Input, ListBox, ListBoxItem, ListBoxLoadMoreItem, Popover, Text, useAsyncList, useLocale, } from "react-aria-components";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
import { ComponentDefaultsProvider, fieldRadiusClass, splitRadius, useFieldSize, useRadius } from "../defaults.js";
|
|
7
|
+
import { IconGlyph } from "../display/icon.js";
|
|
8
|
+
import { ControlFieldError, FieldDescription, FieldLabel, forwardedInvalid, useErrorRowLink, useFieldName } from "../form/field-parts.js";
|
|
9
|
+
import { FIELD_FRAME, FIELD_ICON, FIELD_SIZE, FIELD_STACK, INLINE_ACTION, INPUT } from "../form/styles.js";
|
|
10
|
+
import { useRequiredChoice } from "../form/validation.js";
|
|
11
|
+
import { createItemLabel, loadingLabel, noMatchLabel, removeItemLabel, showSuggestionsLabel } from "../i18n.js";
|
|
12
|
+
import { hasContent } from "./choice-text.js";
|
|
13
|
+
import { ITEM_ICON, LISTBOX, OPTION, POPOVER } from "./listbox.js";
|
|
14
|
+
import { Highlight, matchesQuery } from "./match.js";
|
|
15
|
+
import { TAG, TAG_REMOVE } from "./multi-select.js";
|
|
16
|
+
const CREATE_KEY = "__ds-combobox-create__";
|
|
17
|
+
/** A plain button inside the ComboBox: React Aria would otherwise wire every Button in it as the trigger. */
|
|
18
|
+
function OwnButton(props) {
|
|
19
|
+
return (_jsx(ButtonContext.Provider, { value: null, children: _jsx(Button, { ...props }) }));
|
|
20
|
+
}
|
|
21
|
+
/** Exposes React Aria's combobox state to handlers outside its render tree (closing after a create). */
|
|
22
|
+
function StateBridge({ into }) {
|
|
23
|
+
const state = React.useContext(ComboBoxStateContext);
|
|
24
|
+
into.current = state;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const SPIN = "size-ds-icon animate-spin rounded-ds-full border-2 border-current border-e-transparent text-ds-icon-subtle motion-reduce:animate-none";
|
|
28
|
+
/** The 16px spinner used while results load (the Spinner component's look). */
|
|
29
|
+
export function FieldSpinner() {
|
|
30
|
+
const { locale } = useLocale();
|
|
31
|
+
return (_jsxs("span", { role: "status", "data-slot": "field-spinner", className: "grid size-6 shrink-0 place-items-center", children: [_jsx("span", { "aria-hidden": "true", className: SPIN }), _jsx("span", { className: "sr-only", children: loadingLabel(locale) })] }));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `isLoading` given (true or false): a live region that stays mounted, so
|
|
35
|
+
* each start of loading is announced, plus a decorative spinner in the field.
|
|
36
|
+
* Omitted, nothing renders. `announce` is off with `loadItems`, whose own
|
|
37
|
+
* field spinner is already the status region.
|
|
38
|
+
*/
|
|
39
|
+
function LoadingState({ isLoading, text, spinner, announce }) {
|
|
40
|
+
// Mounted empty and filled after mount: a live region born with its text is usually not read, so a field
|
|
41
|
+
// that mounts already loading would go unannounced (the BulkBar count does the same).
|
|
42
|
+
const [spoken, setSpoken] = React.useState("");
|
|
43
|
+
React.useEffect(() => setSpoken(isLoading ? text : ""), [isLoading, text]);
|
|
44
|
+
if (isLoading === undefined)
|
|
45
|
+
return null;
|
|
46
|
+
return (_jsxs(_Fragment, { children: [isLoading && spinner && (_jsx("span", { "aria-hidden": "true", "data-slot": "combobox-loading-spinner", className: "grid size-6 shrink-0 place-items-center", children: _jsx("span", { className: SPIN }) })), announce && (_jsx("span", { role: "status", "data-slot": "combobox-loading-status", className: "sr-only", children: spoken }))] }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Items for the current query: filtered here, or the latest page from the
|
|
50
|
+
* server. While a server search for new text is in flight the old rows are
|
|
51
|
+
* hidden, so a nonsense search never shows leftovers.
|
|
52
|
+
*/
|
|
53
|
+
function useSource(items, loadItems, query, appSearch = false) {
|
|
54
|
+
const seen = React.useRef(new Map());
|
|
55
|
+
const next = React.useRef(undefined);
|
|
56
|
+
const remote = useAsyncList({
|
|
57
|
+
async load({ signal, cursor, filterText }) {
|
|
58
|
+
if (!loadItems)
|
|
59
|
+
return { items: [] };
|
|
60
|
+
try {
|
|
61
|
+
const page = await loadItems(filterText ?? "", cursor, signal);
|
|
62
|
+
// A superseded request never overwrites the cursor of the current one.
|
|
63
|
+
if (!signal.aborted)
|
|
64
|
+
next.current = page.cursor;
|
|
65
|
+
return { items: page.items, cursor: page.cursor };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (!signal.aborted)
|
|
69
|
+
next.current = undefined;
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
if (loadItems && remote.filterText !== query)
|
|
76
|
+
remote.setFilterText(query);
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
}, [query]);
|
|
79
|
+
for (const item of items ?? [])
|
|
80
|
+
seen.current.set(item.id, item);
|
|
81
|
+
for (const item of remote.items)
|
|
82
|
+
seen.current.set(item.id, item);
|
|
83
|
+
const loading = Boolean(loadItems) && (remote.loadingState === "loading" || remote.loadingState === "filtering");
|
|
84
|
+
// The app's own server search (`onSearchChange`) answers with its results: they are shown as given.
|
|
85
|
+
const list = loadItems
|
|
86
|
+
? (loading ? [] : remote.items)
|
|
87
|
+
: appSearch
|
|
88
|
+
? [...(items ?? [])]
|
|
89
|
+
: (items ?? []).filter((item) => matchesQuery(query, item.label, item.description));
|
|
90
|
+
return {
|
|
91
|
+
list,
|
|
92
|
+
loading,
|
|
93
|
+
loadingMore: remote.loadingState === "loadingMore",
|
|
94
|
+
hasMore: Boolean(loadItems) && Boolean(next.current) && !loading && remote.loadingState !== "error",
|
|
95
|
+
loadMore: () => remote.loadMore(),
|
|
96
|
+
remember: (extra) => extra.forEach((item) => item && seen.current.set(item.id, item)),
|
|
97
|
+
find: (key) => (key === null || key === undefined ? undefined : seen.current.get(key)),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** Tells the app's server search (`onSearchChange`) when the text to search for changes; never on mount. */
|
|
101
|
+
function useSearchReport(search, onSearchChange) {
|
|
102
|
+
const reported = React.useRef(search);
|
|
103
|
+
const latest = React.useRef(onSearchChange);
|
|
104
|
+
latest.current = onSearchChange;
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (reported.current === search)
|
|
107
|
+
return;
|
|
108
|
+
reported.current = search;
|
|
109
|
+
latest.current?.(search);
|
|
110
|
+
}, [search]);
|
|
111
|
+
}
|
|
112
|
+
/** How long the same rows must stand, with no loading said, before they count as the answer to a new search. */
|
|
113
|
+
export const APP_RESULTS_QUIET_MS = 1000;
|
|
114
|
+
/** The rows as the app's search answers them: what they say and in what order, not the array they come in. */
|
|
115
|
+
function resultsSignature(items) {
|
|
116
|
+
return (items ?? [])
|
|
117
|
+
.map((item) => [typeof item.id, String(item.id), item.label, item.description ?? "", item.isDisabled ? "1" : ""].join("\u0000"))
|
|
118
|
+
.join("\u0001");
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Whether the app's server search (`onSearchChange`) has answered the current text yet. The rows the
|
|
122
|
+
* app holds were found for the previous text, so from the render the text changes in (typing, clearing it, the chevron's
|
|
123
|
+
* full list, the chosen label) they are hidden until the app's answer arrives, and the loading row and status show
|
|
124
|
+
* instead, so a debounce or a slow server does not show the previous text's rows. The field cannot tell which text an
|
|
125
|
+
* answer was asked for: an out-of-order earlier response that arrives after the next keystroke still counts as the
|
|
126
|
+
* answer, so apps should abort superseded requests. The answer has arrived when, after the change:
|
|
127
|
+
* - the rows differ from the hidden ones (their ids, labels, second lines or disabled state; a new array holding the
|
|
128
|
+
* same rows does not count, as an app that derives `items` in render hands a new one on every render, also the
|
|
129
|
+
* one in which it stores the text it was told);
|
|
130
|
+
* - or `isLoading` was set and is cleared again (the app's fetch finished, also when it found the same rows);
|
|
131
|
+
* - or, with neither, the same rows stand for {@link APP_RESULTS_QUIET_MS} with nothing re-rendered and no loading said:
|
|
132
|
+
* a server that answered with the very same rows is shown then, never left hidden.
|
|
133
|
+
* Only for the app's own search: with `loadItems` or the local filter it is never on. Synchronous filtering belongs to
|
|
134
|
+
* the local filter, not `onSearchChange`: an answer with the same rows and no `isLoading` stays hidden for the quiet time.
|
|
135
|
+
*/
|
|
136
|
+
function useAppResults(enabled, search, items, isLoading) {
|
|
137
|
+
const signature = enabled ? resultsSignature(items) : "";
|
|
138
|
+
const reported = React.useRef(search);
|
|
139
|
+
const waiting = React.useRef(null);
|
|
140
|
+
if (search !== reported.current) {
|
|
141
|
+
reported.current = search;
|
|
142
|
+
waiting.current = enabled ? { signature, sawLoading: false } : null;
|
|
143
|
+
}
|
|
144
|
+
if (!enabled)
|
|
145
|
+
waiting.current = null;
|
|
146
|
+
if (waiting.current) {
|
|
147
|
+
if (isLoading)
|
|
148
|
+
waiting.current.sawLoading = true;
|
|
149
|
+
else if (waiting.current.sawLoading || signature !== waiting.current.signature)
|
|
150
|
+
waiting.current = null;
|
|
151
|
+
}
|
|
152
|
+
const awaiting = waiting.current !== null;
|
|
153
|
+
const [, settle] = React.useReducer((count) => count + 1, 0);
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
if (!awaiting || isLoading)
|
|
156
|
+
return;
|
|
157
|
+
const timer = setTimeout(() => {
|
|
158
|
+
waiting.current = null;
|
|
159
|
+
settle();
|
|
160
|
+
}, APP_RESULTS_QUIET_MS);
|
|
161
|
+
return () => clearTimeout(timer);
|
|
162
|
+
}, [awaiting, isLoading, items, search]);
|
|
163
|
+
return awaiting;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The app's `onLoadMore`, asked at most once per answer. React Aria's end-of-list sentinel fires again
|
|
167
|
+
* whenever the collection changes, even while a page is on its way, so a request stays open until the app answers:
|
|
168
|
+
* a page arrives (the item count changes), `isLoading` comes or goes, or the search changes. Never while loading.
|
|
169
|
+
*/
|
|
170
|
+
function useLoadMore(onLoadMore, isLoading, count, search) {
|
|
171
|
+
const asked = React.useRef(false);
|
|
172
|
+
const latest = React.useRef(onLoadMore);
|
|
173
|
+
latest.current = onLoadMore;
|
|
174
|
+
const loading = React.useRef(isLoading);
|
|
175
|
+
loading.current = isLoading;
|
|
176
|
+
React.useEffect(() => {
|
|
177
|
+
asked.current = false;
|
|
178
|
+
}, [isLoading, count, search]);
|
|
179
|
+
const loadMore = React.useCallback(() => {
|
|
180
|
+
if (loading.current || asked.current || !latest.current)
|
|
181
|
+
return;
|
|
182
|
+
asked.current = true;
|
|
183
|
+
latest.current();
|
|
184
|
+
}, []);
|
|
185
|
+
return onLoadMore ? loadMore : undefined;
|
|
186
|
+
}
|
|
187
|
+
function Option({ item, query, single }) {
|
|
188
|
+
const create = item.id === CREATE_KEY;
|
|
189
|
+
return (_jsx(ListBoxItem, { id: item.id, textValue: item.label, isDisabled: item.isDisabled, "data-slot": create ? "combobox-create" : "combobox-option", className: cn(OPTION, create && "mt-ds-050 border-t border-ds-border"), children: ({ isSelected }) => (_jsxs(_Fragment, { children: [create && _jsx(IconGlyph, { name: "plus", "data-slot": "combobox-create-icon" }), !create && hasContent(item.icon) && (_jsx("span", { "aria-hidden": "true", "data-slot": "combobox-option-icon", className: ITEM_ICON, children: item.icon })), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col py-ds-075", children: [_jsx(Text, { slot: "label", "data-slot": "combobox-option-label", className: "truncate", children: create ? item.label : _jsx(Highlight, { text: item.label, query: query }) }), item.description && (_jsx(Text, { slot: "description", "data-slot": "combobox-option-description", className: "truncate text-body-small text-ds-text-subtlest", children: _jsx(Highlight, { text: item.description, query: query }) }))] }), item.badge !== undefined && _jsx("span", { "data-slot": "combobox-option-badge", className: "shrink-0", children: item.badge }), single && isSelected && !create && _jsx(IconGlyph, { name: "check", color: "brand", "data-slot": "combobox-option-check" })] })) }));
|
|
190
|
+
}
|
|
191
|
+
function OptionList({ shown, query, single, hasMore, loadingMore, loadMore, loading, empty, isLoading, loadingText, appLoadMore, }) {
|
|
192
|
+
const { locale } = useLocale();
|
|
193
|
+
// A list with item icons (a country picker) never grows past the viewport (React Aria's 12px edge padding each
|
|
194
|
+
// side): a long name truncates beside its chip at 320px. Without icons the popover is as before.
|
|
195
|
+
const capped = shown.some((item) => hasContent(item.icon));
|
|
196
|
+
return (_jsx(Popover, { "data-slot": "combobox-popover", placement: "bottom start", offset: 4, className: capped ? cn(POPOVER, "max-w-[calc(100vw-1.5rem)]") : POPOVER, children: _jsxs(ListBox, { "data-slot": "combobox-listbox", className: LISTBOX, renderEmptyState: () => (_jsx("div", { "data-slot": "combobox-empty", className: "px-ds-100 py-ds-150 text-body-small text-ds-text-subtlest", children: loading || isLoading ? (loadingText ?? loadingLabel(locale)) : empty })), children: [_jsx(Collection, { items: shown, dependencies: [query, single], children: (item) => _jsx(Option, { item: item, query: query, single: single }) }), hasMore && (_jsx(ListBoxLoadMoreItem, { onLoadMore: loadMore, isLoading: loadingMore, "data-slot": "combobox-load-more", className: "flex justify-center py-ds-050", children: _jsx(FieldSpinner, {}) })), appLoadMore && !hasMore && shown.length > 0 && (_jsxs(ListBoxLoadMoreItem, { onLoadMore: appLoadMore, isLoading: Boolean(isLoading), "data-slot": "combobox-loading", className: "flex items-center justify-center gap-ds-075 py-ds-075 text-body-small text-ds-text-subtlest", children: [_jsx("span", { "aria-hidden": "true", className: SPIN }), _jsx("span", { children: loadingText ?? loadingLabel(locale) })] })), isLoading && !hasMore && !appLoadMore && shown.length > 0 && (_jsxs(ListBoxLoadMoreItem, { isLoading: true, "data-slot": "combobox-loading", className: "flex items-center justify-center gap-ds-075 py-ds-075 text-body-small text-ds-text-subtlest", children: [_jsx("span", { "aria-hidden": "true", className: SPIN }), _jsx("span", { children: loadingText ?? loadingLabel(locale) })] }))] }) }));
|
|
197
|
+
}
|
|
198
|
+
/** Opening by the chevron (or by focus) shows the full list; typing filters it again. */
|
|
199
|
+
function useShowAll() {
|
|
200
|
+
const [showAll, setShowAll] = React.useState(false);
|
|
201
|
+
return {
|
|
202
|
+
showAll,
|
|
203
|
+
// Closing keeps the flag, so closing never starts a new search; typing clears it.
|
|
204
|
+
onOpenChange: (open, trigger) => {
|
|
205
|
+
if (open)
|
|
206
|
+
setShowAll(trigger === "manual" || trigger === "focus");
|
|
207
|
+
},
|
|
208
|
+
onType: () => setShowAll(false),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* One item (or several) from a long list by typing to filter: products,
|
|
213
|
+
* customers, countries, locations. Matching is anywhere in the label and the
|
|
214
|
+
* secondary line, case- and diacritic-insensitive, with the match in bold.
|
|
215
|
+
* A visible `label`, or an `aria-label` where the context already names the
|
|
216
|
+
* field; an empty `aria-label` counts as none. In a form that
|
|
217
|
+
* renders its own label, give neither and pass `id` for its `<label htmlFor>`;
|
|
218
|
+
* `aria-describedby` adds the form's hint or error.
|
|
219
|
+
*/
|
|
220
|
+
export function ComboBox(allProps) {
|
|
221
|
+
const [radius, props] = splitRadius(allProps);
|
|
222
|
+
return (_jsx(ComponentDefaultsProvider, { value: { radius }, children: props.selectionMode === "multiple" ? _jsx(MultipleComboBox, { ...props }) : _jsx(SingleComboBox, { ...props }) }));
|
|
223
|
+
}
|
|
224
|
+
function SingleComboBox({ label, "aria-label": ariaLabel, items, loadItems, description, errorMessage: errorMessageProp, placeholder, menuTrigger = "input", emptyState, allowsCustomValue, onCreate, createLabel, onInputChange, size: fieldSize, selectedKey, defaultSelectedKey, onSelectionChange, selectedItem, isLoading, loadingText, "aria-invalid": ariaInvalid, onSearchChange, onLoadMore, requiredValidation, isInvalid: isInvalidProp, ...rest }) {
|
|
225
|
+
const size = useFieldSize(fieldSize);
|
|
226
|
+
const frameRadius = useRadius(undefined);
|
|
227
|
+
const { locale } = useLocale();
|
|
228
|
+
const inputRef = React.useRef(null);
|
|
229
|
+
const { named, showLabel, externalNameProps } = useFieldName("ComboBox", label, ariaLabel, rest["aria-labelledby"], rest.id, inputRef);
|
|
230
|
+
const [own, setOwn] = React.useState(selectedKey ?? defaultSelectedKey ?? null);
|
|
231
|
+
if (selectedKey !== undefined && selectedKey !== own)
|
|
232
|
+
setOwn(selectedKey);
|
|
233
|
+
const value = selectedKey !== undefined ? selectedKey : own;
|
|
234
|
+
const [input, setInputState] = React.useState("");
|
|
235
|
+
// React Aria reports the new text and then the selection in one event; read the latest text, not the render's.
|
|
236
|
+
const latestInput = React.useRef(input);
|
|
237
|
+
const setInput = (text) => {
|
|
238
|
+
latestInput.current = text;
|
|
239
|
+
setInputState(text);
|
|
240
|
+
onInputChange?.(text);
|
|
241
|
+
};
|
|
242
|
+
const { showAll, onOpenChange, onType } = useShowAll();
|
|
243
|
+
const query = showAll ? "" : input;
|
|
244
|
+
const appSearch = Boolean(onSearchChange) && !loadItems;
|
|
245
|
+
const source = useSource(items, loadItems, query, appSearch);
|
|
246
|
+
source.remember([selectedItem]);
|
|
247
|
+
const current = source.find(value);
|
|
248
|
+
const state = React.useRef(null);
|
|
249
|
+
// The app's server search is for typed text: the chosen item's label shown in the field is not a search.
|
|
250
|
+
const search = current && input === current.label ? "" : query;
|
|
251
|
+
useSearchReport(search, appSearch ? onSearchChange : undefined);
|
|
252
|
+
const awaiting = useAppResults(appSearch, search, items, Boolean(isLoading));
|
|
253
|
+
// React Aria never finds an empty ComboBox missing under `aria` validation; the DS does. Custom
|
|
254
|
+
// text is the value when it is allowed.
|
|
255
|
+
const required = useRequiredChoice({
|
|
256
|
+
filled: value !== null || (Boolean(allowsCustomValue) && input.trim() !== ""), isRequired: rest.isRequired, requiredValidation,
|
|
257
|
+
isInvalid: isInvalidProp, errorMessage: errorMessageProp,
|
|
258
|
+
});
|
|
259
|
+
const errorMessage = required.errorMessage;
|
|
260
|
+
const forwarded = forwardedInvalid(ariaInvalid);
|
|
261
|
+
const errorRowLink = useErrorRowLink(forwarded.invalid, errorMessage);
|
|
262
|
+
// A value set from outside shows its label (a cleared value clears the field). A label that only
|
|
263
|
+
// arrives later with a server page fills the field only while the user is not typing in it.
|
|
264
|
+
const focused = React.useRef(false);
|
|
265
|
+
const shownFor = React.useRef(null);
|
|
266
|
+
const previous = shownFor.current;
|
|
267
|
+
const valueChanged = previous === null || previous.value !== value;
|
|
268
|
+
const labelArrived = !valueChanged && previous.label !== current?.label;
|
|
269
|
+
if (valueChanged || labelArrived) {
|
|
270
|
+
shownFor.current = { value, label: current?.label };
|
|
271
|
+
const untouched = latestInput.current === "" || latestInput.current === previous?.label;
|
|
272
|
+
if (valueChanged || !focused.current || untouched) {
|
|
273
|
+
const text = current?.label ?? (allowsCustomValue && value === null && previous !== null ? latestInput.current : "");
|
|
274
|
+
if (text !== latestInput.current) {
|
|
275
|
+
latestInput.current = text;
|
|
276
|
+
setInputState(text);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Until the app answers a new search its rows are not shown.
|
|
281
|
+
const shown = awaiting ? [] : [...source.list];
|
|
282
|
+
// The chosen item off the loaded page still belongs to the collection, so its label and check hold.
|
|
283
|
+
if (current && !shown.some((item) => item.id === current.id) && (query === "" || query === current.label))
|
|
284
|
+
shown.unshift(current);
|
|
285
|
+
const typed = input.trim();
|
|
286
|
+
const exact = shown.some((item) => item.label.localeCompare(typed, locale, { sensitivity: "base" }) === 0);
|
|
287
|
+
if (onCreate && typed && !exact && !showAll && !awaiting) {
|
|
288
|
+
shown.push({ id: CREATE_KEY, label: createLabel?.(typed) ?? createItemLabel(locale, typed) });
|
|
289
|
+
}
|
|
290
|
+
const appLoadMore = useLoadMore(loadItems ? undefined : onLoadMore, Boolean(isLoading), items?.length ?? 0, search);
|
|
291
|
+
const commit = (key) => {
|
|
292
|
+
setOwn(key);
|
|
293
|
+
onSelectionChange?.(key);
|
|
294
|
+
};
|
|
295
|
+
return (_jsx(AriaComboBox, { ...rest, ...forwarded.fieldProps, ...errorRowLink, isInvalid: required.isInvalid, items: shown, selectedKey: value, inputValue: input, allowsCustomValue: allowsCustomValue, allowsEmptyCollection: true, menuTrigger: menuTrigger, onOpenChange: onOpenChange, onInputChange: (text) => {
|
|
296
|
+
setInput(text);
|
|
297
|
+
onType();
|
|
298
|
+
// Clearing the field clears the value.
|
|
299
|
+
if (text.trim() === "" && value !== null)
|
|
300
|
+
commit(null);
|
|
301
|
+
}, onSelectionChange: (key) => {
|
|
302
|
+
if (key === CREATE_KEY) {
|
|
303
|
+
onCreate?.(latestInput.current.trim());
|
|
304
|
+
setInput(current?.label ?? "");
|
|
305
|
+
state.current?.close();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (key === null) {
|
|
309
|
+
//: re-selecting the current option keeps it (the text still reads its label).
|
|
310
|
+
if (value === null || latestInput.current === current?.label)
|
|
311
|
+
return;
|
|
312
|
+
// Custom text was committed: the key goes, the text stays.
|
|
313
|
+
if (allowsCustomValue)
|
|
314
|
+
commit(null);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (key !== value)
|
|
318
|
+
commit(key);
|
|
319
|
+
}, onFocus: () => {
|
|
320
|
+
focused.current = true;
|
|
321
|
+
}, onBlur: (event) => {
|
|
322
|
+
focused.current = false;
|
|
323
|
+
// Leaving the field shows the chosen label again, unless custom text is allowed.
|
|
324
|
+
if (!allowsCustomValue)
|
|
325
|
+
setInput(source.find(value)?.label ?? "");
|
|
326
|
+
required.onBlur?.(event);
|
|
327
|
+
}, "aria-label": named, ...externalNameProps, "data-slot": "combobox", className: cn("group", FIELD_STACK), children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsx(StateBridge, { into: state }), showLabel && _jsx(FieldLabel, { isRequired: rest.isRequired, children: label }), _jsxs(Group, { "data-slot": "combobox-field", isInvalid: isInvalid || forwarded.invalid, isDisabled: isDisabled, className: cn(FIELD_FRAME, FIELD_SIZE[size], "pe-ds-050", fieldRadiusClass(frameRadius)), children: [current && hasContent(current.icon) && input === current.label && (_jsx("span", { "aria-hidden": "true", "data-slot": "combobox-value-icon", className: isDisabled ? cn(ITEM_ICON, "opacity-40") : ITEM_ICON, onMouseDown: (event) => {
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
if (!isDisabled)
|
|
330
|
+
inputRef.current?.focus();
|
|
331
|
+
}, children: current.icon })), _jsx(Input, { ref: inputRef, ...(forwarded.invalid ? { "aria-invalid": true } : null), placeholder: placeholder, "data-slot": "combobox-input", className: cn(INPUT, "text-body"), onKeyDown: (event) => {
|
|
332
|
+
// Escape gives back the chosen label even when the filtered list no longer holds it.
|
|
333
|
+
if (event.key === "Escape" && !allowsCustomValue)
|
|
334
|
+
setInput(current?.label ?? "");
|
|
335
|
+
} }), source.loading && _jsx(FieldSpinner, {}), _jsx(LoadingState, { isLoading: appSearch ? Boolean(isLoading) || awaiting : isLoading, text: loadingText ?? loadingLabel(locale), spinner: !source.loading, announce: !loadItems }), _jsx(Button, { "aria-label": showSuggestionsLabel(locale), "data-slot": "combobox-button", className: INLINE_ACTION, children: _jsx(IconGlyph, { name: "chevron-down", className: FIELD_ICON, "data-slot": "combobox-chevron" }) })] }), description && _jsx(FieldDescription, { children: description }), _jsx(ControlFieldError, { forwardedInvalid: forwarded.invalid, children: errorMessage }), _jsx(OptionList, { shown: shown, query: query, single: true, appLoadMore: awaiting ? undefined : appLoadMore, hasMore: source.hasMore, loadingMore: source.loadingMore, loadMore: source.loadMore, loading: source.loading || awaiting, isLoading: awaiting || isLoading, loadingText: loadingText, empty: typed ? (typeof emptyState === "function" ? emptyState(typed) : (emptyState ?? noMatchLabel(locale, typed))) : null })] })) }));
|
|
336
|
+
}
|
|
337
|
+
function sameKeys(a, b) {
|
|
338
|
+
return a.length === b.length && a.every((key, index) => key === b[index]);
|
|
339
|
+
}
|
|
340
|
+
function MultipleComboBox({ label, "aria-label": ariaLabel, items, loadItems, description, errorMessage: errorMessageProp, placeholder, menuTrigger = "input", emptyState, onCreate, createLabel, onInputChange, size: fieldSize, selectedKeys, defaultSelectedKeys, onSelectionChange, selectedItems, isLoading, loadingText, "aria-invalid": ariaInvalid, onSearchChange, onLoadMore, requiredValidation, isInvalid: isInvalidProp, ...rest }) {
|
|
341
|
+
const size = useFieldSize(fieldSize);
|
|
342
|
+
const frameRadius = useRadius(undefined);
|
|
343
|
+
const { locale } = useLocale();
|
|
344
|
+
const inputRef = React.useRef(null);
|
|
345
|
+
const { named, showLabel, externalNameProps } = useFieldName("ComboBox", label, ariaLabel, rest["aria-labelledby"], rest.id, inputRef);
|
|
346
|
+
const [own, setOwn] = React.useState([...(selectedKeys ?? defaultSelectedKeys ?? [])]);
|
|
347
|
+
const value = selectedKeys !== undefined ? [...selectedKeys] : own;
|
|
348
|
+
const change = (keys) => {
|
|
349
|
+
setOwn(keys);
|
|
350
|
+
onSelectionChange?.(keys);
|
|
351
|
+
};
|
|
352
|
+
const [input, setInputState] = React.useState("");
|
|
353
|
+
const setInput = (text) => {
|
|
354
|
+
setInputState(text);
|
|
355
|
+
onInputChange?.(text);
|
|
356
|
+
};
|
|
357
|
+
const { showAll, onOpenChange, onType } = useShowAll();
|
|
358
|
+
const query = showAll ? "" : input;
|
|
359
|
+
const appSearch = Boolean(onSearchChange) && !loadItems;
|
|
360
|
+
const source = useSource(items, loadItems, query, appSearch);
|
|
361
|
+
source.remember(selectedItems ?? []);
|
|
362
|
+
useSearchReport(query, appSearch ? onSearchChange : undefined);
|
|
363
|
+
const awaiting = useAppResults(appSearch, query, items, Boolean(isLoading));
|
|
364
|
+
const appLoadMore = useLoadMore(loadItems ? undefined : onLoadMore, Boolean(isLoading), items?.length ?? 0, query);
|
|
365
|
+
const state = React.useRef(null);
|
|
366
|
+
// React Aria never finds an empty selection missing under `aria` validation; the DS does.
|
|
367
|
+
const required = useRequiredChoice({
|
|
368
|
+
filled: value.length > 0, isRequired: rest.isRequired, requiredValidation, isInvalid: isInvalidProp, errorMessage: errorMessageProp,
|
|
369
|
+
});
|
|
370
|
+
const errorMessage = required.errorMessage;
|
|
371
|
+
const forwarded = forwardedInvalid(ariaInvalid);
|
|
372
|
+
const errorRowLink = useErrorRowLink(forwarded.invalid, errorMessage);
|
|
373
|
+
// Every chosen key gets a tag; one with no known item shows its key rather than vanishing.
|
|
374
|
+
const chosen = value.map((key) => source.find(key) ?? { id: key, label: String(key) });
|
|
375
|
+
// Until the app answers a new search its rows are not shown.
|
|
376
|
+
const shown = awaiting ? [] : [...source.list];
|
|
377
|
+
for (const item of chosen)
|
|
378
|
+
if (!shown.some((entry) => entry.id === item.id) && query === "")
|
|
379
|
+
shown.push(item);
|
|
380
|
+
const typed = input.trim();
|
|
381
|
+
const exact = shown.some((item) => item.label.localeCompare(typed, locale, { sensitivity: "base" }) === 0);
|
|
382
|
+
if (onCreate && typed && !exact && !showAll && !awaiting) {
|
|
383
|
+
shown.push({ id: CREATE_KEY, label: createLabel?.(typed) ?? createItemLabel(locale, typed) });
|
|
384
|
+
}
|
|
385
|
+
return (_jsx(AriaComboBox, { ...rest, ...forwarded.fieldProps, ...errorRowLink, isInvalid: required.isInvalid, onBlur: required.onBlur, selectionMode: "multiple", items: shown, value: value, inputValue: input, allowsEmptyCollection: true, menuTrigger: menuTrigger, onOpenChange: onOpenChange, onInputChange: (text) => {
|
|
386
|
+
setInput(text);
|
|
387
|
+
onType();
|
|
388
|
+
}, onChange: (keys) => {
|
|
389
|
+
const next = [...keys];
|
|
390
|
+
if (next.includes(CREATE_KEY)) {
|
|
391
|
+
onCreate?.(typed);
|
|
392
|
+
setInput("");
|
|
393
|
+
state.current?.close();
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
// React Aria re-commits the same selection on blur; that is not a change and keeps the text.
|
|
397
|
+
if (sameKeys(next, value))
|
|
398
|
+
return;
|
|
399
|
+
change(next);
|
|
400
|
+
setInput("");
|
|
401
|
+
}, "aria-label": named, ...externalNameProps, "data-slot": "combobox", className: cn("group", FIELD_STACK), children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsx(StateBridge, { into: state }), showLabel && _jsx(FieldLabel, { isRequired: rest.isRequired, children: label }), _jsxs(Group, { "data-slot": "combobox-field", isInvalid: isInvalid || forwarded.invalid, isDisabled: isDisabled, className: cn(FIELD_FRAME, FIELD_SIZE[size], "flex-wrap gap-ds-050 py-[3px] pe-ds-050", fieldRadiusClass(frameRadius)), children: [chosen.map((item) => (_jsxs("span", { "data-slot": "combobox-tag", className: TAG, children: [hasContent(item.icon) ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", "data-slot": "combobox-tag-icon", className: ITEM_ICON, children: item.icon }), _jsx("span", { className: "truncate", children: item.label })] })) : (_jsx("span", { className: "truncate", children: item.label })), !isDisabled && (_jsx(OwnButton, { "aria-label": removeItemLabel(locale, item.label), "data-slot": "combobox-tag-remove", className: TAG_REMOVE, onPress: () => {
|
|
402
|
+
change(value.filter((key) => key !== item.id));
|
|
403
|
+
inputRef.current?.focus();
|
|
404
|
+
}, children: _jsx(IconGlyph, { name: "x", size: "small", "data-slot": "combobox-tag-remove-icon" }) }))] }, String(item.id)))), _jsx(Input, { ref: inputRef, ...(forwarded.invalid ? { "aria-invalid": true } : null), placeholder: chosen.length ? undefined : placeholder, "data-slot": "combobox-input", className: cn(INPUT, "min-w-20 text-body"), onKeyDown: (event) => {
|
|
405
|
+
// Backspace in the empty field removes the last tag.
|
|
406
|
+
if (event.key === "Backspace" && input === "" && value.length > 0)
|
|
407
|
+
change(value.slice(0, -1));
|
|
408
|
+
} }), source.loading && _jsx(FieldSpinner, {}), _jsx(LoadingState, { isLoading: appSearch ? Boolean(isLoading) || awaiting : isLoading, text: loadingText ?? loadingLabel(locale), spinner: !source.loading, announce: !loadItems }), _jsx(Button, { "aria-label": showSuggestionsLabel(locale), "data-slot": "combobox-button", className: INLINE_ACTION, children: _jsx(IconGlyph, { name: "chevron-down", className: FIELD_ICON, "data-slot": "combobox-chevron" }) })] }), description && _jsx(FieldDescription, { children: description }), _jsx(ControlFieldError, { forwardedInvalid: forwarded.invalid, children: errorMessage }), _jsx(OptionList, { shown: shown, query: query, single: false, appLoadMore: awaiting ? undefined : appLoadMore, hasMore: source.hasMore, loadingMore: source.loadingMore, loadMore: source.loadMore, loading: source.loading || awaiting, isLoading: awaiting || isLoading, loadingText: loadingText, empty: typed ? (typeof emptyState === "function" ? emptyState(typed) : (emptyState ?? noMatchLabel(locale, typed))) : null })] })) }));
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=combobox.js.map
|