@regardio/react 0.3.2
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 +9 -0
- package/README.md +133 -0
- package/dist/components/background-slideshow.d.ts +22 -0
- package/dist/components/background-slideshow.d.ts.map +1 -0
- package/dist/components/background-slideshow.js +76 -0
- package/dist/components/blurry-gradient.d.ts +9 -0
- package/dist/components/blurry-gradient.d.ts.map +1 -0
- package/dist/components/blurry-gradient.js +6 -0
- package/dist/components/box.d.ts +17 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +25 -0
- package/dist/components/carousel.d.ts +26 -0
- package/dist/components/carousel.d.ts.map +1 -0
- package/dist/components/carousel.js +87 -0
- package/dist/components/countdown.d.ts +2 -0
- package/dist/components/countdown.d.ts.map +1 -0
- package/dist/components/countdown.js +48 -0
- package/dist/components/definition-list.d.ts +40 -0
- package/dist/components/definition-list.d.ts.map +1 -0
- package/dist/components/definition-list.js +57 -0
- package/dist/components/generic-error.d.ts +23 -0
- package/dist/components/generic-error.d.ts.map +1 -0
- package/dist/components/generic-error.js +39 -0
- package/dist/components/heading.d.ts +24 -0
- package/dist/components/heading.d.ts.map +1 -0
- package/dist/components/heading.js +29 -0
- package/dist/components/highlight.d.ts +16 -0
- package/dist/components/highlight.d.ts.map +1 -0
- package/dist/components/highlight.js +19 -0
- package/dist/components/icon-button.d.ts +6 -0
- package/dist/components/icon-button.d.ts.map +1 -0
- package/dist/components/icon-button.js +6 -0
- package/dist/components/if.d.ts +8 -0
- package/dist/components/if.d.ts.map +1 -0
- package/dist/components/if.js +16 -0
- package/dist/components/iframe.d.ts +8 -0
- package/dist/components/iframe.d.ts.map +1 -0
- package/dist/components/iframe.js +3 -0
- package/dist/components/item.d.ts +67 -0
- package/dist/components/item.d.ts.map +1 -0
- package/dist/components/item.js +309 -0
- package/dist/components/leaflet-map.d.ts +33 -0
- package/dist/components/leaflet-map.d.ts.map +1 -0
- package/dist/components/leaflet-map.js +195 -0
- package/dist/components/link.d.ts +41 -0
- package/dist/components/link.d.ts.map +1 -0
- package/dist/components/link.js +111 -0
- package/dist/components/link.test.d.ts +2 -0
- package/dist/components/link.test.d.ts.map +1 -0
- package/dist/components/link.test.js +204 -0
- package/dist/components/list-item.d.ts +16 -0
- package/dist/components/list-item.d.ts.map +1 -0
- package/dist/components/list-item.js +19 -0
- package/dist/components/maptiler-map.d.ts +26 -0
- package/dist/components/maptiler-map.d.ts.map +1 -0
- package/dist/components/maptiler-map.js +116 -0
- package/dist/components/markdown-container.d.ts +20 -0
- package/dist/components/markdown-container.d.ts.map +1 -0
- package/dist/components/markdown-container.js +93 -0
- package/dist/components/password-input.d.ts +9 -0
- package/dist/components/password-input.d.ts.map +1 -0
- package/dist/components/password-input.js +13 -0
- package/dist/components/picture.d.ts +26 -0
- package/dist/components/picture.d.ts.map +1 -0
- package/dist/components/picture.js +36 -0
- package/dist/components/protected-email.d.ts +9 -0
- package/dist/components/protected-email.d.ts.map +1 -0
- package/dist/components/protected-email.js +16 -0
- package/dist/components/text.d.ts +17 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +27 -0
- package/dist/components/unordered-list.d.ts +16 -0
- package/dist/components/unordered-list.d.ts.map +1 -0
- package/dist/components/unordered-list.js +21 -0
- package/dist/hooks/use-current-route-data.d.ts +2 -0
- package/dist/hooks/use-current-route-data.d.ts.map +1 -0
- package/dist/hooks/use-current-route-data.js +12 -0
- package/dist/hooks/use-focus-search.d.ts +3 -0
- package/dist/hooks/use-focus-search.d.ts.map +1 -0
- package/dist/hooks/use-focus-search.js +15 -0
- package/dist/hooks/use-matches-data.d.ts +2 -0
- package/dist/hooks/use-matches-data.d.ts.map +1 -0
- package/dist/hooks/use-matches-data.js +11 -0
- package/dist/hooks/use-media-query.d.ts +2 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +16 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-mobile.js +15 -0
- package/dist/hooks/use-nonce.d.ts +5 -0
- package/dist/hooks/use-nonce.d.ts.map +1 -0
- package/dist/hooks/use-nonce.js +9 -0
- package/dist/hooks/use-nonce.test.d.ts +2 -0
- package/dist/hooks/use-nonce.test.d.ts.map +1 -0
- package/dist/hooks/use-nonce.test.js +27 -0
- package/dist/hooks/use-orientation.d.ts +3 -0
- package/dist/hooks/use-orientation.d.ts.map +1 -0
- package/dist/hooks/use-orientation.js +25 -0
- package/dist/hooks/use-user.d.ts +15 -0
- package/dist/hooks/use-user.d.ts.map +1 -0
- package/dist/hooks/use-user.js +17 -0
- package/dist/shadcn/accordion.d.ts +25 -0
- package/dist/shadcn/accordion.d.ts.map +1 -0
- package/dist/shadcn/accordion.js +45 -0
- package/dist/shadcn/alert-dialog.d.ts +73 -0
- package/dist/shadcn/alert-dialog.d.ts.map +1 -0
- package/dist/shadcn/alert-dialog.js +93 -0
- package/dist/shadcn/alert.d.ts +34 -0
- package/dist/shadcn/alert.d.ts.map +1 -0
- package/dist/shadcn/alert.js +42 -0
- package/dist/shadcn/aspect-ratio.d.ts +6 -0
- package/dist/shadcn/aspect-ratio.d.ts.map +1 -0
- package/dist/shadcn/aspect-ratio.js +7 -0
- package/dist/shadcn/avatar.d.ts +16 -0
- package/dist/shadcn/avatar.d.ts.map +1 -0
- package/dist/shadcn/avatar.js +27 -0
- package/dist/shadcn/badge.d.ts +29 -0
- package/dist/shadcn/badge.d.ts.map +1 -0
- package/dist/shadcn/badge.js +29 -0
- package/dist/shadcn/breadcrumb.d.ts +42 -0
- package/dist/shadcn/breadcrumb.d.ts.map +1 -0
- package/dist/shadcn/breadcrumb.js +74 -0
- package/dist/shadcn/button.d.ts +38 -0
- package/dist/shadcn/button.d.ts.map +1 -0
- package/dist/shadcn/button.js +38 -0
- package/dist/shadcn/calendar.d.ts +23 -0
- package/dist/shadcn/calendar.d.ts.map +1 -0
- package/dist/shadcn/calendar.js +163 -0
- package/dist/shadcn/card.d.ts +31 -0
- package/dist/shadcn/card.d.ts.map +1 -0
- package/dist/shadcn/card.js +55 -0
- package/dist/shadcn/carousel.d.ts +51 -0
- package/dist/shadcn/carousel.d.ts.map +1 -0
- package/dist/shadcn/carousel.js +161 -0
- package/dist/shadcn/chart.d.ts +103 -0
- package/dist/shadcn/chart.d.ts.map +1 -0
- package/dist/shadcn/chart.js +248 -0
- package/dist/shadcn/checkbox.d.ts +8 -0
- package/dist/shadcn/checkbox.d.ts.map +1 -0
- package/dist/shadcn/checkbox.js +22 -0
- package/dist/shadcn/collapsible.d.ts +16 -0
- package/dist/shadcn/collapsible.d.ts.map +1 -0
- package/dist/shadcn/collapsible.js +19 -0
- package/dist/shadcn/command.d.ts +61 -0
- package/dist/shadcn/command.d.ts.map +1 -0
- package/dist/shadcn/command.js +123 -0
- package/dist/shadcn/context-menu.d.ts +107 -0
- package/dist/shadcn/context-menu.d.ts.map +1 -0
- package/dist/shadcn/context-menu.js +151 -0
- package/dist/shadcn/dialog.d.ts +57 -0
- package/dist/shadcn/dialog.d.ts.map +1 -0
- package/dist/shadcn/dialog.js +96 -0
- package/dist/shadcn/drawer.d.ts +54 -0
- package/dist/shadcn/drawer.d.ts.map +1 -0
- package/dist/shadcn/drawer.js +96 -0
- package/dist/shadcn/dropdown-menu.d.ts +110 -0
- package/dist/shadcn/dropdown-menu.d.ts.map +1 -0
- package/dist/shadcn/dropdown-menu.js +152 -0
- package/dist/shadcn/form.d.ts +59 -0
- package/dist/shadcn/form.d.ts.map +1 -0
- package/dist/shadcn/form.js +99 -0
- package/dist/shadcn/hover-card.d.ts +20 -0
- package/dist/shadcn/hover-card.d.ts.map +1 -0
- package/dist/shadcn/hover-card.js +26 -0
- package/dist/shadcn/input-otp.d.ts +25 -0
- package/dist/shadcn/input-otp.d.ts.map +1 -0
- package/dist/shadcn/input-otp.js +54 -0
- package/dist/shadcn/input.d.ts +14 -0
- package/dist/shadcn/input.d.ts.map +1 -0
- package/dist/shadcn/input.js +48 -0
- package/dist/shadcn/label.d.ts +8 -0
- package/dist/shadcn/label.d.ts.map +1 -0
- package/dist/shadcn/label.js +16 -0
- package/dist/shadcn/menubar.d.ts +108 -0
- package/dist/shadcn/menubar.d.ts.map +1 -0
- package/dist/shadcn/menubar.js +174 -0
- package/dist/shadcn/navigation-menu.d.ts +79 -0
- package/dist/shadcn/navigation-menu.d.ts.map +1 -0
- package/dist/shadcn/navigation-menu.js +108 -0
- package/dist/shadcn/pagination.d.ts +45 -0
- package/dist/shadcn/pagination.d.ts.map +1 -0
- package/dist/shadcn/pagination.js +83 -0
- package/dist/shadcn/popover.d.ts +19 -0
- package/dist/shadcn/popover.d.ts.map +1 -0
- package/dist/shadcn/popover.js +29 -0
- package/dist/shadcn/progress.d.ts +9 -0
- package/dist/shadcn/progress.d.ts.map +1 -0
- package/dist/shadcn/progress.js +17 -0
- package/dist/shadcn/radio-group.d.ts +12 -0
- package/dist/shadcn/radio-group.d.ts.map +1 -0
- package/dist/shadcn/radio-group.js +32 -0
- package/dist/shadcn/resizable.d.ts +20 -0
- package/dist/shadcn/resizable.d.ts.map +1 -0
- package/dist/shadcn/resizable.js +32 -0
- package/dist/shadcn/scroll-area.d.ts +16 -0
- package/dist/shadcn/scroll-area.d.ts.map +1 -0
- package/dist/shadcn/scroll-area.js +40 -0
- package/dist/shadcn/select.d.ts +63 -0
- package/dist/shadcn/select.d.ts.map +1 -0
- package/dist/shadcn/select.js +120 -0
- package/dist/shadcn/separator.d.ts +10 -0
- package/dist/shadcn/separator.d.ts.map +1 -0
- package/dist/shadcn/separator.js +18 -0
- package/dist/shadcn/sheet.d.ts +48 -0
- package/dist/shadcn/sheet.d.ts.map +1 -0
- package/dist/shadcn/sheet.js +99 -0
- package/dist/shadcn/sidebar.d.ts +200 -0
- package/dist/shadcn/sidebar.d.ts.map +1 -0
- package/dist/shadcn/sidebar.js +528 -0
- package/dist/shadcn/skeleton.d.ts +6 -0
- package/dist/shadcn/skeleton.d.ts.map +1 -0
- package/dist/shadcn/skeleton.js +11 -0
- package/dist/shadcn/slider.d.ts +12 -0
- package/dist/shadcn/slider.d.ts.map +1 -0
- package/dist/shadcn/slider.js +50 -0
- package/dist/shadcn/sonner.d.ts +7 -0
- package/dist/shadcn/sonner.d.ts.map +1 -0
- package/dist/shadcn/sonner.js +20 -0
- package/dist/shadcn/switch.d.ts +8 -0
- package/dist/shadcn/switch.d.ts.map +1 -0
- package/dist/shadcn/switch.js +22 -0
- package/dist/shadcn/table.d.ts +35 -0
- package/dist/shadcn/table.d.ts.map +1 -0
- package/dist/shadcn/table.js +73 -0
- package/dist/shadcn/tabs.d.ts +20 -0
- package/dist/shadcn/tabs.d.ts.map +1 -0
- package/dist/shadcn/tabs.js +40 -0
- package/dist/shadcn/textarea.d.ts +7 -0
- package/dist/shadcn/textarea.d.ts.map +1 -0
- package/dist/shadcn/textarea.js +14 -0
- package/dist/shadcn/toggle-group.d.ts +22 -0
- package/dist/shadcn/toggle-group.d.ts.map +1 -0
- package/dist/shadcn/toggle-group.js +43 -0
- package/dist/shadcn/toggle.d.ts +29 -0
- package/dist/shadcn/toggle.d.ts.map +1 -0
- package/dist/shadcn/toggle.js +31 -0
- package/dist/shadcn/tooltip.d.ts +20 -0
- package/dist/shadcn/tooltip.d.ts.map +1 -0
- package/dist/shadcn/tooltip.js +40 -0
- package/dist/stories/BackgroundSlideshow.stories.d.ts +9 -0
- package/dist/stories/BackgroundSlideshow.stories.d.ts.map +1 -0
- package/dist/stories/BackgroundSlideshow.stories.js +60 -0
- package/dist/stories/BlurryGradient.stories.d.ts +11 -0
- package/dist/stories/BlurryGradient.stories.d.ts.map +1 -0
- package/dist/stories/BlurryGradient.stories.js +53 -0
- package/dist/stories/Box.stories.d.ts +13 -0
- package/dist/stories/Box.stories.d.ts.map +1 -0
- package/dist/stories/Box.stories.js +50 -0
- package/dist/stories/Carousel.stories.d.ts +9 -0
- package/dist/stories/Carousel.stories.d.ts.map +1 -0
- package/dist/stories/Carousel.stories.js +30 -0
- package/dist/stories/Countdown.stories.d.ts +7 -0
- package/dist/stories/Countdown.stories.d.ts.map +1 -0
- package/dist/stories/Countdown.stories.js +11 -0
- package/dist/stories/DefinitionList.stories.d.ts +9 -0
- package/dist/stories/DefinitionList.stories.d.ts.map +1 -0
- package/dist/stories/DefinitionList.stories.js +20 -0
- package/dist/stories/GenericError.stories.d.ts +9 -0
- package/dist/stories/GenericError.stories.d.ts.map +1 -0
- package/dist/stories/GenericError.stories.js +39 -0
- package/dist/stories/Heading.stories.d.ts +15 -0
- package/dist/stories/Heading.stories.d.ts.map +1 -0
- package/dist/stories/Heading.stories.js +61 -0
- package/dist/stories/Highlight.stories.d.ts +8 -0
- package/dist/stories/Highlight.stories.d.ts.map +1 -0
- package/dist/stories/Highlight.stories.js +19 -0
- package/dist/stories/IconButton.stories.d.ts +10 -0
- package/dist/stories/IconButton.stories.d.ts.map +1 -0
- package/dist/stories/IconButton.stories.js +32 -0
- package/dist/stories/If.stories.d.ts +13 -0
- package/dist/stories/If.stories.d.ts.map +1 -0
- package/dist/stories/If.stories.js +54 -0
- package/dist/stories/Iframe.stories.d.ts +8 -0
- package/dist/stories/Iframe.stories.d.ts.map +1 -0
- package/dist/stories/Iframe.stories.js +23 -0
- package/dist/stories/Item.stories.d.ts +10 -0
- package/dist/stories/Item.stories.d.ts.map +1 -0
- package/dist/stories/Item.stories.js +32 -0
- package/dist/stories/Link.stories.d.ts +10 -0
- package/dist/stories/Link.stories.d.ts.map +1 -0
- package/dist/stories/Link.stories.js +36 -0
- package/dist/stories/ListItem.stories.d.ts +9 -0
- package/dist/stories/ListItem.stories.d.ts.map +1 -0
- package/dist/stories/ListItem.stories.js +25 -0
- package/dist/stories/MarkdownContainer.stories.d.ts +11 -0
- package/dist/stories/MarkdownContainer.stories.d.ts.map +1 -0
- package/dist/stories/MarkdownContainer.stories.js +66 -0
- package/dist/stories/PasswordInput.stories.d.ts +9 -0
- package/dist/stories/PasswordInput.stories.d.ts.map +1 -0
- package/dist/stories/PasswordInput.stories.js +27 -0
- package/dist/stories/Picture.stories.d.ts +10 -0
- package/dist/stories/Picture.stories.d.ts.map +1 -0
- package/dist/stories/Picture.stories.js +46 -0
- package/dist/stories/ProtectedEmail.stories.d.ts +10 -0
- package/dist/stories/ProtectedEmail.stories.d.ts.map +1 -0
- package/dist/stories/ProtectedEmail.stories.js +34 -0
- package/dist/stories/Text.stories.d.ts +10 -0
- package/dist/stories/Text.stories.d.ts.map +1 -0
- package/dist/stories/Text.stories.js +31 -0
- package/dist/stories/UnorderedList.stories.d.ts +10 -0
- package/dist/stories/UnorderedList.stories.d.ts.map +1 -0
- package/dist/stories/UnorderedList.stories.js +24 -0
- package/dist/test-setup.d.ts +2 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +1 -0
- package/dist/utils/author.d.ts +9 -0
- package/dist/utils/author.d.ts.map +1 -0
- package/dist/utils/author.js +37 -0
- package/dist/utils/author.test.d.ts +2 -0
- package/dist/utils/author.test.d.ts.map +1 -0
- package/dist/utils/author.test.js +46 -0
- package/dist/utils/cn.d.ts +5 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/cn.js +10 -0
- package/dist/utils/cn.test.d.ts +2 -0
- package/dist/utils/cn.test.d.ts.map +1 -0
- package/dist/utils/cn.test.js +33 -0
- package/dist/utils/is-route-active.d.ts +3 -0
- package/dist/utils/is-route-active.d.ts.map +1 -0
- package/dist/utils/is-route-active.js +54 -0
- package/dist/utils/is-route-active.test.d.ts +2 -0
- package/dist/utils/is-route-active.test.d.ts.map +1 -0
- package/dist/utils/is-route-active.test.js +61 -0
- package/dist/utils/locale.d.ts +22 -0
- package/dist/utils/locale.d.ts.map +1 -0
- package/dist/utils/locale.js +25 -0
- package/dist/utils/locale.test.d.ts +2 -0
- package/dist/utils/locale.test.d.ts.map +1 -0
- package/dist/utils/locale.test.js +99 -0
- package/dist/utils/text.d.ts +7 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +102 -0
- package/dist/utils/text.test.d.ts +2 -0
- package/dist/utils/text.test.d.ts.map +1 -0
- package/dist/utils/text.test.js +122 -0
- package/package.json +117 -0
- package/src/components/background-slideshow.tsx +172 -0
- package/src/components/blurry-gradient.tsx +97 -0
- package/src/components/box.tsx +45 -0
- package/src/components/carousel.tsx +197 -0
- package/src/components/countdown.tsx +82 -0
- package/src/components/definition-list.tsx +90 -0
- package/src/components/generic-error.tsx +104 -0
- package/src/components/heading.tsx +60 -0
- package/src/components/highlight.tsx +53 -0
- package/src/components/icon-button.tsx +20 -0
- package/src/components/if.tsx +29 -0
- package/src/components/iframe.tsx +19 -0
- package/src/components/item.tsx +340 -0
- package/src/components/leaflet-map.tsx +294 -0
- package/src/components/link.test.tsx +387 -0
- package/src/components/link.tsx +206 -0
- package/src/components/list-item.tsx +30 -0
- package/src/components/maptiler-map.tsx +181 -0
- package/src/components/markdown-container.tsx +153 -0
- package/src/components/password-input.tsx +49 -0
- package/src/components/picture.tsx +107 -0
- package/src/components/protected-email.tsx +49 -0
- package/src/components/text.tsx +38 -0
- package/src/components/unordered-list.tsx +32 -0
- package/src/hooks/use-current-route-data.ts +18 -0
- package/src/hooks/use-focus-search.ts +20 -0
- package/src/hooks/use-matches-data.ts +19 -0
- package/src/hooks/use-media-query.ts +33 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-nonce.test.ts +35 -0
- package/src/hooks/use-nonce.ts +20 -0
- package/src/hooks/use-orientation.ts +48 -0
- package/src/hooks/use-user.tsx +72 -0
- package/src/stories/BackgroundSlideshow.stories.tsx +68 -0
- package/src/stories/BlurryGradient.stories.tsx +62 -0
- package/src/stories/Box.stories.tsx +83 -0
- package/src/stories/Carousel.stories.tsx +95 -0
- package/src/stories/Countdown.stories.tsx +16 -0
- package/src/stories/DefinitionList.stories.tsx +51 -0
- package/src/stories/GenericError.stories.tsx +58 -0
- package/src/stories/Heading.stories.tsx +82 -0
- package/src/stories/Highlight.stories.tsx +28 -0
- package/src/stories/IconButton.stories.tsx +90 -0
- package/src/stories/If.stories.tsx +72 -0
- package/src/stories/Iframe.stories.tsx +29 -0
- package/src/stories/Item.stories.tsx +79 -0
- package/src/stories/Link.stories.tsx +58 -0
- package/src/stories/ListItem.stories.tsx +37 -0
- package/src/stories/MarkdownContainer.stories.tsx +76 -0
- package/src/stories/PasswordInput.stories.tsx +34 -0
- package/src/stories/Picture.stories.tsx +54 -0
- package/src/stories/ProtectedEmail.stories.tsx +57 -0
- package/src/stories/Text.stories.tsx +44 -0
- package/src/stories/UnorderedList.stories.tsx +73 -0
- package/src/styles/storybook.css +1 -0
- package/src/styles/tailwind.css +7 -0
- package/src/test-setup.ts +1 -0
- package/src/utils/author.test.ts +54 -0
- package/src/utils/author.tsx +73 -0
- package/src/utils/cn.test.ts +48 -0
- package/src/utils/cn.ts +14 -0
- package/src/utils/is-route-active.test.ts +80 -0
- package/src/utils/is-route-active.ts +100 -0
- package/src/utils/locale.test.ts +148 -0
- package/src/utils/locale.ts +127 -0
- package/src/utils/text.test.ts +152 -0
- package/src/utils/text.tsx +209 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import 'leaflet/dist/leaflet.css';
|
|
2
|
+
import L from 'leaflet';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
interface MapMarker {
|
|
6
|
+
lat: number;
|
|
7
|
+
lng: number;
|
|
8
|
+
id: string;
|
|
9
|
+
content?: string;
|
|
10
|
+
htmlContent?: string;
|
|
11
|
+
imageUrl?: string;
|
|
12
|
+
imageAlt?: string;
|
|
13
|
+
offset?: { x: number; y: number };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface LeafletMapProps {
|
|
17
|
+
markers: MapMarker[];
|
|
18
|
+
mapUrl: string;
|
|
19
|
+
center?: { lat: number; lng: number };
|
|
20
|
+
zoom?: number;
|
|
21
|
+
icon?: {
|
|
22
|
+
iconUrl: string;
|
|
23
|
+
iconSize: [number, number];
|
|
24
|
+
iconAnchor: [number, number];
|
|
25
|
+
};
|
|
26
|
+
attribution?: string;
|
|
27
|
+
showPopupsOnHover?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const LeafletMap = ({
|
|
31
|
+
markers,
|
|
32
|
+
mapUrl,
|
|
33
|
+
center,
|
|
34
|
+
zoom = 12,
|
|
35
|
+
icon = {
|
|
36
|
+
iconAnchor: [12, 41] as [number, number],
|
|
37
|
+
iconSize: [25, 41] as [number, number],
|
|
38
|
+
iconUrl: '/marker-icon-2x.png',
|
|
39
|
+
},
|
|
40
|
+
attribution = '',
|
|
41
|
+
showPopupsOnHover = false,
|
|
42
|
+
}: LeafletMapProps) => {
|
|
43
|
+
const mapContainerRef = useRef<HTMLDivElement>(null);
|
|
44
|
+
const mapRef = useRef<L.Map | null>(null);
|
|
45
|
+
const markersRef = useRef<L.Marker[]>([]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!mapContainerRef.current || typeof window === 'undefined') return;
|
|
49
|
+
|
|
50
|
+
// Calculate center
|
|
51
|
+
let calculatedCenter: [number, number];
|
|
52
|
+
if (center) {
|
|
53
|
+
calculatedCenter = [center.lat, center.lng];
|
|
54
|
+
} else if (markers.length > 0) {
|
|
55
|
+
const firstMarker = markers[0];
|
|
56
|
+
if (firstMarker) {
|
|
57
|
+
calculatedCenter = [firstMarker.lat, firstMarker.lng];
|
|
58
|
+
} else {
|
|
59
|
+
calculatedCenter = [52.520008, 13.404954];
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
calculatedCenter = [52.520008, 13.404954];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Initialize map - check if already initialized
|
|
66
|
+
if (mapRef.current) {
|
|
67
|
+
try {
|
|
68
|
+
// Clean up existing markers
|
|
69
|
+
markersRef.current.forEach((marker) => {
|
|
70
|
+
try {
|
|
71
|
+
mapRef.current?.removeLayer(marker);
|
|
72
|
+
} catch (_error) {
|
|
73
|
+
// Marker might already be removed
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
mapRef.current.remove();
|
|
77
|
+
} catch (_error) {
|
|
78
|
+
// Map might already be removed
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Ensure container is clean and prevent duplicate initialization
|
|
83
|
+
const container = mapContainerRef.current;
|
|
84
|
+
if (container) {
|
|
85
|
+
// Clear any existing content and remove any existing map
|
|
86
|
+
container.innerHTML = '';
|
|
87
|
+
|
|
88
|
+
// Check if container already has a map
|
|
89
|
+
const leafletContainer = container as HTMLDivElement & {
|
|
90
|
+
_leaflet_id?: number;
|
|
91
|
+
};
|
|
92
|
+
if (leafletContainer._leaflet_id) {
|
|
93
|
+
delete leafletContainer._leaflet_id;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Ensure container has unique ID or remove existing map
|
|
97
|
+
container.setAttribute('data-map-initialized', 'false');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const map = new L.Map(mapContainerRef.current, {
|
|
101
|
+
center: calculatedCenter,
|
|
102
|
+
scrollWheelZoom: false,
|
|
103
|
+
tapTolerance: 100,
|
|
104
|
+
zoom: zoom,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Add tile layer
|
|
108
|
+
new L.TileLayer(mapUrl, {
|
|
109
|
+
attribution,
|
|
110
|
+
}).addTo(map);
|
|
111
|
+
|
|
112
|
+
// Create custom icon
|
|
113
|
+
const customIcon = new L.Icon({
|
|
114
|
+
iconAnchor: icon.iconAnchor,
|
|
115
|
+
iconSize: icon.iconSize,
|
|
116
|
+
iconUrl: icon.iconUrl,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Add markers with popups
|
|
120
|
+
const newMarkers: L.Marker[] = [];
|
|
121
|
+
|
|
122
|
+
markers.forEach((marker) => {
|
|
123
|
+
const markerLatLng: [number, number] = [marker.lat, marker.lng];
|
|
124
|
+
const leafletMarker = new L.Marker(markerLatLng, {
|
|
125
|
+
icon: customIcon,
|
|
126
|
+
}).addTo(map);
|
|
127
|
+
|
|
128
|
+
// Apply offset if provided
|
|
129
|
+
const offset = marker.offset || { x: 0, y: 0 };
|
|
130
|
+
|
|
131
|
+
// Create popup content
|
|
132
|
+
let popupContent = '';
|
|
133
|
+
if (marker.htmlContent) {
|
|
134
|
+
popupContent = marker.htmlContent;
|
|
135
|
+
} else if (marker.content) {
|
|
136
|
+
popupContent = marker.content;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Add image if provided
|
|
140
|
+
if (marker.imageUrl) {
|
|
141
|
+
const imageHtml = `<img src="${marker.imageUrl}" alt="${marker.imageAlt || ''}" style="max-width: 100%; height: auto; display: block; margin-bottom: 8px;" />`;
|
|
142
|
+
popupContent = imageHtml + popupContent;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (popupContent) {
|
|
146
|
+
const popup = new L.Popup({
|
|
147
|
+
className: 'custom-map-popup',
|
|
148
|
+
closeButton: false,
|
|
149
|
+
offset: [offset.x, offset.y],
|
|
150
|
+
}).setContent(popupContent);
|
|
151
|
+
|
|
152
|
+
leafletMarker.bindPopup(popup);
|
|
153
|
+
|
|
154
|
+
// Show popup on hover if enabled
|
|
155
|
+
if (showPopupsOnHover) {
|
|
156
|
+
leafletMarker.on('mouseover', () => {
|
|
157
|
+
leafletMarker.openPopup();
|
|
158
|
+
});
|
|
159
|
+
leafletMarker.on('mouseout', () => {
|
|
160
|
+
leafletMarker.closePopup();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
newMarkers.push(leafletMarker);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
markersRef.current = newMarkers;
|
|
169
|
+
|
|
170
|
+
// Fit bounds if markers exist
|
|
171
|
+
if (markers.length > 0) {
|
|
172
|
+
const bounds = new L.LatLngBounds(markers.map((m) => new L.LatLng(m.lat, m.lng)));
|
|
173
|
+
map.fitBounds(bounds, { padding: [20, 20] });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
mapRef.current = map;
|
|
177
|
+
|
|
178
|
+
// Cleanup function
|
|
179
|
+
return () => {
|
|
180
|
+
if (mapRef.current) {
|
|
181
|
+
try {
|
|
182
|
+
// Remove all markers
|
|
183
|
+
markersRef.current.forEach((marker) => {
|
|
184
|
+
try {
|
|
185
|
+
mapRef.current?.removeLayer(marker);
|
|
186
|
+
} catch (_error) {
|
|
187
|
+
// Marker might already be removed
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
mapRef.current.remove();
|
|
191
|
+
mapRef.current = null;
|
|
192
|
+
|
|
193
|
+
// Clean up container
|
|
194
|
+
if (mapContainerRef.current) {
|
|
195
|
+
mapContainerRef.current.innerHTML = '';
|
|
196
|
+
mapContainerRef.current.removeAttribute('data-map-initialized');
|
|
197
|
+
}
|
|
198
|
+
} catch (_error) {
|
|
199
|
+
// Map might already be removed
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
markersRef.current = [];
|
|
203
|
+
};
|
|
204
|
+
}, [markers, mapUrl, zoom, icon, attribution, center, showPopupsOnHover]);
|
|
205
|
+
|
|
206
|
+
// Update markers when they change
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
const map = mapRef.current;
|
|
209
|
+
if (!map || typeof window === 'undefined') return;
|
|
210
|
+
|
|
211
|
+
// Remove existing markers
|
|
212
|
+
markersRef.current.forEach((marker) => {
|
|
213
|
+
try {
|
|
214
|
+
map.removeLayer(marker);
|
|
215
|
+
} catch (_error) {
|
|
216
|
+
// Marker might already be removed
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
markersRef.current = [];
|
|
220
|
+
|
|
221
|
+
// Create new icon
|
|
222
|
+
const customIcon = new L.Icon({
|
|
223
|
+
iconAnchor: icon.iconAnchor,
|
|
224
|
+
iconSize: icon.iconSize,
|
|
225
|
+
iconUrl: icon.iconUrl,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Add new markers with popups
|
|
229
|
+
const newMarkers: L.Marker[] = [];
|
|
230
|
+
|
|
231
|
+
markers.forEach((marker) => {
|
|
232
|
+
const markerLatLng: [number, number] = [marker.lat, marker.lng];
|
|
233
|
+
const leafletMarker = new L.Marker(markerLatLng, {
|
|
234
|
+
icon: customIcon,
|
|
235
|
+
}).addTo(map);
|
|
236
|
+
|
|
237
|
+
// Apply offset if provided
|
|
238
|
+
const offset = marker.offset || { x: 0, y: 0 };
|
|
239
|
+
|
|
240
|
+
// Create popup content
|
|
241
|
+
let popupContent = '';
|
|
242
|
+
if (marker.htmlContent) {
|
|
243
|
+
popupContent = marker.htmlContent;
|
|
244
|
+
} else if (marker.content) {
|
|
245
|
+
popupContent = marker.content;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Add image if provided
|
|
249
|
+
if (marker.imageUrl) {
|
|
250
|
+
const imageHtml = `<img src="${marker.imageUrl}" alt="${marker.imageAlt || ''}" style="max-width: 100%; height: auto; display: block; margin-bottom: 8px;" />`;
|
|
251
|
+
popupContent = imageHtml + popupContent;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (popupContent) {
|
|
255
|
+
const popup = new L.Popup({
|
|
256
|
+
className: 'custom-map-popup',
|
|
257
|
+
closeButton: false,
|
|
258
|
+
offset: [offset.x, offset.y],
|
|
259
|
+
}).setContent(popupContent);
|
|
260
|
+
|
|
261
|
+
leafletMarker.bindPopup(popup);
|
|
262
|
+
|
|
263
|
+
// Show popup on hover if enabled
|
|
264
|
+
if (showPopupsOnHover) {
|
|
265
|
+
leafletMarker.on('mouseover', () => {
|
|
266
|
+
leafletMarker.openPopup();
|
|
267
|
+
});
|
|
268
|
+
leafletMarker.on('mouseout', () => {
|
|
269
|
+
leafletMarker.closePopup();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
newMarkers.push(leafletMarker);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
markersRef.current = newMarkers;
|
|
278
|
+
|
|
279
|
+
// Update bounds if markers exist
|
|
280
|
+
if (markers.length > 0) {
|
|
281
|
+
const bounds = new L.LatLngBounds(markers.map((m) => new L.LatLng(m.lat, m.lng)));
|
|
282
|
+
map.fitBounds(bounds, { padding: [20, 20] });
|
|
283
|
+
}
|
|
284
|
+
}, [markers, icon, showPopupsOnHover]);
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<div
|
|
288
|
+
className="h-full w-full"
|
|
289
|
+
ref={mapContainerRef}
|
|
290
|
+
/>
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export default LeafletMap;
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { MemoryRouter } from 'react-router';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
4
|
+
import { Link, LinkBase, MarkdownLink, PathResolverProvider, usePathResolver } from './link';
|
|
5
|
+
|
|
6
|
+
// Helper to render with router context
|
|
7
|
+
const renderWithRouter = (ui: React.ReactNode, { route = '/' } = {}) => {
|
|
8
|
+
return render(<MemoryRouter initialEntries={[route]}>{ui}</MemoryRouter>);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('LinkBase', () => {
|
|
12
|
+
describe('path resolution', () => {
|
|
13
|
+
test('renders with string "to" prop', () => {
|
|
14
|
+
renderWithRouter(<LinkBase to="/about">About</LinkBase>);
|
|
15
|
+
|
|
16
|
+
const link = screen.getByRole('link', { name: 'About' });
|
|
17
|
+
expect(link).toHaveAttribute('href', '/about');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('renders with object "to" prop containing pathname', () => {
|
|
21
|
+
renderWithRouter(<LinkBase to={{ pathname: '/contact' }}>Contact</LinkBase>);
|
|
22
|
+
|
|
23
|
+
const link = screen.getByRole('link', { name: 'Contact' });
|
|
24
|
+
expect(link).toHaveAttribute('href', '/contact');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('renders with object "to" prop containing pathname, search, and hash', () => {
|
|
28
|
+
renderWithRouter(
|
|
29
|
+
<LinkBase to={{ hash: '#section', pathname: '/page', search: '?foo=bar' }}>
|
|
30
|
+
Full Path
|
|
31
|
+
</LinkBase>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const link = screen.getByRole('link', { name: 'Full Path' });
|
|
35
|
+
expect(link).toHaveAttribute('href', '/page?foo=bar#section');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('uses pathResolver when routeKey is provided', () => {
|
|
39
|
+
const mockResolver = vi.fn().mockReturnValue('/resolved-path');
|
|
40
|
+
|
|
41
|
+
renderWithRouter(
|
|
42
|
+
<PathResolverProvider value={mockResolver}>
|
|
43
|
+
<LinkBase routeKey="home">Home</LinkBase>
|
|
44
|
+
</PathResolverProvider>,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(mockResolver).toHaveBeenCalledWith('home');
|
|
48
|
+
const link = screen.getByRole('link', { name: 'Home' });
|
|
49
|
+
expect(link).toHaveAttribute('href', '/resolved-path');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('falls back to "to" prop when no pathResolver is available', () => {
|
|
53
|
+
renderWithRouter(
|
|
54
|
+
<LinkBase
|
|
55
|
+
routeKey="home"
|
|
56
|
+
to="/fallback"
|
|
57
|
+
>
|
|
58
|
+
Home
|
|
59
|
+
</LinkBase>,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const link = screen.getByRole('link', { name: 'Home' });
|
|
63
|
+
expect(link).toHaveAttribute('href', '/fallback');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('renders children only when path is empty', () => {
|
|
67
|
+
renderWithRouter(<LinkBase>No Link</LinkBase>);
|
|
68
|
+
|
|
69
|
+
expect(screen.queryByRole('link')).toBeNull();
|
|
70
|
+
expect(screen.getByText('No Link')).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('renders nothing for function children when path is empty', () => {
|
|
74
|
+
const { container } = renderWithRouter(
|
|
75
|
+
<LinkBase>{() => <span>Function Child</span>}</LinkBase>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(screen.queryByRole('link')).toBeNull();
|
|
79
|
+
expect(container.textContent).toBe('');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('external links', () => {
|
|
84
|
+
let windowOpenSpy: ReturnType<typeof vi.spyOn>;
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
windowOpenSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
afterEach(() => {
|
|
91
|
+
windowOpenSpy.mockRestore();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('renders tel: links as anchor elements', () => {
|
|
95
|
+
renderWithRouter(<LinkBase to="tel:+1234567890">Call Us</LinkBase>);
|
|
96
|
+
|
|
97
|
+
const link = screen.getByRole('link', { name: 'Call Us' });
|
|
98
|
+
expect(link.tagName).toBe('A');
|
|
99
|
+
expect(link).toHaveAttribute('href', 'tel:+1234567890');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('renders mailto: links as anchor elements', () => {
|
|
103
|
+
renderWithRouter(<LinkBase to="mailto:test@example.com">Email Us</LinkBase>);
|
|
104
|
+
|
|
105
|
+
const link = screen.getByRole('link', { name: 'Email Us' });
|
|
106
|
+
expect(link.tagName).toBe('A');
|
|
107
|
+
expect(link).toHaveAttribute('href', 'mailto:test@example.com');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('opens http links in new tab on click', () => {
|
|
111
|
+
renderWithRouter(<LinkBase to="https://example.com">External</LinkBase>);
|
|
112
|
+
|
|
113
|
+
const link = screen.getByRole('link', { name: 'External' });
|
|
114
|
+
fireEvent.click(link);
|
|
115
|
+
|
|
116
|
+
expect(windowOpenSpy).toHaveBeenCalledWith(
|
|
117
|
+
'https://example.com',
|
|
118
|
+
'_blank',
|
|
119
|
+
'noopener,noreferrer',
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('handles hash links with smooth scroll', () => {
|
|
124
|
+
const mockElement = document.createElement('div');
|
|
125
|
+
mockElement.id = 'section';
|
|
126
|
+
mockElement.scrollIntoView = vi.fn();
|
|
127
|
+
document.body.appendChild(mockElement);
|
|
128
|
+
|
|
129
|
+
renderWithRouter(<LinkBase to="#section">Go to Section</LinkBase>);
|
|
130
|
+
|
|
131
|
+
const link = screen.getByRole('link', { name: 'Go to Section' });
|
|
132
|
+
fireEvent.click(link);
|
|
133
|
+
|
|
134
|
+
expect(mockElement.scrollIntoView).toHaveBeenCalledWith({ behavior: 'smooth' });
|
|
135
|
+
|
|
136
|
+
document.body.removeChild(mockElement);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('does not scroll if hash element does not exist', () => {
|
|
140
|
+
renderWithRouter(<LinkBase to="#nonexistent">Missing Section</LinkBase>);
|
|
141
|
+
|
|
142
|
+
const link = screen.getByRole('link', { name: 'Missing Section' });
|
|
143
|
+
// Should not throw
|
|
144
|
+
expect(() => fireEvent.click(link)).not.toThrow();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('onClick handling', () => {
|
|
149
|
+
test('calls custom onClick handler', () => {
|
|
150
|
+
const handleClick = vi.fn();
|
|
151
|
+
|
|
152
|
+
renderWithRouter(
|
|
153
|
+
<LinkBase
|
|
154
|
+
onClick={handleClick}
|
|
155
|
+
to="/page"
|
|
156
|
+
>
|
|
157
|
+
Click Me
|
|
158
|
+
</LinkBase>,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const link = screen.getByRole('link', { name: 'Click Me' });
|
|
162
|
+
fireEvent.click(link);
|
|
163
|
+
|
|
164
|
+
expect(handleClick).toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('respects preventDefault from custom onClick', () => {
|
|
168
|
+
const windowOpenSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
|
|
169
|
+
const handleClick = vi.fn((e: React.MouseEvent) => e.preventDefault());
|
|
170
|
+
|
|
171
|
+
renderWithRouter(
|
|
172
|
+
<LinkBase
|
|
173
|
+
onClick={handleClick}
|
|
174
|
+
to="https://example.com"
|
|
175
|
+
>
|
|
176
|
+
External
|
|
177
|
+
</LinkBase>,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const link = screen.getByRole('link', { name: 'External' });
|
|
181
|
+
fireEvent.click(link);
|
|
182
|
+
|
|
183
|
+
expect(handleClick).toHaveBeenCalled();
|
|
184
|
+
expect(windowOpenSpy).not.toHaveBeenCalled();
|
|
185
|
+
|
|
186
|
+
windowOpenSpy.mockRestore();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('className and style handling', () => {
|
|
191
|
+
test('applies static className to external links', () => {
|
|
192
|
+
renderWithRouter(
|
|
193
|
+
<LinkBase
|
|
194
|
+
className="custom-class"
|
|
195
|
+
to="https://example.com"
|
|
196
|
+
>
|
|
197
|
+
External
|
|
198
|
+
</LinkBase>,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const link = screen.getByRole('link', { name: 'External' });
|
|
202
|
+
expect(link).toHaveClass('custom-class');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('resolves function className for external links', () => {
|
|
206
|
+
renderWithRouter(
|
|
207
|
+
<LinkBase
|
|
208
|
+
className={({ isActive }) => (isActive ? 'active' : 'inactive')}
|
|
209
|
+
to="https://example.com"
|
|
210
|
+
>
|
|
211
|
+
External
|
|
212
|
+
</LinkBase>,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const link = screen.getByRole('link', { name: 'External' });
|
|
216
|
+
expect(link).toHaveClass('inactive');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('resolves function style for external links', () => {
|
|
220
|
+
renderWithRouter(
|
|
221
|
+
<LinkBase
|
|
222
|
+
style={({ isActive }) => ({ color: isActive ? 'red' : 'blue' })}
|
|
223
|
+
to="https://example.com"
|
|
224
|
+
>
|
|
225
|
+
External
|
|
226
|
+
</LinkBase>,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const link = screen.getByRole('link', { name: 'External' });
|
|
230
|
+
expect(link).toHaveStyle({ color: 'rgb(0, 0, 255)' });
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('resolves function children for external links', () => {
|
|
234
|
+
renderWithRouter(
|
|
235
|
+
<LinkBase to="https://example.com">
|
|
236
|
+
{({ isActive }) => (isActive ? 'Active' : 'Inactive')}
|
|
237
|
+
</LinkBase>,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
expect(screen.getByText('Inactive')).toBeInTheDocument();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('viewTransition prop', () => {
|
|
245
|
+
test('defaults to true for internal links', () => {
|
|
246
|
+
renderWithRouter(<LinkBase to="/page">Page</LinkBase>);
|
|
247
|
+
|
|
248
|
+
// NavLink should receive viewTransition=true by default
|
|
249
|
+
const link = screen.getByRole('link', { name: 'Page' });
|
|
250
|
+
expect(link).toBeInTheDocument();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('can be disabled', () => {
|
|
254
|
+
renderWithRouter(
|
|
255
|
+
<LinkBase
|
|
256
|
+
to="/page"
|
|
257
|
+
viewTransition={false}
|
|
258
|
+
>
|
|
259
|
+
Page
|
|
260
|
+
</LinkBase>,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const link = screen.getByRole('link', { name: 'Page' });
|
|
264
|
+
expect(link).toBeInTheDocument();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('Link', () => {
|
|
270
|
+
test('applies variant classes', () => {
|
|
271
|
+
renderWithRouter(
|
|
272
|
+
<Link
|
|
273
|
+
to="/page"
|
|
274
|
+
variant="button"
|
|
275
|
+
>
|
|
276
|
+
Button Link
|
|
277
|
+
</Link>,
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
const link = screen.getByRole('link', { name: 'Button Link' });
|
|
281
|
+
expect(link).toHaveClass('button');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test('applies arrow classes', () => {
|
|
285
|
+
renderWithRouter(
|
|
286
|
+
<Link
|
|
287
|
+
arrow="rarr"
|
|
288
|
+
to="/page"
|
|
289
|
+
>
|
|
290
|
+
Arrow Link
|
|
291
|
+
</Link>,
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const link = screen.getByRole('link', { name: 'Arrow Link' });
|
|
295
|
+
expect(link).toHaveClass('rarr');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('merges custom className with variant classes', () => {
|
|
299
|
+
renderWithRouter(
|
|
300
|
+
<Link
|
|
301
|
+
className="custom"
|
|
302
|
+
to="/page"
|
|
303
|
+
variant="code"
|
|
304
|
+
>
|
|
305
|
+
Code Link
|
|
306
|
+
</Link>,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const link = screen.getByRole('link', { name: 'Code Link' });
|
|
310
|
+
expect(link).toHaveClass('font-monospace');
|
|
311
|
+
expect(link).toHaveClass('custom');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test('passes through routeKey to LinkBase', () => {
|
|
315
|
+
const mockResolver = vi.fn().mockReturnValue('/resolved');
|
|
316
|
+
|
|
317
|
+
renderWithRouter(
|
|
318
|
+
<PathResolverProvider value={mockResolver}>
|
|
319
|
+
<Link routeKey="test">Test</Link>
|
|
320
|
+
</PathResolverProvider>,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
expect(mockResolver).toHaveBeenCalledWith('test');
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe('MarkdownLink', () => {
|
|
328
|
+
test('renders Link when href is provided', () => {
|
|
329
|
+
renderWithRouter(<MarkdownLink href="/page">Markdown Link</MarkdownLink>);
|
|
330
|
+
|
|
331
|
+
const link = screen.getByRole('link', { name: 'Markdown Link' });
|
|
332
|
+
expect(link).toHaveAttribute('href', '/page');
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('renders null when href is not provided', () => {
|
|
336
|
+
const { container } = renderWithRouter(<MarkdownLink>No Href</MarkdownLink>);
|
|
337
|
+
|
|
338
|
+
expect(container.textContent).toBe('');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test('passes through Link props', () => {
|
|
342
|
+
renderWithRouter(
|
|
343
|
+
<MarkdownLink
|
|
344
|
+
href="/page"
|
|
345
|
+
variant="subtitle"
|
|
346
|
+
>
|
|
347
|
+
Styled Link
|
|
348
|
+
</MarkdownLink>,
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const link = screen.getByRole('link', { name: 'Styled Link' });
|
|
352
|
+
expect(link).toHaveClass('text-lg');
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe('usePathResolver', () => {
|
|
357
|
+
test('returns null when no provider is present', () => {
|
|
358
|
+
let resolverValue: ReturnType<typeof usePathResolver> = vi.fn();
|
|
359
|
+
|
|
360
|
+
const TestComponent = () => {
|
|
361
|
+
resolverValue = usePathResolver();
|
|
362
|
+
return null;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
render(<TestComponent />);
|
|
366
|
+
|
|
367
|
+
expect(resolverValue).toBeNull();
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('returns resolver function when provider is present', () => {
|
|
371
|
+
const mockResolver = vi.fn().mockReturnValue('/path');
|
|
372
|
+
let resolverValue: ReturnType<typeof usePathResolver> = null;
|
|
373
|
+
|
|
374
|
+
const TestComponent = () => {
|
|
375
|
+
resolverValue = usePathResolver();
|
|
376
|
+
return null;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
render(
|
|
380
|
+
<PathResolverProvider value={mockResolver}>
|
|
381
|
+
<TestComponent />
|
|
382
|
+
</PathResolverProvider>,
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
expect(resolverValue).toBe(mockResolver);
|
|
386
|
+
});
|
|
387
|
+
});
|