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

Add Reverse on Mobile Attribute for Columns Blocks #55763

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Display content in multiple columns, with blocks added to each column. ([Source]
- **Name:** core/columns
- **Category:** design
- **Supports:** align (full, wide), anchor, color (background, button, gradients, heading, link, text), layout (default, ~~allowEditing~~, ~~allowInheriting~~, ~~allowSwitching~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** isStackedOnMobile, templateLock, verticalAlignment
- **Attributes:** isReversedOnMobile, isStackedOnMobile, templateLock, verticalAlignment

## Comment Author Avatar (deprecated)

Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/columns/block.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"type": "boolean",
"default": true
},
"isReversedOnMobile": {
"type": "boolean",
"default": false
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
Expand Down
18 changes: 17 additions & 1 deletion packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ function ColumnsEditContainer( {
updateColumns,
clientId,
} ) {
const { isStackedOnMobile, verticalAlignment, templateLock } = attributes;
const {
isStackedOnMobile,
isReversedOnMobile,
verticalAlignment,
templateLock,
} = attributes;

const { count, canInsertColumnBlock, minCount } = useSelect(
( select ) => {
Expand Down Expand Up @@ -97,6 +102,7 @@ function ColumnsEditContainer( {
const classes = classnames( {
[ `are-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
[ `is-not-stacked-on-mobile` ]: ! isStackedOnMobile,
[ `is-reversed-on-mobile` ]: isReversedOnMobile,
} );

const blockProps = useBlockProps( {
Expand Down Expand Up @@ -157,6 +163,16 @@ function ColumnsEditContainer( {
} )
}
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Reverse on mobile' ) }
checked={ isReversedOnMobile }
onChange={ () =>
setAttributes( {
isReversedOnMobile: ! isReversedOnMobile,
} )
}
/>
</PanelBody>
</InspectorControls>
<div { ...innerBlocksProps } />
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/columns/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import classnames from 'classnames';
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { isStackedOnMobile, verticalAlignment } = attributes;
const { isStackedOnMobile, isReversedOnMobile, verticalAlignment } =
attributes;

const className = classnames( {
[ `are-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
[ `is-not-stacked-on-mobile` ]: ! isStackedOnMobile,
[ `is-reversed-on-mobile` ]: isReversedOnMobile,
} );

const blockProps = useBlockProps.save( { className } );
Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/columns/style.scss
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
}
}

// Reverse on mobile: Reverse column order
@media (max-width: #{ ($break-medium - 1) }) {
.wp-block-columns.is-reversed-on-mobile.is-not-stacked-on-mobile {
flex-direction: row-reverse;
}

.wp-block-columns.is-reversed-on-mobile:not(.is-not-stacked-on-mobile) {
flex-direction: column-reverse;
}
}


// Lower specificity of margin styles so they don't override the Layout block support.
:where(.wp-block-columns) {
margin-bottom: 1.75em;
Expand Down
Empty file modified packages/block-library/src/media-text/block.json
100644 → 100755
Empty file.
Empty file modified packages/block-library/src/media-text/style.scss
100644 → 100755
Empty file.
Loading