@12-apps/ui 1.0.0 → 1.3.1
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/components-catalog.md +14 -0
- package/package.json +42 -27
- package/src/__tests__/data-grid.test.tsx +125 -0
- package/src/__tests__/package-wiring.test.ts +12 -8
- package/src/__tests__/social-login-button.test.tsx +5 -5
- package/src/__tests__/viewport.test.ts +50 -0
- package/src/charts/index.ts +8 -0
- package/src/components/data-display/Alert/Alert.md +1 -1
- package/src/components/data-display/Alert/Alert.stories.tsx +5 -7
- package/src/components/data-display/Alert/Alert.styles.tsx +255 -0
- package/src/components/data-display/Alert/Alert.test.stories.tsx +11 -13
- package/src/components/data-display/Alert/Alert.tsx +135 -328
- package/src/components/data-display/AlertDialog/AlertDialog.stories.tsx +3 -1
- package/src/components/data-display/AlertDialog/AlertDialog.tsx +191 -78
- package/src/components/data-display/AlertDialog/AlertDialog.types.ts +8 -1
- package/src/components/data-display/AsyncStateContainer/AsyncStateContainer.test.stories.tsx +5 -5
- package/src/components/data-display/AsyncStateContainer/AsyncStateContainer.tsx +44 -35
- package/src/components/data-display/Avatar/Avatar.stories.tsx +4 -1
- package/src/components/data-display/Avatar/Avatar.test.stories.tsx +5 -3
- package/src/components/data-display/Avatar/Avatar.tsx +154 -450
- package/src/components/data-display/Avatar/Avatar.view.tsx +396 -0
- package/src/components/data-display/Badge/Badge.animations.ts +67 -0
- package/src/components/data-display/Badge/Badge.helpers.ts +74 -0
- package/src/components/data-display/Badge/Badge.stories.tsx +14 -16
- package/src/components/data-display/Badge/Badge.styles.ts +261 -0
- package/src/components/data-display/Badge/Badge.test.stories.tsx +32 -31
- package/src/components/data-display/Badge/Badge.tsx +151 -557
- package/src/components/data-display/Badge/Badge.variants.ts +106 -0
- package/src/components/data-display/Badge/BadgeContent.tsx +107 -0
- package/src/components/data-display/Banner/Banner.stories.tsx +5 -1
- package/src/components/data-display/Banner/Banner.styles.ts +120 -0
- package/src/components/data-display/Banner/Banner.tsx +179 -224
- package/src/components/data-display/Chart/Chart.md +48 -1
- package/src/components/data-display/Chart/Chart.tsx +82 -500
- package/src/components/data-display/Chart/Chart.types.ts +2 -0
- package/src/components/data-display/Chart/ChartComposables.tsx +121 -0
- package/src/components/data-display/Chart/ChartSpec.types.ts +70 -0
- package/src/components/data-display/Chart/SpecChart.stories.tsx +150 -0
- package/src/components/data-display/Chart/SpecChart.test.stories.tsx +56 -0
- package/src/components/data-display/Chart/SpecChart.tsx +53 -0
- package/src/components/data-display/Chart/__tests__/SpecChart.test.tsx +60 -0
- package/src/components/data-display/Chart/__tests__/chart-format.test.ts +43 -0
- package/src/components/data-display/Chart/__tests__/chart-spec.test.ts +119 -0
- package/src/components/data-display/Chart/chart-format.ts +26 -0
- package/src/components/data-display/Chart/chart-internals.ts +148 -0
- package/src/components/data-display/Chart/chart-renderers.tsx +338 -0
- package/src/components/data-display/Chart/chart-spec-registry.ts +74 -0
- package/src/components/data-display/Chart/chart-spec.ts +171 -0
- package/src/components/data-display/Chart/index.ts +30 -0
- package/src/components/data-display/Chip/Chip.helpers.tsx +131 -0
- package/src/components/data-display/Chip/Chip.stories.tsx +2 -1
- package/src/components/data-display/Chip/Chip.test.stories.tsx +11 -8
- package/src/components/data-display/Chip/Chip.tsx +31 -94
- package/src/components/data-display/DataGrid/DataGrid.body.tsx +141 -0
- package/src/components/data-display/DataGrid/DataGrid.cells.tsx +238 -0
- package/src/components/data-display/DataGrid/DataGrid.model.ts +315 -0
- package/src/components/data-display/DataGrid/DataGrid.rows.ts +112 -0
- package/src/components/data-display/DataGrid/DataGrid.states.tsx +102 -0
- package/src/components/data-display/DataGrid/DataGrid.test.stories.tsx +6 -12
- package/src/components/data-display/DataGrid/DataGrid.tsx +129 -725
- package/src/components/data-display/DataViews/DataViewsGrid.tsx +187 -0
- package/src/components/data-display/DataViews/DataViewsTableBase.tsx +400 -0
- package/src/components/data-display/DataViews/ManageViewsDialog.tsx +140 -0
- package/src/components/data-display/DataViews/SaveViewModal.tsx +289 -0
- package/src/components/data-display/DataViews/__tests__/DataViewsGrid.test.tsx +271 -0
- package/src/components/data-display/DataViews/__tests__/DataViewsTableBase.test.tsx +134 -0
- package/src/components/data-display/DataViews/__tests__/SaveViewModal.test.tsx +83 -0
- package/src/components/data-display/DataViews/__tests__/data-views-filter.test.ts +115 -0
- package/src/components/data-display/DataViews/__tests__/data-views-preview.test.ts +53 -0
- package/src/components/data-display/DataViews/__tests__/range-pill.test.tsx +114 -0
- package/src/components/data-display/DataViews/base-card.stories.tsx +136 -0
- package/src/components/data-display/DataViews/base-card.tsx +278 -0
- package/src/components/data-display/DataViews/data-views-filter-panel.tsx +184 -0
- package/src/components/data-display/DataViews/data-views-filter.ts +138 -0
- package/src/components/data-display/DataViews/data-views-grid-helpers.tsx +248 -0
- package/src/components/data-display/DataViews/data-views-grid-parts.tsx +400 -0
- package/src/components/data-display/DataViews/data-views-inline-bar.tsx +257 -0
- package/src/components/data-display/DataViews/data-views-layout-context.tsx +176 -0
- package/src/components/data-display/DataViews/data-views-pagination.tsx +31 -0
- package/src/components/data-display/DataViews/data-views-preview.ts +53 -0
- package/src/components/data-display/DataViews/data-views-range-pill.tsx +277 -0
- package/src/components/data-display/DataViews/data-views-table-parts.tsx +150 -0
- package/src/components/data-display/DataViews/data-views-toolbar.tsx +149 -0
- package/src/components/data-display/DataViews/data-views-types.ts +312 -0
- package/src/components/data-display/DataViews/data-views-view-mutations.ts +68 -0
- package/src/components/data-display/DataViews/index.ts +33 -0
- package/src/components/data-display/DataViews/use-data-views-state.ts +349 -0
- package/src/components/data-display/DateTimeDisplay/DateTimeDisplay.hooks.ts +104 -0
- package/src/components/data-display/DateTimeDisplay/DateTimeDisplay.tsx +68 -118
- package/src/components/data-display/DescriptionItem/DescriptionItem.stories.tsx +1 -1
- package/src/components/data-display/DescriptionItem/DescriptionItem.tsx +52 -34
- package/src/components/data-display/EmptyState/EmptyState.test.stories.tsx +6 -6
- package/src/components/data-display/EmptyState/EmptyState.tsx +218 -135
- package/src/components/data-display/ErrorState/ErrorState.test.stories.tsx +2 -2
- package/src/components/data-display/ErrorState/ErrorState.tsx +83 -55
- package/src/components/data-display/HoverCard/HoverCard.stories.tsx +3 -1
- package/src/components/data-display/HoverCard/HoverCard.test.stories.tsx +5 -5
- package/src/components/data-display/InteractiveTooltip/InteractiveTooltip.hooks.ts +99 -0
- package/src/components/data-display/InteractiveTooltip/InteractiveTooltip.styles.ts +87 -0
- package/src/components/data-display/InteractiveTooltip/InteractiveTooltip.tsx +28 -155
- package/src/components/data-display/LazyImage/LazyImage.hooks.ts +203 -0
- package/src/components/data-display/LazyImage/LazyImage.md +1 -1
- package/src/components/data-display/LazyImage/LazyImage.stories.tsx +3 -3
- package/src/components/data-display/LazyImage/LazyImage.tsx +144 -243
- package/src/components/data-display/Lightbox/Lightbox.constants.ts +53 -0
- package/src/components/data-display/Lightbox/Lightbox.helpers.ts +39 -0
- package/src/components/data-display/Lightbox/Lightbox.hooks.ts +259 -0
- package/src/components/data-display/Lightbox/Lightbox.test.stories.tsx +28 -35
- package/src/components/data-display/Lightbox/Lightbox.tsx +98 -658
- package/src/components/data-display/Lightbox/LightboxControls.tsx +152 -0
- package/src/components/data-display/Lightbox/LightboxCurrentMedia.tsx +50 -0
- package/src/components/data-display/Lightbox/LightboxMedia.tsx +76 -0
- package/src/components/data-display/Lightbox/LightboxOverlay.tsx +83 -0
- package/src/components/data-display/Lightbox/LightboxStage.tsx +97 -0
- package/src/components/data-display/Lightbox/LightboxThumbnails.tsx +83 -0
- package/src/components/data-display/Lightbox/useLightbox.ts +80 -0
- package/src/components/data-display/LoadingState/LoadingState.helpers.ts +52 -0
- package/src/components/data-display/LoadingState/LoadingState.tsx +117 -87
- package/src/components/data-display/MapPreview/MapControlBar.tsx +116 -0
- package/src/components/data-display/MapPreview/MapDecorations.tsx +155 -0
- package/src/components/data-display/MapPreview/MapLayers.tsx +70 -0
- package/src/components/data-display/MapPreview/MapMarkers.tsx +84 -0
- package/src/components/data-display/MapPreview/MapOverlays.tsx +68 -0
- package/src/components/data-display/MapPreview/MapPreview.constants.ts +19 -0
- package/src/components/data-display/MapPreview/MapPreview.helpers.ts +63 -0
- package/src/components/data-display/MapPreview/MapPreview.hooks.ts +265 -0
- package/src/components/data-display/MapPreview/MapPreview.test.stories.tsx +14 -10
- package/src/components/data-display/MapPreview/MapPreview.tsx +52 -882
- package/src/components/data-display/MapPreview/MapPreview.types.ts +8 -1
- package/src/components/data-display/MapPreview/MapSearchBar.tsx +64 -0
- package/src/components/data-display/MapPreview/MapTiles.tsx +70 -0
- package/src/components/data-display/MapPreview/StaticMapView.tsx +63 -0
- package/src/components/data-display/MapPreview/mapProjection.ts +52 -0
- package/src/components/data-display/MapPreview/mapSurface.ts +37 -0
- package/src/components/data-display/MapPreview/useMapPreview.ts +62 -0
- package/src/components/data-display/Popover/Popover.test.stories.tsx +13 -19
- package/src/components/data-display/Progress/Progress.helpers.ts +37 -0
- package/src/components/data-display/Progress/Progress.styles.ts +101 -0
- package/src/components/data-display/Progress/Progress.tsx +185 -213
- package/src/components/data-display/SectionOnboarding/SectionOnboarding.stories.tsx +1 -1
- package/src/components/data-display/SectionOnboarding/SectionOnboarding.tsx +1 -1
- package/src/components/data-display/StatCard/StatCard.md +117 -0
- package/src/components/data-display/StatCard/StatCard.stories.tsx +167 -0
- package/src/components/data-display/StatCard/StatCard.test.stories.tsx +240 -0
- package/src/components/data-display/StatCard/StatCard.tsx +236 -0
- package/src/components/data-display/StatCard/StatCard.types.ts +62 -0
- package/src/components/data-display/StatCard/index.ts +7 -0
- package/src/components/data-display/Stepper/Stepper.test.stories.tsx +12 -19
- package/src/components/data-display/Stepper/Stepper.tsx +1 -1
- package/src/components/data-display/Table/Table.helpers.ts +31 -0
- package/src/components/data-display/Table/Table.hooks.ts +161 -0
- package/src/components/data-display/Table/Table.stories.tsx +3 -1
- package/src/components/data-display/Table/Table.styles.ts +223 -0
- package/src/components/data-display/Table/Table.test.stories.tsx +4 -4
- package/src/components/data-display/Table/Table.tsx +291 -748
- package/src/components/data-display/Table/TableParts.hooks.tsx +112 -0
- package/src/components/data-display/Table/TableParts.tsx +298 -0
- package/src/components/data-display/Table/TableStates.tsx +21 -0
- package/src/components/data-display/Timeline/Timeline.stories.tsx +10 -12
- package/src/components/data-display/Timeline/Timeline.test.stories.tsx +30 -44
- package/src/components/data-display/Timeline/Timeline.tsx +23 -284
- package/src/components/data-display/Timeline/TimelineRow.tsx +346 -0
- package/src/components/data-display/TimingDiagram/TimingDiagram.tsx +38 -311
- package/src/components/data-display/TimingDiagram/TimingDiagram.views.tsx +346 -0
- package/src/components/data-display/Tooltip/Tooltip.stories.tsx +4 -1
- package/src/components/data-display/Tooltip/Tooltip.test.stories.tsx +44 -58
- package/src/components/data-display/Tooltip/Tooltip.tsx +67 -62
- package/src/components/data-display/index.ts +1 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.hooks.ts +96 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.md +140 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.parts.tsx +154 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.stories.tsx +146 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.test.stories.tsx +114 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.tsx +46 -0
- package/src/components/feedback/ConfirmAction/ConfirmAction.types.ts +111 -0
- package/src/components/feedback/ConfirmAction/ConfirmButton.tsx +18 -0
- package/src/components/feedback/ConfirmAction/__tests__/confirm-action.test.tsx +288 -0
- package/src/components/feedback/ConfirmAction/index.ts +16 -0
- package/src/components/feedback/ConfirmAction/with-confirmation.tsx +112 -0
- package/src/components/feedback/Dialog/Dialog.styles.ts +4 -2
- package/src/components/feedback/Dialog/Dialog.tsx +26 -1
- package/src/components/feedback/Dialog/__tests__/dialog-content-spacing.test.tsx +66 -0
- package/src/components/feedback/Modal/Modal.md +1 -1
- package/src/components/feedback/Modal/Modal.stories.tsx +2 -2
- package/src/components/feedback/Sonner/Sonner.tsx +104 -288
- package/src/components/feedback/Sonner/Sonner.types.ts +7 -0
- package/src/components/feedback/Sonner/SonnerToast.tsx +216 -0
- package/src/components/feedback/StackedModal/StackedModal.hooks.ts +226 -0
- package/src/components/feedback/StackedModal/StackedModal.parts.tsx +311 -0
- package/src/components/feedback/StackedModal/StackedModal.stories.tsx +13 -15
- package/src/components/feedback/StackedModal/StackedModal.styles.ts +193 -0
- package/src/components/feedback/StackedModal/StackedModal.tsx +100 -619
- package/src/components/feedback/StackedModal/StackedModal.types.ts +17 -3
- package/src/components/feedback/StackedModal/__tests__/stacked-modal-viewport.test.tsx +104 -0
- package/src/components/feedback/StackedModal/modal-stack.tsx +119 -0
- package/src/components/feedback/Toast/Toast.tsx +92 -81
- package/src/components/feedback/TutorialOverlay/TutorialOverlay.geometry.ts +65 -0
- package/src/components/feedback/TutorialOverlay/TutorialOverlay.hooks.ts +185 -0
- package/src/components/feedback/TutorialOverlay/TutorialOverlay.test.stories.tsx +2 -2
- package/src/components/feedback/TutorialOverlay/TutorialOverlay.tsx +156 -414
- package/src/components/feedback/TutorialOverlay/TutorialStepBody.tsx +255 -0
- package/src/components/feedback/index.ts +1 -0
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.helpers.ts +58 -0
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.hooks.ts +93 -0
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.mapper.ts +57 -0
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.stories.tsx +4 -2
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.test.stories.tsx +20 -16
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.tsx +26 -829
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.types.ts +11 -0
- package/src/components/form/AddressAutocomplete/AddressAutocompleteField.tsx +86 -0
- package/src/components/form/AddressAutocomplete/AddressFallbackField.tsx +64 -0
- package/src/components/form/AddressAutocomplete/AddressInputField.tsx +80 -0
- package/src/components/form/AddressAutocomplete/AddressOption.tsx +83 -0
- package/src/components/form/AddressAutocomplete/AddressSuggestionsPaper.tsx +24 -0
- package/src/components/form/AddressAutocomplete/AddressTextField.tsx +43 -0
- package/src/components/form/AddressAutocomplete/mockPlaces.ts +208 -0
- package/src/components/form/AddressAutocomplete/useAddressPredictions.ts +136 -0
- package/src/components/form/AddressAutocomplete/useAddressSelection.ts +113 -0
- package/src/components/form/AddressAutocomplete/useCurrentLocation.ts +116 -0
- package/src/components/form/AddressAutocomplete/useGoogleMapsAPI.ts +75 -0
- package/src/components/form/Button/Button.helpers.ts +36 -0
- package/src/components/form/Button/Button.stories.tsx +4 -1
- package/src/components/form/Button/Button.styles.ts +225 -0
- package/src/components/form/Button/Button.test.stories.tsx +25 -21
- package/src/components/form/Button/Button.tsx +45 -252
- package/src/components/form/Calendar/Calendar.dates.ts +100 -0
- package/src/components/form/Calendar/Calendar.helpers.ts +32 -0
- package/src/components/form/Calendar/Calendar.hooks.ts +278 -0
- package/src/components/form/Calendar/Calendar.keyboard.ts +32 -0
- package/src/components/form/Calendar/Calendar.selection.ts +156 -0
- package/src/components/form/Calendar/Calendar.test.stories.tsx +33 -34
- package/src/components/form/Calendar/Calendar.tsx +63 -551
- package/src/components/form/Calendar/Calendar.types.ts +16 -0
- package/src/components/form/Calendar/CalendarDay.tsx +127 -0
- package/src/components/form/Calendar/CalendarDayCell.tsx +52 -0
- package/src/components/form/Calendar/CalendarMonth.tsx +128 -0
- package/src/components/form/CepField/CepField.md +138 -0
- package/src/components/form/CepField/CepField.stories.tsx +138 -0
- package/src/components/form/CepField/CepField.test.stories.tsx +281 -0
- package/src/components/form/CepField/CepField.tsx +211 -0
- package/src/components/form/CepField/CepField.types.ts +73 -0
- package/src/components/form/CepField/index.ts +2 -0
- package/src/components/form/Checkbox/Checkbox.helpers.ts +28 -0
- package/src/components/form/Checkbox/Checkbox.tsx +19 -16
- package/src/components/form/CodeEditor/CodeEditor.helpers.ts +45 -0
- package/src/components/form/CodeEditor/CodeEditor.hooks.ts +104 -0
- package/src/components/form/CodeEditor/CodeEditor.monaco.ts +109 -0
- package/src/components/form/CodeEditor/CodeEditor.test.stories.tsx +17 -18
- package/src/components/form/CodeEditor/CodeEditor.tsx +81 -330
- package/src/components/form/CodeEditor/CodeEditorToolbar.tsx +168 -0
- package/src/components/form/Command/Command.hooks.ts +207 -0
- package/src/components/form/Command/Command.parts.tsx +58 -0
- package/src/components/form/Command/Command.styles.ts +83 -0
- package/src/components/form/Command/Command.tsx +61 -270
- package/src/components/form/CreatableSelect/CreatableSelect.md +1 -1
- package/src/components/form/CreatableSelect/CreatableSelect.test.stories.tsx +1 -1
- package/src/components/form/CreatableSelect/CreatableSelect.tsx +152 -71
- package/src/components/form/CreatableSelect/CreatableSelect.types.ts +13 -0
- package/src/components/form/HeaderButton/HeaderButton.tsx +80 -0
- package/src/components/form/HeaderButton/index.ts +2 -0
- package/src/components/form/Input/Input.stories.tsx +5 -1
- package/src/components/form/Input/Input.styles.ts +176 -0
- package/src/components/form/Input/Input.test.stories.tsx +30 -23
- package/src/components/form/Input/Input.tsx +71 -211
- package/src/components/form/Input/Input.types.ts +11 -0
- package/src/components/form/InputOTP/InputOTP.test.stories.tsx +9 -17
- package/src/components/form/Menubar/Menubar.test.stories.tsx +4 -8
- package/src/components/form/PasswordStrength/PasswordStrength.helpers.tsx +117 -0
- package/src/components/form/PasswordStrength/PasswordStrength.test.stories.tsx +3 -3
- package/src/components/form/PasswordStrength/PasswordStrength.tsx +202 -255
- package/src/components/form/PhoneInput/PhoneInput.hooks.ts +134 -0
- package/src/components/form/PhoneInput/PhoneInput.test.stories.tsx +4 -4
- package/src/components/form/PhoneInput/PhoneInput.tsx +279 -292
- package/src/components/form/PhoneInput/countries.ts +54 -0
- package/src/components/form/PhoneInput/phone.ts +47 -0
- package/src/components/form/RadioGroup/RadioGroup.test.stories.tsx +9 -9
- package/src/components/form/RichTextEditor/RichTextEditor.dom.ts +124 -0
- package/src/components/form/RichTextEditor/RichTextEditor.format.ts +61 -0
- package/src/components/form/RichTextEditor/RichTextEditor.hooks.ts +142 -0
- package/src/components/form/RichTextEditor/RichTextEditor.test.stories.tsx +5 -12
- package/src/components/form/RichTextEditor/RichTextEditor.tsx +98 -410
- package/src/components/form/RichTextEditor/RichTextEditorToolbar.tsx +187 -0
- package/src/components/form/SearchPalette/SearchPalette.parts.tsx +22 -0
- package/src/components/form/SearchPalette/SearchPalette.tsx +13 -9
- package/src/components/form/Select/Select.test.stories.tsx +35 -27
- package/src/components/form/Slider/Slider.test.stories.tsx +9 -11
- package/src/components/form/Switch/Switch.md +2 -1
- package/src/components/form/Switch/Switch.test.stories.tsx +6 -6
- package/src/components/form/Textarea/Textarea.styles.ts +143 -0
- package/src/components/form/Textarea/Textarea.test.stories.tsx +20 -26
- package/src/components/form/Textarea/Textarea.tsx +114 -535
- package/src/components/form/Textarea/TextareaRichEditor.tsx +377 -0
- package/src/components/form/Toggle/Toggle.styles.ts +211 -0
- package/src/components/form/Toggle/Toggle.test.stories.tsx +19 -27
- package/src/components/form/Toggle/Toggle.tsx +10 -185
- package/src/components/form/UploadButton/UploadButton.hooks.ts +323 -0
- package/src/components/form/UploadButton/UploadButton.parts.tsx +210 -0
- package/src/components/form/UploadButton/UploadButton.stories.tsx +2 -1
- package/src/components/form/UploadButton/UploadButton.test.stories.tsx +123 -4
- package/src/components/form/UploadButton/UploadButton.tsx +76 -305
- package/src/components/form/UploadButton/UploadButton.types.ts +16 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/form/total-form/Fields/CepField.tsx +143 -0
- package/src/components/form/total-form/Fields/ToggleField.tsx +61 -0
- package/src/components/form/total-form/Fields/index.ts +4 -0
- package/src/components/form/total-form/FormContainer.tsx +3 -3
- package/src/components/form/total-form/SubmitButton.tsx +25 -2
- package/src/components/form/total-form/total-form.test.tsx +118 -1
- package/src/components/layout/Accordion/Accordion.md +1 -1
- package/src/components/layout/Accordion/Accordion.stories.tsx +5 -1
- package/src/components/layout/Accordion/Accordion.styles.ts +80 -0
- package/src/components/layout/Accordion/Accordion.test.stories.tsx +32 -50
- package/src/components/layout/Accordion/Accordion.tsx +2 -75
- package/src/components/layout/Card/Card.helpers.ts +30 -0
- package/src/components/layout/Card/Card.stories.tsx +9 -11
- package/src/components/layout/Card/Card.styles.ts +182 -0
- package/src/components/layout/Card/Card.test.stories.tsx +46 -46
- package/src/components/layout/Card/Card.tsx +24 -241
- package/src/components/layout/CardGrid/CardGrid.md +96 -0
- package/src/components/layout/CardGrid/CardGrid.tsx +140 -0
- package/src/components/layout/CardGrid/__tests__/CardGrid.test.tsx +92 -0
- package/src/components/layout/CardGrid/index.ts +2 -0
- package/src/components/layout/Collapsible/Collapsible.helpers.ts +83 -0
- package/src/components/layout/Collapsible/Collapsible.test.stories.tsx +7 -3
- package/src/components/layout/Collapsible/Collapsible.tsx +111 -107
- package/src/components/layout/Container/Container.test.stories.tsx +11 -16
- package/src/components/layout/ContentToolbar/ColumnsMenu.tsx +1 -1
- package/src/components/layout/ContentToolbar/ContentToolbar.tsx +120 -44
- package/src/components/layout/ContentToolbar/ContentToolbar.types.ts +9 -0
- package/src/components/layout/ContentToolbar/FilterTrigger.tsx +1 -1
- package/src/components/layout/ContentToolbar/MultiSelectDropdown.tsx +58 -43
- package/src/components/layout/ContentToolbar/MultiSelectTriggers.tsx +139 -0
- package/src/components/layout/ContentToolbar/SavedViewsMenu.tsx +10 -3
- package/src/components/layout/ContentToolbar/SortByDropdown.tsx +35 -11
- package/src/components/layout/ContentToolbar/ViewSelector.tsx +5 -6
- package/src/components/layout/ContentToolbar/__tests__/MultiSelectDropdown.test.tsx +21 -0
- package/src/components/layout/Dashboard/Dashboard.test.stories.tsx +27 -1
- package/src/components/layout/Dashboard/Dashboard.tsx +27 -8
- package/src/components/layout/Dashboard/DashboardParts.tsx +12 -19
- package/src/components/layout/Dashboard/index.ts +2 -1
- package/src/components/layout/Drawer/Drawer.stories.tsx +8 -10
- package/src/components/layout/Drawer/Drawer.test.stories.tsx +18 -14
- package/src/components/layout/Drawer/Drawer.tsx +67 -53
- package/src/components/layout/Resizable/Resizable.helpers.ts +133 -0
- package/src/components/layout/Resizable/Resizable.hooks.ts +68 -0
- package/src/components/layout/Resizable/Resizable.tsx +38 -153
- package/src/components/layout/ScrollArea/ScrollArea.helpers.ts +51 -0
- package/src/components/layout/ScrollArea/ScrollArea.styles.ts +248 -0
- package/src/components/layout/ScrollArea/ScrollArea.tsx +183 -374
- package/src/components/layout/ScrollArea/ScrollAreaContent.tsx +70 -0
- package/src/components/layout/ScrollArea/ScrollViewport.tsx +90 -0
- package/src/components/layout/Separator/Separator.styles.ts +128 -0
- package/src/components/layout/Separator/Separator.test.stories.tsx +3 -12
- package/src/components/layout/Separator/Separator.tsx +6 -132
- package/src/components/layout/SettingsLayout/SettingsLayout.parts.tsx +2 -1
- package/src/components/layout/SettingsLayout/SettingsLayout.stories.tsx +6 -8
- package/src/components/layout/Sidebar/Sidebar.stories.tsx +10 -12
- package/src/components/layout/Sidebar/Sidebar.test.stories.tsx +35 -37
- package/src/components/layout/Skeleton/Skeleton.helpers.ts +33 -0
- package/src/components/layout/Skeleton/Skeleton.styles.ts +114 -0
- package/src/components/layout/Skeleton/Skeleton.test.stories.tsx +3 -3
- package/src/components/layout/Skeleton/Skeleton.tsx +67 -155
- package/src/components/layout/TableFilter/TableFilter.tsx +2 -1
- package/src/components/navigation/Breadcrumbs/BreadcrumbEntry.tsx +305 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.md +2 -1
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.stories.tsx +12 -14
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.styles.tsx +212 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.test.stories.tsx +62 -61
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.tsx +116 -429
- package/src/components/navigation/CommandPalette/CommandPalette.helpers.ts +82 -0
- package/src/components/navigation/CommandPalette/CommandPalette.hooks.ts +202 -0
- package/src/components/navigation/CommandPalette/CommandPalette.stories.tsx +3 -1
- package/src/components/navigation/CommandPalette/CommandPalette.test.stories.tsx +3 -5
- package/src/components/navigation/CommandPalette/CommandPalette.tsx +108 -341
- package/src/components/navigation/CommandPalette/CommandPaletteResults.tsx +182 -0
- package/src/components/navigation/CommandPalette/ShortcutChip.tsx +18 -0
- package/src/components/navigation/ContextMenu/ContextMenu.md +3 -1
- package/src/components/navigation/ContextMenu/ContextMenu.stories.tsx +4 -1
- package/src/components/navigation/ContextMenu/ContextMenu.test.stories.tsx +19 -24
- package/src/components/navigation/ContextMenu/ContextMenu.tsx +70 -54
- package/src/components/navigation/DropdownMenu/DropdownMenu.md +3 -1
- package/src/components/navigation/DropdownMenu/DropdownMenu.stories.tsx +17 -19
- package/src/components/navigation/DropdownMenu/DropdownMenu.test.stories.tsx +26 -26
- package/src/components/navigation/DropdownMenu/DropdownMenu.tsx +189 -111
- package/src/components/navigation/NavigationMenu/NavigationMegaSection.tsx +66 -0
- package/src/components/navigation/NavigationMenu/NavigationMenu.md +7 -2
- package/src/components/navigation/NavigationMenu/NavigationMenu.shell.tsx +218 -0
- package/src/components/navigation/NavigationMenu/NavigationMenu.styles.ts +223 -0
- package/src/components/navigation/NavigationMenu/NavigationMenu.tsx +119 -808
- package/src/components/navigation/NavigationMenu/NavigationMenuItem.hooks.ts +126 -0
- package/src/components/navigation/NavigationMenu/NavigationMenuItem.tsx +352 -0
- package/src/components/navigation/NavigationMenu/NavigationStandardBody.tsx +148 -0
- package/src/components/navigation/NavigationMenu/stories/NavigationMenu.stories.tsx +15 -17
- package/src/components/navigation/NavigationMenu/stories/NavigationMenu.test.stories.tsx +27 -23
- package/src/components/navigation/NavigationMenu/stories/NavigationMenuHorizontal.stories.tsx +11 -13
- package/src/components/navigation/NavigationMenu/stories/NavigationMenuVertical.stories.tsx +9 -11
- package/src/components/navigation/Pagination/Pagination.helpers.tsx +85 -0
- package/src/components/navigation/Pagination/Pagination.md +2 -1
- package/src/components/navigation/Pagination/Pagination.stories.tsx +4 -6
- package/src/components/navigation/Pagination/Pagination.styles.ts +135 -0
- package/src/components/navigation/Pagination/Pagination.tsx +178 -313
- package/src/components/navigation/Pagination/PaginationParts.tsx +81 -0
- package/src/components/navigation/Tabs/Tabs.md +3 -1
- package/src/components/navigation/Tabs/Tabs.stories.tsx +21 -23
- package/src/components/navigation/Tabs/Tabs.styles.ts +163 -0
- package/src/components/navigation/Tabs/Tabs.test.stories.tsx +37 -37
- package/src/components/navigation/Tabs/Tabs.tsx +192 -361
- package/src/components/navigation/Tabs/TabsPanel.tsx +100 -0
- package/src/components/typography/Blockquote/Blockquote.tsx +1 -1
- package/src/components/typography/Code/Code.test.stories.tsx +5 -5
- package/src/components/typography/Code/Code.tsx +74 -49
- package/src/components/typography/Heading/Heading.test.stories.tsx +8 -8
- package/src/components/typography/Paragraph/Paragraph.test.stories.tsx +5 -12
- package/src/components/typography/Text/Text.tsx +84 -77
- package/src/components/utility/AnimatedIcon/AnimatedIcon.md +4 -4
- package/src/components/utility/AnimatedIcon/AnimatedIcon.stories.tsx +19 -21
- package/src/components/utility/AnimatedIcon/AnimatedIcon.test.stories.tsx +19 -12
- package/src/components/utility/AspectRatio/AspectRatio.test.stories.tsx +9 -9
- package/src/components/utility/InfiniteScroll/InfiniteScroll.hooks.ts +118 -0
- package/src/components/utility/InfiniteScroll/InfiniteScroll.parts.tsx +54 -0
- package/src/components/utility/InfiniteScroll/InfiniteScroll.test.stories.tsx +12 -9
- package/src/components/utility/InfiniteScroll/InfiniteScroll.tsx +29 -148
- package/src/components/utility/InstallPrompt/InstallPrompt.helpers.ts +124 -0
- package/src/components/utility/InstallPrompt/InstallPrompt.md +113 -0
- package/src/components/utility/InstallPrompt/InstallPrompt.stories.tsx +118 -0
- package/src/components/utility/InstallPrompt/InstallPrompt.styles.ts +50 -0
- package/src/components/utility/InstallPrompt/InstallPrompt.test.stories.tsx +83 -0
- package/src/components/utility/InstallPrompt/InstallPrompt.tsx +192 -0
- package/src/components/utility/InstallPrompt/InstallPrompt.types.ts +78 -0
- package/src/components/utility/InstallPrompt/__tests__/InstallPrompt.ios.test.tsx +65 -0
- package/src/components/utility/InstallPrompt/__tests__/usePwaInstall.test.tsx +271 -0
- package/src/components/utility/InstallPrompt/index.ts +10 -0
- package/src/components/utility/InstallPrompt/usePwaInstall.ts +171 -0
- package/src/components/utility/Transition/Transition.helpers.ts +40 -0
- package/src/components/utility/Transition/Transition.tsx +17 -68
- package/src/components/utility/VirtualList/VirtualList.hooks.ts +319 -0
- package/src/components/utility/VirtualList/VirtualList.test.stories.tsx +49 -38
- package/src/components/utility/VirtualList/VirtualList.tsx +110 -315
- package/src/components/utility/WorkflowStep/WorkflowStep.helpers.ts +151 -0
- package/src/components/utility/WorkflowStep/WorkflowStep.parts.tsx +371 -0
- package/src/components/utility/WorkflowStep/WorkflowStep.stories.tsx +9 -11
- package/src/components/utility/WorkflowStep/WorkflowStep.test.stories.tsx +7 -7
- package/src/components/utility/WorkflowStep/WorkflowStep.tsx +51 -449
- package/src/components/utility/WorkflowStep/WorkflowStepRow.tsx +96 -0
- package/src/components/utility/index.ts +1 -0
- package/src/mui/Link.ts +2 -0
- package/src/utils/index.ts +2 -1
- package/src/utils/viewport.ts +65 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useTheme } from '@mui/material';
|
|
2
|
+
import type { CSSProperties, FC } from 'react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import type { HeatmapPoint } from './MapPreview.types';
|
|
6
|
+
|
|
7
|
+
const OVERLAY_STYLE: CSSProperties = {
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
top: 0,
|
|
10
|
+
left: 0,
|
|
11
|
+
width: '100%',
|
|
12
|
+
height: '100%',
|
|
13
|
+
pointerEvents: 'none',
|
|
14
|
+
zIndex: 1,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const MAX_HEAT_RADIUS = 30;
|
|
18
|
+
const MAX_HEAT_OPACITY = 0.3;
|
|
19
|
+
const DEGREES_TO_PIXELS = 10;
|
|
20
|
+
|
|
21
|
+
export interface HeatmapOverlayProps {
|
|
22
|
+
points: HeatmapPoint[];
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Each point's weight drives both its radius and its opacity, so denser areas
|
|
28
|
+
// read hotter where circles overlap.
|
|
29
|
+
export const HeatmapOverlay: FC<HeatmapOverlayProps> = ({ points, width, height }) => {
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
|
|
32
|
+
if (points.length === 0) return null;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<svg style={OVERLAY_STYLE} viewBox={`0 0 ${width} ${height}`}>
|
|
36
|
+
{points.map((point, index) => (
|
|
37
|
+
<circle
|
|
38
|
+
key={`${point.lat}-${point.lng}-${index}`}
|
|
39
|
+
cx={width / 2 + point.lng * DEGREES_TO_PIXELS}
|
|
40
|
+
cy={height / 2 - point.lat * DEGREES_TO_PIXELS}
|
|
41
|
+
r={MAX_HEAT_RADIUS * point.weight}
|
|
42
|
+
fill={theme.palette.error.main}
|
|
43
|
+
opacity={MAX_HEAT_OPACITY * point.weight}
|
|
44
|
+
/>
|
|
45
|
+
))}
|
|
46
|
+
</svg>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const RouteOverlay: FC<{ color: string }> = ({ color }) => {
|
|
51
|
+
const theme = useTheme();
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<svg style={OVERLAY_STYLE} viewBox="0 0 100 100">
|
|
55
|
+
<path
|
|
56
|
+
d="M 20,20 Q 40,10 50,30 T 80,80"
|
|
57
|
+
stroke={color || theme.palette.primary.main}
|
|
58
|
+
strokeWidth="3"
|
|
59
|
+
fill="none"
|
|
60
|
+
strokeDasharray="5,5"
|
|
61
|
+
opacity="0.8"
|
|
62
|
+
>
|
|
63
|
+
{/* Marching-ants dashes to suggest direction of travel. */}
|
|
64
|
+
<animate attributeName="stroke-dashoffset" values="0;10" dur="1s" repeatCount="indefinite" />
|
|
65
|
+
</path>
|
|
66
|
+
</svg>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MapType } from './MapPreview.types';
|
|
2
|
+
|
|
3
|
+
export const MIN_ZOOM = 1;
|
|
4
|
+
export const MAX_ZOOM = 20;
|
|
5
|
+
export const DEFAULT_ZOOM = 15;
|
|
6
|
+
export const CITY_ZOOM = 12;
|
|
7
|
+
|
|
8
|
+
// The order the map-type button cycles through.
|
|
9
|
+
export const MAP_TYPES: MapType[] = ['roadmap', 'satellite', 'hybrid', 'terrain'];
|
|
10
|
+
|
|
11
|
+
// Degrees of movement per pixel dragged — small enough that a drag reads as a
|
|
12
|
+
// nudge rather than a jump.
|
|
13
|
+
export const DRAG_DEGREES_PER_PIXEL = 0.0001;
|
|
14
|
+
|
|
15
|
+
// Spread of the simulated coordinate change a map click produces.
|
|
16
|
+
export const CLICK_JITTER_DEGREES = 0.001;
|
|
17
|
+
|
|
18
|
+
export const MARKER_PIXELS_PER_DEGREE = 100;
|
|
19
|
+
export const HEATMAP_VIEWBOX = { width: 800, height: 400 };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Theme } from '@mui/material';
|
|
2
|
+
import { alpha } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_ZOOM } from './MapPreview.constants';
|
|
5
|
+
import type { MapPreviewProps } from './MapPreview.types';
|
|
6
|
+
|
|
7
|
+
type MapDefaultedKeys =
|
|
8
|
+
| 'markers'
|
|
9
|
+
| 'marker'
|
|
10
|
+
| 'height'
|
|
11
|
+
| 'interactive'
|
|
12
|
+
| 'zoom'
|
|
13
|
+
| 'mapType'
|
|
14
|
+
| 'variant'
|
|
15
|
+
| 'showControls'
|
|
16
|
+
| 'showSearch'
|
|
17
|
+
| 'searchPlaceholder'
|
|
18
|
+
| 'showRoute'
|
|
19
|
+
| 'heatmapData'
|
|
20
|
+
| 'showHeatmap'
|
|
21
|
+
| 'animated';
|
|
22
|
+
|
|
23
|
+
export type ResolvedMapPreviewProps = MapPreviewProps &
|
|
24
|
+
Required<Pick<MapPreviewProps, MapDefaultedKeys>>;
|
|
25
|
+
|
|
26
|
+
const MAP_PREVIEW_DEFAULTS: Pick<MapPreviewProps, MapDefaultedKeys> = {
|
|
27
|
+
markers: [],
|
|
28
|
+
marker: true,
|
|
29
|
+
height: '400px',
|
|
30
|
+
interactive: false,
|
|
31
|
+
zoom: DEFAULT_ZOOM,
|
|
32
|
+
mapType: 'roadmap',
|
|
33
|
+
variant: 'default',
|
|
34
|
+
showControls: true,
|
|
35
|
+
showSearch: false,
|
|
36
|
+
searchPlaceholder: 'Search location...',
|
|
37
|
+
showRoute: false,
|
|
38
|
+
heatmapData: [],
|
|
39
|
+
showHeatmap: false,
|
|
40
|
+
animated: true,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Strips explicitly-undefined props before the merge, so `prop={undefined}` still
|
|
44
|
+
// falls back to the default exactly as a destructuring default would.
|
|
45
|
+
const definedProps = (props: MapPreviewProps): Partial<MapPreviewProps> =>
|
|
46
|
+
Object.fromEntries(
|
|
47
|
+
Object.entries(props).filter(([, value]) => value !== undefined),
|
|
48
|
+
) as Partial<MapPreviewProps>;
|
|
49
|
+
|
|
50
|
+
// Applied as a merge rather than destructuring defaults, which would otherwise
|
|
51
|
+
// put fourteen branches into the component's own complexity budget.
|
|
52
|
+
export const resolveMapPreviewProps = (props: MapPreviewProps): ResolvedMapPreviewProps =>
|
|
53
|
+
({ ...MAP_PREVIEW_DEFAULTS, ...definedProps(props) }) as ResolvedMapPreviewProps;
|
|
54
|
+
|
|
55
|
+
export const glassStyles = (variant: MapPreviewProps['variant'], theme: Theme) =>
|
|
56
|
+
variant === 'glass'
|
|
57
|
+
? {
|
|
58
|
+
background: alpha(theme.palette.background.paper, 0.7),
|
|
59
|
+
backdropFilter: 'blur(20px)',
|
|
60
|
+
WebkitBackdropFilter: 'blur(20px)',
|
|
61
|
+
border: `1px solid ${alpha(theme.palette.divider, 0.1)}`,
|
|
62
|
+
}
|
|
63
|
+
: {};
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { geocode } from './mapProjection';
|
|
5
|
+
import {
|
|
6
|
+
CITY_ZOOM,
|
|
7
|
+
CLICK_JITTER_DEGREES,
|
|
8
|
+
DRAG_DEGREES_PER_PIXEL,
|
|
9
|
+
MAP_TYPES,
|
|
10
|
+
MAX_ZOOM,
|
|
11
|
+
MIN_ZOOM,
|
|
12
|
+
} from './MapPreview.constants';
|
|
13
|
+
import type { LatLng, MapType } from './MapPreview.types';
|
|
14
|
+
|
|
15
|
+
const ORIGIN = { x: 0, y: 0 };
|
|
16
|
+
|
|
17
|
+
export const useMapView = ({
|
|
18
|
+
coordinates,
|
|
19
|
+
initialZoom,
|
|
20
|
+
initialMapType,
|
|
21
|
+
}: {
|
|
22
|
+
coordinates: LatLng;
|
|
23
|
+
initialZoom: number;
|
|
24
|
+
initialMapType: MapType;
|
|
25
|
+
}) => {
|
|
26
|
+
const [zoom, setZoom] = useState(initialZoom);
|
|
27
|
+
const [mapType, setMapType] = useState<MapType>(initialMapType);
|
|
28
|
+
const [markerPosition, setMarkerPosition] = useState(coordinates);
|
|
29
|
+
const [panOffset, setPanOffset] = useState(ORIGIN);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setMarkerPosition(coordinates);
|
|
33
|
+
}, [coordinates]);
|
|
34
|
+
|
|
35
|
+
// Panning is relative to the tile grid, so a zoom change invalidates it.
|
|
36
|
+
const zoomTo = useCallback((next: number) => {
|
|
37
|
+
setZoom(next);
|
|
38
|
+
setPanOffset(ORIGIN);
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
zoom,
|
|
43
|
+
zoomTo,
|
|
44
|
+
mapType,
|
|
45
|
+
setMapType,
|
|
46
|
+
markerPosition,
|
|
47
|
+
setMarkerPosition,
|
|
48
|
+
panOffset,
|
|
49
|
+
setPanOffset,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const useMapControls = ({
|
|
54
|
+
coordinates,
|
|
55
|
+
zoom,
|
|
56
|
+
mapType,
|
|
57
|
+
zoomTo,
|
|
58
|
+
setMapType,
|
|
59
|
+
setMarkerPosition,
|
|
60
|
+
setPanOffset,
|
|
61
|
+
containerRef,
|
|
62
|
+
}: {
|
|
63
|
+
coordinates: LatLng;
|
|
64
|
+
zoom: number;
|
|
65
|
+
mapType: MapType;
|
|
66
|
+
zoomTo: (zoom: number) => void;
|
|
67
|
+
setMapType: (type: MapType) => void;
|
|
68
|
+
setMarkerPosition: (position: LatLng) => void;
|
|
69
|
+
setPanOffset: (offset: { x: number; y: number }) => void;
|
|
70
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
71
|
+
}) => {
|
|
72
|
+
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
73
|
+
|
|
74
|
+
const handleZoomIn = useCallback(() => zoomTo(Math.min(zoom + 1, MAX_ZOOM)), [zoom, zoomTo]);
|
|
75
|
+
const handleZoomOut = useCallback(() => zoomTo(Math.max(zoom - 1, MIN_ZOOM)), [zoom, zoomTo]);
|
|
76
|
+
|
|
77
|
+
const handleCenter = useCallback(() => {
|
|
78
|
+
setMarkerPosition({ ...coordinates });
|
|
79
|
+
setPanOffset(ORIGIN);
|
|
80
|
+
}, [coordinates, setMarkerPosition, setPanOffset]);
|
|
81
|
+
|
|
82
|
+
const handleToggleMapType = useCallback(() => {
|
|
83
|
+
const nextIndex = (MAP_TYPES.indexOf(mapType) + 1) % MAP_TYPES.length;
|
|
84
|
+
setMapType(MAP_TYPES[nextIndex] as MapType);
|
|
85
|
+
}, [mapType, setMapType]);
|
|
86
|
+
|
|
87
|
+
const handleToggleFullscreen = useCallback(() => {
|
|
88
|
+
if (!isFullscreen && containerRef.current) {
|
|
89
|
+
containerRef.current.requestFullscreen?.();
|
|
90
|
+
} else if (document.fullscreenElement) {
|
|
91
|
+
document.exitFullscreen?.();
|
|
92
|
+
}
|
|
93
|
+
setIsFullscreen((prev) => !prev);
|
|
94
|
+
}, [isFullscreen, containerRef]);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
isFullscreen,
|
|
98
|
+
handleZoomIn,
|
|
99
|
+
handleZoomOut,
|
|
100
|
+
handleCenter,
|
|
101
|
+
handleToggleMapType,
|
|
102
|
+
handleToggleFullscreen,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
interface DragStart {
|
|
107
|
+
x: number;
|
|
108
|
+
y: number;
|
|
109
|
+
lat: number;
|
|
110
|
+
lng: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface PanStart {
|
|
114
|
+
x: number;
|
|
115
|
+
y: number;
|
|
116
|
+
offsetX: number;
|
|
117
|
+
offsetY: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const isOnMapSurface = (target: HTMLElement): boolean =>
|
|
121
|
+
target.dataset.testid === 'static-map-view' ||
|
|
122
|
+
Boolean(target.closest('[data-testid="static-map-view"]'));
|
|
123
|
+
|
|
124
|
+
const panTo = (event: React.MouseEvent, start: PanStart) => ({
|
|
125
|
+
x: start.offsetX + (event.clientX - start.x),
|
|
126
|
+
y: start.offsetY + (event.clientY - start.y),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const dragTo = (event: React.MouseEvent, start: DragStart): LatLng => ({
|
|
130
|
+
lat: start.lat + (event.clientY - start.y) * DRAG_DEGREES_PER_PIXEL,
|
|
131
|
+
lng: start.lng + (event.clientX - start.x) * DRAG_DEGREES_PER_PIXEL,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Shift-drag pans the surface; a plain drag moves the marker.
|
|
135
|
+
export const useMapPointer = ({
|
|
136
|
+
interactive,
|
|
137
|
+
markerPosition,
|
|
138
|
+
panOffset,
|
|
139
|
+
onMarkerDrag,
|
|
140
|
+
setMarkerPosition,
|
|
141
|
+
setPanOffset,
|
|
142
|
+
}: {
|
|
143
|
+
interactive: boolean;
|
|
144
|
+
markerPosition: LatLng;
|
|
145
|
+
panOffset: { x: number; y: number };
|
|
146
|
+
onMarkerDrag?: (coords: LatLng) => void;
|
|
147
|
+
setMarkerPosition: (position: LatLng) => void;
|
|
148
|
+
setPanOffset: (offset: { x: number; y: number }) => void;
|
|
149
|
+
}) => {
|
|
150
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
151
|
+
const [isPanning, setIsPanning] = useState(false);
|
|
152
|
+
const dragStartRef = useRef<DragStart | null>(null);
|
|
153
|
+
const panStartRef = useRef<PanStart | null>(null);
|
|
154
|
+
|
|
155
|
+
const handleMouseDown = useCallback(
|
|
156
|
+
(event: React.MouseEvent<HTMLDivElement>) => {
|
|
157
|
+
if (!interactive) return;
|
|
158
|
+
const { clientX: x, clientY: y } = event;
|
|
159
|
+
|
|
160
|
+
if (isOnMapSurface(event.target as HTMLElement) && event.shiftKey) {
|
|
161
|
+
setIsPanning(true);
|
|
162
|
+
panStartRef.current = { x, y, offsetX: panOffset.x, offsetY: panOffset.y };
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setIsDragging(true);
|
|
167
|
+
dragStartRef.current = { x, y, lat: markerPosition.lat, lng: markerPosition.lng };
|
|
168
|
+
},
|
|
169
|
+
[interactive, markerPosition, panOffset],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const handleMouseMove = useCallback(
|
|
173
|
+
(event: React.MouseEvent<HTMLDivElement>) => {
|
|
174
|
+
const panStart = panStartRef.current;
|
|
175
|
+
if (isPanning && panStart) {
|
|
176
|
+
setPanOffset(panTo(event, panStart));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const dragStart = dragStartRef.current;
|
|
181
|
+
if (!isDragging || !dragStart) return;
|
|
182
|
+
|
|
183
|
+
const position = dragTo(event, dragStart);
|
|
184
|
+
setMarkerPosition(position);
|
|
185
|
+
onMarkerDrag?.(position);
|
|
186
|
+
},
|
|
187
|
+
[isDragging, isPanning, onMarkerDrag, setMarkerPosition, setPanOffset],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const handleMouseUp = useCallback(() => {
|
|
191
|
+
setIsDragging(false);
|
|
192
|
+
setIsPanning(false);
|
|
193
|
+
dragStartRef.current = null;
|
|
194
|
+
panStartRef.current = null;
|
|
195
|
+
}, []);
|
|
196
|
+
|
|
197
|
+
return { isDragging, isPanning, handleMouseDown, handleMouseMove, handleMouseUp };
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const useMapSearch = ({
|
|
201
|
+
zoomTo,
|
|
202
|
+
setMarkerPosition,
|
|
203
|
+
}: {
|
|
204
|
+
zoomTo: (zoom: number) => void;
|
|
205
|
+
setMarkerPosition: (position: LatLng) => void;
|
|
206
|
+
}) => {
|
|
207
|
+
const [searchValue, setSearchValue] = useState('');
|
|
208
|
+
const [isSearching, setIsSearching] = useState(false);
|
|
209
|
+
|
|
210
|
+
const handleSearch = useCallback(
|
|
211
|
+
async (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
212
|
+
if (event.key !== 'Enter' || !searchValue) return;
|
|
213
|
+
|
|
214
|
+
setIsSearching(true);
|
|
215
|
+
try {
|
|
216
|
+
const result = await geocode(searchValue);
|
|
217
|
+
// An unknown place leaves the map where it is; a production build would
|
|
218
|
+
// surface an error here.
|
|
219
|
+
if (!result) return;
|
|
220
|
+
|
|
221
|
+
setMarkerPosition({ ...result });
|
|
222
|
+
zoomTo(CITY_ZOOM);
|
|
223
|
+
} finally {
|
|
224
|
+
setIsSearching(false);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
[searchValue, zoomTo, setMarkerPosition],
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
return { searchValue, setSearchValue, isSearching, handleSearch };
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const useMapClick = ({
|
|
234
|
+
coordinates,
|
|
235
|
+
interactive,
|
|
236
|
+
isPanning,
|
|
237
|
+
onMapClick,
|
|
238
|
+
onMarkerDrag,
|
|
239
|
+
setMarkerPosition,
|
|
240
|
+
}: {
|
|
241
|
+
coordinates: LatLng;
|
|
242
|
+
interactive: boolean;
|
|
243
|
+
isPanning: boolean;
|
|
244
|
+
onMapClick?: (lat: number, lng: number) => void;
|
|
245
|
+
onMarkerDrag?: (coords: LatLng) => void;
|
|
246
|
+
setMarkerPosition: (position: LatLng) => void;
|
|
247
|
+
}) =>
|
|
248
|
+
useCallback(() => {
|
|
249
|
+
// A pan ends with a click event; that should not also drop a marker.
|
|
250
|
+
if (isPanning) return;
|
|
251
|
+
|
|
252
|
+
// Without a real projection there is nothing to convert a click position
|
|
253
|
+
// into, so the mock jitters around the centre instead.
|
|
254
|
+
const coords = {
|
|
255
|
+
lat: coordinates.lat + (Math.random() - 0.5) * CLICK_JITTER_DEGREES,
|
|
256
|
+
lng: coordinates.lng + (Math.random() - 0.5) * CLICK_JITTER_DEGREES,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
onMapClick?.(coords.lat, coords.lng);
|
|
260
|
+
|
|
261
|
+
if (interactive && onMarkerDrag) {
|
|
262
|
+
setMarkerPosition(coords);
|
|
263
|
+
onMarkerDrag(coords);
|
|
264
|
+
}
|
|
265
|
+
}, [coordinates, interactive, isPanning, onMapClick, onMarkerDrag, setMarkerPosition]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { expect, fn, waitFor, within } from 'storybook/test';
|
|
3
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
4
4
|
|
|
5
5
|
import { MapPreview } from './MapPreview';
|
|
6
6
|
import type { HeatmapPoint,MapMarker } from './MapPreview.types';
|
|
@@ -43,7 +43,7 @@ export const BasicInteraction: Story = {
|
|
|
43
43
|
const canvas = within(canvasElement);
|
|
44
44
|
|
|
45
45
|
// Wait for map container to render with extended timeout
|
|
46
|
-
|
|
46
|
+
await waitFor(
|
|
47
47
|
async () => {
|
|
48
48
|
const container = await canvas.findByTestId('map-preview-container');
|
|
49
49
|
expect(container).toBeInTheDocument();
|
|
@@ -93,7 +93,7 @@ export const MarkerInteraction: Story = {
|
|
|
93
93
|
);
|
|
94
94
|
|
|
95
95
|
// Test marker renders with extended wait
|
|
96
|
-
|
|
96
|
+
await waitFor(
|
|
97
97
|
async () => {
|
|
98
98
|
const markerElement = await canvas.findByTestId('map-marker-0');
|
|
99
99
|
expect(markerElement).toBeInTheDocument();
|
|
@@ -117,7 +117,7 @@ export const KeyboardNavigation: Story = {
|
|
|
117
117
|
const canvas = within(canvasElement);
|
|
118
118
|
|
|
119
119
|
// Wait for map to render and test container is focusable
|
|
120
|
-
|
|
120
|
+
await waitFor(
|
|
121
121
|
async () => {
|
|
122
122
|
const container = await canvas.findByTestId('map-preview-container');
|
|
123
123
|
expect(container).toBeInTheDocument();
|
|
@@ -142,7 +142,7 @@ export const ScreenReader: Story = {
|
|
|
142
142
|
const canvas = within(canvasElement);
|
|
143
143
|
|
|
144
144
|
// Wait for map and test ARIA labels
|
|
145
|
-
|
|
145
|
+
await waitFor(
|
|
146
146
|
async () => {
|
|
147
147
|
const container = await canvas.findByTestId('map-preview-container');
|
|
148
148
|
expect(container).toBeInTheDocument();
|
|
@@ -168,7 +168,7 @@ export const FocusManagement: Story = {
|
|
|
168
168
|
const canvas = within(canvasElement);
|
|
169
169
|
|
|
170
170
|
// Wait for map and test initial focus
|
|
171
|
-
const
|
|
171
|
+
const mapContainer = await waitFor(
|
|
172
172
|
async () => {
|
|
173
173
|
const container = await canvas.findByTestId('map-preview-container');
|
|
174
174
|
expect(container).toBeInTheDocument();
|
|
@@ -177,8 +177,9 @@ export const FocusManagement: Story = {
|
|
|
177
177
|
{ timeout: 10000 }
|
|
178
178
|
);
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
// The container carries tabIndex={0}, so clicking it should focus it.
|
|
181
|
+
await userEvent.click(mapContainer);
|
|
182
|
+
await waitFor(() => expect(mapContainer).toHaveFocus());
|
|
182
183
|
|
|
183
184
|
// Mark test as passed
|
|
184
185
|
const statusElement = document.createElement('div');
|
|
@@ -270,10 +271,13 @@ export const Performance: Story = {
|
|
|
270
271
|
render: () => (
|
|
271
272
|
<MapPreview
|
|
272
273
|
center={defaultCenter}
|
|
274
|
+
// Spread deterministically around the centre. These were random offsets,
|
|
275
|
+
// which meant the marker layout — and any snapshot of it — differed on
|
|
276
|
+
// every run.
|
|
273
277
|
markers={Array.from({ length: 5 }, (_, i) => ({
|
|
274
278
|
position: {
|
|
275
|
-
lat: defaultCenter.lat + (
|
|
276
|
-
lng: defaultCenter.lng + (
|
|
279
|
+
lat: defaultCenter.lat + (i - 2) * 0.02,
|
|
280
|
+
lng: defaultCenter.lng + (2 - i) * 0.02,
|
|
277
281
|
},
|
|
278
282
|
title: `Marker ${i + 1}`,
|
|
279
283
|
}))}
|