Implement widget and fix some bugs

This commit is contained in:
inpsyde-maticluznar 2024-11-28 10:31:16 +01:00
parent 6225943c00
commit fac3dfcf84
No known key found for this signature in database
GPG key ID: D005973F231309F6
6 changed files with 306 additions and 215 deletions

View file

@ -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(