Skip to content

Commit

Permalink
Add visualizers back
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 15, 2023
1 parent befe1e8 commit cd20917
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default function DimensionsPanel( {
settings,
panelId,
defaultControls = DEFAULT_CONTROLS,
onVisualize = () => {},
} ) {
const decodeValue = ( rawValue ) =>
getValueFromVariable( { settings }, '', rawValue );
Expand Down Expand Up @@ -247,6 +248,7 @@ export default function DimensionsPanel( {
!! value?.spacing?.padding &&
Object.keys( value?.spacing?.padding ).length;
const resetPaddingValue = () => setPaddingValues( undefined );
const onMouseOverPadding = () => onVisualize( 'padding' );

// Margin
const showMarginControl = useHasMargin( settings );
Expand All @@ -272,6 +274,7 @@ export default function DimensionsPanel( {
!! value?.spacing?.margin &&
Object.keys( value?.spacing?.margin ).length;
const resetMarginValue = () => setMarginValues( undefined );
const onMouseOverMargin = () => onVisualize( 'margin' );

// Block Gap
const showGapControl = useHasGap( settings );
Expand Down Expand Up @@ -370,6 +373,7 @@ export default function DimensionsPanel( {
},
} );
};
const onMouseLeaveControls = () => onVisualize( false );

return (
<Wrapper resetAll={ resetAll }>
Expand Down Expand Up @@ -450,6 +454,8 @@ export default function DimensionsPanel( {
units={ units }
allowReset={ false }
splitOnAxis={ isAxialPadding }
onMouseOver={ onMouseOverPadding }
onMouseOut={ onMouseLeaveControls }
/>
) }
{ showSpacingPresetsControl && (
Expand All @@ -461,6 +467,8 @@ export default function DimensionsPanel( {
units={ units }
allowReset={ false }
splitOnAxis={ isAxialPadding }
onMouseOver={ onMouseOverPadding }
onMouseOut={ onMouseLeaveControls }
/>
) }
</ToolsPanelItem>
Expand All @@ -485,6 +493,8 @@ export default function DimensionsPanel( {
units={ units }
allowReset={ false }
splitOnAxis={ isAxialMargin }
onMouseOver={ onMouseOverMargin }
onMouseOut={ onMouseLeaveControls }
/>
) }
{ showSpacingPresetsControl && (
Expand All @@ -496,6 +506,8 @@ export default function DimensionsPanel( {
units={ units }
allowReset={ false }
splitOnAxis={ isAxialMargin }
onMouseOver={ onMouseOverMargin }
onMouseOut={ onMouseLeaveControls }
/>
) }
</ToolsPanelItem>
Expand Down
48 changes: 22 additions & 26 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* WordPress dependencies
*/
/*import { useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';*/
import { useState, useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { getBlockSupport } from '@wordpress/blocks';
import deprecated from '@wordpress/deprecated';

Expand All @@ -14,35 +14,33 @@ import {
DimensionsPanel as StylesDimensionsPanel,
useHasDimensionsPanel,
} from '../components/global-styles';
/*import { MarginVisualizer } from './margin';
import { MarginVisualizer } from './margin';
import { PaddingVisualizer } from './padding';
import { store as blockEditorStore } from '../store';
import { unlock } from '../lock-unlock';
*/

import { cleanEmptyObject, useBlockSettings } from './utils';

export const DIMENSIONS_SUPPORT_KEY = 'dimensions';
export const SPACING_SUPPORT_KEY = 'spacing';
export const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];
export const AXIAL_SIDES = [ 'vertical', 'horizontal' ];

/*function useVisualizerMouseOver() {
const [ isMouseOver, setIsMouseOver ] = useState( false );
function useVisualizer() {
const [ property, setProperty ] = useState( false );
const { hideBlockInterface, showBlockInterface } = unlock(
useDispatch( blockEditorStore )
);
const onMouseOver = ( e ) => {
e.stopPropagation();
hideBlockInterface();
setIsMouseOver( true );
};
const onMouseOut = ( e ) => {
e.stopPropagation();
showBlockInterface();
setIsMouseOver( false );
};
return { isMouseOver, onMouseOver, onMouseOut };
}*/
useEffect( () => {
if ( ! property ) {
showBlockInterface();
} else {
hideBlockInterface();
}
}, [ property, showBlockInterface, hideBlockInterface ] );

return [ property, setProperty ];
}

function DimensionsInspectorControl( { children } ) {
return (
Expand All @@ -61,8 +59,7 @@ export function DimensionsPanel( props ) {
const settings = useBlockSettings( name, __unstableParentLayout );
const isEnabled = useHasDimensionsPanel( settings );
const value = attributes.style;
//const paddingMouseOver = useVisualizerMouseOver();
//const marginMouseOver = useVisualizerMouseOver();
const [ visualizedProperty, setVisualizedProperty ] = useVisualizer();
const onChange = ( newStyle ) => {
setAttributes( {
style: cleanEmptyObject( newStyle ),
Expand Down Expand Up @@ -96,21 +93,20 @@ export function DimensionsPanel( props ) {
value={ value }
onChange={ onChange }
defaultControls={ defaultControls }
onVisualize={ setVisualizedProperty }
/>
{ /*
{ ! isPaddingDisabled && (
{ !! settings?.spacing?.padding && (
<PaddingVisualizer
forceShow={ paddingMouseOver.isMouseOver }
forceShow={ visualizedProperty === 'padding' }
{ ...props }
/>
) }
{ ! isMarginDisabled && (
{ !! settings?.spacing?.margin && (
<MarginVisualizer
forceShow={ marginMouseOver.isMouseOver }
forceShow={ visualizedProperty === 'margin' }
{ ...props }
/>
) }
/*/ }
</>
);
}
Expand Down

0 comments on commit cd20917

Please sign in to comment.