2020-01-10 14:37:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2020-01-10 14:37:27 +00:00
|
|
|
|
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,
|
2023-08-08 10:56:19 +00:00
|
|
|
disabled = false,
|
2024-04-10 09:54:05 +00:00
|
|
|
highlightChecked = false,
|
2022-02-10 11:59:43 +00:00
|
|
|
}: 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 (
|
2023-12-12 23:05:20 +00:00
|
|
|
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
2020-01-10 14:37:27 +00:00
|
|
|
<label
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx( 'wc-block-components-radio-control__option', {
|
|
|
|
'wc-block-components-radio-control__option-checked': checked,
|
|
|
|
'wc-block-components-radio-control__option--checked-option-highlighted':
|
|
|
|
checked && highlightChecked,
|
|
|
|
} ) }
|
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 }
|
2024-05-31 03:49:36 +00:00
|
|
|
aria-describedby={ clsx( {
|
2020-01-10 14:37:27 +00:00
|
|
|
[ `${ 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
|
|
|
} ) }
|
2023-08-08 10:56:19 +00:00
|
|
|
disabled={ disabled }
|
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;
|