@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, RefObject } from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ReactNode, RefObject, KeyboardEvent } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Open state + close-on-outside-click for the custom dropdowns (MultiSelect,
|
|
@@ -23,14 +23,52 @@ import { ReactNode, RefObject } from 'react';
|
|
|
23
23
|
* is for the ONE case where a second entry would be wrong: a caller whose panel is
|
|
24
24
|
* itself a `PickerSheet`, which already registers one — both comboboxes swap shape at
|
|
25
25
|
* {@link PHONE_QUERY}, and two entries would cost two Back presses to close one sheet.
|
|
26
|
+
*
|
|
27
|
+
* ## One outside-click rule for the whole package
|
|
28
|
+
*
|
|
29
|
+
* This hand-rolled a second document listener, on `mousedown`, months after
|
|
30
|
+
* {@link useOutsideClick} — the hook the entity pickers dismiss through — was moved to
|
|
31
|
+
* `pointerdown` for a reason that applies here word for word: on a touch platform
|
|
32
|
+
* `mousedown` is SYNTHESISED, the browser emits it for most taps but is not obliged
|
|
33
|
+
* to, and MultiSelect, CurrencySelect, GroupedPicker, AmountInput's currency picker
|
|
34
|
+
* and both comboboxes all dismiss through this. Two copies of one rule is one copy
|
|
35
|
+
* too many; this now delegates, so the package has a single answer to "what is an
|
|
36
|
+
* outside press".
|
|
37
|
+
*
|
|
38
|
+
* `panelIsSheet` is what that delegation needs. A {@link PickerSheet} is modal and
|
|
39
|
+
* fills the screen, so it has no outside — and being portalled to `<body>`, it is
|
|
40
|
+
* inside neither `wrapperRef` nor `panelRef`, so a listener left running would read
|
|
41
|
+
* every tap in it as a press outside and close it at finger-down. The sheet's own
|
|
42
|
+
* `onMouseDown` stopPropagation guard used to hide that from this hook; it cannot
|
|
43
|
+
* stop a `pointerdown`. It defaults to `!backCloses` because the two ask the same
|
|
44
|
+
* question — "is this caller's panel a sheet?" — and the one caller that answers yes
|
|
45
|
+
* already says so; they are separate props so a future caller can answer them apart.
|
|
46
|
+
*
|
|
47
|
+
* ## Escape, and where focus lands after it
|
|
48
|
+
*
|
|
49
|
+
* This hook had no Escape at all (the audit's §a11y): Back closed these lists, an
|
|
50
|
+
* outside press closed them, and the one key every other dismissible surface in the
|
|
51
|
+
* package answers to did nothing — so a keyboard user who opened a list had no way
|
|
52
|
+
* out of it that did not also choose something. {@link useEscapeKey} is the listener
|
|
53
|
+
* `Modal`, `Popover` and `useComboboxCore` already dismiss through, so the package
|
|
54
|
+
* keeps one answer to "what does Escape do" rather than growing a fifth.
|
|
55
|
+
*
|
|
56
|
+
* Escape RESTORES FOCUS; an outside press does not. A press has already put focus
|
|
57
|
+
* where the user pointed, and dragging it back from there would be the bug. Attach
|
|
58
|
+
* `triggerRef` to the control that opens the panel and the keyboard paths — Escape,
|
|
59
|
+
* Tab, a commit — hand focus back to it; leave it unattached and they simply close,
|
|
60
|
+
* which is what the callers written before this get.
|
|
26
61
|
*/
|
|
27
|
-
declare function useDropdown<T extends HTMLElement = HTMLDivElement>({ backCloses, }?: {
|
|
62
|
+
declare function useDropdown<T extends HTMLElement = HTMLDivElement>({ backCloses, panelIsSheet, }?: {
|
|
28
63
|
backCloses?: boolean;
|
|
64
|
+
panelIsSheet?: boolean;
|
|
29
65
|
}): {
|
|
30
66
|
open: boolean;
|
|
31
67
|
setOpen: react.Dispatch<react.SetStateAction<boolean>>;
|
|
32
68
|
wrapperRef: RefObject<T | null>;
|
|
33
69
|
panelRef: RefObject<HTMLDivElement | null>;
|
|
70
|
+
triggerRef: RefObject<HTMLButtonElement | null>;
|
|
71
|
+
closeToTrigger: () => void;
|
|
34
72
|
};
|
|
35
73
|
/**
|
|
36
74
|
* {@link useDropdown} plus a search box: clears the query and focuses the search
|
|
@@ -41,17 +79,68 @@ declare function useDropdownSearch<T extends HTMLElement = HTMLDivElement>(): {
|
|
|
41
79
|
setOpen: react.Dispatch<react.SetStateAction<boolean>>;
|
|
42
80
|
wrapperRef: RefObject<T | null>;
|
|
43
81
|
panelRef: RefObject<HTMLDivElement | null>;
|
|
82
|
+
triggerRef: RefObject<HTMLButtonElement | null>;
|
|
83
|
+
closeToTrigger: () => void;
|
|
44
84
|
query: string;
|
|
45
85
|
setQuery: react.Dispatch<react.SetStateAction<string>>;
|
|
46
86
|
inputRef: RefObject<HTMLInputElement | null>;
|
|
47
87
|
};
|
|
48
|
-
/**
|
|
49
|
-
|
|
88
|
+
/** `onKeyDown` is the INPUT's, not the wrapper's — the list's keyboard is handled
|
|
89
|
+
* where the focus is (see the note above), so the div's own handler signature is
|
|
90
|
+
* omitted in favour of it. */
|
|
91
|
+
interface DropdownSearchHeaderProps extends Omit<ComponentPropsWithoutRef<"div">, "onKeyDown"> {
|
|
50
92
|
query: string;
|
|
51
93
|
onQueryChange: (v: string) => void;
|
|
52
94
|
inputRef: RefObject<HTMLInputElement | null>;
|
|
53
95
|
placeholder?: string;
|
|
54
|
-
|
|
96
|
+
/** The `<ul role="listbox">` this box filters. */
|
|
97
|
+
listboxId?: string;
|
|
98
|
+
/** The id of the option the arrow keys are currently on, if any. */
|
|
99
|
+
activeId?: string;
|
|
100
|
+
/** Arrow/Home/End/Enter/Tab — the list's keyboard, handled where the focus is. */
|
|
101
|
+
onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
102
|
+
}
|
|
103
|
+
/** The search row (magnifier + text input) shared by the searchable dropdowns.
|
|
104
|
+
*
|
|
105
|
+
* The input had `outline-none` and nothing in its place (the audit's §a11y, the same
|
|
106
|
+
* finding as the numpad's keys). That mattered more here than the bare class suggests:
|
|
107
|
+
* {@link useDropdownSearch} focuses this box the moment a panel opens, so the caret is
|
|
108
|
+
* the ONLY evidence of where the next keystroke goes — and a caret in an empty field
|
|
109
|
+
* showing a placeholder is a single blinking pixel column. The ring is what says "this
|
|
110
|
+
* list is being typed into"; it appears whenever the field holds focus, which for a
|
|
111
|
+
* text input is exactly when it is true.
|
|
112
|
+
*
|
|
113
|
+
* ## Why this box is a plain textbox and the TRIGGER is the combobox
|
|
114
|
+
*
|
|
115
|
+
* The panels this header sits in are opened by a field-shaped trigger, and that
|
|
116
|
+
* trigger is what carries `role="combobox"` (see {@link MultiSelect},
|
|
117
|
+
* {@link EntityCombobox}). Two comboboxes for one list would be one too many — a
|
|
118
|
+
* reader tabbing back to the field would meet a second one describing the same
|
|
119
|
+
* choice. So this stays a textbox, which ARIA lets own `aria-activedescendant` and
|
|
120
|
+
* `aria-controls` exactly as a combobox does: focus is HERE while the list is up, so
|
|
121
|
+
* this is what has to say which option the arrow keys are on.
|
|
122
|
+
*
|
|
123
|
+
* Pass `listboxId` and the wiring appears; omit it and the box is what it always
|
|
124
|
+
* was, for the callers that have no listbox to point at. */
|
|
125
|
+
declare function DropdownSearchHeader({ query, onQueryChange, inputRef, placeholder, listboxId, activeId, onKeyDown, "aria-label": ariaLabel, className, ...rest }: DropdownSearchHeaderProps): react.JSX.Element;
|
|
126
|
+
interface DropdownPanelProps extends ComponentPropsWithoutRef<"div"> {
|
|
127
|
+
header?: ReactNode;
|
|
128
|
+
empty?: boolean;
|
|
129
|
+
/** Attributes for the `<ul>` itself — how a caller whose children are options
|
|
130
|
+
* gives the list its `role="listbox"`, its id and `aria-multiselectable`. The
|
|
131
|
+
* panel owns the scrolling and the padding, so `className` here is merged rather
|
|
132
|
+
* than replaced. */
|
|
133
|
+
listProps?: ComponentPropsWithoutRef<"ul">;
|
|
134
|
+
/** The trigger to hang off. Given, the panel portals and goes `fixed`. */
|
|
135
|
+
anchorRef?: RefObject<HTMLElement | null>;
|
|
136
|
+
/** {@link useDropdown}'s `panelRef`, so an outside-click sees this as inside. */
|
|
137
|
+
panelRef?: RefObject<HTMLDivElement | null>;
|
|
138
|
+
/** Panel width in px, for the anchored form (the CSS `w-*` cannot be measured). */
|
|
139
|
+
width?: number;
|
|
140
|
+
/** Which of the panel's edges lines up with the trigger's, room permitting. */
|
|
141
|
+
align?: "left" | "right";
|
|
142
|
+
children: ReactNode;
|
|
143
|
+
}
|
|
55
144
|
/**
|
|
56
145
|
* The floating popover surface for the searchable dropdowns: bordered/shadowed
|
|
57
146
|
* panel, an optional `header` slot (search box, plus any actions), and a
|
|
@@ -80,19 +169,6 @@ declare function DropdownSearchHeader({ query, onQueryChange, inputRef, placehol
|
|
|
80
169
|
* no longer inside the wrapper, so the outside-click handler has to be told about it
|
|
81
170
|
* or the first click on an option closes the list instead of choosing from it.
|
|
82
171
|
*/
|
|
83
|
-
declare function DropdownPanel({ header, empty, className, anchorRef, panelRef, width, align, children, }:
|
|
84
|
-
header?: ReactNode;
|
|
85
|
-
empty?: boolean;
|
|
86
|
-
className?: string;
|
|
87
|
-
/** The trigger to hang off. Given, the panel portals and goes `fixed`. */
|
|
88
|
-
anchorRef?: RefObject<HTMLElement | null>;
|
|
89
|
-
/** {@link useDropdown}'s `panelRef`, so an outside-click sees this as inside. */
|
|
90
|
-
panelRef?: RefObject<HTMLDivElement | null>;
|
|
91
|
-
/** Panel width in px, for the anchored form (the CSS `w-*` cannot be measured). */
|
|
92
|
-
width?: number;
|
|
93
|
-
/** Which of the panel's edges lines up with the trigger's, room permitting. */
|
|
94
|
-
align?: "left" | "right";
|
|
95
|
-
children: ReactNode;
|
|
96
|
-
}): react.JSX.Element | null;
|
|
172
|
+
declare function DropdownPanel({ header, empty, className, listProps, anchorRef, panelRef, width, align, children, style, ...rest }: DropdownPanelProps): react.JSX.Element | null;
|
|
97
173
|
|
|
98
|
-
export { DropdownPanel, DropdownSearchHeader, useDropdown, useDropdownSearch };
|
|
174
|
+
export { DropdownPanel, type DropdownPanelProps, DropdownSearchHeader, type DropdownSearchHeaderProps, useDropdown, useDropdownSearch };
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
4
|
import { createPortal } from "react-dom";
|
|
4
5
|
import { Search } from "lucide-react";
|
|
5
6
|
import { useAnchoredPanel } from "../hooks/use-anchored-panel.js";
|
|
7
|
+
import { useEscapeKey, useOutsideClick } from "../hooks/use-dismiss.js";
|
|
6
8
|
import { useOverlayHistory } from "../hooks/use-overlay-history.js";
|
|
7
9
|
import { cn } from "../lib/cn.js";
|
|
8
10
|
function useDropdown({
|
|
9
|
-
backCloses = true
|
|
11
|
+
backCloses = true,
|
|
12
|
+
panelIsSheet = !backCloses
|
|
10
13
|
} = {}) {
|
|
11
14
|
const [open, setOpen] = useState(false);
|
|
12
15
|
const wrapperRef = useRef(null);
|
|
16
|
+
const triggerRef = useRef(null);
|
|
13
17
|
const panelRef = useRef(null);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, [open]);
|
|
24
|
-
useOverlayHistory(open && backCloses, useCallback(() => setOpen(false), []));
|
|
25
|
-
return { open, setOpen, wrapperRef, panelRef };
|
|
18
|
+
const close = useCallback(() => setOpen(false), []);
|
|
19
|
+
const closeToTrigger = useCallback(() => {
|
|
20
|
+
setOpen(false);
|
|
21
|
+
triggerRef.current?.focus();
|
|
22
|
+
}, []);
|
|
23
|
+
useOutsideClick([wrapperRef, panelRef], close, open && !panelIsSheet);
|
|
24
|
+
useEscapeKey(closeToTrigger, open);
|
|
25
|
+
useOverlayHistory(open && backCloses, close);
|
|
26
|
+
return { open, setOpen, wrapperRef, panelRef, triggerRef, closeToTrigger };
|
|
26
27
|
}
|
|
27
28
|
function useDropdownSearch() {
|
|
28
|
-
const { open, setOpen, wrapperRef, panelRef } = useDropdown();
|
|
29
|
+
const { open, setOpen, wrapperRef, panelRef, triggerRef, closeToTrigger } = useDropdown();
|
|
29
30
|
const [query, setQuery] = useState("");
|
|
30
31
|
const inputRef = useRef(null);
|
|
31
32
|
useEffect(() => {
|
|
@@ -34,54 +35,96 @@ function useDropdownSearch() {
|
|
|
34
35
|
requestAnimationFrame(() => inputRef.current?.focus());
|
|
35
36
|
}
|
|
36
37
|
}, [open]);
|
|
37
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
open,
|
|
40
|
+
setOpen,
|
|
41
|
+
wrapperRef,
|
|
42
|
+
panelRef,
|
|
43
|
+
triggerRef,
|
|
44
|
+
closeToTrigger,
|
|
45
|
+
query,
|
|
46
|
+
setQuery,
|
|
47
|
+
inputRef
|
|
48
|
+
};
|
|
38
49
|
}
|
|
39
50
|
function DropdownSearchHeader({
|
|
40
51
|
query,
|
|
41
52
|
onQueryChange,
|
|
42
53
|
inputRef,
|
|
43
|
-
placeholder
|
|
54
|
+
placeholder,
|
|
55
|
+
listboxId,
|
|
56
|
+
activeId,
|
|
57
|
+
onKeyDown,
|
|
58
|
+
"aria-label": ariaLabel,
|
|
59
|
+
className,
|
|
60
|
+
...rest
|
|
44
61
|
}) {
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
return (
|
|
63
|
+
// `rest` dresses the header row; the NAME goes on the box below it. A search
|
|
64
|
+
// input whose only name is its placeholder has none the moment a character is
|
|
65
|
+
// typed into it — the placeholder disappears — which is why this is worth a prop
|
|
66
|
+
// at all rather than something a caller could add from outside.
|
|
67
|
+
/* @__PURE__ */ jsxs(
|
|
68
|
+
"div",
|
|
49
69
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
...rest,
|
|
71
|
+
className: cn(
|
|
72
|
+
"flex items-center gap-2 border-b border-[var(--border)] px-2 py-1.5",
|
|
73
|
+
className
|
|
74
|
+
),
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsx(Search, { className: "size-4 text-[var(--text-placeholder)]" }),
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
"input",
|
|
79
|
+
{
|
|
80
|
+
ref: inputRef,
|
|
81
|
+
type: "text",
|
|
82
|
+
value: query,
|
|
83
|
+
onChange: (e) => onQueryChange(e.target.value),
|
|
84
|
+
onKeyDown,
|
|
85
|
+
placeholder,
|
|
86
|
+
"aria-label": ariaLabel,
|
|
87
|
+
"aria-controls": listboxId,
|
|
88
|
+
"aria-activedescendant": activeId,
|
|
89
|
+
"aria-autocomplete": listboxId ? "list" : void 0,
|
|
90
|
+
className: "w-full rounded-sm bg-transparent text-sm outline-none placeholder:text-[var(--text-placeholder)] text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--brand)]"
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
]
|
|
56
94
|
}
|
|
57
95
|
)
|
|
58
|
-
|
|
96
|
+
);
|
|
59
97
|
}
|
|
60
98
|
function DropdownPanel({
|
|
61
99
|
header,
|
|
62
100
|
empty,
|
|
63
101
|
className,
|
|
102
|
+
listProps,
|
|
64
103
|
anchorRef,
|
|
65
104
|
panelRef,
|
|
66
105
|
width = 256,
|
|
67
106
|
align = "right",
|
|
68
|
-
children
|
|
107
|
+
children,
|
|
108
|
+
style,
|
|
109
|
+
...rest
|
|
69
110
|
}) {
|
|
70
111
|
const anchored = useAnchoredPanel(anchorRef ?? EMPTY_REF, Boolean(anchorRef));
|
|
71
112
|
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
72
113
|
header,
|
|
73
|
-
/* @__PURE__ */ jsxs("ul", { className: "overflow-y-auto py-1", children: [
|
|
114
|
+
/* @__PURE__ */ jsxs("ul", { ...listProps, className: cn("overflow-y-auto py-1", listProps?.className), children: [
|
|
74
115
|
children,
|
|
75
|
-
empty && /* @__PURE__ */ jsx("li", { className: "px-3 py-2 text-sm text-
|
|
116
|
+
empty && /* @__PURE__ */ jsx("li", { role: "presentation", className: "px-3 py-2 text-sm text-[var(--text-muted)]", children: "\u2014" })
|
|
76
117
|
] })
|
|
77
118
|
] });
|
|
78
119
|
if (!anchorRef) {
|
|
79
120
|
return /* @__PURE__ */ jsx(
|
|
80
121
|
"div",
|
|
81
122
|
{
|
|
123
|
+
...rest,
|
|
124
|
+
style,
|
|
82
125
|
ref: panelRef,
|
|
83
126
|
className: cn(
|
|
84
|
-
"absolute z-30 mt-1 rounded-md border border-
|
|
127
|
+
"absolute z-30 mt-1 rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg",
|
|
85
128
|
"[&>ul]:max-h-64",
|
|
86
129
|
className
|
|
87
130
|
),
|
|
@@ -97,10 +140,11 @@ function DropdownPanel({
|
|
|
97
140
|
/* @__PURE__ */ jsx(
|
|
98
141
|
"div",
|
|
99
142
|
{
|
|
143
|
+
...rest,
|
|
100
144
|
ref: panelRef,
|
|
101
|
-
style: { position: "fixed", top: anchored.top, left, width, maxHeight: anchored.maxHeight },
|
|
145
|
+
style: { ...style, position: "fixed", top: anchored.top, left, width, maxHeight: anchored.maxHeight },
|
|
102
146
|
className: cn(
|
|
103
|
-
"z-50 flex flex-col overflow-hidden rounded-md border border-
|
|
147
|
+
"z-50 flex flex-col overflow-hidden rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg",
|
|
104
148
|
// The list, not the panel, is what scrolls: the search header has to stay put
|
|
105
149
|
// while the options move under it.
|
|
106
150
|
"[&>ul]:min-h-0 [&>ul]:flex-1",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/dropdown.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Search } from \"lucide-react\";\nimport { useAnchoredPanel } from \"../hooks/use-anchored-panel\";\nimport { useOverlayHistory } from \"../hooks/use-overlay-history\";\nimport { cn } from \"../lib/cn\";\n\n/**\n * Open state + close-on-outside-click for the custom dropdowns (MultiSelect,\n * CurrencySelect, AmountInput's currency picker, Combobox). Attach `wrapperRef`\n * to the relatively-positioned container; the popover lives inside it so a click\n * anywhere else closes it.\n *\n * ## Back closes the list, not the page behind it\n *\n * Keksdose live #309 rework: *\"It shall only close it if it is prior open, and not\n * when I am seeing the dialog.\"* Round one wired {@link PickerSheet} — the shape\n * these lists take on a PHONE — into {@link useOverlayHistory}, and left the pointer\n * shape out. So on a desktop one Back press over an open list still went past it to\n * the dialog underneath: measured on his own budget, the transfer form's account list\n * was showing and Back took the entire add card, amount and all. That is the same\n * loss round one called *\"discarding an edit in progress in order to dismiss a\n * list\"*, in the other shell.\n *\n * Every dropdown built on this hook is dismissible and is the topmost thing on screen\n * while it is up, so the rule is the hook's rather than each caller's. `backCloses`\n * is for the ONE case where a second entry would be wrong: a caller whose panel is\n * itself a `PickerSheet`, which already registers one — both comboboxes swap shape at\n * {@link PHONE_QUERY}, and two entries would cost two Back presses to close one sheet.\n */\nexport function useDropdown<T extends HTMLElement = HTMLDivElement>({\n backCloses = true,\n}: { backCloses?: boolean } = {}) {\n const [open, setOpen] = useState(false);\n const wrapperRef = useRef<T>(null);\n // The panel, once it is PORTALLED (see {@link DropdownPanel}'s `anchorRef`): it is\n // then a child of <body> rather than of the wrapper, so \"did the click land inside\n // the wrapper\" answers no for every click on the list itself and the first option a\n // user picked closed the dropdown without picking anything.\n const panelRef = useRef<HTMLDivElement>(null);\n useEffect(() => {\n if (!open) return;\n const handler = (e: MouseEvent) => {\n const target = e.target as Node;\n const inside =\n (wrapperRef.current?.contains(target) ?? false) ||\n (panelRef.current?.contains(target) ?? false);\n if (!inside) setOpen(false);\n };\n document.addEventListener(\"mousedown\", handler);\n return () => document.removeEventListener(\"mousedown\", handler);\n }, [open]);\n // Same close path Escape and an outside click take, so a list dismissed by Back\n // cannot end up in a different state from one dismissed any other way.\n useOverlayHistory(open && backCloses, useCallback(() => setOpen(false), []));\n return { open, setOpen, wrapperRef, panelRef };\n}\n\n/**\n * {@link useDropdown} plus a search box: clears the query and focuses the search\n * input each time the panel opens, so typing filters immediately.\n */\nexport function useDropdownSearch<T extends HTMLElement = HTMLDivElement>() {\n const { open, setOpen, wrapperRef, panelRef } = useDropdown<T>();\n const [query, setQuery] = useState(\"\");\n const inputRef = useRef<HTMLInputElement>(null);\n useEffect(() => {\n if (open) {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- reset the query on open\n setQuery(\"\");\n requestAnimationFrame(() => inputRef.current?.focus());\n }\n }, [open]);\n return { open, setOpen, wrapperRef, panelRef, query, setQuery, inputRef };\n}\n\n/** The search row (magnifier + text input) shared by the searchable dropdowns. */\nexport function DropdownSearchHeader({\n query,\n onQueryChange,\n inputRef,\n placeholder,\n}: {\n query: string;\n onQueryChange: (v: string) => void;\n inputRef: RefObject<HTMLInputElement | null>;\n placeholder?: string;\n}) {\n return (\n <div className=\"flex items-center gap-2 border-b border-slate-100 dark:border-slate-800 px-2 py-1.5\">\n <Search className=\"size-4 text-slate-400 dark:text-slate-500\" />\n <input\n ref={inputRef}\n type=\"text\"\n value={query}\n onChange={(e) => onQueryChange(e.target.value)}\n placeholder={placeholder}\n className=\"w-full bg-transparent text-sm outline-none placeholder:text-slate-400 dark:text-slate-100 dark:placeholder:text-slate-500\"\n />\n </div>\n );\n}\n\n/**\n * The floating popover surface for the searchable dropdowns: bordered/shadowed\n * panel, an optional `header` slot (search box, plus any actions), and a\n * scrollable `<ul>` of `children` with an \"empty\" row when nothing matches.\n *\n * ## Anchored, or merely absolute\n *\n * Without `anchorRef` the panel is `position: absolute` inside whatever relative box\n * the caller put it in, and the caller places it with `className` (`w-64`,\n * `right-0 top-full`). That is fine in a page that does not scroll around it, and\n * wrong the moment an ancestor has `overflow` — the panel is then CLIPPED by that\n * ancestor's box, with no error and no scrollbar, just a list with its side sliced\n * off. Keksdose dev#548 is what that looks like in practice: the app's own content\n * scroller starts 280px from the left, the amount field's currency picker opens\n * right-aligned and 256px wide, and in the transaction row editor its left third —\n * the search box's first letter, and every row's currency symbol — was cut away.\n *\n * With `anchorRef` the panel is PORTALLED to `<body>` and positioned `fixed` against\n * that trigger's rect, so no ancestor can clip it: the same treatment {@link Popover}\n * already gives the calculator, and the same reason. It re-aligns on scroll and\n * resize, flips above the trigger when the room is there instead (a phone keyboard\n * eats the bottom of the screen), and is clamped to the viewport's edges so a trigger\n * near either side cannot push it off-screen.\n *\n * Pass `panelRef` from {@link useDropdown} along with it: once portalled the panel is\n * no longer inside the wrapper, so the outside-click handler has to be told about it\n * or the first click on an option closes the list instead of choosing from it.\n */\nexport function DropdownPanel({\n header,\n empty,\n className,\n anchorRef,\n panelRef,\n width = 256,\n align = \"right\",\n children,\n}: {\n header?: ReactNode;\n empty?: boolean;\n className?: string;\n /** The trigger to hang off. Given, the panel portals and goes `fixed`. */\n anchorRef?: RefObject<HTMLElement | null>;\n /** {@link useDropdown}'s `panelRef`, so an outside-click sees this as inside. */\n panelRef?: RefObject<HTMLDivElement | null>;\n /** Panel width in px, for the anchored form (the CSS `w-*` cannot be measured). */\n width?: number;\n /** Which of the panel's edges lines up with the trigger's, room permitting. */\n align?: \"left\" | \"right\";\n children: ReactNode;\n}) {\n const anchored = useAnchoredPanel(anchorRef ?? EMPTY_REF, Boolean(anchorRef));\n const body = (\n <>\n {header}\n {/* The anchored form caps its own height against the VISIBLE viewport and lets\n this list have the rest; the absolute form keeps the fixed `max-h-64` it has\n always had, applied by the wrapper below. */}\n <ul className=\"overflow-y-auto py-1\">\n {children}\n {empty && <li className=\"px-3 py-2 text-sm text-slate-500 dark:text-slate-400\">—</li>}\n </ul>\n </>\n );\n\n if (!anchorRef) {\n return (\n <div\n ref={panelRef}\n className={cn(\n \"absolute z-30 mt-1 rounded-md border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-900\",\n \"[&>ul]:max-h-64\",\n className,\n )}\n >\n {body}\n </div>\n );\n }\n\n const rect = anchored.rect;\n if (!rect) return null;\n // Clamped exactly as `Popover` clamps: the panel may leave the trigger's edge to\n // stay on screen, because a list half off the viewport is the bug this exists for.\n const wanted = align === \"right\" ? rect.right - width : rect.left;\n const left = Math.min(Math.max(8, wanted), window.innerWidth - width - 8);\n return createPortal(\n <div\n ref={panelRef}\n style={{ position: \"fixed\", top: anchored.top, left, width, maxHeight: anchored.maxHeight }}\n className={cn(\n \"z-50 flex flex-col overflow-hidden rounded-md border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-900\",\n // The list, not the panel, is what scrolls: the search header has to stay put\n // while the options move under it.\n \"[&>ul]:min-h-0 [&>ul]:flex-1\",\n className,\n )}\n >\n {body}\n </div>,\n document.body,\n );\n}\n\n/** A ref that is always null, for the un-anchored form — hooks may not be conditional. */\nconst EMPTY_REF: RefObject<HTMLElement | null> = { current: null };\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/dropdown.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithoutRef,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n RefObject,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Search } from \"lucide-react\";\nimport { useAnchoredPanel } from \"../hooks/use-anchored-panel\";\nimport { useEscapeKey, useOutsideClick } from \"../hooks/use-dismiss\";\nimport { useOverlayHistory } from \"../hooks/use-overlay-history\";\nimport { cn } from \"../lib/cn\";\n\n/**\n * Open state + close-on-outside-click for the custom dropdowns (MultiSelect,\n * CurrencySelect, AmountInput's currency picker, Combobox). Attach `wrapperRef`\n * to the relatively-positioned container; the popover lives inside it so a click\n * anywhere else closes it.\n *\n * ## Back closes the list, not the page behind it\n *\n * Keksdose live #309 rework: *\"It shall only close it if it is prior open, and not\n * when I am seeing the dialog.\"* Round one wired {@link PickerSheet} — the shape\n * these lists take on a PHONE — into {@link useOverlayHistory}, and left the pointer\n * shape out. So on a desktop one Back press over an open list still went past it to\n * the dialog underneath: measured on his own budget, the transfer form's account list\n * was showing and Back took the entire add card, amount and all. That is the same\n * loss round one called *\"discarding an edit in progress in order to dismiss a\n * list\"*, in the other shell.\n *\n * Every dropdown built on this hook is dismissible and is the topmost thing on screen\n * while it is up, so the rule is the hook's rather than each caller's. `backCloses`\n * is for the ONE case where a second entry would be wrong: a caller whose panel is\n * itself a `PickerSheet`, which already registers one — both comboboxes swap shape at\n * {@link PHONE_QUERY}, and two entries would cost two Back presses to close one sheet.\n *\n * ## One outside-click rule for the whole package\n *\n * This hand-rolled a second document listener, on `mousedown`, months after\n * {@link useOutsideClick} — the hook the entity pickers dismiss through — was moved to\n * `pointerdown` for a reason that applies here word for word: on a touch platform\n * `mousedown` is SYNTHESISED, the browser emits it for most taps but is not obliged\n * to, and MultiSelect, CurrencySelect, GroupedPicker, AmountInput's currency picker\n * and both comboboxes all dismiss through this. Two copies of one rule is one copy\n * too many; this now delegates, so the package has a single answer to \"what is an\n * outside press\".\n *\n * `panelIsSheet` is what that delegation needs. A {@link PickerSheet} is modal and\n * fills the screen, so it has no outside — and being portalled to `<body>`, it is\n * inside neither `wrapperRef` nor `panelRef`, so a listener left running would read\n * every tap in it as a press outside and close it at finger-down. The sheet's own\n * `onMouseDown` stopPropagation guard used to hide that from this hook; it cannot\n * stop a `pointerdown`. It defaults to `!backCloses` because the two ask the same\n * question — \"is this caller's panel a sheet?\" — and the one caller that answers yes\n * already says so; they are separate props so a future caller can answer them apart.\n *\n * ## Escape, and where focus lands after it\n *\n * This hook had no Escape at all (the audit's §a11y): Back closed these lists, an\n * outside press closed them, and the one key every other dismissible surface in the\n * package answers to did nothing — so a keyboard user who opened a list had no way\n * out of it that did not also choose something. {@link useEscapeKey} is the listener\n * `Modal`, `Popover` and `useComboboxCore` already dismiss through, so the package\n * keeps one answer to \"what does Escape do\" rather than growing a fifth.\n *\n * Escape RESTORES FOCUS; an outside press does not. A press has already put focus\n * where the user pointed, and dragging it back from there would be the bug. Attach\n * `triggerRef` to the control that opens the panel and the keyboard paths — Escape,\n * Tab, a commit — hand focus back to it; leave it unattached and they simply close,\n * which is what the callers written before this get.\n */\nexport function useDropdown<T extends HTMLElement = HTMLDivElement>({\n backCloses = true,\n panelIsSheet = !backCloses,\n}: { backCloses?: boolean; panelIsSheet?: boolean } = {}) {\n const [open, setOpen] = useState(false);\n const wrapperRef = useRef<T>(null);\n // The control that opens the panel — see the note above on why only the keyboard\n // paths read it, and why attaching it is the caller's choice.\n const triggerRef = useRef<HTMLButtonElement>(null);\n // The panel, once it is PORTALLED (see {@link DropdownPanel}'s `anchorRef`): it is\n // then a child of <body> rather than of the wrapper, so \"did the click land inside\n // the wrapper\" answers no for every click on the list itself and the first option a\n // user picked closed the dropdown without picking anything.\n const panelRef = useRef<HTMLDivElement>(null);\n const close = useCallback(() => setOpen(false), []);\n // Closing unmounts whatever held focus — the search box, the row the keyboard was\n // on — and the browser then drops focus on <body>: the caret vanishes and the next\n // Tab restarts at the top of the document. Whoever closed the list with a key gets\n // it handed back to the trigger they opened it from.\n const closeToTrigger = useCallback(() => {\n setOpen(false);\n triggerRef.current?.focus();\n }, []);\n useOutsideClick([wrapperRef, panelRef], close, open && !panelIsSheet);\n useEscapeKey(closeToTrigger, open);\n // Same close path Escape and an outside click take, so a list dismissed by Back\n // cannot end up in a different state from one dismissed any other way.\n useOverlayHistory(open && backCloses, close);\n return { open, setOpen, wrapperRef, panelRef, triggerRef, closeToTrigger };\n}\n\n/**\n * {@link useDropdown} plus a search box: clears the query and focuses the search\n * input each time the panel opens, so typing filters immediately.\n */\nexport function useDropdownSearch<T extends HTMLElement = HTMLDivElement>() {\n const { open, setOpen, wrapperRef, panelRef, triggerRef, closeToTrigger } =\n useDropdown<T>();\n const [query, setQuery] = useState(\"\");\n const inputRef = useRef<HTMLInputElement>(null);\n useEffect(() => {\n if (open) {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- reset the query on open\n setQuery(\"\");\n requestAnimationFrame(() => inputRef.current?.focus());\n }\n }, [open]);\n return {\n open,\n setOpen,\n wrapperRef,\n panelRef,\n triggerRef,\n closeToTrigger,\n query,\n setQuery,\n inputRef,\n };\n}\n\n/** `onKeyDown` is the INPUT's, not the wrapper's — the list's keyboard is handled\n * where the focus is (see the note above), so the div's own handler signature is\n * omitted in favour of it. */\nexport interface DropdownSearchHeaderProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onKeyDown\"> {\n query: string;\n onQueryChange: (v: string) => void;\n inputRef: RefObject<HTMLInputElement | null>;\n placeholder?: string;\n /** The `<ul role=\"listbox\">` this box filters. */\n listboxId?: string;\n /** The id of the option the arrow keys are currently on, if any. */\n activeId?: string;\n /** Arrow/Home/End/Enter/Tab — the list's keyboard, handled where the focus is. */\n onKeyDown?: (e: ReactKeyboardEvent<HTMLInputElement>) => void;\n}\n\n/** The search row (magnifier + text input) shared by the searchable dropdowns.\n *\n * The input had `outline-none` and nothing in its place (the audit's §a11y, the same\n * finding as the numpad's keys). That mattered more here than the bare class suggests:\n * {@link useDropdownSearch} focuses this box the moment a panel opens, so the caret is\n * the ONLY evidence of where the next keystroke goes — and a caret in an empty field\n * showing a placeholder is a single blinking pixel column. The ring is what says \"this\n * list is being typed into\"; it appears whenever the field holds focus, which for a\n * text input is exactly when it is true.\n *\n * ## Why this box is a plain textbox and the TRIGGER is the combobox\n *\n * The panels this header sits in are opened by a field-shaped trigger, and that\n * trigger is what carries `role=\"combobox\"` (see {@link MultiSelect},\n * {@link EntityCombobox}). Two comboboxes for one list would be one too many — a\n * reader tabbing back to the field would meet a second one describing the same\n * choice. So this stays a textbox, which ARIA lets own `aria-activedescendant` and\n * `aria-controls` exactly as a combobox does: focus is HERE while the list is up, so\n * this is what has to say which option the arrow keys are on.\n *\n * Pass `listboxId` and the wiring appears; omit it and the box is what it always\n * was, for the callers that have no listbox to point at. */\nexport function DropdownSearchHeader({\n query,\n onQueryChange,\n inputRef,\n placeholder,\n listboxId,\n activeId,\n onKeyDown,\n \"aria-label\": ariaLabel,\n className,\n ...rest\n}: DropdownSearchHeaderProps) {\n return (\n // `rest` dresses the header row; the NAME goes on the box below it. A search\n // input whose only name is its placeholder has none the moment a character is\n // typed into it — the placeholder disappears — which is why this is worth a prop\n // at all rather than something a caller could add from outside.\n <div\n {...rest}\n className={cn(\n \"flex items-center gap-2 border-b border-[var(--border)] px-2 py-1.5\",\n className,\n )}\n >\n <Search className=\"size-4 text-[var(--text-placeholder)]\" />\n <input\n ref={inputRef}\n type=\"text\"\n value={query}\n onChange={(e) => onQueryChange(e.target.value)}\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n aria-label={ariaLabel}\n aria-controls={listboxId}\n aria-activedescendant={activeId}\n aria-autocomplete={listboxId ? \"list\" : undefined}\n className=\"w-full rounded-sm bg-transparent text-sm outline-none placeholder:text-[var(--text-placeholder)] text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--brand)]\"\n />\n </div>\n );\n}\n\nexport interface DropdownPanelProps extends ComponentPropsWithoutRef<\"div\"> {\n header?: ReactNode;\n empty?: boolean;\n /** Attributes for the `<ul>` itself — how a caller whose children are options\n * gives the list its `role=\"listbox\"`, its id and `aria-multiselectable`. The\n * panel owns the scrolling and the padding, so `className` here is merged rather\n * than replaced. */\n listProps?: ComponentPropsWithoutRef<\"ul\">;\n /** The trigger to hang off. Given, the panel portals and goes `fixed`. */\n anchorRef?: RefObject<HTMLElement | null>;\n /** {@link useDropdown}'s `panelRef`, so an outside-click sees this as inside. */\n panelRef?: RefObject<HTMLDivElement | null>;\n /** Panel width in px, for the anchored form (the CSS `w-*` cannot be measured). */\n width?: number;\n /** Which of the panel's edges lines up with the trigger's, room permitting. */\n align?: \"left\" | \"right\";\n children: ReactNode;\n}\n\n/**\n * The floating popover surface for the searchable dropdowns: bordered/shadowed\n * panel, an optional `header` slot (search box, plus any actions), and a\n * scrollable `<ul>` of `children` with an \"empty\" row when nothing matches.\n *\n * ## Anchored, or merely absolute\n *\n * Without `anchorRef` the panel is `position: absolute` inside whatever relative box\n * the caller put it in, and the caller places it with `className` (`w-64`,\n * `right-0 top-full`). That is fine in a page that does not scroll around it, and\n * wrong the moment an ancestor has `overflow` — the panel is then CLIPPED by that\n * ancestor's box, with no error and no scrollbar, just a list with its side sliced\n * off. Keksdose dev#548 is what that looks like in practice: the app's own content\n * scroller starts 280px from the left, the amount field's currency picker opens\n * right-aligned and 256px wide, and in the transaction row editor its left third —\n * the search box's first letter, and every row's currency symbol — was cut away.\n *\n * With `anchorRef` the panel is PORTALLED to `<body>` and positioned `fixed` against\n * that trigger's rect, so no ancestor can clip it: the same treatment {@link Popover}\n * already gives the calculator, and the same reason. It re-aligns on scroll and\n * resize, flips above the trigger when the room is there instead (a phone keyboard\n * eats the bottom of the screen), and is clamped to the viewport's edges so a trigger\n * near either side cannot push it off-screen.\n *\n * Pass `panelRef` from {@link useDropdown} along with it: once portalled the panel is\n * no longer inside the wrapper, so the outside-click handler has to be told about it\n * or the first click on an option closes the list instead of choosing from it.\n */\nexport function DropdownPanel({\n header,\n empty,\n className,\n listProps,\n anchorRef,\n panelRef,\n width = 256,\n align = \"right\",\n children,\n style,\n ...rest\n}: DropdownPanelProps) {\n const anchored = useAnchoredPanel(anchorRef ?? EMPTY_REF, Boolean(anchorRef));\n const body = (\n <>\n {header}\n {/* The anchored form caps its own height against the VISIBLE viewport and lets\n this list have the rest; the absolute form keeps the fixed `max-h-64` it has\n always had, applied by the wrapper below. */}\n <ul {...listProps} className={cn(\"overflow-y-auto py-1\", listProps?.className)}>\n {children}\n {/* `presentation`, so that a caller who made this list a `listbox` does not\n end up with one child that is not an option. The em dash still reads — it\n is the row's semantics that are dropped, not its text. */}\n {empty && (\n <li role=\"presentation\" className=\"px-3 py-2 text-sm text-[var(--text-muted)]\">\n —\n </li>\n )}\n </ul>\n </>\n );\n\n if (!anchorRef) {\n return (\n <div\n {...rest}\n style={style}\n ref={panelRef}\n className={cn(\n \"absolute z-30 mt-1 rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg\",\n \"[&>ul]:max-h-64\",\n className,\n )}\n >\n {body}\n </div>\n );\n }\n\n const rect = anchored.rect;\n if (!rect) return null;\n // Clamped exactly as `Popover` clamps: the panel may leave the trigger's edge to\n // stay on screen, because a list half off the viewport is the bug this exists for.\n const wanted = align === \"right\" ? rect.right - width : rect.left;\n const left = Math.min(Math.max(8, wanted), window.innerWidth - width - 8);\n return createPortal(\n <div\n {...rest}\n ref={panelRef}\n // The caller's `style` is kept underneath, but the placement is measured rather\n // than chosen (dev#548: an `overflow` ancestor clipped a third of this panel\n // away), so those five values are the panel's own.\n style={{ ...style, position: \"fixed\", top: anchored.top, left, width, maxHeight: anchored.maxHeight }}\n className={cn(\n \"z-50 flex flex-col overflow-hidden rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg\",\n // The list, not the panel, is what scrolls: the search header has to stay put\n // while the options move under it.\n \"[&>ul]:min-h-0 [&>ul]:flex-1\",\n className,\n )}\n >\n {body}\n </div>,\n document.body,\n );\n}\n\n/** A ref that is always null, for the un-anchored form — hooks may not be conditional. */\nconst EMPTY_REF: RefObject<HTMLElement | null> = { current: null };\n"],"mappings":"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","names":[]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
3
|
import { ComboOption } from './combobox-core.js';
|
|
4
4
|
import '../hooks/use-anchored-rect.js';
|
|
5
5
|
import '../hooks/use-anchored-panel.js';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/** `onChange` is the kit's — "a selection was made", carrying values — rather
|
|
8
|
+
* than the div's form event, so the DOM's spelling of it is omitted. */
|
|
9
|
+
interface EntityComboboxProps<V extends string | number> extends Omit<ComponentPropsWithoutRef<"div">, "onChange"> {
|
|
8
10
|
/** Selected id, or null/undefined when nothing is selected. */
|
|
9
11
|
value: V | null | undefined;
|
|
10
12
|
/** Selecting an option emits its value; the clear button emits `null`. */
|
|
@@ -33,7 +35,6 @@ interface EntityComboboxProps<V extends string | number> {
|
|
|
33
35
|
/** When set, a "create" row appears for a non-empty query with no exact match. */
|
|
34
36
|
onCreate?: (query: string) => void;
|
|
35
37
|
createLabel?: (query: string) => string;
|
|
36
|
-
className?: string;
|
|
37
38
|
/** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */
|
|
38
39
|
invalid?: boolean;
|
|
39
40
|
}
|
|
@@ -44,6 +45,6 @@ interface EntityComboboxProps<V extends string | number> {
|
|
|
44
45
|
* the shared field/anchor/dismiss/search primitives (no cmdk/Radix). For picking
|
|
45
46
|
* several entities use {@link MultiEntityCombobox}.
|
|
46
47
|
*/
|
|
47
|
-
declare function EntityCombobox<V extends string | number>({ value, onChange, options, loadOptions, loading, label, placeholder, searchPlaceholder, emptyLabel, clearable, clearLabel, closeLabel, disabled, onCreate, createLabel, className, invalid, }: EntityComboboxProps<V>): react.JSX.Element;
|
|
48
|
+
declare function EntityCombobox<V extends string | number>({ value, onChange, options, loadOptions, loading, label, placeholder, searchPlaceholder, emptyLabel, clearable, clearLabel, closeLabel, disabled, onCreate, createLabel, className, invalid, "aria-label": ariaLabel, ...rest }: EntityComboboxProps<V>): react.JSX.Element;
|
|
48
49
|
|
|
49
50
|
export { ComboOption, EntityCombobox, type EntityComboboxProps };
|