Skip to content

Commit

Permalink
Remove: Alignment options from button nested inside buttons (#19824)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Feb 7, 2020
1 parent a7fbd6e commit a8f6bda
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
19 changes: 15 additions & 4 deletions packages/block-editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { assign, get, has, includes, without } from 'lodash';
/**
* WordPress dependencies
*/
import { createContext, useContext } from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import {
Expand Down Expand Up @@ -99,6 +100,13 @@ export function addAttribute( settings ) {
return settings;
}

const AlignmentHookSettings = createContext( {} );

/**
* Allows to pass additional settings to the alignment hook.
*/
export const AlignmentHookSettingsProvider = AlignmentHookSettings.Provider;

/**
* Override the default edit UI to include new toolbar controls for block
* alignment, if block defines support.
Expand All @@ -108,14 +116,17 @@ export function addAttribute( settings ) {
*/
export const withToolbarControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { isEmbedButton } = useContext( AlignmentHookSettings );
const { name: blockName } = props;
// Compute valid alignments without taking into account,
// if the theme supports wide alignments or not.
// BlockAlignmentToolbar takes into account the theme support.
const validAlignments = getValidAlignments(
getBlockSupport( blockName, 'align' ),
hasBlockSupport( blockName, 'alignWide', true )
);
const validAlignments = isEmbedButton
? []
: getValidAlignments(
getBlockSupport( blockName, 'align' ),
hasBlockSupport( blockName, 'alignWide', true )
);

const updateAlignment = ( nextAlign ) => {
if ( ! nextAlign ) {
Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* Internal dependencies
*/
import './align';
import { AlignmentHookSettingsProvider } from './align';
import './anchor';
import './custom-class-name';
import './generated-class-name';

export { AlignmentHookSettingsProvider };
3 changes: 2 additions & 1 deletion packages/block-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import '@wordpress/keyboard-shortcuts';
/**
* Internal dependencies
*/
import './hooks';
import { AlignmentHookSettingsProvider as __experimentalAlignmentHookSettingsProvider } from './hooks';
export { __experimentalAlignmentHookSettingsProvider };
export * from './components';
export * from './utils';
export { storeConfig } from './store';
Expand Down
24 changes: 17 additions & 7 deletions packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import {
__experimentalAlignmentHookSettingsProvider as AlignmentHookSettingsProvider,
InnerBlocks,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -14,15 +17,22 @@ const UI_PARTS = {
hasSelectedUI: false,
};

// Inside buttons block alignment options are not supported.
const alignmentHooksSetting = {
isEmbedButton: true,
};

function ButtonsEdit( { className } ) {
return (
<div className={ className }>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ BUTTONS_TEMPLATE }
__experimentalUIParts={ UI_PARTS }
__experimentalMoverDirection="horizontal"
/>
<AlignmentHookSettingsProvider value={ alignmentHooksSetting }>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ BUTTONS_TEMPLATE }
__experimentalUIParts={ UI_PARTS }
__experimentalMoverDirection="horizontal"
/>
</AlignmentHookSettingsProvider>
</div>
);
}
Expand Down

0 comments on commit a8f6bda

Please sign in to comment.