import { useId, useRef, useEffect } from 'react'; import { Button, Dialog, DialogTrigger, Popover } from 'react-aria-components'; import { MapIcon } from '@heroicons/react/outline'; import { Slider } from '@reach/slider'; import '@reach/slider/styles.css'; import { LayersMap, NBS } from './styles'; const STYLES = { ortho: 'Satellite', vector: 'Vectoriel', ign: 'Carte IGN' }; export function StyleSwitch({ styleId, layers, setStyle, setLayerEnabled, setLayerOpacity }: { styleId: string; setStyle: (style: string) => void; layers: LayersMap; setLayerEnabled: (layer: string, enabled: boolean) => void; setLayerOpacity: (layer: string, opacity: number) => void; }) { const configurableLayers = Object.entries(layers).filter( ([, { configurable }]) => configurable ); const mapId = useId(); const buttonRef = useRef(null); useEffect(() => { if (buttonRef.current) { buttonRef.current.title = 'Sélectionner les couches cartographiques'; } }, []); return (
event.preventDefault()} >
{Object.entries(STYLES).map(([style, title]) => (
{ setStyle(event.target.value); }} />
))}
{configurableLayers.length ? (
{configurableLayers.map( ([layer, { enabled, opacity, name }]) => (
{ setLayerEnabled(layer, event.target.checked); }} />
{ setLayerOpacity(layer, value); }} className="fr-range fr-range--sm mt-1" title={`Réglage de l’opacité de la couche «${NBS}${name}${NBS}»`} getAriaLabel={() => `Réglage de l’opacité de la couche «${NBS}${name}${NBS}»` } getAriaValueText={(value) => `L’opacité de la couche «${NBS}${name}${NBS}» est à ${value}${NBS}%` } />
) )}
) : null}
); }