2020-02-14 03:43:13 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import RadioControl, {
|
|
|
|
RadioControlOptionLayout,
|
|
|
|
} from '@woocommerce/base-components/radio-control';
|
|
|
|
|
|
|
|
const PackageOptions = ( {
|
|
|
|
className,
|
|
|
|
noResultsMessage,
|
|
|
|
onChange,
|
|
|
|
options,
|
|
|
|
renderOption,
|
|
|
|
selected,
|
|
|
|
} ) => {
|
|
|
|
if ( options.length === 0 ) {
|
2020-11-17 11:58:38 +00:00
|
|
|
return noResultsMessage;
|
2020-02-14 03:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( options.length > 1 ) {
|
|
|
|
return (
|
|
|
|
<RadioControl
|
|
|
|
className={ className }
|
|
|
|
onChange={ onChange }
|
|
|
|
selected={ selected }
|
|
|
|
options={ options.map( renderOption ) }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
label,
|
|
|
|
secondaryLabel,
|
|
|
|
description,
|
|
|
|
secondaryDescription,
|
2020-02-17 11:12:15 +00:00
|
|
|
} = renderOption( options[ 0 ] );
|
2020-02-14 03:43:13 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<RadioControlOptionLayout
|
|
|
|
label={ label }
|
|
|
|
secondaryLabel={ secondaryLabel }
|
|
|
|
description={ description }
|
|
|
|
secondaryDescription={ secondaryDescription }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
PackageOptions.propTypes = {
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
options: PropTypes.arrayOf( PropTypes.object ).isRequired,
|
|
|
|
renderOption: PropTypes.func.isRequired,
|
|
|
|
className: PropTypes.string,
|
2020-11-17 11:58:38 +00:00
|
|
|
noResultsMessage: PropTypes.node,
|
2020-02-14 03:43:13 +00:00
|
|
|
selected: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PackageOptions;
|