/* eslint-disable react/display-name */ /* eslint-disable react/button-has-type */ import React, { useState } from "react"; import { AttributionControl, MapProvider, NavigationControl, ScaleControl, useMap } from "react-map-gl/maplibre"; import { action } from "storybook/actions"; import { StoryFn } from "@storybook/react-vite"; import AllVehiclesOverlay from "../__mocks__/AllVehicles"; import ContextMenuDemo from "../__mocks__/ContextMenuDemo"; import { withMap } from "../../../.storybook/base-map-wrapper"; import BaseMap, { MarkerWithPopup, LayerWrapper, Popup, Styled } from "."; const center: [number, number] = [45.522862, -122.667837]; export default { args: { center }, component: BaseMap, title: "BaseMap", parameters: { storyshots: { disable: true } } }; const samplePopup = (

Popup Title

Sample popup content.

); const sampleMarkers = ( ); const onClick = action("onClick"); const onContextMenu = action("onContextMenu"); const onViewportChanged = action("onViewportChanged"); export const clickAndViewportchangedEvents = { args: { center, // Note: Although onClick and onContextMenu are correctly triggered, // the parameter returned by these events contains a cyclical reference that prevents Storybook from printing them. onClick, onContextMenu, onViewportChanged }, decorators: [withMap()] }; export const zoomed = { args: { center, zoom: 17 }, decorators: [withMap()] }; const SetBoundsButton = () => { const { mapWithBounds } = useMap(); const bbox = [-79, 43, -73, 45]; return ( ); }; // This story causes the map to be rendered twice // This is a storybook bug: https://github.com/storybookjs/storybook/issues/12670 export const clickToSetBounds: StoryFn = () => ( ); export const maxZoom = { args: { maxZoom: 18, zoom: 30 }, decorators: [withMap()] }; export const withSampleMarkers = () => ( {sampleMarkers}{" "} ); export const overlayWithLargeDataSet = { render: () => ( <>
Do not add Storybook overhead on layers with large dataset...
), decorators: [withMap()] }; export const customLocationPopupContent = () => ( {samplePopup} ); export const optionalLayers = { args: { showEverything: false }, // eslint-disable-next-line react/display-name render: (props: any): JSX.Element => ( {/* eslint-disable-next-line react/jsx-props-no-spreading */} ) }; export const onContextMenuPopup = () => ; /** * See https://visgl.github.io/react-map-gl/docs/api-reference/attribution-control * See https://visgl.github.io/react-map-gl/docs/api-reference/navigation-control * See https://visgl.github.io/react-map-gl/docs/api-reference/scale-control * * Any control which is added as a child of a react-map-gl map is supported */ export const withOptionalControls = { render: () => ( ), decorators: [withMap()] }; export const withMultipleBaseLayers = () => { const [mapTilerKey, setMapTilerKey] = useState(""); return ( setMapTilerKey(e.target.value)} placeholder="MapTiler API Key" type="text" value={mapTilerKey} /> {mapTilerKey && ( )} ); }; export const withMultipleBaseLayersAndOptionalLayers = () => { const [mapTilerKey, setMapTilerKey] = useState(""); return ( setMapTilerKey(e.target.value)} placeholder="MapTiler API Key" type="text" value={mapTilerKey} /> {mapTilerKey && ( )} ); };