@eifi1/ui-kit 0.4.1 → 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 +89 -19
- 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 +74 -19
- package/dist/components/dropdown.js +72 -22
- 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 +21 -7
- package/dist/components/file-dropzone.js +28 -7
- 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 +21 -2
- package/dist/components/number-input.js +2 -1
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +25 -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 +5 -3
- package/dist/components/user-avatar.js +4 -2
- 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 +14 -1
- package/dist/theme/palette-presets.js +231 -3
- 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 +66 -13
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/mini-calendar.tsx"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { parseIsoDate, sameYmd, toLocalIso } from \"../lib/dates\";\n\nexport interface MiniCalendarProps {\n from: string;\n to: string;\n locale: string;\n onSelect: (from: string, to: string) => void;\n /** `\"range\"` (default) = two-click from→to; `\"single\"` = one click selects a\n * single day (emitted as `onSelect(iso, iso)`). */\n mode?: \"single\" | \"range\";\n /** Optional inclusive ISO bounds; days outside `[min, max]` are disabled. */\n min?: string;\n max?: string;\n /** Screen-reader names for the two month arrows. The package carries no\n * translation catalog (see the README), so every user-facing string is a prop\n * with an English default — these two were the exception, and a German app\n * reached this component through a bare re-export and announced them in\n * English on a page whose `<html lang>` says `de`. */\n labels?: { previousMonth?: string; nextMonth?: string };\n}\n\n/**\n * Month-grid range picker used by the data-table date filter. Click once to set\n * the start (and clear the end), click again to set the end; clicking with a\n * full range already selected starts over. Monday-first, locale-aware labels.\n * In `single` mode each click selects one day. Days outside `min`/`max` (when\n * given) are disabled.\n */\nexport function MiniCalendar({\n from,\n to,\n locale,\n onSelect,\n mode = \"range\",\n min,\n max,\n labels,\n}: MiniCalendarProps) {\n const fromDate = parseIsoDate(from);\n const toDate = parseIsoDate(to);\n const minDate = min ? parseIsoDate(min) : null;\n const maxDate = max ? parseIsoDate(max) : null;\n const isDisabled = (d: Date) => Boolean((minDate && d < minDate) || (maxDate && d > maxDate));\n const initial = fromDate ?? toDate ?? new Date();\n const [view, setView] = useState<{ year: number; month: number }>({\n year: initial.getFullYear(),\n month: initial.getMonth(),\n });\n const [lastKey, setLastKey] = useState(`${from}|${to}`);\n const currentKey = `${from}|${to}`;\n if (currentKey !== lastKey) {\n setLastKey(currentKey);\n const next = parseIsoDate(from) ?? parseIsoDate(to);\n if (next && (next.getFullYear() !== view.year || next.getMonth() !== view.month)) {\n setView({ year: next.getFullYear(), month: next.getMonth() });\n }\n }\n\n const firstOfMonth = new Date(view.year, view.month, 1);\n const lastOfMonth = new Date(view.year, view.month + 1, 0);\n // Monday-first grid\n const startWeekday = (firstOfMonth.getDay() + 6) % 7;\n const cells: (Date | null)[] = [];\n for (let i = 0; i < startWeekday; i++) cells.push(null);\n for (let d = 1; d <= lastOfMonth.getDate(); d++) cells.push(new Date(view.year, view.month, d));\n while (cells.length % 7 !== 0) cells.push(null);\n\n const monthLabel = firstOfMonth.toLocaleDateString(locale, { month: \"long\", year: \"numeric\" });\n\n // Monday..Sunday short weekday labels via locale\n const weekdayLabels = useMemo(() => {\n const ref = new Date(2024, 0, 1); // a Monday\n return Array.from({ length: 7 }, (_, i) => {\n const d = new Date(ref);\n d.setDate(ref.getDate() + i);\n return d.toLocaleDateString(locale, { weekday: \"narrow\" });\n });\n }, [locale]);\n\n const move = (delta: number) => {\n setView((v) => {\n const d = new Date(v.year, v.month + delta, 1);\n return { year: d.getFullYear(), month: d.getMonth() };\n });\n };\n\n const handleClick = (d: Date) => {\n const iso = toLocalIso(d);\n if (mode === \"single\") {\n onSelect(iso, iso);\n return;\n }\n const f = parseIsoDate(from);\n const tt = parseIsoDate(to);\n if (!f || (f && tt)) {\n // start a new selection\n onSelect(iso, \"\");\n return;\n }\n // f set, tt empty\n if (d < f) {\n onSelect(iso, toLocalIso(f));\n } else {\n onSelect(toLocalIso(f), iso);\n }\n };\n\n const today = new Date();\n const inRange = (d: Date) => {\n if (!fromDate || !toDate) return false;\n return d >= fromDate && d <= toDate;\n };\n\n return (\n <div className=\"select-none\">\n <div className=\"flex items-center justify-between pb-1\">\n <button\n type=\"button\"\n onClick={() => move(-1)}\n aria-label={labels?.previousMonth ?? \"Previous month\"}\n className=\"rounded p-1 text-slate-500 hover:bg-slate-100 dark:text-slate-400 dark:hover:bg-slate-800\"\n >\n <ChevronLeft className=\"size-4\" />\n </button>\n <div className=\"text-xs font-medium capitalize text-slate-700 dark:text-slate-200\">{monthLabel}</div>\n <button\n type=\"button\"\n onClick={() => move(1)}\n aria-label={labels?.nextMonth ?? \"Next month\"}\n className=\"rounded p-1 text-slate-500 hover:bg-slate-100 dark:text-slate-400 dark:hover:bg-slate-800\"\n >\n <ChevronRight className=\"size-4\" />\n </button>\n </div>\n <div className=\"grid grid-cols-7 gap-0.5 text-center text-[10px] font-medium uppercase text-slate-400 dark:text-slate-500\">\n {weekdayLabels.map((w, i) => (\n <div key={i} className=\"py-0.5\">{w}</div>\n ))}\n </div>\n <div className=\"grid grid-cols-7 gap-0.5\">\n {cells.map((d, i) => {\n if (!d) return <div key={i} className=\"h-7\" />;\n const disabled = isDisabled(d);\n const isStart = !disabled && fromDate && sameYmd(d, fromDate);\n const isEnd = !disabled && toDate && sameYmd(d, toDate);\n const isToday = sameYmd(d, today);\n const isInRange = !disabled && inRange(d) && !isStart && !isEnd;\n return (\n <button\n key={i}\n type=\"button\"\n disabled={disabled}\n onClick={() => handleClick(d)}\n className={cn(\n \"h-7 text-xs rounded transition-colors\",\n disabled\n ? \"cursor-not-allowed text-slate-300 dark:text-slate-600\"\n : isStart || isEnd\n ? \"bg-sky-600 text-white hover:bg-sky-700 dark:bg-sky-500 dark:hover:bg-sky-400\"\n : isInRange\n ? \"bg-sky-100 text-sky-800 hover:bg-sky-200 dark:bg-sky-500/20 dark:text-sky-200\"\n : \"text-slate-700 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-800\",\n isToday && !isStart && !isEnd && !isInRange && !disabled && \"ring-1 ring-inset ring-slate-300 dark:ring-slate-600\",\n )}\n >\n {d.getDate()}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":"AAsHM,SAOI,KAPJ;AAtHN,SAAS,SAAS,gBAAgB;AAClC,SAAS,aAAa,oBAAoB;AAC1C,SAAS,UAAU;AACnB,SAAS,cAAc,SAAS,kBAAkB;AA4B3C,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,E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EC,YAAE,QAAQ;AAAA;AAAA,QAhBN;AAAA,MAiBP;AAAA,IAEJ,CAAC,GACH;AAAA,KACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/mini-calendar.tsx"],"sourcesContent":["import { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent } from \"react\";\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { useAnnounce } from \"../hooks/use-announce\";\nimport { parseIsoDate, sameYmd, toLocalIso } from \"../lib/dates\";\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\n\n/**\n * Every string this calendar can speak — the `miniCalendar` namespace of\n * `<UiKitProvider labels>`, overridable per instance through the `labels` prop. The\n * package carries no translation catalog (see the README), so the English defaults\n * below are a starting point and not a commitment. `previousMonth`/`nextMonth` were already props for the\n * reason the audit records: a German app reached this component through a bare\n * re-export and announced its two icon-only arrows in English on a page whose\n * `<html lang>` says `de`.\n *\n * The month caption is deliberately NOT here. It is produced by `Intl` from the\n * `locale` prop, so it is already in the user's language, and the grid takes its\n * accessible name from that element rather than from a string someone has to\n * translate a second time.\n *\n * The ones that interpolate a date are FUNCTIONS taking the formatted date, for the\n * reason `DataTableLabels` gives for its counted strings: a value glued into an\n * English template literal is untranslatable, and the grammar around a date moves\n * with it in most languages.\n */\nexport interface MiniCalendarLabels {\n previousMonth: string;\n nextMonth: string;\n /**\n * Accessible name of one day cell, given that day formatted in `locale`\n * (\"Monday, 14 September 2026\").\n *\n * The name has to carry the WHOLE date. The visible text of a cell is the day\n * number alone, and \"14\" on its own tells a screen-reader user nothing — not the\n * month they have arrowed into, not the year, not the weekday they are picking.\n */\n day: (date: string) => string;\n /** Range mode: what the NEXT click will set. Spoken after every click, and the\n * grid's description while the panel is open. */\n chooseStart: string;\n chooseEnd: string;\n /** Range mode: spoken after the click that set the start. */\n startSelected: (date: string) => string;\n /** Range mode: spoken after the click that completed the range. */\n rangeSelected: (from: string, to: string) => string;\n}\n\n/** English defaults. Exported as the `miniCalendar` namespace of `UiKitLabels`\n * (src/i18n), the complete reference a translation is written against. */\nexport const DEFAULT_MINI_CALENDAR_LABELS: MiniCalendarLabels = {\n previousMonth: \"Previous month\",\n nextMonth: \"Next month\",\n day: (date) => date,\n chooseStart: \"Choose a start date\",\n chooseEnd: \"Choose an end date\",\n startSelected: (date) => `${date} selected as the start. Choose an end date.`,\n rangeSelected: (from, to) => `${from} to ${to} selected. Choose a start date to begin again.`,\n};\n\n/**\n * How a day is spoken. The weekday is in there on purpose: picking a date is very\n * often picking a *day of the week* (\"the first Monday\"), and a grid that makes you\n * count columns to find one is a grid you cannot use without sight.\n */\nconst DAY_NAME_FORMAT: Intl.DateTimeFormatOptions = {\n weekday: \"long\",\n day: \"numeric\",\n month: \"long\",\n year: \"numeric\",\n};\n\n/**\n * `onSelect` is omitted from the `<div>` attributes and kept as this component's own:\n * the DOM event of that name is a text-selection event taking one argument, and this one\n * answers with the two ISO dates a range is made of. Everything else a `<div>` takes\n * passes through to the root, so a tour anchor or a test id can find the calendar —\n * before this, a closed prop list dropped both (audit §api-design).\n */\nexport interface MiniCalendarProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSelect\"> {\n from: string;\n to: string;\n /**\n * BCP 47 tag for the month caption, the weekday heads, the day numbers and the\n * spoken dates. Optional since the kit grew `<UiKitProvider locale>`: a calendar\n * NESTED in another kit component (the data table's date filter) has no call site\n * of its own to pass one at, so it reads the provider's. Without either, `Intl`\n * uses the runtime's default.\n */\n locale?: string;\n /**\n * The weekday the grid starts on, `0` = Sunday … `6` = Saturday (as `Date#getDay`).\n * Defaults to the LOCALE's first day — Monday in most of Europe, Sunday in the US,\n * Saturday in much of the Arab world — which is what the user's own wall calendar\n * does. It was hard-wired to Monday before, which is wrong for most of the people\n * who use a Sunday-first calendar and invisible to the people who wrote this one.\n */\n weekStartsOn?: WeekDay;\n onSelect: (from: string, to: string) => void;\n /** `\"range\"` (default) = two-click from→to; `\"single\"` = one click selects a\n * single day (emitted as `onSelect(iso, iso)`). */\n mode?: \"single\" | \"range\";\n /** Optional inclusive ISO bounds; days outside `[min, max]` are disabled. */\n min?: string;\n max?: string;\n /** User-facing strings; see {@link MiniCalendarLabels}. */\n labels?: Partial<MiniCalendarLabels>;\n /**\n * Take focus to the day the grid opens on — the selected one, or today — when this\n * calendar mounts. For a panel that opened BECAUSE the user asked to pick a date:\n * landing them on the day they are editing is the difference between one arrow key\n * and a hunt through 42 cells.\n *\n * Off by default, and not called `autoFocus`, because it is not the same promise as\n * the DOM attribute of that name: a calendar rendered INLINE (the data-table's\n * column filter draws one above its from/to inputs) must not take the page's focus\n * merely by existing.\n */\n focusOnOpen?: boolean;\n /** Extra classes for the calendar's root. */\n className?: string;\n}\n\nexport type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * The first day of the week in `locale`, as a `Date#getDay` index.\n *\n * `Intl.Locale#getWeekInfo()` is the standard spelling; V8 shipped it first as the\n * `weekInfo` accessor, and Firefox has neither yet — hence both reads and a Monday\n * fallback, which is ISO 8601 and what this grid did unconditionally before. Its\n * `firstDay` counts 1 = Monday … 7 = Sunday, so `% 7` maps it onto `getDay`.\n */\nfunction localeWeekStart(locale: string | undefined): WeekDay {\n try {\n const tag = locale ?? new Intl.DateTimeFormat().resolvedOptions().locale;\n const loc = new Intl.Locale(tag) as Intl.Locale & {\n getWeekInfo?: () => { firstDay: number };\n weekInfo?: { firstDay: number };\n };\n const firstDay = (loc.getWeekInfo?.() ?? loc.weekInfo)?.firstDay;\n if (typeof firstDay === \"number\") return (firstDay % 7) as WeekDay;\n } catch {\n // A malformed tag throws from `Intl.Locale`; the calendar still has to render.\n }\n return 1;\n}\n\n/** Where `d` sits in a week that starts on `weekStart` (the first column = 0). */\nconst weekdayIndex = (d: Date, weekStart: WeekDay) => (d.getDay() - weekStart + 7) % 7;\n\n/** Move `d` by whole months, keeping the day of the month where the target has one.\n * `setMonth` alone ROLLS OVER — 31 January + 1 month is 3 March — which would skip\n * February entirely for anyone paging through the year with PageDown. */\nfunction stepMonths(d: Date, months: number): Date {\n const day = d.getDate();\n const out = new Date(d.getFullYear(), d.getMonth() + months, 1);\n const lastOfTarget = new Date(out.getFullYear(), out.getMonth() + 1, 0).getDate();\n out.setDate(Math.min(day, lastOfTarget));\n return out;\n}\n\n/**\n * Month-grid range picker used by the data-table date filter. Click once to set\n * the start (and clear the end), click again to set the end; clicking with a\n * full range already selected starts over. The week starts where the locale's does\n * (or at `weekStartsOn`), and every label comes from `Intl` in that locale.\n * In `single` mode each click selects one day. Days outside `min`/`max` (when\n * given) are disabled.\n *\n * **It is a grid, in the APG sense** (audit §a11y, \"MiniCalendar is unusable with a\n * keyboard or screen reader\"). Before this it was 42 buttons in a `grid-cols-7` div:\n * every one of them in the tab order, none of them saying which date it was, and no\n * way to reach next month without a mouse. Now the month is a `role=\"grid\"` of rows\n * and `gridcell`s, exactly one day is tabbable (the roving tabindex), and the arrows\n * walk the calendar the way the pattern says — day, week, month — crossing into the\n * neighbouring month by MOVING the grid rather than stopping at its edge.\n *\n * Out-of-range days are `aria-disabled` rather than `disabled`, which is the APG\n * guidance and not a shortcut: a `disabled` button cannot be focused, so a bounded\n * month would have holes that the roving tabindex falls into. They stay reachable and\n * readable, and the click handler is what refuses them.\n */\nexport function MiniCalendar({\n from,\n to,\n locale: localeProp,\n weekStartsOn,\n onSelect,\n mode = \"range\",\n min,\n max,\n labels: labelsProp,\n focusOnOpen,\n className,\n ...rest\n}: MiniCalendarProps) {\n const labels = useKitLabels(\"miniCalendar\", DEFAULT_MINI_CALENDAR_LABELS, labelsProp);\n const locale = useKitLocale(localeProp);\n const weekStart = useMemo(\n () => weekStartsOn ?? localeWeekStart(locale),\n [weekStartsOn, locale],\n );\n // Day numbers through `Intl` too: `getDate()` is always ASCII digits, and a locale\n // that writes its own (Arabic, Persian, Bengali …) would get a grid of foreign\n // numerals under a caption in its own script.\n const dayNumber = useMemo(() => new Intl.NumberFormat(locale), [locale]);\n const fromDate = parseIsoDate(from);\n const toDate = parseIsoDate(to);\n const minDate = min ? parseIsoDate(min) : null;\n const maxDate = max ? parseIsoDate(max) : null;\n const isDisabled = (d: Date) => Boolean((minDate && d < minDate) || (maxDate && d > maxDate));\n\n const gridRef = useRef<HTMLDivElement>(null);\n const id = useId();\n const monthId = `${id}-month`;\n const hintId = `${id}-hint`;\n const { announce, regionProps } = useAnnounce();\n\n /**\n * The day that holds the tab order, and with it the visible month — one piece of\n * state, not two, because they cannot be allowed to disagree: a tabbable cell in a\n * month that is not on screen is a tab stop that focuses nothing.\n *\n * Starts on the selection, or on today when there is none, pulled inside `[min, max]`\n * so a bounded calendar opens on a day it will actually let you pick.\n */\n const [activeIso, setActiveIso] = useState(() => {\n const start = fromDate ?? toDate ?? new Date();\n if (minDate && start < minDate) return toLocalIso(minDate);\n if (maxDate && start > maxDate) return toLocalIso(maxDate);\n return toLocalIso(start);\n });\n\n // Follow the caller's value when it changes from outside (a preset, a cleared\n // filter, a form reset). Written as a render-phase adjustment rather than an effect\n // so the grid never paints one frame on the old month.\n const [lastValue, setLastValue] = useState({ from, to });\n if (lastValue.from !== from || lastValue.to !== to) {\n // Follow the end that actually CHANGED, not `from` unconditionally. Picking the\n // end of a range that spans months used to send the grid back to the start's\n // month — which with a roving tabindex means the cell the user just activated is\n // no longer rendered, and their focus goes with it to `<body>`.\n const changed = lastValue.from !== from ? from : to;\n setLastValue({ from, to });\n const next = parseIsoDate(changed) ?? fromDate ?? toDate;\n if (next && toLocalIso(next) !== activeIso) setActiveIso(toLocalIso(next));\n }\n\n const activeDate = parseIsoDate(activeIso) ?? new Date();\n const view = { year: activeDate.getFullYear(), month: activeDate.getMonth() };\n\n const firstOfMonth = new Date(view.year, view.month, 1);\n const lastOfMonth = new Date(view.year, view.month + 1, 0);\n // Leading blanks up to the first of the month, counted from the week's first day.\n const startWeekday = weekdayIndex(firstOfMonth, weekStart);\n const cells: (Date | null)[] = [];\n for (let i = 0; i < startWeekday; i++) cells.push(null);\n for (let d = 1; d <= lastOfMonth.getDate(); d++) cells.push(new Date(view.year, view.month, d));\n while (cells.length % 7 !== 0) cells.push(null);\n const weeks: (Date | null)[][] = [];\n for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));\n\n const monthLabel = firstOfMonth.toLocaleDateString(locale, { month: \"long\", year: \"numeric\" });\n const formatDay = (d: Date) => d.toLocaleDateString(locale, DAY_NAME_FORMAT);\n\n // Weekday labels via locale, from the week's first day: the narrow one for the\n // column head, the long one as its accessible name — \"M\" is the same letter for\n // Monday, March and May, and a column header is the one place a screen reader\n // reads it on its own.\n const weekdayLabels = useMemo(() => {\n const ref = new Date(2024, 0, 7 + weekStart); // 7 January 2024 was a Sunday\n return Array.from({ length: 7 }, (_, i) => {\n const d = new Date(ref);\n d.setDate(ref.getDate() + i);\n return {\n narrow: d.toLocaleDateString(locale, { weekday: \"narrow\" }),\n long: d.toLocaleDateString(locale, { weekday: \"long\" }),\n };\n });\n }, [locale, weekStart]);\n\n /**\n * A day whose cell has to take focus once it exists. Arrowing off the edge of the\n * month renders a different month, so the element to focus is not in the DOM at the\n * time the key is handled — it is one commit away.\n */\n const pendingFocus = useRef<string | null>(null);\n useEffect(() => {\n const iso = pendingFocus.current;\n if (!iso) return;\n pendingFocus.current = null;\n gridRef.current?.querySelector<HTMLElement>(`[data-iso=\"${iso}\"]`)?.focus();\n });\n\n // The roving tab stop is the day to open on, so there is nothing else to work out\n // here — it is already the selection, or today, pulled inside the bounds.\n useEffect(() => {\n if (!focusOnOpen) return;\n gridRef.current?.querySelector<HTMLElement>('[tabindex=\"0\"]')?.focus();\n }, [focusOnOpen]);\n\n /** Move the roving tabindex, and the month with it when the day lands outside. */\n const moveTo = (d: Date, focus: boolean) => {\n const iso = toLocalIso(d);\n if (iso === activeIso) return;\n if (focus) pendingFocus.current = iso;\n setActiveIso(iso);\n };\n\n /**\n * On each day rather than once on the grid: the cell is where focus is, and a\n * container listening for keys it cannot itself receive is the shape\n * `jsx-a11y/interactive-supports-focus` objects to. One shared function, not a\n * closure per cell — it reads the active day from state, which is always the\n * focused one.\n */\n const onDayKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {\n const next = new Date(activeDate);\n switch (e.key) {\n case \"ArrowLeft\":\n next.setDate(next.getDate() - 1);\n break;\n case \"ArrowRight\":\n next.setDate(next.getDate() + 1);\n break;\n case \"ArrowUp\":\n next.setDate(next.getDate() - 7);\n break;\n case \"ArrowDown\":\n next.setDate(next.getDate() + 7);\n break;\n case \"Home\":\n next.setDate(next.getDate() - weekdayIndex(next, weekStart));\n break;\n case \"End\":\n next.setDate(next.getDate() + (6 - weekdayIndex(next, weekStart)));\n break;\n // Shift+Page is the year step, as in the APG example. It is the only way to\n // reach a birth year without holding PageUp for four hundred keystrokes.\n case \"PageUp\":\n next.setTime(stepMonths(next, e.shiftKey ? -12 : -1).getTime());\n break;\n case \"PageDown\":\n next.setTime(stepMonths(next, e.shiftKey ? 12 : 1).getTime());\n break;\n default:\n return;\n }\n // Before the no-op check: every key above also scrolls the panel this calendar\n // usually sits in, and a day that cannot move still must not move the page.\n e.preventDefault();\n moveTo(next, true);\n };\n\n const moveMonth = (delta: number) => {\n // Focus stays on the arrow button the user is pressing — only the grid moves.\n moveTo(stepMonths(activeDate, delta), false);\n };\n\n const handleClick = (d: Date) => {\n // The guard that `disabled` used to be. Out-of-range days are focusable on\n // purpose (see the component note), so refusing the click is this function's job.\n if (isDisabled(d)) return;\n const iso = toLocalIso(d);\n // Keep the tab order on the day that was just activated even if the caller\n // ignores the selection — a controlled component may reject it, and the roving\n // tabindex is this component's own state, not an echo of the value.\n moveTo(d, false);\n if (mode === \"single\") {\n onSelect(iso, iso);\n return;\n }\n const f = parseIsoDate(from);\n const tt = parseIsoDate(to);\n if (!f || (f && tt)) {\n // start a new selection\n onSelect(iso, \"\");\n announce(labels.startSelected(formatDay(d)));\n return;\n }\n // f set, tt empty\n if (d < f) {\n onSelect(iso, toLocalIso(f));\n announce(labels.rangeSelected(formatDay(d), formatDay(f)));\n } else {\n onSelect(toLocalIso(f), iso);\n announce(labels.rangeSelected(formatDay(f), formatDay(d)));\n }\n };\n\n const today = new Date();\n const hasBand = Boolean(fromDate && toDate && !sameYmd(fromDate, toDate));\n const daysInMonth = (d: Date) => new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();\n const inRange = (d: Date) => {\n if (!fromDate || !toDate) return false;\n return d >= fromDate && d <= toDate;\n };\n\n // What the next click does. A range is two clicks and nothing on screen says which\n // one you are on — sighted users read it off the highlighted start.\n const awaitingEnd = Boolean(fromDate) && !toDate;\n const rangeHint = awaitingEnd ? labels.chooseEnd : labels.chooseStart;\n\n return (\n // The caller's classes come last, so tailwind-merge lets them win the way\n // `className` does everywhere else in the kit; `...rest` first, as in the rest of\n // this wave, so nothing from outside can take the grid's own wiring away.\n <div {...rest} className={cn(\"select-none\", className)}>\n <div className=\"flex items-center justify-between pb-1\">\n <button\n type=\"button\"\n onClick={() => moveMonth(-1)}\n aria-label={labels.previousMonth}\n className=\"rounded p-1 text-[var(--text-muted)] hover:bg-[var(--bg-hover)]\"\n >\n <ChevronLeft className=\"size-4\" />\n </button>\n {/* Named by this element rather than by a string of its own, and `aria-live`\n so paging months says which month you have landed on — the caption is the\n only thing on screen that changes when the grid moves, and the user\n pressing the arrow is not inside the grid to hear the cells change. */}\n <div\n id={monthId}\n aria-live=\"polite\"\n className=\"text-xs font-medium capitalize text-[var(--text-secondary)]\"\n >\n {monthLabel}\n </div>\n <button\n type=\"button\"\n onClick={() => moveMonth(1)}\n aria-label={labels.nextMonth}\n className=\"rounded p-1 text-[var(--text-muted)] hover:bg-[var(--bg-hover)]\"\n >\n <ChevronRight className=\"size-4\" />\n </button>\n </div>\n <div\n ref={gridRef}\n role=\"grid\"\n aria-labelledby={monthId}\n aria-describedby={mode === \"range\" ? hintId : undefined}\n className=\"grid gap-y-0.5\"\n >\n <div\n role=\"row\"\n className=\"grid grid-cols-7 text-center text-[10px] font-medium uppercase text-[var(--text-placeholder)]\"\n >\n {weekdayLabels.map((w, i) => (\n <div key={i} role=\"columnheader\" aria-label={w.long} className=\"py-0.5\">\n {w.narrow}\n </div>\n ))}\n </div>\n {weeks.map((week, wi) => (\n // No column gap: the days of a range join into ONE band. With a gap each day\n // was its own tinted box, and a selected fortnight read as fourteen chips.\n <div key={wi} role=\"row\" className=\"grid grid-cols-7\">\n {week.map((d, di) => {\n // The padding cells still have to BE cells, or the rows are ragged and\n // a screen reader's \"column 3\" stops meaning Wednesday.\n if (!d) return <div key={di} role=\"gridcell\" className=\"h-8\" />;\n const iso = toLocalIso(d);\n const disabled = isDisabled(d);\n const isStart = !disabled && fromDate && sameYmd(d, fromDate);\n const isEnd = !disabled && toDate && sameYmd(d, toDate);\n const isToday = sameYmd(d, today);\n const isInRange = !disabled && inRange(d) && !isStart && !isEnd;\n const isActive = iso === activeIso;\n // The band behind the day: full width between the ends, half width at an\n // end (so the round endpoint sits ON the band's tip), rounded where a row\n // or the month breaks it. Only when both ends exist and differ — a lone\n // start is a dot, not a band of one.\n const banded =\n hasBand && !disabled && (isStart || isEnd || isInRange);\n const lastOfMonth = d.getDate() === daysInMonth(d);\n const band = banded\n ? cn(\n \"pointer-events-none absolute inset-y-0 bg-[var(--brand-bg)]\",\n isStart ? \"start-1/2 end-0\" : isEnd ? \"start-0 end-1/2\" : \"inset-x-0\",\n isInRange && (di === 0 || d.getDate() === 1) && \"rounded-s-full\",\n isInRange && (di === 6 || lastOfMonth) && \"rounded-e-full\",\n isStart && (di === 6 || lastOfMonth) && \"hidden\",\n isEnd && (di === 0 || d.getDate() === 1) && \"hidden\",\n )\n : null;\n return (\n <div key={di} role=\"none\" className=\"relative flex h-8 items-center justify-center\">\n {band && <span aria-hidden className={band} />}\n <button\n key={di}\n type=\"button\"\n role=\"gridcell\"\n data-iso={iso}\n // The roving tabindex: ONE tab stop for the whole month. Every day\n // being tabbable meant 31 stops between a date field and the next\n // control, which is the same reason the pattern exists.\n tabIndex={isActive ? 0 : -1}\n aria-label={labels.day(formatDay(d))}\n aria-selected={Boolean(isStart || isEnd || isInRange)}\n aria-disabled={disabled || undefined}\n aria-current={isToday ? \"date\" : undefined}\n onClick={() => handleClick(d)}\n onKeyDown={onDayKeyDown}\n className={cn(\n \"relative size-8 rounded-full text-xs tabular-nums transition-colors\",\n // A grid you can walk with the keyboard needs to show where the\n // keyboard IS. Inset because the cells sit half a pixel apart and\n // an outset ring would be drawn over by its neighbours; the\n // colour flips on the selected days for the reason the numpad's\n // \"Done\" key does — a --brand ring on a --brand fill is a ring\n // that exists only in the DOM.\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset\",\n isStart || isEnd\n ? \"focus-visible:ring-[var(--brand-contrast)]\"\n : \"focus-visible:ring-[var(--brand)]\",\n disabled\n ? \"cursor-not-allowed text-[var(--text-placeholder)]\"\n // The two selected states are the BRAND, not a fixed sky: the endpoints\n // are the solid fill and the days between them its soft tint. Hardcoding\n // them left an app that changed `--brand` with a calendar in the old\n // colour (docs/module-audit-2026-09-22.md §theming). Both token pairs\n // flip light/dark themselves, so there is no `dark:` partner to carry —\n // one would override the token and bring the hardcoded hue back.\n : isStart || isEnd\n ? \"bg-[var(--brand)] text-[var(--brand-contrast)] hover:bg-[var(--brand-hover)]\"\n : isInRange\n ? \"font-medium text-[var(--brand-muted)] hover:bg-[var(--brand-bg-hover)]\"\n : \"text-[var(--text-primary)] hover:bg-[var(--bg-hover)]\",\n isToday && !isStart && !isEnd && !isInRange && !disabled && \"ring-1 ring-inset ring-[var(--border-strong)]\",\n )}\n >\n {dayNumber.format(d.getDate())}\n </button>\n </div>\n );\n })}\n </div>\n ))}\n </div>\n {/* `sr-only-fixed`, not `sr-only`: this renders inside whatever panel a consumer\n opens it in, and there is no wrapper we can require to be `relative` — see\n the note on the class in tokens.css. */}\n {mode === \"range\" && (\n <span id={hintId} className=\"sr-only-fixed\">\n {rangeHint}\n </span>\n )}\n <span {...region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BACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAOA;AAAA,wBACA,WAAW,QACP,+CACA;AAAA,wBACJ,WACI,sDAOA,WAAW,QACT,iFACA,YACE,2EACA;AAAA,wBACR,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,YAAY;AAAA,sBAC9D;AAAA,sBAEC,oBAAU,OAAO,EAAE,QAAQ,CAAC;AAAA;AAAA,oBA1CxB;AAAA,kBA2CP;AAAA,qBA9CU,EA+CV;AAAA,cAEJ,CAAC,KA/EO,EAgFV;AAAA,aACD;AAAA;AAAA;AAAA,MACH;AAAA,MAIC,SAAS,WACR,oBAAC,UAAK,IAAI,QAAQ,WAAU,iBACzB,qBACH;AAAA,MAEF,oBAAC,UAAM,GAAG,aAAa;AAAA,OACzB;AAAA;AAEJ;","names":["lastOfMonth"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, KeyboardEvent, MouseEvent } from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ReactNode, KeyboardEvent, MouseEvent } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Backdrop handlers that close only when a press starts AND ends on the
|
|
@@ -12,7 +12,13 @@ declare function useBackdropClose(onClose: () => void): {
|
|
|
12
12
|
onMouseDown: (e: MouseEvent<HTMLDivElement>) => void;
|
|
13
13
|
onMouseUp: (e: MouseEvent<HTMLDivElement>) => void;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* `extends ComponentPropsWithoutRef<"div">` so anything a `<div>` takes reaches the
|
|
17
|
+
* PANEL — the element with `role="dialog"`, which is the one a consumer means. That is
|
|
18
|
+
* where a `data-tour` anchor, a test id, an `aria-describedby` or an `aria-label` has
|
|
19
|
+
* to land; before this, a closed prop list dropped all four silently (audit §api-design).
|
|
20
|
+
*/
|
|
21
|
+
interface ModalProps extends ComponentPropsWithoutRef<"div"> {
|
|
16
22
|
/** Invoked on backdrop click and on Escape. */
|
|
17
23
|
onClose: () => void;
|
|
18
24
|
children: ReactNode;
|
|
@@ -71,6 +77,6 @@ interface ModalProps {
|
|
|
71
77
|
* into the panel on open and back to the trigger on close, a Tab focus trap, and
|
|
72
78
|
* `role="dialog"`/`aria-modal`.
|
|
73
79
|
*/
|
|
74
|
-
declare function Modal({ onClose, children, size, className, labelledBy, onKeyDown, fullBleed, draggable, }: ModalProps): react.ReactPortal;
|
|
80
|
+
declare function Modal({ onClose, children, size, className, labelledBy, onKeyDown, fullBleed, draggable, style, ...rest }: ModalProps): react.ReactPortal;
|
|
75
81
|
|
|
76
82
|
export { Modal, type ModalProps, useBackdropClose };
|
package/dist/components/modal.js
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
+
import { useRef, useState } from "react";
|
|
3
4
|
import { createPortal } from "react-dom";
|
|
4
5
|
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { useFocusTrap } from "../hooks/use-focus-trap.js";
|
|
5
7
|
import { useBodyScrollLock } from "../hooks/use-body-scroll-lock.js";
|
|
6
8
|
import { useOverlayHistory } from "../hooks/use-overlay-history.js";
|
|
7
9
|
import { useCloseTransition } from "../hooks/use-close-transition.js";
|
|
8
10
|
function useDragOffset(enabled) {
|
|
9
11
|
const [offset, setOffset] = useState(null);
|
|
10
12
|
const from = useRef(null);
|
|
11
|
-
const
|
|
12
|
-
const start = from.current;
|
|
13
|
-
if (!start) return;
|
|
14
|
-
setOffset({ x: start.ox + e.clientX - start.x, y: start.oy + e.clientY - start.y });
|
|
15
|
-
};
|
|
16
|
-
const onPointerUp = () => {
|
|
13
|
+
const endDrag = () => {
|
|
17
14
|
from.current = null;
|
|
18
|
-
window.removeEventListener("pointermove", onPointerMove);
|
|
19
|
-
window.removeEventListener("pointerup", onPointerUp);
|
|
20
15
|
};
|
|
21
16
|
return {
|
|
22
17
|
style: offset ? { transform: `translate(${offset.x}px, ${offset.y}px)` } : void 0,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
handlers: !enabled ? void 0 : {
|
|
19
|
+
onPointerDown: (e) => {
|
|
20
|
+
if (e.button !== 0 || window.innerWidth < 768) return;
|
|
21
|
+
const target = e.target;
|
|
22
|
+
if (target.closest("input,textarea,select,button,a,[role='button']")) return;
|
|
23
|
+
from.current = { x: e.clientX, y: e.clientY, ox: offset?.x ?? 0, oy: offset?.y ?? 0 };
|
|
24
|
+
try {
|
|
25
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
onPointerMove: (e) => {
|
|
30
|
+
const start = from.current;
|
|
31
|
+
if (!start) return;
|
|
32
|
+
setOffset({ x: start.ox + e.clientX - start.x, y: start.oy + e.clientY - start.y });
|
|
33
|
+
},
|
|
34
|
+
onPointerUp: endDrag,
|
|
35
|
+
// A cancel (the browser taking the pointer for a scroll or a gesture) and a
|
|
36
|
+
// lost capture both mean no `pointerup` is coming. Without them the drag would
|
|
37
|
+
// stay "live" and the next move over the panel would jump it.
|
|
38
|
+
onPointerCancel: endDrag,
|
|
39
|
+
onLostPointerCapture: endDrag
|
|
30
40
|
}
|
|
31
41
|
};
|
|
32
42
|
}
|
|
@@ -43,7 +53,6 @@ function useBackdropClose(onClose) {
|
|
|
43
53
|
}
|
|
44
54
|
};
|
|
45
55
|
}
|
|
46
|
-
const FOCUSABLE = 'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
47
56
|
function Modal({
|
|
48
57
|
onClose,
|
|
49
58
|
children,
|
|
@@ -52,7 +61,9 @@ function Modal({
|
|
|
52
61
|
labelledBy,
|
|
53
62
|
onKeyDown,
|
|
54
63
|
fullBleed,
|
|
55
|
-
draggable
|
|
64
|
+
draggable,
|
|
65
|
+
style,
|
|
66
|
+
...rest
|
|
56
67
|
}) {
|
|
57
68
|
const panelRef = useRef(null);
|
|
58
69
|
const drag = useDragOffset(Boolean(draggable));
|
|
@@ -60,13 +71,7 @@ function Modal({
|
|
|
60
71
|
const backdropClose = useBackdropClose(requestClose);
|
|
61
72
|
useOverlayHistory(true, requestClose);
|
|
62
73
|
useBodyScrollLock(true);
|
|
63
|
-
|
|
64
|
-
const previouslyFocused = document.activeElement;
|
|
65
|
-
panelRef.current?.focus();
|
|
66
|
-
return () => {
|
|
67
|
-
previouslyFocused?.focus?.();
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
74
|
+
useFocusTrap(panelRef, { active: true, initialFocus: "container" });
|
|
70
75
|
const handleKeyDown = (e) => {
|
|
71
76
|
onKeyDown?.(e);
|
|
72
77
|
if (e.defaultPrevented) return;
|
|
@@ -75,23 +80,6 @@ function Modal({
|
|
|
75
80
|
requestClose();
|
|
76
81
|
return;
|
|
77
82
|
}
|
|
78
|
-
if (e.key !== "Tab") return;
|
|
79
|
-
const focusables = panelRef.current?.querySelectorAll(FOCUSABLE);
|
|
80
|
-
if (!focusables || focusables.length === 0) {
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
panelRef.current?.focus();
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const first = focusables[0];
|
|
86
|
-
const last = focusables[focusables.length - 1];
|
|
87
|
-
const active = document.activeElement;
|
|
88
|
-
if (e.shiftKey && (active === first || active === panelRef.current)) {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
last.focus();
|
|
91
|
-
} else if (!e.shiftKey && active === last) {
|
|
92
|
-
e.preventDefault();
|
|
93
|
-
first.focus();
|
|
94
|
-
}
|
|
95
83
|
};
|
|
96
84
|
return createPortal(
|
|
97
85
|
/* @__PURE__ */ jsx(
|
|
@@ -109,17 +97,18 @@ function Modal({
|
|
|
109
97
|
children: /* @__PURE__ */ jsx(
|
|
110
98
|
"div",
|
|
111
99
|
{
|
|
100
|
+
...rest,
|
|
112
101
|
ref: panelRef,
|
|
113
102
|
role: "dialog",
|
|
114
103
|
"aria-modal": "true",
|
|
115
104
|
"aria-labelledby": labelledBy,
|
|
116
105
|
tabIndex: -1,
|
|
117
106
|
onKeyDown: handleKeyDown,
|
|
118
|
-
|
|
119
|
-
style: drag.style,
|
|
107
|
+
...drag.handlers,
|
|
108
|
+
style: { ...style, ...drag.style },
|
|
120
109
|
className: cn(
|
|
121
110
|
closing ? "animate-sheet-out md:animate-none" : "animate-sheet md:animate-none",
|
|
122
|
-
"w-full rounded-lg border border-
|
|
111
|
+
"w-full rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] shadow-sm outline-none",
|
|
123
112
|
{ md: "max-w-md", lg: "max-w-lg", xl: "max-w-3xl" }[size],
|
|
124
113
|
// A panel taller than the screen has to scroll ITSELF. The backdrop is
|
|
125
114
|
// `fixed inset-0` and the body is scroll-locked while a dialog is open, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/modal.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type {\n KeyboardEvent,\n MouseEvent as ReactMouseEvent,\n PointerEvent as ReactPointerEvent,\n ReactNode,\n} from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useBodyScrollLock } from \"../hooks/use-body-scroll-lock\";\nimport { useOverlayHistory } from \"../hooks/use-overlay-history\";\nimport { useCloseTransition } from \"../hooks/use-close-transition\";\n\n/**\n * Drag the panel by its top strip, in pointer space (dev#460).\n *\n * Deliberately not a library and not persisted: the offset is component state that\n * dies with the dialog. It starts only on a press that lands on the panel's own\n * chrome — never on a field, a button or a link, which is what keeps \"drag to select\n * text in the textarea\" working. Above `md` only: below it the panel is a\n * full-width bottom sheet with nothing beside it to uncover.\n */\nfunction useDragOffset(enabled: boolean) {\n const [offset, setOffset] = useState<{ x: number; y: number } | null>(null);\n const from = useRef<{ x: number; y: number; ox: number; oy: number } | null>(null);\n\n const onPointerMove = (e: PointerEvent) => {\n const start = from.current;\n if (!start) return;\n setOffset({ x: start.ox + e.clientX - start.x, y: start.oy + e.clientY - start.y });\n };\n const onPointerUp = () => {\n from.current = null;\n window.removeEventListener(\"pointermove\", onPointerMove);\n window.removeEventListener(\"pointerup\", onPointerUp);\n };\n\n return {\n style: offset ? { transform: `translate(${offset.x}px, ${offset.y}px)` } : undefined,\n onPointerDown: !enabled\n ? undefined\n : (e: ReactPointerEvent<HTMLDivElement>) => {\n if (e.button !== 0 || window.innerWidth < 768) return;\n const target = e.target as HTMLElement;\n // Only the panel itself and its non-interactive chrome start a drag; a\n // press inside any control belongs to that control.\n if (target.closest(\"input,textarea,select,button,a,[role='button']\")) return;\n from.current = { x: e.clientX, y: e.clientY, ox: offset?.x ?? 0, oy: offset?.y ?? 0 };\n window.addEventListener(\"pointermove\", onPointerMove);\n window.addEventListener(\"pointerup\", onPointerUp);\n },\n };\n}\n\n/**\n * Backdrop handlers that close only when a press starts AND ends on the\n * backdrop itself. A plain onClick fires on mouseup, so dragging a text\n * selection that starts inside the panel and releases over the backdrop would\n * dismiss the dialog (feedback #254) — and the reverse drag would too, since\n * click targets the common ancestor of the down/up elements.\n */\nexport function useBackdropClose(onClose: () => void) {\n const pressStartedOnBackdrop = useRef(false);\n return {\n onMouseDown: (e: ReactMouseEvent<HTMLDivElement>) => {\n pressStartedOnBackdrop.current = e.target === e.currentTarget;\n },\n onMouseUp: (e: ReactMouseEvent<HTMLDivElement>) => {\n const started = pressStartedOnBackdrop.current;\n pressStartedOnBackdrop.current = false;\n if (started && e.target === e.currentTarget) onClose();\n },\n };\n}\n\n// Tab-cycle target set: the interactive descendants the focus trap rotates\n// through. Querying live (per keystroke) means dynamically rendered fields are\n// included automatically.\nconst FOCUSABLE =\n 'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\nexport interface ModalProps {\n /** Invoked on backdrop click and on Escape. */\n onClose: () => void;\n children: ReactNode;\n /**\n * Panel max-width: `md` (28rem), `lg` (32rem), `xl` (48rem).\n *\n * `xl` exists because two callers had already written `className=\"max-w-3xl\"` to\n * reach it — the payee backfill's preview table and the price-merge dialog, both\n * of which hold a list and several fields rather than one question. A caller\n * patching a missing size IS the signal that the size is missing, and a\n * hand-written width in a `className` is a width nothing else can line up with.\n *\n * The panel is `w-full` under every one of them, so the cap only bites once the\n * viewport is wider than it: on a phone all three are the same full-width bottom\n * sheet. Nothing here may introduce a `min-w-*`, which is what would break that.\n */\n size?: \"md\" | \"lg\" | \"xl\";\n /** Extra classes for the panel (e.g. `space-y-3` for form content spacing). */\n className?: string;\n /** id of the heading element, wired to `aria-labelledby`. */\n labelledBy?: string;\n /**\n * Extra key handling on the panel (e.g. Ctrl/Cmd+Enter to submit). Runs first;\n * if it calls `preventDefault()` the built-in Escape/Tab handling is skipped\n * for that event.\n */\n onKeyDown?: (e: KeyboardEvent<HTMLDivElement>) => void;\n /**\n * Drop the backdrop's mobile margin so the panel can reach the screen edges\n * (a full-screen sheet on phones). The panel still needs its own\n * `h-[100dvh] max-w-full rounded-none` classes via `className` to fill it; the\n * desktop `md:p-4` margin is kept. Defaults to false (padded on all sizes).\n */\n fullBleed?: boolean;\n /**\n * Let the user drag the panel out of the way by its top edge (Keksdose feedback\n * dev#460: *\"Make the feedback dialog draggable so I can see behind it if it\n * blocks something.\"*).\n *\n * Opt-in, because it only makes sense for a dialog whose content is ABOUT the page\n * behind it — the feedback composer is the case, an ordinary form is not, and a\n * draggable panel that has nothing to reveal is a control that can only get lost.\n *\n * Pointer-only by design: it is a \"move this out of the way\" gesture, not a layout\n * choice worth persisting, and the position resets when the dialog closes. On a\n * phone the panel is a bottom sheet the width of the screen, so dragging is\n * suppressed there — there is nothing beside it to see.\n */\n draggable?: boolean;\n}\n\n/**\n * Centered (bottom-sheet on mobile) modal dialog: dimmed backdrop, single\n * rounded panel. Owns the overlay mechanics that the hand-rolled dialogs each\n * re-implemented or lacked — backdrop-click + Escape to close, the platform Back\n * gesture (Keksdose feedback #172), background scroll lock (feedback #204), focus\n * into the panel on open and back to the trigger on close, a Tab focus trap, and\n * `role=\"dialog\"`/`aria-modal`.\n */\nexport function Modal({\n onClose,\n children,\n size = \"md\",\n className,\n labelledBy,\n onKeyDown,\n fullBleed,\n draggable,\n}: ModalProps) {\n const panelRef = useRef<HTMLDivElement>(null);\n const drag = useDragOffset(Boolean(draggable));\n // The panel lowers itself before the caller unmounts it (live #320 rework). Every\n // dismissal below goes through `requestClose`; `onClose` still does the closing, one\n // animation later. A caller that closes the dialog ITSELF — after a save, say —\n // unmounts with no exit, which is the documented limit of this.\n const { closing, requestClose } = useCloseTransition(onClose);\n const backdropClose = useBackdropClose(requestClose);\n // Back means the same as Escape here. On a phone Escape doesn't exist, so without\n // this the only way out of a dialog is finding its close button — and Back, the\n // gesture everyone reaches for, navigated the page underneath instead (#172).\n // Mounted only while open, hence the constant `true`.\n useOverlayHistory(true, requestClose);\n\n // Mounted only while open, hence the constant `true`. Through the shared hook and\n // not by hand: this component's own save/restore copy was one half of the pair that\n // left the page permanently unscrollable when a dialog containing an open sheet was\n // closed — see the note in use-body-scroll-lock.ts.\n useBodyScrollLock(true);\n\n useEffect(() => {\n const previouslyFocused = document.activeElement as HTMLElement | null;\n // Focus the panel itself (not the first field) so opening doesn't pop the\n // mobile keyboard, while still moving focus into the dialog for keyboard and\n // screen-reader users.\n panelRef.current?.focus();\n return () => {\n previouslyFocused?.focus?.();\n };\n }, []);\n\n const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === \"Escape\") {\n e.stopPropagation();\n requestClose();\n return;\n }\n if (e.key !== \"Tab\") return;\n // Keep Tab within the dialog. Elements inside a portal'd panel (e.g. an open\n // dropdown) live outside this subtree, so this handler never fires for them\n // — they manage their own focus.\n const focusables = panelRef.current?.querySelectorAll<HTMLElement>(FOCUSABLE);\n if (!focusables || focusables.length === 0) {\n e.preventDefault();\n panelRef.current?.focus();\n return;\n }\n const first = focusables[0];\n const last = focusables[focusables.length - 1];\n const active = document.activeElement;\n if (e.shiftKey && (active === first || active === panelRef.current)) {\n e.preventDefault();\n last.focus();\n } else if (!e.shiftKey && active === last) {\n e.preventDefault();\n first.focus();\n }\n };\n\n // Portal to <body> so the `fixed inset-0 z-50` overlay escapes whatever stacking\n // context its caller sits in. Rendered inline, a modal opened from e.g. the top\n // bar (a z-30 context) could paint BELOW a sibling z-30 sticky element like the\n // expanded transaction editor (feedback #320). The tour/command-palette overlays\n // already portal for the same reason.\n return createPortal(\n <div\n className={cn(\n // Live #320. The panel below rises only where it is bottom-anchored: from md up\n // it is centred, and a centred box sliding up from off-screen reads as a\n // different component arriving rather than as the same one settling.\n closing ? \"animate-overlay-out\" : \"animate-overlay\",\n \"fixed inset-0 z-50 flex items-end justify-center bg-black/40 md:items-center\",\n fullBleed ? \"p-0 md:p-4\" : \"p-4\",\n )}\n {...backdropClose}\n >\n <div\n ref={panelRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={labelledBy}\n tabIndex={-1}\n onKeyDown={handleKeyDown}\n onPointerDown={drag.onPointerDown}\n style={drag.style}\n className={cn(\n closing ? \"animate-sheet-out md:animate-none\" : \"animate-sheet md:animate-none\",\n \"w-full rounded-lg border border-slate-200 bg-white shadow-sm outline-none dark:border-slate-800 dark:bg-slate-900\",\n { md: \"max-w-md\", lg: \"max-w-lg\", xl: \"max-w-3xl\" }[size],\n // A panel taller than the screen has to scroll ITSELF. The backdrop is\n // `fixed inset-0` and the body is scroll-locked while a dialog is open, so\n // without this the overflow simply had nowhere to go: on a phone the panel\n // is bottom-anchored, so it grew UPWARD past the top edge and the part that\n // went past it could not be reached by any gesture (Keksdose live #254, on\n // the price-merge dialog — but it was every dialog with more than a screen\n // of content). `max-h-full` resolves against the backdrop's content box,\n // which is the viewport minus its own padding, so the panel stops exactly\n // where the screen does; `overscroll-contain` keeps the fling inside it.\n //\n // Three callers had already patched themselves with `max-h-[90vh]` +\n // an inner scroller. Those still win — `cn` is tailwind-merge — and this is\n // the default they should not have needed.\n \"max-h-full overflow-y-auto overscroll-contain\",\n \"p-4\",\n // The grab affordance sits on the panel's own top strip: a drag handle of\n // its own would be one more control in a dialog that is mostly one field.\n draggable && \"md:[&>*:first-child]:cursor-grab\",\n className,\n )}\n >\n {children}\n </div>\n </div>,\n document.body,\n );\n}\n"],"mappings":"AAqOM;AArON,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,oBAAoB;AAO7B,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAWnC,SAAS,cAAc,SAAkB;AACvC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0C,IAAI;AAC1E,QAAM,OAAO,OAAgE,IAAI;AAEjF,QAAM,gBAAgB,CAAC,MAAoB;AACzC,UAAM,QAAQ,KAAK;AACnB,QAAI,CAAC,MAAO;AACZ,cAAU,EAAE,GAAG,MAAM,KAAK,EAAE,UAAU,MAAM,GAAG,GAAG,MAAM,KAAK,EAAE,UAAU,MAAM,EAAE,CAAC;AAAA,EACpF;AACA,QAAM,cAAc,MAAM;AACxB,SAAK,UAAU;AACf,WAAO,oBAAoB,eAAe,aAAa;AACvD,WAAO,oBAAoB,aAAa,WAAW;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,OAAO,SAAS,EAAE,WAAW,aAAa,OAAO,CAAC,OAAO,OAAO,CAAC,MAAM,IAAI;AAAA,IAC3E,eAAe,CAAC,UACZ,SACA,CAAC,MAAyC;AACxC,UAAI,EAAE,WAAW,KAAK,OAAO,aAAa,IAAK;AAC/C,YAAM,SAAS,EAAE;AAGjB,UAAI,OAAO,QAAQ,gDAAgD,EAAG;AACtE,WAAK,UAAU,EAAE,GAAG,EAAE,SAAS,GAAG,EAAE,SAAS,IAAI,QAAQ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E,eAAe;AACjB,eAAS,SAAS,MAAM;AACxB;AAAA,IACF;AACA,UAAM,QAAQ,WAAW,CAAC;AAC1B,UAAM,OAAO,WAAW,WAAW,SAAS,CAAC;AAC7C,UAAM,SAAS,SAAS;AACxB,QAAI,EAAE,aAAa,WAAW,SAAS,WAAW,SAAS,UAAU;AACnE,QAAE,eAAe;AACjB,WAAK,MAAM;AAAA,IACb,WAAW,CAAC,EAAE,YAAY,WAAW,MAAM;AACzC,QAAE,eAAe;AACjB,YAAM,MAAM;AAAA,IACd;AAAA,EACF;AAOA,SAAO;AAAA,IACL;AAAA,MAAC;AAAA;AAAA,QACC,WAAW;AAAA;AAAA;AAAA;AAAA,UAIT,UAAU,wBAAwB;AAAA,UAClC;AAAA,UACA,YAAY,eAAe;AAAA,QAC7B;AAAA,QACC,GAAG;AAAA,QAEJ;AAAA,UAAC;AAAA;AAAA,YACC,KAAK;AAAA,YACL,MAAK;AAAA,YACL,cAAW;AAAA,YACX,mBAAiB;AAAA,YACjB,UAAU;AAAA,YACV,WAAW;AAAA,YACX,eAAe,KAAK;AAAA,YACpB,OAAO,KAAK;AAAA,YACZ,WAAW;AAAA,cACT,UAAU,sCAAsC;AAAA,cAChD;AAAA,cACA,EAAE,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAcxD;AAAA,cACA;AAAA;AAAA;AAAA,cAGA,aAAa;AAAA,cACb;AAAA,YACF;AAAA,YAEC;AAAA;AAAA,QACH;AAAA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,EACX;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/modal.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type {\n ComponentPropsWithoutRef,\n KeyboardEvent,\n MouseEvent as ReactMouseEvent,\n PointerEvent as ReactPointerEvent,\n ReactNode,\n} from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useFocusTrap } from \"../hooks/use-focus-trap\";\nimport { useBodyScrollLock } from \"../hooks/use-body-scroll-lock\";\nimport { useOverlayHistory } from \"../hooks/use-overlay-history\";\nimport { useCloseTransition } from \"../hooks/use-close-transition\";\n\n/**\n * Drag the panel by its top strip, in pointer space (dev#460).\n *\n * Deliberately not a library and not persisted: the offset is component state that\n * dies with the dialog. It starts only on a press that lands on the panel's own\n * chrome — never on a field, a button or a link, which is what keeps \"drag to select\n * text in the textarea\" working. Above `md` only: below it the panel is a\n * full-width bottom sheet with nothing beside it to uncover.\n *\n * The whole gesture stays on the PANEL — captured pointer, React handlers — rather than\n * on `window`. The first shape of this added `pointermove`/`pointerup` to `window` from\n * inside the `pointerdown` handler and took them off again from the `pointerup` handler,\n * so the teardown ran only if the gesture ended: React never sees a listener added from\n * an event handler, and an unmount mid-drag left a live `pointermove` on `window` for\n * the life of the page, pinning this hook's state with it. The one caller that enables\n * dragging is the feedback composer, which closes ITSELF on submit — a Ctrl+Enter sent\n * with the pointer still down is exactly that order of events, once per drag.\n */\nfunction useDragOffset(enabled: boolean) {\n const [offset, setOffset] = useState<{ x: number; y: number } | null>(null);\n const from = useRef<{ x: number; y: number; ox: number; oy: number } | null>(null);\n\n const endDrag = () => {\n from.current = null;\n };\n\n return {\n style: offset ? { transform: `translate(${offset.x}px, ${offset.y}px)` } : undefined,\n handlers: !enabled\n ? undefined\n : {\n onPointerDown: (e: ReactPointerEvent<HTMLDivElement>) => {\n if (e.button !== 0 || window.innerWidth < 768) return;\n const target = e.target as HTMLElement;\n // Only the panel itself and its non-interactive chrome start a drag; a\n // press inside any control belongs to that control.\n if (target.closest(\"input,textarea,select,button,a,[role='button']\")) return;\n from.current = { x: e.clientX, y: e.clientY, ox: offset?.x ?? 0, oy: offset?.y ?? 0 };\n try {\n // Capture is what lets the handlers live on the panel: every later\n // pointer event for this pointer retargets here, so the drag keeps\n // working once the pointer outruns the panel's own box — which it always\n // does, since the panel moves out from under it.\n e.currentTarget.setPointerCapture(e.pointerId);\n } catch {\n // jsdom implements no pointer capture, and a browser throws\n // NotFoundError for a pointerId that is already gone. Neither is worth\n // refusing the drag: uncaptured, the panel still gets the moves that\n // land on it.\n }\n },\n onPointerMove: (e: ReactPointerEvent<HTMLDivElement>) => {\n const start = from.current;\n if (!start) return;\n setOffset({ x: start.ox + e.clientX - start.x, y: start.oy + e.clientY - start.y });\n },\n onPointerUp: endDrag,\n // A cancel (the browser taking the pointer for a scroll or a gesture) and a\n // lost capture both mean no `pointerup` is coming. Without them the drag would\n // stay \"live\" and the next move over the panel would jump it.\n onPointerCancel: endDrag,\n onLostPointerCapture: endDrag,\n },\n };\n}\n\n/**\n * Backdrop handlers that close only when a press starts AND ends on the\n * backdrop itself. A plain onClick fires on mouseup, so dragging a text\n * selection that starts inside the panel and releases over the backdrop would\n * dismiss the dialog (feedback #254) — and the reverse drag would too, since\n * click targets the common ancestor of the down/up elements.\n */\nexport function useBackdropClose(onClose: () => void) {\n const pressStartedOnBackdrop = useRef(false);\n return {\n onMouseDown: (e: ReactMouseEvent<HTMLDivElement>) => {\n pressStartedOnBackdrop.current = e.target === e.currentTarget;\n },\n onMouseUp: (e: ReactMouseEvent<HTMLDivElement>) => {\n const started = pressStartedOnBackdrop.current;\n pressStartedOnBackdrop.current = false;\n if (started && e.target === e.currentTarget) onClose();\n },\n };\n}\n\n// Tab-cycle target set: the interactive descendants the focus trap rotates\n// through. Querying live (per keystroke) means dynamically rendered fields are\n// included automatically.\n/**\n * `extends ComponentPropsWithoutRef<\"div\">` so anything a `<div>` takes reaches the\n * PANEL — the element with `role=\"dialog\"`, which is the one a consumer means. That is\n * where a `data-tour` anchor, a test id, an `aria-describedby` or an `aria-label` has\n * to land; before this, a closed prop list dropped all four silently (audit §api-design).\n */\nexport interface ModalProps extends ComponentPropsWithoutRef<\"div\"> {\n /** Invoked on backdrop click and on Escape. */\n onClose: () => void;\n children: ReactNode;\n /**\n * Panel max-width: `md` (28rem), `lg` (32rem), `xl` (48rem).\n *\n * `xl` exists because two callers had already written `className=\"max-w-3xl\"` to\n * reach it — the payee backfill's preview table and the price-merge dialog, both\n * of which hold a list and several fields rather than one question. A caller\n * patching a missing size IS the signal that the size is missing, and a\n * hand-written width in a `className` is a width nothing else can line up with.\n *\n * The panel is `w-full` under every one of them, so the cap only bites once the\n * viewport is wider than it: on a phone all three are the same full-width bottom\n * sheet. Nothing here may introduce a `min-w-*`, which is what would break that.\n */\n size?: \"md\" | \"lg\" | \"xl\";\n /** Extra classes for the panel (e.g. `space-y-3` for form content spacing). */\n className?: string;\n /** id of the heading element, wired to `aria-labelledby`. */\n labelledBy?: string;\n /**\n * Extra key handling on the panel (e.g. Ctrl/Cmd+Enter to submit). Runs first;\n * if it calls `preventDefault()` the built-in Escape/Tab handling is skipped\n * for that event.\n */\n onKeyDown?: (e: KeyboardEvent<HTMLDivElement>) => void;\n /**\n * Drop the backdrop's mobile margin so the panel can reach the screen edges\n * (a full-screen sheet on phones). The panel still needs its own\n * `h-[100dvh] max-w-full rounded-none` classes via `className` to fill it; the\n * desktop `md:p-4` margin is kept. Defaults to false (padded on all sizes).\n */\n fullBleed?: boolean;\n /**\n * Let the user drag the panel out of the way by its top edge (Keksdose feedback\n * dev#460: *\"Make the feedback dialog draggable so I can see behind it if it\n * blocks something.\"*).\n *\n * Opt-in, because it only makes sense for a dialog whose content is ABOUT the page\n * behind it — the feedback composer is the case, an ordinary form is not, and a\n * draggable panel that has nothing to reveal is a control that can only get lost.\n *\n * Pointer-only by design: it is a \"move this out of the way\" gesture, not a layout\n * choice worth persisting, and the position resets when the dialog closes. On a\n * phone the panel is a bottom sheet the width of the screen, so dragging is\n * suppressed there — there is nothing beside it to see.\n */\n draggable?: boolean;\n}\n\n/**\n * Centered (bottom-sheet on mobile) modal dialog: dimmed backdrop, single\n * rounded panel. Owns the overlay mechanics that the hand-rolled dialogs each\n * re-implemented or lacked — backdrop-click + Escape to close, the platform Back\n * gesture (Keksdose feedback #172), background scroll lock (feedback #204), focus\n * into the panel on open and back to the trigger on close, a Tab focus trap, and\n * `role=\"dialog\"`/`aria-modal`.\n */\nexport function Modal({\n onClose,\n children,\n size = \"md\",\n className,\n labelledBy,\n onKeyDown,\n fullBleed,\n draggable,\n style,\n ...rest\n}: ModalProps) {\n const panelRef = useRef<HTMLDivElement>(null);\n const drag = useDragOffset(Boolean(draggable));\n // The panel lowers itself before the caller unmounts it (live #320 rework). Every\n // dismissal below goes through `requestClose`; `onClose` still does the closing, one\n // animation later. A caller that closes the dialog ITSELF — after a save, say —\n // unmounts with no exit, which is the documented limit of this.\n const { closing, requestClose } = useCloseTransition(onClose);\n const backdropClose = useBackdropClose(requestClose);\n // Back means the same as Escape here. On a phone Escape doesn't exist, so without\n // this the only way out of a dialog is finding its close button — and Back, the\n // gesture everyone reaches for, navigated the page underneath instead (#172).\n // Mounted only while open, hence the constant `true`.\n useOverlayHistory(true, requestClose);\n\n // Mounted only while open, hence the constant `true`. Through the shared hook and\n // not by hand: this component's own save/restore copy was one half of the pair that\n // left the page permanently unscrollable when a dialog containing an open sheet was\n // closed — see the note in use-body-scroll-lock.ts.\n useBodyScrollLock(true);\n\n // Focus the panel itself (not the first field) so opening doesn't pop the mobile\n // keyboard, while still moving focus into the dialog for keyboard and screen-reader\n // users. Through the shared hook since this component is where it came from — the\n // hook adds per-keystroke recomputation, a guard on restoring to a detached node,\n // and nesting, none of which this copy had.\n useFocusTrap(panelRef, { active: true, initialFocus: \"container\" });\n\n const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === \"Escape\") {\n e.stopPropagation();\n requestClose();\n return;\n }\n // Tab containment lives in useFocusTrap, which listens on the panel itself.\n };\n\n // Portal to <body> so the `fixed inset-0 z-50` overlay escapes whatever stacking\n // context its caller sits in. Rendered inline, a modal opened from e.g. the top\n // bar (a z-30 context) could paint BELOW a sibling z-30 sticky element like the\n // expanded transaction editor (feedback #320). The tour/command-palette overlays\n // already portal for the same reason.\n return createPortal(\n <div\n className={cn(\n // Live #320. The panel below rises only where it is bottom-anchored: from md up\n // it is centred, and a centred box sliding up from off-screen reads as a\n // different component arriving rather than as the same one settling.\n closing ? \"animate-overlay-out\" : \"animate-overlay\",\n \"fixed inset-0 z-50 flex items-end justify-center bg-black/40 md:items-center\",\n fullBleed ? \"p-0 md:p-4\" : \"p-4\",\n )}\n {...backdropClose}\n >\n <div\n // `...rest` FIRST, everything the dialog needs to be a dialog after it. A\n // wrapper that spreads its own props through to this one cannot then take away\n // the role, the modality or the `tabIndex={-1}` that `useFocusTrap` needs —\n // losing any of the three is silent, and the symptom (a dialog a screen reader\n // walks straight out of) shows up nowhere near the call site that caused it.\n {...rest}\n ref={panelRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={labelledBy}\n tabIndex={-1}\n onKeyDown={handleKeyDown}\n {...drag.handlers}\n // MERGED, not replaced: `drag.style` is undefined until a drag starts, so\n // assigning it outright would drop a caller's own `style` on every render but\n // the ones where the panel is being dragged.\n style={{ ...style, ...drag.style }}\n className={cn(\n closing ? \"animate-sheet-out md:animate-none\" : \"animate-sheet md:animate-none\",\n \"w-full rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] shadow-sm outline-none\",\n { md: \"max-w-md\", lg: \"max-w-lg\", xl: \"max-w-3xl\" }[size],\n // A panel taller than the screen has to scroll ITSELF. The backdrop is\n // `fixed inset-0` and the body is scroll-locked while a dialog is open, so\n // without this the overflow simply had nowhere to go: on a phone the panel\n // is bottom-anchored, so it grew UPWARD past the top edge and the part that\n // went past it could not be reached by any gesture (Keksdose live #254, on\n // the price-merge dialog — but it was every dialog with more than a screen\n // of content). `max-h-full` resolves against the backdrop's content box,\n // which is the viewport minus its own padding, so the panel stops exactly\n // where the screen does; `overscroll-contain` keeps the fling inside it.\n //\n // Three callers had already patched themselves with `max-h-[90vh]` +\n // an inner scroller. Those still win — `cn` is tailwind-merge — and this is\n // the default they should not have needed.\n \"max-h-full overflow-y-auto overscroll-contain\",\n \"p-4\",\n // The grab affordance sits on the panel's own top strip: a drag handle of\n // its own would be one more control in a dialog that is mostly one field.\n draggable && \"md:[&>*:first-child]:cursor-grab\",\n className,\n )}\n >\n {children}\n </div>\n </div>,\n document.body,\n );\n}\n"],"mappings":";AA8OM;AA9ON,SAAS,QAAQ,gBAAgB;AACjC,SAAS,oBAAoB;AAQ7B,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAoBnC,SAAS,cAAc,SAAkB;AACvC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0C,IAAI;AAC1E,QAAM,OAAO,OAAgE,IAAI;AAEjF,QAAM,UAAU,MAAM;AACpB,SAAK,UAAU;AAAA,EACjB;AAEA,SAAO;AAAA,IACL,OAAO,SAAS,EAAE,WAAW,aAAa,OAAO,CAAC,OAAO,OAAO,CAAC,MAAM,IAAI;AAAA,IAC3E,UAAU,CAAC,UACP,SACA;AAAA,MACE,eAAe,CAAC,MAAyC;AACvD,YAAI,EAAE,WAAW,KAAK,OAAO,aAAa,IAAK;AAC/C,cAAM,SAAS,EAAE;AAGjB,YAAI,OAAO,QAAQ,gDAAgD,EAAG;AACtE,aAAK,UAAU,EAAE,GAAG,EAAE,SAAS,GAAG,EAAE,SAAS,IAAI,QAAQ,KAAK,GAAG,IAAI,QAAQ,KAAK,EAAE;AACpF,YAAI;AAKF,YAAE,cAAc,kBAAkB,EAAE,SAAS;AAAA,QAC/C,QAAQ;AAAA,QAKR;AAAA,MACF;AAAA,MACA,eAAe,CAAC,MAAyC;AACvD,cAAM,QAAQ,KAAK;AACnB,YAAI,CAAC,MAAO;AACZ,kBAAU,EAAE,GAAG,MAAM,KAAK,EAAE,UAAU,MAAM,GAAG,GAAG,MAAM,KAAK,EAAE,UAAU,MAAM,EAAE,CAAC;AAAA,MACpF;AAAA,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AA,YACL,MAAK;AAAA,YACL,cAAW;AAAA,YACX,mBAAiB;AAAA,YACjB,UAAU;AAAA,YACV,WAAW;AAAA,YACV,GAAG,KAAK;AAAA,YAIT,OAAO,EAAE,GAAG,OAAO,GAAG,KAAK,MAAM;AAAA,YACjC,WAAW;AAAA,cACT,UAAU,sCAAsC;AAAA,cAChD;AAAA,cACA,EAAE,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAcxD;AAAA,cACA;AAAA;AAAA;AAAA,cAGA,aAAa;AAAA,cACb;AAAA,YACF;AAAA,YAEC;AAAA;AAAA,QACH;AAAA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,EACX;AACF;","names":[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every string the month picker can speak. The month and year names are NOT here —
|
|
6
|
+
* they come from `Intl` in the `locale` prop, so they are already in the user's
|
|
7
|
+
* language. What is left is the two icon-only year arrows, whose `aria-label` is the
|
|
8
|
+
* only name they have, the panel's name, and a month cell's name.
|
|
9
|
+
*/
|
|
10
|
+
interface MonthPickerLabels {
|
|
11
|
+
previousYear: string;
|
|
12
|
+
nextYear: string;
|
|
13
|
+
/** The popover's accessible name (`role="dialog"`). */
|
|
14
|
+
panel: string;
|
|
15
|
+
/**
|
|
16
|
+
* Accessible name of one month cell, given that month and its year formatted in
|
|
17
|
+
* `locale` ("August 2026"). The cell's visible text is the short month alone, and
|
|
18
|
+
* "Aug" read out on its own does not say which year the grid is on.
|
|
19
|
+
*/
|
|
20
|
+
month: (monthYear: string) => string;
|
|
21
|
+
}
|
|
22
|
+
/** The English starting point every override is merged onto. Exported (unlike the
|
|
23
|
+
* calendar's) because it is asked for by name: a host building its own translation
|
|
24
|
+
* table can spread it rather than re-typing four keys to change one. */
|
|
25
|
+
declare const DEFAULT_MONTH_PICKER_LABELS: MonthPickerLabels;
|
|
26
|
+
/**
|
|
27
|
+
* `onChange` is omitted from the `<div>` attributes: the DOM event of that name carries
|
|
28
|
+
* a `FormEvent`, and this one answers with a month key. Everything else reaches the
|
|
29
|
+
* field's root, so a test id or a `data-tour` anchor can find it.
|
|
30
|
+
*/
|
|
31
|
+
interface MonthPickerProps extends Omit<ComponentPropsWithoutRef<"div">, "onChange"> {
|
|
32
|
+
/**
|
|
33
|
+
* The selected month as a `"YYYY-MM"` key, or `""` for none.
|
|
34
|
+
*
|
|
35
|
+
* A string rather than `{ year, month }` or a `Date`, for the reason every date in
|
|
36
|
+
* this kit is one: it is what `monthKey()` in `lib/dates` produces, it sorts
|
|
37
|
+
* chronologically so the bounds are plain `<` / `>`, and it crosses a URL or an API
|
|
38
|
+
* without a serialiser. A `{ year, month }` caller converts with
|
|
39
|
+
* `` `${year}-${pad(month)}` `` (month 1–12) and back with `key.split("-").map(Number)`.
|
|
40
|
+
*/
|
|
41
|
+
value: string;
|
|
42
|
+
/** Called with the picked month as `"YYYY-MM"`. */
|
|
43
|
+
onChange: (month: string) => void;
|
|
44
|
+
/** Drives the month and year names (`Intl.DateTimeFormat`). Defaults to the
|
|
45
|
+
* `<UiKitProvider>` locale, then the runtime's. */
|
|
46
|
+
locale?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Inclusive bounds, as `"YYYY-MM"`. A full ISO date (`"YYYY-MM-DD"`) is accepted and
|
|
49
|
+
* read as its month, so a host holding "the first day we have data for" can pass it
|
|
50
|
+
* straight in. Months outside are shown but refuse selection; a year arrow is
|
|
51
|
+
* disabled once the whole year beyond it is out of bounds.
|
|
52
|
+
*/
|
|
53
|
+
min?: string;
|
|
54
|
+
max?: string;
|
|
55
|
+
/** Embedded top-boundary label, matching the other field-shaped controls. */
|
|
56
|
+
label?: ReactNode;
|
|
57
|
+
/** Trigger text when `value` is `""`. */
|
|
58
|
+
placeholder?: string;
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
/** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */
|
|
61
|
+
invalid?: boolean;
|
|
62
|
+
/** Intl options for the trigger's text (default: long month + numeric year). */
|
|
63
|
+
formatOptions?: Intl.DateTimeFormatOptions;
|
|
64
|
+
/**
|
|
65
|
+
* The month to ring as "now", as `"YYYY-MM"`. Defaults to the local calendar's
|
|
66
|
+
* current month; pass one to pin it (a test, a host with its own notion of today).
|
|
67
|
+
*/
|
|
68
|
+
currentMonth?: string;
|
|
69
|
+
/** User-facing strings; see {@link MonthPickerLabels}. */
|
|
70
|
+
labels?: Partial<MonthPickerLabels>;
|
|
71
|
+
/** Extra classes for the field's root. */
|
|
72
|
+
className?: string;
|
|
73
|
+
/** Extra classes for the trigger button — e.g. a compact `h-9 w-auto` trigger
|
|
74
|
+
* sitting between two icon buttons in a toolbar. */
|
|
75
|
+
triggerClassName?: string;
|
|
76
|
+
}
|
|
77
|
+
declare function MonthPicker({ value, onChange, locale: localeProp, min, max, label, placeholder, disabled, invalid, formatOptions, currentMonth, labels: labelsProp, className, triggerClassName, ...rest }: MonthPickerProps): react.JSX.Element;
|
|
78
|
+
|
|
79
|
+
export { DEFAULT_MONTH_PICKER_LABELS, MonthPicker, type MonthPickerLabels, type MonthPickerProps };
|