Display.js
2 years ago
FlexDirection.js
3 years ago
LayoutCSS.js
3 years ago
LayoutControl.js
3 years ago
ThemeWidth.js
2 years ago
ZIndex.js
3 years ago
editor.scss
3 years ago
ThemeWidth.js
68 lines
| 1 | import { BaseControl, Button, ButtonGroup, Tooltip } from '@wordpress/components'; |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import { alignNone, stretchWide, stretchFullWidth } from '@wordpress/icons'; |
| 4 | import { useSelect } from '@wordpress/data'; |
| 5 | import { store as blockEditorStore, useSetting } from '@wordpress/block-editor'; |
| 6 | |
| 7 | export default function ThemeWidth( { value, onChange } ) { |
| 8 | const hasWideSize = useSetting( 'layout.wideSize' ); |
| 9 | const { themeSupportsAlignWide } = useSelect( |
| 10 | ( select ) => { |
| 11 | const { getSettings } = select( blockEditorStore ); |
| 12 | return { |
| 13 | themeSupportsAlignWide: getSettings()?.alignWide, |
| 14 | }; |
| 15 | }, |
| 16 | [] |
| 17 | ); |
| 18 | |
| 19 | if ( ! themeSupportsAlignWide && ! hasWideSize ) { |
| 20 | return null; |
| 21 | } |
| 22 | |
| 23 | const options = [ |
| 24 | { |
| 25 | label: __( 'Default', 'generateblocks' ), |
| 26 | value: '', |
| 27 | icon: alignNone, |
| 28 | }, |
| 29 | { |
| 30 | label: __( 'Wide', 'generateblocks' ), |
| 31 | value: 'wide', |
| 32 | icon: stretchWide, |
| 33 | }, |
| 34 | { |
| 35 | label: __( 'Full', 'generateblocks' ), |
| 36 | value: 'full', |
| 37 | icon: stretchFullWidth, |
| 38 | }, |
| 39 | ]; |
| 40 | |
| 41 | return ( |
| 42 | <BaseControl |
| 43 | label={ __( 'Block Alignment', 'generateblocks' ) } |
| 44 | id="gblocks-theme-width-button-group" |
| 45 | help={ __( 'Change the width of this block using a method defined by your theme.', 'generateblocks' ) } |
| 46 | > |
| 47 | <div> |
| 48 | <ButtonGroup |
| 49 | className="gblocks-alignment-button-group" |
| 50 | id="gblocks-theme-width-button-group" |
| 51 | > |
| 52 | { options.map( ( option ) => { |
| 53 | return ( |
| 54 | <Tooltip key={ 'align' + option.value } text={ option.label }> |
| 55 | <Button |
| 56 | variant={ value === option.value ? 'primary' : '' } |
| 57 | onClick={ () => onChange( option.value ) } |
| 58 | icon={ option.icon } |
| 59 | /> |
| 60 | </Tooltip> |
| 61 | ); |
| 62 | } ) } |
| 63 | </ButtonGroup> |
| 64 | </div> |
| 65 | </BaseControl> |
| 66 | ); |
| 67 | } |
| 68 |