2020-03-06 10:26:03 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-04-07 15:37:03 +00:00
|
|
|
import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
|
2020-03-06 10:26:03 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component used to show a checkbox control with styles.
|
|
|
|
*/
|
2020-04-07 15:37:03 +00:00
|
|
|
const CheckboxControl = ( {
|
|
|
|
className,
|
|
|
|
label,
|
|
|
|
id,
|
|
|
|
instanceId,
|
|
|
|
onChange,
|
|
|
|
...rest
|
|
|
|
} ) => {
|
|
|
|
const checkboxId = id || `checkbox-control-${ instanceId }`;
|
|
|
|
|
2020-03-06 10:26:03 +00:00
|
|
|
return (
|
2020-04-07 15:37:03 +00:00
|
|
|
<label
|
2020-03-06 10:26:03 +00:00
|
|
|
className={ classNames( 'wc-block-checkbox', className ) }
|
2020-04-07 15:37:03 +00:00
|
|
|
htmlFor={ checkboxId }
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
id={ checkboxId }
|
|
|
|
className="wc-block-checkbox__input"
|
|
|
|
type="checkbox"
|
|
|
|
onChange={ ( event ) => onChange( event.target.checked ) }
|
|
|
|
{ ...rest }
|
|
|
|
/>
|
|
|
|
<span className="wc-block-checkbox__label">{ label }</span>
|
|
|
|
</label>
|
2020-03-06 10:26:03 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
CheckboxControl.propTypes = {
|
|
|
|
className: PropTypes.string,
|
2020-04-07 15:37:03 +00:00
|
|
|
label: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
|
|
|
onChange: PropTypes.func,
|
2020-03-06 10:26:03 +00:00
|
|
|
};
|
|
|
|
|
2020-04-07 15:37:03 +00:00
|
|
|
export default withInstanceId( CheckboxControl );
|