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 classNames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
type CheckboxControlProps = {
|
|
|
|
className?: string;
|
|
|
|
label?: string;
|
|
|
|
id?: string;
|
|
|
|
instanceId: string;
|
|
|
|
onChange: ( value: boolean ) => void;
|
|
|
|
children: React.ReactChildren;
|
|
|
|
};
|
|
|
|
|
2020-03-06 10:26:03 +00:00
|
|
|
/**
|
|
|
|
* Component used to show a checkbox control with styles.
|
|
|
|
*/
|
2020-04-07 15:37:03 +00:00
|
|
|
const CheckboxControl = ( {
|
|
|
|
className,
|
|
|
|
label,
|
|
|
|
id,
|
|
|
|
instanceId,
|
|
|
|
onChange,
|
2021-07-22 11:03:00 +00:00
|
|
|
children,
|
2020-04-07 15:37:03 +00:00
|
|
|
...rest
|
2021-07-22 11:03:00 +00:00
|
|
|
}: CheckboxControlProps ): JSX.Element => {
|
2020-04-07 15:37:03 +00:00
|
|
|
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-08-11 08:59:59 +00:00
|
|
|
<svg
|
|
|
|
className="wc-block-components-checkbox__mark"
|
|
|
|
aria-hidden="true"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
viewBox="0 0 24 20"
|
|
|
|
>
|
|
|
|
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
|
|
|
|
</svg>
|
2021-07-22 11:03:00 +00:00
|
|
|
{ label && (
|
|
|
|
<span className="wc-block-components-checkbox__label">
|
|
|
|
{ label }
|
|
|
|
</span>
|
|
|
|
) }
|
|
|
|
{ children }
|
2020-04-07 15:37:03 +00:00
|
|
|
</label>
|
2020-03-06 10:26:03 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-04-07 15:37:03 +00:00
|
|
|
export default withInstanceId( CheckboxControl );
|