import React, { useEffect, useState } from 'react'; import { v4 as uuidv4 } from 'uuid'; export const RadioButton = function RadioButton({ id, height, properties, styles, fireEvent, setExposedVariable, registerAction, darkMode, dataCy, }) { const { label, value, values, display_values } = properties; const { visibility, disabledState, activeColor } = styles; const textColor = darkMode && styles.textColor === '#000' ? '#fff' : styles.textColor; const [checkedValue, setValue] = useState(() => value); useEffect(() => setValue(value), [value]); let selectOptions = []; try { selectOptions = [ ...values.map((value, index) => { return { name: display_values[index], value: value }; }), ]; } catch (err) { console.log(err); } function onSelect(selection) { setValue(selection); setExposedVariable('value', selection).then(() => fireEvent('onSelectionChange')); } useEffect(() => { setExposedVariable('value', value); // eslint-disable-next-line react-hooks/exhaustive-deps }, [value]); registerAction( 'selectOption', async function (option) { onSelect(option); }, [setValue] ); return (
{label}
{selectOptions.map((option, index) => ( ))}
); };