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

Commit

Permalink
Revert "import checkbox from single place (#12015)"
Browse files Browse the repository at this point in the history
This reverts commit d952f8e.
  • Loading branch information
wavvves committed Dec 4, 2023
1 parent d952f8e commit e2b370a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
noticeContexts,
} from '@woocommerce/base-context';
import { getSetting } from '@woocommerce/settings';
import { CheckboxControl } from '@woocommerce/blocks-checkout';
import {
StoreNoticesContainer,
ValidatedTextInput,
CheckboxControl,
} from '@woocommerce/blocks-components';
import { useDispatch, useSelect } from '@wordpress/data';
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import {
useEditorContext,
noticeContexts,
} from '@woocommerce/base-context';
import {
StoreNoticesContainer,
CheckboxControl,
} from '@woocommerce/blocks-components';
import { CheckboxControl } from '@woocommerce/blocks-checkout';
import { StoreNoticesContainer } from '@woocommerce/blocks-components';
import Noninteractive from '@woocommerce/base-components/noninteractive';
import type {
BillingAddress,
Expand Down
81 changes: 80 additions & 1 deletion packages/checkout/components/checkbox-control/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
export { CheckboxControl } from '@woocommerce/blocks-components';
/**
* External dependencies
*/
import classNames from 'classnames';
import { useInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
*/
import './style.scss';

export type CheckboxControlProps = {
className?: string;
label?: string | React.ReactNode;
id?: string;
onChange: ( value: boolean ) => void;
children?: React.ReactChildren;
hasError?: boolean;
checked?: boolean;
disabled?: boolean;
};

/**
* Component used to show a checkbox control with styles.
*/
export const CheckboxControl = ( {
className,
label,
id,
onChange,
children,
hasError = false,
checked = false,
disabled = false,
...rest
}: CheckboxControlProps ): JSX.Element => {
const instanceId = useInstanceId( CheckboxControl );
const checkboxId = id || `checkbox-control-${ instanceId }`;

return (
<div
className={ classNames(
'wc-block-components-checkbox',
{
'has-error': hasError,
},
className
) }
>
<label htmlFor={ checkboxId }>
<input
id={ checkboxId }
className="wc-block-components-checkbox__input"
type="checkbox"
onChange={ ( event ) => onChange( event.target.checked ) }
aria-invalid={ hasError === true }
checked={ checked }
disabled={ disabled }
{ ...rest }
/>
<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>
{ label && (
<span className="wc-block-components-checkbox__label">
{ label }
</span>
) }
{ children }
</label>
</div>
);
};

export default CheckboxControl;

0 comments on commit e2b370a

Please sign in to comment.