@senvenli/react 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/action/button-group.d.ts +26 -0
- package/dist/action/button-group.js +12 -0
- package/dist/action/button-group.js.map +1 -0
- package/dist/action/button.d.ts +42 -0
- package/dist/action/button.js +58 -0
- package/dist/action/button.js.map +1 -0
- package/dist/action/close-button.d.ts +12 -0
- package/dist/action/close-button.js +13 -0
- package/dist/action/close-button.js.map +1 -0
- package/dist/action/copy-button.d.ts +21 -0
- package/dist/action/copy-button.js +38 -0
- package/dist/action/copy-button.js.map +1 -0
- package/dist/action/fab.d.ts +29 -0
- package/dist/action/fab.js +57 -0
- package/dist/action/fab.js.map +1 -0
- package/dist/action/files.d.ts +70 -0
- package/dist/action/files.js +156 -0
- package/dist/action/files.js.map +1 -0
- package/dist/action/index.d.ts +23 -0
- package/dist/action/index.js +16 -0
- package/dist/action/index.js.map +1 -0
- package/dist/action/language-names.d.ts +19 -0
- package/dist/action/language-names.js +79 -0
- package/dist/action/language-names.js.map +1 -0
- package/dist/action/language-switcher.d.ts +57 -0
- package/dist/action/language-switcher.js +53 -0
- package/dist/action/language-switcher.js.map +1 -0
- package/dist/action/link-button.d.ts +57 -0
- package/dist/action/link-button.js +48 -0
- package/dist/action/link-button.js.map +1 -0
- package/dist/action/link.d.ts +24 -0
- package/dist/action/link.js +18 -0
- package/dist/action/link.js.map +1 -0
- package/dist/action/pressable.d.ts +40 -0
- package/dist/action/pressable.js +65 -0
- package/dist/action/pressable.js.map +1 -0
- package/dist/action/styles.d.ts +60 -0
- package/dist/action/styles.js +109 -0
- package/dist/action/styles.js.map +1 -0
- package/dist/action/theme-script.d.ts +12 -0
- package/dist/action/theme-script.js +23 -0
- package/dist/action/theme-script.js.map +1 -0
- package/dist/action/theme-switcher.d.ts +43 -0
- package/dist/action/theme-switcher.js +260 -0
- package/dist/action/theme-switcher.js.map +1 -0
- package/dist/action/theme-toggle.d.ts +43 -0
- package/dist/action/theme-toggle.js +259 -0
- package/dist/action/theme-toggle.js.map +1 -0
- package/dist/action/toggle.d.ts +44 -0
- package/dist/action/toggle.js +28 -0
- package/dist/action/toggle.js.map +1 -0
- package/dist/action/touch-target.d.ts +9 -0
- package/dist/action/touch-target.js +14 -0
- package/dist/action/touch-target.js.map +1 -0
- package/dist/charts/axis-width.d.ts +186 -0
- package/dist/charts/axis-width.js +1262 -0
- package/dist/charts/axis-width.js.map +1 -0
- package/dist/charts/bar-public.d.ts +16 -0
- package/dist/charts/bar-public.js +16 -0
- package/dist/charts/bar-public.js.map +1 -0
- package/dist/charts/chart-parts.d.ts +136 -0
- package/dist/charts/chart-parts.js +160 -0
- package/dist/charts/chart-parts.js.map +1 -0
- package/dist/charts/core-charts.d.ts +157 -0
- package/dist/charts/core-charts.js +505 -0
- package/dist/charts/core-charts.js.map +1 -0
- package/dist/charts/index.d.ts +12 -0
- package/dist/charts/index.js +8 -0
- package/dist/charts/index.js.map +1 -0
- package/dist/charts/list-charts.d.ts +124 -0
- package/dist/charts/list-charts.js +308 -0
- package/dist/charts/list-charts.js.map +1 -0
- package/dist/charts/more-charts.d.ts +138 -0
- package/dist/charts/more-charts.js +284 -0
- package/dist/charts/more-charts.js.map +1 -0
- package/dist/charts/report-charts.d.ts +138 -0
- package/dist/charts/report-charts.js +370 -0
- package/dist/charts/report-charts.js.map +1 -0
- package/dist/charts/value-tick.d.ts +178 -0
- package/dist/charts/value-tick.js +240 -0
- package/dist/charts/value-tick.js.map +1 -0
- package/dist/collection/data-table-url-hook.d.ts +34 -0
- package/dist/collection/data-table-url-hook.js +70 -0
- package/dist/collection/data-table-url-hook.js.map +1 -0
- package/dist/collection/data-table-url.d.ts +30 -0
- package/dist/collection/data-table-url.js +48 -0
- package/dist/collection/data-table-url.js.map +1 -0
- package/dist/collection/data-table.d.ts +112 -0
- package/dist/collection/data-table.js +188 -0
- package/dist/collection/data-table.js.map +1 -0
- package/dist/collection/grid-list-public.d.ts +18 -0
- package/dist/collection/grid-list-public.js +19 -0
- package/dist/collection/grid-list-public.js.map +1 -0
- package/dist/collection/grid-list.d.ts +73 -0
- package/dist/collection/grid-list.js +46 -0
- package/dist/collection/grid-list.js.map +1 -0
- package/dist/collection/index.d.ts +14 -0
- package/dist/collection/index.js +8 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/list.d.ts +61 -0
- package/dist/collection/list.js +38 -0
- package/dist/collection/list.js.map +1 -0
- package/dist/collection/selection-checkbox.d.ts +5 -0
- package/dist/collection/selection-checkbox.js +13 -0
- package/dist/collection/selection-checkbox.js.map +1 -0
- package/dist/collection/table.d.ts +91 -0
- package/dist/collection/table.js +183 -0
- package/dist/collection/table.js.map +1 -0
- package/dist/collection/tree.d.ts +31 -0
- package/dist/collection/tree.js +22 -0
- package/dist/collection/tree.js.map +1 -0
- package/dist/color/color.d.ts +87 -0
- package/dist/color/color.js +200 -0
- package/dist/color/color.js.map +1 -0
- package/dist/color/contrast.d.ts +34 -0
- package/dist/color/contrast.js +44 -0
- package/dist/color/contrast.js.map +1 -0
- package/dist/color/index.d.ts +4 -0
- package/dist/color/index.js +5 -0
- package/dist/color/index.js.map +1 -0
- package/dist/date/calendar.d.ts +71 -0
- package/dist/date/calendar.js +291 -0
- package/dist/date/calendar.js.map +1 -0
- package/dist/date/fields.d.ts +174 -0
- package/dist/date/fields.js +250 -0
- package/dist/date/fields.js.map +1 -0
- package/dist/date/index.d.ts +7 -0
- package/dist/date/index.js +6 -0
- package/dist/date/index.js.map +1 -0
- package/dist/date/month-grid.d.ts +31 -0
- package/dist/date/month-grid.js +115 -0
- package/dist/date/month-grid.js.map +1 -0
- package/dist/date/pickers.d.ts +118 -0
- package/dist/date/pickers.js +176 -0
- package/dist/date/pickers.js.map +1 -0
- package/dist/date/public.d.ts +25 -0
- package/dist/date/public.js +24 -0
- package/dist/date/public.js.map +1 -0
- package/dist/date/segments.d.ts +153 -0
- package/dist/date/segments.js +433 -0
- package/dist/date/segments.js.map +1 -0
- package/dist/defaults.d.ts +74 -0
- package/dist/defaults.js +100 -0
- package/dist/defaults.js.map +1 -0
- package/dist/density.d.ts +2 -0
- package/dist/density.js +2 -0
- package/dist/density.js.map +1 -0
- package/dist/display/avatar.d.ts +29 -0
- package/dist/display/avatar.js +71 -0
- package/dist/display/avatar.js.map +1 -0
- package/dist/display/badge.d.ts +65 -0
- package/dist/display/badge.js +99 -0
- package/dist/display/badge.js.map +1 -0
- package/dist/display/card.d.ts +72 -0
- package/dist/display/card.js +91 -0
- package/dist/display/card.js.map +1 -0
- package/dist/display/carousel.d.ts +47 -0
- package/dist/display/carousel.js +214 -0
- package/dist/display/carousel.js.map +1 -0
- package/dist/display/description-list.d.ts +25 -0
- package/dist/display/description-list.js +36 -0
- package/dist/display/description-list.js.map +1 -0
- package/dist/display/icon-aliases.d.ts +1 -0
- package/dist/display/icon-aliases.js +259 -0
- package/dist/display/icon-aliases.js.map +1 -0
- package/dist/display/icon-names.d.ts +4 -0
- package/dist/display/icon-names.js +2 -0
- package/dist/display/icon-names.js.map +1 -0
- package/dist/display/icon.d.ts +51 -0
- package/dist/display/icon.js +96 -0
- package/dist/display/icon.js.map +1 -0
- package/dist/display/image-crop.d.ts +106 -0
- package/dist/display/image-crop.js +117 -0
- package/dist/display/image-crop.js.map +1 -0
- package/dist/display/image-cropper.d.ts +68 -0
- package/dist/display/image-cropper.js +284 -0
- package/dist/display/image-cropper.js.map +1 -0
- package/dist/display/image-viewer.d.ts +54 -0
- package/dist/display/image-viewer.js +84 -0
- package/dist/display/image-viewer.js.map +1 -0
- package/dist/display/image.d.ts +26 -0
- package/dist/display/image.js +17 -0
- package/dist/display/image.js.map +1 -0
- package/dist/display/index.d.ts +29 -0
- package/dist/display/index.js +16 -0
- package/dist/display/index.js.map +1 -0
- package/dist/display/iso-chip.d.ts +19 -0
- package/dist/display/iso-chip.js +21 -0
- package/dist/display/iso-chip.js.map +1 -0
- package/dist/display/kbd.d.ts +11 -0
- package/dist/display/kbd.js +33 -0
- package/dist/display/kbd.js.map +1 -0
- package/dist/display/lozenge.d.ts +30 -0
- package/dist/display/lozenge.js +55 -0
- package/dist/display/lozenge.js.map +1 -0
- package/dist/display/scroll-area.d.ts +29 -0
- package/dist/display/scroll-area.js +95 -0
- package/dist/display/scroll-area.js.map +1 -0
- package/dist/display/separator.d.ts +13 -0
- package/dist/display/separator.js +24 -0
- package/dist/display/separator.js.map +1 -0
- package/dist/display/stat.d.ts +35 -0
- package/dist/display/stat.js +41 -0
- package/dist/display/stat.js.map +1 -0
- package/dist/display/timeline.d.ts +44 -0
- package/dist/display/timeline.js +111 -0
- package/dist/display/timeline.js.map +1 -0
- package/dist/display/typography.d.ts +37 -0
- package/dist/display/typography.js +53 -0
- package/dist/display/typography.js.map +1 -0
- package/dist/display/visually-hidden.d.ts +14 -0
- package/dist/display/visually-hidden.js +10 -0
- package/dist/display/visually-hidden.js.map +1 -0
- package/dist/feedback/banner.d.ts +46 -0
- package/dist/feedback/banner.js +157 -0
- package/dist/feedback/banner.js.map +1 -0
- package/dist/feedback/cooldown.d.ts +17 -0
- package/dist/feedback/cooldown.js +59 -0
- package/dist/feedback/cooldown.js.map +1 -0
- package/dist/feedback/empty-state.d.ts +35 -0
- package/dist/feedback/empty-state.js +39 -0
- package/dist/feedback/empty-state.js.map +1 -0
- package/dist/feedback/index.d.ts +12 -0
- package/dist/feedback/index.js +11 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/feedback/meter.d.ts +33 -0
- package/dist/feedback/meter.js +42 -0
- package/dist/feedback/meter.js.map +1 -0
- package/dist/feedback/motion.d.ts +9 -0
- package/dist/feedback/motion.js +57 -0
- package/dist/feedback/motion.js.map +1 -0
- package/dist/feedback/progress.d.ts +39 -0
- package/dist/feedback/progress.js +68 -0
- package/dist/feedback/progress.js.map +1 -0
- package/dist/feedback/skeleton.d.ts +48 -0
- package/dist/feedback/skeleton.js +61 -0
- package/dist/feedback/skeleton.js.map +1 -0
- package/dist/feedback/spinner.d.ts +19 -0
- package/dist/feedback/spinner.js +29 -0
- package/dist/feedback/spinner.js.map +1 -0
- package/dist/feedback/status-dot.d.ts +23 -0
- package/dist/feedback/status-dot.js +37 -0
- package/dist/feedback/status-dot.js.map +1 -0
- package/dist/form/countries.d.ts +34 -0
- package/dist/form/countries.js +273 -0
- package/dist/form/countries.js.map +1 -0
- package/dist/form/data-attributes.d.ts +11 -0
- package/dist/form/data-attributes.js +22 -0
- package/dist/form/data-attributes.js.map +1 -0
- package/dist/form/field-parts.d.ts +113 -0
- package/dist/form/field-parts.js +178 -0
- package/dist/form/field-parts.js.map +1 -0
- package/dist/form/field.d.ts +36 -0
- package/dist/form/field.js +65 -0
- package/dist/form/field.js.map +1 -0
- package/dist/form/files.d.ts +70 -0
- package/dist/form/files.js +156 -0
- package/dist/form/files.js.map +1 -0
- package/dist/form/form.d.ts +40 -0
- package/dist/form/form.js +74 -0
- package/dist/form/form.js.map +1 -0
- package/dist/form/image-crop.d.ts +106 -0
- package/dist/form/image-crop.js +117 -0
- package/dist/form/image-crop.js.map +1 -0
- package/dist/form/image-cropper.d.ts +68 -0
- package/dist/form/image-cropper.js +284 -0
- package/dist/form/image-cropper.js.map +1 -0
- package/dist/form/index.d.ts +24 -0
- package/dist/form/index.js +15 -0
- package/dist/form/index.js.map +1 -0
- package/dist/form/input-group.d.ts +63 -0
- package/dist/form/input-group.js +63 -0
- package/dist/form/input-group.js.map +1 -0
- package/dist/form/input-otp.d.ts +35 -0
- package/dist/form/input-otp.js +83 -0
- package/dist/form/input-otp.js.map +1 -0
- package/dist/form/input.d.ts +36 -0
- package/dist/form/input.js +41 -0
- package/dist/form/input.js.map +1 -0
- package/dist/form/number-field.d.ts +84 -0
- package/dist/form/number-field.js +81 -0
- package/dist/form/number-field.js.map +1 -0
- package/dist/form/otp-field.d.ts +37 -0
- package/dist/form/otp-field.js +116 -0
- package/dist/form/otp-field.js.map +1 -0
- package/dist/form/password-field.d.ts +61 -0
- package/dist/form/password-field.js +61 -0
- package/dist/form/password-field.js.map +1 -0
- package/dist/form/phone-field.d.ts +104 -0
- package/dist/form/phone-field.js +275 -0
- package/dist/form/phone-field.js.map +1 -0
- package/dist/form/phone-paste.d.ts +24 -0
- package/dist/form/phone-paste.js +40 -0
- package/dist/form/phone-paste.js.map +1 -0
- package/dist/form/phone.d.ts +159 -0
- package/dist/form/phone.js +309 -0
- package/dist/form/phone.js.map +1 -0
- package/dist/form/search-field.d.ts +29 -0
- package/dist/form/search-field.js +23 -0
- package/dist/form/search-field.js.map +1 -0
- package/dist/form/styles.d.ts +31 -0
- package/dist/form/styles.js +43 -0
- package/dist/form/styles.js.map +1 -0
- package/dist/form/text-area.d.ts +70 -0
- package/dist/form/text-area.js +93 -0
- package/dist/form/text-area.js.map +1 -0
- package/dist/form/text-field.d.ts +131 -0
- package/dist/form/text-field.js +59 -0
- package/dist/form/text-field.js.map +1 -0
- package/dist/form/validation.d.ts +145 -0
- package/dist/form/validation.js +136 -0
- package/dist/form/validation.js.map +1 -0
- package/dist/i18n.d.ts +438 -0
- package/dist/i18n.js +948 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/intl-locale.d.ts +30 -0
- package/dist/intl-locale.js +83 -0
- package/dist/intl-locale.js.map +1 -0
- package/dist/layers.d.ts +32 -0
- package/dist/layers.js +33 -0
- package/dist/layers.js.map +1 -0
- package/dist/layout/auth-form-layout.d.ts +71 -0
- package/dist/layout/auth-form-layout.js +61 -0
- package/dist/layout/auth-form-layout.js.map +1 -0
- package/dist/layout/auth-layout.d.ts +59 -0
- package/dist/layout/auth-layout.js +26 -0
- package/dist/layout/auth-layout.js.map +1 -0
- package/dist/layout/box.d.ts +26 -0
- package/dist/layout/box.js +16 -0
- package/dist/layout/box.js.map +1 -0
- package/dist/layout/grid.d.ts +27 -0
- package/dist/layout/grid.js +26 -0
- package/dist/layout/grid.js.map +1 -0
- package/dist/layout/index.d.ts +16 -0
- package/dist/layout/index.js +12 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/pressable.d.ts +40 -0
- package/dist/layout/pressable.js +65 -0
- package/dist/layout/pressable.js.map +1 -0
- package/dist/layout/reset-sent-card.d.ts +39 -0
- package/dist/layout/reset-sent-card.js +22 -0
- package/dist/layout/reset-sent-card.js.map +1 -0
- package/dist/layout/scroll-area.d.ts +29 -0
- package/dist/layout/scroll-area.js +95 -0
- package/dist/layout/scroll-area.js.map +1 -0
- package/dist/layout/section.d.ts +41 -0
- package/dist/layout/section.js +22 -0
- package/dist/layout/section.js.map +1 -0
- package/dist/layout/split.d.ts +50 -0
- package/dist/layout/split.js +35 -0
- package/dist/layout/split.js.map +1 -0
- package/dist/layout/stack.d.ts +44 -0
- package/dist/layout/stack.js +36 -0
- package/dist/layout/stack.js.map +1 -0
- package/dist/layout/tokens.d.ts +33 -0
- package/dist/layout/tokens.js +85 -0
- package/dist/layout/tokens.js.map +1 -0
- package/dist/layout/toolbar.d.ts +37 -0
- package/dist/layout/toolbar.js +334 -0
- package/dist/layout/toolbar.js.map +1 -0
- package/dist/navigate-context.d.ts +12 -0
- package/dist/navigate-context.js +13 -0
- package/dist/navigate-context.js.map +1 -0
- package/dist/navigation/accordion.d.ts +40 -0
- package/dist/navigation/accordion.js +33 -0
- package/dist/navigation/accordion.js.map +1 -0
- package/dist/navigation/bottom-nav.d.ts +29 -0
- package/dist/navigation/bottom-nav.js +48 -0
- package/dist/navigation/bottom-nav.js.map +1 -0
- package/dist/navigation/brand-link-context.d.ts +8 -0
- package/dist/navigation/brand-link-context.js +9 -0
- package/dist/navigation/brand-link-context.js.map +1 -0
- package/dist/navigation/breadcrumbs.d.ts +36 -0
- package/dist/navigation/breadcrumbs.js +51 -0
- package/dist/navigation/breadcrumbs.js.map +1 -0
- package/dist/navigation/dock.d.ts +27 -0
- package/dist/navigation/dock.js +47 -0
- package/dist/navigation/dock.js.map +1 -0
- package/dist/navigation/footer.d.ts +43 -0
- package/dist/navigation/footer.js +43 -0
- package/dist/navigation/footer.js.map +1 -0
- package/dist/navigation/index.d.ts +22 -0
- package/dist/navigation/index.js +17 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/language-names.d.ts +19 -0
- package/dist/navigation/language-names.js +79 -0
- package/dist/navigation/language-names.js.map +1 -0
- package/dist/navigation/language-switcher.d.ts +55 -0
- package/dist/navigation/language-switcher.js +53 -0
- package/dist/navigation/language-switcher.js.map +1 -0
- package/dist/navigation/nav-panel.d.ts +18 -0
- package/dist/navigation/nav-panel.js +51 -0
- package/dist/navigation/nav-panel.js.map +1 -0
- package/dist/navigation/navbar.d.ts +73 -0
- package/dist/navigation/navbar.js +64 -0
- package/dist/navigation/navbar.js.map +1 -0
- package/dist/navigation/page-header.d.ts +37 -0
- package/dist/navigation/page-header.js +50 -0
- package/dist/navigation/page-header.js.map +1 -0
- package/dist/navigation/pagination.d.ts +25 -0
- package/dist/navigation/pagination.js +51 -0
- package/dist/navigation/pagination.js.map +1 -0
- package/dist/navigation/panel-header.d.ts +37 -0
- package/dist/navigation/panel-header.js +50 -0
- package/dist/navigation/panel-header.js.map +1 -0
- package/dist/navigation/sidebar-script.d.ts +12 -0
- package/dist/navigation/sidebar-script.js +20 -0
- package/dist/navigation/sidebar-script.js.map +1 -0
- package/dist/navigation/sidebar.d.ts +149 -0
- package/dist/navigation/sidebar.js +332 -0
- package/dist/navigation/sidebar.js.map +1 -0
- package/dist/navigation/skip-link.d.ts +12 -0
- package/dist/navigation/skip-link.js +30 -0
- package/dist/navigation/skip-link.js.map +1 -0
- package/dist/navigation/stepper.d.ts +50 -0
- package/dist/navigation/stepper.js +96 -0
- package/dist/navigation/stepper.js.map +1 -0
- package/dist/navigation/tabs.d.ts +84 -0
- package/dist/navigation/tabs.js +118 -0
- package/dist/navigation/tabs.js.map +1 -0
- package/dist/navigation/toolbar.d.ts +37 -0
- package/dist/navigation/toolbar.js +334 -0
- package/dist/navigation/toolbar.js.map +1 -0
- package/dist/overlay/alert-dialog.d.ts +63 -0
- package/dist/overlay/alert-dialog.js +76 -0
- package/dist/overlay/alert-dialog.js.map +1 -0
- package/dist/overlay/command-palette.d.ts +53 -0
- package/dist/overlay/command-palette.js +130 -0
- package/dist/overlay/command-palette.js.map +1 -0
- package/dist/overlay/command.d.ts +53 -0
- package/dist/overlay/command.js +129 -0
- package/dist/overlay/command.js.map +1 -0
- package/dist/overlay/context-menu.d.ts +29 -0
- package/dist/overlay/context-menu.js +58 -0
- package/dist/overlay/context-menu.js.map +1 -0
- package/dist/overlay/dialog.d.ts +162 -0
- package/dist/overlay/dialog.js +174 -0
- package/dist/overlay/dialog.js.map +1 -0
- package/dist/overlay/drawer.d.ts +41 -0
- package/dist/overlay/drawer.js +114 -0
- package/dist/overlay/drawer.js.map +1 -0
- package/dist/overlay/floating.d.ts +142 -0
- package/dist/overlay/floating.js +226 -0
- package/dist/overlay/floating.js.map +1 -0
- package/dist/overlay/hover-card.d.ts +19 -0
- package/dist/overlay/hover-card.js +31 -0
- package/dist/overlay/hover-card.js.map +1 -0
- package/dist/overlay/index.d.ts +18 -0
- package/dist/overlay/index.js +12 -0
- package/dist/overlay/index.js.map +1 -0
- package/dist/overlay/overlay-base.d.ts +105 -0
- package/dist/overlay/overlay-base.js +250 -0
- package/dist/overlay/overlay-base.js.map +1 -0
- package/dist/overlay/overlay.d.ts +299 -0
- package/dist/overlay/overlay.js +558 -0
- package/dist/overlay/overlay.js.map +1 -0
- package/dist/overlay/toast.d.ts +58 -0
- package/dist/overlay/toast.js +145 -0
- package/dist/overlay/toast.js.map +1 -0
- package/dist/provider.d.ts +26 -0
- package/dist/provider.js +30 -0
- package/dist/provider.js.map +1 -0
- package/dist/selection/autocomplete.d.ts +54 -0
- package/dist/selection/autocomplete.js +122 -0
- package/dist/selection/autocomplete.js.map +1 -0
- package/dist/selection/checkbox.d.ts +56 -0
- package/dist/selection/checkbox.js +49 -0
- package/dist/selection/checkbox.js.map +1 -0
- package/dist/selection/choice-size.d.ts +26 -0
- package/dist/selection/choice-size.js +50 -0
- package/dist/selection/choice-size.js.map +1 -0
- package/dist/selection/choice-text.d.ts +21 -0
- package/dist/selection/choice-text.js +33 -0
- package/dist/selection/choice-text.js.map +1 -0
- package/dist/selection/combobox.d.ts +173 -0
- package/dist/selection/combobox.js +410 -0
- package/dist/selection/combobox.js.map +1 -0
- package/dist/selection/index.d.ts +20 -0
- package/dist/selection/index.js +13 -0
- package/dist/selection/index.js.map +1 -0
- package/dist/selection/list-box.d.ts +30 -0
- package/dist/selection/list-box.js +16 -0
- package/dist/selection/list-box.js.map +1 -0
- package/dist/selection/listbox.d.ts +44 -0
- package/dist/selection/listbox.js +49 -0
- package/dist/selection/listbox.js.map +1 -0
- package/dist/selection/match.d.ts +20 -0
- package/dist/selection/match.js +57 -0
- package/dist/selection/match.js.map +1 -0
- package/dist/selection/multi-select.d.ts +72 -0
- package/dist/selection/multi-select.js +138 -0
- package/dist/selection/multi-select.js.map +1 -0
- package/dist/selection/radio-card.d.ts +31 -0
- package/dist/selection/radio-card.js +29 -0
- package/dist/selection/radio-card.js.map +1 -0
- package/dist/selection/radio.d.ts +72 -0
- package/dist/selection/radio.js +64 -0
- package/dist/selection/radio.js.map +1 -0
- package/dist/selection/select-public.d.ts +19 -0
- package/dist/selection/select-public.js +24 -0
- package/dist/selection/select-public.js.map +1 -0
- package/dist/selection/select.d.ts +72 -0
- package/dist/selection/select.js +69 -0
- package/dist/selection/select.js.map +1 -0
- package/dist/selection/slider.d.ts +16 -0
- package/dist/selection/slider.js +44 -0
- package/dist/selection/slider.js.map +1 -0
- package/dist/selection/styles.d.ts +26 -0
- package/dist/selection/styles.js +78 -0
- package/dist/selection/styles.js.map +1 -0
- package/dist/selection/switch.d.ts +24 -0
- package/dist/selection/switch.js +27 -0
- package/dist/selection/switch.js.map +1 -0
- package/dist/selection/tag-group.d.ts +38 -0
- package/dist/selection/tag-group.js +45 -0
- package/dist/selection/tag-group.js.map +1 -0
- package/dist/tone.d.ts +6 -0
- package/dist/tone.js +2 -0
- package/dist/tone.js.map +1 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +42 -0
- package/dist/utils.js.map +1 -0
- package/manifest/component.full.schema.json +391 -0
- package/manifest/component.schema.json +279 -0
- package/manifests/accordion.json +299 -0
- package/manifests/alert-dialog.json +261 -0
- package/manifests/area-chart.json +338 -0
- package/manifests/autocomplete.json +299 -0
- package/manifests/avatar.json +253 -0
- package/manifests/badge.json +288 -0
- package/manifests/banner.json +185 -0
- package/manifests/bar-chart.json +454 -0
- package/manifests/bar-list.json +262 -0
- package/manifests/bottom-nav.json +139 -0
- package/manifests/box.json +3450 -0
- package/manifests/breadcrumbs.json +199 -0
- package/manifests/button-group.json +2294 -0
- package/manifests/button.json +1211 -0
- package/manifests/calendar-heatmap.json +218 -0
- package/manifests/calendar.json +299 -0
- package/manifests/card.json +308 -0
- package/manifests/carousel.json +263 -0
- package/manifests/chart-parts.json +309 -0
- package/manifests/checkbox.json +998 -0
- package/manifests/close-button.json +1000 -0
- package/manifests/color-field.json +276 -0
- package/manifests/color-picker.json +161 -0
- package/manifests/color-swatch-picker.json +220 -0
- package/manifests/color-swatch.json +140 -0
- package/manifests/combobox.json +581 -0
- package/manifests/command.json +275 -0
- package/manifests/composed-chart.json +287 -0
- package/manifests/context-menu.json +148 -0
- package/manifests/copy-button.json +192 -0
- package/manifests/data-table.json +334 -0
- package/manifests/date-field.json +302 -0
- package/manifests/date-picker.json +472 -0
- package/manifests/description-list.json +201 -0
- package/manifests/dialog.json +322 -0
- package/manifests/donut-chart.json +264 -0
- package/manifests/drawer.json +211 -0
- package/manifests/empty-state.json +185 -0
- package/manifests/fab.json +172 -0
- package/manifests/field.json +209 -0
- package/manifests/file-upload.json +791 -0
- package/manifests/form.json +829 -0
- package/manifests/funnel-chart.json +223 -0
- package/manifests/gauge-chart.json +252 -0
- package/manifests/grid-list.json +335 -0
- package/manifests/grid.json +3482 -0
- package/manifests/heading.json +183 -0
- package/manifests/heatmap.json +265 -0
- package/manifests/hover-card.json +172 -0
- package/manifests/icon.json +201 -0
- package/manifests/image-cropper.json +295 -0
- package/manifests/image-viewer.json +198 -0
- package/manifests/image.json +193 -0
- package/manifests/index.json +2035 -0
- package/manifests/input-group.json +3571 -0
- package/manifests/input.json +1557 -0
- package/manifests/kbd.json +98 -0
- package/manifests/language-switcher.json +274 -0
- package/manifests/line-chart.json +342 -0
- package/manifests/link.json +867 -0
- package/manifests/list-box.json +213 -0
- package/manifests/menu.json +453 -0
- package/manifests/meter.json +145 -0
- package/manifests/navbar.json +281 -0
- package/manifests/otp-field.json +1029 -0
- package/manifests/page-header.json +164 -0
- package/manifests/pagination.json +181 -0
- package/manifests/popover.json +205 -0
- package/manifests/pressable.json +367 -0
- package/manifests/progress.json +282 -0
- package/manifests/radar-chart.json +229 -0
- package/manifests/radial-chart.json +195 -0
- package/manifests/radio.json +975 -0
- package/manifests/scatter-chart.json +277 -0
- package/manifests/scroll-area.json +127 -0
- package/manifests/section.json +169 -0
- package/manifests/select.json +474 -0
- package/manifests/separator.json +119 -0
- package/manifests/sidebar.json +584 -0
- package/manifests/skeleton.json +235 -0
- package/manifests/skip-link.json +89 -0
- package/manifests/slider.json +706 -0
- package/manifests/sparkline.json +208 -0
- package/manifests/spinner.json +105 -0
- package/manifests/split.json +6618 -0
- package/manifests/stack.json +3541 -0
- package/manifests/stat.json +192 -0
- package/manifests/stepper.json +279 -0
- package/manifests/switch.json +205 -0
- package/manifests/table.json +375 -0
- package/manifests/tabs.json +438 -0
- package/manifests/tag-group.json +264 -0
- package/manifests/text-area.json +1136 -0
- package/manifests/text.json +244 -0
- package/manifests/theme-switcher.json +152 -0
- package/manifests/time-field.json +284 -0
- package/manifests/timeline.json +196 -0
- package/manifests/toast.json +87 -0
- package/manifests/toggle-button.json +1489 -0
- package/manifests/toolbar.json +145 -0
- package/manifests/tooltip.json +181 -0
- package/manifests/tracker.json +192 -0
- package/manifests/tree.json +245 -0
- package/manifests/visually-hidden.json +114 -0
- package/package.json +117 -3
- package/styles/base.css +56 -0
- package/styles/theme.css +154 -0
|
@@ -0,0 +1,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 "./button.js";
|
|
9
|
+
import { LINK_FOCUS } from "./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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/action/files.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb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riaFileTrigger,\n useLocale,\n type DropItem,\n type FileTriggerProps as AriaFileTriggerProps,\n} from \"react-aria-components\";\nimport { IconGlyph } from \"../display/icon\";\n\nimport { cn } from \"../utils\";\nimport {\n cancelUploadLabel, chooseFilesLabel, onlyOneLabel, orChooseTemplate, removeFileLabel, replaceLabel, tooLargeLabel, upToLabel,\n uploadedLabel, wrongTypeLabel,\n} from \"../i18n\";\nimport { Button } from \"./button\";\nimport { LINK_FOCUS } from \"./styles\";\n\n/** Bytes as the locale writes them: \"2.4 MB\", \"980 kB\". */\nexport function formatFileSize(bytes: number, locale: string): string {\n const units = [\"byte\", \"kilobyte\", \"megabyte\", \"gigabyte\"] as const;\n let value = bytes;\n let unit = 0;\n // Round the way the unit will print before choosing it, so 999,600 bytes is \"1 MB\", not \"1.000 kB\".\n const rounded = () => (unit < 2 ? Math.round(value) : Math.round(value * 10) / 10);\n while (rounded() >= 1000 && unit < units.length - 1) {\n value /= 1000;\n unit += 1;\n }\n return new Intl.NumberFormat(locale, {\n style: \"unit\",\n unit: units[unit],\n unitDisplay: \"short\",\n maximumFractionDigits: unit < 2 ? 0 : 1,\n }).format(value);\n}\n\nexport type FileRules = {\n /** MIME types or extensions: \"image/jpeg\", \"image/*\", \".heic\", \"application/pdf\". */\n acceptedFileTypes?: readonly string[];\n /** Bytes. */\n maxSize?: number;\n};\n\nexport type RejectedFile = { file: File; reason: string };\n\nfunction accepts(file: File, types: readonly string[] | undefined) {\n if (!types || types.length === 0) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return types.some((rule) => {\n const pattern = rule.toLowerCase().trim();\n if (pattern.startsWith(\".\")) return name.endsWith(pattern);\n if (pattern.endsWith(\"/*\")) return type.startsWith(pattern.slice(0, -1));\n return type === pattern;\n });\n}\n\n/**\n * Checks each file on its own: a wrong type or a file over `maxSize` is\n * rejected with the reason, and the others are kept (design rule).\n */\nexport function validateFiles(files: readonly File[], rules: FileRules, locale: string) {\n const accepted: File[] = [];\n const rejected: RejectedFile[] = [];\n for (const file of files) {\n if (!accepts(file, rules.acceptedFileTypes)) rejected.push({ file, reason: wrongTypeLabel(locale) });\n else if (rules.maxSize !== undefined && file.size > rules.maxSize) {\n rejected.push({ file, reason: tooLargeLabel(locale, formatFileSize(rules.maxSize, locale)) });\n } else accepted.push(file);\n }\n return { accepted, rejected };\n}\n\nexport type FileTriggerProps = Omit<AriaFileTriggerProps, \"onSelect\" | \"acceptedFileTypes\"> &\n FileRules & {\n /** Files that passed the rules. */\n onSelect?: (files: File[]) => void;\n /** Files that did not, each with its reason. */\n onReject?: (rejected: RejectedFile[]) => void;\n /** The control that opens the picker: a DS Button or Link. */\n children: React.ReactElement;\n };\n\n/**\n * Hands the picked files on, then empties the picker's hidden input, so the same file picked again is\n * a change and reaches the app again, however the input was filled. The files are copied\n * out of the FileList before the callbacks run; clearing the input empties that list, not the copies.\n */\nfunction pickThenClear(input: React.RefObject<HTMLInputElement | null>, list: FileList | null, handle: (files: File[]) => void) {\n const files = Array.from(list ?? []);\n try {\n handle(files);\n } finally {\n if (input.current) input.current.value = \"\";\n }\n}\n\n/** Opens the system file picker from any button. */\nexport function FileTrigger({ onSelect, onReject, acceptedFileTypes, maxSize, children, ...rest }: FileTriggerProps) {\n const { locale } = useLocale();\n const inputRef = React.useRef<HTMLInputElement>(null);\n return (\n <AriaFileTrigger\n {...rest}\n ref={inputRef}\n acceptedFileTypes={acceptedFileTypes ? [...acceptedFileTypes] : undefined}\n onSelect={(list) =>\n pickThenClear(inputRef, list, (files) => {\n const { accepted, rejected } = validateFiles(files, { acceptedFileTypes, maxSize }, locale);\n if (accepted.length) onSelect?.(accepted);\n if (rejected.length) onReject?.(rejected);\n })\n }\n >\n {children}\n </AriaFileTrigger>\n );\n}\n\nexport type DropZoneProps = FileRules & {\n /** What to drop, as a call to action: \"Drag your photos here\". */\n label: string;\n /** The accepted types as people read them (\"JPG, PNG, HEIC\"); the size limit is added. */\n typesLabel?: string;\n allowsMultiple?: boolean;\n onSelect?: (files: File[]) => void;\n onReject?: (rejected: RejectedFile[]) => void;\n isDisabled?: boolean;\n};\n\n/** The files among dropped items; folders, text and files the browser cannot read are skipped. */\nexport async function filesFrom(items: readonly DropItem[]) {\n const reads = items.flatMap((item) => (item.kind === \"file\" ? [item.getFile()] : []));\n const results = await Promise.allSettled(reads);\n return results.flatMap((result) => (result.status === \"fulfilled\" ? [result.value] : []));\n}\n\n/**\n * A drop target with the picker inside: states the accepted types and the\n * size limit before the user picks; while a file is over it the zone takes\n * the selected fill and border.\n */\nexport function DropZone({ label, typesLabel, allowsMultiple, acceptedFileTypes, maxSize, onSelect, onReject, isDisabled }: DropZoneProps) {\n const { locale } = useLocale();\n const inputRef = React.useRef<HTMLInputElement>(null);\n const handle = (files: File[]) => {\n const list = allowsMultiple ? files : files.slice(0, 1);\n const { accepted, rejected } = validateFiles(list, { acceptedFileTypes, maxSize }, locale);\n // Extra files on a single-file zone are rejected with a reason, never dropped silently.\n if (!allowsMultiple) for (const file of files.slice(1)) rejected.push({ file, reason: onlyOneLabel(locale) });\n if (accepted.length) onSelect?.(accepted);\n if (rejected.length) onReject?.(rejected);\n };\n const [before, after] = orChooseTemplate(locale).split(\"{choose}\");\n const details = [typesLabel, maxSize !== undefined ? upToLabel(locale, formatFileSize(maxSize, locale)) : undefined]\n .filter(Boolean)\n .join(\" · \");\n\n return (\n <AriaDropZone\n // Names the zone's keyboard and paste target (React Aria's own fallback is the untranslated \"DropZone\").\n aria-label={label}\n isDisabled={isDisabled}\n onDrop={async (event) => handle(await filesFrom(event.items))}\n data-slot=\"drop-zone\"\n className={cn(\n \"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\",\n \"data-[drop-target]:border-ds-border-selected data-[drop-target]:bg-ds-background-selected\",\n // Keyboard focus: the 2px inner border every DS control uses.\n \"data-[focus-visible]:inset-ring-2 data-[focus-visible]:inset-ring-ds-border-focused\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:border-ds-border data-[disabled]:bg-ds-background-disabled\",\n )}\n >\n <IconGlyph name=\"image-up\" size=\"large\" color=\"subtle\" data-slot=\"drop-zone-icon\" />\n <span data-slot=\"drop-zone-label\" className=\"text-body-strong text-ds-text\">{label}</span>\n <span data-slot=\"drop-zone-help\" className=\"text-body-small text-ds-text-subtlest\">\n {before}\n <AriaFileTrigger\n ref={inputRef}\n allowsMultiple={allowsMultiple}\n acceptedFileTypes={acceptedFileTypes ? [...acceptedFileTypes] : undefined}\n onSelect={(list) => pickThenClear(inputRef, list, handle)}\n >\n <AriaButton\n isDisabled={isDisabled}\n data-slot=\"drop-zone-choose\"\n className={cn(\n \"cursor-pointer text-ds-link underline-offset-3 data-[hovered]:underline\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-ds-text-disabled data-[disabled]:no-underline\",\n LINK_FOCUS,\n )}\n >\n {chooseFilesLabel(locale)}\n </AriaButton>\n </AriaFileTrigger>\n {after}\n {details && ` · ${details}`}\n </span>\n </AriaDropZone>\n );\n}\n\n/** A thumbnail URL for an image file, created in an effect and revoked on change or unmount. */\nfunction useObjectUrl(file: File | undefined) {\n const [url, setUrl] = React.useState<string>();\n React.useEffect(() => {\n if (!file || !file.type.startsWith(\"image/\") || typeof URL.createObjectURL !== \"function\") {\n setUrl(undefined);\n return;\n }\n const next = URL.createObjectURL(file);\n setUrl(next);\n return () => URL.revokeObjectURL(next);\n }, [file]);\n return url;\n}\n\nexport type FileRowProps = {\n /** The picked file; photos get a thumbnail at once, before upload ends. */\n file?: File;\n /** Shown name and size when there is no File object (a stored document). */\n name?: string;\n size?: number;\n /** 0–1 while uploading; omit when done. */\n progress?: number;\n error?: string;\n onCancel?: () => void;\n onRemove?: () => void;\n onReplace?: () => void;\n};\n\n/** One picked or stored file: thumbnail, name, progress or size, per-file error, one trailing action. */\nexport function FileRow({ file, name, size, progress, error, onCancel, onRemove, onReplace }: FileRowProps) {\n const { locale } = useLocale();\n const url = useObjectUrl(file);\n // A type the browser cannot draw (HEIC on most browsers) falls back to the file icon.\n const [broken, setBroken] = React.useState<string>();\n const thumbnail = url && url !== broken ? url : undefined;\n const total = size ?? file?.size;\n const uploading = progress !== undefined && progress < 1 && !error;\n\n return (\n <li\n data-slot=\"file-row\"\n data-state={error ? \"error\" : uploading ? \"uploading\" : \"done\"}\n className=\"flex items-center gap-ds-150 rounded-ds-large bg-ds-surface-raised p-ds-100 pe-ds-150 shadow-ds-raised\"\n >\n <span data-slot=\"file-thumbnail\" className=\"grid size-10 shrink-0 place-items-center overflow-hidden rounded-ds-medium bg-ds-surface-sunken\">\n {thumbnail ? <img src={thumbnail} alt=\"\" onError={() => setBroken(thumbnail)} className=\"size-full object-cover\" /> : <IconGlyph name={error ? \"file-exclamation-point\" : \"file\"} color=\"subtle\" data-slot=\"file-row-icon\" />}\n </span>\n <span className=\"flex min-w-0 flex-1 flex-col gap-ds-050\">\n <span data-slot=\"file-name\" className=\"truncate text-body text-ds-text\">{name ?? file?.name}</span>\n {uploading && (\n <span\n role=\"progressbar\"\n aria-label={name ?? file?.name}\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={Math.round((progress ?? 0) * 100)}\n aria-valuetext={total !== undefined ? `${formatFileSize(total * (progress ?? 0), locale)} / ${formatFileSize(total, locale)}` : undefined}\n data-slot=\"file-progress\"\n className=\"h-1 overflow-hidden rounded-ds-full bg-ds-background-neutral\"\n >\n <span className=\"block h-full rounded-ds-full bg-ds-background-brand-bold\" style={{ width: `${Math.round((progress ?? 0) * 100)}%` }} />\n </span>\n )}\n {error ? (\n <span role=\"status\" data-slot=\"file-error\" className=\"text-body-small text-ds-text-danger\">{error}</span>\n ) : total !== undefined ? (\n <span data-slot=\"file-meta\" className=\"text-body-small tabular-nums text-ds-text-subtlest\">\n {uploading\n ? `${formatFileSize(total * (progress ?? 0), locale)} / ${formatFileSize(total, locale)}`\n : `${formatFileSize(total, locale)} · ${uploadedLabel(locale)}`}\n </span>\n ) : null}\n </span>\n {error && onReplace ? (\n <Button variant=\"link\" size=\"small\" onPress={onReplace}>{replaceLabel(locale)}</Button>\n ) : uploading && onCancel ? (\n <Button variant=\"subtle\" size=\"small\" iconOnly iconBefore=\"x\" aria-label={cancelUploadLabel(locale)} onPress={onCancel} />\n ) : onRemove ? (\n <Button variant=\"subtle\" size=\"small\" iconOnly iconBefore=\"trash-2\" aria-label={removeFileLabel(locale)} onPress={onRemove} />\n ) : null}\n </li>\n );\n}\n\n/** The list of picked or stored files. */\nexport function FileUploadList({ children, \"aria-label\": ariaLabel }: { children: React.ReactNode; \"aria-label\"?: string }) {\n return (\n // role=\"list\": Safari drops the list role from a `list-none` list.\n <ul role=\"list\" aria-label={ariaLabel} data-slot=\"file-list\" className=\"m-0 flex list-none flex-col gap-ds-100 p-0\">\n {children}\n </ul>\n );\n}\n\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { Button } from "./button.js";
|
|
2
|
+
export type { ButtonActionProps, ButtonProps } from "./button.js";
|
|
3
|
+
export { ButtonGroup } from "./button-group.js";
|
|
4
|
+
export type { ButtonGroupProps } from "./button-group.js";
|
|
5
|
+
export { CloseButton } from "./close-button.js";
|
|
6
|
+
export type { CloseButtonProps } from "./close-button.js";
|
|
7
|
+
export { ToggleButton, ToggleGroup } from "./toggle.js";
|
|
8
|
+
export type { ToggleButtonProps, ToggleGroupProps } from "./toggle.js";
|
|
9
|
+
export { Link } from "./link.js";
|
|
10
|
+
export type { LinkProps } from "./link.js";
|
|
11
|
+
export type { ButtonSize, ButtonTone, ButtonVariant, LinkVariant, ToggleSize } from "./styles.js";
|
|
12
|
+
export { Fab } from "./fab.js";
|
|
13
|
+
export type { FabProps } from "./fab.js";
|
|
14
|
+
export { ThemeSwitcher, useThemePreference } from "./theme-switcher.js";
|
|
15
|
+
export { DEFAULT_THEME_STORAGE_KEY, themeScript, themeScriptSource } from "./theme-script.js";
|
|
16
|
+
export type { ResolvedTheme, ThemeChoice, ThemeLabels, ThemeSwitcherProps } from "./theme-switcher.js";
|
|
17
|
+
export { CopyButton } from "./copy-button.js";
|
|
18
|
+
export type { CopyButtonProps } from "./copy-button.js";
|
|
19
|
+
export { Pressable } from "./pressable.js";
|
|
20
|
+
export type { PressableProps } from "./pressable.js";
|
|
21
|
+
export { LanguageLabel, LanguageSwitcher } from "./language-switcher.js";
|
|
22
|
+
export type { LanguageSwitcherProps } from "./language-switcher.js";
|
|
23
|
+
export { capitalizeLanguageName, languageName, languageOptions, registerLanguageNames } from "./language-names.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @senvenli/react/action:
|
|
2
|
+
// Button, ButtonGroup, CloseButton, ToggleButton, ToggleGroup and Link on React
|
|
3
|
+
// Aria Components; Fab; Pressable; ThemeSwitcher and LanguageSwitcher.
|
|
4
|
+
export { Button } from "./button.js";
|
|
5
|
+
export { ButtonGroup } from "./button-group.js";
|
|
6
|
+
export { CloseButton } from "./close-button.js";
|
|
7
|
+
export { ToggleButton, ToggleGroup } from "./toggle.js";
|
|
8
|
+
export { Link } from "./link.js";
|
|
9
|
+
export { Fab } from "./fab.js";
|
|
10
|
+
export { ThemeSwitcher, useThemePreference } from "./theme-switcher.js";
|
|
11
|
+
export { DEFAULT_THEME_STORAGE_KEY, themeScript, themeScriptSource } from "./theme-script.js";
|
|
12
|
+
export { CopyButton } from "./copy-button.js";
|
|
13
|
+
export { Pressable } from "./pressable.js";
|
|
14
|
+
export { LanguageLabel, LanguageSwitcher } from "./language-switcher.js";
|
|
15
|
+
export { capitalizeLanguageName, languageName, languageOptions, registerLanguageNames } from "./language-names.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/action/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,gFAAgF;AAChF,uEAAuE;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE3F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["// @senvenli/react/action:\n// Button, ButtonGroup, CloseButton, ToggleButton, ToggleGroup and Link on React\n// Aria Components; Fab; Pressable; ThemeSwitcher and LanguageSwitcher.\nexport { Button } from \"./button\";\nexport type { ButtonActionProps, ButtonProps } from \"./button\";\nexport { ButtonGroup } from \"./button-group\";\nexport type { ButtonGroupProps } from \"./button-group\";\nexport { CloseButton } from \"./close-button\";\nexport type { CloseButtonProps } from \"./close-button\";\nexport { ToggleButton, ToggleGroup } from \"./toggle\";\nexport type { ToggleButtonProps, ToggleGroupProps } from \"./toggle\";\nexport { Link } from \"./link\";\nexport type { LinkProps } from \"./link\";\nexport type { ButtonSize, ButtonTone, ButtonVariant, LinkVariant, ToggleSize } from \"./styles\";\nexport { Fab } from \"./fab\";\nexport type { FabProps } from \"./fab\";\nexport { ThemeSwitcher, useThemePreference } from \"./theme-switcher\";\nexport { DEFAULT_THEME_STORAGE_KEY, themeScript, themeScriptSource } from \"./theme-script\";\nexport type { ResolvedTheme, ThemeChoice, ThemeLabels, ThemeSwitcherProps } from \"./theme-switcher\";\nexport { CopyButton } from \"./copy-button\";\nexport type { CopyButtonProps } from \"./copy-button\";\nexport { Pressable } from \"./pressable\";\nexport type { PressableProps } from \"./pressable\";\nexport { LanguageLabel, LanguageSwitcher } from \"./language-switcher\";\nexport type { LanguageSwitcherProps } from \"./language-switcher\";\nexport { capitalizeLanguageName, languageName, languageOptions, registerLanguageNames } from \"./language-names\";\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names for languages the runtime names wrongly or not at all, as the reader of `uiLocale` should see them:
|
|
3
|
+
* Montenegrin, which Intl calls Serbian (`registerLanguageNames("en", { me: "Montenegrin" })`), or every
|
|
4
|
+
* language in a UI language whose display names browsers do not ship (Albanian, Macedonian). `uiLocale` is a
|
|
5
|
+
* language ("sq") or a full tag ("pt-BR"); the full tag wins.
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerLanguageNames(uiLocale: string, names: Readonly<Record<string, string>>): void;
|
|
8
|
+
/** Uppercase the first code point only, in the UI language ("İngilizce" in Turkish), leaving the rest as given. */
|
|
9
|
+
export declare function capitalizeLanguageName(name: string, uiLocale: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* A language's name in the UI language: the app's registered name, else Intl's (through `registerLocaleAliases`),
|
|
12
|
+
* else the language's own name (its endonym), never the host's language, else the tag itself.
|
|
13
|
+
*/
|
|
14
|
+
export declare function languageName(locale: string, uiLocale: string): string;
|
|
15
|
+
/** The locales with their names in the UI language, sorted by that name the way the UI language sorts. */
|
|
16
|
+
export declare function languageOptions<Locale extends string>(locales: readonly Locale[], uiLocale: string): Array<{
|
|
17
|
+
locale: Locale;
|
|
18
|
+
label: string;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// No "use client": plain functions, usable on the server so both render the same names.
|
|
2
|
+
import { hasIntlData, intlLocale } from "../intl-locale.js";
|
|
3
|
+
/** App-registered names, by UI language then by language tag. */
|
|
4
|
+
const registered = new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Names for languages the runtime names wrongly or not at all, as the reader of `uiLocale` should see them:
|
|
7
|
+
* Montenegrin, which Intl calls Serbian (`registerLanguageNames("en", { me: "Montenegrin" })`), or every
|
|
8
|
+
* language in a UI language whose display names browsers do not ship (Albanian, Macedonian). `uiLocale` is a
|
|
9
|
+
* language ("sq") or a full tag ("pt-BR"); the full tag wins.
|
|
10
|
+
*/
|
|
11
|
+
export function registerLanguageNames(uiLocale, names) {
|
|
12
|
+
const key = uiLocale.toLowerCase();
|
|
13
|
+
const table = registered.get(key) ?? new Map();
|
|
14
|
+
for (const [tag, name] of Object.entries(names))
|
|
15
|
+
table.set(tag.toLowerCase(), name);
|
|
16
|
+
registered.set(key, table);
|
|
17
|
+
}
|
|
18
|
+
function registeredName(locale, uiLocale) {
|
|
19
|
+
const tag = locale.toLowerCase();
|
|
20
|
+
const ui = uiLocale.toLowerCase();
|
|
21
|
+
return registered.get(ui)?.get(tag) ?? registered.get(ui.split(/[-_]/)[0] ?? ui)?.get(tag);
|
|
22
|
+
}
|
|
23
|
+
/** Uppercase the first code point only, in the UI language ("İngilizce" in Turkish), leaving the rest as given. */
|
|
24
|
+
export function capitalizeLanguageName(name, uiLocale) {
|
|
25
|
+
const first = [...name][0];
|
|
26
|
+
if (!first)
|
|
27
|
+
return name;
|
|
28
|
+
try {
|
|
29
|
+
return first.toLocaleUpperCase(intlLocale(uiLocale)) + name.slice(first.length);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return first.toUpperCase() + name.slice(first.length);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function displayName(locale, uiLocale) {
|
|
36
|
+
try {
|
|
37
|
+
// "standard" names a region in brackets ("Portuguese (Brazil)"), not "Brazilian Portuguese".
|
|
38
|
+
return new Intl.DisplayNames([uiLocale], { type: "language", fallback: "none", languageDisplay: "standard" }).of(locale) ?? undefined;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A language's name in the UI language: the app's registered name, else Intl's (through `registerLocaleAliases`),
|
|
46
|
+
* else the language's own name (its endonym), never the host's language, else the tag itself.
|
|
47
|
+
*/
|
|
48
|
+
export function languageName(locale, uiLocale) {
|
|
49
|
+
const own = registeredName(locale, uiLocale);
|
|
50
|
+
if (own)
|
|
51
|
+
return own;
|
|
52
|
+
const ui = intlLocale(uiLocale);
|
|
53
|
+
const target = intlLocale(locale);
|
|
54
|
+
// A runtime with no data for the UI language would name languages in the host's language; the endonym is never that.
|
|
55
|
+
const name = hasIntlData(ui) ? displayName(target, ui) : undefined;
|
|
56
|
+
if (name)
|
|
57
|
+
return capitalizeLanguageName(name, uiLocale);
|
|
58
|
+
// The same rule for the endonym: a language with no data of its own would be named in the host's language.
|
|
59
|
+
const endonym = registeredName(locale, locale) ?? (hasIntlData(target) ? displayName(target, target) : undefined);
|
|
60
|
+
if (endonym)
|
|
61
|
+
return capitalizeLanguageName(endonym, locale);
|
|
62
|
+
// No name anywhere: the tag as given, not dressed up as a word.
|
|
63
|
+
return locale;
|
|
64
|
+
}
|
|
65
|
+
/** The locales with their names in the UI language, sorted by that name the way the UI language sorts. */
|
|
66
|
+
export function languageOptions(locales, uiLocale) {
|
|
67
|
+
let collator;
|
|
68
|
+
try {
|
|
69
|
+
collator = new Intl.Collator(intlLocale(uiLocale).replace(/_/g, "-"), { sensitivity: "base" });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// A tag Intl cannot read ("x-app") still gets a list, in the runtime's default order.
|
|
73
|
+
collator = new Intl.Collator(undefined, { sensitivity: "base" });
|
|
74
|
+
}
|
|
75
|
+
return locales
|
|
76
|
+
.map((locale) => ({ locale, label: languageName(locale, uiLocale) }))
|
|
77
|
+
.sort((a, b) => collator.compare(a.label, b.label) || (a.locale < b.locale ? -1 : a.locale > b.locale ? 1 : 0));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=language-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-names.js","sourceRoot":"","sources":["../../src/action/language-names.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEzD,iEAAiE;AACjE,MAAM,UAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,KAAuC;IAC7F,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;IAC/D,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;IACpF,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,cAAc,CAAC,MAAc,EAAE,QAAgB;IACtD,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACjC,MAAM,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAClC,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7F,CAAC;AAED,mHAAmH;AACnH,MAAM,UAAU,sBAAsB,CAAC,IAA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AG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpH,CAAC","sourcesContent":["// No \"use client\": plain functions, usable on the server so both render the same names.\nimport { hasIntlData, intlLocale } from \"../intl-locale\";\n\n/** App-registered names, by UI language then by language tag. */\nconst registered = new Map<string, Map<string, string>>();\n\n/**\n * Names for languages the runtime names wrongly or not at all, as the reader of `uiLocale` should see them:\n * Montenegrin, which Intl calls Serbian (`registerLanguageNames(\"en\", { me: \"Montenegrin\" })`), or every\n * language in a UI language whose display names browsers do not ship (Albanian, Macedonian). `uiLocale` is a\n * language (\"sq\") or a full tag (\"pt-BR\"); the full tag wins.\n */\nexport function registerLanguageNames(uiLocale: string, names: Readonly<Record<string, string>>): void {\n const key = uiLocale.toLowerCase();\n const table = registered.get(key) ?? new Map<string, string>();\n for (const [tag, name] of Object.entries(names)) table.set(tag.toLowerCase(), name);\n registered.set(key, table);\n}\n\nfunction registeredName(locale: string, uiLocale: string): string | undefined {\n const tag = locale.toLowerCase();\n const ui = uiLocale.toLowerCase();\n return registered.get(ui)?.get(tag) ?? registered.get(ui.split(/[-_]/)[0] ?? ui)?.get(tag);\n}\n\n/** Uppercase the first code point only, in the UI language (\"İngilizce\" in Turkish), leaving the rest as given. */\nexport function capitalizeLanguageName(name: string, uiLocale: string): string {\n const first = [...name][0];\n if (!first) return name;\n try {\n return first.toLocaleUpperCase(intlLocale(uiLocale)) + name.slice(first.length);\n } catch {\n return first.toUpperCase() + name.slice(first.length);\n }\n}\n\nfunction displayName(locale: string, uiLocale: string): string | undefined {\n try {\n // \"standard\" names a region in brackets (\"Portuguese (Brazil)\"), not \"Brazilian Portuguese\".\n return new Intl.DisplayNames([uiLocale], { type: \"language\", fallback: \"none\", languageDisplay: \"standard\" }).of(locale) ?? undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * A language's name in the UI language: the app's registered name, else Intl's (through `registerLocaleAliases`),\n * else the language's own name (its endonym), never the host's language, else the tag itself.\n */\nexport function languageName(locale: string, uiLocale: string): string {\n const own = registeredName(locale, uiLocale);\n if (own) return own;\n const ui = intlLocale(uiLocale);\n const target = intlLocale(locale);\n // A runtime with no data for the UI language would name languages in the host's language; the endonym is never that.\n const name = hasIntlData(ui) ? displayName(target, ui) : undefined;\n if (name) return capitalizeLanguageName(name, uiLocale);\n // The same rule for the endonym: a language with no data of its own would be named in the host's language.\n const endonym = registeredName(locale, locale) ?? (hasIntlData(target) ? displayName(target, target) : undefined);\n if (endonym) return capitalizeLanguageName(endonym, locale);\n // No name anywhere: the tag as given, not dressed up as a word.\n return locale;\n}\n\n/** The locales with their names in the UI language, sorted by that name the way the UI language sorts. */\nexport function languageOptions<Locale extends string>(locales: readonly Locale[], uiLocale: string): Array<{ locale: Locale; label: string }> {\n let collator: Intl.Collator;\n try {\n collator = new Intl.Collator(intlLocale(uiLocale).replace(/_/g, \"-\"), { sensitivity: \"base\" });\n } catch {\n // A tag Intl cannot read (\"x-app\") still gets a list, in the runtime's default order.\n collator = new Intl.Collator(undefined, { sensitivity: \"base\" });\n }\n return locales\n .map((locale) => ({ locale, label: languageName(locale, uiLocale) }))\n .sort((a, b) => collator.compare(a.label, b.label) || (a.locale < b.locale ? -1 : a.locale > b.locale ? 1 : 0));\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* One language as the switcher shows it: the app's mark (a flag, a code chip), if any, and the name in the UI
|
|
4
|
+
* language. With the name hidden (a square trigger) the mark stands alone; the name stays for screen readers.
|
|
5
|
+
* The mark is decorative next to the name, so it is hidden from assistive technology, and the name always tells
|
|
6
|
+
* the options apart.
|
|
7
|
+
*/
|
|
8
|
+
export declare function LanguageLabel({ locale, uiLocale, hideName, mark, }: {
|
|
9
|
+
locale: string;
|
|
10
|
+
uiLocale: string;
|
|
11
|
+
hideName?: boolean;
|
|
12
|
+
mark?: React.ReactNode;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export interface LanguageSwitcherProps<Locale extends string> {
|
|
15
|
+
/** Locales to offer, already narrowed to what this product enables. */
|
|
16
|
+
locales: readonly Locale[];
|
|
17
|
+
/** The active UI locale. */
|
|
18
|
+
value: Locale;
|
|
19
|
+
/** Called with the picked locale (routing, persistence). */
|
|
20
|
+
onChange: (locale: Locale) => void;
|
|
21
|
+
/** The trigger's accessible name and tooltip; "Language" (the DS string) by default. */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Hold the disabled trigger while the product's locale list resolves. */
|
|
24
|
+
isLoading?: boolean;
|
|
25
|
+
/** `button` (default): a trigger in a bar. `sidebar`: a full-width row whose list opens upward, for a panel sidebar. */
|
|
26
|
+
variant?: "button" | "sidebar";
|
|
27
|
+
/** A collapsed rail: the mark alone (or the name, without one), kept for screen readers either way. */
|
|
28
|
+
isCollapsed?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* A mark before each language's name: a flag, an `IsoChip`, an icon. None by default: a language is not a
|
|
31
|
+
* country, and the name alone tells the options apart.
|
|
32
|
+
*/
|
|
33
|
+
renderMark?: (locale: Locale) => React.ReactNode;
|
|
34
|
+
/** Control height: `medium` (default) matches the DS controls, `small` is the compact step. */
|
|
35
|
+
size?: "small" | "medium";
|
|
36
|
+
/**
|
|
37
|
+
* Ids of elements that describe the trigger ("Changes the language of the whole panel"). It lands on the
|
|
38
|
+
* trigger button, the focusable control, also while it is disabled for `isLoading`; left out, nothing is
|
|
39
|
+
* added. While the trigger's tooltip is open it takes the place of the tooltip's id, which only
|
|
40
|
+
* repeats `label`.
|
|
41
|
+
*/
|
|
42
|
+
"aria-describedby"?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The language choice every surface offers, on the DS.
|
|
46
|
+
*
|
|
47
|
+
* Presentation only: the app resolves the product's locale list and handles
|
|
48
|
+
* `onChange` (routing, persistence). Names come from `Intl.DisplayNames` in
|
|
49
|
+
* the active UI locale (`value`), ordered by that visible name.
|
|
50
|
+
* Choosing a value is a Select, not a Menu, so the list is a listbox whose
|
|
51
|
+
* current option is selected for assistive technology and carries a check.
|
|
52
|
+
*
|
|
53
|
+
* The trigger stays disabled until the component has mounted *and* the
|
|
54
|
+
* caller reports the list resolved, so a product restricted to one language
|
|
55
|
+
* never flashes the full list on a cold cache.
|
|
56
|
+
*/
|
|
57
|
+
export declare function LanguageSwitcher<Locale extends string>({ locales, value: current, onChange: onSelect, label: labelProp, isLoading: loading, variant, isCollapsed: collapsed, size, renderMark, "aria-describedby": describedBy, }: LanguageSwitcherProps<Locale>): React.JSX.Element;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Button as AriaButton, ListBox, ListBoxItem, Popover, Select as AriaSelect, } from "react-aria-components";
|
|
5
|
+
import { BUTTON_BASE, BUTTON_SIZE, buttonVariantClasses, ICON_ONLY_SIZE } from "./styles.js";
|
|
6
|
+
import { IconGlyph } from "../display/icon.js";
|
|
7
|
+
import { TooltipFor } from "../overlay/floating.js";
|
|
8
|
+
import { LISTBOX, OPTION } from "../selection/listbox.js";
|
|
9
|
+
import { languageLabel } from "../i18n.js";
|
|
10
|
+
import { cn } from "../utils.js";
|
|
11
|
+
import { languageOptions, languageName } from "./language-names.js";
|
|
12
|
+
/**
|
|
13
|
+
* One language as the switcher shows it: the app's mark (a flag, a code chip), if any, and the name in the UI
|
|
14
|
+
* language. With the name hidden (a square trigger) the mark stands alone; the name stays for screen readers.
|
|
15
|
+
* The mark is decorative next to the name, so it is hidden from assistive technology, and the name always tells
|
|
16
|
+
* the options apart.
|
|
17
|
+
*/
|
|
18
|
+
export function LanguageLabel({ locale, uiLocale, hideName = false, mark, }) {
|
|
19
|
+
return (_jsxs("span", { "data-slot": "language-label", className: "inline-flex min-w-0 items-center gap-ds-075", children: [mark != null && (_jsx("span", { "data-slot": "language-mark", "aria-hidden": "true", className: "inline-flex shrink-0 items-center", children: mark })), _jsx("span", { className: hideName ? "sr-only" : "truncate", children: languageName(locale, uiLocale) })] }));
|
|
20
|
+
}
|
|
21
|
+
const subscribeToClient = () => () => { };
|
|
22
|
+
/**
|
|
23
|
+
* The language choice every surface offers, on the DS.
|
|
24
|
+
*
|
|
25
|
+
* Presentation only: the app resolves the product's locale list and handles
|
|
26
|
+
* `onChange` (routing, persistence). Names come from `Intl.DisplayNames` in
|
|
27
|
+
* the active UI locale (`value`), ordered by that visible name.
|
|
28
|
+
* Choosing a value is a Select, not a Menu, so the list is a listbox whose
|
|
29
|
+
* current option is selected for assistive technology and carries a check.
|
|
30
|
+
*
|
|
31
|
+
* The trigger stays disabled until the component has mounted *and* the
|
|
32
|
+
* caller reports the list resolved, so a product restricted to one language
|
|
33
|
+
* never flashes the full list on a cold cache.
|
|
34
|
+
*/
|
|
35
|
+
export function LanguageSwitcher({ locales, value: current, onChange: onSelect, label: labelProp, isLoading: loading = false, variant = "button", isCollapsed: collapsed = false, size = "medium", renderMark, "aria-describedby": describedBy, }) {
|
|
36
|
+
const sidebar = variant === "sidebar";
|
|
37
|
+
const label = labelProp ?? languageLabel(current);
|
|
38
|
+
// A collapsed trigger hides the name only behind a mark that is really there.
|
|
39
|
+
const currentMark = renderMark?.(current) ?? null;
|
|
40
|
+
const mounted = React.useSyncExternalStore(subscribeToClient, () => true, () => false);
|
|
41
|
+
const buttonSize = size;
|
|
42
|
+
const square = collapsed && !sidebar;
|
|
43
|
+
const trigger = cn(BUTTON_BASE, buttonVariantClasses("subtle"), BUTTON_SIZE[buttonSize], "font-normal", square && ICON_ONLY_SIZE[buttonSize], sidebar && (collapsed ? "w-full justify-center px-0" : "w-full justify-start"));
|
|
44
|
+
if (!mounted || loading) {
|
|
45
|
+
return (_jsx(AriaButton, { "data-slot": "language-switcher-trigger", "aria-label": label, "aria-describedby": describedBy, isDisabled: true, className: trigger, children: _jsx(LanguageLabel, { locale: current, uiLocale: current, hideName: collapsed && currentMark != null, mark: currentMark }) }));
|
|
46
|
+
}
|
|
47
|
+
const options = languageOptions(locales, current);
|
|
48
|
+
return (_jsxs(AriaSelect, { "aria-label": label, "aria-describedby": describedBy, value: current, onChange: (key) => {
|
|
49
|
+
if (key != null)
|
|
50
|
+
onSelect(String(key));
|
|
51
|
+
}, "data-slot": "language-switcher", className: cn(sidebar && "w-full"), children: [_jsx(TooltipFor, { content: label, placement: "bottom", children: _jsx(AriaButton, { "data-slot": "language-switcher-trigger", className: trigger, children: _jsx(LanguageLabel, { locale: current, uiLocale: current, hideName: collapsed && currentMark != null, mark: currentMark }) }) }), _jsx(Popover, { "data-slot": "language-switcher-popover", placement: sidebar ? "top start" : "bottom end", offset: 4, className: "flex min-w-44 flex-col overflow-hidden rounded-ds-large [--ds-surface-radius:var(--ds-radius-large)] bg-ds-surface-overlay p-ds-050 text-ds-text shadow-ds-overlay outline-hidden", children: _jsx(ListBox, { "data-slot": "language-switcher-list", className: LISTBOX, children: options.map((option) => (_jsx(ListBoxItem, { id: option.locale, textValue: option.label, "data-slot": "language-switcher-option", className: cn(OPTION, "whitespace-nowrap"), children: ({ isSelected }) => (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", "data-slot": "language-switcher-check", className: "flex size-4 shrink-0 items-center justify-center", children: isSelected && _jsx(IconGlyph, { name: "check" }) }), _jsx(LanguageLabel, { locale: option.locale, uiLocale: current, mark: renderMark?.(option.locale) })] })) }, option.locale))) }) })] }));
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=language-switcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-switcher.js","sourceRoot":"","sources":["../../src/action/language-switcher.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,MAAM,IAAI,UAAU,EACpB,OAAO,EACP,WAAW,EACX,OAAO,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AC,MAAM,CAAC,GAAI,IAC7F,CACJ,IAfI,MAAM,CAAC,MAAM,CAgBN,CACf,CAAC,GACM,GACF,IACC,CACd,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Button as AriaButton,\n ListBox,\n ListBoxItem,\n Popover,\n Select as AriaSelect,\n type Key,\n} from \"react-aria-components\";\n\nimport { BUTTON_BASE, BUTTON_SIZE, buttonVariantClasses, ICON_ONLY_SIZE } from \"./styles\";\nimport { IconGlyph } from \"../display/icon\";\nimport { TooltipFor } from \"../overlay/floating\";\nimport { LISTBOX, OPTION } from \"../selection/listbox\";\nimport { languageLabel } from \"../i18n\";\nimport { cn } from \"../utils\";\nimport { languageOptions, languageName } from \"./language-names\";\n\n/**\n * One language as the switcher shows it: the app's mark (a flag, a code chip), if any, and the name in the UI\n * language. With the name hidden (a square trigger) the mark stands alone; the name stays for screen readers.\n * The mark is decorative next to the name, so it is hidden from assistive technology, and the name always tells\n * the options apart.\n */\nexport function LanguageLabel({\n locale, uiLocale, hideName = false, mark,\n}: { locale: string; uiLocale: string; hideName?: boolean; mark?: React.ReactNode }) {\n return (\n <span data-slot=\"language-label\" className=\"inline-flex min-w-0 items-center gap-ds-075\">\n {mark != null && (\n <span data-slot=\"language-mark\" aria-hidden=\"true\" className=\"inline-flex shrink-0 items-center\">\n {mark}\n </span>\n )}\n <span className={hideName ? \"sr-only\" : \"truncate\"}>{languageName(locale, uiLocale)}</span>\n </span>\n );\n}\n\nexport interface LanguageSwitcherProps<Locale extends string> {\n /** Locales to offer, already narrowed to what this product enables. */\n locales: readonly Locale[];\n /** The active UI locale. */\n value: Locale;\n /** Called with the picked locale (routing, persistence). */\n onChange: (locale: Locale) => void;\n /** The trigger's accessible name and tooltip; \"Language\" (the DS string) by default. */\n label?: string;\n /** Hold the disabled trigger while the product's locale list resolves. */\n isLoading?: boolean;\n /** `button` (default): a trigger in a bar. `sidebar`: a full-width row whose list opens upward, for a panel sidebar. */\n variant?: \"button\" | \"sidebar\";\n /** A collapsed rail: the mark alone (or the name, without one), kept for screen readers either way. */\n isCollapsed?: boolean;\n /**\n * A mark before each language's name: a flag, an `IsoChip`, an icon. None by default: a language is not a\n * country, and the name alone tells the options apart.\n */\n renderMark?: (locale: Locale) => React.ReactNode;\n /** Control height: `medium` (default) matches the DS controls, `small` is the compact step. */\n size?: \"small\" | \"medium\";\n /**\n * Ids of elements that describe the trigger (\"Changes the language of the whole panel\"). It lands on the\n * trigger button, the focusable control, also while it is disabled for `isLoading`; left out, nothing is\n * added. While the trigger's tooltip is open it takes the place of the tooltip's id, which only\n * repeats `label`.\n */\n \"aria-describedby\"?: string;\n}\n\nconst subscribeToClient = () => () => {};\n\n/**\n * The language choice every surface offers, on the DS.\n *\n * Presentation only: the app resolves the product's locale list and handles\n * `onChange` (routing, persistence). Names come from `Intl.DisplayNames` in\n * the active UI locale (`value`), ordered by that visible name.\n * Choosing a value is a Select, not a Menu, so the list is a listbox whose\n * current option is selected for assistive technology and carries a check.\n *\n * The trigger stays disabled until the component has mounted *and* the\n * caller reports the list resolved, so a product restricted to one language\n * never flashes the full list on a cold cache.\n */\nexport function LanguageSwitcher<Locale extends string>({\n locales,\n value: current,\n onChange: onSelect,\n label: labelProp,\n isLoading: loading = false,\n variant = \"button\",\n isCollapsed: collapsed = false,\n size = \"medium\",\n renderMark,\n \"aria-describedby\": describedBy,\n}: LanguageSwitcherProps<Locale>) {\n const sidebar = variant === \"sidebar\";\n const label = labelProp ?? languageLabel(current);\n // A collapsed trigger hides the name only behind a mark that is really there.\n const currentMark = renderMark?.(current) ?? null;\n const mounted = React.useSyncExternalStore(subscribeToClient, () => true, () => false);\n const buttonSize = size;\n const square = collapsed && !sidebar;\n const trigger = cn(\n BUTTON_BASE,\n buttonVariantClasses(\"subtle\"),\n BUTTON_SIZE[buttonSize],\n \"font-normal\",\n square && ICON_ONLY_SIZE[buttonSize],\n sidebar && (collapsed ? \"w-full justify-center px-0\" : \"w-full justify-start\"),\n );\n\n if (!mounted || loading) {\n return (\n <AriaButton data-slot=\"language-switcher-trigger\" aria-label={label} aria-describedby={describedBy} isDisabled className={trigger}>\n <LanguageLabel locale={current} uiLocale={current} hideName={collapsed && currentMark != null} mark={currentMark} />\n </AriaButton>\n );\n }\n\n const options = languageOptions(locales, current);\n\n return (\n <AriaSelect\n aria-label={label}\n // React Aria's Select hands it to the trigger button (useSelect → useField → triggerProps), not the wrapper.\n aria-describedby={describedBy}\n value={current as Key}\n onChange={(key) => {\n if (key != null) onSelect(String(key) as Locale);\n }}\n data-slot=\"language-switcher\"\n className={cn(sidebar && \"w-full\")}\n >\n <TooltipFor content={label} placement=\"bottom\">\n <AriaButton data-slot=\"language-switcher-trigger\" className={trigger}>\n {/* No SelectValue: the trigger is named by the caller's label alone, as before, and shows the current\n language itself (it is always `current`). */}\n <LanguageLabel locale={current} uiLocale={current} hideName={collapsed && currentMark != null} mark={currentMark} />\n </AriaButton>\n </TooltipFor>\n <Popover\n data-slot=\"language-switcher-popover\"\n placement={sidebar ? \"top start\" : \"bottom end\"}\n offset={4}\n className=\"flex min-w-44 flex-col overflow-hidden rounded-ds-large [--ds-surface-radius:var(--ds-radius-large)] bg-ds-surface-overlay p-ds-050 text-ds-text shadow-ds-overlay outline-hidden\"\n >\n <ListBox data-slot=\"language-switcher-list\" className={LISTBOX}>\n {options.map((option) => (\n <ListBoxItem\n key={option.locale}\n id={option.locale}\n textValue={option.label}\n data-slot=\"language-switcher-option\"\n className={cn(OPTION, \"whitespace-nowrap\")}\n >\n {({ isSelected }) => (\n <>\n {/* The slot holds its width whether or not it is filled, so switching never shifts the rows;\n the indicator stays at the inline start. */}\n <span aria-hidden=\"true\" data-slot=\"language-switcher-check\" className=\"flex size-4 shrink-0 items-center justify-center\">\n {isSelected && <IconGlyph name=\"check\" />}\n </span>\n <LanguageLabel locale={option.locale} uiLocale={current} mark={renderMark?.(option.locale)} />\n </>\n )}\n </ListBoxItem>\n ))}\n </ListBox>\n </Popover>\n </AriaSelect>\n );\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type LinkProps as AriaLinkProps } from "react-aria-components";
|
|
3
|
+
import { type IconName } from "../display/icon.js";
|
|
4
|
+
import { type ComponentRadius } from "../defaults.js";
|
|
5
|
+
import { type ButtonSize, type ButtonTone, type ButtonVariant } from "./styles.js";
|
|
6
|
+
type BaseProps = Omit<AriaLinkProps, "className" | "style" | "children" | "target" | "href" | "onPress" | "onPressStart" | "onPressEnd" | "onPressChange" | "onPressUp" | "onClick"> & {
|
|
7
|
+
/** Where it goes. Rendered as a real `href`, so the link works before (and without) JavaScript. */
|
|
8
|
+
href: string;
|
|
9
|
+
/** Button's look: `primary` for the one main call to action of a view. */
|
|
10
|
+
variant?: ButtonVariant;
|
|
11
|
+
/** `danger` for a destructive action; it keeps the variant's shape. */
|
|
12
|
+
tone?: ButtonTone;
|
|
13
|
+
/** As wide as its container. */
|
|
14
|
+
fullWidth?: boolean;
|
|
15
|
+
/** Corner radius: `none`, `small`, `medium` (the design), `large` or `full` (a pill). The provider's default otherwise. */
|
|
16
|
+
radius?: ComponentRadius;
|
|
17
|
+
size?: ButtonSize;
|
|
18
|
+
/** Lucide icon name shown before the label. */
|
|
19
|
+
iconBefore?: IconName;
|
|
20
|
+
/** Lucide icon name shown after the label. */
|
|
21
|
+
iconAfter?: IconName;
|
|
22
|
+
/**
|
|
23
|
+
* Link's convention: opens in a new tab with `noopener noreferrer`, shows `arrow-up-right` after the label
|
|
24
|
+
* (unless `iconAfter` is set) and tells screen readers it opens a new tab. With `onPress` a plain click
|
|
25
|
+
* opens nothing (the app handles it in place), so the arrow and the new-tab words are left out; `target`
|
|
26
|
+
* and `rel` stay for the page before JavaScript. Disabled, it opens nothing either: no `target`, `rel` or
|
|
27
|
+
* new-tab words (the arrow stays, as `iconAfter` would).
|
|
28
|
+
*/
|
|
29
|
+
isExternal?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Optional. Runs on a plain primary click or Enter, and cancels that navigation (`preventDefault`), so the
|
|
32
|
+
* app can handle it in place (open a dialog, track and route). A click with Ctrl, Cmd, Shift or Alt, or with
|
|
33
|
+
* the middle button, is left to the browser (new tab, new window, download). Without JavaScript the `href`
|
|
34
|
+
* is followed as usual. It receives the click itself, a `React.MouseEvent<HTMLAnchorElement>`, not the
|
|
35
|
+
* `PressEvent` Button's `onPress` receives.
|
|
36
|
+
*/
|
|
37
|
+
onPress?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
|
|
38
|
+
};
|
|
39
|
+
export type LinkButtonProps = BaseProps & ({
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
iconOnly?: false;
|
|
42
|
+
} | {
|
|
43
|
+
/** A square link that shows only `iconBefore`; it needs an `aria-label`. */
|
|
44
|
+
iconOnly: true;
|
|
45
|
+
iconBefore: IconName;
|
|
46
|
+
"aria-label": string;
|
|
47
|
+
children?: never;
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* A link that looks like a Button: a real `<a href>` with Button's variants and sizes, for a
|
|
51
|
+
* call to action that goes somewhere ("Add product" → /products/new). Its semantics are Link's: role `link`,
|
|
52
|
+
* Enter follows it and Space does not, internal links go through the `DesignSystemProvider` router, and
|
|
53
|
+
* `isDisabled` renders it unfocusable with `aria-disabled` and no `href`. Keyboard focus shows Button's inner
|
|
54
|
+
* ring. Actions that change data in place use Button.
|
|
55
|
+
*/
|
|
56
|
+
export declare const LinkButton: React.ForwardRefExoticComponent<LinkButtonProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
57
|
+
export {};
|