Skip to content

Commit

Permalink
Mobile - useEditorWrapperStyles - Move max width values from the SCSS…
Browse files Browse the repository at this point in the history
… styles to the JavaScript side and update tests
  • Loading branch information
Gerardo committed Apr 25, 2023
1 parent cc984f2 commit 696d5a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,16 @@ import { registerCoreBlocks } from '@wordpress/block-library';
import { useEditorWrapperStyles } from '../use-editor-wrapper-styles';

jest.mock( '../use-editor-wrapper-styles.scss', () => ( {
'block-editor-hooks__use-editor-wrapper-styles': {
'use-editor-wrapper-styles': {
width: '100%',
maxWidth: 580,
alignSelf: 'center',
},
'block-editor-hooks__use-editor-wrapper-styles--reversed': {
'use-editor-wrapper-styles--reversed': {
flexDirection: 'column-reverse',
width: '100%',
maxWidth: 580,
},
'block-editor-hooks__use-editor-wrapper-styles-alignment--full': {
maxWidth: '100%',
},
'block-editor-hooks__use-editor-wrapper-styles-alignment--wide': {
maxWidth: 1054,
},
'block-editor-hooks__use-editor-wrapper-styles-alignment--wide-medium': {
maxWidth: 770,
},
'block-editor-hooks__use-editor-wrapper-styles-alignment--wide-landscape': {
maxWidth: 662,
},
'block-editor-hooks__use-editor-wrapper-styles-block': {
marginLeft: 16,
},
} ) );

const defaultCanvasStyles = {
Expand Down
36 changes: 16 additions & 20 deletions packages/block-editor/src/hooks/use-editor-wrapper-styles.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import {
*/
import styles from './use-editor-wrapper-styles.scss';

const ALIGNMENT_MAX_WIDTH = {
full: '100%',
wide: 1054,
wideMedium: 770,
wideLandscape: 662,
};

const BLOCK_DEFAULT_MARGIN = 16;

/**
* Get the styles for the wide width alignment.
*
Expand All @@ -32,9 +41,7 @@ function getWideWidthStyles( align, isLandscape, width ) {
}

if ( isLandscape && width < ALIGNMENT_BREAKPOINTS.large ) {
return styles[
'block-editor-hooks__use-editor-wrapper-styles-alignment--wide-landscape'
];
return { maxWidth: ALIGNMENT_MAX_WIDTH.wideLandscape };
}

if ( width <= ALIGNMENT_BREAKPOINTS.small ) {
Expand All @@ -45,14 +52,10 @@ function getWideWidthStyles( align, isLandscape, width ) {
width >= ALIGNMENT_BREAKPOINTS.medium &&
width < ALIGNMENT_BREAKPOINTS.wide
) {
return styles[
'block-editor-hooks__use-editor-wrapper-styles-alignment--wide-medium'
];
return { maxWidth: ALIGNMENT_MAX_WIDTH.wideMedium };
}

return styles[
'block-editor-hooks__use-editor-wrapper-styles-alignment--wide'
];
return { maxWidth: ALIGNMENT_MAX_WIDTH.wide };
}

/**
Expand All @@ -67,9 +70,7 @@ function getWideWidthStyles( align, isLandscape, width ) {
function getFullWidthStyles( align, blockName, hasParents, parentBlockName ) {
const { isContainerRelated, isFullWidth } = alignmentHelpers;
const fullWidthStyles = isFullWidth( align )
? styles[
'block-editor-hooks__use-editor-wrapper-styles-alignment--full'
]
? { maxWidth: ALIGNMENT_MAX_WIDTH.full }
: {};

if (
Expand All @@ -78,10 +79,7 @@ function getFullWidthStyles( align, blockName, hasParents, parentBlockName ) {
! isContainerRelated( parentBlockName ) &&
isContainerRelated( blockName )
) {
fullWidthStyles.paddingHorizontal =
styles[
'block-editor-hooks__use-editor-wrapper-styles-block'
].marginLeft;
fullWidthStyles.paddingHorizontal = BLOCK_DEFAULT_MARGIN;
}

return fullWidthStyles;
Expand Down Expand Up @@ -209,10 +207,8 @@ export function useEditorWrapperStyles( {
const wrapperStyles = useMemo( () => {
const stretchStyle = contentResizeMode === 'stretch' && { flex: 1 };
let canvasStyles = ! reversed
? styles[ 'block-editor-hooks__use-editor-wrapper-styles' ]
: styles[
'block-editor-hooks__use-editor-wrapper-styles--reversed'
];
? styles[ 'use-editor-wrapper-styles' ]
: styles[ 'use-editor-wrapper-styles--reversed' ];

// For these cases, no width constraints should be added.
if ( stretchStyle ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
.block-editor-hooks__use-editor-wrapper-styles {
.use-editor-wrapper-styles {
width: 100%;
max-width: 580;
align-self: center;
}

.block-editor-hooks__use-editor-wrapper-styles--reversed {
.use-editor-wrapper-styles--reversed {
flex-direction: column-reverse;
width: 100%;
max-width: 580;
}

.block-editor-hooks__use-editor-wrapper-styles-alignment--full {
max-width: 100%;
}

.block-editor-hooks__use-editor-wrapper-styles-alignment--wide {
max-width: 1054;
}

.block-editor-hooks__use-editor-wrapper-styles-alignment--wide-medium {
max-width: 770;
}

.block-editor-hooks__use-editor-wrapper-styles-alignment--wide-landscape {
max-width: 662;
}

.block-editor-hooks__use-editor-wrapper-styles-block {
margin: $block-edge-to-content;
}

0 comments on commit 696d5a9

Please sign in to comment.