woocommerce/packages/woocommerce-blocks/assets/js/base/components/radio-control/index.js
2021-12-10 12:03:04 +00:00

53 lines
1.1 KiB
JavaScript

/**
* External dependencies
*/
import classnames from 'classnames';
import { withInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
*/
import RadioControlOption from './option';
import './style.scss';
const RadioControl = ( {
className,
instanceId,
id,
selected,
onChange,
options = [],
} ) => {
const radioControlId = id || instanceId;
return (
options.length && (
<div
className={ classnames(
'wc-block-components-radio-control',
className
) }
>
{ options.map( ( option ) => (
<RadioControlOption
key={ `${ radioControlId }-${ option.value }` }
name={ `radio-control-${ radioControlId }` }
checked={ option.value === selected }
option={ option }
onChange={ ( value ) => {
onChange( value );
if ( typeof option.onChange === 'function' ) {
option.onChange( value );
}
} }
/>
) ) }
</div>
)
);
};
export default withInstanceId( RadioControl );
export { RadioControlOption };
export { default as RadioControlOptionLayout } from './option-layout';