@slipstream-ui/core 0.8.0 → 0.10.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 +203 -8
- package/dist/index.d.ts +203 -8
- package/dist/index.js +1737 -965
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1729 -961
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +2 -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 +1 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +1 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +1 -1
- 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 +1 -1
- 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 +13 -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 +1 -1
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +1 -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 +8 -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 +12 -1
- package/dist/src/components/accordion/Accordion.js +26 -19
- package/dist/src/components/accordion/Accordion.js.map +1 -1
- package/dist/src/components/accordion/Accordion.mjs +26 -19
- 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/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/checkbox/Checkbox.js +1 -1
- package/dist/src/components/checkbox/Checkbox.js.map +1 -1
- package/dist/src/components/checkbox/Checkbox.mjs +1 -1
- package/dist/src/components/checkbox/Checkbox.mjs.map +1 -1
- 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.js +2 -1
- package/dist/src/components/drawer/Drawer.js.map +1 -1
- package/dist/src/components/drawer/Drawer.mjs +2 -1
- package/dist/src/components/drawer/Drawer.mjs.map +1 -1
- package/dist/src/components/filter-chips/FilterChips.d.ts +4 -0
- package/dist/src/components/filter-chips/FilterChips.js +35 -4
- package/dist/src/components/filter-chips/FilterChips.js.map +1 -1
- package/dist/src/components/filter-chips/FilterChips.mjs +35 -4
- package/dist/src/components/filter-chips/FilterChips.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/page-header/PageHeader.js +1 -1
- package/dist/src/components/page-header/PageHeader.js.map +1 -1
- package/dist/src/components/page-header/PageHeader.mjs +1 -1
- 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/radio/Radio.js +1 -1
- package/dist/src/components/radio/Radio.js.map +1 -1
- package/dist/src/components/radio/Radio.mjs +1 -1
- package/dist/src/components/radio/Radio.mjs.map +1 -1
- package/dist/src/components/range-slider/RangeSlider.js +3 -3
- package/dist/src/components/range-slider/RangeSlider.js.map +1 -1
- package/dist/src/components/range-slider/RangeSlider.mjs +3 -3
- package/dist/src/components/range-slider/RangeSlider.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/select/Select.d.ts +10 -0
- package/dist/src/components/select/Select.js +2 -2
- package/dist/src/components/select/Select.js.map +1 -1
- package/dist/src/components/select/Select.mjs +2 -2
- package/dist/src/components/select/Select.mjs.map +1 -1
- 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/components/timeline/Timeline.js +17 -13
- package/dist/src/components/timeline/Timeline.js.map +1 -1
- package/dist/src/components/timeline/Timeline.mjs +17 -13
- package/dist/src/components/timeline/Timeline.mjs.map +1 -1
- package/dist/src/components/tooltip/Tooltip.d.ts +5 -0
- package/dist/src/components/tooltip/Tooltip.js +9 -2
- package/dist/src/components/tooltip/Tooltip.js.map +1 -1
- package/dist/src/components/tooltip/Tooltip.mjs +9 -2
- package/dist/src/components/tooltip/Tooltip.mjs.map +1 -1
- package/dist/src/index.d.ts +3 -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 +1 -1
- package/src/components/accordion/Accordion.test.tsx +14 -3
- package/src/components/accordion/Accordion.tsx +34 -21
- 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/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/checkbox/Checkbox.tsx +1 -1
- 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 +12 -0
- package/src/components/drawer/Drawer.tsx +8 -1
- package/src/components/filter-chips/FilterChips.test.tsx +11 -0
- package/src/components/filter-chips/FilterChips.tsx +40 -4
- 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/page-header/PageHeader.tsx +1 -1
- package/src/components/popover/Popover.test.tsx +307 -3
- package/src/components/popover/Popover.tsx +228 -91
- package/src/components/radio/Radio.tsx +1 -1
- package/src/components/range-slider/RangeSlider.tsx +3 -3
- package/src/components/section-heading/SectionHeading.tsx +1 -1
- package/src/components/select/Select.test.tsx +14 -0
- package/src/components/select/Select.tsx +7 -2
- 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/components/timeline/Timeline.test.tsx +11 -0
- package/src/components/timeline/Timeline.tsx +13 -2
- package/src/components/tooltip/Tooltip.test.tsx +15 -0
- package/src/components/tooltip/Tooltip.tsx +19 -2
- package/src/index.ts +3 -0
- package/src/manifests/accordion.manifest.json +2 -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 +1 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +1 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +1 -1
- 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 +1 -1
- 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 +13 -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 +1 -1
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +1 -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 +8 -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 +12 -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,277 @@
|
|
|
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 { Calendar } from './Calendar';
|
|
6
|
+
|
|
7
|
+
const TODAY = '2026-11-13';
|
|
8
|
+
|
|
9
|
+
function setup(overrides: Partial<React.ComponentProps<typeof Calendar>> = {}) {
|
|
10
|
+
const onValueChange = vi.fn();
|
|
11
|
+
render(<Calendar today={TODAY} value="2026-11-13" onValueChange={onValueChange} {...overrides} />);
|
|
12
|
+
return { onValueChange };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function day(name: RegExp | string) {
|
|
16
|
+
return screen.getByRole('button', { name });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('Calendar', () => {
|
|
20
|
+
it('renders a labelled month grid', () => {
|
|
21
|
+
setup();
|
|
22
|
+
expect(screen.getByRole('grid', { name: 'November 2026' })).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText('November 2026')).toBeInTheDocument();
|
|
24
|
+
expect(screen.getAllByRole('columnheader')).toHaveLength(7);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('marks the selected day and today', () => {
|
|
28
|
+
setup();
|
|
29
|
+
const selected = day(/Nov 13, 2026/);
|
|
30
|
+
expect(selected).toHaveAttribute('aria-current', 'date');
|
|
31
|
+
const cell = selected.closest('[role="gridcell"]');
|
|
32
|
+
expect(cell).toHaveAttribute('aria-selected', 'true');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('selects a day by click', async () => {
|
|
36
|
+
const user = userEvent.setup();
|
|
37
|
+
const { onValueChange } = setup();
|
|
38
|
+
await user.click(day(/Nov 20, 2026/));
|
|
39
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-20');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('works uncontrolled', async () => {
|
|
43
|
+
const user = userEvent.setup();
|
|
44
|
+
const onValueChange = vi.fn();
|
|
45
|
+
render(<Calendar defaultValue="2026-11-13" today={TODAY} onValueChange={onValueChange} />);
|
|
46
|
+
await user.click(day(/Nov 5, 2026/));
|
|
47
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-05');
|
|
48
|
+
expect(day(/Nov 5, 2026/).closest('[role="gridcell"]')).toHaveAttribute(
|
|
49
|
+
'aria-selected',
|
|
50
|
+
'true'
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('moves focus with every arrow key and selects with Enter', async () => {
|
|
55
|
+
const user = userEvent.setup();
|
|
56
|
+
const { onValueChange } = setup({ autoFocus: true });
|
|
57
|
+
|
|
58
|
+
await waitFor(() => expect(day(/Nov 13, 2026/)).toHaveFocus());
|
|
59
|
+
|
|
60
|
+
await user.keyboard('{ArrowRight}');
|
|
61
|
+
expect(day(/Nov 14, 2026/)).toHaveFocus();
|
|
62
|
+
await user.keyboard('{ArrowDown}');
|
|
63
|
+
expect(day(/Nov 21, 2026/)).toHaveFocus();
|
|
64
|
+
await user.keyboard('{ArrowLeft}');
|
|
65
|
+
expect(day(/Nov 20, 2026/)).toHaveFocus();
|
|
66
|
+
await user.keyboard('{ArrowUp}');
|
|
67
|
+
expect(day(/Nov 13, 2026/)).toHaveFocus();
|
|
68
|
+
await user.keyboard('{Home}');
|
|
69
|
+
expect(day(/Nov 8, 2026/)).toHaveFocus();
|
|
70
|
+
await user.keyboard('{End}');
|
|
71
|
+
expect(day(/Nov 14, 2026/)).toHaveFocus();
|
|
72
|
+
await user.keyboard('{PageDown}');
|
|
73
|
+
expect(day(/Dec 14, 2026/)).toHaveFocus();
|
|
74
|
+
await user.keyboard('{PageUp}');
|
|
75
|
+
expect(day(/Nov 14, 2026/)).toHaveFocus();
|
|
76
|
+
|
|
77
|
+
await user.keyboard('{Enter}');
|
|
78
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-14');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('pages months with the header buttons and clamps the day', async () => {
|
|
82
|
+
const user = userEvent.setup();
|
|
83
|
+
setup({ value: '2026-01-31' });
|
|
84
|
+
await user.click(screen.getByRole('button', { name: 'Next month' }));
|
|
85
|
+
expect(screen.getByRole('grid', { name: 'February 2026' })).toBeInTheDocument();
|
|
86
|
+
expect(day(/Feb 28, 2026/)).toBeInTheDocument();
|
|
87
|
+
await user.click(screen.getByRole('button', { name: 'Previous month' }));
|
|
88
|
+
expect(screen.getByRole('grid', { name: 'January 2026' })).toBeInTheDocument();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('disables days outside min and max', async () => {
|
|
92
|
+
const user = userEvent.setup();
|
|
93
|
+
const { onValueChange } = setup({ min: '2026-11-10', max: '2026-11-20' });
|
|
94
|
+
|
|
95
|
+
const blocked = day(/Nov 5, 2026/);
|
|
96
|
+
expect(blocked).toHaveAttribute('aria-disabled', 'true');
|
|
97
|
+
await user.click(blocked);
|
|
98
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
99
|
+
|
|
100
|
+
await user.click(day(/Nov 15, 2026/));
|
|
101
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-15');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('honours isDateDisabled', async () => {
|
|
105
|
+
const user = userEvent.setup();
|
|
106
|
+
const { onValueChange } = setup({ isDateDisabled: (key) => key === '2026-11-13' });
|
|
107
|
+
const blocked = day(/Nov 13, 2026/);
|
|
108
|
+
expect(blocked).toHaveAttribute('aria-disabled', 'true');
|
|
109
|
+
await user.click(blocked);
|
|
110
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('does nothing while disabled', async () => {
|
|
114
|
+
const user = userEvent.setup();
|
|
115
|
+
const { onValueChange } = setup({ disabled: true });
|
|
116
|
+
await user.click(day(/Nov 15, 2026/));
|
|
117
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
118
|
+
expect(screen.getByRole('button', { name: 'Next month' })).toBeDisabled();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('starts the week on Monday when asked', () => {
|
|
122
|
+
setup({ weekStartsOn: 1 });
|
|
123
|
+
const headers = screen.getAllByRole('columnheader').map((node) => node.textContent);
|
|
124
|
+
expect(headers[0]).toBe('Mon');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('hides outside days on request', () => {
|
|
128
|
+
const { unmount } = render(
|
|
129
|
+
<Calendar today={TODAY} value="2026-12-15" showOutsideDays={false} onValueChange={() => {}} />
|
|
130
|
+
);
|
|
131
|
+
// December 2026 starts on a Tuesday, so the first cells are November days.
|
|
132
|
+
expect(screen.queryByRole('button', { name: /Nov 30, 2026/ })).not.toBeInTheDocument();
|
|
133
|
+
unmount();
|
|
134
|
+
|
|
135
|
+
render(<Calendar today={TODAY} value="2026-12-15" onValueChange={() => {}} />);
|
|
136
|
+
expect(screen.getByRole('button', { name: /Nov 30, 2026/ })).toBeInTheDocument();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('has no accessibility violations', async () => {
|
|
140
|
+
const { container } = render(
|
|
141
|
+
<Calendar today={TODAY} value="2026-11-13" onValueChange={() => {}} />
|
|
142
|
+
);
|
|
143
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('Calendar edge cases', () => {
|
|
148
|
+
it('accepts an aria-label for the grid', () => {
|
|
149
|
+
render(
|
|
150
|
+
<Calendar
|
|
151
|
+
today={TODAY}
|
|
152
|
+
value="2026-11-13"
|
|
153
|
+
aria-label="Choose a start date"
|
|
154
|
+
onValueChange={() => {}}
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
157
|
+
expect(screen.getByRole('grid', { name: 'Choose a start date' })).toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('follows a controlled value into its month', async () => {
|
|
161
|
+
const { rerender } = render(
|
|
162
|
+
<Calendar today={TODAY} value="2026-11-13" onValueChange={() => {}} />
|
|
163
|
+
);
|
|
164
|
+
expect(screen.getByRole('grid', { name: 'November 2026' })).toBeInTheDocument();
|
|
165
|
+
|
|
166
|
+
rerender(<Calendar today={TODAY} value="2027-02-10" onValueChange={() => {}} />);
|
|
167
|
+
await waitFor(() =>
|
|
168
|
+
expect(screen.getByRole('grid', { name: 'February 2027' })).toBeInTheDocument()
|
|
169
|
+
);
|
|
170
|
+
expect(day(/Feb 10, 2027/)).toHaveAttribute('tabindex', '0');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('selects an outside day and follows it into the previous month', async () => {
|
|
174
|
+
const user = userEvent.setup();
|
|
175
|
+
const onValueChange = vi.fn();
|
|
176
|
+
render(<Calendar defaultValue="2026-12-15" today={TODAY} onValueChange={onValueChange} />);
|
|
177
|
+
|
|
178
|
+
await user.click(day(/Nov 30, 2026/));
|
|
179
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-30');
|
|
180
|
+
await waitFor(() =>
|
|
181
|
+
expect(screen.getByRole('grid', { name: 'November 2026' })).toBeInTheDocument()
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('keeps exactly one tab stop and moves it with the keyboard', async () => {
|
|
186
|
+
const user = userEvent.setup();
|
|
187
|
+
render(<Calendar today={TODAY} value="2026-11-13" autoFocus onValueChange={() => {}} />);
|
|
188
|
+
await waitFor(() => expect(day(/Nov 13, 2026/)).toHaveFocus());
|
|
189
|
+
|
|
190
|
+
const tabbable = () =>
|
|
191
|
+
within(screen.getByRole('grid'))
|
|
192
|
+
.getAllByRole('button')
|
|
193
|
+
.filter((button) => button.tabIndex === 0);
|
|
194
|
+
expect(tabbable()).toHaveLength(1);
|
|
195
|
+
expect(tabbable()[0]).toHaveAttribute('data-date', '2026-11-13');
|
|
196
|
+
|
|
197
|
+
await user.keyboard('{ArrowRight}');
|
|
198
|
+
expect(tabbable()).toHaveLength(1);
|
|
199
|
+
expect(tabbable()[0]).toHaveAttribute('data-date', '2026-11-14');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('moves focus from the keyboard without autoFocus', async () => {
|
|
203
|
+
const user = userEvent.setup();
|
|
204
|
+
render(<Calendar today={TODAY} value="2026-11-13" onValueChange={() => {}} />);
|
|
205
|
+
|
|
206
|
+
// A keyboard user tabs into the grid rather than relying on autoFocus.
|
|
207
|
+
day(/Nov 13, 2026/).focus();
|
|
208
|
+
await user.keyboard('{ArrowRight}');
|
|
209
|
+
expect(day(/Nov 14, 2026/)).toHaveFocus();
|
|
210
|
+
await user.keyboard('{ArrowDown}');
|
|
211
|
+
expect(day(/Nov 21, 2026/)).toHaveFocus();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('selects with Space', async () => {
|
|
215
|
+
const user = userEvent.setup();
|
|
216
|
+
const onValueChange = vi.fn();
|
|
217
|
+
render(
|
|
218
|
+
<Calendar today={TODAY} value="2026-11-13" autoFocus onValueChange={onValueChange} />
|
|
219
|
+
);
|
|
220
|
+
await waitFor(() => expect(day(/Nov 13, 2026/)).toHaveFocus());
|
|
221
|
+
|
|
222
|
+
await user.keyboard(' ');
|
|
223
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-13');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('treats min and max as inclusive', async () => {
|
|
227
|
+
const user = userEvent.setup();
|
|
228
|
+
const onValueChange = vi.fn();
|
|
229
|
+
render(
|
|
230
|
+
<Calendar
|
|
231
|
+
today={TODAY}
|
|
232
|
+
value="2026-11-13"
|
|
233
|
+
min="2026-11-13"
|
|
234
|
+
max="2026-11-15"
|
|
235
|
+
onValueChange={onValueChange}
|
|
236
|
+
/>
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
expect(day(/Nov 13, 2026/)).not.toHaveAttribute('aria-disabled');
|
|
240
|
+
expect(day(/Nov 15, 2026/)).not.toHaveAttribute('aria-disabled');
|
|
241
|
+
expect(day(/Nov 12, 2026/)).toHaveAttribute('aria-disabled', 'true');
|
|
242
|
+
expect(day(/Nov 16, 2026/)).toHaveAttribute('aria-disabled', 'true');
|
|
243
|
+
|
|
244
|
+
await user.click(day(/Nov 15, 2026/));
|
|
245
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-11-15');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('clamps the day when paging months from the 31st', async () => {
|
|
249
|
+
const user = userEvent.setup();
|
|
250
|
+
const onValueChange = vi.fn();
|
|
251
|
+
render(
|
|
252
|
+
<Calendar today="2026-01-31" value="2026-01-31" autoFocus onValueChange={onValueChange} />
|
|
253
|
+
);
|
|
254
|
+
await waitFor(() => expect(day(/Jan 31, 2026/)).toHaveFocus());
|
|
255
|
+
|
|
256
|
+
await user.keyboard('{PageDown}');
|
|
257
|
+
await waitFor(() => expect(day(/Feb 28, 2026/)).toHaveFocus());
|
|
258
|
+
await user.keyboard('{Enter}');
|
|
259
|
+
expect(onValueChange).toHaveBeenCalledWith('2026-02-28');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('renders a usable grid for an unparseable value', () => {
|
|
263
|
+
render(<Calendar today={TODAY} value="not-a-date" onValueChange={() => {}} />);
|
|
264
|
+
expect(screen.getByRole('grid', { name: 'January 1970' })).toBeInTheDocument();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('marks every day unavailable when disabled', async () => {
|
|
268
|
+
const user = userEvent.setup();
|
|
269
|
+
const onValueChange = vi.fn();
|
|
270
|
+
render(
|
|
271
|
+
<Calendar today={TODAY} value="2026-11-13" disabled onValueChange={onValueChange} />
|
|
272
|
+
);
|
|
273
|
+
expect(day(/Nov 15, 2026/)).toHaveAttribute('aria-disabled', 'true');
|
|
274
|
+
await user.click(day(/Nov 15, 2026/));
|
|
275
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
276
|
+
});
|
|
277
|
+
});
|
|
@@ -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';
|
|
@@ -24,7 +24,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
24
24
|
onChange?.(event);
|
|
25
25
|
}}
|
|
26
26
|
className={cn(
|
|
27
|
-
'peer h-4 w-4 shrink-0 rounded-sm border border-primary',
|
|
27
|
+
'peer h-4 w-4 shrink-0 rounded-sm border border-primary accent-primary',
|
|
28
28
|
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
|
29
29
|
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
30
30
|
'checked:bg-primary checked:text-primary-foreground',
|
|
@@ -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
|
)}
|