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 element-selector to group block #28576

Merged
merged 5 commits into from
Feb 2, 2021
Merged
Changes from 1 commit
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
45 changes: 36 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 @@ -33,14 +38,36 @@ function GroupEdit( { attributes, clientId } ) {
}
);

return (
<TagName { ...blockProps }>
<BoxControlVisualizer
values={ attributes.style?.spacing?.padding }
showValues={ attributes.style?.visualizers?.padding }
const inspectorAdvancedControls = (
<InspectorAdvancedControls>
aristath marked this conversation as resolved.
Show resolved Hide resolved
<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 } ) }
/>
<div { ...innerBlocksProps } />
</TagName>
</InspectorAdvancedControls>
);

return (
<>
{ inspectorAdvancedControls }
<TagName { ...blockProps }>
<BoxControlVisualizer
values={ attributes.style?.spacing?.padding }
showValues={ attributes.style?.visualizers?.padding }
/>
<div { ...innerBlocksProps } />
</TagName>
</>
);
}

Expand Down