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';
|
2022-02-10 11:59:43 +00:00
|
|
|
import type { RadioControlOptionProps } from './types';
|
2020-02-14 03:43:13 +00:00
|
|
|
|
2022-02-10 11:59:43 +00:00
|
|
|
const Option = ( {
|
|
|
|
checked,
|
|
|
|
name,
|
|
|
|
onChange,
|
|
|
|
option,
|
|
|
|
}: RadioControlOptionProps ): JSX.Element => {
|
2022-06-15 09:56:52 +00:00
|
|
|
const { value, label, description, secondaryLabel, secondaryDescription } =
|
|
|
|
option;
|
2022-02-10 11:59:43 +00:00
|
|
|
const onChangeValue = ( event: React.ChangeEvent< HTMLInputElement > ) =>
|
|
|
|
onChange( event.target.value );
|
2020-01-10 14:37:27 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<label
|
2021-02-02 04:51:47 +00:00
|
|
|
className={ classnames(
|
|
|
|
'wc-block-components-radio-control__option',
|
|
|
|
{
|
2022-06-15 09:56:52 +00:00
|
|
|
'wc-block-components-radio-control__option-checked':
|
|
|
|
checked,
|
2021-02-02 04:51:47 +00:00
|
|
|
}
|
|
|
|
) }
|
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,
|
2022-06-15 09:56:52 +00:00
|
|
|
[ `${ name }-${ value }__secondary-description` ]:
|
|
|
|
secondaryDescription,
|
2020-01-10 14:37:27 +00:00
|
|
|
} ) }
|
|
|
|
/>
|
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;
|