Skip to content

Commit

Permalink
Framework: Deprecate grouped inner blocks layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 10, 2018
1 parent a5d7295 commit 67deb06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 85 deletions.
1 change: 1 addition & 0 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
- `focusOnMount` prop in the `Popover` component has been changed from `Boolean`-only to an enum-style property that accepts `"firstElement"`, `"container"`, or `false`. Please convert any `<Popover focusOnMount />` usage to `<Popover focusOnMount="firstElement" />`.
- `wp.utils.keycodes` utilities are removed. Please use `wp.keycodes` instead.
- Block `id` prop in `edit` function removed. Please use block `clientId` prop instead.
- `InnerBlocks` grouped layout is removed. Use intermediary nested inner blocks instead. See Columns / Column block for reference implementation.

## 3.3.0

Expand Down
8 changes: 8 additions & 0 deletions editor/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
*/
import { createElement } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand All @@ -34,6 +35,13 @@ const GroupedLayoutBlockList = withSelect(
layouts,
...props
} ) => map( layouts, ( layout ) => {
deprecated( 'grouped layout', {
alternative: 'intermediary nested inner blocks',
version: 'v3.4',
plugin: 'Gutenberg',
hint: 'See core Columns / Column block for reference implementation',
} );

// Filter blocks assigned to layout when rendering grouped layouts.
const layoutBlockUIDs = reduce( blocks, ( result, block ) => {
if ( get( block, [ 'attributes', 'layout' ] ) === layout.name ) {
Expand Down
88 changes: 3 additions & 85 deletions editor/components/inner-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,101 +107,19 @@ If the block is a top level block: the locking of the Custom Post Type is used.
### `layouts`
* **Type:** `Array<Object>|Object`

To achieve distinct arrangements of nested blocks, you may assign layout as an array of objects, or an object. When assigned, a user will be provided with the option to move blocks between layouts, and the rendered output will assign a layout-specific class which can be used in your block stylesheet to effect the visual arrangement of nested blocks.
To achieve distinct arrangements of nested blocks, you may assign layout as an object. When assigned, the rendered output will assign a layout-specific class which can be used in your block stylesheet to effect the visual arrangement of nested blocks.

Because `InnerBlocks.Content` will generate a single continuous flow of block markup for nested content, it may be advisable to use [CSS Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout) to assign layout positions. Be aware that CSS grid is [not suported in legacy browsers](https://caniuse.com/#feat=css-grid), and therefore you should consider how this might impact your block's appearance when viewed on the front end of a site in such browsers.
A layout is an object where each key is the slug of the layout (used also in the applied class to the block), and its value an object consisting of:

Layouts can be assigned either as an object (ungrouped layouts) or an array of objects (grouped layouts). These are documented below.

In both cases, each layout consists of:

- Name: A slug to use in generating the layout class applied to nested blocks
- Icon (`icon: string`): The slug of the Dashicon to use in controls presented to the user in moving between layouts
- Reference: https://developer.wordpress.org/resource/dashicons/
- Label (`label: string`): The text to display in the controls presented to the user in moving between layouts

_Ungrouped Layouts:_

If you do not depend on a particular order of markup for your nested content and need merely to assign a layout class to each nested block, you should assign `layouts` as an object, where each key is the name of a layout:
**Example:**

```jsx
<InnerBlocks layouts={ {
normal: { label: 'Normal Width', icon: 'align-center' },
wide: { label: 'Width Width', icon: 'align-wide' },
} } />
```

_Grouped Layouts:_

If your nested content depends on having each layout grouped in its markup, you should assign `layouts` as an array of layout objects, where the name of the layout is set as a property of the object:

```jsx
<InnerBlocks layouts={ [
{ name: 'column-1', label: 'Column 1', icon: 'columns' },
{ name: 'column-2', label: 'Column 2', icon: 'columns' },
] } />
```

Consider a Columns block. When the user changes the layout of a block from one column to another, it is not sufficient to simply reassign the class name of the block to the new layout, as the user may then proceed to attempt to move the block up or down within the new column. The expected behavior here requires that the markup of the block itself be moved in relation to blocks already present in the new layout.

```html
<!-- wp:columns -->
<div class="wp-block-columns">
<!-- wp:paragraph {"layout":"column-1"} -->
<p>First Paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"layout":"column-1"} -->
<p>Second Paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"layout":"column-2"} -->
<p>Third Paragraph</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:columns -->
```

In the above example markup, if the user moved the first nested paragraph block to the second column, we must ensure that if they then proceed to move the block down, that the block would be the last item in the markup, otherwise it would not appear to move because it would still exist in markup prior to the third paragraph.

_Bad:_

```html
<!-- wp:columns -->
<div class="wp-block-columns">
<!-- wp:paragraph {"layout":"column-2"} -->
<p>First Paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"layout":"column-1"} -->
<p>Second Paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"layout":"column-2"} -->
<p>Third Paragraph</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:columns -->
```

We achieve this by ensuring that the markup of each layout is kept grouped together.

_Good:_

```html
<!-- wp:columns -->
<div class="wp-block-columns">
<!-- wp:paragraph {"layout":"column-1"} -->
<p>Second Paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"layout":"column-2"} -->
<p>First Paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"layout":"column-2"} -->
<p>Third Paragraph</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:columns -->
```

0 comments on commit 67deb06

Please sign in to comment.