2020-01-10 14:37:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
2020-02-14 03:43:13 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import OptionLayout from './option-layout';
|
|
|
|
|
2020-01-10 14:37:27 +00:00
|
|
|
const Option = ( { checked, name, onChange, option } ) => {
|
|
|
|
const {
|
|
|
|
value,
|
|
|
|
label,
|
|
|
|
description,
|
|
|
|
secondaryLabel,
|
|
|
|
secondaryDescription,
|
|
|
|
} = option;
|
|
|
|
const onChangeValue = ( event ) => onChange( event.target.value );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<label
|
2021-02-02 04:51:47 +00:00
|
|
|
className={ classnames(
|
|
|
|
'wc-block-components-radio-control__option',
|
|
|
|
{
|
|
|
|
'wc-block-components-radio-control__option-checked': checked,
|
|
|
|
}
|
|
|
|
) }
|
2020-01-10 14:37:27 +00:00
|
|
|
htmlFor={ `${ name }-${ value }` }
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
id={ `${ name }-${ value }` }
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-components-radio-control__input"
|
2020-01-10 14:37:27 +00:00
|
|
|
type="radio"
|
|
|
|
name={ name }
|
|
|
|
value={ value }
|
|
|
|
onChange={ onChangeValue }
|
|
|
|
checked={ checked }
|
|
|
|
aria-describedby={ classnames( {
|
|
|
|
[ `${ name }-${ value }__label` ]: label,
|
|
|
|
[ `${ name }-${ value }__secondary-label` ]: secondaryLabel,
|
|
|
|
[ `${ name }-${ value }__description` ]: description,
|
|
|
|
[ `${ name }-${ value }__secondary-description` ]: secondaryDescription,
|
|
|
|
} ) }
|
|
|
|
/>
|
2020-02-14 03:43:13 +00:00
|
|
|
<OptionLayout
|
|
|
|
id={ `${ name }-${ value }` }
|
|
|
|
label={ label }
|
|
|
|
secondaryLabel={ secondaryLabel }
|
|
|
|
description={ description }
|
|
|
|
secondaryDescription={ secondaryDescription }
|
|
|
|
/>
|
2020-01-10 14:37:27 +00:00
|
|
|
</label>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Option;
|