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 (
handleCheckboxState( checked, props )
}
/>
);
};
export const PayPalCheckboxGroup = ( props ) => {
const renderCheckboxGroup = () => {
return props.value.map( ( checkbox ) => {
return (
);
} );
};
return <>{ renderCheckboxGroup() }>;
};
export const PayPalRdb = ( props ) => {
return (
props.handleRdbState( props.value ) }
/>
);
};
export const PayPalRdbWithContent = ( props ) => {
const className = [ 'ppcp-r__radio-wrapper' ];
if ( props?.className ) {
className.push( props.className );
}
return (
{ props.description && (
) }
{ props?.toggleAdditionalContent &&
props.children &&
props.value === props.currentValue && (
{ props.children }
) }
);
};
export const handleCheckboxState = ( checked, props ) => {
let newValue = null;
if ( ! Array.isArray( props.currentValue ) ) {
newValue = checked;
} else if ( checked ) {
newValue = [ ...props.currentValue, props.value ];
} else {
newValue = props.currentValue.filter(
( value ) => value !== props.value
);
}
props.changeCallback( newValue );
};