diff --git a/src/editor/components/ClearCustomisation.js b/src/editor/components/ClearCustomisation.js new file mode 100644 index 00000000..913ebfba --- /dev/null +++ b/src/editor/components/ClearCustomisation.js @@ -0,0 +1,49 @@ +/** + * 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, 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 = useMemo( () => { + const currentVal = get( userConfig, selector ); + if ( currentVal !== themeConfigVal ) { + return true; + } + }, [ selector, userConfig, themeConfigVal ] ); + + // Sets userConfig for selector to themeConfig value. + const onClick = () => { + let config = structuredClone( userConfig ); + config = set( config, selector, themeConfigVal ); + setUserConfig( config ); + }; + return ( + + { () => ( + <> + + + { __( 'Remove customisation', 'themer' ) } + + + + ) } + + ); +}; +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' ) } +