woocommerce/plugins/woocommerce-blocks/assets/js/base/components/radio-control/index.js

43 lines
824 B
JavaScript

/**
* External dependencies
*/
import classnames from 'classnames';
import withComponentId from '@woocommerce/base-hocs/with-component-id';
/**
* Internal dependencies
*/
import RadioControlOption from './option';
import './style.scss';
const RadioControl = ( {
className,
componentId,
id,
selected,
onChange,
options = [],
} ) => {
const radioControlId = id || componentId;
return (
options.length && (
<div
className={ classnames( 'wc-block-radio-control', className ) }
>
{ options.map( ( option ) => (
<RadioControlOption
key={ option.value }
name={ `radio-control-${ radioControlId }` }
checked={ option.value === selected }
option={ option }
onChange={ onChange }
/>
) ) }
</div>
)
);
};
export default withComponentId( RadioControl );