Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimensions Support: Add SlotFill to Dimensions Panel #34063

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { createSlotFill } from '@wordpress/components';

const InspectorControlsDefault = createSlotFill( 'InspectorControls' );
const InspectorControlsAdvanced = createSlotFill( 'InspectorAdvancedControls' );
const InspectorControlsDimensions = createSlotFill(
'InspectorDimensionsControls'
);

const groups = {
default: InspectorControlsDefault,
advanced: InspectorControlsAdvanced,
dimensions: InspectorControlsDimensions,
};

export default groups;
29 changes: 25 additions & 4 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,36 @@ export function DimensionsPanel( props ) {
] );

// Callback to reset all block support attributes controlled via this panel.
const resetAll = () => {
const resetAll = ( resetFilters = [] ) => {
const { style } = props.attributes;

props.setAttributes( {
style: cleanEmptyObject( {
let newAttributes = {
style: {
...style,
spacing: {
...style?.spacing,
margin: undefined,
padding: undefined,
},
} ),
},
};

// Injected controls can register additional functions to further adjust
// the attributes being reset.
resetFilters.forEach( ( resetFilter ) => {
newAttributes = {
...newAttributes,
...resetFilter( newAttributes ),
};
} );

// Enforce a cleaned style object.
newAttributes = {
...newAttributes,
style: cleanEmptyObject( newAttributes.style ),
};

props.setAttributes( newAttributes );
};

return (
Expand Down Expand Up @@ -98,6 +115,10 @@ export function DimensionsPanel( props ) {
<MarginEdit { ...props } />
</ToolsPanelItem>
) }
<InspectorControls.Slot
__experimentalGroup="dimensions"
bubblesVirtually={ false }
/>
</ToolsPanel>
</InspectorControls>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/tools-panel/tools-panel-item/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function useToolsPanelItem( props ) {
hasValue,
isShownByDefault,
label,
resetAllFilter,
onDeselect = () => undefined,
onSelect = () => undefined,
...otherProps
Expand All @@ -41,6 +42,7 @@ export function useToolsPanelItem( props ) {
hasValue,
isShownByDefault,
label,
resetAllFilter,
} );

return () => deregisterPanelItem( label );
Expand Down
14 changes: 13 additions & 1 deletion packages/components/src/tools-panel/tools-panel/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,22 @@ export function useToolsPanel( props ) {
} );
};

const getResetAllFilters = () => {
const filters = [];

panelItems.forEach( ( item ) => {
if ( item.resetAllFilter ) {
filters.push( item.resetAllFilter );
}
} );

return filters;
};

// Resets display of children and executes resetAll callback if available.
const resetAllItems = () => {
if ( typeof resetAll === 'function' ) {
resetAll();
resetAll( getResetAllFilters() );
}

// Turn off display of all non-default items.
Expand Down