PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / alignment-toolbar / BlockWidth.jsx
generateblocks / src / components / alignment-toolbar Last commit date
AlignmentToolbar.jsx 1 year ago BlockWidth.jsx 1 year ago
BlockWidth.jsx
74 lines
1 import { __ } from '@wordpress/i18n';
2 import { MenuGroup, MenuItem } from '@wordpress/components';
3 import { useSelect } from '@wordpress/data';
4 import { store as blockEditorStore, useSetting } from '@wordpress/block-editor';
5 import { alignNone, stretchWide, stretchFullWidth } from '@wordpress/icons';
6 import { applyFilters } from '@wordpress/hooks';
7
8 export function BlockWidth( { align, onChange, clientId } ) {
9 const hasWideSize = useSetting( 'layout.wideSize' );
10 const { themeSupportsAlignWide } = useSelect(
11 ( select ) => {
12 const { getSettings } = select( blockEditorStore );
13 return {
14 themeSupportsAlignWide: getSettings()?.alignWide,
15 };
16 },
17 []
18 );
19 const {
20 getBlockRootClientId,
21 } = useSelect( ( select ) => select( blockEditorStore ), [] );
22
23 const removeBlockWidthOptions = applyFilters(
24 'generateblocks.editor.removeBlockWidthOptions',
25 false,
26 { clientId }
27 );
28
29 if ( ( ! themeSupportsAlignWide && ! hasWideSize ) || removeBlockWidthOptions ) {
30 return null;
31 }
32
33 const parentBlockId = getBlockRootClientId( clientId );
34
35 if ( parentBlockId ) {
36 return null;
37 }
38
39 const options = [
40 {
41 label: __( 'Default', 'generateblocks' ),
42 value: '',
43 icon: alignNone,
44 },
45 {
46 label: __( 'Wide', 'generateblocks' ),
47 value: 'wide',
48 icon: stretchWide,
49 },
50 {
51 label: __( 'Full', 'generateblocks' ),
52 value: 'full',
53 icon: stretchFullWidth,
54 },
55 ];
56
57 return (
58 <MenuGroup label={ __( 'Block Width', 'generateblocks' ) }>
59 { options.map( ( option ) => {
60 return (
61 <MenuItem
62 key={ option.value }
63 isPressed={ align === option.value }
64 onClick={ () => onChange( option.value ) }
65 icon={ option.icon }
66 >
67 { option.label }
68 </MenuItem>
69 );
70 } ) }
71 </MenuGroup>
72 );
73 }
74