mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Implement widget and fix some bugs
This commit is contained in:
parent
6225943c00
commit
fac3dfcf84
6 changed files with 306 additions and 215 deletions
|
@ -1,12 +1,20 @@
|
|||
import { CheckboxControl } from '@wordpress/components';
|
||||
|
||||
export const PayPalCheckbox = ( props ) => {
|
||||
let isChecked = null;
|
||||
|
||||
if ( Array.isArray( props.currentValue ) ) {
|
||||
isChecked = props.currentValue.includes( props.value );
|
||||
} else {
|
||||
isChecked = props.currentValue;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="ppcp-r__checkbox">
|
||||
<CheckboxControl
|
||||
label={ props?.label ? props.label : '' }
|
||||
value={ props.value }
|
||||
checked={ props.currentValue.includes( props.value ) }
|
||||
checked={ isChecked }
|
||||
onChange={ ( checked ) =>
|
||||
handleCheckboxState( checked, props )
|
||||
}
|
||||
|
@ -86,7 +94,9 @@ export const PayPalRdbWithContent = ( props ) => {
|
|||
|
||||
export const handleCheckboxState = ( checked, props ) => {
|
||||
let newValue = null;
|
||||
if ( checked ) {
|
||||
if ( ! Array.isArray( props.currentValue ) ) {
|
||||
newValue = checked;
|
||||
} else if ( checked ) {
|
||||
newValue = [ ...props.currentValue, props.value ];
|
||||
} else {
|
||||
newValue = props.currentValue.filter(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue