-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LayoutPanel: Update to use ToolsPanel and ToolsPanelItems
- Loading branch information
1 parent
4f25464
commit 475324a
Showing
7 changed files
with
356 additions
and
146 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getBlockSupport } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useSetting from '../components/use-setting'; | ||
import { LAYOUT_SUPPORT_KEY } from './layout'; | ||
import { cleanEmptyObject } from './utils'; | ||
|
||
/** | ||
* Determines if there is content layout support. | ||
* | ||
* @param {string|Object} blockType Block name or Block Type object. | ||
* @return {boolean} Whether there is support. | ||
*/ | ||
export function hasContentLayoutSupport( blockType ) { | ||
const support = getBlockSupport( blockType, LAYOUT_SUPPORT_KEY ); | ||
return !! ( | ||
true === support || | ||
! support?.default?.type || | ||
support?.default?.type === 'default' || | ||
support?.default?.type === 'constrained' | ||
); | ||
} | ||
|
||
/** | ||
* Checks if there is a current value set for content layout. | ||
* | ||
* @param {Object} props Block props. | ||
* @return {boolean} Whether or not the block has a minHeight value set. | ||
*/ | ||
export function hasContentLayoutValue( props ) { | ||
return ( | ||
props.attributes.layout?.type === 'default' || | ||
props.attributes.layout?.type === 'constrained' | ||
); | ||
} | ||
|
||
/** | ||
* Resets the content layout block support attributes. | ||
* | ||
* @param {Object} props Block props. | ||
* @param {Object} props.attributes Block's attributes. | ||
* @param {Object} props.setAttributes Function to set block's attributes. | ||
*/ | ||
export function resetContentLayout( { attributes = {}, setAttributes } ) { | ||
const { layout } = attributes; | ||
|
||
setAttributes( { | ||
layout: cleanEmptyObject( { | ||
...layout, | ||
type: undefined, | ||
} ), | ||
} ); | ||
} | ||
|
||
/** | ||
* Custom hook that checks if content layout controls have been disabled. | ||
* | ||
* @param {string} name The name of the block. | ||
* @return {boolean} Whether content layout control is disabled. | ||
*/ | ||
export function useIsContentLayoutDisabled( { name: blockName } = {} ) { | ||
// TODO: Is this check valid? The following assumes on by default unless explicitly opted out. | ||
const isDisabled = useSetting( 'layout.contentLayout' ) === false; | ||
return ! hasContentLayoutSupport( blockName ) || isDisabled; | ||
} |
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
Oops, something went wrong.