@espressif/dashboard-ui-components 1.10.0 → 1.11.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/CHANGELOG.md +65 -0
- package/dist/_vendor/@radix-ui/primitive/dist/index.js +9 -0
- package/dist/_vendor/@radix-ui/react-checkbox/dist/index.js +185 -0
- package/dist/_vendor/@radix-ui/react-compose-refs/dist/index.js +28 -0
- package/dist/_vendor/@radix-ui/react-context/dist/index.js +68 -0
- package/dist/_vendor/@radix-ui/react-presence/dist/index.js +127 -0
- package/dist/_vendor/@radix-ui/react-primitive/dist/index.js +42 -0
- package/dist/_vendor/@radix-ui/react-use-controllable-state/dist/index.js +55 -0
- package/dist/_vendor/@radix-ui/react-use-layout-effect/dist/index.js +5 -0
- package/dist/_vendor/@radix-ui/react-use-previous/dist/index.js +17 -0
- package/dist/_vendor/@radix-ui/react-use-size/dist/index.js +39 -0
- package/dist/_vendor/lottie-react/build/index.es.js +537 -0
- package/dist/_vendor/lottie-web/build/player/lottie.js +14149 -0
- package/dist/_virtual/_rolldown/runtime.js +24 -0
- package/dist/assets/illustrations/bulb-cloud-drawing.js +4 -0
- package/dist/assets/illustrations/rm-dashboard-update.js +4 -0
- package/dist/assets/illustrations/rm-data-download.js +4 -0
- package/dist/assets/logos/espressif/espressif-no-text.js +4 -0
- package/dist/assets/logos/espressif/espressif-with-text-dm.js +4 -0
- package/dist/assets/logos/espressif/espressif-with-text.js +4 -0
- package/dist/assets/logos/insights/insights-no-text.js +4 -0
- package/dist/assets/logos/insights/insights-with-text-dm.js +4 -0
- package/dist/assets/logos/insights/insights-with-text.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-no-text-dm.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-no-text.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-with-text-dm.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-with-text.js +4 -0
- package/dist/assets/logos/private-agents/private-agents-no-text.js +4 -0
- package/dist/assets/logos/private-agents/private-agents-with-text-dm.js +4 -0
- package/dist/assets/logos/private-agents/private-agents-with-text.js +4 -0
- package/dist/assets/logos/rainmaker/rainmaker-no-text.js +4 -0
- package/dist/assets/logos/rainmaker/rainmaker-with-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker/rainmaker-with-text.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-no-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-no-text.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-with-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-with-text.js +4 -0
- package/dist/assets/logos/rainmaker-neo/rainmaker-neo-no-text.js +4 -0
- package/dist/assets/logos/rainmaker-neo/rainmaker-neo-with-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker-neo/rainmaker-neo-with-text.js +4 -0
- package/dist/assets/logos/ui-components/ui-components-no-text.js +4 -0
- package/dist/assets/logos/ui-components/ui-components-with-text-dm.js +4 -0
- package/dist/assets/logos/ui-components/ui-components-with-text.js +4 -0
- package/dist/assets/logos/zerocode/zerocode-no-text.js +4 -0
- package/dist/assets/logos/zerocode/zerocode-with-text-dm.js +4 -0
- package/dist/assets/logos/zerocode/zerocode-with-text.js +4 -0
- package/dist/assets/logos/zerocode-ai/zerocode-ai-no-text.js +4 -0
- package/dist/assets/logos/zerocode-ai/zerocode-ai-with-text-dm.js +4 -0
- package/dist/assets/logos/zerocode-ai/zerocode-ai-with-text.js +4 -0
- package/dist/common/animated-rainmaker-logo/animated-rainmaker-logo.constants.js +18 -0
- package/dist/common/animated-rainmaker-logo/animated-rainmaker-logo.js +24 -0
- package/dist/common/animated-rainmaker-logo/rainmaker-c-logo.js +50 -0
- package/dist/common/animated-rainmaker-logo/use-animated-rainmaker-logo-animation.js +85 -0
- package/dist/common/app-logo/app-logo.js +59 -0
- package/dist/common/app-logo/logo-config.js +297 -0
- package/dist/common/copyright-card/copyright-card.js +39 -0
- package/dist/common/footer-card/footer-card.js +22 -0
- package/dist/common/index.js +8 -8
- package/dist/common/my-account-menu/my-account-menu.js +32 -0
- package/dist/common/page-loader/page-loader.js +21 -0
- package/dist/common/profile-card/profile-card.js +26 -0
- package/dist/components/accordion/accordion.js +52 -0
- package/dist/components/advanced-search-box/advanced-search-box.js +106 -0
- package/dist/components/alert/alert.js +85 -0
- package/dist/components/animated-containers/pop-collection-item.js +28 -0
- package/dist/components/async-multi-select/async-multi-select.js +199 -0
- package/dist/components/avatar/avatar.js +41 -0
- package/dist/components/button/button.js +191 -0
- package/dist/components/button/flash-button.js +110 -0
- package/dist/components/button/invert-button.js +13 -0
- package/dist/components/calendar/calendar.js +105 -0
- package/dist/components/cards/animated-card/animated-card-animations.js +57 -0
- package/dist/components/cards/animated-card/animated-card.js +42 -0
- package/dist/components/cards/basic-details-card.js +46 -0
- package/dist/components/cards/collapsible-card.js +48 -0
- package/dist/components/cards/no-data-card/no-data-card.js +30 -0
- package/dist/components/cards/section-card.js +265 -0
- package/dist/components/cards/simple-card.js +24 -0
- package/dist/components/carousel/carousel.js +158 -0
- package/dist/components/chart/area-chart.js +135 -0
- package/dist/components/chart/bar-chart.js +151 -0
- package/dist/components/chart/chart-colors.js +85 -0
- package/dist/components/chart/chart-series-data.js +53 -0
- package/dist/components/chart/chart.js +147 -0
- package/dist/components/chart/chart.types.js +7 -0
- package/dist/components/chart/composed-chart.js +182 -0
- package/dist/components/chart/donut-chart.js +177 -0
- package/dist/components/chart/line-chart.js +137 -0
- package/dist/components/chart/treemap-chart.js +294 -0
- package/dist/components/circular-progress/circular-progress.js +125 -0
- package/dist/components/code-editor/code-editor.js +235 -0
- package/dist/components/code-editor/code-editor.utils.js +122 -0
- package/dist/components/code-editor/use-code-editor-keys.js +79 -0
- package/dist/components/code-editor/use-highlighted-html.js +102 -0
- package/dist/components/confirmation-dialog/confirmation-dialog.js +72 -0
- package/dist/components/content-container/content-container.js +20 -0
- package/dist/components/copiable-text/copiable-text.js +46 -0
- package/dist/components/data-table/data-table.js +186 -0
- package/dist/components/data-table/responsive-columns.js +65 -0
- package/dist/components/data-table/row-actions.js +27 -0
- package/dist/components/data-table/sticky-columns.js +71 -0
- package/dist/components/data-table/table-body.js +57 -0
- package/dist/components/data-table/table-header.js +21 -0
- package/dist/components/date-picker/date-picker.js +95 -0
- package/dist/components/date-range-picker/date-range-picker.js +301 -0
- package/dist/components/date-range-picker/presets.js +174 -0
- package/dist/components/date-time-picker/date-time-picker.js +144 -0
- package/dist/components/date-time-picker/date-time-picker.utils.js +32 -0
- package/dist/components/device-icon/device-icon.config.js +194 -0
- package/dist/components/device-icon/device-icon.js +17 -0
- package/dist/components/device-icon/icons/air-conditioner.js +22 -0
- package/dist/components/device-icon/icons/blind.js +24 -0
- package/dist/components/device-icon/icons/dimmer.js +14 -0
- package/dist/components/device-icon/icons/extension-board.js +42 -0
- package/dist/components/device-icon/icons/fan.js +14 -0
- package/dist/components/device-icon/icons/knob.js +14 -0
- package/dist/components/device-icon/icons/led-strip.js +22 -0
- package/dist/components/device-icon/icons/light.js +14 -0
- package/dist/components/device-icon/icons/refrigerator.js +18 -0
- package/dist/components/device-icon/icons/retro-switch.js +18 -0
- package/dist/components/device-icon/icons/router.js +20 -0
- package/dist/components/device-icon/icons/sensor.js +20 -0
- package/dist/components/device-icon/icons/socket.js +19 -0
- package/dist/components/device-icon/icons/switch.js +19 -0
- package/dist/components/device-icon/icons/thermostat.js +21 -0
- package/dist/components/device-icon/icons/washing-machine.js +22 -0
- package/dist/components/device-icon/match-device.js +61 -0
- package/dist/components/dynamic-list/dynamic-list.js +445 -0
- package/dist/components/error-display/full-size-error/full-size-error.js +20 -0
- package/dist/components/error-display/inline-error/inline-error.js +12 -0
- package/dist/components/file-input/file-input.js +318 -0
- package/dist/components/file-upload/file-upload.js +317 -0
- package/dist/components/filters-bar/filters-bar.js +36 -0
- package/dist/components/fullscreen-dialog/fullscreen-dialog.js +68 -0
- package/dist/components/icon-avatar/icon-avatar.js +130 -0
- package/dist/components/icon-text-action-card/icon-text-action-card.js +190 -0
- package/dist/components/illustration/illustration-registry.js +37 -0
- package/dist/components/illustration/illustration-variants.js +21 -0
- package/dist/components/illustration/illustration.js +68 -0
- package/dist/components/index.d.ts +0 -20
- package/dist/components/index.js +134 -6
- package/dist/components/key-value-manager/key-value-manager-add-popover.js +126 -0
- package/dist/components/key-value-manager/key-value-manager-field.js +47 -0
- package/dist/components/key-value-manager/key-value-manager-table.js +188 -0
- package/dist/components/key-value-manager/key-value-manager.js +111 -0
- package/dist/components/key-value-manager/key-value-manager.props.js +28 -0
- package/dist/components/key-value-manager/key-value-manager.utils.js +21 -0
- package/dist/components/link/link.js +67 -0
- package/dist/components/list/dropdown-list-item.js +60 -0
- package/dist/components/list/list-item.utils.js +76 -0
- package/dist/components/list/list.js +49 -0
- package/dist/components/list/list.props.js +27 -0
- package/dist/components/list/standard-list-item.js +66 -0
- package/dist/components/list-details/list-details-item-button.js +46 -0
- package/dist/components/list-details/list-details-item-dropdown.js +112 -0
- package/dist/components/list-details/list-details-item-strip.js +125 -0
- package/dist/components/list-details/list-details.js +148 -0
- package/dist/components/lottie-animation-container/lottie-animation-container.js +31 -0
- package/dist/components/lottie-animations/animation-data/access-denied.js +3980 -0
- package/dist/components/lottie-animations/animation-data/active.js +825 -0
- package/dist/components/lottie-animations/animation-data/bar-chart.js +610 -0
- package/dist/components/lottie-animations/animation-data/chart-loading.js +5368 -0
- package/dist/components/lottie-animations/animation-data/cloud-download.js +1660 -0
- package/dist/components/lottie-animations/animation-data/cloud-sync.js +932 -0
- package/dist/components/lottie-animations/animation-data/coud-upload.js +7060 -0
- package/dist/components/lottie-animations/animation-data/cross-throb.js +1506 -0
- package/dist/components/lottie-animations/animation-data/dashboard-loading.js +14330 -0
- package/dist/components/lottie-animations/animation-data/error-spread-out.js +5567 -0
- package/dist/components/lottie-animations/animation-data/error.js +1211 -0
- package/dist/components/lottie-animations/animation-data/green-success.js +14826 -0
- package/dist/components/lottie-animations/animation-data/inactive.js +723 -0
- package/dist/components/lottie-animations/animation-data/light.js +2678 -0
- package/dist/components/lottie-animations/animation-data/lock.js +900 -0
- package/dist/components/lottie-animations/animation-data/lock2.js +1686 -0
- package/dist/components/lottie-animations/animation-data/locked.js +641 -0
- package/dist/components/lottie-animations/animation-data/search-error.js +954 -0
- package/dist/components/lottie-animations/animation-data/security.js +4121 -0
- package/dist/components/lottie-animations/animation-data/success.js +404 -0
- package/dist/components/lottie-animations/animation-data/verification-in-progress.js +10138 -0
- package/dist/components/lottie-animations/animation-data/warning.js +843 -0
- package/dist/components/lottie-animations/verification-in-progress/verification-in-progress.js +19 -0
- package/dist/components/markdown-content/markdown-content.components.js +114 -0
- package/dist/components/markdown-content/markdown-content.js +39 -0
- package/dist/components/menu/menu.js +19 -0
- package/dist/components/monospace-content/monospace-content.js +80 -0
- package/dist/components/nav-bar/nav-bar-details-panel.js +51 -0
- package/dist/components/nav-bar/nav-bar-mobile-menu.js +105 -0
- package/dist/components/nav-bar/nav-bar.js +449 -0
- package/dist/components/nav-bar/use-nav-bar-overflow.js +74 -0
- package/dist/components/nav-bar/use-nav-bar-scroll.js +42 -0
- package/dist/components/overflow-badge-list/overflow-badge-list.js +58 -0
- package/dist/components/page-container/page-container-skeleton.js +72 -0
- package/dist/components/page-container/page-container.js +93 -0
- package/dist/components/pagination/pagination.js +96 -0
- package/dist/components/pagination/pagination.props.js +16 -0
- package/dist/components/progress-bar/progress-bar.js +106 -0
- package/dist/components/radio-group/radio-group.js +41 -0
- package/dist/components/requirement-list/requirement-list.js +83 -0
- package/dist/components/scrollable-sections/scrollable-sections.js +270 -0
- package/dist/components/search-box/search-box.js +54 -0
- package/dist/components/search-field-shell.js +24 -0
- package/dist/components/selectable-card-list/checkbox-card-list.js +85 -0
- package/dist/components/selectable-card-list/radio-card-list.js +99 -0
- package/dist/components/selectable-card-list/selectable-card-list-shared.js +135 -0
- package/dist/components/selectable-card-list/selectable-card-list.js +34 -0
- package/dist/components/sidebar/sidebar.js +344 -0
- package/dist/components/sidebar/types.js +6 -0
- package/dist/components/simple-clickable-card/simple-clickable-card-shared.js +309 -0
- package/dist/components/simple-clickable-card/simple-clickable-card.js +106 -0
- package/dist/components/simple-info-card/simple-info-card.js +154 -0
- package/dist/components/simple-list/simple-list.js +146 -0
- package/dist/components/simple-paginated-list/simple-paginated-list.js +178 -0
- package/dist/components/simplified-date/simplified-date.js +56 -0
- package/dist/components/skeletons/table-skeleton.js +16 -0
- package/dist/components/spinner/spinner.js +25 -0
- package/dist/components/stat-card/stat-card.js +206 -0
- package/dist/components/status-badge/status-badge.js +108 -0
- package/dist/components/status-card-list/status-card-list.js +282 -0
- package/dist/components/tag/tag.js +144 -0
- package/dist/components/tag-input/tag-input.js +161 -0
- package/dist/components/text-effects/glitch-effect/glitch-text.js +115 -0
- package/dist/components/text-effects/gradient-text/gradient-text.js +32 -0
- package/dist/components/text-effects/highlight-text/highlight-text.js +35 -0
- package/dist/components/text-effects/parse-text-markup.js +53 -0
- package/dist/components/text-effects/shimmer-text/shimmer-text.js +67 -0
- package/dist/components/time-picker/time-picker.js +23 -0
- package/dist/components/toast/toast.js +126 -0
- package/dist/components/togglable-items-list/togglable-items-list.js +28 -0
- package/dist/components/tooltip/tooltip.js +21 -0
- package/dist/components/transfer-list/transfer-list.js +413 -0
- package/dist/components/truncated-line-with-tooltip/truncated-line-with-tooltip.js +61 -0
- package/dist/components/typography/typography-variants.js +41 -0
- package/dist/components/typography/typography.js +15 -0
- package/dist/components/user-type-badge/user-type-badge.js +40 -0
- package/dist/components/user-type-badge/user-type-badge.registry.js +17 -0
- package/dist/components/vertical-stepper/vertical-stepper.js +171 -0
- package/dist/core/alert.js +33 -0
- package/dist/core/animate-ui/components/animate/code-header.js +30 -0
- package/dist/core/animate-ui/components/animate/code.js +35 -0
- package/dist/core/animate-ui/components/animate/tabs.js +188 -0
- package/dist/core/animate-ui/components/animate/tooltip.js +39 -0
- package/dist/core/animate-ui/components/base/preview-card.js +29 -0
- package/dist/core/animate-ui/components/base/progress.js +32 -0
- package/dist/core/animate-ui/components/base/radio.js +24 -0
- package/dist/core/animate-ui/components/buttons/copy.js +95 -0
- package/dist/core/animate-ui/components/radix/accordion.js +36 -0
- package/dist/core/animate-ui/components/radix/dialog.js +60 -0
- package/dist/core/animate-ui/components/radix/dropdown-menu.js +129 -0
- package/dist/core/animate-ui/components/radix/sheet.js +110 -0
- package/dist/core/animate-ui/components/radix/sidebar.js +416 -0
- package/dist/core/animate-ui/components/radix/switch.js +34 -0
- package/dist/core/animate-ui/components/radix/toggle-group.js +115 -0
- package/dist/core/animate-ui/components/radix/toggle.js +24 -0
- package/dist/core/animate-ui/primitives/animate/code-block.js +131 -0
- package/dist/core/animate-ui/primitives/animate/escape-html.js +7 -0
- package/dist/core/animate-ui/primitives/animate/shiki-highlighter.js +64 -0
- package/dist/core/animate-ui/primitives/animate/slot.js +39 -0
- package/dist/core/animate-ui/primitives/animate/tabs.js +202 -0
- package/dist/core/animate-ui/primitives/animate/tooltip.js +351 -0
- package/dist/core/animate-ui/primitives/base/preview-card.js +107 -0
- package/dist/core/animate-ui/primitives/base/progress.js +60 -0
- package/dist/core/animate-ui/primitives/base/radio.js +83 -0
- package/dist/core/animate-ui/primitives/buttons/button.js +15 -0
- package/dist/core/animate-ui/primitives/effects/highlight.js +407 -0
- package/dist/core/animate-ui/primitives/radix/accordion.js +76 -0
- package/dist/core/animate-ui/primitives/radix/dialog.js +136 -0
- package/dist/core/animate-ui/primitives/radix/dropdown-menu.js +305 -0
- package/dist/core/animate-ui/primitives/radix/sheet.js +165 -0
- package/dist/core/animate-ui/primitives/radix/switch.js +86 -0
- package/dist/core/animate-ui/primitives/radix/toggle-group.js +100 -0
- package/dist/core/animate-ui/primitives/texts/counting-number.js +75 -0
- package/dist/core/avatar.js +32 -0
- package/dist/core/badge.js +27 -0
- package/dist/core/breadcrumb.js +62 -0
- package/dist/core/button/button.js +43 -0
- package/dist/core/button/craft-button.js +78 -0
- package/dist/core/button-group.js +38 -0
- package/dist/core/button.js +40 -0
- package/dist/core/card.js +42 -0
- package/dist/core/carousel/carousel.js +149 -0
- package/dist/core/checkbox/motion-checkbox.js +103 -0
- package/dist/core/collapsible.js +54 -0
- package/dist/core/combobox/combobox.js +85 -0
- package/dist/core/command.js +61 -0
- package/dist/core/field-end-icons.js +36 -0
- package/dist/core/field-label-row.js +33 -0
- package/dist/core/form.js +92 -0
- package/dist/core/hooks/use-controlled-state.js +27 -0
- package/dist/core/hooks/use-data-state.js +39 -0
- package/dist/core/hooks/use-is-in-view.js +18 -0
- package/dist/core/hooks/use-mobile.js +19 -0
- package/dist/core/hooks/use-reveal-on-scroll-up.js +141 -0
- package/dist/core/hooks/use-scroll-overflow.js +50 -0
- package/dist/core/index.js +18 -52
- package/dist/core/input/input-password.js +30 -0
- package/dist/core/input/input.js +147 -0
- package/dist/core/input-otp/input-otp.js +183 -0
- package/dist/core/label.js +15 -0
- package/dist/core/popover.js +31 -0
- package/dist/core/scroll-area.js +42 -0
- package/dist/core/select.js +121 -0
- package/dist/core/separator.js +40 -0
- package/dist/core/skeleton.js +11 -0
- package/dist/core/table.js +59 -0
- package/dist/core/textarea/textarea.js +97 -0
- package/dist/core/utils/get-strict-context.js +18 -0
- package/dist/index.js +148 -9
- package/dist/layouts/entry-layout/entry-layout-bg.js +4 -0
- package/dist/layouts/entry-layout/entry-layout.js +52 -0
- package/dist/layouts/index.js +7 -6
- package/dist/layouts/workspace-layout/account-menu/account-menu.js +108 -0
- package/dist/layouts/workspace-layout/breadcrumbs/derive-breadcrumbs.js +37 -0
- package/dist/layouts/workspace-layout/breadcrumbs/workspace-breadcrumbs.js +22 -0
- package/dist/layouts/workspace-layout/footer/footer.js +15 -0
- package/dist/layouts/workspace-layout/header/header.js +54 -0
- package/dist/layouts/workspace-layout/workspace-layout.js +157 -0
- package/dist/tailwind-preset.js +3 -4
- package/dist/utils/cn.js +8 -0
- package/dist/utils/color.js +72 -0
- package/dist/utils/index.js +3 -2
- package/dist/utils/path-match.js +17 -0
- package/dist/utils/silver-shine.js +63 -0
- package/dist/utils/variant-gradient-underlay.js +45 -0
- package/dist/utils/variant.js +426 -0
- package/package.json +7 -4
- package/dist/chunk-2GDYZAKR.js +0 -505
- package/dist/chunk-ALCWXFUC.js +0 -733
- package/dist/chunk-CDHBLANU.js +0 -59
- package/dist/chunk-LUESSJAF.js +0 -70068
- package/dist/chunk-TMORRNEB.js +0 -323
- package/dist/chunk-TRTQSARU.js +0 -31
- package/dist/chunk-VU4CZ76T.js +0 -43
- package/dist/chunk-XNLCVHBC.js +0 -364
- package/dist/chunk-Z4776NRY.js +0 -4347
- package/src/assets/illustrations/add-to-group.svg +0 -32
- package/src/assets/illustrations/chip.svg +0 -51
- package/src/assets/illustrations/create-new-group.svg +0 -27
- package/src/assets/illustrations/new-ota.svg +0 -61
- package/src/assets/illustrations/secured-key.svg +0 -48
- /package/dist/assets/{entry-layout-bg-JPI7GJ42.webp → entry-layout-bg-DUM0UhT3.webp} +0 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { inputLabelClassName } from "../../core/field-label-row.js";
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { RefreshCw, Upload, X } from "lucide-react";
|
|
6
|
+
//#region src/components/file-input/file-input.tsx
|
|
7
|
+
function syncInputFiles(input, files) {
|
|
8
|
+
const dt = new DataTransfer();
|
|
9
|
+
for (const f of files) dt.items.add(f);
|
|
10
|
+
input.files = dt.files;
|
|
11
|
+
}
|
|
12
|
+
function assignRef(r, node) {
|
|
13
|
+
if (r == null) return;
|
|
14
|
+
if (typeof r === "function") r(node);
|
|
15
|
+
else r.current = node;
|
|
16
|
+
}
|
|
17
|
+
function fileKey(file) {
|
|
18
|
+
return `${file.name}-${file.size}-${file.lastModified}`;
|
|
19
|
+
}
|
|
20
|
+
function filesFromList(list) {
|
|
21
|
+
if (list == null || list.length === 0) return [];
|
|
22
|
+
return Array.from(list);
|
|
23
|
+
}
|
|
24
|
+
function mergeFiles(existing, incoming, multiple) {
|
|
25
|
+
if (!multiple) return incoming.length > 0 ? [incoming[0]] : [];
|
|
26
|
+
const seen = new Set(existing.map(fileKey));
|
|
27
|
+
const next = [...existing];
|
|
28
|
+
for (const f of incoming) {
|
|
29
|
+
const k = fileKey(f);
|
|
30
|
+
if (!seen.has(k)) {
|
|
31
|
+
seen.add(k);
|
|
32
|
+
next.push(f);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return next;
|
|
36
|
+
}
|
|
37
|
+
var sizeClasses = {
|
|
38
|
+
sm: "h-8 text-xs",
|
|
39
|
+
default: "h-10 text-base md:text-sm",
|
|
40
|
+
lg: "h-12 text-lg"
|
|
41
|
+
};
|
|
42
|
+
var iconSizeClasses = {
|
|
43
|
+
sm: "size-3.5",
|
|
44
|
+
default: "size-4",
|
|
45
|
+
lg: "size-5"
|
|
46
|
+
};
|
|
47
|
+
var clearButtonSizeClasses = {
|
|
48
|
+
sm: "size-5",
|
|
49
|
+
default: "size-6",
|
|
50
|
+
lg: "size-7"
|
|
51
|
+
};
|
|
52
|
+
var PRESET_BROWSE_TOKENS = {
|
|
53
|
+
primary: {
|
|
54
|
+
wrapperBg: "bg-primary/10",
|
|
55
|
+
wrapperBorder: "border-s-primary/20",
|
|
56
|
+
buttonText: "text-primary"
|
|
57
|
+
},
|
|
58
|
+
secondary: {
|
|
59
|
+
wrapperBg: "bg-secondary/10",
|
|
60
|
+
wrapperBorder: "border-s-secondary/20",
|
|
61
|
+
buttonText: "text-secondary"
|
|
62
|
+
},
|
|
63
|
+
error: {
|
|
64
|
+
wrapperBg: "bg-error/10",
|
|
65
|
+
wrapperBorder: "border-s-error/20",
|
|
66
|
+
buttonText: "text-error"
|
|
67
|
+
},
|
|
68
|
+
info: {
|
|
69
|
+
wrapperBg: "bg-info/10",
|
|
70
|
+
wrapperBorder: "border-s-info/20",
|
|
71
|
+
buttonText: "text-info"
|
|
72
|
+
},
|
|
73
|
+
success: {
|
|
74
|
+
wrapperBg: "bg-success/10",
|
|
75
|
+
wrapperBorder: "border-s-success/20",
|
|
76
|
+
buttonText: "text-success"
|
|
77
|
+
},
|
|
78
|
+
warning: {
|
|
79
|
+
wrapperBg: "bg-warning/10",
|
|
80
|
+
wrapperBorder: "border-s-warning/20",
|
|
81
|
+
buttonText: "text-warning"
|
|
82
|
+
},
|
|
83
|
+
disabled: {
|
|
84
|
+
wrapperBg: "bg-disabled/10",
|
|
85
|
+
wrapperBorder: "border-s-disabled/20",
|
|
86
|
+
buttonText: "text-disabled"
|
|
87
|
+
},
|
|
88
|
+
gray: {
|
|
89
|
+
wrapperBg: "bg-gray/10",
|
|
90
|
+
wrapperBorder: "border-s-gray/20",
|
|
91
|
+
buttonText: "text-gray"
|
|
92
|
+
},
|
|
93
|
+
mist: {
|
|
94
|
+
wrapperBg: "bg-mist",
|
|
95
|
+
wrapperBorder: "border-s-mist-border",
|
|
96
|
+
buttonText: "text-mist-foreground"
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function resolveBrowseTokens(color) {
|
|
100
|
+
if (color in PRESET_BROWSE_TOKENS) return PRESET_BROWSE_TOKENS[color];
|
|
101
|
+
return {
|
|
102
|
+
wrapperBg: "bg-[color-mix(in_srgb,var(--fi-accent)_10%,transparent)]",
|
|
103
|
+
wrapperBorder: "border-s-[color-mix(in_srgb,var(--fi-accent)_20%,transparent)]",
|
|
104
|
+
buttonText: "text-[var(--fi-accent)]",
|
|
105
|
+
style: { "--fi-accent": color }
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
var FileInput = React$1.forwardRef(function FileInput({ label, required, size, rounded, color = "primary", startHelperContent, endHelperContent, hintContent, error, errorContent, startIcon, disabled = false, readOnly = false, id, className, name, accept, multiple = false, files: filesProp, onFilesChange, onChange, browseLabel = "Browse", changeLabel = "Change", clearLabel = "Clear file", placeholder = "No file chosen", andMoreLabel = (n) => `and ${n} more`, ...restProps }, ref) {
|
|
109
|
+
const autoId = React$1.useId();
|
|
110
|
+
const inputId = id ?? autoId;
|
|
111
|
+
const effectiveSize = size ?? "default";
|
|
112
|
+
const hasError = error || !!errorContent;
|
|
113
|
+
const browseTokens = resolveBrowseTokens(color);
|
|
114
|
+
const { ref: refFromRegister, ...inputAttrs } = restProps;
|
|
115
|
+
const isControlled = filesProp !== void 0;
|
|
116
|
+
const innerRef = React$1.useRef(null);
|
|
117
|
+
const filesRef = React$1.useRef([]);
|
|
118
|
+
const [internalFiles, setInternalFiles] = React$1.useState([]);
|
|
119
|
+
const listFiles = isControlled ? filesProp ?? [] : internalFiles;
|
|
120
|
+
filesRef.current = listFiles;
|
|
121
|
+
const hasFiles = listFiles.length > 0;
|
|
122
|
+
React$1.useLayoutEffect(() => {
|
|
123
|
+
const input = innerRef.current;
|
|
124
|
+
if (!input) return;
|
|
125
|
+
syncInputFiles(input, listFiles);
|
|
126
|
+
}, [listFiles]);
|
|
127
|
+
const setRefs = React$1.useCallback((node) => {
|
|
128
|
+
innerRef.current = node;
|
|
129
|
+
assignRef(ref, node);
|
|
130
|
+
assignRef(refFromRegister, node);
|
|
131
|
+
}, [ref, refFromRegister]);
|
|
132
|
+
const fireSyntheticChange = React$1.useCallback((input) => {
|
|
133
|
+
onChange?.({
|
|
134
|
+
target: input,
|
|
135
|
+
currentTarget: input
|
|
136
|
+
});
|
|
137
|
+
}, [onChange]);
|
|
138
|
+
const handleInputChange = React$1.useCallback((event) => {
|
|
139
|
+
const input = event.target;
|
|
140
|
+
const picked = filesFromList(input.files);
|
|
141
|
+
input.value = "";
|
|
142
|
+
const next = mergeFiles(multiple ? filesRef.current : [], picked, multiple);
|
|
143
|
+
syncInputFiles(input, next);
|
|
144
|
+
if (!isControlled) setInternalFiles(next);
|
|
145
|
+
onFilesChange?.(next);
|
|
146
|
+
onChange?.({
|
|
147
|
+
...event,
|
|
148
|
+
target: input,
|
|
149
|
+
currentTarget: input
|
|
150
|
+
});
|
|
151
|
+
}, [
|
|
152
|
+
multiple,
|
|
153
|
+
onChange,
|
|
154
|
+
onFilesChange,
|
|
155
|
+
isControlled
|
|
156
|
+
]);
|
|
157
|
+
const clearFiles = React$1.useCallback(() => {
|
|
158
|
+
const input = innerRef.current;
|
|
159
|
+
if (!input) return;
|
|
160
|
+
syncInputFiles(input, []);
|
|
161
|
+
if (!isControlled) setInternalFiles([]);
|
|
162
|
+
onFilesChange?.([]);
|
|
163
|
+
fireSyntheticChange(input);
|
|
164
|
+
}, [
|
|
165
|
+
isControlled,
|
|
166
|
+
onFilesChange,
|
|
167
|
+
fireSyntheticChange
|
|
168
|
+
]);
|
|
169
|
+
const openFileDialog = React$1.useCallback(() => {
|
|
170
|
+
if (disabled || readOnly) return;
|
|
171
|
+
innerRef.current?.click();
|
|
172
|
+
}, [disabled, readOnly]);
|
|
173
|
+
const onDisplayKeyDown = React$1.useCallback((e) => {
|
|
174
|
+
if (disabled || readOnly) return;
|
|
175
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
openFileDialog();
|
|
178
|
+
}
|
|
179
|
+
}, [
|
|
180
|
+
disabled,
|
|
181
|
+
readOnly,
|
|
182
|
+
openFileDialog
|
|
183
|
+
]);
|
|
184
|
+
const helperStartId = `${inputId}-helper-start`;
|
|
185
|
+
const helperEndId = `${inputId}-helper-end`;
|
|
186
|
+
const describedBy = [
|
|
187
|
+
errorContent && `${inputId}-error`,
|
|
188
|
+
startHelperContent && !errorContent && helperStartId,
|
|
189
|
+
endHelperContent && !errorContent && helperEndId
|
|
190
|
+
].filter(Boolean).join(" ") || void 0;
|
|
191
|
+
let displayContent;
|
|
192
|
+
if (!hasFiles) displayContent = /* @__PURE__ */ jsx("span", {
|
|
193
|
+
className: "truncate text-muted-foreground",
|
|
194
|
+
children: placeholder
|
|
195
|
+
});
|
|
196
|
+
else if (listFiles.length === 1) displayContent = /* @__PURE__ */ jsx("span", {
|
|
197
|
+
className: "truncate text-foreground",
|
|
198
|
+
children: listFiles[0].name
|
|
199
|
+
});
|
|
200
|
+
else {
|
|
201
|
+
const remaining = listFiles.length - 1;
|
|
202
|
+
displayContent = /* @__PURE__ */ jsxs("span", {
|
|
203
|
+
className: "flex min-w-0 items-center gap-1 text-foreground",
|
|
204
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
205
|
+
className: "truncate",
|
|
206
|
+
children: listFiles[0].name
|
|
207
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
208
|
+
className: "shrink-0 text-muted-foreground",
|
|
209
|
+
children: andMoreLabel(remaining)
|
|
210
|
+
})]
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const containerClasses = cn("flex w-full items-center overflow-hidden ps-3 border border-input bg-background ring-offset-background transition-[box-shadow,border-color] duration-200 ease-in-out", "focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2", sizeClasses[effectiveSize], rounded ? "rounded-full" : "rounded-md", hasError && "border-destructive focus-within:ring-destructive", startIcon && "ps-9", disabled && "cursor-not-allowed opacity-50", readOnly && "cursor-default bg-muted");
|
|
214
|
+
const actionButtonClasses = cn("inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-md px-2 text-[length:inherit] font-medium transition-colors", browseTokens.buttonText, "hover:bg-accent", "focus-visible:outline-none focus-visible:ring-0", disabled && "pointer-events-none opacity-50");
|
|
215
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
216
|
+
className: cn("@container flex-1 space-y-2", className),
|
|
217
|
+
style: browseTokens.style,
|
|
218
|
+
children: [
|
|
219
|
+
/* @__PURE__ */ jsx("input", {
|
|
220
|
+
...inputAttrs,
|
|
221
|
+
ref: setRefs,
|
|
222
|
+
id: inputId,
|
|
223
|
+
type: "file",
|
|
224
|
+
name,
|
|
225
|
+
accept,
|
|
226
|
+
multiple,
|
|
227
|
+
disabled,
|
|
228
|
+
tabIndex: -1,
|
|
229
|
+
className: "sr-only",
|
|
230
|
+
"aria-invalid": hasError || void 0,
|
|
231
|
+
"aria-describedby": describedBy,
|
|
232
|
+
onChange: handleInputChange
|
|
233
|
+
}),
|
|
234
|
+
label && /* @__PURE__ */ jsxs("div", {
|
|
235
|
+
className: "flex items-center justify-between",
|
|
236
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
237
|
+
htmlFor: inputId,
|
|
238
|
+
className: inputLabelClassName,
|
|
239
|
+
children: [label, required && /* @__PURE__ */ jsx("span", {
|
|
240
|
+
className: "text-destructive",
|
|
241
|
+
children: "*"
|
|
242
|
+
})]
|
|
243
|
+
}), hintContent && /* @__PURE__ */ jsx("span", {
|
|
244
|
+
className: "text-sm text-muted-foreground",
|
|
245
|
+
children: hintContent
|
|
246
|
+
})]
|
|
247
|
+
}),
|
|
248
|
+
!label && hintContent && /* @__PURE__ */ jsx("span", {
|
|
249
|
+
className: "text-sm text-muted-foreground",
|
|
250
|
+
children: hintContent
|
|
251
|
+
}),
|
|
252
|
+
/* @__PURE__ */ jsxs("div", {
|
|
253
|
+
className: "group relative",
|
|
254
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
255
|
+
role: "button",
|
|
256
|
+
tabIndex: disabled ? -1 : 0,
|
|
257
|
+
"aria-label": hasFiles ? listFiles.map((f) => f.name).join(", ") : placeholder,
|
|
258
|
+
onClick: openFileDialog,
|
|
259
|
+
onKeyDown: onDisplayKeyDown,
|
|
260
|
+
className: containerClasses,
|
|
261
|
+
children: [
|
|
262
|
+
/* @__PURE__ */ jsx("span", {
|
|
263
|
+
className: "min-w-0 flex-1 truncate",
|
|
264
|
+
children: displayContent
|
|
265
|
+
}),
|
|
266
|
+
hasFiles && !disabled && !readOnly && /* @__PURE__ */ jsx("button", {
|
|
267
|
+
type: "button",
|
|
268
|
+
"aria-label": clearLabel,
|
|
269
|
+
onClick: (e) => {
|
|
270
|
+
e.stopPropagation();
|
|
271
|
+
clearFiles();
|
|
272
|
+
},
|
|
273
|
+
className: cn("inline-flex shrink-0 cursor-pointer items-center justify-center text-error transition-colors", "hover:text-error/80", "focus-visible:outline-none focus-visible:ring-0", clearButtonSizeClasses[effectiveSize]),
|
|
274
|
+
children: /* @__PURE__ */ jsx(X, { className: iconSizeClasses[effectiveSize] })
|
|
275
|
+
}),
|
|
276
|
+
!readOnly && /* @__PURE__ */ jsx("div", {
|
|
277
|
+
className: cn("inline-flex shrink-0 self-stretch items-center border-s", browseTokens.wrapperBorder, browseTokens.wrapperBg, rounded ? "rounded-e-full" : "rounded-e-[calc(var(--radius)-1px)]"),
|
|
278
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
279
|
+
type: "button",
|
|
280
|
+
disabled,
|
|
281
|
+
onClick: (e) => {
|
|
282
|
+
e.stopPropagation();
|
|
283
|
+
openFileDialog();
|
|
284
|
+
},
|
|
285
|
+
className: actionButtonClasses,
|
|
286
|
+
children: [hasFiles ? /* @__PURE__ */ jsx(RefreshCw, { className: cn(iconSizeClasses[effectiveSize], "shrink-0") }) : /* @__PURE__ */ jsx(Upload, { className: cn(iconSizeClasses[effectiveSize], "shrink-0") }), /* @__PURE__ */ jsx("span", {
|
|
287
|
+
className: "hidden @[14rem]:inline",
|
|
288
|
+
children: hasFiles ? changeLabel : browseLabel
|
|
289
|
+
})]
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
]
|
|
293
|
+
}), startIcon && /* @__PURE__ */ jsx("div", {
|
|
294
|
+
className: "pointer-events-none absolute inset-y-0 start-0 flex items-center justify-center ps-3 text-muted-foreground/80",
|
|
295
|
+
children: startIcon
|
|
296
|
+
})]
|
|
297
|
+
}),
|
|
298
|
+
errorContent && /* @__PURE__ */ jsx("div", {
|
|
299
|
+
id: `${inputId}-error`,
|
|
300
|
+
className: "text-sm text-destructive",
|
|
301
|
+
children: errorContent
|
|
302
|
+
}),
|
|
303
|
+
startHelperContent && !errorContent && /* @__PURE__ */ jsx("div", {
|
|
304
|
+
id: helperStartId,
|
|
305
|
+
className: "text-sm text-muted-foreground",
|
|
306
|
+
children: startHelperContent
|
|
307
|
+
}),
|
|
308
|
+
endHelperContent && !errorContent && /* @__PURE__ */ jsx("div", {
|
|
309
|
+
id: helperEndId,
|
|
310
|
+
className: "text-sm text-end text-muted-foreground",
|
|
311
|
+
children: endHelperContent
|
|
312
|
+
})
|
|
313
|
+
]
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
FileInput.displayName = "FileInput";
|
|
317
|
+
//#endregion
|
|
318
|
+
export { FileInput };
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { buttonVariants } from "../../core/button.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
|
+
import { IconAvatar } from "../icon-avatar/icon-avatar.js";
|
|
5
|
+
import { Typography } from "../typography/typography.js";
|
|
6
|
+
import * as React$1 from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { FileCheck, Upload, X } from "lucide-react";
|
|
9
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
10
|
+
//#region src/components/file-upload/file-upload.tsx
|
|
11
|
+
function FileListItemIcon() {
|
|
12
|
+
return /* @__PURE__ */ jsx(IconAvatar, {
|
|
13
|
+
size: 36,
|
|
14
|
+
color: "gray",
|
|
15
|
+
ring: {
|
|
16
|
+
show: true,
|
|
17
|
+
color: "gray"
|
|
18
|
+
},
|
|
19
|
+
className: "shrink-0",
|
|
20
|
+
children: /* @__PURE__ */ jsx(FileCheck, { className: "size-5 stroke-1.5" })
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function formatFileSize(bytes) {
|
|
24
|
+
if (bytes === 0) return "0 B";
|
|
25
|
+
const k = 1024;
|
|
26
|
+
const sizes = [
|
|
27
|
+
"B",
|
|
28
|
+
"KB",
|
|
29
|
+
"MB",
|
|
30
|
+
"GB"
|
|
31
|
+
];
|
|
32
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
33
|
+
const n = bytes / Math.pow(k, i);
|
|
34
|
+
return `${n < 10 && i > 0 ? n.toFixed(1) : Math.round(n)} ${sizes[i]}`;
|
|
35
|
+
}
|
|
36
|
+
function fileKey(file) {
|
|
37
|
+
return `${file.name}-${file.size}-${file.lastModified}`;
|
|
38
|
+
}
|
|
39
|
+
function filesFromList(list) {
|
|
40
|
+
if (list == null || list.length === 0) return [];
|
|
41
|
+
return Array.from(list);
|
|
42
|
+
}
|
|
43
|
+
function syncInputFiles(input, files) {
|
|
44
|
+
const dt = new DataTransfer();
|
|
45
|
+
for (const f of files) dt.items.add(f);
|
|
46
|
+
input.files = dt.files;
|
|
47
|
+
}
|
|
48
|
+
function assignRef(r, node) {
|
|
49
|
+
if (r == null) return;
|
|
50
|
+
if (typeof r === "function") r(node);
|
|
51
|
+
else r.current = node;
|
|
52
|
+
}
|
|
53
|
+
function mergeFiles(existing, incoming, multiple) {
|
|
54
|
+
if (!multiple) return incoming.length > 0 ? [incoming[0]] : [];
|
|
55
|
+
const seen = new Set(existing.map(fileKey));
|
|
56
|
+
const next = [...existing];
|
|
57
|
+
for (const f of incoming) {
|
|
58
|
+
const k = fileKey(f);
|
|
59
|
+
if (!seen.has(k)) {
|
|
60
|
+
seen.add(k);
|
|
61
|
+
next.push(f);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return next;
|
|
65
|
+
}
|
|
66
|
+
var FileUpload = React$1.forwardRef(function FileUpload({ className, title = "Drag & drop files here", description, browseLabel = "Browse files", multiple = false, disabled = false, onChange, onFilesChange, files: filesProp, hideDropzoneOnFileSelect = false, id, ...inputPropsRest }, ref) {
|
|
67
|
+
const autoId = React$1.useId();
|
|
68
|
+
const inputId = id ?? autoId;
|
|
69
|
+
const descriptionId = `${inputId}-description`;
|
|
70
|
+
const { ref: refFromRegister, ...inputAttrs } = inputPropsRest;
|
|
71
|
+
const isControlled = filesProp !== void 0;
|
|
72
|
+
const innerRef = React$1.useRef(null);
|
|
73
|
+
const filesRef = React$1.useRef([]);
|
|
74
|
+
const dragDepthRef = React$1.useRef(0);
|
|
75
|
+
const [internalFiles, setInternalFiles] = React$1.useState([]);
|
|
76
|
+
const [isDragging, setIsDragging] = React$1.useState(false);
|
|
77
|
+
const listFiles = isControlled ? filesProp ?? [] : internalFiles;
|
|
78
|
+
filesRef.current = listFiles;
|
|
79
|
+
React$1.useLayoutEffect(() => {
|
|
80
|
+
const input = innerRef.current;
|
|
81
|
+
if (!input) return;
|
|
82
|
+
syncInputFiles(input, listFiles);
|
|
83
|
+
}, [listFiles]);
|
|
84
|
+
const setRefs = React$1.useCallback((node) => {
|
|
85
|
+
innerRef.current = node;
|
|
86
|
+
assignRef(ref, node);
|
|
87
|
+
assignRef(refFromRegister, node);
|
|
88
|
+
}, [ref, refFromRegister]);
|
|
89
|
+
const applyFiles = React$1.useCallback((incoming) => {
|
|
90
|
+
const input = innerRef.current;
|
|
91
|
+
if (!input) return;
|
|
92
|
+
const next = mergeFiles(multiple ? filesRef.current : [], incoming, Boolean(multiple));
|
|
93
|
+
syncInputFiles(input, next);
|
|
94
|
+
if (!isControlled) setInternalFiles(next);
|
|
95
|
+
onFilesChange?.(next);
|
|
96
|
+
onChange?.({
|
|
97
|
+
target: input,
|
|
98
|
+
currentTarget: input
|
|
99
|
+
});
|
|
100
|
+
}, [
|
|
101
|
+
multiple,
|
|
102
|
+
onChange,
|
|
103
|
+
onFilesChange,
|
|
104
|
+
isControlled
|
|
105
|
+
]);
|
|
106
|
+
const handleInputChange = React$1.useCallback((event) => {
|
|
107
|
+
const input = event.target;
|
|
108
|
+
const picked = filesFromList(input.files);
|
|
109
|
+
input.value = "";
|
|
110
|
+
const next = mergeFiles(multiple ? filesRef.current : [], picked, Boolean(multiple));
|
|
111
|
+
syncInputFiles(input, next);
|
|
112
|
+
if (!isControlled) setInternalFiles(next);
|
|
113
|
+
onFilesChange?.(next);
|
|
114
|
+
onChange?.({
|
|
115
|
+
...event,
|
|
116
|
+
target: input,
|
|
117
|
+
currentTarget: input
|
|
118
|
+
});
|
|
119
|
+
}, [
|
|
120
|
+
multiple,
|
|
121
|
+
onChange,
|
|
122
|
+
onFilesChange,
|
|
123
|
+
isControlled
|
|
124
|
+
]);
|
|
125
|
+
const removeAt = React$1.useCallback((index) => {
|
|
126
|
+
const input = innerRef.current;
|
|
127
|
+
if (!input) return;
|
|
128
|
+
const next = filesRef.current.filter((_, i) => i !== index);
|
|
129
|
+
syncInputFiles(input, next);
|
|
130
|
+
if (!isControlled) setInternalFiles(next);
|
|
131
|
+
onFilesChange?.(next);
|
|
132
|
+
onChange?.({
|
|
133
|
+
target: input,
|
|
134
|
+
currentTarget: input
|
|
135
|
+
});
|
|
136
|
+
}, [
|
|
137
|
+
onChange,
|
|
138
|
+
onFilesChange,
|
|
139
|
+
isControlled
|
|
140
|
+
]);
|
|
141
|
+
const onDragEnter = React$1.useCallback((e) => {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
e.stopPropagation();
|
|
144
|
+
if (disabled) return;
|
|
145
|
+
dragDepthRef.current += 1;
|
|
146
|
+
setIsDragging(true);
|
|
147
|
+
}, [disabled]);
|
|
148
|
+
const onDragLeave = React$1.useCallback((e) => {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
e.stopPropagation();
|
|
151
|
+
if (disabled) return;
|
|
152
|
+
dragDepthRef.current -= 1;
|
|
153
|
+
if (dragDepthRef.current <= 0) {
|
|
154
|
+
dragDepthRef.current = 0;
|
|
155
|
+
setIsDragging(false);
|
|
156
|
+
}
|
|
157
|
+
}, [disabled]);
|
|
158
|
+
const onDragOver = React$1.useCallback((e) => {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
e.stopPropagation();
|
|
161
|
+
}, []);
|
|
162
|
+
const onDrop = React$1.useCallback((e) => {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
dragDepthRef.current = 0;
|
|
166
|
+
setIsDragging(false);
|
|
167
|
+
if (disabled) return;
|
|
168
|
+
const dropped = filesFromList(e.dataTransfer.files);
|
|
169
|
+
if (dropped.length === 0) return;
|
|
170
|
+
applyFiles(dropped);
|
|
171
|
+
}, [applyFiles, disabled]);
|
|
172
|
+
const openFileDialog = React$1.useCallback(() => {
|
|
173
|
+
if (disabled) return;
|
|
174
|
+
innerRef.current?.click();
|
|
175
|
+
}, [disabled]);
|
|
176
|
+
const onDropZoneKeyDown = React$1.useCallback((e) => {
|
|
177
|
+
if (disabled) return;
|
|
178
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
openFileDialog();
|
|
181
|
+
}
|
|
182
|
+
}, [disabled, openFileDialog]);
|
|
183
|
+
const hasDescription = description != null && description !== "";
|
|
184
|
+
const dropZoneLabel = `${title}. ${browseLabel}`;
|
|
185
|
+
const showDropzone = !(hideDropzoneOnFileSelect && listFiles.length > 0);
|
|
186
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
187
|
+
className: cn("w-full space-y-3", className),
|
|
188
|
+
children: [
|
|
189
|
+
/* @__PURE__ */ jsx("input", {
|
|
190
|
+
...inputAttrs,
|
|
191
|
+
ref: setRefs,
|
|
192
|
+
id: inputId,
|
|
193
|
+
type: "file",
|
|
194
|
+
multiple,
|
|
195
|
+
disabled,
|
|
196
|
+
tabIndex: -1,
|
|
197
|
+
className: "sr-only",
|
|
198
|
+
onChange: handleInputChange
|
|
199
|
+
}),
|
|
200
|
+
/* @__PURE__ */ jsx(AnimatePresence, {
|
|
201
|
+
initial: false,
|
|
202
|
+
children: showDropzone ? /* @__PURE__ */ jsx(motion.div, {
|
|
203
|
+
initial: {
|
|
204
|
+
height: 0,
|
|
205
|
+
opacity: 0
|
|
206
|
+
},
|
|
207
|
+
animate: {
|
|
208
|
+
height: "auto",
|
|
209
|
+
opacity: 1
|
|
210
|
+
},
|
|
211
|
+
exit: {
|
|
212
|
+
height: 0,
|
|
213
|
+
opacity: 0
|
|
214
|
+
},
|
|
215
|
+
transition: {
|
|
216
|
+
duration: .25,
|
|
217
|
+
ease: "easeInOut"
|
|
218
|
+
},
|
|
219
|
+
style: { overflow: "hidden" },
|
|
220
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
221
|
+
role: "button",
|
|
222
|
+
tabIndex: disabled ? -1 : 0,
|
|
223
|
+
"aria-label": dropZoneLabel,
|
|
224
|
+
"aria-describedby": hasDescription ? descriptionId : void 0,
|
|
225
|
+
onClick: openFileDialog,
|
|
226
|
+
onKeyDown: onDropZoneKeyDown,
|
|
227
|
+
onDragEnter,
|
|
228
|
+
onDragLeave,
|
|
229
|
+
onDragOver,
|
|
230
|
+
onDrop,
|
|
231
|
+
className: cn("flex flex-col items-center gap-3 rounded-xl border-2 border-dashed border-input bg-background px-6 py-8 text-center transition-colors outline-none", !disabled && "cursor-pointer hover:border-muted-foreground/40", isDragging && !disabled && "border-primary bg-primary/5", disabled && "pointer-events-none opacity-50", "focus-visible:border-input focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"),
|
|
232
|
+
children: [
|
|
233
|
+
/* @__PURE__ */ jsx("span", {
|
|
234
|
+
className: "inline-flex",
|
|
235
|
+
"aria-hidden": true,
|
|
236
|
+
children: /* @__PURE__ */ jsx(IconAvatar, {
|
|
237
|
+
size: 48,
|
|
238
|
+
color: "primary",
|
|
239
|
+
ring: {
|
|
240
|
+
show: true,
|
|
241
|
+
color: "primary"
|
|
242
|
+
},
|
|
243
|
+
children: /* @__PURE__ */ jsx(Upload, {
|
|
244
|
+
className: "size-5",
|
|
245
|
+
strokeWidth: 1.75
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
}),
|
|
249
|
+
/* @__PURE__ */ jsxs("div", {
|
|
250
|
+
className: "space-y-1",
|
|
251
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
252
|
+
variant: "body2",
|
|
253
|
+
as: "p",
|
|
254
|
+
className: "font-semibold text-foreground",
|
|
255
|
+
children: title
|
|
256
|
+
}), hasDescription ? /* @__PURE__ */ jsx(Typography, {
|
|
257
|
+
id: descriptionId,
|
|
258
|
+
variant: "body2",
|
|
259
|
+
as: "p",
|
|
260
|
+
className: "text-sm text-muted-foreground",
|
|
261
|
+
children: description
|
|
262
|
+
}) : null]
|
|
263
|
+
}),
|
|
264
|
+
/* @__PURE__ */ jsx("span", {
|
|
265
|
+
"aria-hidden": true,
|
|
266
|
+
className: cn(buttonVariants({
|
|
267
|
+
variant: "outline",
|
|
268
|
+
size: "sm"
|
|
269
|
+
}), "pointer-events-none shrink-0 border-input text-gray shadow-none ring-offset-background transition-all duration-300 hover:bg-gray/5 hover:border-gray hover:ring-2 hover:ring-offset-2 hover:ring-gray/90"),
|
|
270
|
+
children: browseLabel
|
|
271
|
+
})
|
|
272
|
+
]
|
|
273
|
+
})
|
|
274
|
+
}, "dropzone") : null
|
|
275
|
+
}),
|
|
276
|
+
listFiles.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
277
|
+
className: "flex flex-col gap-2",
|
|
278
|
+
"aria-live": "polite",
|
|
279
|
+
children: listFiles.map((file, index) => /* @__PURE__ */ jsxs("li", {
|
|
280
|
+
className: "flex items-center gap-3 rounded-xl border border-input bg-background px-3 py-2.5",
|
|
281
|
+
children: [
|
|
282
|
+
/* @__PURE__ */ jsx(FileListItemIcon, {}),
|
|
283
|
+
/* @__PURE__ */ jsxs("div", {
|
|
284
|
+
className: "min-w-0 flex-1 text-left",
|
|
285
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
286
|
+
variant: "body2",
|
|
287
|
+
as: "p",
|
|
288
|
+
className: "truncate font-semibold",
|
|
289
|
+
children: file.name
|
|
290
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
291
|
+
variant: "body2",
|
|
292
|
+
as: "p",
|
|
293
|
+
className: "text-xs text-muted-foreground",
|
|
294
|
+
children: formatFileSize(file.size)
|
|
295
|
+
})]
|
|
296
|
+
}),
|
|
297
|
+
/* @__PURE__ */ jsx(Button, {
|
|
298
|
+
type: "button",
|
|
299
|
+
variant: "ghost",
|
|
300
|
+
size: "sm",
|
|
301
|
+
color: "error",
|
|
302
|
+
fullWidth: false,
|
|
303
|
+
className: "size-9 shrink-0 p-0",
|
|
304
|
+
disabled,
|
|
305
|
+
"aria-label": `Remove ${file.name}`,
|
|
306
|
+
onClick: () => removeAt(index),
|
|
307
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
308
|
+
})
|
|
309
|
+
]
|
|
310
|
+
}, `${fileKey(file)}-${index}`))
|
|
311
|
+
}) : null
|
|
312
|
+
]
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
FileUpload.displayName = "FileUpload";
|
|
316
|
+
//#endregion
|
|
317
|
+
export { FileUpload };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/components/filters-bar/filters-bar.tsx
|
|
4
|
+
function FiltersBar({ search, actions, filters, searchClassName, className }) {
|
|
5
|
+
if (!filters) return /* @__PURE__ */ jsxs("div", {
|
|
6
|
+
className: cn("flex w-full items-center justify-between gap-3 md:gap-4", className),
|
|
7
|
+
children: [search && /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: cn("min-w-0 flex-1", searchClassName ?? "max-w-md"),
|
|
9
|
+
children: search
|
|
10
|
+
}), actions && /* @__PURE__ */ jsx("div", {
|
|
11
|
+
className: "ml-auto flex shrink-0 items-center justify-end gap-2 md:gap-3",
|
|
12
|
+
children: actions
|
|
13
|
+
})]
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsx("div", {
|
|
16
|
+
className: cn("@container w-full", className),
|
|
17
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
18
|
+
className: "flex flex-col gap-3 @3xl:flex-row @3xl:flex-wrap @3xl:items-center @3xl:gap-x-5",
|
|
19
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
20
|
+
className: "flex flex-wrap items-center gap-2 empty:hidden @3xl:contents",
|
|
21
|
+
children: [search && /* @__PURE__ */ jsx("div", {
|
|
22
|
+
className: cn("min-w-0 flex-1 @3xl:order-1 @3xl:flex-none", searchClassName ?? "@3xl:w-xs"),
|
|
23
|
+
children: search
|
|
24
|
+
}), actions && /* @__PURE__ */ jsx("div", {
|
|
25
|
+
className: "ml-auto flex shrink-0 items-center justify-end gap-2 @3xl:order-3",
|
|
26
|
+
children: actions
|
|
27
|
+
})]
|
|
28
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
29
|
+
className: "-m-1 flex min-w-0 flex-nowrap items-center gap-2 overflow-x-auto p-1 [scrollbar-width:none] empty:hidden *:shrink-0 [&::-webkit-scrollbar]:hidden @3xl:order-2 @3xl:m-0 @3xl:flex-1 @3xl:flex-wrap @3xl:gap-x-5 @3xl:gap-y-3 @3xl:overflow-visible @3xl:p-0",
|
|
30
|
+
children: filters
|
|
31
|
+
})]
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { FiltersBar as default };
|