Skip to content

Commit

Permalink
Add element-selector to group block (#28576)
Browse files Browse the repository at this point in the history
* Add element-selector

* Inline in the main return

* template-port: inline advanced controls in main return for consistency
  • Loading branch information
aristath authored Feb 2, 2021
1 parent a4b7c9b commit 5259168
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
43 changes: 34 additions & 9 deletions packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { useSelect } from '@wordpress/data';
import {
InnerBlocks,
useBlockProps,
InspectorAdvancedControls,
__experimentalUseInnerBlocksProps as useInnerBlocksProps,
} from '@wordpress/block-editor';
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';
import {
SelectControl,
__experimentalBoxControl as BoxControl,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
const { __Visualizer: BoxControlVisualizer } = BoxControl;

function GroupEdit( { attributes, clientId } ) {
function GroupEdit( { attributes, setAttributes, clientId } ) {
const hasInnerBlocks = useSelect(
( select ) => {
const { getBlock } = select( 'core/block-editor' );
Expand All @@ -34,13 +39,33 @@ function GroupEdit( { attributes, clientId } ) {
);

return (
<TagName { ...blockProps }>
<BoxControlVisualizer
values={ attributes.style?.spacing?.padding }
showValues={ attributes.style?.visualizers?.padding }
/>
<div { ...innerBlocksProps } />
</TagName>
<>
<InspectorAdvancedControls>
<SelectControl
label={ __( 'HTML element' ) }
options={ [
{ label: __( 'Default (<div>)' ), value: 'div' },
{ label: '<header>', value: 'header' },
{ label: '<main>', value: 'main' },
{ label: '<section>', value: 'section' },
{ label: '<article>', value: 'article' },
{ label: '<aside>', value: 'aside' },
{ label: '<footer>', value: 'footer' },
] }
value={ TagName }
onChange={ ( value ) =>
setAttributes( { tagName: value } )
}
/>
</InspectorAdvancedControls>
<TagName { ...blockProps }>
<BoxControlVisualizer
values={ attributes.style?.spacing?.padding }
showValues={ attributes.style?.visualizers?.padding }
/>
<div { ...innerBlocksProps } />
</TagName>
</>
);
}

Expand Down
38 changes: 18 additions & 20 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,26 @@ export default function TemplatePartEdit( {
);
}

const inspectorAdvancedControls = (
<InspectorAdvancedControls>
<SelectControl
label={ __( 'HTML element' ) }
options={ [
{ label: __( 'Default (<div>)' ), value: 'div' },
{ label: '<header>', value: 'header' },
{ label: '<main>', value: 'main' },
{ label: '<section>', value: 'section' },
{ label: '<article>', value: 'article' },
{ label: '<aside>', value: 'aside' },
{ label: '<footer>', value: 'footer' },
] }
value={ TagName }
onChange={ ( value ) => setAttributes( { tagName: value } ) }
/>
</InspectorAdvancedControls>
);

return (
<>
{ inspectorAdvancedControls }
<InspectorAdvancedControls>
<SelectControl
label={ __( 'HTML element' ) }
options={ [
{ label: __( 'Default (<div>)' ), value: 'div' },
{ label: '<header>', value: 'header' },
{ label: '<main>', value: 'main' },
{ label: '<section>', value: 'section' },
{ label: '<article>', value: 'article' },
{ label: '<aside>', value: 'aside' },
{ label: '<footer>', value: 'footer' },
] }
value={ TagName }
onChange={ ( value ) =>
setAttributes( { tagName: value } )
}
/>
</InspectorAdvancedControls>
<TagName { ...blockProps }>
{ isPlaceholder && (
<TemplatePartPlaceholder
Expand Down

0 comments on commit 5259168

Please sign in to comment.