diff --git a/src/blocks/shape/components/BlockSettings.jsx b/src/blocks/shape/components/BlockSettings.jsx index 34bc0875b..cb2ab8932 100644 --- a/src/blocks/shape/components/BlockSettings.jsx +++ b/src/blocks/shape/components/BlockSettings.jsx @@ -13,6 +13,7 @@ import { moreDesignOptions } from '@utils'; import { useBlockStyles } from '@hooks/useBlockStyles'; import generalSvgs from '@components/icon-picker/svgs-general'; import socialSvgs from '@components/icon-picker/svgs-social'; +import { ShapeDividerControls } from './ShapeDividerControls'; export const shapeColorControls = [ { @@ -97,6 +98,11 @@ export function BlockSettings( { openLabel={ __( 'Open Library', 'generateblocks' ) } modalTitle={ __( 'Shape Library', 'generateblocks' ) } /> + + { + if ( 'absolute' !== currentPosition ) { + return ''; + } + + if ( '0' === currentTopValue && '' === currentBottomValue ) { + return 'top'; + } + + if ( '0' === currentBottomValue && '' === currentTopValue ) { + return 'bottom'; + } + + return ''; + }, [ currentPosition, currentTopValue, currentBottomValue ] ); + const flippedHorizontallyValue = useMemo( () => { + if ( ! currentTransformsValue ) { + return false; + } + + const existingTransforms = currentTransformsValue ? splitSpaces( currentTransformsValue ) : []; + const scaleValue = existingTransforms.find( ( transform ) => transform.startsWith( 'scale' ) ) ?? ''; + + if ( 'top' === locationValue ) { + return scaleValue.includes( '-1, -1' ); + } + + return scaleValue.includes( '-1, 1' ); + }, [ currentTransformsValue, locationValue ] ); + + return ( + <> + { + const newValues = {}; + const existingTransformsValue = getStyleValue( 'transform', currentAtRule ); + const existingTransforms = existingTransformsValue ? splitSpaces( existingTransformsValue ) : []; + const scaleValue = existingTransforms.find( ( transform ) => transform.startsWith( 'scale' ) ); + let newScaleValue = 'top' === value ? 'scale(1, -1)' : ''; + + if ( flippedHorizontallyValue ) { + if ( 'top' === value ) { + newScaleValue = 'scale(-1, -1)'; + } else { + newScaleValue = 'scale(-1, 1)'; + } + } + + if ( 'top' === value ) { + newValues.top = '0'; + newValues.bottom = ''; + } else { + newValues.top = ''; + newValues.bottom = '0'; + } + + if ( scaleValue ) { + newValues.transform = existingTransformsValue.replace( scaleValue, newScaleValue ).trim(); + } else { + newValues.transform = existingTransformsValue ? `${ existingTransformsValue } ${ newScaleValue }` : newScaleValue; + newValues.transform = newValues.transform.trim(); + } + + onStyleChange( newValues, currentAtRule ); + } } + /> + + { + const newValues = {}; + const existingTransformsValue = getStyleValue( 'transform', currentAtRule ); + const existingTransforms = existingTransformsValue ? splitSpaces( existingTransformsValue ) : []; + const scaleValue = existingTransforms.find( ( transform ) => transform.startsWith( 'scale' ) ); + let newScaleValue = value ? 'scale(-1, 1)' : ''; + + if ( 'top' === locationValue ) { + if ( value ) { + newScaleValue = 'scale(-1, -1)'; + } else { + newScaleValue = 'scale(1, -1)'; + } + } + + if ( scaleValue ) { + newValues.transform = existingTransformsValue.replace( scaleValue, newScaleValue ).trim(); + } else { + newValues.transform = existingTransformsValue ? `${ existingTransformsValue } ${ newScaleValue }` : newScaleValue; + newValues.transform = newValues.transform.trim(); + } + + onStyleChange( newValues, currentAtRule ); + } } + /> + + ); +}