@eifi1/ui-kit 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +32 -0
- package/README.md +498 -57
- package/dist/chart.d.ts +10 -0
- package/dist/chart.js +10 -0
- package/dist/chart.js.map +1 -0
- package/dist/components/account-settings.d.ts +11 -0
- package/dist/components/account-settings.js +19 -12
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/alert-banner.d.ts +10 -6
- package/dist/components/alert-banner.js +20 -16
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +30 -4
- package/dist/components/amount-input.js +36 -14
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/calculator.d.ts +24 -7
- package/dist/components/calculator.js +37 -20
- package/dist/components/calculator.js.map +1 -1
- package/dist/components/chart-zoom.d.ts +156 -0
- package/dist/components/chart-zoom.js +262 -0
- package/dist/components/chart-zoom.js.map +1 -0
- package/dist/components/chart.d.ts +28 -3
- package/dist/components/chart.js +71 -32
- package/dist/components/chart.js.map +1 -1
- package/dist/components/checkbox.d.ts +51 -0
- package/dist/components/checkbox.js +123 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/chip.d.ts +128 -0
- package/dist/components/chip.js +357 -0
- package/dist/components/chip.js.map +1 -0
- package/dist/components/choice-parts.d.ts +24 -0
- package/dist/components/choice-parts.js +18 -0
- package/dist/components/choice-parts.js.map +1 -0
- package/dist/components/combobox-core.d.ts +52 -9
- package/dist/components/combobox-core.js +91 -20
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +43 -33
- package/dist/components/combobox.js +409 -340
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/currency-select.d.ts +48 -8
- package/dist/components/currency-select.js +107 -65
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/data-table-filter-popover.d.ts +15 -3
- package/dist/components/data-table-filter-popover.js +23 -17
- package/dist/components/data-table-filter-popover.js.map +1 -1
- package/dist/components/data-table-filters.d.ts +1 -1
- package/dist/components/data-table-filters.js +3 -2
- package/dist/components/data-table-filters.js.map +1 -1
- package/dist/components/data-table-labels.d.ts +53 -2
- package/dist/components/data-table-labels.js +31 -2
- package/dist/components/data-table-labels.js.map +1 -1
- package/dist/components/data-table-pagination.d.ts +3 -1
- package/dist/components/data-table-pagination.js +16 -10
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table-sort.js +1 -0
- package/dist/components/data-table-sort.js.map +1 -1
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/data-table.js +201 -85
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +25 -9
- package/dist/components/date-picker.js +232 -94
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/dropdown.d.ts +96 -20
- package/dist/components/dropdown.js +77 -33
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +5 -4
- package/dist/components/entity-combobox.js +107 -76
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +36 -0
- package/dist/components/facing-pair.js +40 -0
- package/dist/components/facing-pair.js.map +1 -0
- package/dist/components/field-sync.d.ts +164 -0
- package/dist/components/field-sync.js +264 -0
- package/dist/components/field-sync.js.map +1 -0
- package/dist/components/file-dropzone.d.ts +38 -6
- package/dist/components/file-dropzone.js +34 -9
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/full-bleed-dialog.d.ts +37 -26
- package/dist/components/full-bleed-dialog.js +20 -5
- package/dist/components/full-bleed-dialog.js.map +1 -1
- package/dist/components/grouped-picker.d.ts +21 -10
- package/dist/components/grouped-picker.js +66 -52
- package/dist/components/grouped-picker.js.map +1 -1
- package/dist/components/hover-menu.d.ts +20 -4
- package/dist/components/hover-menu.js +15 -4
- package/dist/components/hover-menu.js.map +1 -1
- package/dist/components/mini-calendar.d.ts +102 -14
- package/dist/components/mini-calendar.js +256 -70
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/modal.d.ts +9 -3
- package/dist/components/modal.js +34 -45
- package/dist/components/modal.js.map +1 -1
- package/dist/components/month-picker.d.ts +79 -0
- package/dist/components/month-picker.js +342 -0
- package/dist/components/month-picker.js.map +1 -0
- package/dist/components/multi-entity-combobox.d.ts +7 -6
- package/dist/components/multi-entity-combobox.js +112 -72
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +13 -11
- package/dist/components/multi-select.js +161 -84
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-field.d.ts +92 -0
- package/dist/components/number-field.js +111 -0
- package/dist/components/number-field.js.map +1 -0
- package/dist/components/number-input.d.ts +28 -2
- package/dist/components/number-input.js +12 -2
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +32 -4
- package/dist/components/numpad-sheet.js +30 -13
- package/dist/components/numpad-sheet.js.map +1 -1
- package/dist/components/page-contents.d.ts +90 -0
- package/dist/components/page-contents.js +170 -0
- package/dist/components/page-contents.js.map +1 -0
- package/dist/components/password-strength.d.ts +106 -0
- package/dist/components/password-strength.js +132 -0
- package/dist/components/password-strength.js.map +1 -0
- package/dist/components/picker-sheet.d.ts +23 -15
- package/dist/components/picker-sheet.js +34 -14
- package/dist/components/picker-sheet.js.map +1 -1
- package/dist/components/popover.d.ts +62 -4
- package/dist/components/popover.js +52 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/search-field.d.ts +25 -7
- package/dist/components/search-field.js +7 -5
- package/dist/components/search-field.js.map +1 -1
- package/dist/components/series-chart-labels.d.ts +14 -0
- package/dist/components/series-chart-labels.js +11 -0
- package/dist/components/series-chart-labels.js.map +1 -0
- package/dist/components/series-chart.d.ts +207 -0
- package/dist/components/series-chart.js +223 -0
- package/dist/components/series-chart.js.map +1 -0
- package/dist/components/settings-fields.d.ts +14 -4
- package/dist/components/settings-fields.js +19 -8
- package/dist/components/settings-fields.js.map +1 -1
- package/dist/components/signature-pad.d.ts +119 -0
- package/dist/components/signature-pad.js +405 -0
- package/dist/components/signature-pad.js.map +1 -0
- package/dist/components/slider.d.ts +80 -0
- package/dist/components/slider.js +155 -0
- package/dist/components/slider.js.map +1 -0
- package/dist/components/sparkline.d.ts +93 -0
- package/dist/components/sparkline.js +205 -0
- package/dist/components/sparkline.js.map +1 -0
- package/dist/components/stat-tile.d.ts +151 -0
- package/dist/components/stat-tile.js +236 -0
- package/dist/components/stat-tile.js.map +1 -0
- package/dist/components/swipeable-row.d.ts +25 -2
- package/dist/components/swipeable-row.js +31 -0
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/switch.d.ts +60 -0
- package/dist/components/switch.js +81 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/time-input.d.ts +58 -0
- package/dist/components/time-input.js +50 -0
- package/dist/components/time-input.js.map +1 -0
- package/dist/components/toggle-group.d.ts +18 -3
- package/dist/components/toggle-group.js +10 -6
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle-legend.d.ts +115 -0
- package/dist/components/toggle-legend.js +114 -0
- package/dist/components/toggle-legend.js.map +1 -0
- package/dist/components/tooltip.d.ts +40 -11
- package/dist/components/tooltip.js +77 -20
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/treemap.d.ts +132 -0
- package/dist/components/treemap.js +179 -0
- package/dist/components/treemap.js.map +1 -0
- package/dist/components/ui.d.ts +159 -46
- package/dist/components/ui.js +220 -115
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-mobile-reveal.js +1 -0
- package/dist/components/use-mobile-reveal.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -1
- package/dist/components/use-table-state.js +38 -17
- package/dist/components/use-table-state.js.map +1 -1
- package/dist/components/user-avatar.d.ts +15 -4
- package/dist/components/user-avatar.js +5 -4
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/components/wizard-stepper.js +3 -2
- package/dist/components/wizard-stepper.js.map +1 -1
- package/dist/{data-table-filters-aXyf0Xub.d.ts → data-table-filters-DM1auUfH.d.ts} +27 -5
- package/dist/data-table.d.ts +7 -0
- package/dist/data-table.js +12 -0
- package/dist/data-table.js.map +1 -0
- package/dist/feedback/feedback-attachment.js +12 -11
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.js +2 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.d.ts +33 -7
- package/dist/feedback/feedback-inbox.js +49 -37
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback.d.ts +5 -0
- package/dist/feedback.js +5 -0
- package/dist/feedback.js.map +1 -0
- package/dist/hooks/use-anchored-panel.js +1 -0
- package/dist/hooks/use-anchored-panel.js.map +1 -1
- package/dist/hooks/use-anchored-rect.js +1 -0
- package/dist/hooks/use-anchored-rect.js.map +1 -1
- package/dist/hooks/use-announce.d.ts +46 -0
- package/dist/hooks/use-announce.js +37 -0
- package/dist/hooks/use-announce.js.map +1 -0
- package/dist/hooks/use-body-scroll-lock.js +1 -0
- package/dist/hooks/use-body-scroll-lock.js.map +1 -1
- package/dist/hooks/use-close-transition.js +1 -0
- package/dist/hooks/use-close-transition.js.map +1 -1
- package/dist/hooks/use-dismiss.js +1 -0
- package/dist/hooks/use-dismiss.js.map +1 -1
- package/dist/hooks/use-focus-trap.d.ts +16 -0
- package/dist/hooks/use-focus-trap.js +67 -0
- package/dist/hooks/use-focus-trap.js.map +1 -0
- package/dist/hooks/use-media-query.js +1 -0
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-overlay-history.js +27 -1
- package/dist/hooks/use-overlay-history.js.map +1 -1
- package/dist/hooks/use-row-swipe.js +1 -0
- package/dist/hooks/use-row-swipe.js.map +1 -1
- package/dist/i18n/defaults.d.ts +31 -0
- package/dist/i18n/defaults.js +63 -0
- package/dist/i18n/defaults.js.map +1 -0
- package/dist/i18n/kit-labels.d.ts +250 -0
- package/dist/i18n/kit-labels.js +184 -0
- package/dist/i18n/kit-labels.js.map +1 -0
- package/dist/index.d.ts +47 -22
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/calc.js +1 -0
- package/dist/lib/calc.js.map +1 -1
- package/dist/lib/cn.js +1 -0
- package/dist/lib/cn.js.map +1 -1
- package/dist/lib/dates.js +1 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/logger.js +1 -0
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/safe-storage.js +1 -0
- package/dist/lib/safe-storage.js.map +1 -1
- package/dist/search/command-palette.d.ts +11 -1
- package/dist/search/command-palette.js +21 -15
- package/dist/search/command-palette.js.map +1 -1
- package/dist/search.d.ts +2 -0
- package/dist/search.js +3 -0
- package/dist/search.js.map +1 -0
- package/dist/shell/app-shell.d.ts +33 -4
- package/dist/shell/app-shell.js +275 -78
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/option-switcher-menu.js +3 -2
- package/dist/shell/option-switcher-menu.js.map +1 -1
- package/dist/shell/role-switcher.d.ts +6 -0
- package/dist/shell/role-switcher.js +7 -4
- package/dist/shell/role-switcher.js.map +1 -1
- package/dist/shell/top-bar.d.ts +15 -7
- package/dist/shell/top-bar.js +3 -5
- package/dist/shell/top-bar.js.map +1 -1
- package/dist/shell/topbar-action-menu.js +3 -2
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell/topbar-controls.d.ts +5 -2
- package/dist/shell/topbar-controls.js +20 -15
- package/dist/shell/topbar-controls.js.map +1 -1
- package/dist/shell.d.ts +13 -0
- package/dist/shell.js +8 -0
- package/dist/shell.js.map +1 -0
- package/dist/theme/chart-palette.d.ts +19 -12
- package/dist/theme/chart-palette.js +24 -30
- package/dist/theme/chart-palette.js.map +1 -1
- package/dist/theme/color.d.ts +78 -0
- package/dist/theme/color.js +148 -0
- package/dist/theme/color.js.map +1 -0
- package/dist/theme/palette-derive.d.ts +140 -0
- package/dist/theme/palette-derive.js +376 -0
- package/dist/theme/palette-derive.js.map +1 -0
- package/dist/theme/palette-presets.d.ts +27 -5
- package/dist/theme/palette-presets.js +231 -33
- package/dist/theme/palette-presets.js.map +1 -1
- package/dist/theme/palette-store.js +1 -0
- package/dist/theme/palette-store.js.map +1 -1
- package/dist/theme/theme-store.js +1 -0
- package/dist/theme/theme-store.js.map +1 -1
- package/dist/tour/tour.d.ts +2 -1
- package/dist/tour/tour.js +15 -9
- package/dist/tour/tour.js.map +1 -1
- package/dist/tour.d.ts +2 -0
- package/dist/tour.js +3 -0
- package/dist/tour.js.map +1 -0
- package/dist/wizard/stepper-nav.js +10 -8
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard/types.d.ts +18 -2
- package/dist/wizard/types.js +4 -1
- package/dist/wizard/types.js.map +1 -1
- package/dist/wizard/use-wizard.js +12 -4
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/validation.js +1 -0
- package/dist/wizard/validation.js.map +1 -1
- package/dist/wizard/wizard-context.js +1 -0
- package/dist/wizard/wizard-context.js.map +1 -1
- package/dist/wizard/wizard-step.js +1 -0
- package/dist/wizard/wizard-step.js.map +1 -1
- package/dist/wizard/wizard-summary.js +5 -3
- package/dist/wizard/wizard-summary.js.map +1 -1
- package/dist/wizard.d.ts +8 -0
- package/dist/wizard.js +9 -0
- package/dist/wizard.js.map +1 -0
- package/package.json +67 -14
- package/src/chart.ts +22 -0
- package/src/components/account-settings.tsx +275 -0
- package/src/components/alert-banner.tsx +75 -0
- package/src/components/amount-input.tsx +471 -0
- package/src/components/calculator.tsx +252 -0
- package/src/components/chart-zoom.tsx +499 -0
- package/src/components/chart.tsx +363 -0
- package/src/components/checkbox.tsx +222 -0
- package/src/components/chip.tsx +570 -0
- package/src/components/choice-parts.ts +33 -0
- package/src/components/combobox-core.tsx +540 -0
- package/src/components/combobox.tsx +1026 -0
- package/src/components/currency-select.tsx +269 -0
- package/src/components/data-table-filter-popover.tsx +252 -0
- package/src/components/data-table-filters.ts +176 -0
- package/src/components/data-table-labels.ts +190 -0
- package/src/components/data-table-pagination.tsx +126 -0
- package/src/components/data-table-sort.ts +70 -0
- package/src/components/data-table.tsx +1740 -0
- package/src/components/date-picker.tsx +631 -0
- package/src/components/dropdown.tsx +341 -0
- package/src/components/entity-combobox.tsx +215 -0
- package/src/components/facing-pair.ts +86 -0
- package/src/components/field-sync.tsx +472 -0
- package/src/components/file-dropzone.tsx +181 -0
- package/src/components/full-bleed-dialog.tsx +179 -0
- package/src/components/grouped-picker.tsx +157 -0
- package/src/components/hover-menu.tsx +183 -0
- package/src/components/mini-calendar.tsx +554 -0
- package/src/components/modal.tsx +287 -0
- package/src/components/month-picker.tsx +549 -0
- package/src/components/multi-entity-combobox.tsx +226 -0
- package/src/components/multi-select.tsx +303 -0
- package/src/components/number-field.tsx +225 -0
- package/src/components/number-input.tsx +211 -0
- package/src/components/numpad-sheet.tsx +264 -0
- package/src/components/page-contents.tsx +289 -0
- package/src/components/password-strength.tsx +258 -0
- package/src/components/picker-sheet.tsx +251 -0
- package/src/components/popover.tsx +195 -0
- package/src/components/search-field.tsx +146 -0
- package/src/components/series-chart-labels.ts +26 -0
- package/src/components/series-chart.tsx +481 -0
- package/src/components/settings-fields.tsx +68 -0
- package/src/components/signature-pad.tsx +630 -0
- package/src/components/slider.tsx +313 -0
- package/src/components/sparkline.tsx +329 -0
- package/src/components/stat-tile.tsx +448 -0
- package/src/components/swipeable-row.tsx +271 -0
- package/src/components/switch.tsx +170 -0
- package/src/components/time-input.tsx +107 -0
- package/src/components/toggle-group.tsx +153 -0
- package/src/components/toggle-legend.tsx +229 -0
- package/src/components/tooltip.tsx +477 -0
- package/src/components/treemap.tsx +390 -0
- package/src/components/ui.tsx +1284 -0
- package/src/components/use-mobile-reveal.ts +54 -0
- package/src/components/use-table-state.ts +295 -0
- package/src/components/user-avatar.tsx +61 -0
- package/src/components/wizard-stepper.tsx +37 -0
- package/src/data-table.ts +19 -0
- package/src/feedback/feedback-attachment.tsx +246 -0
- package/src/feedback/feedback-dialog.tsx +209 -0
- package/src/feedback/feedback-inbox.tsx +615 -0
- package/src/feedback.ts +8 -0
- package/src/hooks/use-anchored-panel.ts +169 -0
- package/src/hooks/use-anchored-rect.ts +78 -0
- package/src/hooks/use-announce.ts +85 -0
- package/src/hooks/use-body-scroll-lock.ts +94 -0
- package/src/hooks/use-close-transition.ts +99 -0
- package/src/hooks/use-dismiss.ts +77 -0
- package/src/hooks/use-focus-trap.ts +160 -0
- package/src/hooks/use-media-query.ts +23 -0
- package/src/hooks/use-overlay-history.ts +345 -0
- package/src/hooks/use-row-swipe.ts +212 -0
- package/src/i18n/defaults.ts +68 -0
- package/src/i18n/kit-labels.tsx +447 -0
- package/src/index.ts +169 -0
- package/src/lib/calc.ts +309 -0
- package/src/lib/cn.ts +5 -0
- package/src/lib/dates.ts +187 -0
- package/src/lib/logger.ts +73 -0
- package/src/lib/safe-storage.ts +37 -0
- package/src/search/command-palette.tsx +342 -0
- package/src/search.ts +3 -0
- package/src/shell/app-shell.tsx +772 -0
- package/src/shell/option-switcher-menu.tsx +72 -0
- package/src/shell/role-switcher.tsx +46 -0
- package/src/shell/top-bar.tsx +39 -0
- package/src/shell/topbar-action-menu.tsx +91 -0
- package/src/shell/topbar-controls.tsx +229 -0
- package/src/shell.ts +10 -0
- package/src/theme/chart-palette.ts +145 -0
- package/src/theme/color.ts +266 -0
- package/src/theme/palette-derive.ts +681 -0
- package/src/theme/palette-presets.ts +760 -0
- package/src/theme/palette-store.ts +94 -0
- package/src/theme/theme-store.ts +145 -0
- package/src/tour/tour.tsx +586 -0
- package/src/tour.ts +3 -0
- package/src/vite-env.d.ts +26 -0
- package/src/wizard/stepper-nav.tsx +221 -0
- package/src/wizard/types.ts +178 -0
- package/src/wizard/use-wizard.ts +345 -0
- package/src/wizard/validation.ts +37 -0
- package/src/wizard/wizard-context.tsx +29 -0
- package/src/wizard/wizard-step.tsx +14 -0
- package/src/wizard/wizard-summary.tsx +69 -0
- package/src/wizard.ts +14 -0
- package/tokens.css +222 -20
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import { useEffect, useId, useMemo, useRef } from "react";
|
|
2
|
+
import type { ComponentPropsWithoutRef, ComponentType, ReactNode, RefObject } from "react";
|
|
3
|
+
import { Calendar, CalendarClock, ChevronLeft, ChevronRight, X } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/cn";
|
|
5
|
+
import { addDaysIso, parseIsoDate } from "../lib/dates";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_DATE_PICKER_LABELS,
|
|
8
|
+
useKitLabels,
|
|
9
|
+
useKitLocale,
|
|
10
|
+
type DatePickerLabels,
|
|
11
|
+
} from "../i18n/kit-labels";
|
|
12
|
+
import { FieldLabel, FIELD_BASE, FIELD_TRIGGER, FIELD_FLOATING_PAD, FIELD_INVALID } from "./ui";
|
|
13
|
+
import { MiniCalendar, type MiniCalendarProps } from "./mini-calendar";
|
|
14
|
+
import { Popover } from "./popover";
|
|
15
|
+
import { Tooltip } from "./tooltip";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* What both pickers share — and, through `ComponentPropsWithoutRef<"div">`, everything a
|
|
19
|
+
* `<div>` takes, so a `data-tour` anchor, a test id or an `aria-describedby` reaches the
|
|
20
|
+
* field's root element instead of being dropped (audit §api-design).
|
|
21
|
+
*
|
|
22
|
+
* `onChange` is omitted from those attributes: the DOM event of that name carries a
|
|
23
|
+
* `FormEvent`, while both pickers answer with ISO date strings. Each declares its own
|
|
24
|
+
* below.
|
|
25
|
+
*/
|
|
26
|
+
interface DatePickerBaseProps extends Omit<ComponentPropsWithoutRef<"div">, "onChange"> {
|
|
27
|
+
/** BCP 47 tag for the trigger's date and the calendar. Falls back to
|
|
28
|
+
* `<UiKitProvider locale>`, then to the runtime's default. */
|
|
29
|
+
locale?: string;
|
|
30
|
+
/** Embedded top-boundary label, matching the native Input/Select fields. */
|
|
31
|
+
label?: ReactNode;
|
|
32
|
+
placeholder?: string;
|
|
33
|
+
/** Inclusive ISO bounds for selectable days. */
|
|
34
|
+
min?: string;
|
|
35
|
+
max?: string;
|
|
36
|
+
/** Show an X to clear the value (emits `""`). */
|
|
37
|
+
clearable?: boolean;
|
|
38
|
+
/** Accessible name of the clear button. Wins over `datePicker.clear` from
|
|
39
|
+
* `<UiKitProvider labels>`; kept as a prop because it predates the provider. */
|
|
40
|
+
clearLabel?: string;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
/** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */
|
|
43
|
+
invalid?: boolean;
|
|
44
|
+
className?: string;
|
|
45
|
+
/** Intl options for the trigger's formatted date (default: locale short date). */
|
|
46
|
+
formatOptions?: Intl.DateTimeFormatOptions;
|
|
47
|
+
/** Render the trigger's text for an ISO date yourself; wins over `formatOptions`.
|
|
48
|
+
* For a host whose date rendering is more than one `Intl` call can say — Keksdose
|
|
49
|
+
* puts the weekday's name in the UI language beside digits ordered by a separate
|
|
50
|
+
* format preference, two locales in one string. `locale` still drives the calendar. */
|
|
51
|
+
formatValue?: (iso: string) => string;
|
|
52
|
+
/** Passed through to the {@link MiniCalendar} this opens. Its month arrows are
|
|
53
|
+
* icon-only, so their `aria-label` is the only name they have — and the package
|
|
54
|
+
* ships English defaults, which a translating host has to be able to replace.
|
|
55
|
+
* Usually unnecessary now: the calendar reads `miniCalendar` from the provider. */
|
|
56
|
+
calendarLabels?: MiniCalendarProps["labels"];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Format an ISO date for the trigger. `lib/dates`' `formatIsoDate` insists on a
|
|
60
|
+
* locale, and here there may be none — no prop and no provider — which `Intl` reads
|
|
61
|
+
* as "the runtime's default", as every other kit formatter does. */
|
|
62
|
+
function formatDate(iso: string, locale: string | undefined, options?: Intl.DateTimeFormatOptions) {
|
|
63
|
+
return parseIsoDate(iso)?.toLocaleDateString(locale, options) ?? "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The field-shaped button that opens the calendar.
|
|
68
|
+
*
|
|
69
|
+
* A component of its own rather than JSX inline in `Popover`'s `trigger` render prop,
|
|
70
|
+
* because handing focus back to it is an effect and a render prop is not somewhere a
|
|
71
|
+
* hook can go.
|
|
72
|
+
*/
|
|
73
|
+
function DateFieldTrigger({
|
|
74
|
+
open,
|
|
75
|
+
toggle,
|
|
76
|
+
triggerRef,
|
|
77
|
+
triggerText,
|
|
78
|
+
hasValue,
|
|
79
|
+
labelledBy,
|
|
80
|
+
valueId,
|
|
81
|
+
padded,
|
|
82
|
+
disabled,
|
|
83
|
+
invalid,
|
|
84
|
+
panelId,
|
|
85
|
+
}: {
|
|
86
|
+
open: boolean;
|
|
87
|
+
toggle: () => void;
|
|
88
|
+
triggerRef: RefObject<HTMLButtonElement | null>;
|
|
89
|
+
/** The panel's id — `role="combobox"` requires `aria-controls`. */
|
|
90
|
+
panelId: string;
|
|
91
|
+
triggerText: string;
|
|
92
|
+
hasValue: boolean;
|
|
93
|
+
/** ids of the hidden label twin + the value span, in the order they are spoken. */
|
|
94
|
+
labelledBy?: string;
|
|
95
|
+
valueId: string;
|
|
96
|
+
padded: boolean;
|
|
97
|
+
disabled?: boolean;
|
|
98
|
+
invalid?: boolean;
|
|
99
|
+
}) {
|
|
100
|
+
const wasOpen = useRef(false);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const justClosed = wasOpen.current && !open;
|
|
103
|
+
wasOpen.current = open;
|
|
104
|
+
if (!justClosed) return;
|
|
105
|
+
// Only when the panel still HAD focus. The day the user was standing on has just
|
|
106
|
+
// been unmounted with the panel, which drops focus to <body> and leaves a
|
|
107
|
+
// keyboard user back at the top of the document with no idea where they were.
|
|
108
|
+
// But an outside click closes this panel too, and that click has already given
|
|
109
|
+
// focus to whatever it landed on — dragging it back here would be worse than the
|
|
110
|
+
// bug, so a focus that is somewhere real is left alone.
|
|
111
|
+
const active = document.activeElement;
|
|
112
|
+
if (!active || active === document.body) triggerRef.current?.focus();
|
|
113
|
+
// Here rather than through `useFocusTrap`'s `restoreFocus`, and not only because
|
|
114
|
+
// `Popover` runs no trap to carry it: that option restores to whatever held focus
|
|
115
|
+
// when the panel opened, and on Safari — and on Firefox on macOS — clicking a
|
|
116
|
+
// button does not focus it, so "whatever held focus" is the page. The requirement
|
|
117
|
+
// is this trigger, every time, however the panel was opened.
|
|
118
|
+
}, [open, triggerRef]);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<button
|
|
122
|
+
ref={triggerRef}
|
|
123
|
+
type="button"
|
|
124
|
+
disabled={disabled}
|
|
125
|
+
onClick={toggle}
|
|
126
|
+
// The name has to carry the VALUE. A bare `aria-label={label}` — which is what
|
|
127
|
+
// this was — replaces the button's text outright, so the one field in the form
|
|
128
|
+
// whose entire job is to show a date announced "Due date" and stopped there,
|
|
129
|
+
// and a screen-reader user could not read back what they had picked without
|
|
130
|
+
// opening the calendar and hunting for the selected day.
|
|
131
|
+
//
|
|
132
|
+
// Two ids rather than one composed string (`common.fieldValue`): "label: value"
|
|
133
|
+
// is a sentence, and a name reference is spoken as the two texts in order with
|
|
134
|
+
// no punctuation to translate at all. The hidden twin of the FieldLabel lives
|
|
135
|
+
// in DateField, next to the label it copies.
|
|
136
|
+
aria-labelledby={labelledBy}
|
|
137
|
+
// `role="combobox"` on a button that opens a calendar is the APG date-picker
|
|
138
|
+
// shape, and it is what makes the next two lines legal: `button` supports
|
|
139
|
+
// neither `aria-expanded` nor `aria-invalid`, so the previous markup set an
|
|
140
|
+
// invalid state that announced nothing (ESLint's `role-supports-aria-props`).
|
|
141
|
+
//
|
|
142
|
+
// `aria-haspopup="dialog"` is now honest — it was not when this comment first
|
|
143
|
+
// said so. `Popover` gained a real `role="dialog"` in the same wave, so the
|
|
144
|
+
// trigger's promise and the panel's role finally agree.
|
|
145
|
+
role="combobox"
|
|
146
|
+
aria-haspopup="dialog"
|
|
147
|
+
aria-controls={panelId}
|
|
148
|
+
aria-expanded={open}
|
|
149
|
+
aria-invalid={invalid || undefined}
|
|
150
|
+
className={cn(
|
|
151
|
+
FIELD_TRIGGER,
|
|
152
|
+
"pr-9",
|
|
153
|
+
padded && FIELD_FLOATING_PAD,
|
|
154
|
+
disabled && "cursor-not-allowed opacity-50",
|
|
155
|
+
invalid && FIELD_INVALID,
|
|
156
|
+
)}
|
|
157
|
+
>
|
|
158
|
+
<span id={valueId} className={cn("truncate", !hasValue && "text-[var(--text-placeholder)]")}>
|
|
159
|
+
{/* `|| " "` (a NON-BREAKING space) — triggerText is "" when there is no value and no
|
|
160
|
+
placeholder was passed. An empty span has no line box, so the
|
|
161
|
+
trigger collapses to its padding and sits shorter than every
|
|
162
|
+
other field beside it.
|
|
163
|
+
|
|
164
|
+
It has to be a NON-BREAKING space. This read `|| " "` first, and
|
|
165
|
+
that fix did nothing at all: an ordinary space is collapsible
|
|
166
|
+
white space, and white space at the start and end of a line is
|
|
167
|
+
removed — so the span rendered with height 0 and the trigger
|
|
168
|
+
stayed 22px against the 42px of the fields either side of it
|
|
169
|
+
(Keksdose live #294, measured in the browser: `span.textContent`
|
|
170
|
+
WAS `" "` and `getBoundingClientRect().height` was 0). U+00A0 is
|
|
171
|
+
not collapsible, so it holds the line. */}
|
|
172
|
+
{triggerText || " "}
|
|
173
|
+
</span>
|
|
174
|
+
</button>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A field-styled trigger that opens a portalled MiniCalendar. Shared by the
|
|
179
|
+
* single- and range-date pickers below. */
|
|
180
|
+
function DateField({
|
|
181
|
+
triggerText,
|
|
182
|
+
hasValue,
|
|
183
|
+
label,
|
|
184
|
+
disabled,
|
|
185
|
+
clearable,
|
|
186
|
+
clearLabel,
|
|
187
|
+
panelLabel,
|
|
188
|
+
className,
|
|
189
|
+
width,
|
|
190
|
+
onClear,
|
|
191
|
+
invalid,
|
|
192
|
+
children,
|
|
193
|
+
...rest
|
|
194
|
+
}: Omit<ComponentPropsWithoutRef<"div">, "children"> & {
|
|
195
|
+
triggerText: string;
|
|
196
|
+
hasValue: boolean;
|
|
197
|
+
label?: ReactNode;
|
|
198
|
+
disabled?: boolean;
|
|
199
|
+
clearable?: boolean;
|
|
200
|
+
/** Already resolved by the picker (prop > provider > English). */
|
|
201
|
+
clearLabel: string;
|
|
202
|
+
/** The popover panel's accessible name, resolved likewise. */
|
|
203
|
+
panelLabel: string;
|
|
204
|
+
invalid?: boolean;
|
|
205
|
+
className?: string;
|
|
206
|
+
/** Popover panel width; omit for the default (a bare calendar). */
|
|
207
|
+
width?: number;
|
|
208
|
+
onClear: () => void;
|
|
209
|
+
children: (close: () => void) => ReactNode;
|
|
210
|
+
}) {
|
|
211
|
+
const showClear = Boolean(clearable && hasValue && !disabled);
|
|
212
|
+
const id = useId();
|
|
213
|
+
const labelId = `${id}-label`;
|
|
214
|
+
const valueId = `${id}-value`;
|
|
215
|
+
const panelId = `${id}-panel`;
|
|
216
|
+
// Only a STRING label can be reused as a name; a ReactNode may be a whole row with
|
|
217
|
+
// its own interactive "?" hint in it, and naming a button with that reads the hint
|
|
218
|
+
// out as part of the field's name.
|
|
219
|
+
const named = typeof label === "string";
|
|
220
|
+
return (
|
|
221
|
+
// The caller's attributes land here, on the field's own box — the trigger inside is
|
|
222
|
+
// named by `aria-labelledby` and must keep the id pair it is given.
|
|
223
|
+
<div {...rest} className={cn("relative", className)}>
|
|
224
|
+
{label !== undefined && <FieldLabel>{label}</FieldLabel>}
|
|
225
|
+
{/* The visible FieldLabel is a plain span, not a `<label htmlFor>`, so it names
|
|
226
|
+
nothing on its own — this hidden twin is what the trigger is named by.
|
|
227
|
+
`aria-hidden` because a name reference reads a hidden element deliberately
|
|
228
|
+
(accname §4.3.1), and without it the label would be announced twice: once as
|
|
229
|
+
loose text before the button, once inside the button's own name.
|
|
230
|
+
`sr-only-fixed` rather than `sr-only` — see the note on the class in
|
|
231
|
+
tokens.css. */}
|
|
232
|
+
{named && (
|
|
233
|
+
<span id={labelId} aria-hidden className="sr-only-fixed">
|
|
234
|
+
{label}
|
|
235
|
+
</span>
|
|
236
|
+
)}
|
|
237
|
+
<Popover
|
|
238
|
+
width={width}
|
|
239
|
+
panelId={panelId}
|
|
240
|
+
// Named for what it is. Unnamed, it fell back to `popover.panel`, and a date
|
|
241
|
+
// field announced its calendar as "Popover" — in English, in every language.
|
|
242
|
+
labels={{ panel: panelLabel }}
|
|
243
|
+
trigger={({ open, toggle, ref }) => (
|
|
244
|
+
<DateFieldTrigger
|
|
245
|
+
open={open}
|
|
246
|
+
toggle={toggle}
|
|
247
|
+
triggerRef={ref}
|
|
248
|
+
triggerText={triggerText}
|
|
249
|
+
hasValue={hasValue}
|
|
250
|
+
// ALWAYS a name reference, never `undefined`. A `<button>` takes its
|
|
251
|
+
// accessible name from its contents, so an unlabelled trigger used to
|
|
252
|
+
// announce its own date text for free. `role="combobox"` does not —
|
|
253
|
+
// content is excluded from name computation for that role — so leaving
|
|
254
|
+
// this undefined made an unlabelled date field announce nothing at all.
|
|
255
|
+
// Named: "label, value". Unnamed: the value alone, which is what the
|
|
256
|
+
// button was saying before.
|
|
257
|
+
labelledBy={named ? `${labelId} ${valueId}` : valueId}
|
|
258
|
+
panelId={panelId}
|
|
259
|
+
valueId={valueId}
|
|
260
|
+
padded={label !== undefined}
|
|
261
|
+
disabled={disabled}
|
|
262
|
+
invalid={invalid}
|
|
263
|
+
/>
|
|
264
|
+
)}
|
|
265
|
+
>
|
|
266
|
+
{(close) => children(close)}
|
|
267
|
+
</Popover>
|
|
268
|
+
{showClear ? (
|
|
269
|
+
<button
|
|
270
|
+
type="button"
|
|
271
|
+
aria-label={clearLabel}
|
|
272
|
+
onClick={onClear}
|
|
273
|
+
className="absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]"
|
|
274
|
+
>
|
|
275
|
+
<X className="size-4" />
|
|
276
|
+
</button>
|
|
277
|
+
) : (
|
|
278
|
+
<Calendar
|
|
279
|
+
aria-hidden
|
|
280
|
+
className="pointer-events-none absolute right-2.5 top-1/2 size-4 -translate-y-1/2 text-[var(--text-placeholder)]"
|
|
281
|
+
/>
|
|
282
|
+
)}
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** One ‹ / › day-step button, sized to sit flush beside the field. */
|
|
288
|
+
function StepButton({
|
|
289
|
+
icon: Icon,
|
|
290
|
+
label,
|
|
291
|
+
disabled,
|
|
292
|
+
onClick,
|
|
293
|
+
className,
|
|
294
|
+
}: {
|
|
295
|
+
icon: ComponentType<{ className?: string }>;
|
|
296
|
+
label: string;
|
|
297
|
+
disabled: boolean;
|
|
298
|
+
onClick: () => void;
|
|
299
|
+
/** The button's corners in the joined group (see DatePicker). */
|
|
300
|
+
className?: string;
|
|
301
|
+
}) {
|
|
302
|
+
return (
|
|
303
|
+
<Tooltip label={label} portal>
|
|
304
|
+
<button
|
|
305
|
+
type="button"
|
|
306
|
+
aria-label={label}
|
|
307
|
+
disabled={disabled}
|
|
308
|
+
onClick={onClick}
|
|
309
|
+
className={cn(
|
|
310
|
+
FIELD_BASE,
|
|
311
|
+
// FIELD_BASE is `block w-full` for text inputs; a step button is neither, and
|
|
312
|
+
// px-3 would make it wider than it needs to be. twMerge lets these win.
|
|
313
|
+
"relative flex h-full w-10 shrink-0 items-center justify-center px-0 text-[var(--text-muted)]",
|
|
314
|
+
"hover:bg-[var(--bg-hover)] hover:text-[var(--text-secondary)]",
|
|
315
|
+
// Raised while hovered or focused, so the shared border and the focus ring are
|
|
316
|
+
// drawn on top of the neighbour they overlap by a pixel.
|
|
317
|
+
"hover:z-10 focus-visible:z-10",
|
|
318
|
+
// Dimmed ICON, not a dimmed box: at 40% opacity the whole button — border
|
|
319
|
+
// included — faded out of the group and read as a broken, detached control.
|
|
320
|
+
"disabled:cursor-not-allowed disabled:text-[var(--text-placeholder)] disabled:opacity-60 disabled:hover:bg-[var(--bg-surface)]",
|
|
321
|
+
className,
|
|
322
|
+
)}
|
|
323
|
+
>
|
|
324
|
+
<Icon className="size-4" />
|
|
325
|
+
</button>
|
|
326
|
+
</Tooltip>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface DatePickerProps extends DatePickerBaseProps {
|
|
331
|
+
/** ISO "YYYY-MM-DD", or "" for empty. */
|
|
332
|
+
value: string;
|
|
333
|
+
onChange: (iso: string) => void;
|
|
334
|
+
/**
|
|
335
|
+
* Flank the field with ‹ › buttons that move the value one day. For fields whose
|
|
336
|
+
* typical edit is a day or two — opening a calendar to go "yesterday" is three
|
|
337
|
+
* interactions for what should be one.
|
|
338
|
+
*
|
|
339
|
+
* Off by default: on a filter or a far-away date the buttons are dead weight, and
|
|
340
|
+
* they cost ~5rem of width that a narrow layout may not have.
|
|
341
|
+
*/
|
|
342
|
+
step?: boolean;
|
|
343
|
+
/** Accessible names for the step buttons. Optional: they resolve from
|
|
344
|
+
* `datePicker.previousDay` / `nextDay` in `<UiKitProvider labels>`, then from the
|
|
345
|
+
* English defaults. This prop wins over both, for the one field that says it
|
|
346
|
+
* differently. */
|
|
347
|
+
stepLabels?: { prev: string; next: string };
|
|
348
|
+
/**
|
|
349
|
+
* Today's date as ISO "YYYY-MM-DD". Adds a jump-to-today button beside the field,
|
|
350
|
+
* disabled once the value already is that day.
|
|
351
|
+
*
|
|
352
|
+
* Passed in rather than read from a clock here: a component that decides what "today"
|
|
353
|
+
* is cannot be tested at a fixed date, and the consumer already has one definition of
|
|
354
|
+
* it. The button is always RENDERED — going flat instead of disappearing — because a
|
|
355
|
+
* control that comes and goes with the value reflows whatever sits beside it, which
|
|
356
|
+
* is the report this exists to answer.
|
|
357
|
+
*/
|
|
358
|
+
today?: string;
|
|
359
|
+
/** Accessible name for the today button; wins over `datePicker.today`. */
|
|
360
|
+
todayLabel?: string;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The picker's own label props, folded into one `datePicker` override so they sit at
|
|
365
|
+
* the top of the same precedence chain as everything else: prop > provider > English.
|
|
366
|
+
* They predate the provider and stay public API, which is why they are not simply
|
|
367
|
+
* replaced by a `labels` prop.
|
|
368
|
+
*/
|
|
369
|
+
function useDatePickerLabels(
|
|
370
|
+
clearLabel: string | undefined,
|
|
371
|
+
stepLabels: { prev: string; next: string } | undefined,
|
|
372
|
+
todayLabel: string | undefined,
|
|
373
|
+
): DatePickerLabels {
|
|
374
|
+
const prev = stepLabels?.prev;
|
|
375
|
+
const next = stepLabels?.next;
|
|
376
|
+
const fromProps = useMemo(() => {
|
|
377
|
+
const out: Partial<DatePickerLabels> = {};
|
|
378
|
+
if (clearLabel !== undefined) out.clear = clearLabel;
|
|
379
|
+
if (prev !== undefined) out.previousDay = prev;
|
|
380
|
+
if (next !== undefined) out.nextDay = next;
|
|
381
|
+
if (todayLabel !== undefined) out.today = todayLabel;
|
|
382
|
+
return out;
|
|
383
|
+
}, [clearLabel, prev, next, todayLabel]);
|
|
384
|
+
return useKitLabels("datePicker", DEFAULT_DATE_PICKER_LABELS, fromProps);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Single-date picker: a field showing the formatted date, opening a calendar. */
|
|
388
|
+
export function DatePicker({
|
|
389
|
+
value,
|
|
390
|
+
onChange,
|
|
391
|
+
locale: localeProp,
|
|
392
|
+
placeholder,
|
|
393
|
+
min,
|
|
394
|
+
max,
|
|
395
|
+
formatOptions,
|
|
396
|
+
formatValue,
|
|
397
|
+
step,
|
|
398
|
+
stepLabels,
|
|
399
|
+
today,
|
|
400
|
+
todayLabel,
|
|
401
|
+
className,
|
|
402
|
+
calendarLabels,
|
|
403
|
+
label,
|
|
404
|
+
clearable,
|
|
405
|
+
clearLabel,
|
|
406
|
+
disabled,
|
|
407
|
+
invalid,
|
|
408
|
+
...rest
|
|
409
|
+
}: DatePickerProps) {
|
|
410
|
+
const locale = useKitLocale(localeProp);
|
|
411
|
+
const text = useDatePickerLabels(clearLabel, stepLabels, todayLabel);
|
|
412
|
+
const render = formatValue ?? ((iso: string) => formatDate(iso, locale, formatOptions));
|
|
413
|
+
// With a step or a today button beside it the field is no longer the outermost
|
|
414
|
+
// element — the flex row at the bottom is, and a caller's attributes belong on
|
|
415
|
+
// whichever of the two is actually the root. Naming the shared props rather than
|
|
416
|
+
// letting `...rest` carry them is what makes that choice possible.
|
|
417
|
+
const wrapped = Boolean(step || today);
|
|
418
|
+
const field = (
|
|
419
|
+
<DateField
|
|
420
|
+
{...(wrapped ? {} : rest)}
|
|
421
|
+
label={label}
|
|
422
|
+
clearable={clearable}
|
|
423
|
+
clearLabel={text.clear}
|
|
424
|
+
panelLabel={text.panel}
|
|
425
|
+
disabled={disabled}
|
|
426
|
+
invalid={invalid}
|
|
427
|
+
className={step ? "min-w-0 flex-1" : className}
|
|
428
|
+
hasValue={Boolean(value)}
|
|
429
|
+
triggerText={value ? render(value) : (placeholder ?? "")}
|
|
430
|
+
onClear={() => onChange("")}
|
|
431
|
+
>
|
|
432
|
+
{(close) => (
|
|
433
|
+
<MiniCalendar
|
|
434
|
+
mode="single"
|
|
435
|
+
focusOnOpen
|
|
436
|
+
from={value}
|
|
437
|
+
to={value}
|
|
438
|
+
locale={locale}
|
|
439
|
+
min={min}
|
|
440
|
+
max={max}
|
|
441
|
+
labels={calendarLabels}
|
|
442
|
+
onSelect={(iso) => {
|
|
443
|
+
onChange(iso);
|
|
444
|
+
close();
|
|
445
|
+
}}
|
|
446
|
+
/>
|
|
447
|
+
)}
|
|
448
|
+
</DateField>
|
|
449
|
+
);
|
|
450
|
+
if (!wrapped) return field;
|
|
451
|
+
|
|
452
|
+
// An empty field has nothing to step from, so both buttons are dead until a date
|
|
453
|
+
// is picked. Bounds are compared as strings: "YYYY-MM-DD" sorts chronologically.
|
|
454
|
+
const target = (days: number) => (value ? addDaysIso(value, days) : "");
|
|
455
|
+
const outOfBounds = (iso: string) => Boolean((min && iso < min) || (max && iso > max));
|
|
456
|
+
const blocked = (days: number) => {
|
|
457
|
+
const next = target(days);
|
|
458
|
+
if (!next || disabled) return true;
|
|
459
|
+
return outOfBounds(next);
|
|
460
|
+
};
|
|
461
|
+
return (
|
|
462
|
+
// ONE joined control, not three boxes in a row: the buttons and the field share
|
|
463
|
+
// their borders (each piece overlaps the previous by a pixel) and only the outer
|
|
464
|
+
// ends are rounded — the button-group shape, so ‹ date › reads as one field with
|
|
465
|
+
// controls rather than a field with loose buttons parked beside it, which is what
|
|
466
|
+
// the `gap-1` version looked like.
|
|
467
|
+
//
|
|
468
|
+
// items-stretch, not items-center: the buttons match the field's height, which
|
|
469
|
+
// varies with whether it carries a floating label. The field's trigger is nested
|
|
470
|
+
// inside DateField, so its inner corners are squared from here.
|
|
471
|
+
<div
|
|
472
|
+
{...rest}
|
|
473
|
+
className={cn(
|
|
474
|
+
"flex items-stretch [&>*:not(:first-child)]:-ms-px",
|
|
475
|
+
step && "[&_[role=combobox]]:rounded-s-none",
|
|
476
|
+
(step || today) && "[&_[role=combobox]]:rounded-e-none",
|
|
477
|
+
"[&_[role=combobox]:focus-visible]:relative [&_[role=combobox]:focus-visible]:z-10",
|
|
478
|
+
className,
|
|
479
|
+
)}
|
|
480
|
+
>
|
|
481
|
+
{step && (
|
|
482
|
+
<StepButton
|
|
483
|
+
icon={ChevronLeft}
|
|
484
|
+
label={text.previousDay}
|
|
485
|
+
disabled={blocked(-1)}
|
|
486
|
+
onClick={() => onChange(target(-1))}
|
|
487
|
+
className="rounded-e-none"
|
|
488
|
+
/>
|
|
489
|
+
)}
|
|
490
|
+
{field}
|
|
491
|
+
{step && (
|
|
492
|
+
<StepButton
|
|
493
|
+
icon={ChevronRight}
|
|
494
|
+
label={text.nextDay}
|
|
495
|
+
disabled={blocked(1)}
|
|
496
|
+
onClick={() => onChange(target(1))}
|
|
497
|
+
className={cn("rounded-s-none", today && "rounded-e-none")}
|
|
498
|
+
/>
|
|
499
|
+
)}
|
|
500
|
+
{today && (
|
|
501
|
+
<StepButton
|
|
502
|
+
icon={CalendarClock}
|
|
503
|
+
label={text.today}
|
|
504
|
+
disabled={Boolean(disabled) || value === today || outOfBounds(today)}
|
|
505
|
+
onClick={() => onChange(today)}
|
|
506
|
+
className="rounded-s-none"
|
|
507
|
+
/>
|
|
508
|
+
)}
|
|
509
|
+
</div>
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export interface DateRangePickerPreset {
|
|
514
|
+
label: ReactNode;
|
|
515
|
+
from: string;
|
|
516
|
+
to: string;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export interface DateRangePickerProps extends DatePickerBaseProps {
|
|
520
|
+
from: string;
|
|
521
|
+
to: string;
|
|
522
|
+
onChange: (from: string, to: string) => void;
|
|
523
|
+
/** Separator between the two formatted dates in the trigger (default " – "). */
|
|
524
|
+
separator?: string;
|
|
525
|
+
/** Optional named ranges rendered as a left column (last month / YTD / …). */
|
|
526
|
+
presets?: DateRangePickerPreset[];
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Two-date range picker: click a start then an end; closes once both are set.
|
|
530
|
+
* With `presets`, a left column of named ranges is shown beside the calendar. */
|
|
531
|
+
export function DateRangePicker({
|
|
532
|
+
from,
|
|
533
|
+
to,
|
|
534
|
+
onChange,
|
|
535
|
+
locale: localeProp,
|
|
536
|
+
placeholder,
|
|
537
|
+
min,
|
|
538
|
+
max,
|
|
539
|
+
formatOptions,
|
|
540
|
+
formatValue,
|
|
541
|
+
separator = " – ",
|
|
542
|
+
presets,
|
|
543
|
+
calendarLabels,
|
|
544
|
+
label,
|
|
545
|
+
clearable,
|
|
546
|
+
clearLabel,
|
|
547
|
+
disabled,
|
|
548
|
+
invalid,
|
|
549
|
+
...rest
|
|
550
|
+
}: DateRangePickerProps) {
|
|
551
|
+
const locale = useKitLocale(localeProp);
|
|
552
|
+
const text = useDatePickerLabels(clearLabel, undefined, undefined);
|
|
553
|
+
const render = formatValue ?? ((iso: string) => formatDate(iso, locale, formatOptions));
|
|
554
|
+
const a = from ? render(from) : "";
|
|
555
|
+
const b = to ? render(to) : "";
|
|
556
|
+
const triggerText = from
|
|
557
|
+
? to
|
|
558
|
+
? `${a}${separator}${b}`
|
|
559
|
+
: `${a}${separator}…`
|
|
560
|
+
: (placeholder ?? "");
|
|
561
|
+
const hasPresets = Boolean(presets && presets.length > 0);
|
|
562
|
+
const calendar = (close: () => void) => (
|
|
563
|
+
<MiniCalendar
|
|
564
|
+
focusOnOpen
|
|
565
|
+
from={from}
|
|
566
|
+
to={to}
|
|
567
|
+
locale={locale}
|
|
568
|
+
min={min}
|
|
569
|
+
max={max}
|
|
570
|
+
labels={calendarLabels}
|
|
571
|
+
onSelect={(f, t) => {
|
|
572
|
+
onChange(f, t);
|
|
573
|
+
// Two-click range: only dismiss once both ends are chosen.
|
|
574
|
+
if (f && t) close();
|
|
575
|
+
}}
|
|
576
|
+
/>
|
|
577
|
+
);
|
|
578
|
+
return (
|
|
579
|
+
<DateField
|
|
580
|
+
{...rest}
|
|
581
|
+
label={label}
|
|
582
|
+
clearable={clearable}
|
|
583
|
+
clearLabel={text.clear}
|
|
584
|
+
panelLabel={text.rangePanel}
|
|
585
|
+
disabled={disabled}
|
|
586
|
+
invalid={invalid}
|
|
587
|
+
// Widen so the preset column sits beside the calendar (default otherwise).
|
|
588
|
+
width={hasPresets ? 440 : undefined}
|
|
589
|
+
hasValue={Boolean(from || to)}
|
|
590
|
+
triggerText={triggerText}
|
|
591
|
+
onClear={() => onChange("", "")}
|
|
592
|
+
>
|
|
593
|
+
{(close) =>
|
|
594
|
+
hasPresets ? (
|
|
595
|
+
<div className="flex gap-3">
|
|
596
|
+
{/* `border-e`/`pe`, not `-r`: the preset column is on the START side, and the
|
|
597
|
+
rule between it and the calendar has to follow it in a right-to-left UI. */}
|
|
598
|
+
<div className="flex w-32 shrink-0 flex-col gap-0.5 border-e border-[var(--border)] pe-2">
|
|
599
|
+
{presets!.map((p, i) => {
|
|
600
|
+
const selected = p.from === from && p.to === to;
|
|
601
|
+
return (
|
|
602
|
+
<button
|
|
603
|
+
key={i}
|
|
604
|
+
type="button"
|
|
605
|
+
onClick={() => {
|
|
606
|
+
onChange(p.from, p.to);
|
|
607
|
+
close();
|
|
608
|
+
}}
|
|
609
|
+
className={cn(
|
|
610
|
+
"rounded px-2 py-1.5 text-start text-xs",
|
|
611
|
+
selected
|
|
612
|
+
? "bg-[var(--bg-active)] font-medium text-[var(--text-primary)]"
|
|
613
|
+
: "text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]",
|
|
614
|
+
)}
|
|
615
|
+
>
|
|
616
|
+
{p.label}
|
|
617
|
+
</button>
|
|
618
|
+
);
|
|
619
|
+
})}
|
|
620
|
+
</div>
|
|
621
|
+
{/* `flex-1`: the calendar takes the rest of the panel. Content-sized it was
|
|
622
|
+
seven tiny cells beside a wide preset column. */}
|
|
623
|
+
<div className="min-w-0 flex-1">{calendar(close)}</div>
|
|
624
|
+
</div>
|
|
625
|
+
) : (
|
|
626
|
+
calendar(close)
|
|
627
|
+
)
|
|
628
|
+
}
|
|
629
|
+
</DateField>
|
|
630
|
+
);
|
|
631
|
+
}
|