Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit e2b370a

Browse files
committed
Revert "import checkbox from single place (#12015)"
This reverts commit d952f8e.
1 parent d952f8e commit e2b370a

File tree

3 files changed

+83
-6
lines changed
  • assets/js/blocks/checkout/inner-blocks
  • packages/checkout/components/checkbox-control

3 files changed

+83
-6
lines changed

assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
noticeContexts,
99
} from '@woocommerce/base-context';
1010
import { getSetting } from '@woocommerce/settings';
11+
import { CheckboxControl } from '@woocommerce/blocks-checkout';
1112
import {
1213
StoreNoticesContainer,
1314
ValidatedTextInput,
14-
CheckboxControl,
1515
} from '@woocommerce/blocks-components';
1616
import { useDispatch, useSelect } from '@wordpress/data';
1717
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';

assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/block.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import {
99
useEditorContext,
1010
noticeContexts,
1111
} from '@woocommerce/base-context';
12-
import {
13-
StoreNoticesContainer,
14-
CheckboxControl,
15-
} from '@woocommerce/blocks-components';
12+
import { CheckboxControl } from '@woocommerce/blocks-checkout';
13+
import { StoreNoticesContainer } from '@woocommerce/blocks-components';
1614
import Noninteractive from '@woocommerce/base-components/noninteractive';
1715
import type {
1816
BillingAddress,
Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,80 @@
1-
export { CheckboxControl } from '@woocommerce/blocks-components';
1+
/**
2+
* External dependencies
3+
*/
4+
import classNames from 'classnames';
5+
import { useInstanceId } from '@wordpress/compose';
6+
7+
/**
8+
* Internal dependencies
9+
*/
10+
import './style.scss';
11+
12+
export type CheckboxControlProps = {
13+
className?: string;
14+
label?: string | React.ReactNode;
15+
id?: string;
16+
onChange: ( value: boolean ) => void;
17+
children?: React.ReactChildren;
18+
hasError?: boolean;
19+
checked?: boolean;
20+
disabled?: boolean;
21+
};
22+
23+
/**
24+
* Component used to show a checkbox control with styles.
25+
*/
26+
export const CheckboxControl = ( {
27+
className,
28+
label,
29+
id,
30+
onChange,
31+
children,
32+
hasError = false,
33+
checked = false,
34+
disabled = false,
35+
...rest
36+
}: CheckboxControlProps ): JSX.Element => {
37+
const instanceId = useInstanceId( CheckboxControl );
38+
const checkboxId = id || `checkbox-control-${ instanceId }`;
39+
40+
return (
41+
<div
42+
className={ classNames(
43+
'wc-block-components-checkbox',
44+
{
45+
'has-error': hasError,
46+
},
47+
className
48+
) }
49+
>
50+
<label htmlFor={ checkboxId }>
51+
<input
52+
id={ checkboxId }
53+
className="wc-block-components-checkbox__input"
54+
type="checkbox"
55+
onChange={ ( event ) => onChange( event.target.checked ) }
56+
aria-invalid={ hasError === true }
57+
checked={ checked }
58+
disabled={ disabled }
59+
{ ...rest }
60+
/>
61+
<svg
62+
className="wc-block-components-checkbox__mark"
63+
aria-hidden="true"
64+
xmlns="http://www.w3.org/2000/svg"
65+
viewBox="0 0 24 20"
66+
>
67+
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
68+
</svg>
69+
{ label && (
70+
<span className="wc-block-components-checkbox__label">
71+
{ label }
72+
</span>
73+
) }
74+
{ children }
75+
</label>
76+
</div>
77+
);
78+
};
79+
80+
export default CheckboxControl;

0 commit comments

Comments
 (0)