-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap block support slots in ToolsPanel for dimensions support
Co-Authored-By: Greg Ziółkowski <grzegorz@gziolo.pl>
- Loading branch information
1 parent
3b14a92
commit 269b5d1
Showing
6 changed files
with
127 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/block-editor/src/components/inspector-controls/block-support-tools-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalToolsPanel as ToolsPanel } from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { cleanEmptyObject } from '../../hooks/utils'; | ||
|
||
export default function BlockSupportToolsPanel( { children, label, header } ) { | ||
const { clientId, attributes } = useSelect( ( select ) => { | ||
const { getBlockAttributes, getSelectedBlockClientId } = select( | ||
blockEditorStore | ||
); | ||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
|
||
return { | ||
clientId: selectedBlockClientId, | ||
attributes: getBlockAttributes( selectedBlockClientId ), | ||
}; | ||
} ); | ||
const { updateBlockAttributes } = useDispatch( blockEditorStore ); | ||
|
||
const resetAll = ( resetFilters = [] ) => { | ||
const { style } = attributes; | ||
let newAttributes = { style }; | ||
|
||
resetFilters.forEach( ( resetFilter ) => { | ||
newAttributes = { | ||
...newAttributes, | ||
...resetFilter( newAttributes ), | ||
}; | ||
} ); | ||
|
||
// Enforce a cleaned style object. | ||
newAttributes = { | ||
...newAttributes, | ||
style: cleanEmptyObject( newAttributes.style ), | ||
}; | ||
|
||
updateBlockAttributes( clientId, newAttributes ); | ||
}; | ||
|
||
return ( | ||
<ToolsPanel | ||
label={ label } | ||
header={ header } | ||
resetAll={ resetAll } | ||
key={ clientId } | ||
panelId={ clientId } | ||
> | ||
{ children } | ||
</ToolsPanel> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters