Skip to content

Commit

Permalink
[RNMobile] Enable child block settings to be hidden via parent block (#…
Browse files Browse the repository at this point in the history
…36371)

With this PR, a "__experimentalHideChildBlockControls" block support is introduced. If a parent block declares "__experimentalHideChildBlockControls" to be true with this PR applied, then the settings control for its child blocks won't be displayed. It is set to false by default.
  • Loading branch information
SiobhyB committed Nov 15, 2021
1 parent 79ad4f3 commit 73e6f60
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ import warning from '@wordpress/warning';
* Internal dependencies
*/
import groups from './groups';
import { useBlockEditContext } from '../block-edit/context';
import useDisplayBlockControls from '../use-display-block-controls';
import { BlockSettingsButton } from '../block-settings';

export default function InspectorControlsFill( {
children,
__experimentalGroup: group = 'default',
...props
} ) {
const { isSelected } = useBlockEditContext();
const isDisplayed = useDisplayBlockControls();

const Fill = groups[ group ]?.Fill;
if ( ! Fill ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
return null;
}
if ( ! isSelected ) {
if ( ! isDisplayed ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { hasBlockSupport } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { useBlockEditContext } from '../block-edit/context';
import { store as blockEditorStore } from '../../store';

export default function useDisplayBlockControls() {
const { isSelected, clientId, name } = useBlockEditContext();
return useSelect(
( select ) => {
const { getBlockName, getBlockRootClientId } = select(
blockEditorStore
);

const parentId = getBlockRootClientId( clientId );
const parentBlockName = getBlockName( parentId );

const hideControls = hasBlockSupport(
parentBlockName,
'__experimentalHideChildBlockControls',
false
);

if ( ! hideControls && isSelected ) {
return true;
}

return false;
},
[ clientId, isSelected, name ]
);
}

0 comments on commit 73e6f60

Please sign in to comment.