From 47294ca5308dff015df7e4d9104784d0372413ce Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Tue, 21 Jan 2025 18:57:36 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Organize=20some=20reusable?= =?UTF-8?q?=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReusableComponents/Elements/Action.js | 5 ++ .../ReusableComponents/Elements/Content.js | 16 ++++ .../Elements/ContentWrapper.js | 5 ++ .../Elements/Description.js | 26 ++++++ .../ReusableComponents/Elements/Header.js | 12 +++ .../Elements/SupplementaryLabel.js | 7 ++ .../ReusableComponents/Elements/Title.js | 21 +++++ .../Elements/TitleWrapper.js | 5 ++ .../ReusableComponents/Elements/index.js | 8 ++ .../{SettingsBlocks => }/SettingsBlock.js | 0 .../SettingsBlocks/AccordionSettingsBlock.js | 10 +-- .../SettingsBlocks/ButtonSettingsBlock.js | 5 +- .../SettingsBlocks/FeatureSettingsBlock.js | 7 +- .../SettingsBlocks/InputSettingsBlock.js | 9 +-- .../SettingsBlocks/PaymentMethodItemBlock.js | 5 +- .../SettingsBlocks/PaymentMethodsBlock.js | 2 +- .../SettingsBlocks/RadioSettingsBlock.js | 4 +- .../SettingsBlocks/SelectSettingsBlock.js | 5 +- .../SettingsBlocks/SettingsBlockElements.js | 81 ------------------- .../SettingsBlocks/ToggleSettingsBlock.js | 4 +- .../SettingsBlocks/index.js | 12 --- .../ReusableComponents/SettingsCard.js | 2 +- .../Blocks/Troubleshooting/HooksTableBlock.js | 7 +- .../Troubleshooting/ResubscribeBlock.js | 7 +- .../Blocks/Troubleshooting/SimulationBlock.js | 3 +- .../Blocks/Troubleshooting/Troubleshooting.js | 7 +- .../Components/Settings/Blocks/OrderIntent.js | 6 +- .../Settings/Blocks/SavePaymentMethods.js | 6 +- .../Components/Settings/ExpertSettings.js | 2 +- .../Styling/Layout/StylingSection.js | 4 +- 30 files changed, 152 insertions(+), 141 deletions(-) create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Action.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Content.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/ContentWrapper.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Description.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Header.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/SupplementaryLabel.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Title.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/TitleWrapper.js create mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/index.js rename modules/ppcp-settings/resources/js/Components/ReusableComponents/{SettingsBlocks => }/SettingsBlock.js (100%) delete mode 100644 modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlockElements.js diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Action.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Action.js new file mode 100644 index 000000000..3e5075503 --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Action.js @@ -0,0 +1,5 @@ +const Action = ( { children } ) => ( +
{ children }
+); + +export default Action; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Content.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Content.js new file mode 100644 index 000000000..3f829a587 --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Content.js @@ -0,0 +1,16 @@ +import classNames from 'classnames'; + +const Content = ( { children, className = '', id = '' } ) => { + const elementClasses = classNames( + 'ppcp-r-settings-card__content', + className + ); + + return ( +
+ { children } +
+ ); +}; + +export default Content; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/ContentWrapper.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/ContentWrapper.js new file mode 100644 index 000000000..b35a5f9b1 --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/ContentWrapper.js @@ -0,0 +1,5 @@ +const ContentWrapper = ( { children } ) => ( +
{ children }
+); + +export default ContentWrapper; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Description.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Description.js new file mode 100644 index 000000000..1d638015d --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Description.js @@ -0,0 +1,26 @@ +import classNames from 'classnames'; + +const Description = ( { children, asHtml = false, className = '' } ) => { + // Don't output anything if description is empty. + if ( ! children ) { + return null; + } + + const elementClasses = classNames( + 'ppcp-r-settings-block__description', + className + ); + + if ( ! asHtml ) { + return { children }; + } + + return ( + + ); +}; + +export default Description; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Header.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Header.js new file mode 100644 index 000000000..f767b603e --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Header.js @@ -0,0 +1,12 @@ +import classNames from 'classnames'; + +const Header = ( { children, className = '' } ) => { + const elementClasses = classNames( + 'ppcp-r-settings-block__header', + className + ); + + return
{ children }
; +}; + +export default Header; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/SupplementaryLabel.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/SupplementaryLabel.js new file mode 100644 index 000000000..8d513a275 --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/SupplementaryLabel.js @@ -0,0 +1,7 @@ +const SupplementaryLabel = ( { children } ) => ( + + { children } + +); + +export default SupplementaryLabel; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Title.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Title.js new file mode 100644 index 000000000..3885d5af4 --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/Title.js @@ -0,0 +1,21 @@ +import classNames from 'classnames'; + +const Title = ( { + children, + altStyle = false, + big = false, + className = '', +} ) => { + const elementClasses = classNames( + 'ppcp-r-settings-block__title', + className, + { + 'style-alt': altStyle, + 'style-big': big, + } + ); + + return { children }; +}; + +export default Title; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/TitleWrapper.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/TitleWrapper.js new file mode 100644 index 000000000..d3f55186e --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/TitleWrapper.js @@ -0,0 +1,5 @@ +const TitleWrapper = ( { children } ) => ( + { children } +); + +export default TitleWrapper; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/index.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/index.js new file mode 100644 index 000000000..13c677050 --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/Elements/index.js @@ -0,0 +1,8 @@ +export { default as Action } from './Action'; +export { default as Content } from './Content'; +export { default as ContentWrapper } from './ContentWrapper'; +export { default as Description } from './Description'; +export { default as Header } from './Header'; +export { default as SupplementaryLabel } from './SupplementaryLabel'; +export { default as Title } from './Title'; +export { default as TitleWrapper } from './TitleWrapper'; diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlock.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlock.js similarity index 100% rename from modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/SettingsBlock.js rename to modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlock.js diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/AccordionSettingsBlock.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/AccordionSettingsBlock.js index cf7f2cee4..630afc267 100644 --- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/AccordionSettingsBlock.js +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/AccordionSettingsBlock.js @@ -1,12 +1,6 @@ import Accordion from '../AccordionSection'; -import SettingsBlock from './SettingsBlock'; -import { - Header, - Title, - Action, - Description, - TitleWrapper, -} from './SettingsBlockElements'; +import SettingsBlock from '../SettingsBlock'; +import { Header, Title, Action, Description, TitleWrapper } from '../Elements'; const SettingsAccordion = ( { title, description, children, ...props } ) => ( diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/ButtonSettingsBlock.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/ButtonSettingsBlock.js index eabdde934..42bc832ed 100644 --- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/ButtonSettingsBlock.js +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/ButtonSettingsBlock.js @@ -1,6 +1,7 @@ import { Button } from '@wordpress/components'; -import SettingsBlock from './SettingsBlock'; -import { Action, Description, Header, Title } from './SettingsBlockElements'; + +import SettingsBlock from '../SettingsBlock'; +import { Action, Description, Header, Title } from '../Elements'; const ButtonSettingsBlock = ( { title, description, ...props } ) => ( diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js index 3f747bda7..8144e30c1 100644 --- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js @@ -1,6 +1,7 @@ import { Button } from '@wordpress/components'; -import SettingsBlock from './SettingsBlock'; -import { Header, Title, Action, Description } from './SettingsBlockElements'; + +import { Header, Title, Action, Description } from '../Elements'; +import SettingsBlock from '../SettingsBlock'; import TitleBadge from '../TitleBadge'; const FeatureSettingsBlock = ( { title, description, ...props } ) => { @@ -24,7 +25,7 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {