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