Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimenting with adding writing mode to layout #37932

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useContext, createPortal } from '@wordpress/element';
import { arrowRight, arrowDown } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -49,6 +50,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
allowSwitching,
allowEditing = true,
allowInheriting = true,
allowWritingMode,
default: defaultBlockLayout,
} = layoutBlockSupport;

Expand Down Expand Up @@ -103,6 +105,25 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
layoutBlockSupport={ layoutBlockSupport }
/>
) }

{ ! inherit && allowWritingMode && (
<WritingModeControls
writingMode={ layout?.writingMode }
onChange={ ( newWritingMode ) => {
const newOrientation =
newWritingMode === 'vertical'
? 'vertical'
: layout.orientation;
setAttributes( {
layout: {
...layout,
orientation: newOrientation,
writingMode: newWritingMode,
},
} );
} }
/>
) }
</PanelBody>
</InspectorControls>
{ ! inherit && layoutType && (
Expand All @@ -118,7 +139,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {

function LayoutTypeSwitcher( { type, onChange } ) {
return (
<ButtonGroup>
<ButtonGroup className="block-editor-hooks__layout-controls-buttons">
{ getLayoutTypes().map( ( { name, label } ) => {
return (
<Button
Expand All @@ -134,6 +155,26 @@ function LayoutTypeSwitcher( { type, onChange } ) {
);
}

function WritingModeControls( { writingMode = 'horizontal', onChange } ) {
return (
<fieldset className="block-editor-hooks__writing-mode-controls">
<legend>{ __( 'Writing mode' ) }</legend>
<Button
label={ 'horizontal' }
icon={ arrowRight }
isPressed={ writingMode === 'horizontal' }
onClick={ () => onChange( 'horizontal' ) }
/>
<Button
label={ 'vertical' }
icon={ arrowDown }
isPressed={ writingMode === 'vertical' }
onClick={ () => onChange( 'vertical' ) }
/>
</fieldset>
);
}

/**
* Filters registered block settings, extending attributes to include `layout`.
*
Expand Down
7 changes: 6 additions & 1 deletion packages/block-editor/src/hooks/layout.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.block-editor-hooks__layout-controls {
display: flex;
margin-bottom: $grid-unit-20;
margin-bottom: $grid-unit-30;

.block-editor-hooks__layout-controls-unit {
display: flex;
Expand All @@ -12,6 +12,10 @@
}
}

.block-editor-hooks__layout-controls-buttons {
margin-bottom: $grid-unit-30;
}

.block-editor-hooks__layout-controls-reset {
display: flex;
justify-content: flex-end;
Expand All @@ -23,6 +27,7 @@
}

.block-editor-hooks__flex-layout-justification-controls,
.block-editor-hooks__writing-mode-controls,
.block-editor-hooks__flex-layout-orientation-controls {
margin-bottom: $grid-unit-15;
legend {
Expand Down
6 changes: 5 additions & 1 deletion packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export default {
);
},
save: function FlexLayoutStyle( { selector, layout, style } ) {
const { orientation = 'horizontal' } = layout;
const {
orientation = 'horizontal',
writingMode = 'horizontal',
} = layout;
const blockGapSupport = useSetting( 'spacing.blockGap' );
const hasBlockGapStylesSupport = blockGapSupport !== null;
const blockGapValue =
Expand Down Expand Up @@ -115,6 +118,7 @@ export default {
gap: ${ hasBlockGapStylesSupport ? blockGapValue : '0.5em' };
flex-wrap: ${ flexWrap };
${ orientation === 'horizontal' ? rowOrientation : columnOrientation }
writing-mode: ${ writingMode === 'vertical' ? 'vertical-rl' : 'horizontal-tb' };
}

${ appendSelectors( selector, '> *' ) } {
Expand Down
25 changes: 21 additions & 4 deletions packages/block-editor/src/layouts/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ export default {
return null;
},
save: function DefaultLayoutStyle( { selector, layout = {}, style } ) {
const { contentSize, wideSize } = layout;
const { contentSize, wideSize, writingMode = 'horizontal' } = layout;
const blockGapSupport = useSetting( 'spacing.blockGap' );
const hasBlockGapStylesSupport = blockGapSupport !== null;
const blockGapValue =
style?.spacing?.blockGap ?? 'var( --wp--style--block-gap )';

let output =
let output = `
${ appendSelectors( selector ) } {
writing-mode: ${ writingMode === 'vertical' ? 'vertical-rl' : 'horizontal-tb' };
}
`;
output +=
!! contentSize || !! wideSize
? `
${ appendSelectors( selector, '> *' ) } {
Expand Down Expand Up @@ -144,7 +148,7 @@ export default {

`;

if ( hasBlockGapStylesSupport ) {
if ( hasBlockGapStylesSupport && writingMode !== 'vertical' ) {
output += `
${ appendSelectors( selector, '> *' ) } {
margin-top: 0;
Expand All @@ -156,6 +160,19 @@ export default {
`;
}

if ( hasBlockGapStylesSupport && writingMode === 'vertical' ) {
output += `
${ appendSelectors( selector, '> *' ) } {
margin-left: ${ blockGapValue };
margin-right: 0;
margin-top: 0;
}
${ appendSelectors( selector, '> *:last-child' ) } {
margin-left: 0;
}
`;
}

return <style>{ output }</style>;
},
getOrientation() {
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
"fontSize": true
}
},
"__experimentalLayout": true
"__experimentalLayout": {
"allowWritingMode": true
}
},
"editorStyle": "wp-block-group-editor",
"style": "wp-block-group"
Expand Down