-
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.
- Loading branch information
Showing
4 changed files
with
55 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useInstanceId } from '@wordpress/compose'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../store'; | ||
import { useStyleOverride } from './utils'; | ||
|
||
function useBlockPropsChildLayoutStyles( { style } ) { | ||
const shouldRenderChildLayoutStyles = useSelect( ( select ) => { | ||
return ! select( blockEditorStore ).getSettings().disableLayoutStyles; | ||
} ); | ||
const layout = style?.layout ?? {}; | ||
const { selfStretch, flexSize } = layout; | ||
const id = useInstanceId( useBlockPropsChildLayoutStyles ); | ||
const selector = `.wp-container-content-${ id }`; | ||
|
||
let css = ''; | ||
if ( shouldRenderChildLayoutStyles ) { | ||
if ( selfStretch === 'fixed' && flexSize ) { | ||
css = `${ selector } { | ||
flex-basis: ${ flexSize }; | ||
box-sizing: border-box; | ||
}`; | ||
} else if ( selfStretch === 'fill' ) { | ||
css = `${ selector } { | ||
flex-grow: 1; | ||
}`; | ||
} | ||
} | ||
|
||
useStyleOverride( { css } ); | ||
|
||
// Only attach a container class if there is generated CSS to be attached. | ||
if ( ! css ) { | ||
return; | ||
} | ||
|
||
// Attach a `wp-container-content` id-based classname. | ||
return { className: `wp-container-content-${ id }` }; | ||
} | ||
|
||
export default { | ||
useBlockProps: useBlockPropsChildLayoutStyles, | ||
attributeKeys: [ 'style' ], | ||
hasSupport() { | ||
return true; | ||
}, | ||
}; |
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 was deleted.
Oops, something went wrong.