2019-12-16 22:13:41 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
2020-01-10 14:37:27 +00:00
|
|
|
import withComponentId from '@woocommerce/base-hocs/with-component-id';
|
2019-12-16 22:13:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-01-10 14:37:27 +00:00
|
|
|
import RadioControlOption from './option';
|
2019-12-16 22:13:41 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const RadioControl = ( {
|
|
|
|
className,
|
2020-01-10 14:37:27 +00:00
|
|
|
componentId,
|
2020-01-14 20:21:29 +00:00
|
|
|
id,
|
2019-12-16 22:13:41 +00:00
|
|
|
selected,
|
|
|
|
onChange,
|
|
|
|
options = [],
|
|
|
|
} ) => {
|
2020-01-14 20:21:29 +00:00
|
|
|
const radioControlId = id || componentId;
|
|
|
|
|
2019-12-16 22:13:41 +00:00
|
|
|
return (
|
|
|
|
options.length && (
|
|
|
|
<div
|
2020-01-03 14:23:49 +00:00
|
|
|
className={ classnames( 'wc-block-radio-control', className ) }
|
2019-12-16 22:13:41 +00:00
|
|
|
>
|
2020-01-10 14:37:27 +00:00
|
|
|
{ options.map( ( option ) => (
|
|
|
|
<RadioControlOption
|
|
|
|
key={ option.value }
|
2020-01-14 20:21:29 +00:00
|
|
|
name={ `radio-control-${ radioControlId }` }
|
2020-01-10 14:37:27 +00:00
|
|
|
checked={ option.value === selected }
|
|
|
|
option={ option }
|
|
|
|
onChange={ onChange }
|
|
|
|
/>
|
|
|
|
) ) }
|
2019-12-16 22:13:41 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-10 14:37:27 +00:00
|
|
|
export default withComponentId( RadioControl );
|
2020-02-14 03:43:13 +00:00
|
|
|
export { RadioControlOption };
|
|
|
|
export { default as RadioControlOptionLayout } from './option-layout';
|