@espressif/dashboard-ui-components 1.10.0 → 1.11.1
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 +75 -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 +16 -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,65 @@
|
|
|
1
|
+
import { getColumnMeta } from "./sticky-columns.js";
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
//#region src/components/data-table/responsive-columns.ts
|
|
4
|
+
/** Tailwind's container sizes, in px at the default 16px rem. */
|
|
5
|
+
var BREAKPOINTS = {
|
|
6
|
+
sm: 384,
|
|
7
|
+
md: 448,
|
|
8
|
+
lg: 512,
|
|
9
|
+
xl: 576,
|
|
10
|
+
"2xl": 672,
|
|
11
|
+
"3xl": 768,
|
|
12
|
+
"4xl": 896,
|
|
13
|
+
"5xl": 1024,
|
|
14
|
+
"6xl": 1152,
|
|
15
|
+
"7xl": 1280
|
|
16
|
+
};
|
|
17
|
+
function minWidth(hideBelow) {
|
|
18
|
+
return typeof hideBelow === "number" ? hideBelow : hideBelow && BREAKPOINTS[hideBelow];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Width of `ref`'s element, tracked while `enabled`. `null` until measured, so
|
|
22
|
+
* nothing is hidden before the real width is known.
|
|
23
|
+
*/
|
|
24
|
+
function useElementWidth(ref, enabled) {
|
|
25
|
+
const [width, setWidth] = useState(null);
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
const el = ref.current;
|
|
28
|
+
if (!enabled || !el) return;
|
|
29
|
+
const measure = () => setWidth(el.getBoundingClientRect().width);
|
|
30
|
+
measure();
|
|
31
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
32
|
+
const observer = new ResizeObserver(measure);
|
|
33
|
+
observer.observe(el);
|
|
34
|
+
return () => observer.disconnect();
|
|
35
|
+
}, [ref, enabled]);
|
|
36
|
+
return enabled ? width : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Applies `meta.hideBelow` to the table's column visibility. Visibility is only
|
|
40
|
+
* written when the set of too-narrow columns changes (a breakpoint is crossed),
|
|
41
|
+
* so a column the user shows or hides from the Columns menu stays that way
|
|
42
|
+
* until the next crossing.
|
|
43
|
+
*/
|
|
44
|
+
function useResponsiveColumnVisibility(ref, columns, setColumnVisibility) {
|
|
45
|
+
const responsive = columns.filter((column) => minWidth(getColumnMeta(column)?.hideBelow) !== void 0);
|
|
46
|
+
const width = useElementWidth(ref, responsive.length > 0);
|
|
47
|
+
const hiddenKey = width === null ? null : responsive.filter((column) => width < minWidth(getColumnMeta(column)?.hideBelow)).map((column) => column.id).join("\0");
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
if (hiddenKey === null) return;
|
|
50
|
+
const hidden = new Set(hiddenKey.split("\0"));
|
|
51
|
+
setColumnVisibility((prev) => {
|
|
52
|
+
let next = null;
|
|
53
|
+
for (const column of responsive) {
|
|
54
|
+
const visible = !hidden.has(column.id) && !getColumnMeta(column)?.defaultHidden;
|
|
55
|
+
if ((prev[column.id] ?? true) !== visible) {
|
|
56
|
+
next ?? (next = { ...prev });
|
|
57
|
+
next[column.id] = visible;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return next ?? prev;
|
|
61
|
+
});
|
|
62
|
+
}, [hiddenKey, setColumnVisibility]);
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { useResponsiveColumnVisibility };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/components/data-table/row-actions.tsx
|
|
4
|
+
var revealClasses = {
|
|
5
|
+
always: "[@media(hover:hover)]:opacity-0",
|
|
6
|
+
md: "md:[@media(hover:hover)]:opacity-0"
|
|
7
|
+
};
|
|
8
|
+
/** Menus and dialogs are portalled, but React events still bubble to the row. */
|
|
9
|
+
function stopRowInteraction(event) {
|
|
10
|
+
event.stopPropagation();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Row action cell content for DataTable. Hidden until the row is hovered, but
|
|
14
|
+
* only on devices that can hover, so touch screens always show it. Stays visible
|
|
15
|
+
* for keyboard focus and while a menu or dialog it opened is open. Clicks and
|
|
16
|
+
* key presses don't reach the row's own click handler.
|
|
17
|
+
*/
|
|
18
|
+
function DataTableRowActions({ children, alwaysVisible = false, alwaysVisibleBelow, className }) {
|
|
19
|
+
return /* @__PURE__ */ jsx("div", {
|
|
20
|
+
className: cn("flex min-h-9 items-center justify-end", !alwaysVisible && ["transition-opacity group-hover/data-table-row:opacity-100 group-focus-within/data-table-row:opacity-100 has-[[data-state=open]]:opacity-100", revealClasses[alwaysVisibleBelow ?? "always"]], className),
|
|
21
|
+
onClick: stopRowInteraction,
|
|
22
|
+
onKeyDown: stopRowInteraction,
|
|
23
|
+
children
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { DataTableRowActions };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
//#region src/components/data-table/sticky-columns.ts
|
|
4
|
+
function getColumnMeta(column) {
|
|
5
|
+
return column.columnDef.meta;
|
|
6
|
+
}
|
|
7
|
+
var SELECT_COLUMN_ID = "__select";
|
|
8
|
+
/** Number of leading visible columns that should be pinned. */
|
|
9
|
+
function countStickyColumns(columns) {
|
|
10
|
+
let count = 0;
|
|
11
|
+
for (let i = 0; i < columns.length; i++) {
|
|
12
|
+
const column = columns[i];
|
|
13
|
+
if (!(column.id === SELECT_COLUMN_ID ? Boolean(columns[i + 1] && getColumnMeta(columns[i + 1])?.sticky) : Boolean(getColumnMeta(column)?.sticky))) break;
|
|
14
|
+
count++;
|
|
15
|
+
}
|
|
16
|
+
return count;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Left offset of each of the first `count` columns, measured from the header
|
|
20
|
+
* cells. Re-measured whenever the table resizes (data, visibility, viewport).
|
|
21
|
+
*/
|
|
22
|
+
function useStickyOffsets(tableRef, count) {
|
|
23
|
+
const [offsets, setOffsets] = useState([]);
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
const table = tableRef.current;
|
|
26
|
+
if (!table || count === 0) {
|
|
27
|
+
setOffsets((prev) => prev.length === 0 ? prev : []);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const measure = () => {
|
|
31
|
+
const cells = table.querySelectorAll("thead tr:last-child > th");
|
|
32
|
+
const next = [];
|
|
33
|
+
let left = 0;
|
|
34
|
+
for (let i = 0; i < count && i < cells.length; i++) {
|
|
35
|
+
next.push(left);
|
|
36
|
+
left += cells[i].getBoundingClientRect().width;
|
|
37
|
+
}
|
|
38
|
+
setOffsets((prev) => prev.length === next.length && prev.every((v, i) => v === next[i]) ? prev : next);
|
|
39
|
+
};
|
|
40
|
+
measure();
|
|
41
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
42
|
+
const observer = new ResizeObserver(measure);
|
|
43
|
+
observer.observe(table);
|
|
44
|
+
return () => observer.disconnect();
|
|
45
|
+
}, [tableRef, count]);
|
|
46
|
+
return offsets;
|
|
47
|
+
}
|
|
48
|
+
function buildStickyColumns(columns, offsets) {
|
|
49
|
+
const map = /* @__PURE__ */ new Map();
|
|
50
|
+
const count = Math.min(offsets.length, columns.length);
|
|
51
|
+
for (let i = 0; i < count; i++) map.set(columns[i].id, {
|
|
52
|
+
left: offsets[i],
|
|
53
|
+
isLast: i === count - 1
|
|
54
|
+
});
|
|
55
|
+
return map;
|
|
56
|
+
}
|
|
57
|
+
var stickyBase = "sticky";
|
|
58
|
+
var stickyHeadBg = "z-[2] bg-[var(--data-table-sticky-bg,var(--color-background))]";
|
|
59
|
+
var stickyHeadBorderedBg = "z-[2] bg-[color-mix(in_oklab,var(--color-muted)_50%,var(--data-table-sticky-bg,var(--color-background)))]";
|
|
60
|
+
var stickyCellBg = "z-[1] bg-[var(--data-table-sticky-bg,var(--color-background))] [tr:hover>&]:bg-[color-mix(in_oklab,var(--color-muted)_50%,var(--data-table-sticky-bg,var(--color-background)))] [tr[data-state=selected]>&]:bg-muted";
|
|
61
|
+
var stickyEdge = "after:pointer-events-none after:absolute after:inset-y-0 after:-right-4 after:w-4 after:bg-linear-to-r after:from-black/10 after:to-transparent after:opacity-0 after:transition-opacity group-data-[overflow-start]/data-table:after:opacity-100 dark:after:from-black/40";
|
|
62
|
+
function stickyCellProps(stickyColumns, columnId, kind) {
|
|
63
|
+
const sticky = stickyColumns?.get(columnId);
|
|
64
|
+
if (!sticky) return {};
|
|
65
|
+
return {
|
|
66
|
+
className: cn(stickyBase, kind === "head" ? stickyHeadBg : kind === "headBordered" ? stickyHeadBorderedBg : stickyCellBg, sticky.isLast && stickyEdge),
|
|
67
|
+
style: { left: sticky.left }
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { SELECT_COLUMN_ID, buildStickyColumns, countStickyColumns, getColumnMeta, stickyCellProps, useStickyOffsets };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import NoDataCard from "../cards/no-data-card/no-data-card.js";
|
|
3
|
+
import { TableBody, TableCell, TableRow } from "../../core/table.js";
|
|
4
|
+
import { TableSkeleton } from "../skeletons/table-skeleton.js";
|
|
5
|
+
import { getColumnMeta, stickyCellProps } from "./sticky-columns.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { flexRender } from "@tanstack/react-table";
|
|
8
|
+
//#region src/components/data-table/table-body.tsx
|
|
9
|
+
function DataTableBody({ rows, columnCount, isFetching, pageSize, noResultsHeading, noResultsDescription, noResultsAction, noResultsIllustration, hideNoResultsIllustration, onRowClick, showBorder = false, tableRowClassName, getRowClassName, stickyColumns }) {
|
|
10
|
+
if (isFetching) return /* @__PURE__ */ jsx(TableSkeleton, {
|
|
11
|
+
totalRows: pageSize,
|
|
12
|
+
totalColumns: columnCount,
|
|
13
|
+
showBorder,
|
|
14
|
+
padFirstColumn: showBorder
|
|
15
|
+
});
|
|
16
|
+
if (!rows.length) return /* @__PURE__ */ jsx(TableBody, { children: /* @__PURE__ */ jsx(TableRow, {
|
|
17
|
+
className: "hover:bg-transparent",
|
|
18
|
+
children: /* @__PURE__ */ jsx(TableCell, {
|
|
19
|
+
colSpan: columnCount,
|
|
20
|
+
className: "p-0 transparent",
|
|
21
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
22
|
+
className: "mx-auto max-w-md",
|
|
23
|
+
children: /* @__PURE__ */ jsx(NoDataCard, {
|
|
24
|
+
heading: noResultsHeading,
|
|
25
|
+
description: noResultsDescription,
|
|
26
|
+
action: noResultsAction,
|
|
27
|
+
illustration: noResultsIllustration,
|
|
28
|
+
hideIllustration: hideNoResultsIllustration,
|
|
29
|
+
className: "border-0 shadow-none"
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
}) });
|
|
34
|
+
return /* @__PURE__ */ jsx(TableBody, { children: rows.map((row, rowIndex) => /* @__PURE__ */ jsx(TableRow, {
|
|
35
|
+
"data-state": row.getIsSelected() && "selected",
|
|
36
|
+
tabIndex: onRowClick ? 0 : void 0,
|
|
37
|
+
className: cn("group/data-table-row", onRowClick && "group cursor-pointer outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", showBorder ? "border-b border-border/50 last:border-b-0" : "border-0", getRowClassName?.(row.original, rowIndex), tableRowClassName),
|
|
38
|
+
onClick: onRowClick ? () => onRowClick(row.original) : void 0,
|
|
39
|
+
onKeyDown: onRowClick ? (e) => {
|
|
40
|
+
if (e.repeat) return;
|
|
41
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
onRowClick(row.original);
|
|
44
|
+
}
|
|
45
|
+
} : void 0,
|
|
46
|
+
children: row.getVisibleCells().map((cell, cellIndex) => {
|
|
47
|
+
const sticky = stickyCellProps(stickyColumns, cell.column.id, "cell");
|
|
48
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
49
|
+
className: cn("px-2 py-4", getColumnMeta(cell.column)?.wrap ? "min-w-64 whitespace-normal" : "whitespace-nowrap", getColumnMeta(cell.column)?.fill && "w-full max-w-0", showBorder && cellIndex === 0 && "pl-4", sticky.className),
|
|
50
|
+
style: sticky.style,
|
|
51
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
52
|
+
}, cell.id);
|
|
53
|
+
})
|
|
54
|
+
}, row.id)) });
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { DataTableBody };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { TableHead, TableHeader, TableRow } from "../../core/table.js";
|
|
3
|
+
import { stickyCellProps } from "./sticky-columns.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { flexRender } from "@tanstack/react-table";
|
|
6
|
+
//#region src/components/data-table/table-header.tsx
|
|
7
|
+
function DataTableHeader({ headerGroups, showBorder = false, stickyColumns }) {
|
|
8
|
+
return /* @__PURE__ */ jsx(TableHeader, {
|
|
9
|
+
className: cn(showBorder && "bg-muted/50 [&_tr]:border-border/50"),
|
|
10
|
+
children: headerGroups.map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { children: headerGroup.headers.map((header, headerIndex) => {
|
|
11
|
+
const sticky = stickyCellProps(stickyColumns, header.column.id, showBorder ? "headBordered" : "head");
|
|
12
|
+
return /* @__PURE__ */ jsx(TableHead, {
|
|
13
|
+
className: cn("text-sm text-gray-500 font-medium whitespace-nowrap", showBorder && headerIndex === 0 && "pl-4", sticky.className),
|
|
14
|
+
style: sticky.style,
|
|
15
|
+
children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
|
|
16
|
+
}, header.id);
|
|
17
|
+
}) }, headerGroup.id))
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { DataTableHeader };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../../core/popover.js";
|
|
4
|
+
import { Input } from "../../core/input/input.js";
|
|
5
|
+
import { Calendar } from "../calendar/calendar.js";
|
|
6
|
+
import { FIELD_ICON_SIZE, FieldEndIcons, fieldEndPaddingClassName } from "../../core/field-end-icons.js";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { CalendarIcon } from "lucide-react";
|
|
10
|
+
import { format } from "date-fns";
|
|
11
|
+
//#region src/components/date-picker/date-picker.tsx
|
|
12
|
+
function DatePicker(props) {
|
|
13
|
+
const { value, onChange, defaultValue, formatDate, name, trigger, placeholder = "Pick a date", label, size, hideIcon = false, disabled = false, required = false, rounded = false, error, errorContent, startHelperContent, endHelperContent, hintContent, clearable = false, clearLabel = "Clear", calendarProps, open: controlledOpen, onOpenChange, className } = props;
|
|
14
|
+
const [uncontrolledDate, setUncontrolledDate] = useState(defaultValue);
|
|
15
|
+
const [internalOpen, setInternalOpen] = useState(false);
|
|
16
|
+
const isControlled = "value" in props;
|
|
17
|
+
const selectedDate = isControlled ? value : uncontrolledDate;
|
|
18
|
+
const isOpenControlled = controlledOpen !== void 0;
|
|
19
|
+
const isOpen = isOpenControlled ? controlledOpen : internalOpen;
|
|
20
|
+
const setOpen = (nextOpen) => {
|
|
21
|
+
if (!isOpenControlled) setInternalOpen(nextOpen);
|
|
22
|
+
onOpenChange?.(nextOpen);
|
|
23
|
+
};
|
|
24
|
+
const handleSelect = (date) => {
|
|
25
|
+
if (!isControlled) setUncontrolledDate(date);
|
|
26
|
+
onChange?.(date);
|
|
27
|
+
setOpen(false);
|
|
28
|
+
};
|
|
29
|
+
const handleClear = (event) => {
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
if (!isControlled) setUncontrolledDate(void 0);
|
|
32
|
+
onChange?.(void 0);
|
|
33
|
+
};
|
|
34
|
+
const showClear = clearable && !disabled && selectedDate !== void 0;
|
|
35
|
+
const displayValue = selectedDate ? (formatDate ?? ((d) => format(d, "PPP")))(selectedDate) : "";
|
|
36
|
+
const inputTrigger = /* @__PURE__ */ jsx(Input, {
|
|
37
|
+
readOnly: true,
|
|
38
|
+
value: displayValue,
|
|
39
|
+
placeholder,
|
|
40
|
+
label,
|
|
41
|
+
size,
|
|
42
|
+
disabled,
|
|
43
|
+
required,
|
|
44
|
+
rounded,
|
|
45
|
+
error,
|
|
46
|
+
errorContent,
|
|
47
|
+
startHelperContent,
|
|
48
|
+
endHelperContent,
|
|
49
|
+
hintContent,
|
|
50
|
+
className: cn("cursor-pointer read-only:bg-background", fieldEndPaddingClassName(showClear, !hideIcon), !displayValue && "text-muted-foreground"),
|
|
51
|
+
endIcon: showClear || !hideIcon ? /* @__PURE__ */ jsx(FieldEndIcons, {
|
|
52
|
+
onClear: showClear ? handleClear : void 0,
|
|
53
|
+
clearLabel,
|
|
54
|
+
icon: hideIcon ? void 0 : /* @__PURE__ */ jsx(CalendarIcon, {
|
|
55
|
+
size: FIELD_ICON_SIZE,
|
|
56
|
+
className: "text-muted-foreground"
|
|
57
|
+
})
|
|
58
|
+
}) : void 0
|
|
59
|
+
});
|
|
60
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
61
|
+
className: cn("flex-1", className),
|
|
62
|
+
children: [/* @__PURE__ */ jsxs(Popover, {
|
|
63
|
+
open: isOpen,
|
|
64
|
+
onOpenChange: setOpen,
|
|
65
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
66
|
+
asChild: true,
|
|
67
|
+
disabled,
|
|
68
|
+
children: trigger ? trigger : /* @__PURE__ */ jsx("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
disabled,
|
|
71
|
+
className: "w-full text-start",
|
|
72
|
+
children: inputTrigger
|
|
73
|
+
})
|
|
74
|
+
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
75
|
+
align: "start",
|
|
76
|
+
className: "w-auto overflow-hidden rounded-2xl p-1 shadow-lg",
|
|
77
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
78
|
+
mode: "single",
|
|
79
|
+
selected: selectedDate,
|
|
80
|
+
onSelect: handleSelect,
|
|
81
|
+
showOutsideDays: true,
|
|
82
|
+
captionLayout: "dropdown",
|
|
83
|
+
...calendarProps
|
|
84
|
+
})
|
|
85
|
+
})]
|
|
86
|
+
}), name && /* @__PURE__ */ jsx("input", {
|
|
87
|
+
type: "hidden",
|
|
88
|
+
name,
|
|
89
|
+
value: selectedDate?.toISOString() ?? ""
|
|
90
|
+
})]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
DatePicker.displayName = "DatePicker";
|
|
94
|
+
//#endregion
|
|
95
|
+
export { DatePicker };
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { Button } from "../button/button.js";
|
|
3
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../../core/popover.js";
|
|
4
|
+
import { Input } from "../../core/input/input.js";
|
|
5
|
+
import { Calendar } from "../calendar/calendar.js";
|
|
6
|
+
import { PRESET_IDS, PRESET_LABELS, computeDateRange } from "./presets.js";
|
|
7
|
+
import * as React$1 from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { CalendarRangeIcon, CheckIcon, ChevronRightIcon, XIcon } from "lucide-react";
|
|
10
|
+
import { endOfDay, format, isValid, parse } from "date-fns";
|
|
11
|
+
//#region src/components/date-range-picker/date-range-picker.tsx
|
|
12
|
+
var DEFAULT_DATE_FORMAT = "dd MMM yyyy";
|
|
13
|
+
var EMPTY_DRAFT_RANGE = {
|
|
14
|
+
startDate: null,
|
|
15
|
+
endDate: null
|
|
16
|
+
};
|
|
17
|
+
var toDraftRange = (range) => ({
|
|
18
|
+
startDate: range?.from ?? null,
|
|
19
|
+
endDate: range?.to ?? null
|
|
20
|
+
});
|
|
21
|
+
var toCalendarRange = (range) => {
|
|
22
|
+
if (!range.startDate && !range.endDate) return void 0;
|
|
23
|
+
return {
|
|
24
|
+
from: range.startDate ?? void 0,
|
|
25
|
+
to: range.endDate ?? void 0
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
var parseDateOrNull = (value, dateFormat) => {
|
|
29
|
+
const parsed = parse(value, dateFormat, /* @__PURE__ */ new Date());
|
|
30
|
+
return isValid(parsed) ? parsed : null;
|
|
31
|
+
};
|
|
32
|
+
function DateRangePicker({ presets, presetLabels, allowCustom = false, lockEndToToday = false, disableFutureDates = false, dateFormat = DEFAULT_DATE_FORMAT, onChange, onPresetChange, onDraftChange, selectedPresetId, selectedStartDate, selectedEndDate, clearable = false, clearLabel = "Clear", onClear, trigger, placeholder = "Select date range", label, size, hideIcon = false, disabled = false, required = false, rounded = false, error, errorContent, startHelperContent, endHelperContent, hintContent, align = "start", side = "bottom", className }) {
|
|
33
|
+
const [open, setOpen] = React$1.useState(false);
|
|
34
|
+
const [showCalendar, setShowCalendar] = React$1.useState(false);
|
|
35
|
+
const [draftRange, setDraftRange] = React$1.useState(EMPTY_DRAFT_RANGE);
|
|
36
|
+
const [calendarMonth, setCalendarMonth] = React$1.useState(/* @__PURE__ */ new Date());
|
|
37
|
+
const [calendarLayout, setCalendarLayout] = React$1.useState("right");
|
|
38
|
+
const calendarRef = React$1.useRef(null);
|
|
39
|
+
const [startInputValue, setStartInputValue] = React$1.useState("");
|
|
40
|
+
const [endInputValue, setEndInputValue] = React$1.useState("");
|
|
41
|
+
React$1.useLayoutEffect(() => {
|
|
42
|
+
if (!showCalendar || !calendarRef.current || calendarLayout === "inline") return;
|
|
43
|
+
const rect = calendarRef.current.getBoundingClientRect();
|
|
44
|
+
if (rect.bottom > window.innerHeight) setCalendarLayout("inline");
|
|
45
|
+
else if (calendarLayout === "right" && rect.right > window.innerWidth) setCalendarLayout("left");
|
|
46
|
+
else if (calendarLayout === "left" && rect.left < 0) setCalendarLayout("inline");
|
|
47
|
+
}, [showCalendar, calendarLayout]);
|
|
48
|
+
const activePresets = presets ?? [...PRESET_IDS];
|
|
49
|
+
const resolveLabel = (id) => presetLabels?.[id] ?? (id === "custom" ? "Custom" : PRESET_LABELS[id]);
|
|
50
|
+
const updateDraftRange = React$1.useCallback((nextRange) => {
|
|
51
|
+
setDraftRange(nextRange);
|
|
52
|
+
onDraftChange?.(nextRange);
|
|
53
|
+
}, [onDraftChange]);
|
|
54
|
+
const syncInputsFromDraft = React$1.useCallback((range) => {
|
|
55
|
+
setStartInputValue(range.startDate ? format(range.startDate, dateFormat) : "");
|
|
56
|
+
if (lockEndToToday) setEndInputValue(format(/* @__PURE__ */ new Date(), dateFormat));
|
|
57
|
+
else setEndInputValue(range.endDate ? format(range.endDate, dateFormat) : "");
|
|
58
|
+
}, [dateFormat, lockEndToToday]);
|
|
59
|
+
const handleOpenChange = (nextOpen) => {
|
|
60
|
+
setOpen(nextOpen);
|
|
61
|
+
if (!nextOpen) {
|
|
62
|
+
setShowCalendar(false);
|
|
63
|
+
setCalendarLayout("right");
|
|
64
|
+
updateDraftRange(EMPTY_DRAFT_RANGE);
|
|
65
|
+
setStartInputValue("");
|
|
66
|
+
setEndInputValue("");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const handlePresetClick = (id) => {
|
|
70
|
+
const range = computeDateRange(id);
|
|
71
|
+
onPresetChange?.(id, range);
|
|
72
|
+
onChange?.({
|
|
73
|
+
presetId: id,
|
|
74
|
+
...range
|
|
75
|
+
});
|
|
76
|
+
setOpen(false);
|
|
77
|
+
};
|
|
78
|
+
const handleRangeChange = React$1.useCallback((range) => {
|
|
79
|
+
const nextDraft = toDraftRange(range);
|
|
80
|
+
if (lockEndToToday && nextDraft.startDate) {
|
|
81
|
+
const locked = {
|
|
82
|
+
startDate: nextDraft.startDate,
|
|
83
|
+
endDate: endOfDay(/* @__PURE__ */ new Date())
|
|
84
|
+
};
|
|
85
|
+
updateDraftRange(locked);
|
|
86
|
+
syncInputsFromDraft(locked);
|
|
87
|
+
} else {
|
|
88
|
+
updateDraftRange(nextDraft);
|
|
89
|
+
syncInputsFromDraft(nextDraft);
|
|
90
|
+
}
|
|
91
|
+
}, [
|
|
92
|
+
lockEndToToday,
|
|
93
|
+
syncInputsFromDraft,
|
|
94
|
+
updateDraftRange
|
|
95
|
+
]);
|
|
96
|
+
const handleApply = () => {
|
|
97
|
+
if (draftRange.startDate && draftRange.endDate) {
|
|
98
|
+
onChange?.({
|
|
99
|
+
startDate: draftRange.startDate,
|
|
100
|
+
endDate: draftRange.endDate
|
|
101
|
+
});
|
|
102
|
+
handleOpenChange(false);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const openCalendarPanel = () => {
|
|
106
|
+
if (!showCalendar) {
|
|
107
|
+
setShowCalendar(true);
|
|
108
|
+
const initial = {
|
|
109
|
+
startDate: selectedStartDate ?? null,
|
|
110
|
+
endDate: selectedStartDate ? lockEndToToday ? endOfDay(/* @__PURE__ */ new Date()) : selectedEndDate ?? null : null
|
|
111
|
+
};
|
|
112
|
+
updateDraftRange(initial);
|
|
113
|
+
syncInputsFromDraft(initial);
|
|
114
|
+
setCalendarMonth(initial.startDate ?? /* @__PURE__ */ new Date());
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const handleStartInputChange = (e) => {
|
|
118
|
+
const val = e.target.value;
|
|
119
|
+
setStartInputValue(val);
|
|
120
|
+
const parsed = parseDateOrNull(val, dateFormat);
|
|
121
|
+
updateDraftRange({
|
|
122
|
+
startDate: parsed,
|
|
123
|
+
endDate: lockEndToToday ? endOfDay(/* @__PURE__ */ new Date()) : draftRange.endDate
|
|
124
|
+
});
|
|
125
|
+
if (parsed) setCalendarMonth(parsed);
|
|
126
|
+
};
|
|
127
|
+
const handleStartInputBlur = () => {
|
|
128
|
+
setStartInputValue(draftRange.startDate ? format(draftRange.startDate, dateFormat) : "");
|
|
129
|
+
};
|
|
130
|
+
const handleEndInputChange = (e) => {
|
|
131
|
+
if (lockEndToToday) return;
|
|
132
|
+
const val = e.target.value;
|
|
133
|
+
setEndInputValue(val);
|
|
134
|
+
const parsed = parseDateOrNull(val, dateFormat);
|
|
135
|
+
updateDraftRange({
|
|
136
|
+
startDate: draftRange.startDate,
|
|
137
|
+
endDate: parsed
|
|
138
|
+
});
|
|
139
|
+
if (parsed) setCalendarMonth(parsed);
|
|
140
|
+
};
|
|
141
|
+
const handleEndInputBlur = () => {
|
|
142
|
+
if (lockEndToToday) return;
|
|
143
|
+
setEndInputValue(draftRange.endDate ? format(draftRange.endDate, dateFormat) : "");
|
|
144
|
+
};
|
|
145
|
+
const handleClear = () => {
|
|
146
|
+
onClear?.();
|
|
147
|
+
handleOpenChange(false);
|
|
148
|
+
};
|
|
149
|
+
const displayValue = selectedPresetId ? resolveLabel(selectedPresetId) : "";
|
|
150
|
+
const hasSelection = !!(selectedPresetId || selectedStartDate);
|
|
151
|
+
const inputTrigger = /* @__PURE__ */ jsx(Input, {
|
|
152
|
+
readOnly: true,
|
|
153
|
+
value: displayValue,
|
|
154
|
+
placeholder,
|
|
155
|
+
label,
|
|
156
|
+
size,
|
|
157
|
+
disabled,
|
|
158
|
+
required,
|
|
159
|
+
rounded,
|
|
160
|
+
error,
|
|
161
|
+
errorContent,
|
|
162
|
+
startHelperContent,
|
|
163
|
+
endHelperContent,
|
|
164
|
+
hintContent,
|
|
165
|
+
className: cn("cursor-pointer read-only:bg-background", !displayValue && "text-muted-foreground"),
|
|
166
|
+
endIcon: hideIcon ? void 0 : /* @__PURE__ */ jsx(CalendarRangeIcon, {
|
|
167
|
+
size: 16,
|
|
168
|
+
className: "text-muted-foreground"
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
const isRangeComplete = !!(draftRange.startDate && draftRange.endDate);
|
|
172
|
+
const isInline = calendarLayout === "inline";
|
|
173
|
+
const showPresetRows = !(allowCustom && showCalendar && isInline);
|
|
174
|
+
const cancelButton = /* @__PURE__ */ jsx(Button, {
|
|
175
|
+
variant: "ghost",
|
|
176
|
+
color: "error",
|
|
177
|
+
size: isInline ? void 0 : "sm",
|
|
178
|
+
onClick: () => handleOpenChange(false),
|
|
179
|
+
children: "Cancel"
|
|
180
|
+
});
|
|
181
|
+
const applyButton = /* @__PURE__ */ jsx(Button, {
|
|
182
|
+
variant: "outline",
|
|
183
|
+
color: "primary",
|
|
184
|
+
size: isInline ? void 0 : "sm",
|
|
185
|
+
disabled: !isRangeComplete,
|
|
186
|
+
onClick: handleApply,
|
|
187
|
+
children: "Apply"
|
|
188
|
+
});
|
|
189
|
+
const calendarBody = /* @__PURE__ */ jsxs("div", {
|
|
190
|
+
className: "flex flex-col h-full justify-between",
|
|
191
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
192
|
+
className: cn("p-1", isInline && "flex justify-center"),
|
|
193
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
194
|
+
mode: "range",
|
|
195
|
+
selected: toCalendarRange(draftRange),
|
|
196
|
+
onSelect: handleRangeChange,
|
|
197
|
+
month: calendarMonth,
|
|
198
|
+
onMonthChange: setCalendarMonth,
|
|
199
|
+
numberOfMonths: isInline ? 1 : 2,
|
|
200
|
+
showOutsideDays: true,
|
|
201
|
+
captionLayout: "dropdown",
|
|
202
|
+
disabled: lockEndToToday || disableFutureDates ? { after: /* @__PURE__ */ new Date() } : void 0
|
|
203
|
+
})
|
|
204
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
205
|
+
className: cn("p-3 flex items-end gap-4", isInline ? "flex-wrap justify-end gap-3" : "justify-between"),
|
|
206
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
207
|
+
className: cn(isInline ? "grid w-full grid-cols-2 gap-3" : "flex items-center gap-3"),
|
|
208
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
209
|
+
size: "sm",
|
|
210
|
+
label: "Start date",
|
|
211
|
+
value: startInputValue,
|
|
212
|
+
placeholder: dateFormat.toLowerCase(),
|
|
213
|
+
onChange: handleStartInputChange,
|
|
214
|
+
onBlur: handleStartInputBlur,
|
|
215
|
+
className: isInline ? "w-full min-w-0" : "w-32"
|
|
216
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
217
|
+
size: "sm",
|
|
218
|
+
label: "End date",
|
|
219
|
+
value: endInputValue,
|
|
220
|
+
placeholder: dateFormat.toLowerCase(),
|
|
221
|
+
onChange: handleEndInputChange,
|
|
222
|
+
onBlur: handleEndInputBlur,
|
|
223
|
+
disabled: lockEndToToday,
|
|
224
|
+
className: isInline ? "w-full min-w-0" : "w-32"
|
|
225
|
+
})]
|
|
226
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
227
|
+
className: cn("flex gap-2", isInline ? "w-full flex-col" : "h-full items-end"),
|
|
228
|
+
children: isInline ? /* @__PURE__ */ jsxs(Fragment$1, { children: [applyButton, cancelButton] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [cancelButton, applyButton] })
|
|
229
|
+
})]
|
|
230
|
+
})]
|
|
231
|
+
});
|
|
232
|
+
return /* @__PURE__ */ jsx("div", {
|
|
233
|
+
className: cn("flex-1", className),
|
|
234
|
+
children: /* @__PURE__ */ jsxs(Popover, {
|
|
235
|
+
open,
|
|
236
|
+
onOpenChange: handleOpenChange,
|
|
237
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
238
|
+
asChild: true,
|
|
239
|
+
disabled,
|
|
240
|
+
children: trigger ?? /* @__PURE__ */ jsx("button", {
|
|
241
|
+
type: "button",
|
|
242
|
+
disabled,
|
|
243
|
+
className: "w-full text-start",
|
|
244
|
+
children: inputTrigger
|
|
245
|
+
})
|
|
246
|
+
}), /* @__PURE__ */ jsxs(PopoverContent, {
|
|
247
|
+
align,
|
|
248
|
+
side,
|
|
249
|
+
collisionPadding: 16,
|
|
250
|
+
className: cn("w-auto min-w-[10rem] gap-0 p-0 relative", isInline ? "max-h-(--radix-popover-content-available-height) max-w-(--radix-popover-content-available-width) overflow-y-auto" : "overflow-visible", allowCustom && showCalendar && calendarLayout === "right" && "rounded-r-none", allowCustom && showCalendar && calendarLayout === "left" && "rounded-l-none"),
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ jsxs("div", {
|
|
253
|
+
className: "flex max-h-[min(24rem,calc(100vh-6rem))] min-w-[10rem] flex-col overflow-y-auto py-1.5",
|
|
254
|
+
children: [
|
|
255
|
+
showPresetRows && activePresets.map((id) => /* @__PURE__ */ jsxs("button", {
|
|
256
|
+
type: "button",
|
|
257
|
+
onClick: () => handlePresetClick(id),
|
|
258
|
+
onMouseEnter: () => setShowCalendar(false),
|
|
259
|
+
className: cn("flex w-full items-center justify-between gap-6 px-3 py-1.5 text-left text-sm hover:bg-accent", selectedPresetId === id && "font-medium"),
|
|
260
|
+
children: [resolveLabel(id), selectedPresetId === id && /* @__PURE__ */ jsx(CheckIcon, { className: "size-4 shrink-0 text-primary" })]
|
|
261
|
+
}, id)),
|
|
262
|
+
allowCustom && /* @__PURE__ */ jsxs(Fragment$1, { children: [showPresetRows && /* @__PURE__ */ jsx("div", { className: "mx-1 my-1 h-px bg-border" }), /* @__PURE__ */ jsxs("button", {
|
|
263
|
+
type: "button",
|
|
264
|
+
onClick: () => {
|
|
265
|
+
if (showCalendar) {
|
|
266
|
+
setShowCalendar(false);
|
|
267
|
+
updateDraftRange(EMPTY_DRAFT_RANGE);
|
|
268
|
+
} else openCalendarPanel();
|
|
269
|
+
},
|
|
270
|
+
onPointerEnter: (event) => {
|
|
271
|
+
if (event.pointerType === "mouse") openCalendarPanel();
|
|
272
|
+
},
|
|
273
|
+
className: cn("flex w-full items-center justify-between gap-6 px-3 py-1.5 text-left text-sm hover:bg-accent", showCalendar && "bg-accent font-medium"),
|
|
274
|
+
children: [resolveLabel("custom"), /* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-4 shrink-0 text-muted-foreground transition-transform duration-200", showCalendar && "rotate-90") })]
|
|
275
|
+
})] }),
|
|
276
|
+
showPresetRows && clearable && hasSelection && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", { className: "mx-1 my-1 h-px bg-border" }), /* @__PURE__ */ jsxs("button", {
|
|
277
|
+
type: "button",
|
|
278
|
+
onClick: handleClear,
|
|
279
|
+
onMouseEnter: () => setShowCalendar(false),
|
|
280
|
+
className: "flex w-full items-center justify-between gap-6 px-3 py-1.5 text-left text-sm text-muted-foreground hover:bg-accent",
|
|
281
|
+
children: [clearLabel, /* @__PURE__ */ jsx(XIcon, { className: "size-4 shrink-0" })]
|
|
282
|
+
})] })
|
|
283
|
+
]
|
|
284
|
+
}),
|
|
285
|
+
allowCustom && showCalendar && isInline && /* @__PURE__ */ jsx("div", {
|
|
286
|
+
className: "border-t",
|
|
287
|
+
children: calendarBody
|
|
288
|
+
}),
|
|
289
|
+
allowCustom && showCalendar && !isInline && /* @__PURE__ */ jsx("div", {
|
|
290
|
+
ref: calendarRef,
|
|
291
|
+
className: cn("absolute top-0 border bg-popover text-popover-foreground shadow-lg", calendarLayout === "right" ? "left-full -ml-px rounded-r-2xl border-l" : "right-full -mr-px rounded-l-2xl border-r"),
|
|
292
|
+
children: calendarBody
|
|
293
|
+
})
|
|
294
|
+
]
|
|
295
|
+
})]
|
|
296
|
+
})
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
DateRangePicker.displayName = "DateRangePicker";
|
|
300
|
+
//#endregion
|
|
301
|
+
export { DateRangePicker };
|