Skip to content

Commit

Permalink
Add Position group, ensure Position panel always appears just before …
Browse files Browse the repository at this point in the history
…Advanced
  • Loading branch information
andrewserong committed Dec 5, 2022
1 parent 8abd0a3 commit 338d16b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { default as InspectorControls } from '../inspector-controls';
import { default as InspectorControlsTabs } from '../inspector-controls-tabs';
import useInspectorControlsTabs from '../inspector-controls-tabs/use-inspector-controls-tabs';
import AdvancedControls from '../inspector-controls-tabs/advanced-controls-panel';
import PositionControls from '../inspector-controls-tabs/position-controls-panel';

function useContentBlocks( blockTypes, block ) {
const contentBlocksObjectAux = useMemo( () => {
Expand Down Expand Up @@ -308,6 +309,7 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
__experimentalGroup="border"
label={ __( 'Border' ) }
/>
<PositionControls />
<div>
<AdvancedControls />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* WordPress dependencies
*/
import {
PanelBody,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import InspectorControlsGroups from '../inspector-controls/groups';
import { default as InspectorControls } from '../inspector-controls';

const PositionControls = () => {
const fills = useSlotFills(
InspectorControlsGroups.position.Slot.__unstableName
);
const hasFills = Boolean( fills && fills.length );

if ( ! hasFills ) {
return null;
}

return (
<PanelBody
className="block-editor-block-inspector__position"
title={ __( 'Position' ) }
initialOpen={ false }
>
<InspectorControls.Slot __experimentalGroup="position" />
</PanelBody>
);
};

export default PositionControls;
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* Internal dependencies
*/
import AdvancedControls from './advanced-controls-panel';
import PositionControls from './position-controls-panel';
import { default as InspectorControls } from '../inspector-controls';

const SettingsTab = ( { showAdvancedControls = false } ) => (
<>
<InspectorControls.Slot />
<PositionControls />
{ showAdvancedControls && (
<div>
<AdvancedControls />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function useInspectorControlsTabs( blockName ) {
default: defaultGroup,
dimensions: dimensionsGroup,
list: listGroup,
position: positionGroup,
typography: typographyGroup,
} = InspectorControlsGroups;

Expand Down Expand Up @@ -47,6 +48,7 @@ export default function useInspectorControlsTabs( blockName ) {
// or Advanced Controls slot, then add this tab.
const settingsFills = [
...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( positionGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const InspectorControlsColor = createSlotFill( 'InspectorControlsColor' );
const InspectorControlsDimensions = createSlotFill(
'InspectorControlsDimensions'
);
const InspectorControlsPosition = createSlotFill( 'InspectorControlsPosition' );
const InspectorControlsTypography = createSlotFill(
'InspectorControlsTypography'
);
Expand All @@ -23,6 +24,7 @@ const groups = {
dimensions: InspectorControlsDimensions,
list: InspectorControlsListView,
typography: InspectorControlsTypography,
position: InspectorControlsPosition,
};

export default groups;
15 changes: 6 additions & 9 deletions packages/block-editor/src/hooks/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import classnames from 'classnames';
*/
import { __, sprintf } from '@wordpress/i18n';
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
import {
BaseControl,
CustomSelectControl,
PanelBody,
} from '@wordpress/components';
import { BaseControl, CustomSelectControl } from '@wordpress/components';
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
import {
useContext,
Expand Down Expand Up @@ -295,10 +291,11 @@ export const withInspectorControls = createHigherOrderComponent(

return [
positionSupport && (
<InspectorControls key="position">
<PanelBody title={ __( 'Position' ) } initialOpen={ false }>
<PositionEdit { ...props } />
</PanelBody>
<InspectorControls
key="position"
__experimentalGroup="position"
>
<PositionEdit { ...props } />
</InspectorControls>
),
<BlockEdit key="edit" { ...props } />,
Expand Down

0 comments on commit 338d16b

Please sign in to comment.