From fcb649e8d1a62f8c9d2cc9626d815456890ba09b Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Fri, 30 Aug 2024 09:19:21 +0100 Subject: [PATCH 1/2] feat: creates and adds component for clear individual styles --- src/editor/components/ClearCustomisation.js | 46 +++++++++++++++++++ src/editor/components/StylesBorder.js | 7 +++ src/editor/components/StylesCustomCSS.js | 8 +++- src/editor/components/StylesDimensions.js | 6 +++ src/editor/components/StylesFilter.js | 6 +++ src/editor/components/StylesOutline.js | 6 +++ src/editor/components/StylesShadow.js | 6 +++ src/editor/components/StylesSpacing.js | 6 +++ .../components/StylesTypography/index.js | 6 +++ src/editor/styles/components/styles.scss | 3 ++ 10 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/editor/components/ClearCustomisation.js diff --git a/src/editor/components/ClearCustomisation.js b/src/editor/components/ClearCustomisation.js new file mode 100644 index 00000000..21326a17 --- /dev/null +++ b/src/editor/components/ClearCustomisation.js @@ -0,0 +1,46 @@ +/** + * Component for clearing customisation for individual style components + */ +import { set, get } from 'lodash'; + +import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components'; +import { menu, trash } from '@wordpress/icons'; +import { useContext } from '@wordpress/element'; +import StylesContext from '../context/StylesContext'; + +const ClearCustomisation = ( { selector, userConfig, themeConfigVal } ) => { + const { setUserConfig } = useContext( StylesContext ); + + // Check if the current value is different from the default value to determine if button should be enabled. + const flagCustomisation = () => { + const currentVal = get( userConfig, selector ); + if ( currentVal !== themeConfigVal ) { + return true; + } + }; + + // Sets userConfig for selector to themeConfig value. + const onClick = () => { + let config = structuredClone( userConfig ); + config = set( config, selector, themeConfigVal ); + setUserConfig( config ); + }; + return ( + + { () => ( + <> + + + Remove customisation + + + + ) } + + ); +}; +export default ClearCustomisation; diff --git a/src/editor/components/StylesBorder.js b/src/editor/components/StylesBorder.js index 12c40679..73ed53c1 100644 --- a/src/editor/components/StylesBorder.js +++ b/src/editor/components/StylesBorder.js @@ -6,6 +6,7 @@ import { __experimentalBorderBoxControl as BorderBoxControl } from '@wordpress/c import getThemeOption from '../../utils/get-theme-option'; import EditorContext from '../context/EditorContext'; import StylesContext from '../context/StylesContext'; +import ClearCustomisation from './ClearCustomisation'; /** * Reusable border control style component @@ -32,7 +33,13 @@ const Border = ( { selector } ) => { <> { __( 'Border', 'themer' ) } + + { - const { themeConfig } = useContext( EditorContext ); + const { themeConfig, userConfig } = useContext( EditorContext ); const { setUserConfig } = useContext( StylesContext ); const cssStyles = getThemeOption( selector, themeConfig ) ?? ''; @@ -34,6 +35,11 @@ const CustomCSS = ( { selector } ) => { <> { __( 'Custom CSS', 'themer' ) } + { <> { __( 'Dimensions', 'themer' ) } + { __( 'Min Height', 'themer' ) } diff --git a/src/editor/components/StylesFilter.js b/src/editor/components/StylesFilter.js index 448435bd..2200d44a 100644 --- a/src/editor/components/StylesFilter.js +++ b/src/editor/components/StylesFilter.js @@ -7,6 +7,7 @@ import getThemeOption from '../../utils/get-theme-option'; import EditorContext from '../context/EditorContext'; import StylesContext from '../context/StylesContext'; import { varToDuotone, duotoneToVar } from '../../utils/block-helpers'; +import ClearCustomisation from './ClearCustomisation'; /** * Reusable filter control style component @@ -56,6 +57,11 @@ const Filter = ( { selector } ) => { <> { __( 'Filter', 'themer' ) } + { <> { __( 'Outline', 'themer' ) } + { <> { __( 'Shadow', 'themer' ) } + { <> { __( 'Spacing', 'themer' ) } + { <> { __( 'Typography', 'themer' ) } + Date: Mon, 2 Sep 2024 08:12:11 +0100 Subject: [PATCH 2/2] feat: translation on strings and useMemo instead of function --- src/editor/components/ClearCustomisation.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/editor/components/ClearCustomisation.js b/src/editor/components/ClearCustomisation.js index 21326a17..913ebfba 100644 --- a/src/editor/components/ClearCustomisation.js +++ b/src/editor/components/ClearCustomisation.js @@ -2,22 +2,22 @@ * Component for clearing customisation for individual style components */ import { set, get } from 'lodash'; - +import { __ } from '@wordpress/i18n'; import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components'; import { menu, trash } from '@wordpress/icons'; -import { useContext } from '@wordpress/element'; +import { useContext, useMemo } from '@wordpress/element'; import StylesContext from '../context/StylesContext'; const ClearCustomisation = ( { selector, userConfig, themeConfigVal } ) => { const { setUserConfig } = useContext( StylesContext ); // Check if the current value is different from the default value to determine if button should be enabled. - const flagCustomisation = () => { + const flagCustomisation = useMemo( () => { const currentVal = get( userConfig, selector ); if ( currentVal !== themeConfigVal ) { return true; } - }; + }, [ selector, userConfig, themeConfigVal ] ); // Sets userConfig for selector to themeConfig value. const onClick = () => { @@ -26,16 +26,19 @@ const ClearCustomisation = ( { selector, userConfig, themeConfigVal } ) => { setUserConfig( config ); }; return ( - + { () => ( <> - Remove customisation + { __( 'Remove customisation', 'themer' ) }