import React, { useEffect, useState } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import { useAtomValue, useSetAtom } from 'jotai'; import InputNumber from 'common/input-number'; import RangeSlider from 'common/range-slider'; import { Row, Selector, Label } from 'common/styles'; import updateStyle from 'common/utils/update-style'; import useGetStyleKey from 'hooks/useGetStyleKey'; import { layerState, mapState, selectedLayerIDState, styleObjState, } from 'atoms/map'; const SetOpacity = () => { const intl = useIntl(); const map = useAtomValue(mapState); const openLayerID = useAtomValue(selectedLayerIDState); const setStyleObj = useSetAtom(styleObjState); const layer = useAtomValue(layerState); const { styleKey, property } = useGetStyleKey('opacity'); const [opacity, setOpacity] = useState(100); useEffect(() => { // @ts-ignore line // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access setOpacity((layer?.[styleKey]?.[property] ?? 1) * 100); }, [layer, styleKey, property]); return ( { { if (property && styleKey && openLayerID && map) updateStyle( openLayerID, map, styleKey, property, value[0] / 100, setStyleObj ); } }} /> { { if (property && styleKey && openLayerID && map) updateStyle( openLayerID, map, styleKey, property, number / 100, setStyleObj ); } }} /> ); }; export default SetOpacity;