import { useState, useEffect } from '@wordpress/element'; import { ModifierPanelProps } from '@components/DesignPanel/types'; import ButtonToggleGroup from '@components/ui/ButtonToggle'; import { ButtonToggle } from '@components/ui/ButtonToggle'; import RangeControl from '@components/ui/RangeSlider'; import CaretRightIcon from 'blockbite-icons/dist/CaretRight'; import { getValueUnit, formatUnit } from '@components/DesignPanel/Helpers'; export const ButtonGroupRange: React.FC = ({ options, activeOptionValue, emitOptions, modifierId, }: any) => { const [value, setValue] = useState(''); const [range, setRange] = useState({ min: 0, max: 0 }); const [toggle, setToggle] = useState('off'); useEffect(() => { if (options.length) { setRange({ min: options[0].value, max: options[options.length - 1].value, }); } const { foundValue } = getValueUnit(activeOptionValue); setValue(foundValue); }, [activeOptionValue]); return (
{ setToggle(value === 'on' ? 'off' : 'on'); }} > Toggle {toggle === 'on' && ( ({ label: options.label, value: options.value.toString(), icon: options?.icon, }))} onPressedChange={(value) => { setValue(value); emitOptions([ { id: modifierId, value, }, ]); }} /> )} { let formattedValue = formatUnit(value, 'arbitrary', ''); // eg [.5] if (modifierId === 'opacity') { formattedValue = formatUnit(parseInt(value) / 100, 'arbitrary', ''); } else if (modifierId === 'gridcols' || modifierId === 'gridrows') { formattedValue = value; } setValue(value); emitOptions([ { id: modifierId, value: formattedValue, }, ]); }} />
); }; export default ButtonGroupRange;