2020-02-14 12:30:33 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { CustomSelectControl } from 'wordpress-components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-23 11:22:00 +00:00
|
|
|
const Select = ( {
|
|
|
|
className,
|
|
|
|
feedback,
|
|
|
|
id,
|
|
|
|
label,
|
|
|
|
onChange,
|
|
|
|
options,
|
|
|
|
value,
|
|
|
|
} ) => {
|
2020-02-14 12:30:33 +00:00
|
|
|
return (
|
2020-03-23 11:22:00 +00:00
|
|
|
<div
|
|
|
|
id={ id }
|
2020-06-17 09:53:42 +00:00
|
|
|
className={ classnames( 'wc-block-components-select', className, {
|
2020-02-14 12:30:33 +00:00
|
|
|
'is-active': value,
|
|
|
|
} ) }
|
2020-03-23 11:22:00 +00:00
|
|
|
>
|
|
|
|
<CustomSelectControl
|
|
|
|
label={ label }
|
|
|
|
onChange={ ( { selectedItem } ) => {
|
|
|
|
onChange( selectedItem.key );
|
|
|
|
} }
|
|
|
|
options={ options }
|
|
|
|
value={ value }
|
|
|
|
/>
|
|
|
|
{ feedback }
|
|
|
|
</div>
|
2020-02-14 12:30:33 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Select.propTypes = {
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
options: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape( {
|
|
|
|
key: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
} ).isRequired
|
|
|
|
).isRequired,
|
|
|
|
className: PropTypes.string,
|
2020-03-23 11:22:00 +00:00
|
|
|
feedback: PropTypes.node,
|
|
|
|
id: PropTypes.string,
|
2020-02-14 12:30:33 +00:00
|
|
|
label: PropTypes.string,
|
|
|
|
value: PropTypes.shape( {
|
|
|
|
key: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
} ),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Select;
|
2020-03-23 11:22:00 +00:00
|
|
|
export { default as ValidatedSelect } from './validated';
|