Skip to content

Commit

Permalink
Alignments should work for classic themes
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Aug 4, 2022
1 parent 87d964a commit ef50b1c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) {
}

// Starting here, it's the fallback for themes not supporting the layout config.
if ( layoutType.name !== 'default' ) {
if ( layoutType.name !== 'column' ) {
return [];
}
const { alignments: availableAlignments = DEFAULT_CONTROLS } = layout;
Expand Down
9 changes: 6 additions & 3 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
const usedLayout = layout || defaultBlockLayout || {};
const { inherit = false, type = 'default' } = usedLayout;
/**
* `themeSupportsLayout` is only relevant to the `default/flow`
* layout and it should not be taken into account when other
* `themeSupportsLayout` is only relevant to the `default/flow` or
* `column` layouts and it should not be taken into account when other
* `layout` types are used.
*/
if ( type === 'default' && ! themeSupportsLayout ) {
if (
( type === 'default' || type === 'column' ) &&
! themeSupportsLayout
) {
return null;
}
const layoutType = getLayoutType( type );
Expand Down
33 changes: 2 additions & 31 deletions packages/block-editor/src/layouts/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
__experimentalUseCustomUnits as useCustomUnits,
__experimentalUnitControl as UnitControl,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { Icon, positionCenter, stretchWide } from '@wordpress/icons';
import { getCSSRules } from '@wordpress/style-engine';

/**
* Internal dependencies
*/
import useSetting from '../components/use-setting';
import { appendSelectors, getBlockGapCSS } from './utils';
import { appendSelectors, getBlockGapCSS, getAlignmentsInfo } from './utils';
import { getGapBoxControlValueFromStyle } from '../hooks/gap';
import { shouldSkipSerialization } from '../hooks/utils';

Expand Down Expand Up @@ -215,32 +215,3 @@ export default {
return alignments;
},
};

/**
* Helper method to assign contextual info to clarify
* alignment settings.
*
* Besides checking if `contentSize` and `wideSize` have a
* value, we now show this information only if their values
* are not a `css var`. This needs to change when parsing
* css variables land.
*
* @see https://github.com/WordPress/gutenberg/pull/34710#issuecomment-918000752
*
* @param {Object} layout The layout object.
* @return {Object} An object with contextual info per alignment.
*/
function getAlignmentsInfo( layout ) {
const { contentSize, wideSize } = layout;
const alignmentInfo = {};
const sizeRegex = /^(?!0)\d+(px|em|rem|vw|vh|%)?$/i;
if ( sizeRegex.test( contentSize ) ) {
// translators: %s: container size (i.e. 600px etc)
alignmentInfo.none = sprintf( __( 'Max %s wide' ), contentSize );
}
if ( sizeRegex.test( wideSize ) ) {
// translators: %s: container size (i.e. 600px etc)
alignmentInfo.wide = sprintf( __( 'Max %s wide' ), wideSize );
}
return alignmentInfo;
}
10 changes: 6 additions & 4 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ export default function VisualEditor( { styles } ) {
}

if ( themeSupportsLayout ) {
return defaultLayout;
// We need to ensure support for wide and full alignments,
// so we add the column type.
return { ...defaultLayout, type: 'column' };
}

return undefined;
// Set column layout for classic themes so all alignments are supported.
return { type: 'column' };
}, [ isTemplateMode, themeSupportsLayout, defaultLayout ] );

const titleRef = useRef();
Expand Down Expand Up @@ -265,7 +267,7 @@ export default function VisualEditor( { styles } ) {
className={
isTemplateMode
? 'wp-site-blocks'
: 'is-layout-flow' // Ensure root level blocks receive default/flow blockGap styling rules.
: 'is-layout-column' // Ensure root level blocks receive default/flow blockGap styling rules.
}
__experimentalLayout={ layout }
/>
Expand Down

0 comments on commit ef50b1c

Please sign in to comment.