-
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
Draft wrapping block support slots in ToolsPanel Update tests to check resetAll does not trigger onDeselect
- Loading branch information
1 parent
83bc87e
commit 7c23fd8
Showing
8 changed files
with
177 additions
and
51 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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalToolsPanel as ToolsPanel } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { cleanEmptyObject } from '../../hooks/utils'; | ||
|
||
const labels = { | ||
border: { | ||
label: __( 'Border options' ), | ||
header: __( 'Border' ), | ||
}, | ||
color: { | ||
label: __( 'Color options' ), | ||
header: __( 'Color' ), | ||
}, | ||
dimensions: { | ||
label: __( 'Dimensions options' ), | ||
header: __( 'Dimensions' ), | ||
}, | ||
typography: { | ||
label: __( 'Typography options' ), | ||
header: __( 'Typography' ), | ||
}, | ||
}; | ||
|
||
export default function BlockSupportToolsPanel( { group, children } ) { | ||
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={ labels[ group ].label } | ||
header={ labels[ group ].header } | ||
resetAll={ resetAll } | ||
> | ||
{ 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
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