♻️ Migrate InputSettings to ControlTextInput

This commit is contained in:
Philipp Stracker 2025-01-22 15:32:22 +01:00
parent 2f79a9fe4d
commit f90ab656f5
No known key found for this signature in database
6 changed files with 62 additions and 71 deletions

View file

@ -0,0 +1,18 @@
import { TextControl } from '@wordpress/components';
import { Action } from '../Elements';
const ControlTextInput = ( { value, onChange, placeholder = '' } ) => {
return (
<Action>
<TextControl
className="ppcp-r-vertical-text-control"
placeholder={ placeholder }
value={ value }
onChange={ onChange }
/>
</Action>
);
};
export default ControlTextInput;

View file

@ -1,37 +0,0 @@
import { TextControl } from '@wordpress/components';
import SettingsBlock from '../SettingsBlock';
import { Title, Action, Description, TitleExtra } from '../Elements';
const InputSettingsBlock = ( {
title,
description,
supplementaryLabel,
showDescriptionFirst = false,
value,
onChange,
placeholder = '',
} ) => {
const TheDescription = <Description>{ description }</Description>;
return (
<SettingsBlock className="ppcp-r-settings-block__input">
<Title>
{ title }
<TitleExtra>{ supplementaryLabel }</TitleExtra>
</Title>
{ showDescriptionFirst && TheDescription }
<Action>
<TextControl
className="ppcp-r-vertical-text-control"
placeholder={ placeholder }
value={ value }
onChange={ onChange }
/>
</Action>
{ ! showDescriptionFirst && TheDescription }
</SettingsBlock>
);
};
export default InputSettingsBlock;

View file

@ -1,8 +1,9 @@
export { default as ButtonSettingsBlock } from './ButtonSettingsBlock'; export { default as ButtonSettingsBlock } from './ButtonSettingsBlock';
export { default as InputSettingsBlock } from './InputSettingsBlock';
export { default as SelectSettingsBlock } from './SelectSettingsBlock'; export { default as SelectSettingsBlock } from './SelectSettingsBlock';
export { default as AccordionSettingsBlock } from './AccordionSettingsBlock'; export { default as AccordionSettingsBlock } from './AccordionSettingsBlock';
export { default as ToggleSettingsBlock } from './ToggleSettingsBlock'; export { default as ToggleSettingsBlock } from './ToggleSettingsBlock';
export { default as RadioSettingsBlock } from './RadioSettingsBlock'; export { default as RadioSettingsBlock } from './RadioSettingsBlock';
export { default as PaymentMethodsBlock } from './PaymentMethodsBlock'; export { default as PaymentMethodsBlock } from './PaymentMethodsBlock';
export { default as PaymentMethodItemBlock } from './PaymentMethodItemBlock'; export { default as PaymentMethodItemBlock } from './PaymentMethodItemBlock';
export { default as ControlTextInput } from './ControlTextInput';

View file

@ -3,7 +3,7 @@ import { Button } from '@wordpress/components';
import { import {
AccordionSettingsBlock, AccordionSettingsBlock,
InputSettingsBlock, ControlTextInput,
RadioSettingsBlock, RadioSettingsBlock,
} from '../../../../ReusableComponents/SettingsBlocks'; } from '../../../../ReusableComponents/SettingsBlocks';
@ -80,7 +80,7 @@ const generateOptions = ( config, settings, updateFormValue ) => [
), ),
additionalContent: ( additionalContent: (
<> <>
<InputSettingsBlock <ControlTextInput
title={ config.clientIdTitle } title={ config.clientIdTitle }
// Input field props. // Input field props.
value={ settings[ `${ config.mode }ClientId` ] } value={ settings[ `${ config.mode }ClientId` ] }
@ -90,7 +90,7 @@ const generateOptions = ( config, settings, updateFormValue ) => [
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
) } ) }
/> />
<InputSettingsBlock <ControlTextInput
title={ config.secretKeyTitle } title={ config.secretKeyTitle }
// Input field props. // Input field props.
value={ settings[ `${ config.mode }SecretKey` ] } value={ settings[ `${ config.mode }SecretKey` ] }

