-
-
+const PREVIEW_CLIENT_ID = 'test';
+const PREVIEW_MERCHANT_ID = 'QTQX5NP6N9WZU';
+
+const PreviewPanel = () => {
+ // TODO: Make those props dynamic based on location style settings.
+ const style = {};
+ const components = [ 'buttons', 'googlepay' ];
+
+ const providerOptions = {
+ clientId: PREVIEW_CLIENT_ID,
+ merchantId: PREVIEW_MERCHANT_ID,
+ components: components.join( ',' ),
+ 'disable-funding': 'card',
+ 'buyer-country': 'US',
+ currency: 'USD',
+ };
+
+ return (
+
-
-);
+ );
+};
export default PreviewPanel;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
index d6571a4c5..e739ab629 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
@@ -1,54 +1,28 @@
import { __ } from '@wordpress/i18n';
-import { useState } from '@wordpress/element';
import { RadioControl, SelectControl } from '@wordpress/components';
-import { STYLING_LOCATIONS } from '../../../../../data';
+// Dummy hook.
+import { useStylingLocation, useStylingProps } from '../../Tabs/TabStyling';
+
import { PayPalCheckboxGroup } from '../../../../ReusableComponents/Fields';
import LocationSelector from './LocationSelector';
import StylingSection from './StylingSection';
const SettingsPanel = () => {
- const { location, setLocation } = useState( 'cart' );
-
- const currentLocationSettings = {
- settings: { shape: '', label: '', color: '' },
- };
- const handleChange = () => {};
+ const { location, setLocation } = useStylingLocation();
return (
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
);
};
@@ -56,129 +30,115 @@ const SettingsPanel = () => {
export default SettingsPanel;
// -----
-const SectionPaymentMethods = ( {
- locationSettings,
- updateButtonSettings,
-} ) => {
- const paymentMethodOptions = [];
+const SectionPaymentMethods = ( { location } ) => {
+ const { paymentMethods, setPaymentMethods, paymentMethodChoices } =
+ useStylingProps( location );
return (
-
-
- updateButtonSettings( 'paymentMethods', newValue )
- }
- currentValue={ locationSettings.paymentMethods }
- />
-
+
);
};
-const SectionButtonLayout = ( { locationSettings, updateButtonStyle } ) => {
- const buttonLayoutIsAllowed =
- locationSettings.layout && locationSettings.tagline === false;
- return (
- buttonLayoutIsAllowed && (
-
-
- updateButtonStyle( 'layout', newValue )
- }
- selected={ locationSettings.layout }
- options={ [] }
- />
-
- )
- );
-};
+const SectionButtonLayout = ( { location } ) => {
+ const { supportsLayout, layout, setLayout, layoutChoices } =
+ useStylingProps( location );
+
+ if ( ! supportsLayout ) {
+ return null;
+ }
-const SectionButtonShape = ( { locationSettings, updateButtonStyle } ) => {
return (
- updateButtonStyle( 'shape', newValue )
- }
- selected={ locationSettings.shape }
- options={ [] }
+ options={ layoutChoices }
+ selected={ layout }
+ onChange={ setLayout }
/>
);
};
-const SectionButtonLabel = ( { locationSettings, updateButtonStyle } ) => {
+const SectionButtonShape = ( { location } ) => {
+ const { shape, setShape, shapeChoices } = useStylingProps( location );
+
+ return (
+
+
+
+ );
+};
+
+const SectionButtonLabel = ( { location } ) => {
+ const { label, setLabel, labelChoices } = useStylingProps( location );
+
return (
- updateButtonStyle( 'label', newValue )
- }
- value={ locationSettings.label }
label={ __( 'Button Label', 'woocommerce-paypal-payments' ) }
- options={ [] }
+ className="ppcp-r-styling__select"
+ options={ labelChoices }
+ value={ label }
+ onChange={ setLabel }
/>
);
};
-const SectionButtonColor = ( { locationSettings, updateButtonStyle } ) => {
+const SectionButtonColor = ( { location } ) => {
+ const { color, setColor, colorChoices } = useStylingProps( location );
+
return (
- updateButtonStyle( 'color', newValue )
- }
- value={ locationSettings.color }
- options={ [] }
+ className=" ppcp-r-styling__select"
+ options={ colorChoices }
+ value={ color }
+ onChange={ setColor }
/>
);
};
-const SectionButtonTagline = ( { locationSettings, updateButtonStyle } ) => {
- const taglineIsAllowed =
- locationSettings.hasOwnProperty( 'tagline' ) &&
- locationSettings.layout === 'horizontal';
+const SectionButtonTagline = ( { location } ) => {
+ const { supportsTagline, tagline, setTagline, taglineChoices } =
+ useStylingProps( location );
+
+ if ( ! supportsTagline ) {
+ return null;
+ }
return (
- taglineIsAllowed && (
-
- {
- updateButtonStyle( 'tagline', newValue );
- } }
- currentValue={ locationSettings.tagline }
- />
-
- )
+
+
+
);
};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
index 4a0b8f015..07f5ad4d9 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
@@ -1,22 +1,113 @@
-import { useState } from '@wordpress/element';
+import { __ } from '@wordpress/i18n';
+import { useCallback, useState } from '@wordpress/element';
-import { defaultLocationSettings } from '../../../../data/settings/tab-styling-data';
+import {
+ STYLING_COLORS,
+ STYLING_LABELS,
+ STYLING_LAYOUTS,
+ STYLING_LOCATIONS,
+ STYLING_PAYMENT_METHODS,
+ STYLING_SHAPES,
+} from '../../../../data/styling/constants';
import PreviewPanel from '../Components/Styling/PreviewPanel';
import SettingsPanel from '../Components/Styling/SettingsPanel';
-const TabStyling = () => {
- const [ locationSettings, setLocationSettings ] = useState( {
- ...defaultLocationSettings,
- } );
-
- return (
-
- );
-};
+const TabStyling = () => (
+
+);
export default TabStyling;
+
+// ----------------------------------------------------------------------------
+
+// Temporary "hook" to extract logic before moving it to the Redux store.
+export const useStylingLocation = () => {
+ const [ location, setLocation ] = useState( 'cart' );
+
+ return { location, setLocation };
+};
+
+export const useStylingProps = ( location ) => {
+ const defaultStyle = {
+ paymentMethods: [],
+ color: 'gold',
+ shape: 'rect',
+ label: 'paypal',
+ layout: 'vertical',
+ tagline: false,
+ };
+
+ const [ styles, setStyles ] = useState( {
+ cart: { ...defaultStyle, label: 'checkout' },
+ 'classic-checkout': { ...defaultStyle },
+ 'express-checkout': { ...defaultStyle, label: 'pay' },
+ 'mini-cart': { ...defaultStyle, label: 'pay' },
+ 'product-page': { ...defaultStyle },
+ } );
+
+ const getLocationStyle = useCallback(
+ ( prop ) => styles[ location ]?.[ prop ],
+ [ location, styles ]
+ );
+
+ const setLocationStyle = useCallback(
+ ( prop, value ) => {
+ setStyles( ( prevState ) => ( {
+ ...prevState,
+ [ location ]: {
+ ...prevState[ location ],
+ [ prop ]: value,
+ },
+ } ) );
+ },
+ [ location ]
+ );
+
+ return {
+ // Location (drop down).
+ locationChoices: Object.values( STYLING_LOCATIONS ),
+ locationDetails: STYLING_LOCATIONS[ location ],
+
+ // Payment methods (checkboxes).
+ paymentMethodChoices: Object.values( STYLING_PAYMENT_METHODS ),
+ paymentMethods: getLocationStyle( 'paymentMethods' ),
+ setPaymentMethods: ( methods ) =>
+ setLocationStyle( 'paymentMethods', methods ),
+
+ // Color (dropdown).
+ colorChoices: Object.values( STYLING_COLORS ),
+ color: getLocationStyle( 'color' ),
+ setColor: ( color ) => setLocationStyle( 'color', color ),
+
+ // Shape (radio).
+ shapeChoices: Object.values( STYLING_SHAPES ),
+ shape: getLocationStyle( 'shape' ),
+ setShape: ( shape ) => setLocationStyle( 'shape', shape ),
+
+ // Label (dropdown).
+ labelChoices: Object.values( STYLING_LABELS ),
+ label: getLocationStyle( 'label' ),
+ setLabel: ( label ) => setLocationStyle( 'label', label ),
+
+ // Layout (radio).
+ layoutChoices: Object.values( STYLING_LAYOUTS ),
+ supportsLayout: true,
+ layout: getLocationStyle( 'layout' ),
+ setLayout: ( layout ) => setLocationStyle( 'layout', layout ),
+
+ // Tagline (checkbox).
+ taglineChoices: [
+ {
+ value: 'tagline',
+ label: __( 'Enable Tagline', 'woocommerce-paypal-payments' ),
+ },
+ ],
+ supportsTagline: true,
+ tagline: getLocationStyle( 'tagline' ),
+ setTagline: ( tagline ) => setLocationStyle( 'tagline', tagline ),
+ };
+};
diff --git a/modules/ppcp-settings/resources/js/data/settings/tab-styling-data.js b/modules/ppcp-settings/resources/js/data/settings/tab-styling-data.js
deleted file mode 100644
index ae0636481..000000000
--- a/modules/ppcp-settings/resources/js/data/settings/tab-styling-data.js
+++ /dev/null
@@ -1,98 +0,0 @@
-import { __ } from '@wordpress/i18n';
-
-const cartAndExpressCheckoutSettings = {
- paymentMethods: [],
- style: {
- shape: 'pill',
- label: 'paypal',
- color: 'gold',
- },
-};
-
-const settings = {
- paymentMethods: [],
- style: {
- layout: 'vertical',
- shape: cartAndExpressCheckoutSettings.style.shape,
- label: cartAndExpressCheckoutSettings.style.label,
- color: cartAndExpressCheckoutSettings.style.color,
- tagline: false,
- },
-};
-
-export const defaultLocationSettings = {
- cart: {
- value: 'cart',
- label: __( 'Cart', 'woocommerce-paypal-payments' ),
- settings: { ...cartAndExpressCheckoutSettings },
- // translators: %s: Link to Cart page
- description: __(
- 'Customize the appearance of the PayPal smart buttons on the
[MISSING LINK]Cart page and select which additional payment buttons to display in this location.',
- 'wooocommerce-paypal-payments'
- ),
- descriptionLink: '#',
- },
- 'classic-checkout': {
- value: 'classic-checkout',
- label: __( 'Classic Checkout', 'woocommerce-paypal-payments' ),
- settings: { ...settings },
- // translators: %s: Link to Classic Checkout page
- description: __(
- 'Customize the appearance of the PayPal smart buttons on the
[MISSING LINK]Classic Checkout page and choose which additional payment buttons to display in this location.',
- 'wooocommerce-paypal-payments'
- ),
- descriptionLink: '#',
- },
- 'express-checkout': {
- value: 'express-checkout',
- label: __( 'Express Checkout', 'woocommerce-paypal-payments' ),
- settings: { ...cartAndExpressCheckoutSettings },
- // translators: %s: Link to Express Checkout location
- description: __(
- 'Customize the appearance of the PayPal smart buttons on the
[MISSING LINK]Express Checkout location and choose which additional payment buttons to display in this location.',
- 'wooocommerce-paypal-payments'
- ),
- descriptionLink: '#',
- },
- 'mini-cart': {
- value: 'mini-cart',
- label: __( 'Mini Cart', 'woocommerce-paypel-payements' ),
- settings: { ...settings },
- // translators: %s: Link to Mini Cart
- description: __(
- 'Customize the appearance of the PayPal smart buttons on the
[MISSING LINK]Mini Cart and choose which additional payment buttons to display in this location.',
- 'wooocommerce-paypal-payments'
- ),
- descriptionLink: '#',
- },
- 'product-page': {
- value: 'product-page',
- label: __( 'Product Page', 'woocommerce-paypal-payments' ),
- settings: { ...settings },
- // translators: %s: Link to Product Page
- description: __(
- 'Customize the appearance of the PayPal smart buttons on the
[MISSING LINK]Product Page and choose which additional payment buttons to display in this location.',
- 'wooocommerce-paypal-payments'
- ),
- descriptionLink: '#',
- },
-};
-
-export const paymentMethodOptions = [
- {
- value: 'venmo',
- label: __( 'Venmo', 'woocommerce-paypal-payments' ),
- },
- {
- value: 'paylater',
- label: __( 'Pay Later', 'woocommerce-paypal-payments' ),
- },
- {
- value: 'googlepay',
- label: __( 'Google Pay', 'woocommerce-paypal-payments' ),
- },
- {
- value: 'applepay',
- label: __( 'Apple Pay', 'woocommerce-paypal-payments' ),
- },
-];
diff --git a/modules/ppcp-settings/resources/js/data/styling/constants.js b/modules/ppcp-settings/resources/js/data/styling/constants.js
index 92d3714da..395d80cdb 100644
--- a/modules/ppcp-settings/resources/js/data/styling/constants.js
+++ b/modules/ppcp-settings/resources/js/data/styling/constants.js
@@ -145,3 +145,22 @@ export const STYLING_SHAPES = {
label: __( 'Rectangle', 'woocommerce-paypal-payments' ),
},
};
+
+export const STYLING_PAYMENT_METHODS = {
+ venmo: {
+ value: 'venmo',
+ label: __( 'Venmo', 'woocommerce-paypal-payments' ),
+ },
+ paylater: {
+ value: 'paylater',
+ label: __( 'Pay Later', 'woocommerce-paypal-payments' ),
+ },
+ googlepay: {
+ value: 'googlepay',
+ label: __( 'Google Pay', 'woocommerce-paypal-payments' ),
+ },
+ applepay: {
+ value: 'applepay',
+ label: __( 'Apple Pay', 'woocommerce-paypal-payments' ),
+ },
+};
From 85794e77ce2a492cdd3b926df8d8ff5fd8ea6211 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 15 Jan 2025 19:41:46 +0100
Subject: [PATCH 10/66] =?UTF-8?q?=F0=9F=92=84=20Improve=20the=20(broken)?=
=?UTF-8?q?=20UI=20in=20the=20Styling-tab?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/css/components/_reusable.scss | 1 +
.../reusable-components/_hstack.scss | 20 +++
.../screens/settings/_tab-styling.scss | 51 ++----
.../Components/ReusableComponents/Fields.js | 161 +++++++++++-------
.../Components/ReusableComponents/HStack.js | 26 +++
.../Components/Styling/SettingsPanel.js | 68 ++++----
.../resources/js/data/styling/constants.js | 6 +
7 files changed, 198 insertions(+), 135 deletions(-)
create mode 100644 modules/ppcp-settings/resources/css/components/reusable-components/_hstack.scss
create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/HStack.js
diff --git a/modules/ppcp-settings/resources/css/components/_reusable.scss b/modules/ppcp-settings/resources/css/components/_reusable.scss
index 4d4f5c1ba..2de887f57 100644
--- a/modules/ppcp-settings/resources/css/components/_reusable.scss
+++ b/modules/ppcp-settings/resources/css/components/_reusable.scss
@@ -4,6 +4,7 @@
@import './reusable-components/busy-state';
@import './reusable-components/button';
@import './reusable-components/fields';
+@import './reusable-components/hstack';
@import './reusable-components/navigation';
@import './reusable-components/onboarding-header';
@import './reusable-components/payment-method-icons';
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_hstack.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_hstack.scss
new file mode 100644
index 000000000..e55584d1c
--- /dev/null
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_hstack.scss
@@ -0,0 +1,20 @@
+.components-flex {
+ display: flex;
+ -webkit-box-align: stretch;
+ align-items: stretch;
+ flex-direction: column;
+ -webkit-box-pack: center;
+ justify-content: center;
+
+ .components-h-stack {
+ flex-direction: row;
+ justify-content: flex-start;
+ gap: 32px;
+ }
+
+ // Fix layout for checkboxes inside a flex-stack.
+ .components-checkbox-control >.components-base-control__field > .components-flex {
+ flex-direction: row;
+ gap: 12px;
+ }
+}
diff --git a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
index 87472e377..61534cc04 100644
--- a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
@@ -27,6 +27,16 @@ $width-settings-panel: 422px;
padding-bottom: 24px;
margin-bottom: 28px;
border-bottom: 1px solid var(--color-separators);
+
+ &:last-child {
+ padding-bottom: 0;
+ margin-bottom: 0;
+ border-bottom-style: none;
+ }
+ }
+
+ .components-radio-control__option {
+ min-width: 100px;
}
}
@@ -65,46 +75,7 @@ $width-settings-panel: 422px;
color: $color-black;
}
}
-
- .components-flex {
- gap: 12px;
- }
- }
-
- &__payment-method-checkboxes {
- display: flex;
- flex-direction: column;
- gap: 24px;
}
}
-
-.ppcp-r {
- &__horizontal-control {
- .components-flex {
- flex-direction: row;
- justify-content: flex-start;
- gap: 32px;
- }
-
-
- .components-radio-control {
- &__option {
- gap: 12px;
-
- input {
- margin: 0;
- }
-
- label {
- @include font(13, 20, 400);
- color: $color-black;
- }
- }
-
- input {
- margin: 0;
- }
- }
- }
- // */
+//*/
}
diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js
index 74336951f..862e057bb 100644
--- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js
+++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js
@@ -1,107 +1,136 @@
import { CheckboxControl } from '@wordpress/components';
+import classNames from 'classnames';
-export const PayPalCheckbox = ( props ) => {
- let isChecked = null;
+export const PayPalCheckbox = ( {
+ currentValue,
+ label,
+ value,
+ checked = null,
+ disabled = null,
+ changeCallback,
+} ) => {
+ let isChecked = checked;
- if ( Array.isArray( props.currentValue ) ) {
- isChecked = props.currentValue.includes( props.value );
- } else {
- isChecked = props.currentValue;
+ if ( null === isChecked ) {
+ if ( Array.isArray( currentValue ) ) {
+ isChecked = currentValue.includes( value );
+ } else {
+ isChecked = currentValue;
+ }
}
+ const onChange = ( newState ) => {
+ let newValue;
+
+ if ( ! Array.isArray( currentValue ) ) {
+ newValue = newState;
+ } else if ( newState ) {
+ newValue = [ ...currentValue, value ];
+ } else {
+ newValue = currentValue.filter(
+ ( optionValue ) => optionValue !== value
+ );
+ }
+
+ changeCallback( newValue );
+ };
+
return (
+ { /* todo: Can we remove the wrapper div? */ }
- handleCheckboxState( checked, props )
- }
+ disabled={ disabled }
+ onChange={ onChange }
/>
);
};
-export const PayPalCheckboxGroup = ( props ) => {
- const renderCheckboxGroup = () => {
- return props.value.map( ( checkbox ) => {
- return (
-
- );
- } );
- };
+export const CheckboxGroup = ( { options, value, onChange } ) => (
+ <>
+ { options.map( ( checkbox ) => (
+
+ ) ) }
+ >
+);
- return <>{ renderCheckboxGroup() }>;
-};
-
-export const PayPalRdb = ( props ) => {
+export const PayPalRdb = ( {
+ id,
+ name,
+ value,
+ currentValue,
+ handleRdbState,
+} ) => {
return (
+ { /* todo: Can we remove the wrapper div? */ }
props.handleRdbState( props.value ) }
+ id={ id }
+ checked={ value === currentValue }
+ name={ name }
+ value={ value }
+ onChange={ () => handleRdbState( value ) }
/>
);
};
-export const PayPalRdbWithContent = ( props ) => {
- const className = [ 'ppcp-r__radio-wrapper' ];
-
- if ( props?.className ) {
- className.push( props.className );
- }
+export const PayPalRdbWithContent = ( {
+ className,
+ id,
+ name,
+ label,
+ description,
+ value,
+ currentValue,
+ handleRdbState,
+ toggleAdditionalContent,
+ children,
+} ) => {
+ const wrapperClasses = classNames( 'ppcp-r__radio-wrapper', className );
return (
-
-
+
+
+
-
- { props.description && (
+
+ { description && (
) }
- { props?.toggleAdditionalContent &&
- props.children &&
- props.value === props.currentValue && (
-
- { props.children }
-
- ) }
+ { toggleAdditionalContent && children && value === currentValue && (
+
+ { 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 );
-};
diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/HStack.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/HStack.js
new file mode 100644
index 000000000..2c54ac7da
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/HStack.js
@@ -0,0 +1,26 @@
+/**
+ * Temporary component, until the experimental HStack block editor component is stable.
+ *
+ * @see https://wordpress.github.io/gutenberg/?path=/docs/components-experimental-hstack--docs
+ * @file
+ */
+import classNames from 'classnames';
+
+const HStack = ( { className, spacing = 3, children } ) => {
+ const wrapperClass = classNames(
+ 'components-flex components-h-stack',
+ className
+ );
+
+ const styles = {
+ gap: `calc(${ 4 * spacing }px)`,
+ };
+
+ return (
+
+ { children }
+
+ );
+};
+
+export default HStack;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
index e739ab629..f357bb287 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
@@ -4,7 +4,8 @@ import { RadioControl, SelectControl } from '@wordpress/components';
// Dummy hook.
import { useStylingLocation, useStylingProps } from '../../Tabs/TabStyling';
-import { PayPalCheckboxGroup } from '../../../../ReusableComponents/Fields';
+import { CheckboxGroup } from '../../../../ReusableComponents/Fields';
+import HStack from '../../../../ReusableComponents/HStack';
import LocationSelector from './LocationSelector';
import StylingSection from './StylingSection';
@@ -30,6 +31,7 @@ const SettingsPanel = () => {
export default SettingsPanel;
// -----
+
const SectionPaymentMethods = ( { location } ) => {
const { paymentMethods, setPaymentMethods, paymentMethodChoices } =
useStylingProps( location );
@@ -39,11 +41,13 @@ const SectionPaymentMethods = ( { location } ) => {
title={ __( 'Payment Methods', 'woocommerce-paypal-payments' ) }
className="payment-methods"
>
-
+
+
+
);
};
@@ -61,12 +65,13 @@ const SectionButtonLayout = ( { location } ) => {
className="button-layout"
title={ __( 'Button Layout', 'woocommerce-paypal-payments' ) }
>
-
+
+
+
);
};
@@ -79,12 +84,13 @@ const SectionButtonShape = ( { location } ) => {
title={ __( 'Shape', 'woocommerce-paypal-payments' ) }
className="button-shape"
>
-
+
+
+
);
};
@@ -93,10 +99,11 @@ const SectionButtonLabel = ( { location } ) => {
const { label, setLabel, labelChoices } = useStylingProps( location );
return (
-
+
{
const { color, setColor, colorChoices } = useStylingProps( location );
return (
-
+
{
title={ __( 'Tagline', 'woocommerce-paypal-payments' ) }
className="tagline"
>
-
+
+
+
);
};
diff --git a/modules/ppcp-settings/resources/js/data/styling/constants.js b/modules/ppcp-settings/resources/js/data/styling/constants.js
index 395d80cdb..f21ac7adf 100644
--- a/modules/ppcp-settings/resources/js/data/styling/constants.js
+++ b/modules/ppcp-settings/resources/js/data/styling/constants.js
@@ -147,6 +147,12 @@ export const STYLING_SHAPES = {
};
export const STYLING_PAYMENT_METHODS = {
+ paypal: {
+ value: '',
+ label: __( 'PayPal', 'woocommerce-paypal-payments' ),
+ checked: true,
+ disabled: true,
+ },
venmo: {
value: 'venmo',
label: __( 'Venmo', 'woocommerce-paypal-payments' ),
From 1cac69ce990c35c730496413209b10e07f06ccd1 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 14:37:44 +0100
Subject: [PATCH 11/66] =?UTF-8?q?=E2=9C=A8=20Make=20some=20generic=20UI=20?=
=?UTF-8?q?components=20themeable?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ppcp-settings/resources/css/_mixins.scss | 11 ++
.../reusable-components/_fields.scss | 186 +++++++++---------
.../reusable-components/_settings-block.scss | 19 +-
.../Components/ReusableComponents/Fields.js | 22 ++-
.../SettingsBlocks/SettingsBlockElements.js | 47 +++--
5 files changed, 169 insertions(+), 116 deletions(-)
diff --git a/modules/ppcp-settings/resources/css/_mixins.scss b/modules/ppcp-settings/resources/css/_mixins.scss
index d2fac6cd2..29cb3af1c 100644
--- a/modules/ppcp-settings/resources/css/_mixins.scss
+++ b/modules/ppcp-settings/resources/css/_mixins.scss
@@ -43,3 +43,14 @@
display: flex;
gap: $gap;
}
+
+@mixin disabled-state($control-type) {
+ .components-#{$control-type}-control.is-disabled {
+ .components-#{$control-type}-control__input,
+ .components-#{$control-type}-control__label,
+ .components-base-control__help {
+ opacity: 0.5;
+ cursor: default;
+ }
+ }
+}
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss
index 1a9cf102c..195367dfb 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss
@@ -1,27 +1,96 @@
-.ppcp-r {
+.ppcp-r__radio-value {
+ @include hide-input-field;
- &__radio-value {
- @include hide-input-field;
+ &:checked + .ppcp-r__radio-presentation {
+ position: relative;
- &:checked + .ppcp-r__radio-presentation {
- position: relative;
+ &::before {
+ content: '';
+ width: 12px;
+ height: 12px;
+ border-radius: 12px;
+ background-color: $color-blueberry;
+ display: block;
+ position: absolute;
+ transform: translate(-50%, -50%);
+ left: 50%;
+ top: 50%;
+ }
+ }
+}
- &::before {
- content: '';
- width: 12px;
- height: 12px;
- border-radius: 12px;
- background-color: $color-blueberry;
- display: block;
- position: absolute;
- transform: translate(-50%, -50%);
- left: 50%;
- top: 50%;
- }
+.ppcp-r__radio-presentation {
+ @include fake-input-field(20px);
+}
+
+.ppcp-r__checkbox-presentation {
+ @include fake-input-field(2px);
+}
+
+.ppcp-r__radio-wrapper {
+ display: flex;
+ gap: 18px;
+ align-items: center;
+ position: relative;
+
+ label {
+ @include font(13, 20, 400);
+ color: $color-gray-800;
+ }
+}
+
+.ppcp-r__radio-description {
+ @include font(13, 20, 400);
+ margin: 0;
+ color: $color-gray-800;
+}
+
+.ppcp-r__radio-content-additional {
+ padding-left: 38px;
+ padding-top: 18px;
+}
+
+
+.ppcp-r-app {
+ @include disabled-state('base');
+ @include disabled-state('checkbox');
+
+ .components-base-control__label {
+ @include font(13, 16, 600);
+ color: $color-gray-900;
+ text-transform: none;
+ }
+
+ .components-base-control__input {
+ border: 1px solid $color-gray-700;
+ border-radius: 2px;
+ box-shadow: none;
+
+ &:focus {
+ border-color: $color-blueberry;
}
}
- &__checkbox {
+ .components-base-control__help {
+ margin-bottom: 0;
+ }
+
+ // Text input fields.
+ input[type='text'] {
+ @include font(14, 20, 400);
+ @include primaryFont;
+ padding: 7px 11px;
+ border-radius: 2px;
+ }
+
+ // Select lists.
+ select {
+ @include font(14, 20, 400);
+ padding: 7px 27px 7px 11px;
+ }
+
+ // Checkboxes.
+ .components-checkbox-control {
position: relative;
input {
@@ -30,7 +99,7 @@
&:checked {
background-color: $color-blueberry;
- border-color:$color-blueberry;
+ border-color: $color-blueberry;
}
}
@@ -43,78 +112,17 @@
}
}
- &__radio-presentation {
- @include fake-input-field(20px);
+ // Custom styles.
+ .components-form-toggle.is-checked > .components-form-toggle__track {
+ background-color: $color-blueberry;
}
- &__checkbox-presentation {
- @include fake-input-field(2px);
- }
-
- &__radio-wrapper {
- display: flex;
- gap: 18px;
- align-items: center;
- position: relative;
-
- label {
- @include font(13, 20, 400);
- color: $color-gray-800;
- }
- }
-
- &__radio-description {
- @include font(13, 20, 400);
- margin: 0;
- color: $color-gray-800;
- }
-
- &__radio-content-additional {
- padding-left: 38px;
- padding-top: 18px;
- }
-}
-
-.components-base-control {
- &__label {
- color: $color-gray-900;
- @include font(13, 16, 600);
- text-transform: none;
- }
-
- &__input {
- border: 1px solid $color-gray-700;
- border-radius: 2px;
- box-shadow: none;
-
- &:focus {
- border-color: $color-blueberry;
+ .ppcp-r-vertical-text-control {
+ .components-base-control__field {
+ display: flex;
+ flex-direction: column;
+ gap: 0;
+ margin: 0;
}
}
}
-
-
-input[type='text'] {
- padding: 7px 11px;
- @include font(14, 20, 400);
- @include primaryFont;
- border-radius: 2px;
-}
-
-select {
- padding: 7px 27px 7px 11px;
- @include font(14, 20, 400);
-}
-
-.components-form-toggle.is-checked > .components-form-toggle__track {
- background-color: $color-blueberry;
-}
-
-.ppcp-r-vertical-text-control {
- .components-base-control__field {
- display: flex;
- flex-direction: column;
- gap: 0;
- margin: 0;
- }
-}
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss
index f65c5c9d5..f5ddb5ea1 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss
@@ -4,7 +4,7 @@
.ppcp-r-settings-block {
display: flex;
flex-direction: column;
- gap: 16px 0;
+ gap: var(--block-item-gap, 16px) 0;
&.ppcp-r-settings-block__input,
&.ppcp-r-settings-block__select {
@@ -16,8 +16,8 @@
flex-direction: column;
gap: 6px;
- &:not(:last-child):not(.ppcp-r-settings-block--accordion__header) {
- padding-bottom: 6px;
+ &:not(:last-child) {
+ padding-bottom: var(--block-header-gap, 6px);
}
}
@@ -27,6 +27,15 @@
display: block;
text-transform: uppercase;
+ &.style-alt {
+ @include font(14, 16, 600);
+ text-transform: none;
+ }
+
+ &.style-big {
+ @include font(16, 20, 600);
+ }
+
.ppcp-r-title-badge {
text-transform: none;
margin-left: 6px;
@@ -89,8 +98,8 @@
}
+ .ppcp-r-settings-block:not(.no-gap) {
- margin-top: 32px;
- padding-top: 32px;
+ margin-top: var(--block-separator-gap, 32px);
+ padding-top: var(--block-separator-gap, 32px);
border-top: 1px solid var(--color-gray-200);
}
diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js
index 862e057bb..d979cffba 100644
--- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js
+++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Fields.js
@@ -19,6 +19,8 @@ export const PayPalCheckbox = ( {
}
}
+ const className = classNames( { 'is-disabled': disabled } );
+
const onChange = ( newState ) => {
let newValue;
@@ -36,16 +38,14 @@ export const PayPalCheckbox = ( {
};
return (
-
- { /* todo: Can we remove the wrapper div? */ }
-
-
+
);
};
@@ -58,6 +58,8 @@ export const CheckboxGroup = ( { options, value, onChange } ) => (
value={ checkbox.value }
checked={ checkbox.checked }
disabled={ checkbox.disabled }
+ description={ checkbox.description }
+ tooltip={ checkbox.tooltip }
currentValue={ value }
changeCallback={ onChange }
/>
diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlockElements.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlockElements.js
index ec3ba31ae..de45a601b 100644
--- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlockElements.js
+++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlockElements.js
@@ -1,9 +1,20 @@
+import classNames from 'classnames';
+
// Block Elements
-export const Title = ( { children, className = '' } ) => (
-
- { children }
-
-);
+export const Title = ( {
+ children,
+ altStyle = false,
+ big = false,
+ className = '',
+} ) => {
+ className = classNames( 'ppcp-r-settings-block__title', className, {
+ 'style-alt': altStyle,
+ 'style-big': big,
+ } );
+
+ return { children };
+};
+
export const TitleWrapper = ( { children } ) => (
{ children }
);
@@ -14,13 +25,25 @@ export const SupplementaryLabel = ( { children } ) => (
);
-export const Description = ( { children, className = '' } ) => (
-
- { children }
-
-);
+export const Description = ( { children, asHtml = false, className = '' } ) => {
+ // Don't output anything if description is empty.
+ if ( ! children ) {
+ return null;
+ }
+
+ className = classNames( 'ppcp-r-settings-block__description', className );
+
+ if ( ! asHtml ) {
+ return { children };
+ }
+
+ return (
+
+ );
+};
export const Action = ( { children } ) => (
{ children }
From e5eb1a4435c463a251362a95677d4a43e33691f3 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 14:39:27 +0100
Subject: [PATCH 12/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Switch=20Styling=20U?=
=?UTF-8?q?I=20to=20use=20generic=20components?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../screens/settings/_tab-styling.scss | 52 +++++++------------
.../Components/Styling/StylingSection.js | 34 ++++++------
2 files changed, 37 insertions(+), 49 deletions(-)
diff --git a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
index 61534cc04..d88fe64f7 100644
--- a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
@@ -1,21 +1,29 @@
$width-settings-panel: 422px;
.ppcp-r-styling {
+ --block-item-gap: 0;
+ --block-separator-gap: 24px;
+ --block-header-gap: 18px;
+
display: flex;
border: 1px solid var(--color-separators);
border-radius: 8px;
overflow: hidden;
- .ppcp-r-styling__title {
- @include font(14, 16, 600);
+ .ppcp-r-settings-block {
+ &.header-section {
+ margin-bottom: 22px
+ }
- color: var(--color-text-title);
- display: block;
- margin: 0 0 18px 0;
- }
+ // Select-fields have a smaller gap between the header and input field.
+ &.has-select {
+ --block-header-gap: 8px;
+ }
- .header-section .ppcp-r-styling__title {
- @include font(16, 20, 600);
+ // Above the payment methods is a slightly larger gap.
+ &.payment-methods {
+ --block-separator-gap: 28px;
+ }
}
/* The settings-panel (left side) */
@@ -28,6 +36,7 @@ $width-settings-panel: 422px;
margin-bottom: 28px;
border-bottom: 1px solid var(--color-separators);
+ &.no-gap,
&:last-child {
padding-bottom: 0;
margin-bottom: 0;
@@ -35,6 +44,7 @@ $width-settings-panel: 422px;
}
}
+ // Horizontal radio buttons have a width of 100px.
.components-radio-control__option {
min-width: 100px;
}
@@ -52,30 +62,4 @@ $width-settings-panel: 422px;
padding: 24px;
}
}
-
- /* --- *
-
- &__select {
- label {
- @include font(13, 16, 600);
- color: $color-black;
- margin: 0;
- text-transform: none;
- }
-
- select {
- @include font(13, 20, 400);
- }
- }
-
- .ppcp-r__checkbox {
- .components-checkbox-control {
- &__label {
- @include font(13, 20, 400);
- color: $color-black;
- }
- }
- }
-}
-//*/
}
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js
index ae72e5b03..51290831a 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js
@@ -1,28 +1,32 @@
-import classnames from 'classnames';
+import SettingsBlock from '../../../../ReusableComponents/SettingsBlocks/SettingsBlock';
+import {
+ Description,
+ Header,
+ Title,
+} from '../../../../ReusableComponents/SettingsBlocks';
const StylingSection = ( {
title,
+ bigTitle = false,
className = '',
description = '',
+ separatorAndGap = true,
children,
} ) => {
- const sectionClasses = classnames( 'ppcp-r-styling__section', className );
-
return (
-
-
{ title }
-
- { description && (
-
- ) }
+
+
+
+ { title }
+
+ { description }
+
{ children }
-
+
);
};
From 11e6624dfc280bf1a829133e58c42cd879bf954d Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 14:39:55 +0100
Subject: [PATCH 13/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Extract=20common=20S?=
=?UTF-8?q?tyling=20components=20to=20own=20files?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Styling/LocationSelector.js | 36 ++++---
.../Components/Styling/SettingsPanel.js | 93 +++++++------------
.../Styling/StylingSectionWithCheckboxes.js | 39 ++++++++
.../Styling/StylingSectionWithRadiobuttons.js | 39 ++++++++
.../Styling/StylingSectionWithSelect.js | 36 +++++++
5 files changed, 169 insertions(+), 74 deletions(-)
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithSelect.js
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
index c05b68727..01745fbdc 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
@@ -4,7 +4,9 @@ import { __, sprintf } from '@wordpress/i18n';
// Dummy hook.
import { useStylingProps } from '../../Tabs/TabStyling';
+import { Description } from '../../../../ReusableComponents/SettingsBlocks';
import StylingSection from './StylingSection';
+import StylingSectionWithSelect from './StylingSectionWithSelect';
const LocationSelector = ( { location, setLocation } ) => {
const { locationChoices, locationDetails } = useStylingProps( location );
@@ -12,23 +14,29 @@ const LocationSelector = ( { location, setLocation } ) => {
const locationDescription = sprintf( description, link );
return (
-
-
+
+
-
-
+ >
+
+ { locationDescription }
+
+
+ >
);
};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
index f357bb287..40d418276 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
@@ -1,13 +1,12 @@
import { __ } from '@wordpress/i18n';
-import { RadioControl, SelectControl } from '@wordpress/components';
// Dummy hook.
import { useStylingLocation, useStylingProps } from '../../Tabs/TabStyling';
-import { CheckboxGroup } from '../../../../ReusableComponents/Fields';
-import HStack from '../../../../ReusableComponents/HStack';
import LocationSelector from './LocationSelector';
-import StylingSection from './StylingSection';
+import StylingSectionWithSelect from './StylingSectionWithSelect';
+import StylingSectionWithCheckboxes from './StylingSectionWithCheckboxes';
+import StylingSectionWithRadiobuttons from './StylingSectionWithRadiobuttons';
const SettingsPanel = () => {
const { location, setLocation } = useStylingLocation();
@@ -37,18 +36,13 @@ const SectionPaymentMethods = ( { location } ) => {
useStylingProps( location );
return (
-
-
-
-
-
+ options={ paymentMethodChoices }
+ value={ paymentMethods }
+ onChange={ setPaymentMethods }
+ />
);
};
@@ -61,18 +55,13 @@ const SectionButtonLayout = ( { location } ) => {
}
return (
-
-
-
-
-
+ options={ layoutChoices }
+ selected={ layout }
+ onChange={ setLayout }
+ />
);
};
@@ -80,18 +69,13 @@ const SectionButtonShape = ( { location } ) => {
const { shape, setShape, shapeChoices } = useStylingProps( location );
return (
-
-
-
-
-
+ options={ shapeChoices }
+ selected={ shape }
+ onChange={ setShape }
+ />
);
};
@@ -99,16 +83,13 @@ const SectionButtonLabel = ( { location } ) => {
const { label, setLabel, labelChoices } = useStylingProps( location );
return (
-
-
-
+ options={ labelChoices }
+ value={ label }
+ onChange={ setLabel }
+ />
);
};
@@ -116,16 +97,13 @@ const SectionButtonColor = ( { location } ) => {
const { color, setColor, colorChoices } = useStylingProps( location );
return (
-
-
-
+ options={ colorChoices }
+ value={ color }
+ onChange={ setColor }
+ />
);
};
@@ -138,17 +116,12 @@ const SectionButtonTagline = ( { location } ) => {
}
return (
-
-
-
-
-
+ options={ taglineChoices }
+ value={ tagline }
+ onChange={ setTagline }
+ />
);
};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js
new file mode 100644
index 000000000..cc0b259d6
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js
@@ -0,0 +1,39 @@
+import classNames from 'classnames';
+
+import { CheckboxGroup } from '../../../../ReusableComponents/Fields';
+import HStack from '../../../../ReusableComponents/HStack';
+import StylingSection from './StylingSection';
+
+const StylingSectionWithCheckboxes = ( {
+ title,
+ className = '',
+ description = '',
+ separatorAndGap = true,
+ options,
+ value,
+ onChange,
+ children,
+} ) => {
+ className = classNames( 'has-checkboxes', className );
+
+ return (
+
+
+
+
+
+ { children }
+
+ );
+};
+
+export default StylingSectionWithCheckboxes;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js
new file mode 100644
index 000000000..4bc33326f
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js
@@ -0,0 +1,39 @@
+import { RadioControl } from '@wordpress/components';
+import classNames from 'classnames';
+
+import HStack from '../../../../ReusableComponents/HStack';
+import StylingSection from './StylingSection';
+
+const StylingSectionWithRadiobuttons = ( {
+ title,
+ className = '',
+ description = '',
+ separatorAndGap = true,
+ options,
+ selected,
+ onChange,
+ children,
+} ) => {
+ className = classNames( 'has-radio-buttons', className );
+
+ return (
+
+
+
+
+
+ { children }
+
+ );
+};
+
+export default StylingSectionWithRadiobuttons;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithSelect.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithSelect.js
new file mode 100644
index 000000000..c4164d6b8
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithSelect.js
@@ -0,0 +1,36 @@
+import { SelectControl } from '@wordpress/components';
+import classNames from 'classnames';
+
+import StylingSection from './StylingSection';
+
+const StylingSectionWithSelect = ( {
+ title,
+ className = '',
+ description = '',
+ separatorAndGap = true,
+ options,
+ value,
+ onChange,
+ children,
+} ) => {
+ className = classNames( 'has-select', className );
+
+ return (
+
+
+
+ { children }
+
+ );
+};
+
+export default StylingSectionWithSelect;
From 560f6ed30df17e5ba8b3b24f9319371b19c62f41 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 14:53:58 +0100
Subject: [PATCH 14/66] =?UTF-8?q?=F0=9F=92=84=20Fix=20some=20minor=20CSS?=
=?UTF-8?q?=20issues?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../reusable-components/_settings-block.scss | 11 +++++++++-
.../css/components/screens/_settings.scss | 22 ++++++++-----------
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss
index f5ddb5ea1..8888bf2c0 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_settings-block.scss
@@ -4,7 +4,7 @@
.ppcp-r-settings-block {
display: flex;
flex-direction: column;
- gap: var(--block-item-gap, 16px) 0;
+ gap: var(--block-item-gap, 16px);
&.ppcp-r-settings-block__input,
&.ppcp-r-settings-block__select {
@@ -97,6 +97,15 @@
margin-left: 5px;
}
+ .ppcp-r-settings-block__action {
+ display: flex;
+ align-items: center;
+
+ .components-flex {
+ row-gap: 0;
+ }
+ }
+
+ .ppcp-r-settings-block:not(.no-gap) {
margin-top: var(--block-separator-gap, 32px);
padding-top: var(--block-separator-gap, 32px);
diff --git a/modules/ppcp-settings/resources/css/components/screens/_settings.scss b/modules/ppcp-settings/resources/css/components/screens/_settings.scss
index 2f536ac96..207817cb4 100644
--- a/modules/ppcp-settings/resources/css/components/screens/_settings.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/_settings.scss
@@ -22,6 +22,7 @@
&:hover {
cursor: pointer;
+
.ppcp-r-todo-item__inner {
.ppcp-r-todo-item__description {
color: $color-text-text;
@@ -117,7 +118,7 @@
font-weight: 500;
}
- margin-top:24px;
+ margin-top: 24px;
}
}
@@ -137,10 +138,6 @@
}
}
- &__show-all-data {
- margin-left: 12px;
- }
-
&__status-label {
@include font(11, 22, 600);
color: $color-gray-900;
@@ -151,12 +148,16 @@
&__status-value {
@include font(13, 26, 400);
color: $color-text-tertiary;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
}
&__data {
display: flex;
flex-direction: column;
gap: 12px;
+ width: 100%;
}
&__status-toggle--toggled {
@@ -168,9 +169,7 @@
&__status-row {
display: flex;
flex-direction: column;
- * {
- user-select: none;
- }
+
strong {
@include font(14, 24, 600);
color: $color-gray-800;
@@ -181,11 +180,6 @@
.ppcp-r-connection-status__status-toggle {
line-height: 0;
}
- &--first {
- &:hover {
- cursor: pointer;
- }
- }
}
@media screen and (max-width: 767px) {
@@ -195,9 +189,11 @@
}
&__status-row {
flex-wrap: wrap;
+
strong {
width: 100%;
}
+
span {
word-break: break-all;
}
From 59a4991cf3d2481c995c69d34ad7cf52883ca005 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 14:55:13 +0100
Subject: [PATCH 15/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Extract=20a=20compon?=
=?UTF-8?q?ent=20from=20settings.scss?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../css/components/screens/_settings.scss | 80 +------------------
.../screens/settings/_connection-status.scss | 78 ++++++++++++++++++
2 files changed, 79 insertions(+), 79 deletions(-)
create mode 100644 modules/ppcp-settings/resources/css/components/screens/settings/_connection-status.scss
diff --git a/modules/ppcp-settings/resources/css/components/screens/_settings.scss b/modules/ppcp-settings/resources/css/components/screens/_settings.scss
index 207817cb4..0b8802138 100644
--- a/modules/ppcp-settings/resources/css/components/screens/_settings.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/_settings.scss
@@ -1,4 +1,5 @@
@import './settings/input';
+@import './settings/connection-status';
@import './settings/tab-styling';
@import './settings/tab-paylater-configurator';
@@ -122,85 +123,6 @@
}
}
-// Connection Status
-.ppcp-r-connection-status {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- gap: 12px;
-
- &__status-status {
- margin: 0 0 8px 0;
-
- strong {
- @include font(14, 24, 700);
- color: $color-black;
- }
- }
-
- &__status-label {
- @include font(11, 22, 600);
- color: $color-gray-900;
- display: block;
- text-transform: uppercase;
- }
-
- &__status-value {
- @include font(13, 26, 400);
- color: $color-text-tertiary;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- &__data {
- display: flex;
- flex-direction: column;
- gap: 12px;
- width: 100%;
- }
-
- &__status-toggle--toggled {
- .ppcp-r-connection-status__show-all-data {
- transform: rotate(180deg);
- }
- }
-
- &__status-row {
- display: flex;
- flex-direction: column;
-
- strong {
- @include font(14, 24, 600);
- color: $color-gray-800;
- margin-right: 12px;
- white-space: nowrap;
- }
-
- .ppcp-r-connection-status__status-toggle {
- line-height: 0;
- }
- }
-
- @media screen and (max-width: 767px) {
- flex-wrap: wrap;
- &__status {
- width: 100%;
- }
- &__status-row {
- flex-wrap: wrap;
-
- strong {
- width: 100%;
- }
-
- span {
- word-break: break-all;
- }
- }
- }
-}
-
// Feature Refresh
.ppcp-r-feature-refresh {
display: flex;
diff --git a/modules/ppcp-settings/resources/css/components/screens/settings/_connection-status.scss b/modules/ppcp-settings/resources/css/components/screens/settings/_connection-status.scss
new file mode 100644
index 000000000..2bf1417e6
--- /dev/null
+++ b/modules/ppcp-settings/resources/css/components/screens/settings/_connection-status.scss
@@ -0,0 +1,78 @@
+// Connection Status
+.ppcp-r-connection-status {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 12px;
+
+ &__status-status {
+ margin: 0 0 8px 0;
+
+ strong {
+ @include font(14, 24, 700);
+ color: $color-black;
+ }
+ }
+
+ &__status-label {
+ @include font(11, 22, 600);
+ color: $color-gray-900;
+ display: block;
+ text-transform: uppercase;
+ }
+
+ &__status-value {
+ @include font(13, 26, 400);
+ color: $color-text-tertiary;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ &__data {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ width: 100%;
+ }
+
+ &__status-toggle--toggled {
+ .ppcp-r-connection-status__show-all-data {
+ transform: rotate(180deg);
+ }
+ }
+
+ &__status-row {
+ display: flex;
+ flex-direction: column;
+
+ strong {
+ @include font(14, 24, 600);
+ color: $color-gray-800;
+ margin-right: 12px;
+ white-space: nowrap;
+ }
+
+ .ppcp-r-connection-status__status-toggle {
+ line-height: 0;
+ }
+ }
+
+ @media screen and (max-width: 767px) {
+ flex-wrap: wrap;
+ &__status {
+ width: 100%;
+ }
+ &__status-row {
+ flex-wrap: wrap;
+
+ strong {
+ width: 100%;
+ }
+
+ span {
+ word-break: break-all;
+ }
+ }
+ }
+}
From 484356dcc00d015ef76320fd0783e8b05b97ba70 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 15:02:25 +0100
Subject: [PATCH 16/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Shorten=20the=20impo?=
=?UTF-8?q?rt=20path=20for=20styling=20config?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/Components/Screens/Settings/Tabs/TabStyling.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
index 07f5ad4d9..f0ee60151 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
@@ -8,7 +8,7 @@ import {
STYLING_LOCATIONS,
STYLING_PAYMENT_METHODS,
STYLING_SHAPES,
-} from '../../../../data/styling/constants';
+} from '../../../../data';
import PreviewPanel from '../Components/Styling/PreviewPanel';
import SettingsPanel from '../Components/Styling/SettingsPanel';
From c16e5e4c58e17e3c800c3eb14f30bf7876140fca Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 15:03:46 +0100
Subject: [PATCH 17/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Extract=20UI=20confi?=
=?UTF-8?q?guration=20to=20separate=20files?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/configuration.js | 10 ++
.../resources/js/data/constants.js | 9 --
.../ppcp-settings/resources/js/data/index.js | 2 +-
.../js/data/onboarding/configuration.js | 26 +++
.../resources/js/data/onboarding/constants.js | 21 ---
.../resources/js/data/onboarding/hooks.js | 2 +-
.../js/data/styling/configuration.js | 149 ++++++++++++++++++
.../resources/js/data/styling/constants.js | 144 -----------------
8 files changed, 187 insertions(+), 176 deletions(-)
create mode 100644 modules/ppcp-settings/resources/js/data/configuration.js
delete mode 100644 modules/ppcp-settings/resources/js/data/constants.js
create mode 100644 modules/ppcp-settings/resources/js/data/onboarding/configuration.js
create mode 100644 modules/ppcp-settings/resources/js/data/styling/configuration.js
diff --git a/modules/ppcp-settings/resources/js/data/configuration.js b/modules/ppcp-settings/resources/js/data/configuration.js
new file mode 100644
index 000000000..0f3608552
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/data/configuration.js
@@ -0,0 +1,10 @@
+export { BUSINESS_TYPES, PRODUCT_TYPES } from './onboarding/configuration';
+
+export {
+ STYLING_LOCATIONS,
+ STYLING_PAYMENT_METHODS,
+ STYLING_LABELS,
+ STYLING_COLORS,
+ STYLING_LAYOUTS,
+ STYLING_SHAPES,
+} from './styling/configuration';
diff --git a/modules/ppcp-settings/resources/js/data/constants.js b/modules/ppcp-settings/resources/js/data/constants.js
deleted file mode 100644
index fbc8e8e11..000000000
--- a/modules/ppcp-settings/resources/js/data/constants.js
+++ /dev/null
@@ -1,9 +0,0 @@
-export { BUSINESS_TYPES, PRODUCT_TYPES } from './onboarding/constants';
-
-export {
- STYLING_LOCATIONS,
- STYLING_LABELS,
- STYLING_COLORS,
- STYLING_LAYOUTS,
- STYLING_SHAPES,
-} from './styling/constants';
diff --git a/modules/ppcp-settings/resources/js/data/index.js b/modules/ppcp-settings/resources/js/data/index.js
index e447ff770..959c5f187 100644
--- a/modules/ppcp-settings/resources/js/data/index.js
+++ b/modules/ppcp-settings/resources/js/data/index.js
@@ -15,6 +15,6 @@ export const OnboardingStoreName = Onboarding.STORE_NAME;
export const CommonStoreName = Common.STORE_NAME;
export const StylingStoreName = Styling.STORE_NAME;
-export * from './constants';
+export * from './configuration';
addDebugTools( window.ppcpSettings, [ Onboarding, Common, Styling ] );
diff --git a/modules/ppcp-settings/resources/js/data/onboarding/configuration.js b/modules/ppcp-settings/resources/js/data/onboarding/configuration.js
new file mode 100644
index 000000000..4b31689b5
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/data/onboarding/configuration.js
@@ -0,0 +1,26 @@
+/**
+ * Configuration for UI components.
+ *
+ * @file
+ */
+
+/**
+ * Onboarding options for StepBusiness
+ *
+ * @type {Object}
+ */
+export const BUSINESS_TYPES = {
+ CASUAL_SELLER: 'casual_seller',
+ BUSINESS: 'business',
+};
+
+/**
+ * Onboarding options for StepProducts
+ *
+ * @type {Object}
+ */
+export const PRODUCT_TYPES = {
+ VIRTUAL: 'virtual',
+ PHYSICAL: 'physical',
+ SUBSCRIPTIONS: 'subscriptions',
+};
diff --git a/modules/ppcp-settings/resources/js/data/onboarding/constants.js b/modules/ppcp-settings/resources/js/data/onboarding/constants.js
index 7c35ee693..396726199 100644
--- a/modules/ppcp-settings/resources/js/data/onboarding/constants.js
+++ b/modules/ppcp-settings/resources/js/data/onboarding/constants.js
@@ -26,24 +26,3 @@ export const REST_HYDRATE_PATH = '/wc/v3/wc_paypal/onboarding';
* @type {string}
*/
export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/onboarding';
-
-/**
- * Onboarding options for StepBusiness
- *
- * @type {Object}
- */
-export const BUSINESS_TYPES = {
- CASUAL_SELLER: 'casual_seller',
- BUSINESS: 'business',
-};
-
-/**
- * Onboarding options for StepProducts
- *
- * @type {Object}
- */
-export const PRODUCT_TYPES = {
- VIRTUAL: 'virtual',
- PHYSICAL: 'physical',
- SUBSCRIPTIONS: 'subscriptions',
-};
diff --git a/modules/ppcp-settings/resources/js/data/onboarding/hooks.js b/modules/ppcp-settings/resources/js/data/onboarding/hooks.js
index c4308c0fa..2d1542f68 100644
--- a/modules/ppcp-settings/resources/js/data/onboarding/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/onboarding/hooks.js
@@ -9,7 +9,7 @@
import { useSelect, useDispatch } from '@wordpress/data';
-import { PRODUCT_TYPES } from '../constants';
+import { PRODUCT_TYPES } from './configuration';
import { STORE_NAME } from './constants';
const useTransient = ( key ) =>
diff --git a/modules/ppcp-settings/resources/js/data/styling/configuration.js b/modules/ppcp-settings/resources/js/data/styling/configuration.js
new file mode 100644
index 000000000..861379e2d
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/data/styling/configuration.js
@@ -0,0 +1,149 @@
+/**
+ * Configuration for UI components.
+ *
+ * @file
+ */
+
+import { __ } from '@wordpress/i18n';
+
+export const STYLING_LOCATIONS = {
+ cart: {
+ value: 'cart',
+ label: __( 'Cart', 'woocommerce-paypal-payments' ),
+ // translators: %s is the URL to a documentation page.
+ description: __(
+ 'More details on the Cart page.',
+ 'wooocommerce-paypal-payments'
+ ),
+ link: '#',
+ },
+ 'classic-checkout': {
+ value: 'classic-checkout',
+ label: __( 'Classic Checkout', 'woocommerce-paypal-payments' ),
+ // translators: %s is the URL to a documentation page.
+ description: __(
+ 'More details on the Classic Checkout page.',
+ 'wooocommerce-paypal-payments'
+ ),
+ link: '#',
+ },
+ 'express-checkout': {
+ value: 'express-checkout',
+ label: __( 'Express Checkout', 'woocommerce-paypal-payments' ),
+ // translators: %s is the URL to a documentation page.
+ description: __(
+ 'More details on the Express Checkout location.',
+ 'wooocommerce-paypal-payments'
+ ),
+ link: '#',
+ },
+ 'mini-cart': {
+ value: 'mini-cart',
+ label: __( 'Mini Cart', 'woocommerce-paypel-payements' ),
+ // translators: %s is the URL to a documentation page.
+ description: __(
+ 'More details on the Mini Cart.',
+ 'wooocommerce-paypal-payments'
+ ),
+ link: '#',
+ },
+ 'product-page': {
+ value: 'product-page',
+ label: __( 'Product Page', 'woocommerce-paypal-payments' ),
+ // translators: %s is the URL to a documentation page.
+ description: __(
+ 'More details on the Product Page.',
+ 'wooocommerce-paypal-payments'
+ ),
+ link: '#',
+ },
+};
+
+export const STYLING_LABELS = {
+ paypal: {
+ value: 'paypal',
+ label: __( 'PayPal', 'woocommerce-paypal-payments' ),
+ },
+ checkout: {
+ value: 'checkout',
+ label: __( 'Checkout', 'woocommerce-paypal-payments' ),
+ },
+ buynow: {
+ value: 'buynow',
+ label: __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ),
+ },
+ pay: {
+ value: 'pay',
+ label: __( 'Pay with PayPal', 'woocommerce-paypal-payments' ),
+ },
+};
+
+export const STYLING_COLORS = {
+ gold: {
+ value: 'gold',
+ label: __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ),
+ },
+ blue: {
+ value: 'blue',
+ label: __( 'Blue', 'woocommerce-paypal-payments' ),
+ },
+ silver: {
+ value: 'silver',
+ label: __( 'Silver', 'woocommerce-paypal-payments' ),
+ },
+ black: {
+ value: 'black',
+ label: __( 'Black', 'woocommerce-paypal-payments' ),
+ },
+ white: {
+ value: 'white',
+ label: __( 'White', 'woocommerce-paypal-payments' ),
+ },
+};
+
+export const STYLING_LAYOUTS = {
+ vertical: {
+ value: 'vertical',
+ label: __( 'Vertical', 'woocommerce-paypal-payments' ),
+ },
+ horizontal: {
+ value: 'horizontal',
+ label: __( 'Horizontal', 'woocommerce-paypal-payments' ),
+ },
+};
+
+export const STYLING_SHAPES = {
+ pill: {
+ value: 'pill',
+ label: __( 'Pill', 'woocommerce-paypal-payments' ),
+ },
+ rect: {
+ value: 'rect',
+ label: __( 'Rectangle', 'woocommerce-paypal-payments' ),
+ },
+};
+
+export const STYLING_PAYMENT_METHODS = {
+ paypal: {
+ value: '',
+ label: __( 'PayPal', 'woocommerce-paypal-payments' ),
+ checked: true,
+ disabled: true,
+ },
+ venmo: {
+ value: 'venmo',
+ label: __( 'Venmo', 'woocommerce-paypal-payments' ),
+ },
+ paylater: {
+ value: 'paylater',
+ label: __( 'Pay Later', 'woocommerce-paypal-payments' ),
+ },
+ googlepay: {
+ value: 'googlepay',
+ label: __( 'Google Pay', 'woocommerce-paypal-payments' ),
+ },
+ applepay: {
+ value: 'applepay',
+ label: __( 'Apple Pay', 'woocommerce-paypal-payments' ),
+ },
+};
diff --git a/modules/ppcp-settings/resources/js/data/styling/constants.js b/modules/ppcp-settings/resources/js/data/styling/constants.js
index f21ac7adf..db1082f33 100644
--- a/modules/ppcp-settings/resources/js/data/styling/constants.js
+++ b/modules/ppcp-settings/resources/js/data/styling/constants.js
@@ -1,5 +1,3 @@
-import { __ } from '@wordpress/i18n';
-
/**
* Name of the Redux store module.
*
@@ -28,145 +26,3 @@ export const REST_HYDRATE_PATH = '/wc/v3/wc_paypal/styling';
* @type {string}
*/
export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/styling';
-
-export const STYLING_LOCATIONS = {
- cart: {
- value: 'cart',
- label: __( 'Cart', 'woocommerce-paypal-payments' ),
- // translators: %s is the URL to a documentation page.
- description: __(
- 'More details on the Cart page.',
- 'wooocommerce-paypal-payments'
- ),
- link: '#',
- },
- 'classic-checkout': {
- value: 'classic-checkout',
- label: __( 'Classic Checkout', 'woocommerce-paypal-payments' ),
- // translators: %s is the URL to a documentation page.
- description: __(
- 'More details on the Classic Checkout page.',
- 'wooocommerce-paypal-payments'
- ),
- link: '#',
- },
- 'express-checkout': {
- value: 'express-checkout',
- label: __( 'Express Checkout', 'woocommerce-paypal-payments' ),
- // translators: %s is the URL to a documentation page.
- description: __(
- 'More details on the Express Checkout location.',
- 'wooocommerce-paypal-payments'
- ),
- link: '#',
- },
- 'mini-cart': {
- value: 'mini-cart',
- label: __( 'Mini Cart', 'woocommerce-paypel-payements' ),
- // translators: %s is the URL to a documentation page.
- description: __(
- 'More details on the Mini Cart.',
- 'wooocommerce-paypal-payments'
- ),
- link: '#',
- },
- 'product-page': {
- value: 'product-page',
- label: __( 'Product Page', 'woocommerce-paypal-payments' ),
- // translators: %s is the URL to a documentation page.
- description: __(
- 'More details on the Product Page.',
- 'wooocommerce-paypal-payments'
- ),
- link: '#',
- },
-};
-
-export const STYLING_LABELS = {
- paypal: {
- value: 'paypal',
- label: __( 'PayPal', 'woocommerce-paypal-payments' ),
- },
- checkout: {
- value: 'checkout',
- label: __( 'Checkout', 'woocommerce-paypal-payments' ),
- },
- buynow: {
- value: 'buynow',
- label: __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ),
- },
- pay: {
- value: 'pay',
- label: __( 'Pay with PayPal', 'woocommerce-paypal-payments' ),
- },
-};
-
-export const STYLING_COLORS = {
- gold: {
- value: 'gold',
- label: __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ),
- },
- blue: {
- value: 'blue',
- label: __( 'Blue', 'woocommerce-paypal-payments' ),
- },
- silver: {
- value: 'silver',
- label: __( 'Silver', 'woocommerce-paypal-payments' ),
- },
- black: {
- value: 'black',
- label: __( 'Black', 'woocommerce-paypal-payments' ),
- },
- white: {
- value: 'white',
- label: __( 'White', 'woocommerce-paypal-payments' ),
- },
-};
-
-export const STYLING_LAYOUTS = {
- vertical: {
- value: 'vertical',
- label: __( 'Vertical', 'woocommerce-paypal-payments' ),
- },
- horizontal: {
- value: 'horizontal',
- label: __( 'Horizontal', 'woocommerce-paypal-payments' ),
- },
-};
-
-export const STYLING_SHAPES = {
- pill: {
- value: 'pill',
- label: __( 'Pill', 'woocommerce-paypal-payments' ),
- },
- rect: {
- value: 'rect',
- label: __( 'Rectangle', 'woocommerce-paypal-payments' ),
- },
-};
-
-export const STYLING_PAYMENT_METHODS = {
- paypal: {
- value: '',
- label: __( 'PayPal', 'woocommerce-paypal-payments' ),
- checked: true,
- disabled: true,
- },
- venmo: {
- value: 'venmo',
- label: __( 'Venmo', 'woocommerce-paypal-payments' ),
- },
- paylater: {
- value: 'paylater',
- label: __( 'Pay Later', 'woocommerce-paypal-payments' ),
- },
- googlepay: {
- value: 'googlepay',
- label: __( 'Google Pay', 'woocommerce-paypal-payments' ),
- },
- applepay: {
- value: 'applepay',
- label: __( 'Apple Pay', 'woocommerce-paypal-payments' ),
- },
-};
From 8755242530511672eea2d2e9fc7862fb4f339e7a Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 15:05:59 +0100
Subject: [PATCH 18/66] =?UTF-8?q?=F0=9F=90=9B=20Fix=20incorrect=20import?=
=?UTF-8?q?=20path?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/styling/reducer.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/reducer.js b/modules/ppcp-settings/resources/js/data/styling/reducer.js
index b28c3f265..358d261ff 100644
--- a/modules/ppcp-settings/resources/js/data/styling/reducer.js
+++ b/modules/ppcp-settings/resources/js/data/styling/reducer.js
@@ -9,7 +9,7 @@
import { createReducer, createSetters } from '../utils';
import ACTION_TYPES from './action-types';
-import { STYLING_COLORS, STYLING_SHAPES } from './constants';
+import { STYLING_COLORS, STYLING_SHAPES } from './configuration';
// Store structure.
From bd14ea441ec2d38a6abed9861a5f2c5e9a6bb977 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 17:16:37 +0100
Subject: [PATCH 19/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20dummy=20hook?=
=?UTF-8?q?=20into=20redux=20store?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Styling/LocationSelector.js | 8 +-
.../Components/Styling/SettingsPanel.js | 21 ++--
.../Screens/Settings/Tabs/TabStyling.js | 102 ------------------
.../resources/js/data/styling/hooks.js | 98 ++++++++++++++++-
4 files changed, 111 insertions(+), 118 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
index 01745fbdc..35c3a6efd 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
@@ -1,15 +1,13 @@
-import { SelectControl } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
-// Dummy hook.
-import { useStylingProps } from '../../Tabs/TabStyling';
-
+import { StylingHooks } from '../../../../../data';
import { Description } from '../../../../ReusableComponents/SettingsBlocks';
import StylingSection from './StylingSection';
import StylingSectionWithSelect from './StylingSectionWithSelect';
const LocationSelector = ( { location, setLocation } ) => {
- const { locationChoices, locationDetails } = useStylingProps( location );
+ const { locationChoices, locationDetails } =
+ StylingHooks.useStylingProps( location );
const { description, link } = locationDetails || {};
const locationDescription = sprintf( description, link );
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
index 40d418276..4826632a9 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
@@ -1,15 +1,13 @@
import { __ } from '@wordpress/i18n';
-// Dummy hook.
-import { useStylingLocation, useStylingProps } from '../../Tabs/TabStyling';
-
+import { StylingHooks } from '../../../../../data';
import LocationSelector from './LocationSelector';
import StylingSectionWithSelect from './StylingSectionWithSelect';
import StylingSectionWithCheckboxes from './StylingSectionWithCheckboxes';
import StylingSectionWithRadiobuttons from './StylingSectionWithRadiobuttons';
const SettingsPanel = () => {
- const { location, setLocation } = useStylingLocation();
+ const { location, setLocation } = StylingHooks.useStylingLocation();
return (
@@ -33,7 +31,7 @@ export default SettingsPanel;
const SectionPaymentMethods = ( { location } ) => {
const { paymentMethods, setPaymentMethods, paymentMethodChoices } =
- useStylingProps( location );
+ StylingHooks.useStylingProps( location );
return (
{
const SectionButtonLayout = ( { location } ) => {
const { supportsLayout, layout, setLayout, layoutChoices } =
- useStylingProps( location );
+ StylingHooks.useStylingProps( location );
if ( ! supportsLayout ) {
return null;
@@ -66,7 +64,8 @@ const SectionButtonLayout = ( { location } ) => {
};
const SectionButtonShape = ( { location } ) => {
- const { shape, setShape, shapeChoices } = useStylingProps( location );
+ const { shape, setShape, shapeChoices } =
+ StylingHooks.useStylingProps( location );
return (
{
};
const SectionButtonLabel = ( { location } ) => {
- const { label, setLabel, labelChoices } = useStylingProps( location );
+ const { label, setLabel, labelChoices } =
+ StylingHooks.useStylingProps( location );
return (
{
};
const SectionButtonColor = ( { location } ) => {
- const { color, setColor, colorChoices } = useStylingProps( location );
+ const { color, setColor, colorChoices } =
+ StylingHooks.useStylingProps( location );
return (
{
const SectionButtonTagline = ( { location } ) => {
const { supportsTagline, tagline, setTagline, taglineChoices } =
- useStylingProps( location );
+ StylingHooks.useStylingProps( location );
if ( ! supportsTagline ) {
return null;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
index f0ee60151..c1eb5eb19 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabStyling.js
@@ -1,15 +1,3 @@
-import { __ } from '@wordpress/i18n';
-import { useCallback, useState } from '@wordpress/element';
-
-import {
- STYLING_COLORS,
- STYLING_LABELS,
- STYLING_LAYOUTS,
- STYLING_LOCATIONS,
- STYLING_PAYMENT_METHODS,
- STYLING_SHAPES,
-} from '../../../../data';
-
import PreviewPanel from '../Components/Styling/PreviewPanel';
import SettingsPanel from '../Components/Styling/SettingsPanel';
@@ -21,93 +9,3 @@ const TabStyling = () => (
);
export default TabStyling;
-
-// ----------------------------------------------------------------------------
-
-// Temporary "hook" to extract logic before moving it to the Redux store.
-export const useStylingLocation = () => {
- const [ location, setLocation ] = useState( 'cart' );
-
- return { location, setLocation };
-};
-
-export const useStylingProps = ( location ) => {
- const defaultStyle = {
- paymentMethods: [],
- color: 'gold',
- shape: 'rect',
- label: 'paypal',
- layout: 'vertical',
- tagline: false,
- };
-
- const [ styles, setStyles ] = useState( {
- cart: { ...defaultStyle, label: 'checkout' },
- 'classic-checkout': { ...defaultStyle },
- 'express-checkout': { ...defaultStyle, label: 'pay' },
- 'mini-cart': { ...defaultStyle, label: 'pay' },
- 'product-page': { ...defaultStyle },
- } );
-
- const getLocationStyle = useCallback(
- ( prop ) => styles[ location ]?.[ prop ],
- [ location, styles ]
- );
-
- const setLocationStyle = useCallback(
- ( prop, value ) => {
- setStyles( ( prevState ) => ( {
- ...prevState,
- [ location ]: {
- ...prevState[ location ],
- [ prop ]: value,
- },
- } ) );
- },
- [ location ]
- );
-
- return {
- // Location (drop down).
- locationChoices: Object.values( STYLING_LOCATIONS ),
- locationDetails: STYLING_LOCATIONS[ location ],
-
- // Payment methods (checkboxes).
- paymentMethodChoices: Object.values( STYLING_PAYMENT_METHODS ),
- paymentMethods: getLocationStyle( 'paymentMethods' ),
- setPaymentMethods: ( methods ) =>
- setLocationStyle( 'paymentMethods', methods ),
-
- // Color (dropdown).
- colorChoices: Object.values( STYLING_COLORS ),
- color: getLocationStyle( 'color' ),
- setColor: ( color ) => setLocationStyle( 'color', color ),
-
- // Shape (radio).
- shapeChoices: Object.values( STYLING_SHAPES ),
- shape: getLocationStyle( 'shape' ),
- setShape: ( shape ) => setLocationStyle( 'shape', shape ),
-
- // Label (dropdown).
- labelChoices: Object.values( STYLING_LABELS ),
- label: getLocationStyle( 'label' ),
- setLabel: ( label ) => setLocationStyle( 'label', label ),
-
- // Layout (radio).
- layoutChoices: Object.values( STYLING_LAYOUTS ),
- supportsLayout: true,
- layout: getLocationStyle( 'layout' ),
- setLayout: ( layout ) => setLocationStyle( 'layout', layout ),
-
- // Tagline (checkbox).
- taglineChoices: [
- {
- value: 'tagline',
- label: __( 'Enable Tagline', 'woocommerce-paypal-payments' ),
- },
- ],
- supportsTagline: true,
- tagline: getLocationStyle( 'tagline' ),
- setTagline: ( tagline ) => setLocationStyle( 'tagline', tagline ),
- };
-};
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index de08f1124..45280de83 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -7,9 +7,19 @@
* @file
*/
+import { __ } from '@wordpress/i18n';
+import { useCallback, useState } from '@wordpress/element'; // Temporary
import { useSelect, useDispatch } from '@wordpress/data';
import { STORE_NAME } from './constants';
+import {
+ STYLING_COLORS,
+ STYLING_LABELS,
+ STYLING_LAYOUTS,
+ STYLING_LOCATIONS,
+ STYLING_PAYMENT_METHODS,
+ STYLING_SHAPES,
+} from './configuration';
const useTransient = ( key ) =>
useSelect(
@@ -42,7 +52,93 @@ const useHooks = () => {
};
};
-export const useState = () => {
+export const useStore = () => {
const { persist, isReady } = useHooks();
return { persist, isReady };
};
+
+export const useStylingLocation = () => {
+ const [ location, setLocation ] = useState( 'cart' );
+ return { location, setLocation };
+};
+
+export const useStylingProps = ( location ) => {
+ const defaultStyle = {
+ paymentMethods: [],
+ color: 'gold',
+ shape: 'rect',
+ label: 'paypal',
+ layout: 'vertical',
+ tagline: false,
+ };
+
+ const [ styles, setStyles ] = useState( {
+ cart: { ...defaultStyle, label: 'checkout' },
+ 'classic-checkout': { ...defaultStyle },
+ 'express-checkout': { ...defaultStyle, label: 'pay' },
+ 'mini-cart': { ...defaultStyle, label: 'pay' },
+ 'product-page': { ...defaultStyle },
+ } );
+
+ const getLocationStyle = useCallback(
+ ( prop ) => styles[ location ]?.[ prop ],
+ [ location, styles ]
+ );
+
+ const setLocationStyle = useCallback(
+ ( prop, value ) => {
+ setStyles( ( prevState ) => ( {
+ ...prevState,
+ [ location ]: {
+ ...prevState[ location ],
+ [ prop ]: value,
+ },
+ } ) );
+ },
+ [ location ]
+ );
+
+ return {
+ // Location (drop down).
+ locationChoices: Object.values( STYLING_LOCATIONS ),
+ locationDetails: STYLING_LOCATIONS[ location ],
+
+ // Payment methods (checkboxes).
+ paymentMethodChoices: Object.values( STYLING_PAYMENT_METHODS ),
+ paymentMethods: getLocationStyle( 'paymentMethods' ),
+ setPaymentMethods: ( methods ) =>
+ setLocationStyle( 'paymentMethods', methods ),
+
+ // Color (dropdown).
+ colorChoices: Object.values( STYLING_COLORS ),
+ color: getLocationStyle( 'color' ),
+ setColor: ( color ) => setLocationStyle( 'color', color ),
+
+ // Shape (radio).
+ shapeChoices: Object.values( STYLING_SHAPES ),
+ shape: getLocationStyle( 'shape' ),
+ setShape: ( shape ) => setLocationStyle( 'shape', shape ),
+
+ // Label (dropdown).
+ labelChoices: Object.values( STYLING_LABELS ),
+ label: getLocationStyle( 'label' ),
+ setLabel: ( label ) => setLocationStyle( 'label', label ),
+
+ // Layout (radio).
+ layoutChoices: Object.values( STYLING_LAYOUTS ),
+ supportsLayout: true,
+ layout: getLocationStyle( 'layout' ),
+ setLayout: ( layout ) => setLocationStyle( 'layout', layout ),
+
+ // Tagline (checkbox).
+ taglineChoices: [
+ {
+ value: 'tagline',
+ label: __( 'Enable Tagline', 'woocommerce-paypal-payments' ),
+ },
+ ],
+ supportsTagline: true,
+ tagline: getLocationStyle( 'tagline' ),
+ setTagline: ( tagline ) => setLocationStyle( 'tagline', tagline ),
+ };
+};
From f07d9bad82e7b0afcacf0cd5af47a6fe31df9411 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 18:20:03 +0100
Subject: [PATCH 20/66] =?UTF-8?q?=E2=9C=A8=20Add=20gemeric=20hook-generato?=
=?UTF-8?q?r=20for=20data=20access?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/hooks.js | 20 ++----
.../ppcp-settings/resources/js/data/utils.js | 61 +++++++++++++++++++
2 files changed, 66 insertions(+), 15 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 45280de83..6e6a502ab 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -11,6 +11,7 @@ import { __ } from '@wordpress/i18n';
import { useCallback, useState } from '@wordpress/element'; // Temporary
import { useSelect, useDispatch } from '@wordpress/data';
+import { createHooksForStore } from '../utils';
import { STORE_NAME } from './constants';
import {
STYLING_COLORS,
@@ -21,28 +22,17 @@ import {
STYLING_SHAPES,
} from './configuration';
-const useTransient = ( key ) =>
- useSelect(
- ( select ) => select( STORE_NAME ).transientData()?.[ key ],
- [ key ]
- );
-
-const usePersistent = ( key ) =>
- useSelect(
- ( select ) => select( STORE_NAME ).persistentData()?.[ key ],
- [ key ]
- );
-
const useHooks = () => {
- const { persist, setShape } = useDispatch( STORE_NAME );
+ const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
+ const { persist } = useDispatch( STORE_NAME );
// Read-only flags and derived state.
// Transient accessors.
- const isReady = useTransient( 'isReady' );
+ const [ isReady ] = useTransient( 'isReady' );
// Persistent accessors.
- const shape = usePersistent( 'shape' );
+ const [ shape, setShape ] = usePersistent( 'shape' );
return {
persist,
diff --git a/modules/ppcp-settings/resources/js/data/utils.js b/modules/ppcp-settings/resources/js/data/utils.js
index 45c652862..35d7bbbf9 100644
--- a/modules/ppcp-settings/resources/js/data/utils.js
+++ b/modules/ppcp-settings/resources/js/data/utils.js
@@ -1,3 +1,6 @@
+import { useDispatch, useSelect } from '@wordpress/data';
+import { useCallback } from '@wordpress/element';
+
/**
* Updates an object with new values, filtering based on allowed keys.
*
@@ -13,6 +16,10 @@ const updateObject = ( oldObject, newValues, allowedKeys = {} ) => ( {
...Object.keys( newValues ).reduce( ( acc, key ) => {
if ( key in allowedKeys ) {
acc[ key ] = newValues[ key ];
+ } else {
+ console.warn(
+ `Ignoring unknown key "${ key }" - to use it, add it to the initial store properties in the reducer.`
+ );
}
return acc;
}, {} ),
@@ -73,3 +80,57 @@ export const createReducer = (
return state;
};
};
+
+/**
+ * Returns an object with two hooks:
+ * - useTransient( prop )
+ * - usePersistent( prop )
+ *
+ * Both hooks have a similar syntax to the native "useState( prop )" hook, but provide access to
+ * a transient or persistent property in the relevant Redux store.
+ *
+ * Sample:
+ *
+ * const { useTransient } = createHooksForStore( STORE_NAME );
+ * const [ isReady, setIsReady ] = useTransient( 'isReady' );
+ *
+ * @param {string} storeName Store name.
+ * @return {{useTransient, usePersistent}} Store hooks.
+ */
+export const createHooksForStore = ( storeName ) => {
+ const createHook = ( selector, dispatcher ) => ( key ) => {
+ const value = useSelect(
+ ( select ) => {
+ const store = select( storeName );
+ if ( ! store?.[ selector ] ) {
+ throw new Error(
+ `Please create the selector "${ selector }" for store "${ storeName }"`
+ );
+ }
+ return store[ selector ]()?.[ key ];
+ },
+ [ key ]
+ );
+
+ const actions = useDispatch( storeName );
+
+ const setValue = useCallback(
+ ( newValue ) => {
+ if ( ! actions?.[ dispatcher ] ) {
+ throw new Error(
+ `Please create the action "${ dispatcher }" for store "${ storeName }"`
+ );
+ }
+ actions[ dispatcher ]( key, newValue );
+ },
+ [ actions, key ]
+ );
+
+ return [ value, setValue ];
+ };
+
+ return {
+ useTransient: createHook( 'transientData', 'setTransient' ),
+ usePersistent: createHook( 'persistentData', 'setPersistent' ),
+ };
+};
From 96128ee3e4e7280383b0fbeffe0f7068f75886f7 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 18:25:54 +0100
Subject: [PATCH 21/66] =?UTF-8?q?=E2=9C=A8=20Create=20the=20generic=20sett?=
=?UTF-8?q?er-actions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/actions.js | 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/modules/ppcp-settings/resources/js/data/styling/actions.js b/modules/ppcp-settings/resources/js/data/styling/actions.js
index 25cf6f04b..435c4f2d9 100644
--- a/modules/ppcp-settings/resources/js/data/styling/actions.js
+++ b/modules/ppcp-settings/resources/js/data/styling/actions.js
@@ -36,6 +36,30 @@ export const hydrate = ( payload ) => ( {
payload,
} );
+/**
+ * Generic transient-data updater.
+ *
+ * @param {string} prop Name of the property to update.
+ * @param {any} value The new value of the property.
+ * @return {Action} The action.
+ */
+export const setTransient = ( prop, value ) => ( {
+ type: ACTION_TYPES.SET_TRANSIENT,
+ payload: { [ prop ]: value },
+} );
+
+/**
+ * Generic persistent-data updater.
+ *
+ * @param {string} prop Name of the property to update.
+ * @param {any} value The new value of the property.
+ * @return {Action} The action.
+ */
+export const setPersistent = ( prop, value ) => ( {
+ type: ACTION_TYPES.SET_PERSISTENT,
+ payload: { [ prop ]: value },
+} );
+
/**
* Transient. Marks the store as "ready", i.e., fully initialized.
*
From 209b7a7c885a8d3b6513f2172388ebbe09019341 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 18:27:20 +0100
Subject: [PATCH 22/66] =?UTF-8?q?=F0=9F=94=A5=20Clean=20up=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/actions.js | 22 -------------------
.../resources/js/data/styling/hooks.js | 4 +---
2 files changed, 1 insertion(+), 25 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/actions.js b/modules/ppcp-settings/resources/js/data/styling/actions.js
index 435c4f2d9..095a54c91 100644
--- a/modules/ppcp-settings/resources/js/data/styling/actions.js
+++ b/modules/ppcp-settings/resources/js/data/styling/actions.js
@@ -60,28 +60,6 @@ export const setPersistent = ( prop, value ) => ( {
payload: { [ prop ]: value },
} );
-/**
- * Transient. Marks the store as "ready", i.e., fully initialized.
- *
- * @param {boolean} isReady
- * @return {Action} The action.
- */
-export const setIsReady = ( isReady ) => ( {
- type: ACTION_TYPES.SET_TRANSIENT,
- payload: { isReady },
-} );
-
-/**
- * Persistent.
- *
- * @param {string} shape
- * @return {Action} The action.
- */
-export const setShape = ( shape ) => ( {
- type: ACTION_TYPES.SET_PERSISTENT,
- payload: { shape },
-} );
-
/**
* Side effect. Triggers the persistence of store data to the server.
*
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 6e6a502ab..201136695 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -9,7 +9,7 @@
import { __ } from '@wordpress/i18n';
import { useCallback, useState } from '@wordpress/element'; // Temporary
-import { useSelect, useDispatch } from '@wordpress/data';
+import { useDispatch } from '@wordpress/data';
import { createHooksForStore } from '../utils';
import { STORE_NAME } from './constants';
@@ -37,8 +37,6 @@ const useHooks = () => {
return {
persist,
isReady,
- shape,
- setShape,
};
};
From 0673e5d813b6f7314fd47ee17e1761c662365142 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 18:28:11 +0100
Subject: [PATCH 23/66] =?UTF-8?q?=E2=9C=A8=20Move=20prop=20=E2=80=9Clocati?=
=?UTF-8?q?on=E2=80=9D=20into=20Redux=20store?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/styling/hooks.js | 5 ++++-
modules/ppcp-settings/resources/js/data/styling/reducer.js | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 201136695..e8863b3e3 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -30,6 +30,7 @@ const useHooks = () => {
// Transient accessors.
const [ isReady ] = useTransient( 'isReady' );
+ const [ location, setLocation ] = useTransient( 'location' );
// Persistent accessors.
const [ shape, setShape ] = usePersistent( 'shape' );
@@ -37,6 +38,8 @@ const useHooks = () => {
return {
persist,
isReady,
+ location,
+ setLocation,
};
};
@@ -46,7 +49,7 @@ export const useStore = () => {
};
export const useStylingLocation = () => {
- const [ location, setLocation ] = useState( 'cart' );
+ const { location, setLocation } = useHooks();
return { location, setLocation };
};
diff --git a/modules/ppcp-settings/resources/js/data/styling/reducer.js b/modules/ppcp-settings/resources/js/data/styling/reducer.js
index 358d261ff..ec432081f 100644
--- a/modules/ppcp-settings/resources/js/data/styling/reducer.js
+++ b/modules/ppcp-settings/resources/js/data/styling/reducer.js
@@ -16,6 +16,7 @@ import { STYLING_COLORS, STYLING_SHAPES } from './configuration';
// Transient: Values that are _not_ saved to the DB (like app lifecycle-flags).
const defaultTransient = Object.freeze( {
isReady: false,
+ location: 'cart', // Which location is selected in the Styling tab.
} );
// Persistent: Values that are loaded from the DB.
From 2112769de9a7a0bfcc20549d4b0400fd6d9ae71f Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 19:29:16 +0100
Subject: [PATCH 24/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Restructure=20Stylin?=
=?UTF-8?q?g=20component=20files?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Styling/Content/ButtonColor.js | 21 +++
.../Components/Styling/Content/ButtonLabel.js | 21 +++
.../Styling/Content/ButtonLayout.js | 25 ++++
.../Components/Styling/Content/ButtonShape.js | 21 +++
.../Styling/{ => Content}/LocationSelector.js | 13 +-
.../Styling/Content/PaymentMethods.js | 21 +++
.../Components/Styling/Content/TagLine.js | 25 ++++
.../Components/Styling/Content/index.js | 7 +
.../Styling/{ => Layout}/StylingSection.js | 4 +-
.../StylingSectionWithCheckboxes.js | 4 +-
.../StylingSectionWithRadiobuttons.js | 2 +-
.../{ => Layout}/StylingSectionWithSelect.js | 0
.../Components/Styling/Layout/index.js | 4 +
.../Components/Styling/SettingsPanel.js | 127 +++---------------
14 files changed, 171 insertions(+), 124 deletions(-)
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js
rename modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/{ => Content}/LocationSelector.js (72%)
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js
rename modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/{ => Layout}/StylingSection.js (76%)
rename modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/{ => Layout}/StylingSectionWithCheckboxes.js (83%)
rename modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/{ => Layout}/StylingSectionWithRadiobuttons.js (92%)
rename modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/{ => Layout}/StylingSectionWithSelect.js (100%)
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/index.js
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js
new file mode 100644
index 000000000..acadc3943
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js
@@ -0,0 +1,21 @@
+import { __ } from '@wordpress/i18n';
+
+import { StylingHooks } from '../../../../../../data';
+import { SelectStylingSection } from '../Layout';
+
+const SectionButtonColor = ( { location } ) => {
+ const { color, setColor, colorChoices } =
+ StylingHooks.useStylingProps( location );
+
+ return (
+
+ );
+};
+
+export default SectionButtonColor;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js
new file mode 100644
index 000000000..a0763a049
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js
@@ -0,0 +1,21 @@
+import { __ } from '@wordpress/i18n';
+
+import { StylingHooks } from '../../../../../../data';
+import { SelectStylingSection } from '../Layout';
+
+const SectionButtonLabel = ( { location } ) => {
+ const { label, setLabel, labelChoices } =
+ StylingHooks.useStylingProps( location );
+
+ return (
+
+ );
+};
+
+export default SectionButtonLabel;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
new file mode 100644
index 000000000..0b6407ef1
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
@@ -0,0 +1,25 @@
+import { __ } from '@wordpress/i18n';
+
+import { StylingHooks } from '../../../../../../data';
+import { RadiobuttonStylingSection } from '../Layout';
+
+const SectionButtonLayout = ( { location } ) => {
+ const { supportsLayout, layout, setLayout, layoutChoices } =
+ StylingHooks.useStylingProps( location );
+
+ if ( ! supportsLayout ) {
+ return null;
+ }
+
+ return (
+
+ );
+};
+
+export default SectionButtonLayout;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js
new file mode 100644
index 000000000..68eaef1dc
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js
@@ -0,0 +1,21 @@
+import { __ } from '@wordpress/i18n';
+
+import { StylingHooks } from '../../../../../../data';
+import { RadiobuttonStylingSection } from '../Layout';
+
+const SectionButtonShape = ( { location } ) => {
+ const { shape, setShape, shapeChoices } =
+ StylingHooks.useStylingProps( location );
+
+ return (
+
+ );
+};
+
+export default SectionButtonShape;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js
similarity index 72%
rename from modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
rename to modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js
index 35c3a6efd..2fd21caa0 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/LocationSelector.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js
@@ -1,9 +1,8 @@
import { __, sprintf } from '@wordpress/i18n';
-import { StylingHooks } from '../../../../../data';
-import { Description } from '../../../../ReusableComponents/SettingsBlocks';
-import StylingSection from './StylingSection';
-import StylingSectionWithSelect from './StylingSectionWithSelect';
+import { StylingHooks } from '../../../../../../data';
+import { Description } from '../../../../../ReusableComponents/SettingsBlocks';
+import { SelectStylingSection, StylingSection } from '../Layout';
const LocationSelector = ( { location, setLocation } ) => {
const { locationChoices, locationDetails } =
@@ -22,9 +21,9 @@ const LocationSelector = ( { location, setLocation } ) => {
'woocommerce-paypal-payments'
) }
>
- {
{ locationDescription }
-
+
>
);
};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js
new file mode 100644
index 000000000..e379f876b
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js
@@ -0,0 +1,21 @@
+import { __ } from '@wordpress/i18n';
+
+import { StylingHooks } from '../../../../../../data';
+import { CheckboxStylingSection } from '../Layout';
+
+const SectionPaymentMethods = ( { location } ) => {
+ const { paymentMethods, setPaymentMethods, paymentMethodChoices } =
+ StylingHooks.useStylingProps( location );
+
+ return (
+
+ );
+};
+
+export default SectionPaymentMethods;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
new file mode 100644
index 000000000..66fa4cd1f
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
@@ -0,0 +1,25 @@
+import { __ } from '@wordpress/i18n';
+
+import { StylingHooks } from '../../../../../../data';
+import { CheckboxStylingSection } from '../Layout';
+
+const SectionTagline = ( { location } ) => {
+ const { supportsTagline, tagline, setTagline, taglineChoices } =
+ StylingHooks.useStylingProps( location );
+
+ if ( ! supportsTagline ) {
+ return null;
+ }
+
+ return (
+
+ );
+};
+
+export default SectionTagline;
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js
new file mode 100644
index 000000000..27a4e3d56
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js
@@ -0,0 +1,7 @@
+export { default as LocationSelector } from './LocationSelector';
+export { default as ButtonColor } from './ButtonColor';
+export { default as ButtonLabel } from './ButtonLabel';
+export { default as ButtonLayout } from './ButtonLayout';
+export { default as ButtonShape } from './ButtonShape';
+export { default as PaymentMethods } from './PaymentMethods';
+export { default as TagLine } from './TagLine';
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSection.js
similarity index 76%
rename from modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js
rename to modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSection.js
index 51290831a..e528361dc 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSection.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSection.js
@@ -1,9 +1,9 @@
-import SettingsBlock from '../../../../ReusableComponents/SettingsBlocks/SettingsBlock';
+import SettingsBlock from '../../../../../ReusableComponents/SettingsBlocks/SettingsBlock';
import {
Description,
Header,
Title,
-} from '../../../../ReusableComponents/SettingsBlocks';
+} from '../../../../../ReusableComponents/SettingsBlocks';
const StylingSection = ( {
title,
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithCheckboxes.js
similarity index 83%
rename from modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js
rename to modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithCheckboxes.js
index cc0b259d6..d3ca92db4 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithCheckboxes.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithCheckboxes.js
@@ -1,7 +1,7 @@
import classNames from 'classnames';
-import { CheckboxGroup } from '../../../../ReusableComponents/Fields';
-import HStack from '../../../../ReusableComponents/HStack';
+import { CheckboxGroup } from '../../../../../ReusableComponents/Fields';
+import HStack from '../../../../../ReusableComponents/HStack';
import StylingSection from './StylingSection';
const StylingSectionWithCheckboxes = ( {
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithRadiobuttons.js
similarity index 92%
rename from modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js
rename to modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithRadiobuttons.js
index 4bc33326f..337e2b30f 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithRadiobuttons.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithRadiobuttons.js
@@ -1,7 +1,7 @@
import { RadioControl } from '@wordpress/components';
import classNames from 'classnames';
-import HStack from '../../../../ReusableComponents/HStack';
+import HStack from '../../../../../ReusableComponents/HStack';
import StylingSection from './StylingSection';
const StylingSectionWithRadiobuttons = ( {
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithSelect.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithSelect.js
similarity index 100%
rename from modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/StylingSectionWithSelect.js
rename to modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/StylingSectionWithSelect.js
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/index.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/index.js
new file mode 100644
index 000000000..ea856552d
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Layout/index.js
@@ -0,0 +1,4 @@
+export { default as StylingSection } from './StylingSection';
+export { default as CheckboxStylingSection } from './StylingSectionWithCheckboxes';
+export { default as RadiobuttonStylingSection } from './StylingSectionWithRadiobuttons';
+export { default as SelectStylingSection } from './StylingSectionWithSelect';
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
index 4826632a9..ad65185cf 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
@@ -1,10 +1,13 @@
-import { __ } from '@wordpress/i18n';
-
import { StylingHooks } from '../../../../../data';
-import LocationSelector from './LocationSelector';
-import StylingSectionWithSelect from './StylingSectionWithSelect';
-import StylingSectionWithCheckboxes from './StylingSectionWithCheckboxes';
-import StylingSectionWithRadiobuttons from './StylingSectionWithRadiobuttons';
+import {
+ LocationSelector,
+ PaymentMethods,
+ ButtonLayout,
+ ButtonShape,
+ ButtonLabel,
+ ButtonColor,
+ TagLine,
+} from './Content';
const SettingsPanel = () => {
const { location, setLocation } = StylingHooks.useStylingLocation();
@@ -15,114 +18,14 @@ const SettingsPanel = () => {
location={ location }
setLocation={ setLocation }
/>
-
-
-
-
-
-
+
+
+
+
+
+
);
};
export default SettingsPanel;
-
-// -----
-
-const SectionPaymentMethods = ( { location } ) => {
- const { paymentMethods, setPaymentMethods, paymentMethodChoices } =
- StylingHooks.useStylingProps( location );
-
- return (
-
- );
-};
-
-const SectionButtonLayout = ( { location } ) => {
- const { supportsLayout, layout, setLayout, layoutChoices } =
- StylingHooks.useStylingProps( location );
-
- if ( ! supportsLayout ) {
- return null;
- }
-
- return (
-
- );
-};
-
-const SectionButtonShape = ( { location } ) => {
- const { shape, setShape, shapeChoices } =
- StylingHooks.useStylingProps( location );
-
- return (
-
- );
-};
-
-const SectionButtonLabel = ( { location } ) => {
- const { label, setLabel, labelChoices } =
- StylingHooks.useStylingProps( location );
-
- return (
-
- );
-};
-
-const SectionButtonColor = ( { location } ) => {
- const { color, setColor, colorChoices } =
- StylingHooks.useStylingProps( location );
-
- return (
-
- );
-};
-
-const SectionButtonTagline = ( { location } ) => {
- const { supportsTagline, tagline, setTagline, taglineChoices } =
- StylingHooks.useStylingProps( location );
-
- if ( ! supportsTagline ) {
- return null;
- }
-
- return (
-
- );
-};
From f7f140875da7ae6f16b1905c6f47232fb11a6af8 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 19:30:01 +0100
Subject: [PATCH 25/66] =?UTF-8?q?=F0=9F=92=84=20Improve=20UX=20and=20SCSS?=
=?UTF-8?q?=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../screens/settings/_tab-styling.scss | 33 ++++++++++++++-----
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
index d88fe64f7..cc60e1619 100644
--- a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
@@ -1,18 +1,30 @@
-$width-settings-panel: 422px;
-
.ppcp-r-styling {
--block-item-gap: 0;
--block-separator-gap: 24px;
--block-header-gap: 18px;
+ --panel-width: 422px;
+ --sticky-offset-top: 92px; // 32px admin-bar + 60px TopNavigation height
+ --preview-height-reduction: 236px; // 32px admin-bar + 60px TopNavigation height + 48px TopNavigation margin + 48px TabList height + 48px TabList margin
display: flex;
border: 1px solid var(--color-separators);
border-radius: 8px;
- overflow: hidden;
.ppcp-r-settings-block {
&.header-section {
- margin-bottom: 22px
+ margin-bottom: 6px
+ }
+
+ &.location-selector {
+ position: sticky;
+ top: var(--sticky-offset-top);
+ background: var(--ppcp-color-app-bg);
+ border-bottom: 1px solid var(--color-gray-200);
+ box-shadow: 0 5px 10px 5px var(--ppcp-color-app-bg);
+ z-index: 5;
+ padding-top: 16px;
+ padding-bottom: var(--block-separator-gap);
+ margin-bottom: -29px;
}
// Select-fields have a smaller gap between the header and input field.
@@ -28,7 +40,7 @@ $width-settings-panel: 422px;
/* The settings-panel (left side) */
.settings-panel {
- width: $width-settings-panel;
+ width: var(--panel-width);
padding: 48px;
.ppcp-r-styling__section {
@@ -52,14 +64,19 @@ $width-settings-panel: 422px;
/* The preview area (right side) */
.preview-panel {
- width: calc(100% - $width-settings-panel);
+ width: calc(100% - var(--panel-width));
background-color: var(--color-preview-background);
- display: flex;
- align-items: center;
+ z-index: 0;
.preview-panel-inner {
+ position: sticky;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
width: 100%;
padding: 24px;
+ height: calc(100vh - var(--preview-height-reduction));
+ top: var(--sticky-offset-top);
}
}
}
From 34cc8f8fab66ac1274c50bd631e801792f87b6ae Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 19:30:54 +0100
Subject: [PATCH 26/66] =?UTF-8?q?=F0=9F=9A=A7=20=20Prepare=20Redux=20integ?=
=?UTF-8?q?ration=20in=20hooks-file?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/hooks.js | 99 ++++++++++---------
1 file changed, 52 insertions(+), 47 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index e8863b3e3..7db797d3a 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -33,13 +33,51 @@ const useHooks = () => {
const [ location, setLocation ] = useTransient( 'location' );
// Persistent accessors.
- const [ shape, setShape ] = usePersistent( 'shape' );
+ // TODO - this is a dummy implementation.
+ const defaultStyle = {
+ paymentMethods: [],
+ color: 'gold',
+ shape: 'rect',
+ label: 'paypal',
+ layout: 'vertical',
+ tagline: false,
+ };
+
+ // This data-struct is already present in the Redux store via persistentData, e.g. "persistentData.cart.label"
+ const [ styles, setStyles ] = useState( {
+ cart: { ...defaultStyle, label: 'checkout' },
+ 'classic-checkout': { ...defaultStyle },
+ 'express-checkout': { ...defaultStyle, label: 'pay' },
+ 'mini-cart': { ...defaultStyle, label: 'pay' },
+ 'product-page': { ...defaultStyle },
+ } );
+
+ const getLocationProp = useCallback(
+ ( prop ) => styles[ location ]?.[ prop ],
+ [ location, styles ]
+ );
+
+ const setLocationProp = useCallback(
+ ( prop, value ) => {
+ setStyles( ( prevState ) => ( {
+ ...prevState,
+ [ location ]: {
+ ...prevState[ location ],
+ [ prop ]: value,
+ },
+ } ) );
+ },
+ [ location ]
+ );
+ // end of dummy implementation
return {
persist,
isReady,
location,
setLocation,
+ getLocationProp,
+ setLocationProp,
};
};
@@ -54,40 +92,7 @@ export const useStylingLocation = () => {
};
export const useStylingProps = ( location ) => {
- const defaultStyle = {
- paymentMethods: [],
- color: 'gold',
- shape: 'rect',
- label: 'paypal',
- layout: 'vertical',
- tagline: false,
- };
-
- const [ styles, setStyles ] = useState( {
- cart: { ...defaultStyle, label: 'checkout' },
- 'classic-checkout': { ...defaultStyle },
- 'express-checkout': { ...defaultStyle, label: 'pay' },
- 'mini-cart': { ...defaultStyle, label: 'pay' },
- 'product-page': { ...defaultStyle },
- } );
-
- const getLocationStyle = useCallback(
- ( prop ) => styles[ location ]?.[ prop ],
- [ location, styles ]
- );
-
- const setLocationStyle = useCallback(
- ( prop, value ) => {
- setStyles( ( prevState ) => ( {
- ...prevState,
- [ location ]: {
- ...prevState[ location ],
- [ prop ]: value,
- },
- } ) );
- },
- [ location ]
- );
+ const { getLocationProp, setLocationProp } = useHooks();
return {
// Location (drop down).
@@ -96,30 +101,30 @@ export const useStylingProps = ( location ) => {
// Payment methods (checkboxes).
paymentMethodChoices: Object.values( STYLING_PAYMENT_METHODS ),
- paymentMethods: getLocationStyle( 'paymentMethods' ),
+ paymentMethods: getLocationProp( 'paymentMethods' ),
setPaymentMethods: ( methods ) =>
- setLocationStyle( 'paymentMethods', methods ),
+ setLocationProp( 'paymentMethods', methods ),
// Color (dropdown).
colorChoices: Object.values( STYLING_COLORS ),
- color: getLocationStyle( 'color' ),
- setColor: ( color ) => setLocationStyle( 'color', color ),
+ color: getLocationProp( 'color' ),
+ setColor: ( color ) => setLocationProp( 'color', color ),
// Shape (radio).
shapeChoices: Object.values( STYLING_SHAPES ),
- shape: getLocationStyle( 'shape' ),
- setShape: ( shape ) => setLocationStyle( 'shape', shape ),
+ shape: getLocationProp( 'shape' ),
+ setShape: ( shape ) => setLocationProp( 'shape', shape ),
// Label (dropdown).
labelChoices: Object.values( STYLING_LABELS ),
- label: getLocationStyle( 'label' ),
- setLabel: ( label ) => setLocationStyle( 'label', label ),
+ label: getLocationProp( 'label' ),
+ setLabel: ( label ) => setLocationProp( 'label', label ),
// Layout (radio).
layoutChoices: Object.values( STYLING_LAYOUTS ),
supportsLayout: true,
- layout: getLocationStyle( 'layout' ),
- setLayout: ( layout ) => setLocationStyle( 'layout', layout ),
+ layout: getLocationProp( 'layout' ),
+ setLayout: ( layout ) => setLocationProp( 'layout', layout ),
// Tagline (checkbox).
taglineChoices: [
@@ -129,7 +134,7 @@ export const useStylingProps = ( location ) => {
},
],
supportsTagline: true,
- tagline: getLocationStyle( 'tagline' ),
- setTagline: ( tagline ) => setLocationStyle( 'tagline', tagline ),
+ tagline: getLocationProp( 'tagline' ),
+ setTagline: ( tagline ) => setLocationProp( 'tagline', tagline ),
};
};
From 033b6e5b74ca2194e7c1b5bf470bf6d03610eb72 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 20:01:22 +0100
Subject: [PATCH 27/66] =?UTF-8?q?=E2=9C=A8=20Move=20styling=20options=20to?=
=?UTF-8?q?=20Redux=20store!?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/hooks.js | 46 +++++++------------
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 7db797d3a..5cf07655e 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -8,8 +8,8 @@
*/
import { __ } from '@wordpress/i18n';
-import { useCallback, useState } from '@wordpress/element'; // Temporary
-import { useDispatch } from '@wordpress/data';
+import { useCallback } from '@wordpress/element'; // Temporary
+import { useDispatch, useSelect } from '@wordpress/data';
import { createHooksForStore } from '../utils';
import { STORE_NAME } from './constants';
@@ -33,43 +33,29 @@ const useHooks = () => {
const [ location, setLocation ] = useTransient( 'location' );
// Persistent accessors.
- // TODO - this is a dummy implementation.
- const defaultStyle = {
- paymentMethods: [],
- color: 'gold',
- shape: 'rect',
- label: 'paypal',
- layout: 'vertical',
- tagline: false,
- };
+ const persistentData = useSelect(
+ ( select ) => select( STORE_NAME ).persistentData(),
+ []
+ );
- // This data-struct is already present in the Redux store via persistentData, e.g. "persistentData.cart.label"
- const [ styles, setStyles ] = useState( {
- cart: { ...defaultStyle, label: 'checkout' },
- 'classic-checkout': { ...defaultStyle },
- 'express-checkout': { ...defaultStyle, label: 'pay' },
- 'mini-cart': { ...defaultStyle, label: 'pay' },
- 'product-page': { ...defaultStyle },
- } );
+ const [ locationStyles, setLocationStyles ] = usePersistent( location );
const getLocationProp = useCallback(
- ( prop ) => styles[ location ]?.[ prop ],
- [ location, styles ]
+ ( prop ) => {
+ return persistentData[ location ]?.[ prop ];
+ },
+ [ location, persistentData ]
);
const setLocationProp = useCallback(
( prop, value ) => {
- setStyles( ( prevState ) => ( {
- ...prevState,
- [ location ]: {
- ...prevState[ location ],
- [ prop ]: value,
- },
- } ) );
+ setLocationStyles( {
+ ...locationStyles,
+ [ prop ]: value,
+ } );
},
- [ location ]
+ [ locationStyles, setLocationStyles ]
);
- // end of dummy implementation
return {
persist,
From dac414433fffc8feda3b224f6fd97afdfbf19438 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 20:02:37 +0100
Subject: [PATCH 28/66] =?UTF-8?q?=F0=9F=A5=85=20Add=20detection=20for=20ac?=
=?UTF-8?q?cessing=20undefined=20props?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/styling/hooks.js | 5 +++++
modules/ppcp-settings/resources/js/data/utils.js | 8 +++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 5cf07655e..cb0508247 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -42,6 +42,11 @@ const useHooks = () => {
const getLocationProp = useCallback(
( prop ) => {
+ if ( undefined === persistentData[ location ]?.[ prop ] ) {
+ console.error(
+ `Trying to access non-existent style property: ${ location }.${ prop }. Possibly wrong style name - review the reducer.`
+ );
+ }
return persistentData[ location ]?.[ prop ];
},
[ location, persistentData ]
diff --git a/modules/ppcp-settings/resources/js/data/utils.js b/modules/ppcp-settings/resources/js/data/utils.js
index 35d7bbbf9..7d3a14af7 100644
--- a/modules/ppcp-settings/resources/js/data/utils.js
+++ b/modules/ppcp-settings/resources/js/data/utils.js
@@ -107,7 +107,13 @@ export const createHooksForStore = ( storeName ) => {
`Please create the selector "${ selector }" for store "${ storeName }"`
);
}
- return store[ selector ]()?.[ key ];
+ const selectorResult = store[ selector ]();
+ if ( undefined === selectorResult?.[ key ] ) {
+ console.error(
+ `Warning: ${ selector }()[${ key }] is undefined in store "${ storeName }". This may indicate a bug.`
+ );
+ }
+ return selectorResult?.[ key ];
},
[ key ]
);
From e5f882cc57904dba2d969226c2741b694cca47fe Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 20:04:20 +0100
Subject: [PATCH 29/66] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Fix=20issues=20in?=
=?UTF-8?q?=20the=20defaultPersistent=20store?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/reducer.js | 50 ++++++++++++-------
1 file changed, 33 insertions(+), 17 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/reducer.js b/modules/ppcp-settings/resources/js/data/styling/reducer.js
index ec432081f..7c553091e 100644
--- a/modules/ppcp-settings/resources/js/data/styling/reducer.js
+++ b/modules/ppcp-settings/resources/js/data/styling/reducer.js
@@ -9,53 +9,69 @@
import { createReducer, createSetters } from '../utils';
import ACTION_TYPES from './action-types';
-import { STYLING_COLORS, STYLING_SHAPES } from './configuration';
+import {
+ STYLING_COLORS,
+ STYLING_LABELS,
+ STYLING_LAYOUTS,
+ STYLING_LOCATIONS,
+ STYLING_SHAPES,
+} from './configuration';
// Store structure.
// Transient: Values that are _not_ saved to the DB (like app lifecycle-flags).
const defaultTransient = Object.freeze( {
isReady: false,
- location: 'cart', // Which location is selected in the Styling tab.
+ location: STYLING_LOCATIONS.cart.value, // Which location is selected in the Styling tab.
} );
// Persistent: Values that are loaded from the DB.
const defaultPersistent = Object.freeze( {
- cart: {
+ [ STYLING_LOCATIONS.cart.value ]: Object.freeze( {
enabled: true,
methods: [],
- label: 'Pay',
+ label: STYLING_LABELS.pay.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- },
- 'classic-checkout': {
+ layout: STYLING_LAYOUTS.vertical.value,
+ tagline: false,
+ } ),
+ [ STYLING_LOCATIONS[ 'classic-checkout' ].value ]: Object.freeze( {
enabled: true,
methods: [],
- label: 'Checkout',
+ label: STYLING_LABELS.checkout.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- },
- 'express-checkout': {
+ layout: STYLING_LAYOUTS.vertical.value,
+ tagline: false,
+ } ),
+ [ STYLING_LOCATIONS[ 'express-checkout' ].value ]: Object.freeze( {
enabled: true,
methods: [],
- label: 'Checkout',
+ label: STYLING_LABELS.checkout.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- },
- 'mini-cart': {
+ layout: STYLING_LAYOUTS.vertical.value,
+ tagline: false,
+ } ),
+ [ STYLING_LOCATIONS[ 'mini-cart' ].value ]: Object.freeze( {
enabled: true,
methods: [],
- label: 'Pay',
+ label: STYLING_LABELS.pay.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- },
- product: {
+ layout: STYLING_LAYOUTS.vertical.value,
+ tagline: false,
+ } ),
+ [ STYLING_LOCATIONS.product.value ]: Object.freeze( {
enabled: true,
methods: [],
- label: 'Buy',
+ label: STYLING_LABELS.buynow.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- },
+ layout: STYLING_LAYOUTS.vertical.value,
+ tagline: false,
+ } ),
} );
// Reducer logic.
From 510a711caa58fb142a827f73734d038b86b7d88a Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 20:04:47 +0100
Subject: [PATCH 30/66] =?UTF-8?q?=F0=9F=90=9B=20Fix=20inconsistent=20prope?=
=?UTF-8?q?rty=20names?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/configuration.js | 12 ++++++------
.../ppcp-settings/resources/js/data/styling/hooks.js | 5 ++---
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/configuration.js b/modules/ppcp-settings/resources/js/data/styling/configuration.js
index 861379e2d..ecb7a3765 100644
--- a/modules/ppcp-settings/resources/js/data/styling/configuration.js
+++ b/modules/ppcp-settings/resources/js/data/styling/configuration.js
@@ -47,8 +47,8 @@ export const STYLING_LOCATIONS = {
),
link: '#',
},
- 'product-page': {
- value: 'product-page',
+ product: {
+ value: 'product',
label: __( 'Product Page', 'woocommerce-paypal-payments' ),
// translators: %s is the URL to a documentation page.
description: __(
@@ -113,14 +113,14 @@ export const STYLING_LAYOUTS = {
};
export const STYLING_SHAPES = {
- pill: {
- value: 'pill',
- label: __( 'Pill', 'woocommerce-paypal-payments' ),
- },
rect: {
value: 'rect',
label: __( 'Rectangle', 'woocommerce-paypal-payments' ),
},
+ pill: {
+ value: 'pill',
+ label: __( 'Pill', 'woocommerce-paypal-payments' ),
+ },
};
export const STYLING_PAYMENT_METHODS = {
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index cb0508247..d81ee8746 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -92,9 +92,8 @@ export const useStylingProps = ( location ) => {
// Payment methods (checkboxes).
paymentMethodChoices: Object.values( STYLING_PAYMENT_METHODS ),
- paymentMethods: getLocationProp( 'paymentMethods' ),
- setPaymentMethods: ( methods ) =>
- setLocationProp( 'paymentMethods', methods ),
+ paymentMethods: getLocationProp( 'methods' ),
+ setPaymentMethods: ( methods ) => setLocationProp( 'methods', methods ),
// Color (dropdown).
colorChoices: Object.values( STYLING_COLORS ),
From a5ceec2af43361920edac4dd50f8d1f12c168bb6 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 17 Jan 2025 13:04:21 +0100
Subject: [PATCH 31/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Location-prop=20acce?=
=?UTF-8?q?ssors=20require=20a=20location=20arg?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Instead of using the “location” property, we want to explicitly specify which location props to access
---
.../resources/js/data/styling/hooks.js | 28 +++++++++----------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index d81ee8746..946aa4cc7 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -23,8 +23,8 @@ import {
} from './configuration';
const useHooks = () => {
- const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
- const { persist } = useDispatch( STORE_NAME );
+ const { useTransient } = createHooksForStore( STORE_NAME );
+ const { persist, setPersistent } = useDispatch( STORE_NAME );
// Read-only flags and derived state.
@@ -38,28 +38,28 @@ const useHooks = () => {
[]
);
- const [ locationStyles, setLocationStyles ] = usePersistent( location );
-
const getLocationProp = useCallback(
- ( prop ) => {
- if ( undefined === persistentData[ location ]?.[ prop ] ) {
+ ( locatonId, prop ) => {
+ if ( undefined === persistentData[ locatonId ]?.[ prop ] ) {
console.error(
- `Trying to access non-existent style property: ${ location }.${ prop }. Possibly wrong style name - review the reducer.`
+ `Trying to access non-existent style property: ${ locatonId }.${ prop }. Possibly wrong style name - review the reducer.`
);
}
- return persistentData[ location ]?.[ prop ];
+ return persistentData[ locatonId ]?.[ prop ];
},
- [ location, persistentData ]
+ [ persistentData ]
);
const setLocationProp = useCallback(
- ( prop, value ) => {
- setLocationStyles( {
- ...locationStyles,
+ ( locationId, prop, value ) => {
+ const updatedStyles = {
+ ...persistentData[ locationId ],
[ prop ]: value,
- } );
+ };
+
+ setPersistent( locationId, updatedStyles );
},
- [ locationStyles, setLocationStyles ]
+ [ persistentData, setPersistent ]
);
return {
From 18429d91e5d87edd5613d760a0d3e15c94860510 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 17 Jan 2025 13:05:25 +0100
Subject: [PATCH 32/66] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Split=20the=20stylin?=
=?UTF-8?q?g=20hook=20into=20multiple=20hook?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Styling/Content/ButtonColor.js | 5 +-
.../Components/Styling/Content/ButtonLabel.js | 5 +-
.../Styling/Content/ButtonLayout.js | 8 +-
.../Components/Styling/Content/ButtonShape.js | 5 +-
.../Styling/Content/LocationSelector.js | 13 +--
.../Styling/Content/PaymentMethods.js | 6 +-
.../Components/Styling/Content/TagLine.js | 8 +-
.../Components/Styling/Content/index.js | 2 +-
.../Components/Styling/SettingsPanel.js | 4 +-
.../resources/js/data/styling/hooks.js | 97 +++++++++++++------
10 files changed, 90 insertions(+), 63 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js
index acadc3943..29b98069c 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonColor.js
@@ -4,14 +4,13 @@ import { StylingHooks } from '../../../../../../data';
import { SelectStylingSection } from '../Layout';
const SectionButtonColor = ( { location } ) => {
- const { color, setColor, colorChoices } =
- StylingHooks.useStylingProps( location );
+ const { color, setColor, choices } = StylingHooks.useColorProps( location );
return (
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js
index a0763a049..de7c1a103 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLabel.js
@@ -4,14 +4,13 @@ import { StylingHooks } from '../../../../../../data';
import { SelectStylingSection } from '../Layout';
const SectionButtonLabel = ( { location } ) => {
- const { label, setLabel, labelChoices } =
- StylingHooks.useStylingProps( location );
+ const { label, setLabel, choices } = StylingHooks.useLabelProps( location );
return (
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
index 0b6407ef1..1acf666f9 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
@@ -4,10 +4,10 @@ import { StylingHooks } from '../../../../../../data';
import { RadiobuttonStylingSection } from '../Layout';
const SectionButtonLayout = ( { location } ) => {
- const { supportsLayout, layout, setLayout, layoutChoices } =
- StylingHooks.useStylingProps( location );
+ const { isAvailable, layout, setLayout, choices } =
+ StylingHooks.useLayoutProps( location );
- if ( ! supportsLayout ) {
+ if ( ! isAvailable ) {
return null;
}
@@ -15,7 +15,7 @@ const SectionButtonLayout = ( { location } ) => {
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js
index 68eaef1dc..71bc5bebe 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonShape.js
@@ -4,14 +4,13 @@ import { StylingHooks } from '../../../../../../data';
import { RadiobuttonStylingSection } from '../Layout';
const SectionButtonShape = ( { location } ) => {
- const { shape, setShape, shapeChoices } =
- StylingHooks.useStylingProps( location );
+ const { shape, setShape, choices } = StylingHooks.useShapeProps( location );
return (
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js
index 2fd21caa0..f5d8231b8 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/LocationSelector.js
@@ -1,14 +1,11 @@
-import { __, sprintf } from '@wordpress/i18n';
+import { __ } from '@wordpress/i18n';
import { StylingHooks } from '../../../../../../data';
import { Description } from '../../../../../ReusableComponents/SettingsBlocks';
import { SelectStylingSection, StylingSection } from '../Layout';
const LocationSelector = ( { location, setLocation } ) => {
- const { locationChoices, locationDetails } =
- StylingHooks.useStylingProps( location );
- const { description, link } = locationDetails || {};
- const locationDescription = sprintf( description, link );
+ const { choices, description } = StylingHooks.useLocationProps( location );
return (
<>
@@ -25,13 +22,11 @@ const LocationSelector = ( { location, setLocation } ) => {
className="location-selector"
title={ __( 'Location', 'woocommerce-paypal-payments' ) }
separatorAndGap={ false }
- options={ locationChoices }
+ options={ choices }
value={ location }
onChange={ setLocation }
>
-
- { locationDescription }
-
+ { description }
>
);
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js
index e379f876b..0397d34c3 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/PaymentMethods.js
@@ -4,14 +4,14 @@ import { StylingHooks } from '../../../../../../data';
import { CheckboxStylingSection } from '../Layout';
const SectionPaymentMethods = ( { location } ) => {
- const { paymentMethods, setPaymentMethods, paymentMethodChoices } =
- StylingHooks.useStylingProps( location );
+ const { paymentMethods, setPaymentMethods, choices } =
+ StylingHooks.usePaymentMethodProps( location );
return (
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
index 66fa4cd1f..ec292455c 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
@@ -4,10 +4,10 @@ import { StylingHooks } from '../../../../../../data';
import { CheckboxStylingSection } from '../Layout';
const SectionTagline = ( { location } ) => {
- const { supportsTagline, tagline, setTagline, taglineChoices } =
- StylingHooks.useStylingProps( location );
+ const { isAvailable, tagline, setTagline, choices } =
+ StylingHooks.useTaglineProps( location );
- if ( ! supportsTagline ) {
+ if ( ! isAvailable ) {
return null;
}
@@ -15,7 +15,7 @@ const SectionTagline = ( { location } ) => {
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js
index 27a4e3d56..4529fb9eb 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/index.js
@@ -4,4 +4,4 @@ export { default as ButtonLabel } from './ButtonLabel';
export { default as ButtonLayout } from './ButtonLayout';
export { default as ButtonShape } from './ButtonShape';
export { default as PaymentMethods } from './PaymentMethods';
-export { default as TagLine } from './TagLine';
+export { default as Tagline } from './Tagline';
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
index ad65185cf..9151781f7 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/SettingsPanel.js
@@ -6,7 +6,7 @@ import {
ButtonShape,
ButtonLabel,
ButtonColor,
- TagLine,
+ Tagline,
} from './Content';
const SettingsPanel = () => {
@@ -23,7 +23,7 @@ const SettingsPanel = () => {
-
+
);
};
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 946aa4cc7..2e77d41f2 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -7,7 +7,7 @@
* @file
*/
-import { __ } from '@wordpress/i18n';
+import { __, sprintf } from '@wordpress/i18n';
import { useCallback } from '@wordpress/element'; // Temporary
import { useDispatch, useSelect } from '@wordpress/data';
@@ -82,49 +82,84 @@ export const useStylingLocation = () => {
return { location, setLocation };
};
-export const useStylingProps = ( location ) => {
+export const useLocationProps = ( location ) => {
+ const details = STYLING_LOCATIONS[ location ] ?? {};
+
+ // eslint-disable-next-line @wordpress/valid-sprintf
+ const description = sprintf( details.description ?? '', details.link );
+
+ return {
+ choices: Object.values( STYLING_LOCATIONS ),
+ details,
+ description,
+ };
+};
+
+export const usePaymentMethodProps = ( location ) => {
const { getLocationProp, setLocationProp } = useHooks();
return {
- // Location (drop down).
- locationChoices: Object.values( STYLING_LOCATIONS ),
- locationDetails: STYLING_LOCATIONS[ location ],
+ choices: Object.values( STYLING_PAYMENT_METHODS ),
+ paymentMethods: getLocationProp( location, 'methods' ),
+ setPaymentMethods: ( methods ) =>
+ setLocationProp( location, 'methods', methods ),
+ };
+};
- // Payment methods (checkboxes).
- paymentMethodChoices: Object.values( STYLING_PAYMENT_METHODS ),
- paymentMethods: getLocationProp( 'methods' ),
- setPaymentMethods: ( methods ) => setLocationProp( 'methods', methods ),
+export const useColorProps = ( location ) => {
+ const { getLocationProp, setLocationProp } = useHooks();
- // Color (dropdown).
- colorChoices: Object.values( STYLING_COLORS ),
- color: getLocationProp( 'color' ),
- setColor: ( color ) => setLocationProp( 'color', color ),
+ return {
+ choices: Object.values( STYLING_COLORS ),
+ color: getLocationProp( location, 'color' ),
+ setColor: ( color ) => setLocationProp( location, 'color', color ),
+ };
+};
- // Shape (radio).
- shapeChoices: Object.values( STYLING_SHAPES ),
- shape: getLocationProp( 'shape' ),
- setShape: ( shape ) => setLocationProp( 'shape', shape ),
+export const useShapeProps = ( location ) => {
+ const { getLocationProp, setLocationProp } = useHooks();
- // Label (dropdown).
- labelChoices: Object.values( STYLING_LABELS ),
- label: getLocationProp( 'label' ),
- setLabel: ( label ) => setLocationProp( 'label', label ),
+ return {
+ choices: Object.values( STYLING_SHAPES ),
+ shape: getLocationProp( location, 'shape' ),
+ setShape: ( shape ) => setLocationProp( location, 'shape', shape ),
+ };
+};
- // Layout (radio).
- layoutChoices: Object.values( STYLING_LAYOUTS ),
- supportsLayout: true,
- layout: getLocationProp( 'layout' ),
- setLayout: ( layout ) => setLocationProp( 'layout', layout ),
+export const useLabelProps = ( location ) => {
+ const { getLocationProp, setLocationProp } = useHooks();
- // Tagline (checkbox).
- taglineChoices: [
+ return {
+ choices: Object.values( STYLING_LABELS ),
+ label: getLocationProp( location, 'label' ),
+ setLabel: ( label ) => setLocationProp( location, 'label', label ),
+ };
+};
+
+export const useLayoutProps = ( location ) => {
+ const { getLocationProp, setLocationProp } = useHooks();
+
+ return {
+ choices: Object.values( STYLING_LAYOUTS ),
+ isAvailable: true,
+ layout: getLocationProp( location, 'layout' ),
+ setLayout: ( layout ) => setLocationProp( location, 'layout', layout ),
+ };
+};
+
+export const useTaglineProps = ( location ) => {
+ const { getLocationProp, setLocationProp } = useHooks();
+
+ return {
+ choices: [
{
value: 'tagline',
label: __( 'Enable Tagline', 'woocommerce-paypal-payments' ),
},
],
- supportsTagline: true,
- tagline: getLocationProp( 'tagline' ),
- setTagline: ( tagline ) => setLocationProp( 'tagline', tagline ),
+ isAvailable: true,
+ tagline: getLocationProp( location, 'tagline' ),
+ setTagline: ( tagline ) =>
+ setLocationProp( location, 'tagline', tagline ),
};
};
From 4b47084aa20c96dcba52bc9e5e202fae5b61e1cf Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 17 Jan 2025 13:20:15 +0100
Subject: [PATCH 33/66] =?UTF-8?q?=F0=9F=92=84=20Make=20disabled=20option?=
=?UTF-8?q?=20more=20distinct?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/css/_mixins.scss | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/css/_mixins.scss b/modules/ppcp-settings/resources/css/_mixins.scss
index 29cb3af1c..8c83eb436 100644
--- a/modules/ppcp-settings/resources/css/_mixins.scss
+++ b/modules/ppcp-settings/resources/css/_mixins.scss
@@ -49,7 +49,7 @@
.components-#{$control-type}-control__input,
.components-#{$control-type}-control__label,
.components-base-control__help {
- opacity: 0.5;
+ opacity: 0.3;
cursor: default;
}
}
From 0428dd08aa0be410b500c6bf6f67fa79e6707165 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 17 Jan 2025 13:20:58 +0100
Subject: [PATCH 34/66] =?UTF-8?q?=E2=9C=A8=20Add=20location-specific=20con?=
=?UTF-8?q?figuration?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/styling/configuration.js | 5 +++++
modules/ppcp-settings/resources/js/data/styling/hooks.js | 9 +++++++--
.../ppcp-settings/resources/js/data/styling/reducer.js | 4 ----
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/configuration.js b/modules/ppcp-settings/resources/js/data/styling/configuration.js
index ecb7a3765..eef2f90bf 100644
--- a/modules/ppcp-settings/resources/js/data/styling/configuration.js
+++ b/modules/ppcp-settings/resources/js/data/styling/configuration.js
@@ -16,6 +16,7 @@ export const STYLING_LOCATIONS = {
'wooocommerce-paypal-payments'
),
link: '#',
+ props: { layout: false, tagline: false },
},
'classic-checkout': {
value: 'classic-checkout',
@@ -26,6 +27,7 @@ export const STYLING_LOCATIONS = {
'wooocommerce-paypal-payments'
),
link: '#',
+ props: { layout: true, tagline: true },
},
'express-checkout': {
value: 'express-checkout',
@@ -36,6 +38,7 @@ export const STYLING_LOCATIONS = {
'wooocommerce-paypal-payments'
),
link: '#',
+ props: { layout: false, tagline: false },
},
'mini-cart': {
value: 'mini-cart',
@@ -46,6 +49,7 @@ export const STYLING_LOCATIONS = {
'wooocommerce-paypal-payments'
),
link: '#',
+ props: { layout: true, tagline: true },
},
product: {
value: 'product',
@@ -56,6 +60,7 @@ export const STYLING_LOCATIONS = {
'wooocommerce-paypal-payments'
),
link: '#',
+ props: { layout: true, tagline: true },
},
};
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 2e77d41f2..f2bee3952 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -138,10 +138,11 @@ export const useLabelProps = ( location ) => {
export const useLayoutProps = ( location ) => {
const { getLocationProp, setLocationProp } = useHooks();
+ const { details } = useLocationProps( location );
return {
choices: Object.values( STYLING_LAYOUTS ),
- isAvailable: true,
+ isAvailable: false !== details.props.layout,
layout: getLocationProp( location, 'layout' ),
setLayout: ( layout ) => setLocationProp( location, 'layout', layout ),
};
@@ -149,6 +150,7 @@ export const useLayoutProps = ( location ) => {
export const useTaglineProps = ( location ) => {
const { getLocationProp, setLocationProp } = useHooks();
+ const { details } = useLocationProps( location );
return {
choices: [
@@ -157,7 +159,10 @@ export const useTaglineProps = ( location ) => {
label: __( 'Enable Tagline', 'woocommerce-paypal-payments' ),
},
],
- isAvailable: true,
+ isAvailable:
+ false !== details.props.tagline &&
+ STYLING_LAYOUTS.horizontal.value ===
+ getLocationProp( location, 'layout' ),
tagline: getLocationProp( location, 'tagline' ),
setTagline: ( tagline ) =>
setLocationProp( location, 'tagline', tagline ),
diff --git a/modules/ppcp-settings/resources/js/data/styling/reducer.js b/modules/ppcp-settings/resources/js/data/styling/reducer.js
index 7c553091e..e41cd1e40 100644
--- a/modules/ppcp-settings/resources/js/data/styling/reducer.js
+++ b/modules/ppcp-settings/resources/js/data/styling/reducer.js
@@ -33,8 +33,6 @@ const defaultPersistent = Object.freeze( {
label: STYLING_LABELS.pay.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- layout: STYLING_LAYOUTS.vertical.value,
- tagline: false,
} ),
[ STYLING_LOCATIONS[ 'classic-checkout' ].value ]: Object.freeze( {
enabled: true,
@@ -51,8 +49,6 @@ const defaultPersistent = Object.freeze( {
label: STYLING_LABELS.checkout.value,
shape: STYLING_SHAPES.rect.value,
color: STYLING_COLORS.gold.value,
- layout: STYLING_LAYOUTS.vertical.value,
- tagline: false,
} ),
[ STYLING_LOCATIONS[ 'mini-cart' ].value ]: Object.freeze( {
enabled: true,
From 00c00bf9b1719caccef534cd6af8869ceef99df0 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 17 Jan 2025 13:27:31 +0100
Subject: [PATCH 35/66] =?UTF-8?q?=F0=9F=92=84=20Improvement=20UX=20for=20t?=
=?UTF-8?q?he=20=E2=80=9Ctagline=E2=80=9D=20option?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../screens/settings/_tab-styling.scss | 5 +++++
.../Components/Styling/Content/ButtonLayout.js | 18 +++++++++++-------
.../Components/Styling/Content/TagLine.js | 2 +-
.../Components/Styling/SettingsPanel.js | 2 --
.../resources/js/data/styling/hooks.js | 5 ++++-
5 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
index cc60e1619..071855a64 100644
--- a/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/settings/_tab-styling.scss
@@ -36,6 +36,11 @@
&.payment-methods {
--block-separator-gap: 28px;
}
+
+ // It has no header; adjusts the gap to the control right above the tagline.
+ &.tagline {
+ --block-header-gap: 24px;
+ }
}
/* The settings-panel (left side) */
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
index 1acf666f9..1a284f72a 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/ButtonLayout.js
@@ -2,6 +2,7 @@ import { __ } from '@wordpress/i18n';
import { StylingHooks } from '../../../../../../data';
import { RadiobuttonStylingSection } from '../Layout';
+import { Tagline } from './index';
const SectionButtonLayout = ( { location } ) => {
const { isAvailable, layout, setLayout, choices } =
@@ -12,13 +13,16 @@ const SectionButtonLayout = ( { location } ) => {
}
return (
-
+ <>
+
+
+ >
);
};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
index ec292455c..54d823b22 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Styling/Content/TagLine.js
@@ -13,8 +13,8 @@ const SectionTagline = ( { location } ) => {
return (
{
@@ -23,7 +22,6 @@ const SettingsPanel = () => {
-
);
};
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index f2bee3952..2767698d5 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -156,7 +156,10 @@ export const useTaglineProps = ( location ) => {
choices: [
{
value: 'tagline',
- label: __( 'Enable Tagline', 'woocommerce-paypal-payments' ),
+ label: __(
+ 'Show tagline below buttons',
+ 'woocommerce-paypal-payments'
+ ),
},
],
isAvailable:
From 6993038c053b158fe280b19028eb79edc55a7595 Mon Sep 17 00:00:00 2001
From: Daniel Dudzic