CheckboxControl: stop using Gutenberg's CheckboxControl (https://github.com/woocommerce/woocommerce-blocks/pull/2137)

* CheckboxControl: stop using Gutenberg's CheckboxControl

* Simplify styles and make them work fine in the editor
This commit is contained in:
Albert Juhé Lluveras 2020-04-07 17:37:03 +02:00 committed by GitHub
parent 8ae3e1d195
commit 5bcdc8f84a
4 changed files with 63 additions and 18 deletions

View File

@ -1,7 +1,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { CheckboxControl as WPCheckboxControl } from 'wordpress-components'; import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
@ -13,17 +13,38 @@ import './style.scss';
/** /**
* Component used to show a checkbox control with styles. * Component used to show a checkbox control with styles.
*/ */
const CheckboxControl = ( { className, ...props } ) => { const CheckboxControl = ( {
className,
label,
id,
instanceId,
onChange,
...rest
} ) => {
const checkboxId = id || `checkbox-control-${ instanceId }`;
return ( return (
<WPCheckboxControl <label
className={ classNames( 'wc-block-checkbox', className ) } className={ classNames( 'wc-block-checkbox', className ) }
{ ...props } 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>
); );
}; };
CheckboxControl.propTypes = { CheckboxControl.propTypes = {
className: PropTypes.string, className: PropTypes.string,
label: PropTypes.string,
id: PropTypes.string,
onChange: PropTypes.func,
}; };
export default CheckboxControl; export default withInstanceId( CheckboxControl );

View File

@ -1,13 +1,40 @@
.wc-block-checkbox { .wc-block-checkbox {
.components-checkbox-control__input[type="checkbox"]:checked { display: block;
position: relative;
.wc-block-checkbox__input[type="checkbox"] {
appearance: none;
border: 1px solid currentColor;
height: 1rem;
margin: 0;
min-height: 16px;
min-width: 16px;
overflow: hidden;
position: static;
vertical-align: middle;
width: 1rem;
&:checked {
background: currentColor; background: currentColor;
border-color: currentColor; border-color: currentColor;
&::before {
color: #fff;
content: "\2713";
display: block;
height: calc(1rem - 2px);
min-height: 14px;
min-width: 14px;
margin: 0;
line-height: 100%;
text-align: center;
width: calc(1rem - 2px);
} }
.components-checkbox-control__input[type="checkbox"]:focus {
border-color: currentColor;
box-shadow: 0 0 2px currentColor;
} }
.components-checkbox-control__label { }
display: inline;
.wc-block-checkbox__input[type="checkbox"] + .wc-block-checkbox__label {
padding-left: $gap-smaller;
vertical-align: middle;
} }
} }

View File

@ -240,7 +240,6 @@ const Checkout = ( {
onChange={ ( isChecked ) => onChange={ ( isChecked ) =>
setShippingAsBilling( isChecked ) setShippingAsBilling( isChecked )
} }
required={ attributes.requirePhoneField }
/> />
</FormStep> </FormStep>
) } ) }

View File

@ -108,8 +108,6 @@ const stableMainEntry = {
'panel-style': './node_modules/wordpress-components/src/panel/style.scss', 'panel-style': './node_modules/wordpress-components/src/panel/style.scss',
'custom-select-control-style': 'custom-select-control-style':
'./node_modules/wordpress-components/src/custom-select-control/style.scss', './node_modules/wordpress-components/src/custom-select-control/style.scss',
'checkbox-control-style':
'./node_modules/wordpress-components/src/checkbox-control/style.scss',
'spinner-style': 'spinner-style':
'./node_modules/wordpress-components/src/spinner/style.scss', './node_modules/wordpress-components/src/spinner/style.scss',
'snackbar-notice-style': 'snackbar-notice-style':