import { MagnifyingGlassMinusIcon, StarIcon } from "@phosphor-icons/react"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { useEffect, useRef, useState } from "react"; import type { MTDSAtlasCollection, MTDSAtlasElement } from "../atlas"; import { Button, Details, Field, Fieldset, Flex, Group, Heading, Popover, Prose, toast, } from "../react"; import { Atlas, type AtlasMatgeoProps } from "../react-atlas"; const meta = { title: "Designsystem/Atlas", parameters: { layout: "padded", }, } satisfies Meta; export default meta; type Story = StoryObj; const LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque finibus dui id efficitur lobortis. Aliquam erat volutpat. Pellentesque imperdiet consectetur posuere. Donec ultrices libero eu velit egestas tincidunt. Suspendisse placerat risus non tellus faucibus, eu ultricies augue tempus. Donec vestibulum arcu diam, efficitur auctor lectus placerat vel. Nullam aliquam turpis vel mollis pharetra. Etiam eget pulvinar dui, imperdiet congue nisi. Nullam vel finibus risus. Ut sodales luctus odio quis interdum. Donec ligula quam, viverra vitae finibus a, bibendum quis odio. Quisque sodales erat volutpat condimentum maximus. Sed eget augue sed ligula congue hendrerit id sed turpis. Fusce nec leo fringilla, faucibus turpis a, tristique est. In ac semper libero, nec lacinia tellus."; export const Default: Story = { parameters: { showInOverview: false, }, render: () => , }; export const React: Story = { parameters: { showInOverview: false, }, render: () => , }; export const WithView: Story = { render: () => , }; export const WithViewAdvanced: Story = { render: function Render() { const atlasRef = useRef(null); const [open, setOpen] = useState<(typeof markers)[number]>(); const markers = [ { latlng: "59.910815, 10.754078", summary: "Oslo", content: "Informasjon om Oslo", }, { latlng: "63.431958, 10.397461", summary: "Trondheim", content: "Informasjon om Trondheim", }, { latlng: "60.391449, 5.324119", summary: "Bergen", content: "Informasjon om Bergen", }, ]; return ( {markers.map((marker) => ( setOpen(marker)} /> ))} {markers.map((marker) => (
setOpen(marker)}> {marker.summary}
{marker.content}
))}
); }, }; export const WithColor: Story = { render: () => ( ), }; export const WithCustomSize: Story = { render: () => ( ), }; export const WithMarker: Story = { render: () => ( A ), }; export const WithMarkerStyling: Story = { render: () => ( ), }; const getRandomCoordinates = (lat = 60.722, lng = 10.985) => Array.from({ length: 100 }, () => { return `${lat + (Math.random() - 0.5) * 0.025}, ${lng + (Math.random() - 0.5) * 0.1}`; }); export const WithClustering: Story = { render: () => ( {getRandomCoordinates().map((latlng, index) => ( ))} Popover ), }; export const WithPopover: Story = { render: () => ( Popover 1 Popover 2 ), }; export const WithPopoverDynamic: Story = { render: function Render() { const [open, setOpen] = useState(-1); const markers = [ { latlng: "60.722, 10.985", popover: "Min nydelige popover" }, { latlng: "60.721, 10.980", popover: ( Avansert popover

Innhold

), }, ]; return ( {markers.map((marker, index) => ( setOpen(index)} popoverTarget="my-popover" /> ))} {markers[open]?.popover} ); }, }; export const WithMatgeo: Story = { render: () => { const [content, setContent] = useState(""); return ( { setContent( JSON.stringify( event.detail.targets.map((layer) => layer.feature?.properties), null, " ", ), ); }} />
{content}
); }, }; export const WithMatgeoToggle: Story = { render: () => { const atlasRef = useRef(null); const colors = ["info", "success", "warning", "danger"] as const; const [content, setContent] = useState(""); const [collections, setCollections] = useState< (MTDSAtlasCollection & { hidden?: boolean })[] >([]); const handleFeatureClick: AtlasMatgeoProps["onFeatureClick"] = (event) => { const targets = event.detail.targets; const props = targets.map((layer) => layer.feature?.properties); setContent(JSON.stringify(props, null, " ")); }; useEffect(() => { atlasRef.current ?.getCollections() .then((collections) => setCollections(Object.values(collections))); }, []); return ( {collections.map((collection, index) => (
{collections.map((collection, index) => ( { const clone = collections.slice(); clone[index].hidden = !clone[index].hidden; setCollections(clone); }} /> ))}
); }, }; export const WithWMS: Story = { render: () => ( ), }; export const WithTooltip: Story = { render: () => ( ), }; export const WithClickToAddMarker: Story = { render: function Render() { const atlasRef = useRef(null); const [markers, setMarkers] = useState([]); return ( <> { if (atlas !== target) return; // Only add if clicking directly on map const latlng = atlas.latLngFromPoint(clientX, clientY); setMarkers([...markers, `${latlng?.lat}, ${latlng?.lng}`]); toast({`${latlng}`}); }} > {markers.map((latlng, index) => ( { const clone = [...markers]; clone.splice(index, 1); // Remove marker setMarkers(clone); }} onDragEnd={(event) => { const clone = [...markers]; clone[index] = event.currentTarget.latlng; setMarkers(clone); }} > {index + 1} ))}
  1. Klikk på kartet for å legge til markør
  2. Dra markør for å flytte
  3. Klikk på markør for å fjerne
); }, }; export const WithoutScrollZoom: Story = { render: () => (

{LOREM_IPSUM}

{LOREM_IPSUM}

), }; // export const WithGeoJSON: Story = { // render: () => { // const atlasRef = useRef(null); // useEffect(() => { // const map = atlasRef.current?.map; // const url = // "https://mattilsynet.avadaptive.dev/api/core/v1/ogc/features/collections/slammelding_spredeareal/items"; // if (!map) return; // fetch(url) // .then((res) => res.json()) // .then((data) => { // console.log(data); // L.geoJSON(data).addTo(map); // }); // }, []); // return ; // }, // };