@slipstream-ui/core 0.7.0 → 0.9.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/dist/index.d.mts +317 -21
- package/dist/index.d.ts +317 -21
- package/dist/index.js +2004 -1069
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1998 -1068
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +8 -2
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +19 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +13 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +130 -0
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/calendar.manifest.json +175 -0
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +8 -1
- package/dist/manifests/date-picker-popover.manifest.json +202 -0
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +48 -2
- package/dist/manifests/empty-state.manifest.json +1 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +1 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/image.manifest.json +142 -0
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +36 -4
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +7 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +86 -4
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +1 -1
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +1 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +13 -3
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +1 -1
- package/dist/manifests/stepper.manifest.json +7 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +1 -1
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +1 -1
- package/dist/src/components/accordion/Accordion.d.ts +17 -1
- package/dist/src/components/accordion/Accordion.js +5 -1
- package/dist/src/components/accordion/Accordion.js.map +1 -1
- package/dist/src/components/accordion/Accordion.mjs +5 -1
- package/dist/src/components/accordion/Accordion.mjs.map +1 -1
- package/dist/src/components/alert/Alert.js +1 -1
- package/dist/src/components/alert/Alert.js.map +1 -1
- package/dist/src/components/alert/Alert.mjs +1 -1
- package/dist/src/components/alert/Alert.mjs.map +1 -1
- package/dist/src/components/app-shell/AppShell.js +1 -1
- package/dist/src/components/app-shell/AppShell.js.map +1 -1
- package/dist/src/components/app-shell/AppShell.mjs +1 -1
- package/dist/src/components/app-shell/AppShell.mjs.map +1 -1
- package/dist/src/components/article-card/ArticleCard.js +2 -2
- package/dist/src/components/article-card/ArticleCard.js.map +1 -1
- package/dist/src/components/article-card/ArticleCard.mjs +2 -2
- package/dist/src/components/article-card/ArticleCard.mjs.map +1 -1
- package/dist/src/components/auth-layout/AuthLayout.d.ts +14 -2
- package/dist/src/components/auth-layout/AuthLayout.js +10 -2
- package/dist/src/components/auth-layout/AuthLayout.js.map +1 -1
- package/dist/src/components/auth-layout/AuthLayout.mjs +10 -2
- package/dist/src/components/auth-layout/AuthLayout.mjs.map +1 -1
- package/dist/src/components/badge/Badge.d.ts +2 -0
- package/dist/src/components/badge/Badge.js +9 -3
- package/dist/src/components/badge/Badge.js.map +1 -1
- package/dist/src/components/badge/Badge.mjs +9 -3
- package/dist/src/components/badge/Badge.mjs.map +1 -1
- package/dist/src/components/bottom-nav/BottomNav.d.ts +36 -0
- package/dist/src/components/bottom-nav/BottomNav.js +90 -0
- package/dist/src/components/bottom-nav/BottomNav.js.map +1 -0
- package/dist/src/components/bottom-nav/BottomNav.mjs +66 -0
- package/dist/src/components/bottom-nav/BottomNav.mjs.map +1 -0
- package/dist/src/components/bottom-nav/index.d.ts +1 -0
- package/dist/src/components/bottom-nav/index.js +23 -0
- package/dist/src/components/bottom-nav/index.js.map +1 -0
- package/dist/src/components/bottom-nav/index.mjs +2 -0
- package/dist/src/components/bottom-nav/index.mjs.map +1 -0
- package/dist/src/components/calendar/Calendar.d.ts +34 -0
- package/dist/src/components/calendar/Calendar.js +233 -0
- package/dist/src/components/calendar/Calendar.js.map +1 -0
- package/dist/src/components/calendar/Calendar.mjs +208 -0
- package/dist/src/components/calendar/Calendar.mjs.map +1 -0
- package/dist/src/components/calendar/index.d.ts +1 -0
- package/dist/src/components/calendar/index.js +23 -0
- package/dist/src/components/calendar/index.js.map +1 -0
- package/dist/src/components/calendar/index.mjs +2 -0
- package/dist/src/components/calendar/index.mjs.map +1 -0
- package/dist/src/components/comparison-table/ComparisonTable.js +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.js.map +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.mjs +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.mjs.map +1 -1
- package/dist/src/components/cta-section/CTASection.js +1 -1
- package/dist/src/components/cta-section/CTASection.js.map +1 -1
- package/dist/src/components/cta-section/CTASection.mjs +1 -1
- package/dist/src/components/cta-section/CTASection.mjs.map +1 -1
- package/dist/src/components/data-table/DataTable.d.ts +3 -1
- package/dist/src/components/data-table/DataTable.js +2 -4
- package/dist/src/components/data-table/DataTable.js.map +1 -1
- package/dist/src/components/data-table/DataTable.mjs +2 -4
- package/dist/src/components/data-table/DataTable.mjs.map +1 -1
- package/dist/src/components/date-picker-popover/DatePickerPopover.d.ts +33 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.js +117 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.js.map +1 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.mjs +83 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.mjs.map +1 -0
- package/dist/src/components/date-picker-popover/index.d.ts +1 -0
- package/dist/src/components/date-picker-popover/index.js +23 -0
- package/dist/src/components/date-picker-popover/index.js.map +1 -0
- package/dist/src/components/date-picker-popover/index.mjs +2 -0
- package/dist/src/components/date-picker-popover/index.mjs.map +1 -0
- package/dist/src/components/drawer/Drawer.d.ts +25 -2
- package/dist/src/components/drawer/Drawer.js +97 -6
- package/dist/src/components/drawer/Drawer.js.map +1 -1
- package/dist/src/components/drawer/Drawer.mjs +97 -6
- package/dist/src/components/drawer/Drawer.mjs.map +1 -1
- package/dist/src/components/empty-state/EmptyState.d.ts +13 -4
- package/dist/src/components/empty-state/EmptyState.js +13 -1
- package/dist/src/components/empty-state/EmptyState.js.map +1 -1
- package/dist/src/components/empty-state/EmptyState.mjs +13 -1
- package/dist/src/components/empty-state/EmptyState.mjs.map +1 -1
- package/dist/src/components/image/Image.d.ts +34 -0
- package/dist/src/components/image/Image.js +75 -0
- package/dist/src/components/image/Image.js.map +1 -0
- package/dist/src/components/image/Image.mjs +41 -0
- package/dist/src/components/image/Image.mjs.map +1 -0
- package/dist/src/components/image/index.d.ts +1 -0
- package/dist/src/components/image/index.js +29 -0
- package/dist/src/components/image/index.js.map +1 -0
- package/dist/src/components/image/index.mjs +5 -0
- package/dist/src/components/image/index.mjs.map +1 -0
- package/dist/src/components/link/Link.js +4 -4
- package/dist/src/components/link/Link.js.map +1 -1
- package/dist/src/components/link/Link.mjs +4 -4
- package/dist/src/components/link/Link.mjs.map +1 -1
- package/dist/src/components/metric-card/MetricCard.d.ts +23 -4
- package/dist/src/components/metric-card/MetricCard.js +32 -5
- package/dist/src/components/metric-card/MetricCard.js.map +1 -1
- package/dist/src/components/metric-card/MetricCard.mjs +32 -5
- package/dist/src/components/metric-card/MetricCard.mjs.map +1 -1
- package/dist/src/components/page-header/PageHeader.d.ts +4 -0
- package/dist/src/components/page-header/PageHeader.js +4 -3
- package/dist/src/components/page-header/PageHeader.js.map +1 -1
- package/dist/src/components/page-header/PageHeader.mjs +4 -3
- package/dist/src/components/page-header/PageHeader.mjs.map +1 -1
- package/dist/src/components/popover/Popover.d.ts +36 -3
- package/dist/src/components/popover/Popover.js +118 -22
- package/dist/src/components/popover/Popover.js.map +1 -1
- package/dist/src/components/popover/Popover.mjs +117 -22
- package/dist/src/components/popover/Popover.mjs.map +1 -1
- package/dist/src/components/section-heading/SectionHeading.js +1 -1
- package/dist/src/components/section-heading/SectionHeading.js.map +1 -1
- package/dist/src/components/section-heading/SectionHeading.mjs +1 -1
- package/dist/src/components/section-heading/SectionHeading.mjs.map +1 -1
- package/dist/src/components/separator/Separator.d.ts +3 -3
- package/dist/src/components/site-header/SiteHeader.d.ts +25 -3
- package/dist/src/components/site-header/SiteHeader.js +141 -6
- package/dist/src/components/site-header/SiteHeader.js.map +1 -1
- package/dist/src/components/site-header/SiteHeader.mjs +141 -6
- package/dist/src/components/site-header/SiteHeader.mjs.map +1 -1
- package/dist/src/components/stepper/Stepper.d.ts +18 -0
- package/dist/src/components/stepper/Stepper.js +2 -1
- package/dist/src/components/stepper/Stepper.js.map +1 -1
- package/dist/src/components/stepper/Stepper.mjs +2 -1
- package/dist/src/components/stepper/Stepper.mjs.map +1 -1
- package/dist/src/index.d.ts +4 -0
- package/dist/src/utils/date.d.ts +32 -0
- package/dist/src/utils/date.js +171 -0
- package/dist/src/utils/date.js.map +1 -0
- package/dist/src/utils/date.mjs +134 -0
- package/dist/src/utils/date.mjs.map +1 -0
- package/dist/src/utils/position.d.ts +42 -0
- package/dist/src/utils/position.js +91 -0
- package/dist/src/utils/position.js.map +1 -0
- package/dist/src/utils/position.mjs +67 -0
- package/dist/src/utils/position.mjs.map +1 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -3
- package/src/components/accordion/Accordion.test.tsx +31 -0
- package/src/components/accordion/Accordion.tsx +27 -2
- package/src/components/alert/Alert.tsx +1 -1
- package/src/components/app-shell/AppShell.tsx +1 -1
- package/src/components/article-card/ArticleCard.tsx +2 -2
- package/src/components/auth-layout/AuthLayout.test.tsx +36 -0
- package/src/components/auth-layout/AuthLayout.tsx +20 -3
- package/src/components/badge/Badge.test.tsx +7 -0
- package/src/components/badge/Badge.tsx +8 -2
- package/src/components/bottom-nav/BottomNav.test.tsx +48 -0
- package/src/components/bottom-nav/BottomNav.tsx +117 -0
- package/src/components/bottom-nav/index.ts +1 -0
- package/src/components/calendar/Calendar.test.tsx +277 -0
- package/src/components/calendar/Calendar.tsx +273 -0
- package/src/components/calendar/index.ts +1 -0
- package/src/components/comparison-table/ComparisonTable.tsx +1 -1
- package/src/components/cta-section/CTASection.tsx +1 -1
- package/src/components/data-table/DataTable.test.tsx +21 -0
- package/src/components/data-table/DataTable.tsx +4 -1
- package/src/components/date-picker-popover/DatePickerPopover.test.tsx +223 -0
- package/src/components/date-picker-popover/DatePickerPopover.tsx +117 -0
- package/src/components/date-picker-popover/index.ts +1 -0
- package/src/components/drawer/Drawer.test.tsx +86 -1
- package/src/components/drawer/Drawer.tsx +135 -7
- package/src/components/empty-state/EmptyState.test.tsx +26 -1
- package/src/components/empty-state/EmptyState.tsx +40 -3
- package/src/components/image/Image.test.tsx +94 -0
- package/src/components/image/Image.tsx +71 -0
- package/src/components/image/index.ts +1 -0
- package/src/components/link/Link.test.tsx +2 -1
- package/src/components/link/Link.tsx +4 -4
- package/src/components/metric-card/MetricCard.test.tsx +32 -0
- package/src/components/metric-card/MetricCard.tsx +45 -7
- package/src/components/page-header/PageHeader.test.tsx +13 -0
- package/src/components/page-header/PageHeader.tsx +6 -3
- package/src/components/popover/Popover.test.tsx +307 -3
- package/src/components/popover/Popover.tsx +228 -91
- package/src/components/section-heading/SectionHeading.tsx +1 -1
- package/src/components/site-header/SiteHeader.test.tsx +103 -1
- package/src/components/site-header/SiteHeader.tsx +220 -16
- package/src/components/stepper/Stepper.test.tsx +12 -0
- package/src/components/stepper/Stepper.tsx +15 -1
- package/src/index.ts +4 -0
- package/src/manifests/accordion.manifest.json +8 -2
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +19 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +13 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +130 -0
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/calendar.manifest.json +175 -0
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +8 -1
- package/src/manifests/date-picker-popover.manifest.json +202 -0
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +48 -2
- package/src/manifests/empty-state.manifest.json +1 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +1 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/image.manifest.json +142 -0
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +36 -4
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +7 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +86 -4
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +1 -1
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +1 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +13 -3
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +1 -1
- package/src/manifests/stepper.manifest.json +7 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +1 -1
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +1 -1
- package/src/utils/date.test.ts +190 -0
- package/src/utils/date.ts +162 -0
- package/src/utils/position.test.ts +227 -0
- package/src/utils/position.ts +129 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from '../../utils/cn';
|
|
5
|
+
import {
|
|
6
|
+
addMonths,
|
|
7
|
+
calendarWeeks,
|
|
8
|
+
formatDateLabel,
|
|
9
|
+
monthLabel,
|
|
10
|
+
moveDateKey,
|
|
11
|
+
parseDateKey,
|
|
12
|
+
todayKey,
|
|
13
|
+
weekdayLabels,
|
|
14
|
+
type CalendarMove,
|
|
15
|
+
} from '../../utils/date';
|
|
16
|
+
import { Button } from '../button';
|
|
17
|
+
|
|
18
|
+
export type CalendarProps = {
|
|
19
|
+
/** Controlled ISO date key (`YYYY-MM-DD`). */
|
|
20
|
+
value?: string;
|
|
21
|
+
/** Uncontrolled initial date key. */
|
|
22
|
+
defaultValue?: string;
|
|
23
|
+
/** Called with the ISO key when a day is chosen. */
|
|
24
|
+
onValueChange?: (value: string) => void;
|
|
25
|
+
/** Earliest selectable day, inclusive. */
|
|
26
|
+
min?: string;
|
|
27
|
+
/** Latest selectable day, inclusive. */
|
|
28
|
+
max?: string;
|
|
29
|
+
/** Override "today" (testing and server-rendered determinism). */
|
|
30
|
+
today?: string;
|
|
31
|
+
/** BCP-47 locale for month and weekday labels. */
|
|
32
|
+
locale?: string;
|
|
33
|
+
/** 0 starts the week on Sunday, 1 on Monday. */
|
|
34
|
+
weekStartsOn?: 0 | 1;
|
|
35
|
+
/** Block individual days beyond min/max. */
|
|
36
|
+
isDateDisabled?: (value: string) => boolean;
|
|
37
|
+
/** Show leading/trailing days from the neighbouring months. */
|
|
38
|
+
showOutsideDays?: boolean;
|
|
39
|
+
/** Focus the active day when the calendar mounts or opens. */
|
|
40
|
+
autoFocus?: boolean;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
className?: string;
|
|
43
|
+
'aria-label'?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const MOVES: Record<string, CalendarMove> = {
|
|
47
|
+
ArrowLeft: 'left',
|
|
48
|
+
ArrowRight: 'right',
|
|
49
|
+
ArrowUp: 'up',
|
|
50
|
+
ArrowDown: 'down',
|
|
51
|
+
Home: 'home',
|
|
52
|
+
End: 'end',
|
|
53
|
+
PageUp: 'pageup',
|
|
54
|
+
PageDown: 'pagedown',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Month grid with ISO date keys and full keyboard support. Controlled via
|
|
59
|
+
* `value`/`onValueChange`, or uncontrolled with `defaultValue`.
|
|
60
|
+
*/
|
|
61
|
+
const Calendar = React.forwardRef<HTMLDivElement, CalendarProps>(
|
|
62
|
+
(
|
|
63
|
+
{
|
|
64
|
+
value,
|
|
65
|
+
defaultValue,
|
|
66
|
+
onValueChange,
|
|
67
|
+
min,
|
|
68
|
+
max,
|
|
69
|
+
today,
|
|
70
|
+
locale = 'en-US',
|
|
71
|
+
weekStartsOn = 0,
|
|
72
|
+
isDateDisabled,
|
|
73
|
+
showOutsideDays = true,
|
|
74
|
+
autoFocus = false,
|
|
75
|
+
disabled = false,
|
|
76
|
+
className,
|
|
77
|
+
'aria-label': ariaLabel,
|
|
78
|
+
...props
|
|
79
|
+
},
|
|
80
|
+
ref
|
|
81
|
+
) => {
|
|
82
|
+
const resolvedToday = today ?? todayKey();
|
|
83
|
+
const [internal, setInternal] = React.useState(defaultValue ?? '');
|
|
84
|
+
const selected = value ?? internal;
|
|
85
|
+
const initial = selected || resolvedToday;
|
|
86
|
+
const [view, setView] = React.useState(() => {
|
|
87
|
+
const parts = parseDateKey(initial);
|
|
88
|
+
return { year: parts?.year ?? 1970, month: parts?.month ?? 0 };
|
|
89
|
+
});
|
|
90
|
+
const [focusKey, setFocusKey] = React.useState(initial);
|
|
91
|
+
const gridRef = React.useRef<HTMLDivElement | null>(null);
|
|
92
|
+
const keyboardNav = React.useRef(false);
|
|
93
|
+
|
|
94
|
+
// Follow an externally controlled value into its month.
|
|
95
|
+
React.useEffect(() => {
|
|
96
|
+
if (!selected) return;
|
|
97
|
+
const parts = parseDateKey(selected);
|
|
98
|
+
if (parts) setView({ year: parts.year, month: parts.month });
|
|
99
|
+
setFocusKey(selected);
|
|
100
|
+
}, [selected]);
|
|
101
|
+
|
|
102
|
+
const weeks = React.useMemo(
|
|
103
|
+
() => calendarWeeks(view.year, view.month, weekStartsOn),
|
|
104
|
+
[view.year, view.month, weekStartsOn]
|
|
105
|
+
);
|
|
106
|
+
const weekdays = React.useMemo(
|
|
107
|
+
() => weekdayLabels(locale, weekStartsOn),
|
|
108
|
+
[locale, weekStartsOn]
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const blocked = React.useCallback(
|
|
112
|
+
(key: string) =>
|
|
113
|
+
disabled ||
|
|
114
|
+
Boolean((min && key < min) || (max && key > max)) ||
|
|
115
|
+
Boolean(isDateDisabled?.(key)),
|
|
116
|
+
[disabled, isDateDisabled, max, min]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const choose = (key: string) => {
|
|
120
|
+
if (blocked(key)) return;
|
|
121
|
+
if (value === undefined) setInternal(key);
|
|
122
|
+
setFocusKey(key);
|
|
123
|
+
onValueChange?.(key);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const onGridKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
127
|
+
const move = MOVES[event.key];
|
|
128
|
+
if (!move) return;
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
const next = moveDateKey(focusKey, move, weekStartsOn);
|
|
131
|
+
const parts = parseDateKey(next);
|
|
132
|
+
if (parts) setView({ year: parts.year, month: parts.month });
|
|
133
|
+
setFocusKey(next);
|
|
134
|
+
keyboardNav.current = true;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Roving tabindex only means something if the caret moves with it: after a
|
|
138
|
+
// keyboard move, focus the day that owns the tab stop in the new view.
|
|
139
|
+
React.useEffect(() => {
|
|
140
|
+
if (!keyboardNav.current) return;
|
|
141
|
+
const target = gridRef.current?.querySelector<HTMLButtonElement>(`[data-date="${focusKey}"]`);
|
|
142
|
+
keyboardNav.current = false;
|
|
143
|
+
target?.focus();
|
|
144
|
+
}, [focusKey, view.year, view.month]);
|
|
145
|
+
|
|
146
|
+
// Keep one tabbable day: the active one when visible, otherwise the first.
|
|
147
|
+
const visibleKeys = weeks.flat().filter((day) => day.inMonth);
|
|
148
|
+
const tabbable = visibleKeys.some((day) => day.key === focusKey)
|
|
149
|
+
? focusKey
|
|
150
|
+
: (visibleKeys[0]?.key ?? '');
|
|
151
|
+
|
|
152
|
+
React.useEffect(() => {
|
|
153
|
+
if (!autoFocus) return;
|
|
154
|
+
const timer = setTimeout(() => {
|
|
155
|
+
gridRef.current
|
|
156
|
+
?.querySelector<HTMLButtonElement>(`[data-date="${tabbable}"]`)
|
|
157
|
+
?.focus();
|
|
158
|
+
}, 0);
|
|
159
|
+
return () => clearTimeout(timer);
|
|
160
|
+
}, [autoFocus, tabbable, view.year, view.month]);
|
|
161
|
+
|
|
162
|
+
const monthName = monthLabel(view.year, view.month, locale);
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div
|
|
166
|
+
ref={ref}
|
|
167
|
+
className={cn('w-72 select-none', className)}
|
|
168
|
+
data-disabled={disabled ? '' : undefined}
|
|
169
|
+
{...props}
|
|
170
|
+
>
|
|
171
|
+
<div className="mb-2 flex items-center justify-between gap-2">
|
|
172
|
+
<Button
|
|
173
|
+
type="button"
|
|
174
|
+
variant="ghost"
|
|
175
|
+
size="icon"
|
|
176
|
+
aria-label="Previous month"
|
|
177
|
+
disabled={disabled}
|
|
178
|
+
onClick={() => setView(partsOf(addMonths(keyOf(view), -1)))}
|
|
179
|
+
>
|
|
180
|
+
‹
|
|
181
|
+
</Button>
|
|
182
|
+
<div aria-live="polite" className="text-sm font-semibold text-foreground">
|
|
183
|
+
{monthName}
|
|
184
|
+
</div>
|
|
185
|
+
<Button
|
|
186
|
+
type="button"
|
|
187
|
+
variant="ghost"
|
|
188
|
+
size="icon"
|
|
189
|
+
aria-label="Next month"
|
|
190
|
+
disabled={disabled}
|
|
191
|
+
onClick={() => setView(partsOf(addMonths(keyOf(view), 1)))}
|
|
192
|
+
>
|
|
193
|
+
›
|
|
194
|
+
</Button>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div
|
|
198
|
+
ref={gridRef}
|
|
199
|
+
role="grid"
|
|
200
|
+
aria-label={ariaLabel ?? monthName}
|
|
201
|
+
onKeyDown={onGridKeyDown}
|
|
202
|
+
className="flex flex-col gap-1"
|
|
203
|
+
>
|
|
204
|
+
<div role="row" className="grid grid-cols-7 gap-1 text-center text-xs text-muted-foreground">
|
|
205
|
+
{weekdays.map((weekday) => (
|
|
206
|
+
<span key={weekday} role="columnheader" aria-label={weekday} className="py-1">
|
|
207
|
+
{weekday}
|
|
208
|
+
</span>
|
|
209
|
+
))}
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
{weeks.map((week) => (
|
|
213
|
+
<div key={week[0]?.key} role="row" className="grid grid-cols-7 gap-1">
|
|
214
|
+
{week.map((day) => {
|
|
215
|
+
const isSelected = day.key === selected;
|
|
216
|
+
const isToday = day.key === resolvedToday;
|
|
217
|
+
const isBlocked = blocked(day.key);
|
|
218
|
+
const hidden = !day.inMonth && !showOutsideDays;
|
|
219
|
+
|
|
220
|
+
if (hidden) {
|
|
221
|
+
return (
|
|
222
|
+
<div key={day.key} role="gridcell" aria-hidden="true" className="h-9 w-9" />
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<div
|
|
228
|
+
key={day.key}
|
|
229
|
+
role="gridcell"
|
|
230
|
+
aria-selected={isSelected}
|
|
231
|
+
className="flex justify-center"
|
|
232
|
+
>
|
|
233
|
+
<Button
|
|
234
|
+
type="button"
|
|
235
|
+
size="sm"
|
|
236
|
+
variant={isSelected ? 'primary' : 'ghost'}
|
|
237
|
+
data-date={day.key}
|
|
238
|
+
tabIndex={day.key === tabbable ? 0 : -1}
|
|
239
|
+
aria-current={isToday ? 'date' : undefined}
|
|
240
|
+
aria-disabled={isBlocked || undefined}
|
|
241
|
+
aria-label={formatDateLabel(day.key, locale)}
|
|
242
|
+
className={cn(
|
|
243
|
+
'h-9 w-9 p-0 font-normal',
|
|
244
|
+
!day.inMonth && 'text-muted-foreground/80',
|
|
245
|
+
isBlocked && 'cursor-not-allowed opacity-40',
|
|
246
|
+
isToday && !isSelected && 'ring-1 ring-primary'
|
|
247
|
+
)}
|
|
248
|
+
onClick={() => choose(day.key)}
|
|
249
|
+
>
|
|
250
|
+
{day.day}
|
|
251
|
+
</Button>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
})}
|
|
255
|
+
</div>
|
|
256
|
+
))}
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
Calendar.displayName = 'Calendar';
|
|
263
|
+
|
|
264
|
+
function keyOf(view: { year: number; month: number }): string {
|
|
265
|
+
return `${view.year}-${String(view.month + 1).padStart(2, '0')}-01`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function partsOf(key: string): { year: number; month: number } {
|
|
269
|
+
const parts = parseDateKey(key);
|
|
270
|
+
return { year: parts?.year ?? 1970, month: parts?.month ?? 0 };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export { Calendar };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Calendar';
|
|
@@ -99,7 +99,7 @@ export const ComparisonTable = React.forwardRef<HTMLTableElement, ComparisonTabl
|
|
|
99
99
|
scope="col"
|
|
100
100
|
className={cn(
|
|
101
101
|
'min-w-40 px-5 py-4 text-center font-semibold',
|
|
102
|
-
column.highlight && 'bg-primary/10 text-primary'
|
|
102
|
+
column.highlight && 'bg-primary/10 text-primary-ink'
|
|
103
103
|
)}
|
|
104
104
|
>
|
|
105
105
|
{column.label}
|
|
@@ -67,7 +67,7 @@ export const CTASection = React.forwardRef<HTMLElement, CTASectionProps>(functio
|
|
|
67
67
|
)}
|
|
68
68
|
>
|
|
69
69
|
{eyebrow && (
|
|
70
|
-
<p className="text-xs font-semibold uppercase tracking-widest text-primary">{eyebrow}</p>
|
|
70
|
+
<p className="text-xs font-semibold uppercase tracking-widest text-primary-ink">{eyebrow}</p>
|
|
71
71
|
)}
|
|
72
72
|
<h2 className="max-w-3xl text-3xl font-semibold tracking-tight text-balance sm:text-4xl">
|
|
73
73
|
{title}
|
|
@@ -194,6 +194,27 @@ describe('DataTable selection', () => {
|
|
|
194
194
|
expect(onSelectedRowIdsChange).toHaveBeenCalledWith(['2', '1', '3']);
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
+
it('localizes the selection summary with selectedLabel', () => {
|
|
198
|
+
render(
|
|
199
|
+
<DataTable
|
|
200
|
+
columns={[
|
|
201
|
+
{ key: 'name', header: 'Name' },
|
|
202
|
+
{ key: 'role', header: 'Role' },
|
|
203
|
+
]}
|
|
204
|
+
data={[
|
|
205
|
+
{ id: '1', name: 'Ada', role: 'Admin' },
|
|
206
|
+
{ id: '2', name: 'Grace', role: 'Engineer' },
|
|
207
|
+
]}
|
|
208
|
+
rowId={(row) => row.id}
|
|
209
|
+
selectedRowIds={['1', '2']}
|
|
210
|
+
onSelectedRowIdsChange={() => undefined}
|
|
211
|
+
bulkActions={<button type="button">Archive</button>}
|
|
212
|
+
selectedLabel="{count} seleccionados"
|
|
213
|
+
/>
|
|
214
|
+
);
|
|
215
|
+
expect(screen.getByText('2 seleccionados')).toBeInTheDocument();
|
|
216
|
+
});
|
|
217
|
+
|
|
197
218
|
it('respects isRowSelectable', () => {
|
|
198
219
|
render(
|
|
199
220
|
<DataTable
|
|
@@ -74,6 +74,8 @@ export type DataTableProps<T> = {
|
|
|
74
74
|
emptyMessage?: string;
|
|
75
75
|
/** Accessible label for the select-all checkbox (default "Select all rows"). */
|
|
76
76
|
selectAllLabel?: string;
|
|
77
|
+
/** Selection summary template above the table; `{count}` is replaced (default "{count} selected"). */
|
|
78
|
+
selectedLabel?: string;
|
|
77
79
|
/** Pin the header while the body scrolls (needs a max-height on the wrapper via className). */
|
|
78
80
|
stickyHeader?: boolean;
|
|
79
81
|
/** Compact row density. */
|
|
@@ -130,6 +132,7 @@ export function DataTable<T>({
|
|
|
130
132
|
onRowClick,
|
|
131
133
|
emptyMessage = 'No results.',
|
|
132
134
|
selectAllLabel = 'Select all rows',
|
|
135
|
+
selectedLabel = '{count} selected',
|
|
133
136
|
stickyHeader,
|
|
134
137
|
density = 'default',
|
|
135
138
|
zebra,
|
|
@@ -230,7 +233,7 @@ export function DataTable<T>({
|
|
|
230
233
|
<div className={cn('w-full space-y-3', className)}>
|
|
231
234
|
{selectionEnabled && selectedIds.length > 0 && bulkActions && (
|
|
232
235
|
<div className="flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-muted/40 px-3 py-2 text-sm">
|
|
233
|
-
<span className="font-medium">{selectedIds.length}
|
|
236
|
+
<span className="font-medium">{selectedLabel.replace('{count}', String(selectedIds.length))}</span>
|
|
234
237
|
<div className="flex flex-wrap items-center gap-2">{bulkActions}</div>
|
|
235
238
|
</div>
|
|
236
239
|
)}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { axe } from 'jest-axe';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { DatePickerPopover } from './DatePickerPopover';
|
|
6
|
+
|
|
7
|
+
const TODAY = '2026-11-13';
|
|
8
|
+
|
|
9
|
+
function setup(props: Partial<React.ComponentProps<typeof DatePickerPopover>> = {}) {
|
|
10
|
+
const onValueChange = vi.fn();
|
|
11
|
+
render(
|
|
12
|
+
<DatePickerPopover
|
|
13
|
+
value="2026-11-13"
|
|
14
|
+
today={TODAY}
|
|
15
|
+
onValueChange={onValueChange}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
return { onValueChange };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('DatePickerPopover', () => {
|
|
23
|
+
it('shows the formatted selected date', () => {
|
|
24
|
+
setup();
|
|
25
|
+
expect(screen.getByRole('button', { name: /Nov 13, 2026/ })).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('shows a placeholder when empty', () => {
|
|
29
|
+
render(<DatePickerPopover today={TODAY} onValueChange={() => {}} />);
|
|
30
|
+
expect(screen.getByRole('button', { name: 'Pick a date' })).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('opens a calendar panel and focuses the selected day', async () => {
|
|
34
|
+
const user = userEvent.setup();
|
|
35
|
+
setup();
|
|
36
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
37
|
+
|
|
38
|
+
expect(await screen.findByRole('grid', { name: 'November 2026' })).toBeInTheDocument();
|
|
39
|
+
await waitFor(() =>
|
|
40
|
+
expect(document.activeElement?.getAttribute('data-date')).toBe('2026-11-13')
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('chooses a day, closes and restores focus to the trigger', async () => {
|
|
45
|
+
const user = userEvent.setup();
|
|
46
|
+
const { onValueChange } = setup();
|
|
47
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
48
|
+
await screen.findByRole('grid');
|
|
49
|
+
|
|
50
|
+
await user.click(within(screen.getByRole('grid')).getByRole('button', { name: /Nov 20, 2026/ }));
|
|
51
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-20');
|
|
52
|
+
await waitFor(() => expect(screen.queryByRole('grid')).not.toBeInTheDocument());
|
|
53
|
+
expect(screen.getByRole('button', { name: /Nov 13, 2026/ })).toHaveFocus();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('selects with the keyboard', async () => {
|
|
57
|
+
const user = userEvent.setup();
|
|
58
|
+
const { onValueChange } = setup();
|
|
59
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
60
|
+
await screen.findByRole('grid');
|
|
61
|
+
await waitFor(() =>
|
|
62
|
+
expect(document.activeElement?.getAttribute('data-date')).toBe('2026-11-13')
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
await user.keyboard('{ArrowRight}');
|
|
66
|
+
await user.keyboard('{Enter}');
|
|
67
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-14');
|
|
68
|
+
await waitFor(() => expect(screen.queryByRole('grid')).not.toBeInTheDocument());
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('blocks days outside min and max', async () => {
|
|
72
|
+
const user = userEvent.setup();
|
|
73
|
+
const { onValueChange } = setup({ min: '2026-11-13', max: '2026-11-20' });
|
|
74
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
75
|
+
await screen.findByRole('grid');
|
|
76
|
+
|
|
77
|
+
const grid = within(screen.getByRole('grid'));
|
|
78
|
+
const early = grid.getByRole('button', { name: /Nov 10, 2026/ });
|
|
79
|
+
expect(early).toHaveAttribute('aria-disabled', 'true');
|
|
80
|
+
await user.click(early);
|
|
81
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
82
|
+
|
|
83
|
+
await user.click(grid.getByRole('button', { name: /Nov 18, 2026/ }));
|
|
84
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-18');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('closes on Escape', async () => {
|
|
88
|
+
const user = userEvent.setup();
|
|
89
|
+
setup();
|
|
90
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
91
|
+
await screen.findByRole('grid');
|
|
92
|
+
await user.keyboard('{Escape}');
|
|
93
|
+
await waitFor(() => expect(screen.queryByRole('grid')).not.toBeInTheDocument());
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('submits through a hidden input when named', () => {
|
|
97
|
+
const { container } = render(
|
|
98
|
+
<form>
|
|
99
|
+
<DatePickerPopover name="date" value="2026-11-13" today={TODAY} onValueChange={() => {}} />
|
|
100
|
+
</form>
|
|
101
|
+
);
|
|
102
|
+
const input = container.querySelector('input[name="date"]') as HTMLInputElement;
|
|
103
|
+
expect(input.value).toBe('2026-11-13');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('is not interactive when disabled', async () => {
|
|
107
|
+
const user = userEvent.setup();
|
|
108
|
+
setup({ disabled: true });
|
|
109
|
+
const trigger = screen.getByRole('button', { name: /Nov 13, 2026/ });
|
|
110
|
+
expect(trigger).toBeDisabled();
|
|
111
|
+
await user.click(trigger);
|
|
112
|
+
expect(screen.queryByRole('grid')).not.toBeInTheDocument();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('has no accessibility violations', async () => {
|
|
116
|
+
const user = userEvent.setup();
|
|
117
|
+
const { container } = render(
|
|
118
|
+
<DatePickerPopover today={TODAY} value="2026-11-13" onValueChange={() => {}} />
|
|
119
|
+
);
|
|
120
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
121
|
+
await screen.findByRole('grid');
|
|
122
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('DatePickerPopover field wiring', () => {
|
|
127
|
+
it('marks the hidden input required and keeps the ISO value', () => {
|
|
128
|
+
const { container } = render(
|
|
129
|
+
<form>
|
|
130
|
+
<DatePickerPopover
|
|
131
|
+
name="start"
|
|
132
|
+
required
|
|
133
|
+
value="2026-11-13"
|
|
134
|
+
today={TODAY}
|
|
135
|
+
onValueChange={() => {}}
|
|
136
|
+
/>
|
|
137
|
+
</form>
|
|
138
|
+
);
|
|
139
|
+
const input = container.querySelector('input[name="start"]') as HTMLInputElement;
|
|
140
|
+
expect(input.value).toBe('2026-11-13');
|
|
141
|
+
expect(input.required).toBe(true);
|
|
142
|
+
expect(input.type).toBe('hidden');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('renders no hidden input without a name', () => {
|
|
146
|
+
const { container } = render(
|
|
147
|
+
<DatePickerPopover value="2026-11-13" today={TODAY} onValueChange={() => {}} />
|
|
148
|
+
);
|
|
149
|
+
expect(container.querySelector('input[type="hidden"]')).toBeNull();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('passes id and aria-label through and labels the dialog', async () => {
|
|
153
|
+
const user = userEvent.setup();
|
|
154
|
+
render(
|
|
155
|
+
<DatePickerPopover
|
|
156
|
+
id="start-date"
|
|
157
|
+
aria-label="Start date"
|
|
158
|
+
value="2026-11-13"
|
|
159
|
+
today={TODAY}
|
|
160
|
+
onValueChange={() => {}}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
const trigger = screen.getByRole('button', { name: 'Start date' });
|
|
164
|
+
expect(trigger).toHaveAttribute('id', 'start-date');
|
|
165
|
+
|
|
166
|
+
await user.click(trigger);
|
|
167
|
+
const dialog = await screen.findByRole('dialog');
|
|
168
|
+
expect(dialog).toHaveAttribute('aria-labelledby', 'start-date');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('returns focus to the trigger on Escape', async () => {
|
|
172
|
+
const user = userEvent.setup();
|
|
173
|
+
setup();
|
|
174
|
+
const trigger = screen.getByRole('button', { name: /Nov 13, 2026/ });
|
|
175
|
+
await user.click(trigger);
|
|
176
|
+
await screen.findByRole('grid');
|
|
177
|
+
|
|
178
|
+
await user.keyboard('{Escape}');
|
|
179
|
+
await waitFor(() => expect(screen.queryByRole('grid')).not.toBeInTheDocument());
|
|
180
|
+
expect(trigger).toHaveFocus();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('honours the requested side', async () => {
|
|
184
|
+
const user = userEvent.setup();
|
|
185
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
|
|
186
|
+
this: HTMLElement
|
|
187
|
+
) {
|
|
188
|
+
const base = {
|
|
189
|
+
top: 0,
|
|
190
|
+
left: 0,
|
|
191
|
+
right: 0,
|
|
192
|
+
bottom: 0,
|
|
193
|
+
width: 0,
|
|
194
|
+
height: 0,
|
|
195
|
+
x: 0,
|
|
196
|
+
y: 0,
|
|
197
|
+
toJSON: () => ({}),
|
|
198
|
+
} as DOMRect;
|
|
199
|
+
if (this.getAttribute('role') === 'dialog') return { ...base, width: 288, height: 320 };
|
|
200
|
+
return { ...base, top: 500, left: 40, width: 240, height: 40 };
|
|
201
|
+
});
|
|
202
|
+
setup({ side: 'top' });
|
|
203
|
+
|
|
204
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
205
|
+
expect(await screen.findByRole('dialog')).toHaveAttribute('data-side', 'top');
|
|
206
|
+
vi.restoreAllMocks();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('treats min and max as inclusive', async () => {
|
|
210
|
+
const user = userEvent.setup();
|
|
211
|
+
const { onValueChange } = setup({ min: '2026-11-13', max: '2026-11-14' });
|
|
212
|
+
await user.click(screen.getByRole('button', { name: /Nov 13, 2026/ }));
|
|
213
|
+
const grid = within(await screen.findByRole('grid'));
|
|
214
|
+
|
|
215
|
+
expect(grid.getByRole('button', { name: /Nov 13, 2026/ })).not.toHaveAttribute(
|
|
216
|
+
'aria-disabled'
|
|
217
|
+
);
|
|
218
|
+
const last = grid.getByRole('button', { name: /Nov 14, 2026/ });
|
|
219
|
+
expect(last).not.toHaveAttribute('aria-disabled');
|
|
220
|
+
await user.click(last);
|
|
221
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-14');
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from '../../utils/cn';
|
|
5
|
+
import { formatDateLabel } from '../../utils/date';
|
|
6
|
+
import { buttonVariants } from '../button';
|
|
7
|
+
import { Calendar } from '../calendar';
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../popover';
|
|
9
|
+
|
|
10
|
+
export type DatePickerPopoverProps = {
|
|
11
|
+
/** Selected date as an ISO key (`YYYY-MM-DD`). */
|
|
12
|
+
value?: string;
|
|
13
|
+
/** Called with the ISO key when a day is chosen. */
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
/** Earliest selectable day, inclusive. */
|
|
16
|
+
min?: string;
|
|
17
|
+
/** Latest selectable day, inclusive. */
|
|
18
|
+
max?: string;
|
|
19
|
+
/** Override "today" for deterministic rendering. */
|
|
20
|
+
today?: string;
|
|
21
|
+
locale?: string;
|
|
22
|
+
weekStartsOn?: 0 | 1;
|
|
23
|
+
/** Text shown before a date is chosen. */
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Renders a hidden input so the value posts with a native form. */
|
|
26
|
+
name?: string;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/** Preferred side of the field; flips when it cannot fit. */
|
|
30
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
31
|
+
align?: 'start' | 'center' | 'end';
|
|
32
|
+
id?: string;
|
|
33
|
+
className?: string;
|
|
34
|
+
'aria-label'?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Date field with a month-grid panel. Values stay ISO `YYYY-MM-DD` strings, so
|
|
39
|
+
* a browser in a different zone cannot shift the chosen day.
|
|
40
|
+
*/
|
|
41
|
+
const DatePickerPopover = React.forwardRef<HTMLButtonElement, DatePickerPopoverProps>(
|
|
42
|
+
(
|
|
43
|
+
{
|
|
44
|
+
value,
|
|
45
|
+
onValueChange,
|
|
46
|
+
min,
|
|
47
|
+
max,
|
|
48
|
+
today,
|
|
49
|
+
locale = 'en-US',
|
|
50
|
+
weekStartsOn = 0,
|
|
51
|
+
placeholder = 'Pick a date',
|
|
52
|
+
name,
|
|
53
|
+
required,
|
|
54
|
+
disabled,
|
|
55
|
+
side = 'bottom',
|
|
56
|
+
align = 'start',
|
|
57
|
+
id,
|
|
58
|
+
className,
|
|
59
|
+
'aria-label': ariaLabel,
|
|
60
|
+
},
|
|
61
|
+
ref
|
|
62
|
+
) => {
|
|
63
|
+
const [open, setOpen] = React.useState(false);
|
|
64
|
+
const triggerRef = React.useRef<HTMLButtonElement | null>(null);
|
|
65
|
+
const setTriggerRef = React.useCallback(
|
|
66
|
+
(node: HTMLButtonElement | null) => {
|
|
67
|
+
triggerRef.current = node;
|
|
68
|
+
if (typeof ref === 'function') ref(node);
|
|
69
|
+
else if (ref) ref.current = node;
|
|
70
|
+
},
|
|
71
|
+
[ref]
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const label = value ? formatDateLabel(value, locale) : placeholder;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
79
|
+
<PopoverTrigger
|
|
80
|
+
ref={setTriggerRef}
|
|
81
|
+
id={id}
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
aria-label={ariaLabel}
|
|
84
|
+
className={cn(
|
|
85
|
+
buttonVariants({ variant: 'outline' }),
|
|
86
|
+
'w-full justify-start font-normal',
|
|
87
|
+
!value && 'text-muted-foreground',
|
|
88
|
+
className
|
|
89
|
+
)}
|
|
90
|
+
>
|
|
91
|
+
{label}
|
|
92
|
+
</PopoverTrigger>
|
|
93
|
+
<PopoverContent side={side} align={align} matchTriggerWidth className="w-auto p-3">
|
|
94
|
+
<Calendar
|
|
95
|
+
value={value}
|
|
96
|
+
min={min}
|
|
97
|
+
max={max}
|
|
98
|
+
today={today}
|
|
99
|
+
locale={locale}
|
|
100
|
+
weekStartsOn={weekStartsOn}
|
|
101
|
+
autoFocus
|
|
102
|
+
onValueChange={(next) => {
|
|
103
|
+
onValueChange?.(next);
|
|
104
|
+
setOpen(false);
|
|
105
|
+
triggerRef.current?.focus();
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
</PopoverContent>
|
|
109
|
+
</Popover>
|
|
110
|
+
{name ? <input type="hidden" name={name} value={value ?? ''} required={required} /> : null}
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
DatePickerPopover.displayName = 'DatePickerPopover';
|
|
116
|
+
|
|
117
|
+
export { DatePickerPopover };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DatePickerPopover';
|