Set placement

This commit is contained in:
Alex P 2023-12-07 08:15:05 +02:00
parent c1376f927c
commit ee1e6538dc
No known key found for this signature in database
GPG key ID: 54487A734A204D71
4 changed files with 29 additions and 3 deletions

View file

@ -34,6 +34,10 @@
"flexRatio": {
"type": "string",
"default": "8x1"
},
"placement": {
"type": "string",
"default": "auto"
}
},
"supports": {

View file

@ -5,7 +5,7 @@ import { PanelBody, SelectControl, Spinner } from '@wordpress/components';
import { PayPalScriptProvider, PayPalMessages } from "@paypal/react-paypal-js";
export default function Edit( { attributes, clientId, setAttributes } ) {
const { layout, logo, position, color, flexColor, flexRatio, id } = attributes;
const { layout, logo, position, color, flexColor, flexRatio, placement, id } = attributes;
const isFlex = layout === 'flex';
const [loaded, setLoaded] = useState(false);
@ -99,6 +99,21 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
value={flexRatio}
onChange={(value) => setAttributes({flexRatio: value})}
/>)}
<SelectControl
label={ __( 'Placement page', 'woocommerce-paypal-payments' ) }
help={ __( 'Used for the analytics dashboard in the merchant account.', 'woocommerce-paypal-payments' ) }
options={ [
{ label: __( 'Detect automatically', 'woocommerce-paypal-payments' ), value: 'auto' },
{ label: __( 'Cart', 'woocommerce-paypal-payments' ), value: 'cart' },
{ label: __( 'Payment', 'woocommerce-paypal-payments' ), value: 'payment' },
{ label: __( 'Product', 'woocommerce-paypal-payments' ), value: 'product' },
{ label: __( 'Product list', 'woocommerce-paypal-payments' ), value: 'product-list' },
{ label: __( 'Home', 'woocommerce-paypal-payments' ), value: 'home' },
{ label: __( 'Category', 'woocommerce-paypal-payments' ), value: 'category' },
] }
value={ placement }
onChange={ ( value ) => setAttributes( { placement: value } ) }
/>
</PanelBody>
</InspectorControls>
<div {...useBlockProps({className: ['ppcp-paylater-block-preview', 'ppcp-overlay-parent']})}>

View file

@ -1,7 +1,7 @@
import { useBlockProps } from '@wordpress/block-editor';
export default function save( { attributes } ) {
const { layout, logo, position, color, flexColor, flexRatio, id } = attributes;
const { layout, logo, position, color, flexColor, flexRatio, placement, id } = attributes;
const paypalAttributes = layout === 'flex' ? {
'data-pp-style-layout': 'flex',
'data-pp-style-color': flexColor,
@ -12,6 +12,9 @@ export default function save( { attributes } ) {
'data-pp-style-logo-position': position,
'data-pp-style-text-color': color,
};
if (placement && placement !== 'auto') {
paypalAttributes['data-pp-placement'] = placement;
}
const props = {
className: 'ppcp-paylater-message-block',
id,