-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove alignments from the root level of the site editor (#30079)
- Loading branch information
1 parent
39953e6
commit d7e2137
Showing
4 changed files
with
56 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/block-editor/src/components/block-alignment-control/use-available-alignments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useLayout } from '../block-list/layout'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
const DEFAULT_CONTROLS = [ 'left', 'center', 'right', 'wide', 'full' ]; | ||
const WIDE_CONTROLS = [ 'wide', 'full' ]; | ||
|
||
export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) { | ||
const { wideControlsEnabled = false } = useSelect( ( select ) => { | ||
const { getSettings } = select( blockEditorStore ); | ||
const settings = getSettings(); | ||
return { | ||
wideControlsEnabled: settings.alignWide, | ||
}; | ||
}, [] ); | ||
const layout = useLayout(); | ||
const supportsAlignments = layout.type === 'default'; | ||
|
||
if ( ! supportsAlignments ) { | ||
return []; | ||
} | ||
const { alignments: availableAlignments = DEFAULT_CONTROLS } = layout; | ||
const enabledControls = controls.filter( | ||
( control ) => | ||
( layout.alignments || // Ignore the global wideAlignment check if the layout explicitely defines alignments. | ||
wideControlsEnabled || | ||
! WIDE_CONTROLS.includes( control ) ) && | ||
availableAlignments.includes( control ) | ||
); | ||
|
||
return enabledControls; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters