Skip to content

Commit

Permalink
Merge branch 'SLB-459-accordion-heading-items' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dan2k3k4 committed Oct 29, 2024
2 parents 4b03625 + 21c44c2 commit 2543831
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
16 changes: 5 additions & 11 deletions packages/drupal/gutenberg_blocks/js/blocks/accordion-item-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const { t: __ } = Drupal;
registerBlockType<{
title: string;
icon?: string;
headingLevel: string;
}>('custom/accordion-item-text', {
title: 'Accordion Item Text',
icon: 'text',
category: 'layout',
parent: ['custom/accordion'],
usesContext: ['custom/accordion-headingLevel'],
attributes: {
title: {
type: 'string',
Expand All @@ -27,13 +27,9 @@ registerBlockType<{
icon: {
type: 'string',
},
headingLevel: {
type: 'string',
default: 'h3',
},
},
edit: (props) => {
const { attributes, setAttributes } = props;
const { attributes, setAttributes, context } = props;
const icons = [
{ label: __('- Select an optional icon -'), value: '' },
{ label: __('Checkmark'), value: 'checkmark' },
Expand All @@ -45,9 +41,7 @@ registerBlockType<{
icon: attributes.icon === undefined ? '' : attributes.icon,
});

setAttributes({
headingLevel: attributes.headingLevel,
});
const headingLevel = context['custom/accordion-headingLevel'];

return (
<Fragment>
Expand All @@ -58,7 +52,7 @@ registerBlockType<{
</div>
<div>
{__('Currently it is set to:')}{' '}
<strong>{attributes.headingLevel}</strong>
<strong>{headingLevel as string}</strong>
</div>
</PanelBody>
<PanelBody title={__('Block settings')}>
Expand All @@ -83,7 +77,7 @@ registerBlockType<{
>
<RichText
identifier="title"
tagName={attributes.headingLevel as keyof HTMLElementTagNameMap}
tagName={headingLevel as keyof HTMLElementTagNameMap}
value={attributes.title}
allowedFormats={[]}
// @ts-ignore
Expand Down
18 changes: 3 additions & 15 deletions packages/drupal/gutenberg_blocks/js/blocks/accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { InnerBlocks, InspectorControls } from 'wordpress__block-editor';
import { registerBlockType } from 'wordpress__blocks';
import { PanelBody, SelectControl } from 'wordpress__components';
import { dispatch, useSelect } from 'wordpress__data';

const { t: __ } = Drupal;

Expand All @@ -24,22 +23,11 @@ registerBlockType<{
default: HeadingLevels.H2,
},
},
providesContext: {
'custom/accordion-headingLevel': 'headingLevel',
},
edit: (props) => {
const { attributes, setAttributes } = props;
const headingLevel = attributes.headingLevel;

/* eslint-disable-next-line */
const { children } = useSelect((select) => ({
children: select('core/block-editor').getBlocksByClientId(props.clientId),
}));

if (children[0].innerBlocks) {
children[0].innerBlocks.forEach((child: any) => {
dispatch('core/editor').updateBlockAttributes(child.clientId, {
headingLevel: headingLevel,
});
});
}

return (
<>
Expand Down

0 comments on commit 2543831

Please sign in to comment.