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-06-17 09:53:42 +00:00
|
|
|
className={ classNames(
|
|
|
|
'wc-block-components-checkbox',
|
|
|
|
className
|
|
|
|
) }
|
2020-04-07 15:37:03 +00:00
|
|
|
htmlFor={ checkboxId }
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
id={ checkboxId }
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-components-checkbox__input"
|
2020-04-07 15:37:03 +00:00
|
|
|
type="checkbox"
|
|
|
|
onChange={ ( event ) => onChange( event.target.checked ) }
|
|
|
|
{ ...rest }
|
|
|
|
/>
|
2020-06-17 09:53:42 +00:00
|
|
|
<span className="wc-block-components-checkbox__label">
|
|
|
|
{ label }
|
|
|
|
</span>
|
2020-04-07 15:37:03 +00:00
|
|
|
</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 );
|