Skip to content

Commit

Permalink
Merge pull request #157 from philbuchanan/#156
Browse files Browse the repository at this point in the history
Use useInnerBlocksProps for inner blocks handling (#156)
  • Loading branch information
philbuchanan authored Feb 7, 2022
2 parents 6f94271 + 8af4294 commit e4f1909
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
6 changes: 3 additions & 3 deletions accordion-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Plugin Name: Accordion Blocks
* Plugin URI: https://github.com/philbuchanan/Accordion-Blocks
* Description: Gutenberg blocks for creating responsive accordion drop-downs.
* Version: 1.4.1
* Requires at least: 5.8
* Tested up to: 5.8
* Version: 1.5.0
* Requires at least: 5.9
* Tested up to: 5.9
* Requires PHP: 7.3
* Author: Phil Buchanan
* Author URI: https://philbuchanan.com
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keycodes'), 'version' => 'efde7cf566bf861557c8c994b86559d2');
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '348416c729ba3f21f077b8a632fd9ba7');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: philbuchanan
Author URI: https://philbuchanan.com/
Donate Link: https://philbuchanan.com/donate/
Tags: accordion, accordions, gutenberg, block, responsive
Requires at least: 5.8
Tested up to: 5.8
Stable tag: 1.4.1
Requires at least: 5.9
Tested up to: 5.9
Stable tag: 1.5.0
Requires PHP: 7.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -90,6 +90,10 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
2. Accordion block in the editor

== Changelog ==
= 1.5.0 =
* Plugin now requires WordPress 5.9.
* Use `useInnerBlocksProps` and `useInnerBlocksProps.save()` for inner blocks handling.

= 1.4.1 =
* Fixed: Fixed UUID not generating properly in widget editor.

Expand Down Expand Up @@ -186,6 +190,9 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
* All new plugin to support the new WordPress Gutenberg editor.

== Upgrade Notice ==
= 1.5.0 =
Fixed compatibility issues with WordPress 5.9. Plugin now requires WordPress 5.9 (the changes are fundamentally incompatible with previous versions of WordPress).

= 1.4.1 =
Fixed accordions not generating UUIDs in the widgets editor, therefore breaking when returning to the widgets editor.

Expand Down
6 changes: 3 additions & 3 deletions src/block/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ const deprecated = [
uuid,
} = attributes;

var itemClasses = [
let itemClasses = [
'c-accordion__item',
'js-accordion-item',
'no-js',
];

var titleClasses = [
let titleClasses = [
'c-accordion__title',
'js-accordion-controller',
];

var contentStyles = {};
let contentStyles = {};

if (titleTag === 'button') {
titleClasses.push('c-accordion__title--button');
Expand Down
11 changes: 6 additions & 5 deletions src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
BlockControls,
InspectorControls,
RichText,
InnerBlocks,
useBlockProps,
useInnerBlocksProps,
} from '@wordpress/block-editor';
import {
PanelBody,
Expand All @@ -23,7 +23,6 @@ import {
Button,
} from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { DOWN } from '@wordpress/keycodes';

/**
* Internal dependencies
Expand Down Expand Up @@ -143,6 +142,10 @@ const AccordionItemEdit = ({
)
});

const innerBlocksProps = useInnerBlocksProps({
className: 'c-accordion__content',
});

return (
<Fragment>
<BlockControls group="block">
Expand Down Expand Up @@ -314,9 +317,7 @@ const AccordionItemEdit = ({
value={ title }
onChange={ value => setAttributes({title: value}) }
/>
<div className="c-accordion__content">
<InnerBlocks />
</div>
<div { ...innerBlocksProps } />
</div>
</Fragment>
);
Expand Down
20 changes: 10 additions & 10 deletions src/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
import { registerBlockType } from '@wordpress/blocks';
import {
InnerBlocks,
RichText,
useBlockProps,
useInnerBlocksProps,
} from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -38,18 +38,18 @@ registerBlockType('pb/accordion-item', {
uuid,
} = attributes;

var itemClasses = [
let itemClasses = [
'c-accordion__item',
'js-accordion-item',
'no-js',
];

var titleClasses = [
let titleClasses = [
'c-accordion__title',
'js-accordion-controller',
];

var contentStyles = {};
let contentStyles = {};

if (titleTag === 'button') {
titleClasses.push('c-accordion__title--button');
Expand All @@ -71,6 +71,11 @@ registerBlockType('pb/accordion-item', {
'data-scroll-offset': scrollOffset,
});

const innerBlocksProps = useInnerBlocksProps.save({
id: 'ac-' + uuid,
className: 'c-accordion__content',
});

return (
<div { ...blockProps }>
<RichText.Content
Expand All @@ -80,12 +85,7 @@ registerBlockType('pb/accordion-item', {
role="button"
value={ title }
/>
<div
id={ 'ac-' + uuid }
className="c-accordion__content"
>
<InnerBlocks.Content />
</div>
<div { ...innerBlocksProps } />
</div>
);
},
Expand Down
2 changes: 1 addition & 1 deletion src/block/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
type: 'block',
blocks: ['core/paragraph'],
transform: (attributes, innerBlocks) => {
var newBlocks = innerBlocks.map(block => createBlock(block.name, block.attributes));
let newBlocks = innerBlocks.map(block => createBlock(block.name, block.attributes));

const level = attributes.titleTag !== 'button' ?
parseInt(attributes.titleTag.replace('h', '')) : 2;
Expand Down

0 comments on commit e4f1909

Please sign in to comment.