Skip to content

Commit

Permalink
🚧 Refactor the Styling tab
Browse files Browse the repository at this point in the history
  • Loading branch information
stracker-phil committed Jan 15, 2025
1 parent e9644ba commit 4913527
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 343 deletions.
2 changes: 2 additions & 0 deletions modules/ppcp-settings/resources/css/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ $card-vertical-gap: 48px;
--color-gray-100: #{$color-gray-100};
--color-gradient-dark: #{$color-gradient-dark};

--color-preview-background: #FAF8F5;
--color-separators: #{$color-gray-200};
--color-text-title: #{$color-gray-900};
--color-text-main: #{$color-text-text};
--color-text-teriary: #{$color-text-tertiary};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.ppcp-r-paylater-configurator {
display: flex;
border: 1px solid $color-gray-200;
border: 1px solid var(--color-separators);
border-radius: 8px;
overflow: hidden;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
$width-settings-panel: 422px;

.ppcp-r-styling {
display: flex;
border: 1px solid $color-gray-200;
border: 1px solid var(--color-separators);
border-radius: 8px;
overflow: hidden;

&__section:not(:last-child) {
border-bottom: 1px solid black;
padding-bottom: 24px;
margin-bottom: 28px;
border-bottom: 1px solid $color-gray-600;
}
.ppcp-r-styling__title {
@include font(14, 16, 600);

&__main-title {
@include font(14, 20, 600);
color: $color-gray-800;
margin: 0 0 8px 0;
color: var(--color-text-title);
display: block;
margin: 0 0 18px 0;
}

&__description {
@include font(13, 20, 400);
color: $color-gray-800;
margin: 0 0 18px 0;
.header-section .ppcp-r-styling__title {
@include font(16, 20, 600);
}

&__settings {
width: 422px;
background-color: $color-white;
/* The settings-panel (left side) */
.settings-panel {
width: $width-settings-panel;
padding: 48px;

.ppcp-r-styling__section {
padding-bottom: 24px;
margin-bottom: 28px;
border-bottom: 1px solid var(--color-separators);
}
}

&__preview {
width: calc(100% - 422px);
background-color: #FAF8F5;
/* The preview area (right side) */
.preview-panel {
width: calc(100% - $width-settings-panel);
background-color: var(--color-preview-background);
display: flex;
align-items: center;

&-inner {
.preview-panel-inner {
width: 100%;
padding: 24px;
}
}

&__section--rc {
.ppcp-r-styling__title {
@include font(13, 20, 600);
color: $color-black;
display: block;
margin: 0 0 18px 0;
}
}

&__section--empty.ppcp-r-styling__section {
padding-bottom: 0;
margin-bottom: 0;
border-bottom: none;
}
/* --- *
&__select {
label {
Expand Down Expand Up @@ -118,4 +106,5 @@
}
}
}
// */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { SelectControl } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

import StylingSection from './StylingSection';

const LocationSelector = ( { choices = [], location, setLocation } ) => {
// TODO. move to store/hook.
const locationData = choices.find(
( choice ) => choice.value === location
);
const { description, link } = locationData || {};
const locationDescription = sprintf( description, link );

return (
<StylingSection
className="header-section"
title={ __( 'Button Styling', 'wooocommerce-paypal-payments' ) }
description={ __(
'Customize the appearance of the PayPal smart buttons on your website and choose which payment buttons to display.',
'woocommerce-paypal-payments'
) }
>
<SelectControl
className="ppcp-r-styling__select"
label={ __( 'Locations', 'woocommerce-paypal-payments' ) }
value={ location }
options={ choices }
onChange={ ( choice ) => setLocation( choice ) }
/>
<p dangerouslySetInnerHTML={ { __html: locationDescription } } />
</StylingSection>
);
};

export default LocationSelector;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PaymentButtonPreview from '../PaymentButtonPreview';

const PreviewPanel = ( { settings } ) => (
<div className="preview-panel">
<div className="preview-panel-inner">
<PaymentButtonPreview style={ settings } />
</div>
</div>
);

export default PreviewPanel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { RadioControl, SelectControl } from '@wordpress/components';

import { STYLING_LOCATIONS } from '../../../../../data';
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 = () => {};

return (
<div className="settings-panel">
<LocationSelector
choices={ Object.values( STYLING_LOCATIONS ) }
location={ location }
setLocation={ setLocation }
/>

<SectionPaymentMethods
locationSettings={ currentLocationSettings }
updateButtonSettings={ handleChange }
/>

<SectionButtonLayout
locationSettings={ currentLocationSettings }
updateButtonStyle={ handleChange }
/>

<SectionButtonShape
locationSettings={ currentLocationSettings }
updateButtonStyle={ handleChange }
/>
<SectionButtonLabel
locationSettings={ currentLocationSettings }
updateButtonStyle={ handleChange }
/>
<SectionButtonColor
locationSettings={ currentLocationSettings }
updateButtonStyle={ handleChange }
/>
<SectionButtonTagline
locationSettings={ currentLocationSettings }
updateButtonStyle={ handleChange }
/>
</div>
);
};

export default SettingsPanel;

// -----
const SectionPaymentMethods = ( {
locationSettings,
updateButtonSettings,
} ) => {
const paymentMethodOptions = [];

return (
<StylingSection
title={ __( 'Payment Methods', 'woocommerce-paypal-payments' ) }
className="ppcp-r-styling__section--rc"
>
<div className="ppcp-r-styling__payment-method-checkboxes">
<PayPalCheckboxGroup
value={ paymentMethodOptions }
changeCallback={ ( newValue ) =>
updateButtonSettings( 'paymentMethods', newValue )
}
currentValue={ locationSettings.paymentMethods }
/>
</div>
</StylingSection>
);
};

const SectionButtonLayout = ( { locationSettings, updateButtonStyle } ) => {
const buttonLayoutIsAllowed =
locationSettings.layout && locationSettings.tagline === false;
return (
buttonLayoutIsAllowed && (
<StylingSection
className="ppcp-r-styling__section--rc"
title={ __( 'Button Layout', 'woocommerce-paypal-payments' ) }
>
<RadioControl
className="ppcp-r__horizontal-control"
onChange={ ( newValue ) =>
updateButtonStyle( 'layout', newValue )
}
selected={ locationSettings.layout }
options={ [] }
/>
</StylingSection>
)
);
};

const SectionButtonShape = ( { locationSettings, updateButtonStyle } ) => {
return (
<StylingSection
title={ __( 'Shape', 'woocommerce-paypal-payments' ) }
className="ppcp-r-styling__section--rc"
>
<RadioControl
className="ppcp-r__horizontal-control"
onChange={ ( newValue ) =>
updateButtonStyle( 'shape', newValue )
}
selected={ locationSettings.shape }
options={ [] }
/>
</StylingSection>
);
};

const SectionButtonLabel = ( { locationSettings, updateButtonStyle } ) => {
return (
<StylingSection>
<SelectControl
className="ppcp-r-styling__select"
onChange={ ( newValue ) =>
updateButtonStyle( 'label', newValue )
}
value={ locationSettings.label }
label={ __( 'Button Label', 'woocommerce-paypal-payments' ) }
options={ [] }
/>
</StylingSection>
);
};

const SectionButtonColor = ( { locationSettings, updateButtonStyle } ) => {
return (
<StylingSection>
<SelectControl
className=" ppcp-r-styling__select"
label={ __( 'Button Color', 'woocommerce-paypal-payments' ) }
onChange={ ( newValue ) =>
updateButtonStyle( 'color', newValue )
}
value={ locationSettings.color }
options={ [] }
/>
</StylingSection>
);
};

const SectionButtonTagline = ( { locationSettings, updateButtonStyle } ) => {
const taglineIsAllowed =
locationSettings.hasOwnProperty( 'tagline' ) &&
locationSettings.layout === 'horizontal';

return (
taglineIsAllowed && (
<StylingSection
title={ __( 'Tagline', 'woocommerce-paypal-payments' ) }
className="ppcp-r-styling__section--rc"
>
<PayPalCheckboxGroup
value={ [
{
value: 'tagline',
label: __(
'Enable Tagline',
'woocommerce-paypal-payments'
),
},
] }
changeCallback={ ( newValue ) => {
updateButtonStyle( 'tagline', newValue );
} }
currentValue={ locationSettings.tagline }
/>
</StylingSection>
)
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import classnames from 'classnames';

const StylingSection = ( {
title,
className = '',
description = '',
children,
} ) => {
const sectionClasses = classnames( 'ppcp-r-styling__section', className );

return (
<div className={ sectionClasses }>
<span className="ppcp-r-styling__title">{ title }</span>

{ description && (
<p
className="ppcp-r-styling__description"
dangerouslySetInnerHTML={ {
__html: description,
} }
/>
) }

{ children }
</div>
);
};

export default StylingSection;
Loading

0 comments on commit 4913527

Please sign in to comment.