Skip to content

Commit

Permalink
Remove useThemeHasDisabledLayoutStyles hook to simplify feature checks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Jul 28, 2022
1 parent d77120e commit 6b6dadb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
22 changes: 5 additions & 17 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,6 @@ function useLayoutClasses( layout, layoutDefinitions ) {
return layoutClassnames;
}

/**
* Determines whether or not the theme has disabled all layout styles output.
*
* This feature only disables the output of layout styles,
* the controls for adjusting layout will still be available in the editor.
* Themes that use this feature commit to providing their own styling for layout features.
*
* @return {boolean} Whether or not the theme opts-in to disable all layout styles.
*/
function useThemeHasDisabledLayoutStyles() {
return useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return !! getSettings().disableLayoutStyles;
} );
}

function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
const { layout } = attributes;
const defaultThemeLayout = useSetting( 'layout' );
Expand Down Expand Up @@ -284,8 +268,12 @@ export const withLayoutStyles = createHigherOrderComponent(
name,
layoutBlockSupportKey
);
const disableLayoutStyles = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return !! getSettings().disableLayoutStyles;
} );
const shouldRenderLayoutStyles =
hasLayoutBlockSupport && ! useThemeHasDisabledLayoutStyles();
hasLayoutBlockSupport && ! disableLayoutStyles;
const id = useInstanceId( BlockListBlock );
const defaultThemeLayout = useSetting( 'layout' ) || {};
const element = useContext( BlockList.__unstableElementContext );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export const toStyles = (
blockSelectors,
hasBlockGapSupport,
hasFallbackGapSupport,
skipLayoutStyles = false
disableLayoutStyles = false
) => {
const nodesWithStyles = getNodesWithStyles( tree, blockSelectors );
const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
Expand Down Expand Up @@ -616,7 +616,7 @@ export const toStyles = (

// Process blockGap and layout styles.
if (
! skipLayoutStyles &&
! disableLayoutStyles &&
( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport )
) {
ruleset += getLayoutStyles( {
Expand Down Expand Up @@ -767,22 +767,6 @@ export const getBlockSelectors = ( blockTypes ) => {
return result;
};

/**
* Determines whether or not the theme has disabled all layout styles output.
*
* This feature only disables the output of layout styles,
* the controls for adjusting layout will still be available in the editor.
* Themes that use this feature commit to providing their own styling for layout features.
*
* @return {boolean} Whether or not the theme opts-in to disable all layout styles.
*/
function useThemeHasDisabledLayoutStyles() {
return useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return !! getSettings().disableLayoutStyles;
} );
}

export function useGlobalStylesOutput() {
const [ stylesheets, setStylesheets ] = useState( [] );
const [ settings, setSettings ] = useState( {} );
Expand All @@ -791,7 +775,10 @@ export function useGlobalStylesOutput() {
const [ blockGap ] = useSetting( 'spacing.blockGap' );
const hasBlockGapSupport = blockGap !== null;
const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
const skipLayoutStyles = useThemeHasDisabledLayoutStyles();
const disableLayoutStyles = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return !! getSettings().disableLayoutStyles;
} );

useEffect( () => {
if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
Expand All @@ -808,7 +795,7 @@ export function useGlobalStylesOutput() {
blockSelectors,
hasBlockGapSupport,
hasFallbackGapSupport,
skipLayoutStyles
disableLayoutStyles
);
const filters = toSvgFilters( mergedConfig, blockSelectors );
setStylesheets( [
Expand All @@ -827,7 +814,7 @@ export function useGlobalStylesOutput() {
hasBlockGapSupport,
hasFallbackGapSupport,
mergedConfig,
skipLayoutStyles,
disableLayoutStyles,
] );

return [ stylesheets, settings, svgFilters, hasBlockGapSupport ];
Expand Down

0 comments on commit 6b6dadb

Please sign in to comment.