View file

@ -3,9 +3,10 @@ import {
AccordionSettingsBlock, AccordionSettingsBlock,
RadioSettingsBlock, RadioSettingsBlock,
ToggleSettingsBlock, ToggleSettingsBlock,
InputSettingsBlock, ControlTextInput,
SelectSettingsBlock, SelectSettingsBlock,
} from '../../../../ReusableComponents/SettingsBlocks'; } from '../../../../ReusableComponents/SettingsBlocks';
import SettingsBlock from '../../../../ReusableComponents/SettingsBlock';
const PaypalSettings = ( { updateFormValue, settings } ) => { const PaypalSettings = ( { updateFormValue, settings } ) => {
return ( return (
@ -81,14 +82,14 @@ const PaypalSettings = ( { updateFormValue, settings } ) => {
} } } }
/> />
<InputSettingsBlock <SettingsBlock
title={ __( 'Brand name', 'woocommerce-paypal-payments' ) } title={ __( 'Brand name', 'woocommerce-paypal-payments' ) }
description={ __( headerDescription={ __(
'What business name to show to your buyers during checkout and on receipts.', 'What business name to show to your buyers during checkout and on receipts.',
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
) } ) }
showDescriptionFirst={ true } >
// Input field props. <ControlTextInput
value={ settings.brandName } value={ settings.brandName }
onChange={ updateFormValue } onChange={ updateFormValue }
placeholder={ __( placeholder={ __(
@ -96,15 +97,16 @@ const PaypalSettings = ( { updateFormValue, settings } ) => {
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
) } ) }
/> />
</SettingsBlock>
<InputSettingsBlock <SettingsBlock
title={ __( 'Soft Descriptor', 'woocommerce-paypal-payments' ) } title={ __( 'Soft Descriptor', 'woocommerce-paypal-payments' ) }
description={ __( headerDescription={ __(
"The dynamic text used to construct the statement descriptor that appears on a payer's card statement. Applies to PayPal and Credit Card transactions. Max value of 22 characters.", "The dynamic text used to construct the statement descriptor that appears on a payer's card statement. Applies to PayPal and Credit Card transactions. Max value of 22 characters.",
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
) } ) }
showDescriptionFirst={ true } >
// Input field props. <ControlTextInput
value={ settings.softDescriptor } value={ settings.softDescriptor }
onChange={ updateFormValue } onChange={ updateFormValue }
placeholder={ __( placeholder={ __(
@ -112,6 +114,7 @@ const PaypalSettings = ( { updateFormValue, settings } ) => {
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
) } ) }
/> />
</SettingsBlock>
<RadioSettingsBlock <RadioSettingsBlock
title={ __( title={ __(

View file

@ -1,23 +1,29 @@
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { InputSettingsBlock } from '../../../../../ReusableComponents/SettingsBlocks'; import { ControlTextInput } from '../../../../../ReusableComponents/SettingsBlocks';
import { SettingsHooks } from '../../../../../../data'; import { SettingsHooks } from '../../../../../../data';
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
const InvoicePrefix = () => { const InvoicePrefix = () => {
const { invoicePrefix, setInvoicePrefix } = SettingsHooks.useSettings(); const { invoicePrefix, setInvoicePrefix } = SettingsHooks.useSettings();
return ( return (
<InputSettingsBlock <SettingsBlock
title="Invoice Prefix" title="Invoice Prefix"
supplementaryLabel={ __( supplementaryLabel={ __(
'(Recommended)', '(Recommended)',
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
) } ) }
description="Add a unique prefix to invoice numbers for site-specific tracking (recommended)." description="Add a unique prefix to invoice numbers for site-specific tracking (recommended)."
// Input field props. >
placeholder={ __( 'Input prefix', 'woocommerce-paypal-payments' ) } <ControlTextInput
placeholder={ __(
'Input prefix',
'woocommerce-paypal-payments'
) }
onChange={ setInvoicePrefix } onChange={ setInvoicePrefix }
value={ invoicePrefix } value={ invoicePrefix }
/> />
</SettingsBlock>
); );
}; };