2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-08-14 10:02:58 +00:00
|
|
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
|
|
|
import {
|
|
|
|
PanelBody,
|
|
|
|
RadioControl,
|
|
|
|
ToggleControl,
|
|
|
|
Notice,
|
|
|
|
TextControl,
|
|
|
|
} from '@wordpress/components';
|
|
|
|
import ExternalLinkCard from '@woocommerce/editor-components/external-link-card';
|
|
|
|
import { ADMIN_URL } from '@woocommerce/settings';
|
2021-08-20 11:30:38 +00:00
|
|
|
import { useExpressPaymentMethods } from '@woocommerce/base-context/hooks';
|
2024-08-14 10:02:58 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block';
|
|
|
|
import './editor.scss';
|
2024-08-14 10:02:58 +00:00
|
|
|
import { ExpressCheckoutAttributes } from './types';
|
|
|
|
import { ExpressCheckoutContext } from './context';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
2021-08-16 10:20:27 +00:00
|
|
|
export const Edit = ( {
|
|
|
|
attributes,
|
2024-08-14 10:02:58 +00:00
|
|
|
setAttributes,
|
2021-08-16 10:20:27 +00:00
|
|
|
}: {
|
2024-08-14 10:02:58 +00:00
|
|
|
attributes: ExpressCheckoutAttributes;
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => undefined;
|
2021-08-20 11:30:38 +00:00
|
|
|
} ): JSX.Element | null => {
|
|
|
|
const { paymentMethods, isInitialized } = useExpressPaymentMethods();
|
|
|
|
const hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;
|
2021-09-24 13:44:05 +00:00
|
|
|
const blockProps = useBlockProps( {
|
2024-05-31 03:49:36 +00:00
|
|
|
className: clsx(
|
2021-10-20 16:18:13 +00:00
|
|
|
{
|
2022-06-15 09:56:52 +00:00
|
|
|
'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods':
|
|
|
|
hasExpressPaymentMethods,
|
2021-10-20 16:18:13 +00:00
|
|
|
},
|
|
|
|
attributes?.className
|
|
|
|
),
|
2021-08-20 11:30:38 +00:00
|
|
|
attributes,
|
|
|
|
} );
|
|
|
|
|
2023-04-06 11:16:42 +00:00
|
|
|
if ( ! isInitialized || ! hasExpressPaymentMethods ) {
|
2021-08-20 11:30:38 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-07-22 11:03:00 +00:00
|
|
|
|
2024-08-14 10:02:58 +00:00
|
|
|
const { buttonHeight, buttonBorderRadius, showButtonStyles } = attributes;
|
|
|
|
|
|
|
|
const buttonStyleControls = (
|
|
|
|
<>
|
|
|
|
<RadioControl
|
|
|
|
label={ __( 'Button Size', 'woocommerce' ) }
|
|
|
|
selected={ buttonHeight }
|
|
|
|
options={ [
|
|
|
|
{ label: 'Small (40px)', value: '40' },
|
|
|
|
{ label: 'Medium (48px)', value: '48' },
|
|
|
|
{ label: 'Large (55px)', value: '55' },
|
|
|
|
] }
|
|
|
|
onChange={ ( newValue: string ) =>
|
|
|
|
setAttributes( { buttonHeight: newValue } )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<div className="border-radius-control-container">
|
|
|
|
<TextControl
|
|
|
|
label={ __( 'Button Border Radius', 'woocommerce' ) }
|
|
|
|
value={ buttonBorderRadius }
|
|
|
|
onChange={ ( newValue: string ) =>
|
|
|
|
setAttributes( {
|
|
|
|
buttonBorderRadius: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<span className="border-radius-control-px">px</span>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const showControls = () => {
|
|
|
|
if ( showButtonStyles ) {
|
|
|
|
return buttonStyleControls;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Notice
|
|
|
|
status="info"
|
|
|
|
isDismissible={ false }
|
|
|
|
className="show-button-styles-notice"
|
|
|
|
>
|
|
|
|
<p className="wc-block-checkout__controls-text">
|
|
|
|
{ __(
|
|
|
|
'You can change the appearance of individual buttons in the respective payment extension settings page',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<ExternalLinkCard
|
|
|
|
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout` }
|
|
|
|
title="Payment Settings"
|
|
|
|
/>
|
|
|
|
</Notice>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
return (
|
|
|
|
<div { ...blockProps }>
|
2024-08-14 10:02:58 +00:00
|
|
|
<InspectorControls>
|
|
|
|
<PanelBody title={ __( 'Button Settings', 'woocommerce' ) }>
|
|
|
|
<p className="wc-block-checkout__controls-text">
|
|
|
|
{ __(
|
|
|
|
'These settings will override the plugin specific styles for these buttons',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Express Button Styles', 'woocommerce' ) }
|
|
|
|
checked={ showButtonStyles }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showButtonStyles: ! showButtonStyles,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ showControls() }
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
|
|
|
<ExpressCheckoutContext.Provider
|
|
|
|
value={ { showButtonStyles, buttonHeight, buttonBorderRadius } }
|
|
|
|
>
|
|
|
|
<Block />
|
|
|
|
</ExpressCheckoutContext.Provider>
|
2021-07-22 11:03:00 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return <div { ...useBlockProps.save() } />;
|
|
|
|
};
|