2019-12-16 22:13:41 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
2020-03-10 14:40:30 +00:00
|
|
|
import { withInstanceId } from 'wordpress-compose';
|
2019-12-16 22:13:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-01-10 14:37:27 +00:00
|
|
|
import RadioControlOption from './option';
|
2020-02-26 13:02:48 +00:00
|
|
|
import './editor.scss';
|
2019-12-16 22:13:41 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const RadioControl = ( {
|
|
|
|
className,
|
2020-03-10 14:40:30 +00:00
|
|
|
instanceId,
|
2020-01-14 20:21:29 +00:00
|
|
|
id,
|
2019-12-16 22:13:41 +00:00
|
|
|
selected,
|
|
|
|
onChange,
|
|
|
|
options = [],
|
|
|
|
} ) => {
|
2020-03-10 14:40:30 +00:00
|
|
|
const radioControlId = id || instanceId;
|
2020-01-14 20:21:29 +00:00
|
|
|
|
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-03-10 14:40:30 +00:00
|
|
|
export default withInstanceId( RadioControl );
|
2020-02-14 03:43:13 +00:00
|
|
|
export { RadioControlOption };
|
|
|
|
export { default as RadioControlOptionLayout } from './option-layout';
|