@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
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
11
|
+
import { createPortal } from "react-dom";
|
|
12
|
+
import { cn } from "../lib/cn";
|
|
13
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
14
|
+
import { Button } from "../components/ui";
|
|
15
|
+
import { useFocusTrap } from "../hooks/use-focus-trap";
|
|
16
|
+
|
|
17
|
+
export type TourPlacement = "top" | "right" | "bottom" | "left" | "center";
|
|
18
|
+
|
|
19
|
+
export interface TourStep {
|
|
20
|
+
/** CSS selector for the element to spotlight. Omit for a centered step
|
|
21
|
+
* (welcome/finish). If the target isn't found/visible, the step centers. */
|
|
22
|
+
target?: string;
|
|
23
|
+
title: string;
|
|
24
|
+
body: ReactNode;
|
|
25
|
+
/** Extra footer content, e.g. a "load sample data" shortcut. */
|
|
26
|
+
action?: ReactNode;
|
|
27
|
+
/** Spotlight padding around the target, px (default 8). */
|
|
28
|
+
padding?: number;
|
|
29
|
+
/** Where the card sits relative to the target. Omit for auto placement
|
|
30
|
+
* (below → above → centered). "center" ignores the target and centers on
|
|
31
|
+
* screen. An explicit side flips to the opposite side if it would overflow,
|
|
32
|
+
* then clamps into the viewport. */
|
|
33
|
+
placement?: TourPlacement;
|
|
34
|
+
/** Advance only when the user clicks the spotlighted target itself (not the
|
|
35
|
+
* card's Next button). Requires `target`: the real control's own handler runs
|
|
36
|
+
* first, then the tour steps forward on a microtask. The overlay stays
|
|
37
|
+
* click-through to the target. */
|
|
38
|
+
awaitClick?: boolean;
|
|
39
|
+
/** Runs before the step is shown — e.g. navigate to a route, open a panel.
|
|
40
|
+
* May be async; the step waits for it, then locates the target. */
|
|
41
|
+
beforeStep?: () => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface TourLabels {
|
|
45
|
+
next: string;
|
|
46
|
+
back: string;
|
|
47
|
+
skip: string;
|
|
48
|
+
done: string;
|
|
49
|
+
/** Shown in place of the Next button on an `awaitClick` step. */
|
|
50
|
+
awaitClickHint: string;
|
|
51
|
+
/** Step counter, e.g. (2, 7) => "2 / 7". */
|
|
52
|
+
step: (current: number, total: number) => string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const DEFAULT_TOUR_LABELS: TourLabels = {
|
|
56
|
+
next: "Next",
|
|
57
|
+
back: "Back",
|
|
58
|
+
skip: "Skip",
|
|
59
|
+
done: "Done",
|
|
60
|
+
awaitClickHint: "Click the highlighted element to continue",
|
|
61
|
+
step: (c, t) => `${c} / ${t}`,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
interface StartOptions {
|
|
65
|
+
/** Stable id of the tour, surfaced as `activeId` so the app can mirror it to
|
|
66
|
+
* the URL (deep-link / evaluation tracking) and record completion. */
|
|
67
|
+
id?: string;
|
|
68
|
+
/** Start at this step index instead of 0 (clamped) — for URL/deep-link resume. */
|
|
69
|
+
startIndex?: number;
|
|
70
|
+
/** Fires synchronously when the tour starts (e.g. enable a mock interceptor). */
|
|
71
|
+
onStart?: () => void;
|
|
72
|
+
onFinish?: () => void;
|
|
73
|
+
onSkip?: () => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface TourContextValue {
|
|
77
|
+
active: boolean;
|
|
78
|
+
/** Id of the running tour (from {@link StartOptions.id}), else null. */
|
|
79
|
+
activeId: string | null;
|
|
80
|
+
/** Start a tour with the given steps. */
|
|
81
|
+
start: (steps: TourStep[], opts?: StartOptions) => void;
|
|
82
|
+
/** End the current tour (no callbacks fire). */
|
|
83
|
+
stop: () => void;
|
|
84
|
+
/** Advance one step; past the last step it finishes the tour (fires onFinish). */
|
|
85
|
+
next: () => void;
|
|
86
|
+
/** Go back one step (no-op on the first). */
|
|
87
|
+
prev: () => void;
|
|
88
|
+
/** Jump to a step by index, clamped to range — e.g. for URL/deep-link resume. */
|
|
89
|
+
goToStep: (index: number) => void;
|
|
90
|
+
/** Current step (0-based; 0 while inactive). */
|
|
91
|
+
index: number;
|
|
92
|
+
/** Total steps (0 while inactive). */
|
|
93
|
+
total: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const TourContext = createContext<TourContextValue | null>(null);
|
|
97
|
+
|
|
98
|
+
export function useTour(): TourContextValue {
|
|
99
|
+
const ctx = useContext(TourContext);
|
|
100
|
+
if (!ctx) throw new Error("useTour must be used within <TourProvider>");
|
|
101
|
+
return ctx;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The tour engine if it is there, `null` if it is not — for a control that is a
|
|
106
|
+
* DECORATION rather than a participant.
|
|
107
|
+
*
|
|
108
|
+
* {@link useTour}'s throw is correct and stays: a component that runs a tour cannot do
|
|
109
|
+
* its job without the provider, and failing loudly is how that gets fixed. But the
|
|
110
|
+
* throw's blast radius is whatever error boundary is above it, and for a launcher in
|
|
111
|
+
* the app shell that is the whole app.
|
|
112
|
+
*
|
|
113
|
+
* Keksdose feedback dev#524 is what that costs: an `@hb/ui` module was edited while a
|
|
114
|
+
* dev server was running, vite re-evaluated it, and the module's freshly created
|
|
115
|
+
* context object was no longer the one the mounted provider was providing. React's
|
|
116
|
+
* `useContext` then answers `null` for a provider that is, structurally, right there —
|
|
117
|
+
* and the top bar's tour menu took the entire shell down with it. **Build-time module
|
|
118
|
+
* graphs cannot produce that**, so it is a development-only failure; a menu that
|
|
119
|
+
* disappears for a second is the proportionate response to it either way.
|
|
120
|
+
*
|
|
121
|
+
* Only for controls that can honestly render nothing. If a component would show a
|
|
122
|
+
* broken half of itself without the tour, it wants {@link useTour}.
|
|
123
|
+
*/
|
|
124
|
+
export function useTourOptional(): TourContextValue | null {
|
|
125
|
+
return useContext(TourContext);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Provides the guided-tour engine: a dimmed spotlight overlay + step card driven
|
|
130
|
+
* by a list of {@link TourStep}s. Domain-free — the app supplies the steps (copy,
|
|
131
|
+
* selectors, per-step navigation, placement) and the translated {@link TourLabels}.
|
|
132
|
+
* Mount once inside the router; start a tour from anywhere via {@link useTour},
|
|
133
|
+
* which also exposes step control (`next`/`prev`/`goToStep`) and the current
|
|
134
|
+
* `index`/`total` for URL mirroring, `awaitClick` and deep-link resume.
|
|
135
|
+
*/
|
|
136
|
+
export function TourProvider({
|
|
137
|
+
children,
|
|
138
|
+
labels,
|
|
139
|
+
}: {
|
|
140
|
+
children: ReactNode;
|
|
141
|
+
labels?: Partial<TourLabels>;
|
|
142
|
+
}) {
|
|
143
|
+
// `labels` over the provider's `tour` over English. Resolved once here and handed
|
|
144
|
+
// down: the step card is portalled, but context crosses portals anyway — this is
|
|
145
|
+
// simply the one place that already owned the merge.
|
|
146
|
+
const merged = useKitLabels("tour", DEFAULT_TOUR_LABELS, labels);
|
|
147
|
+
const [steps, setSteps] = useState<TourStep[] | null>(null);
|
|
148
|
+
const [index, setIndex] = useState(0);
|
|
149
|
+
const [activeId, setActiveId] = useState<string | null>(null);
|
|
150
|
+
const optsRef = useRef<StartOptions>({});
|
|
151
|
+
// Live mirrors so the step-control callbacks can stay stable (identity-safe for
|
|
152
|
+
// consumers) while still reading the current steps/index.
|
|
153
|
+
const stepsRef = useRef<TourStep[] | null>(null);
|
|
154
|
+
stepsRef.current = steps;
|
|
155
|
+
const indexRef = useRef(0);
|
|
156
|
+
indexRef.current = index;
|
|
157
|
+
const active = !!steps && steps.length > 0;
|
|
158
|
+
const total = steps?.length ?? 0;
|
|
159
|
+
|
|
160
|
+
const start = useCallback((s: TourStep[], opts?: StartOptions) => {
|
|
161
|
+
optsRef.current = opts ?? {};
|
|
162
|
+
optsRef.current.onStart?.();
|
|
163
|
+
setIndex(Math.min(Math.max(0, opts?.startIndex ?? 0), Math.max(0, s.length - 1)));
|
|
164
|
+
setActiveId(opts?.id ?? null);
|
|
165
|
+
setSteps(s);
|
|
166
|
+
}, []);
|
|
167
|
+
const stop = useCallback(() => {
|
|
168
|
+
setSteps(null);
|
|
169
|
+
setActiveId(null);
|
|
170
|
+
}, []);
|
|
171
|
+
const finish = useCallback(() => {
|
|
172
|
+
optsRef.current.onFinish?.();
|
|
173
|
+
setSteps(null);
|
|
174
|
+
setActiveId(null);
|
|
175
|
+
}, []);
|
|
176
|
+
const skip = useCallback(() => {
|
|
177
|
+
optsRef.current.onSkip?.();
|
|
178
|
+
setSteps(null);
|
|
179
|
+
setActiveId(null);
|
|
180
|
+
}, []);
|
|
181
|
+
|
|
182
|
+
const goToStep = useCallback((i: number) => {
|
|
183
|
+
const len = stepsRef.current?.length ?? 0;
|
|
184
|
+
if (len === 0) return;
|
|
185
|
+
setIndex(Math.min(Math.max(0, i), len - 1));
|
|
186
|
+
}, []);
|
|
187
|
+
const next = useCallback(() => {
|
|
188
|
+
const len = stepsRef.current?.length ?? 0;
|
|
189
|
+
if (len === 0) return;
|
|
190
|
+
if (indexRef.current >= len - 1) finish();
|
|
191
|
+
else setIndex(indexRef.current + 1);
|
|
192
|
+
}, [finish]);
|
|
193
|
+
const prev = useCallback(() => {
|
|
194
|
+
if (indexRef.current > 0) setIndex(indexRef.current - 1);
|
|
195
|
+
}, []);
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<TourContext.Provider value={{ active, activeId, start, stop, next, prev, goToStep, index, total }}>
|
|
199
|
+
{children}
|
|
200
|
+
{active && (
|
|
201
|
+
<TourOverlay
|
|
202
|
+
steps={steps!}
|
|
203
|
+
index={index}
|
|
204
|
+
labels={merged}
|
|
205
|
+
onNext={next}
|
|
206
|
+
onPrev={prev}
|
|
207
|
+
onSkip={skip}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
</TourContext.Provider>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface Rect {
|
|
215
|
+
top: number;
|
|
216
|
+
left: number;
|
|
217
|
+
width: number;
|
|
218
|
+
height: number;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function isVisible(el: Element): boolean {
|
|
222
|
+
// A non-zero box already rules out display:none on the element or any ancestor
|
|
223
|
+
// (an unrendered element measures 0x0). We deliberately do NOT test
|
|
224
|
+
// offsetParent: it is null for position:fixed elements even when fully visible,
|
|
225
|
+
// which made the mobile bottom-nav bar (fixed) un-highlightable on mobile
|
|
226
|
+
// (feedback #313). visibility:hidden keeps a box, so check it explicitly.
|
|
227
|
+
const r = el.getBoundingClientRect();
|
|
228
|
+
if (r.width <= 0 || r.height <= 0) return false;
|
|
229
|
+
const style = getComputedStyle(el);
|
|
230
|
+
return style.visibility !== "hidden" && style.display !== "none";
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// The first VISIBLE element matching the selector, not merely the first in DOM
|
|
234
|
+
// order. This lets a step target the same control across layouts with one
|
|
235
|
+
// combined selector — e.g. the desktop sidebar link AND the mobile bottom-bar
|
|
236
|
+
// link — where the off-layout copy is present but `display:none` (feedback
|
|
237
|
+
// #313). Returns null while none is visible so the finder keeps retrying.
|
|
238
|
+
function queryVisibleTarget(selector: string): Element | null {
|
|
239
|
+
const els = document.querySelectorAll(selector);
|
|
240
|
+
for (const el of els) {
|
|
241
|
+
if (isVisible(el)) return el;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function sameRect(a: Rect | null, b: Rect | null): boolean {
|
|
247
|
+
if (a === b) return true;
|
|
248
|
+
if (!a || !b) return false;
|
|
249
|
+
return a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function TourOverlay({
|
|
253
|
+
steps,
|
|
254
|
+
index,
|
|
255
|
+
labels,
|
|
256
|
+
onNext,
|
|
257
|
+
onPrev,
|
|
258
|
+
onSkip,
|
|
259
|
+
}: {
|
|
260
|
+
steps: TourStep[];
|
|
261
|
+
index: number;
|
|
262
|
+
labels: TourLabels;
|
|
263
|
+
onNext: () => void;
|
|
264
|
+
onPrev: () => void;
|
|
265
|
+
onSkip: () => void;
|
|
266
|
+
}) {
|
|
267
|
+
const step = steps[index];
|
|
268
|
+
const isFirst = index === 0;
|
|
269
|
+
const isLast = index === steps.length - 1;
|
|
270
|
+
const [rect, setRect] = useState<Rect | null>(null);
|
|
271
|
+
const [ready, setReady] = useState(false);
|
|
272
|
+
|
|
273
|
+
// Run beforeStep, then locate the target (retrying across route/render lag).
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
let cancelled = false;
|
|
276
|
+
let raf = 0;
|
|
277
|
+
setReady(false);
|
|
278
|
+
setRect(null);
|
|
279
|
+
void (async () => {
|
|
280
|
+
await step.beforeStep?.();
|
|
281
|
+
if (cancelled) return;
|
|
282
|
+
if (!step.target) {
|
|
283
|
+
setReady(true);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
let tries = 0;
|
|
287
|
+
const find = () => {
|
|
288
|
+
if (cancelled) return;
|
|
289
|
+
const el = queryVisibleTarget(step.target!);
|
|
290
|
+
if (el) {
|
|
291
|
+
el.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
292
|
+
const r = el.getBoundingClientRect();
|
|
293
|
+
setRect({ top: r.top, left: r.left, width: r.width, height: r.height });
|
|
294
|
+
setReady(true);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (tries++ < 45) raf = requestAnimationFrame(find);
|
|
298
|
+
else setReady(true); // give up → render centered
|
|
299
|
+
};
|
|
300
|
+
find();
|
|
301
|
+
})();
|
|
302
|
+
return () => {
|
|
303
|
+
cancelled = true;
|
|
304
|
+
cancelAnimationFrame(raf);
|
|
305
|
+
};
|
|
306
|
+
}, [index, step]);
|
|
307
|
+
|
|
308
|
+
// Follow the target as the page scrolls / reflows.
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
if (!step.target) return;
|
|
311
|
+
const update = () => {
|
|
312
|
+
const el = queryVisibleTarget(step.target!);
|
|
313
|
+
if (el) {
|
|
314
|
+
const r = el.getBoundingClientRect();
|
|
315
|
+
const next = { top: r.top, left: r.left, width: r.width, height: r.height };
|
|
316
|
+
setRect((prev) => (sameRect(prev, next) ? prev : next));
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
window.addEventListener("scroll", update, true);
|
|
320
|
+
window.addEventListener("resize", update);
|
|
321
|
+
const id = window.setInterval(update, 250);
|
|
322
|
+
return () => {
|
|
323
|
+
window.removeEventListener("scroll", update, true);
|
|
324
|
+
window.removeEventListener("resize", update);
|
|
325
|
+
clearInterval(id);
|
|
326
|
+
};
|
|
327
|
+
}, [index, step]);
|
|
328
|
+
|
|
329
|
+
// awaitClick: advance when the *real* target is clicked. The overlay is
|
|
330
|
+
// click-through (pointer-events-none except the card) so the element's own
|
|
331
|
+
// handler runs first; we step forward on the next macrotask.
|
|
332
|
+
useEffect(() => {
|
|
333
|
+
if (!ready || !step.awaitClick || !step.target) return;
|
|
334
|
+
const el = queryVisibleTarget(step.target);
|
|
335
|
+
if (!el) return;
|
|
336
|
+
const onClick = () => window.setTimeout(() => onNext(), 0);
|
|
337
|
+
el.addEventListener("click", onClick, { once: true });
|
|
338
|
+
return () => el.removeEventListener("click", onClick);
|
|
339
|
+
}, [ready, index, step, onNext]);
|
|
340
|
+
|
|
341
|
+
// Keyboard: Esc skips, →/Enter advance, ← goes back. On awaitClick steps Enter
|
|
342
|
+
// is ignored (it would fire the target's click AND advance) — → stays as an
|
|
343
|
+
// escape hatch.
|
|
344
|
+
useEffect(() => {
|
|
345
|
+
const onKey = (e: KeyboardEvent) => {
|
|
346
|
+
if (e.key === "Escape") {
|
|
347
|
+
onSkip();
|
|
348
|
+
} else if (e.key === "ArrowRight") {
|
|
349
|
+
e.preventDefault();
|
|
350
|
+
onNext();
|
|
351
|
+
} else if (e.key === "Enter") {
|
|
352
|
+
if (step.awaitClick) return;
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
onNext();
|
|
355
|
+
} else if (e.key === "ArrowLeft") {
|
|
356
|
+
if (!isFirst) onPrev();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
document.addEventListener("keydown", onKey);
|
|
360
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
361
|
+
}, [isFirst, step, onNext, onPrev, onSkip]);
|
|
362
|
+
|
|
363
|
+
if (!ready) return null;
|
|
364
|
+
|
|
365
|
+
const pad = step.padding ?? 8;
|
|
366
|
+
const spot: Rect | null = rect
|
|
367
|
+
? { top: rect.top - pad, left: rect.left - pad, width: rect.width + pad * 2, height: rect.height + pad * 2 }
|
|
368
|
+
: null;
|
|
369
|
+
|
|
370
|
+
return createPortal(
|
|
371
|
+
<div className="pointer-events-none fixed inset-0 z-[60]" role="dialog" aria-modal="true" aria-label={step.title}>
|
|
372
|
+
{spot ? (
|
|
373
|
+
<div
|
|
374
|
+
className="pointer-events-none fixed rounded-lg transition-all duration-200 ease-out"
|
|
375
|
+
style={{
|
|
376
|
+
top: spot.top,
|
|
377
|
+
left: spot.left,
|
|
378
|
+
width: spot.width,
|
|
379
|
+
height: spot.height,
|
|
380
|
+
// A two-tone frame, not a single translucent ring.
|
|
381
|
+
//
|
|
382
|
+
// The old treatment was `ring-2 ring-white/80` over a 55% scrim, and it
|
|
383
|
+
// "was barely visible" on the app's blue-tinted surfaces. Two reasons,
|
|
384
|
+
// and a single ring can't fix either: at 55% the surround stays bright
|
|
385
|
+
// enough that the un-dimmed hole barely reads AS a hole, and a 80%-white
|
|
386
|
+
// ring sitting on the edge of a light card is white-on-near-white.
|
|
387
|
+
//
|
|
388
|
+
// So: an opaque white band immediately around the target, a dark keyline
|
|
389
|
+
// outside it, then the scrim. Whatever the target's own colour is, one of
|
|
390
|
+
// the two bands is always in contrast with it and the other is always in
|
|
391
|
+
// contrast with the dimmed surround — there is no background that can
|
|
392
|
+
// swallow both. The blurred layer between them softens the step so the
|
|
393
|
+
// frame reads as lighting rather than as a pasted-on rectangle.
|
|
394
|
+
boxShadow: [
|
|
395
|
+
"0 0 0 3px rgba(255,255,255,0.98)",
|
|
396
|
+
"0 0 0 5px rgba(15,23,42,0.92)",
|
|
397
|
+
"0 0 18px 6px rgba(15,23,42,0.45)",
|
|
398
|
+
"0 0 0 9999px rgba(15,23,42,0.70)",
|
|
399
|
+
].join(", "),
|
|
400
|
+
}}
|
|
401
|
+
/>
|
|
402
|
+
) : (
|
|
403
|
+
<div className="pointer-events-auto fixed inset-0 bg-black/70" />
|
|
404
|
+
)}
|
|
405
|
+
<TourCard
|
|
406
|
+
step={step}
|
|
407
|
+
index={index}
|
|
408
|
+
total={steps.length}
|
|
409
|
+
labels={labels}
|
|
410
|
+
isFirst={isFirst}
|
|
411
|
+
isLast={isLast}
|
|
412
|
+
rect={spot}
|
|
413
|
+
onBack={onPrev}
|
|
414
|
+
onNext={onNext}
|
|
415
|
+
onSkip={onSkip}
|
|
416
|
+
/>
|
|
417
|
+
</div>,
|
|
418
|
+
document.body,
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Card position (viewport px) for the given placement relative to the padded
|
|
424
|
+
* spotlight `rect`. Omitted placement keeps the original auto behavior
|
|
425
|
+
* (below → above → vertically centered); an explicit side flips to its opposite
|
|
426
|
+
* if it would overflow, then clamps into the viewport. "center" (or no rect)
|
|
427
|
+
* centers on screen.
|
|
428
|
+
*/
|
|
429
|
+
function placeCard(
|
|
430
|
+
rect: Rect | null,
|
|
431
|
+
cw: number,
|
|
432
|
+
ch: number,
|
|
433
|
+
vw: number,
|
|
434
|
+
vh: number,
|
|
435
|
+
m: number,
|
|
436
|
+
placement?: TourPlacement,
|
|
437
|
+
): { top: number; left: number } {
|
|
438
|
+
if (!rect || placement === "center") {
|
|
439
|
+
return { top: Math.max(m, (vh - ch) / 2), left: Math.max(m, (vw - cw) / 2) };
|
|
440
|
+
}
|
|
441
|
+
const clampX = (x: number) => Math.min(Math.max(m, x), Math.max(m, vw - cw - m));
|
|
442
|
+
const clampY = (y: number) => Math.min(Math.max(m, y), Math.max(m, vh - ch - m));
|
|
443
|
+
const centerX = clampX(rect.left + rect.width / 2 - cw / 2);
|
|
444
|
+
const centerY = clampY(rect.top + rect.height / 2 - ch / 2);
|
|
445
|
+
const belowTop = rect.top + rect.height + m;
|
|
446
|
+
const aboveTop = rect.top - ch - m;
|
|
447
|
+
const rightLeft = rect.left + rect.width + m;
|
|
448
|
+
const leftLeft = rect.left - cw - m;
|
|
449
|
+
const fitsBelow = belowTop + ch <= vh;
|
|
450
|
+
const fitsAbove = aboveTop >= 0;
|
|
451
|
+
const fitsRight = rightLeft + cw <= vw;
|
|
452
|
+
const fitsLeft = leftLeft >= 0;
|
|
453
|
+
|
|
454
|
+
switch (placement) {
|
|
455
|
+
case "top":
|
|
456
|
+
return { top: fitsAbove ? aboveTop : fitsBelow ? belowTop : clampY(aboveTop), left: centerX };
|
|
457
|
+
case "bottom":
|
|
458
|
+
return { top: fitsBelow ? belowTop : fitsAbove ? aboveTop : clampY(belowTop), left: centerX };
|
|
459
|
+
case "right":
|
|
460
|
+
return { top: centerY, left: fitsRight ? rightLeft : fitsLeft ? leftLeft : clampX(rightLeft) };
|
|
461
|
+
case "left":
|
|
462
|
+
return { top: centerY, left: fitsLeft ? leftLeft : fitsRight ? rightLeft : clampX(leftLeft) };
|
|
463
|
+
default:
|
|
464
|
+
if (fitsBelow) return { top: belowTop, left: centerX };
|
|
465
|
+
if (fitsAbove) return { top: aboveTop, left: centerX };
|
|
466
|
+
return { top: Math.max(m, (vh - ch) / 2), left: centerX };
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function TourCard({
|
|
471
|
+
step,
|
|
472
|
+
index,
|
|
473
|
+
total,
|
|
474
|
+
labels,
|
|
475
|
+
isFirst,
|
|
476
|
+
isLast,
|
|
477
|
+
rect,
|
|
478
|
+
onBack,
|
|
479
|
+
onNext,
|
|
480
|
+
onSkip,
|
|
481
|
+
}: {
|
|
482
|
+
step: TourStep;
|
|
483
|
+
index: number;
|
|
484
|
+
total: number;
|
|
485
|
+
labels: TourLabels;
|
|
486
|
+
isFirst: boolean;
|
|
487
|
+
isLast: boolean;
|
|
488
|
+
rect: Rect | null;
|
|
489
|
+
onBack: () => void;
|
|
490
|
+
onNext: () => void;
|
|
491
|
+
onSkip: () => void;
|
|
492
|
+
}) {
|
|
493
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
494
|
+
const [style, setStyle] = useState<CSSProperties>({ opacity: 0 });
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* The card holds the focus, because the card is what the tour IS.
|
|
498
|
+
*
|
|
499
|
+
* The overlay above declares `role="dialog" aria-modal="true"` — it always has — and
|
|
500
|
+
* then left focus wherever the page had put it. For a tour that is the most pointed
|
|
501
|
+
* version of the audit's *"Only Modal manages focus"*: the whole component exists to
|
|
502
|
+
* say "look here", and for a keyboard user "here" is the focus ring. They were told
|
|
503
|
+
* the page was hidden, given no way to reach the Next button without Tabbing through
|
|
504
|
+
* it, and left on a control the screen reader would no longer describe.
|
|
505
|
+
*
|
|
506
|
+
* It re-engages on every step, without any bookkeeping here, because `TourOverlay`
|
|
507
|
+
* returns null while it re-locates the next target: the card genuinely unmounts and
|
|
508
|
+
* remounts between steps. That is what keeps focus honest when the BUTTONS change —
|
|
509
|
+
* "Back" does not exist on the first step, so stepping back onto it destroys the
|
|
510
|
+
* control the press came from, and focus would otherwise fall to `<body>`, outside
|
|
511
|
+
* this trap's own listener, where Tab walks straight into the page the overlay claims
|
|
512
|
+
* to have hidden.
|
|
513
|
+
*
|
|
514
|
+
* **The cost, written down:** on an `awaitClick` step the user is asked to click the
|
|
515
|
+
* spotlighted element, and they can no longer Tab to it. ArrowRight still advances
|
|
516
|
+
* (the key handler in `TourOverlay` is on the document and does not care where focus
|
|
517
|
+
* is), which is the escape hatch that step already documents for the case where the
|
|
518
|
+
* target cannot be found. Containment is worth that: an `awaitClick` step is a
|
|
519
|
+
* minority of steps, while focus stranded behind `aria-modal` is every step.
|
|
520
|
+
*/
|
|
521
|
+
useFocusTrap(ref, { active: true });
|
|
522
|
+
|
|
523
|
+
useLayoutEffect(() => {
|
|
524
|
+
const card = ref.current;
|
|
525
|
+
if (!card) return;
|
|
526
|
+
setStyle(
|
|
527
|
+
placeCard(rect, card.offsetWidth, card.offsetHeight, window.innerWidth, window.innerHeight, 12, step.placement),
|
|
528
|
+
);
|
|
529
|
+
}, [rect, index, step.placement]);
|
|
530
|
+
|
|
531
|
+
return (
|
|
532
|
+
<div
|
|
533
|
+
ref={ref}
|
|
534
|
+
// Focusable but not tabbable: the trap above focuses the card itself rather than
|
|
535
|
+
// its first button, so a screen reader reads the step's title and body before it
|
|
536
|
+
// reads "Next" — and without this the container cannot take focus at all and the
|
|
537
|
+
// trap silently does nothing.
|
|
538
|
+
tabIndex={-1}
|
|
539
|
+
style={style}
|
|
540
|
+
className="pointer-events-auto fixed z-[61] w-80 max-w-[calc(100vw-1.5rem)] rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-4 shadow-xl outline-none transition-all duration-200 ease-out"
|
|
541
|
+
>
|
|
542
|
+
<div className="text-sm font-semibold text-[var(--text-primary)]">{step.title}</div>
|
|
543
|
+
<div className="mt-1 text-sm leading-relaxed text-[var(--text-secondary)]">{step.body}</div>
|
|
544
|
+
{step.action && <div className="mt-3">{step.action}</div>}
|
|
545
|
+
<div className="mt-4 space-y-2">
|
|
546
|
+
<div className="flex items-center justify-between gap-2">
|
|
547
|
+
<button
|
|
548
|
+
type="button"
|
|
549
|
+
onClick={onSkip}
|
|
550
|
+
className="text-xs text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]"
|
|
551
|
+
>
|
|
552
|
+
{labels.skip}
|
|
553
|
+
</button>
|
|
554
|
+
<div className="flex items-center gap-2">
|
|
555
|
+
<span className="whitespace-nowrap text-xs tabular-nums text-[var(--text-placeholder)]">
|
|
556
|
+
{labels.step(index + 1, total)}
|
|
557
|
+
</span>
|
|
558
|
+
{!isFirst && (
|
|
559
|
+
<Button variant="secondary" onClick={onBack} className="px-2.5 py-1 text-xs">
|
|
560
|
+
{labels.back}
|
|
561
|
+
</Button>
|
|
562
|
+
)}
|
|
563
|
+
{/* On an awaitClick step the Next button is replaced by a hint on its
|
|
564
|
+
own row below, so it doesn't cram the counter + buttons and wrap.
|
|
565
|
+
Only when the target was actually FOUND, though — `rect` is null
|
|
566
|
+
when the finder gave up, and the click listener early-returns on
|
|
567
|
+
the same absence. Keyed on `step.target` alone this hid the only
|
|
568
|
+
way forward on any step whose anchor happens not to be rendered
|
|
569
|
+
for this user (a guest sees no "add account" button), leaving the
|
|
570
|
+
undocumented ArrowRight key as the sole escape. */}
|
|
571
|
+
{!(step.awaitClick && step.target && rect) && (
|
|
572
|
+
<Button variant="brand" onClick={onNext} className={cn("px-2.5 py-1 text-xs")}>
|
|
573
|
+
{isLast ? labels.done : labels.next}
|
|
574
|
+
</Button>
|
|
575
|
+
)}
|
|
576
|
+
</div>
|
|
577
|
+
</div>
|
|
578
|
+
{step.awaitClick && step.target && rect && (
|
|
579
|
+
<div className="text-center text-xs italic text-[var(--text-placeholder)]">
|
|
580
|
+
{labels.awaitClickHint}
|
|
581
|
+
</div>
|
|
582
|
+
)}
|
|
583
|
+
</div>
|
|
584
|
+
</div>
|
|
585
|
+
);
|
|
586
|
+
}
|
package/src/tour.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Minimal ambient typing for the Vite-injected `import.meta.env` so the package
|
|
2
|
+
// type-checks standalone (consumers provide the real values at build time).
|
|
3
|
+
interface ImportMetaEnv {
|
|
4
|
+
readonly DEV: boolean;
|
|
5
|
+
/** Set by vitest, and by nothing else. `DEV` cannot answer "am I under test" —
|
|
6
|
+
* a test run is neither a dev build nor a production one, and vitest reports
|
|
7
|
+
* `DEV=true` — so anything that should be quiet in a suite has to ask this. */
|
|
8
|
+
readonly VITEST?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface ImportMeta {
|
|
11
|
+
readonly env: ImportMetaEnv;
|
|
12
|
+
/**
|
|
13
|
+
* Vite's compile-time glob. Declared here rather than by pulling in
|
|
14
|
+
* `vite/client` (which drags every asset-module shim with it) or `@types/node`
|
|
15
|
+
* (which this package deliberately does not depend on — it ships browser code).
|
|
16
|
+
*
|
|
17
|
+
* It is what lets a TEST read the package's own sources: `field-invalid.test.tsx`
|
|
18
|
+
* sweeps the component directory to find a field-shaped control that forgot a
|
|
19
|
+
* prop, which is the kind of guard the consumer app writes with `readFileSync`
|
|
20
|
+
* and cannot be written that way here.
|
|
21
|
+
*/
|
|
22
|
+
glob<T = unknown>(
|
|
23
|
+
pattern: string,
|
|
24
|
+
options?: { query?: string; import?: string; eager?: boolean },
|
|
25
|
+
): Record<string, T>;
|
|
26
|
+
}
|