generateblocks
/
src
/
extend
/
inspector-control
/
controls
/
layout
/
components
/
LayoutControl.js
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
LayoutControl.js
56 lines
| 1 | import { BaseControl, ButtonGroup, Button, Tooltip } from '@wordpress/components'; |
| 2 | import { Fragment } from '@wordpress/element'; |
| 3 | import { flexOptions } from '../options'; |
| 4 | import './editor.scss'; |
| 5 | import classnames from 'classnames'; |
| 6 | |
| 7 | export default ( props ) => { |
| 8 | const { |
| 9 | value, |
| 10 | onChange, |
| 11 | label, |
| 12 | attributeName, |
| 13 | directionValue, |
| 14 | fallback, |
| 15 | } = props; |
| 16 | |
| 17 | function ButtonElement( option ) { |
| 18 | return ( |
| 19 | <Button |
| 20 | isPrimary={ option.value === value } |
| 21 | className={ ! value && fallback === option.value ? 'is-inherited' : '' } |
| 22 | onClick={ () => onChange( option.value ) } |
| 23 | > |
| 24 | { option.icon || option.label } |
| 25 | </Button> |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | return ( |
| 30 | <BaseControl |
| 31 | id={ attributeName } |
| 32 | label={ label } |
| 33 | className={ classnames( { |
| 34 | [ `gblocks-flex-direction-${ attributeName + '-' + directionValue }` ]: true, |
| 35 | } ) } |
| 36 | > |
| 37 | <ButtonGroup id={ attributeName } className="gblocks-flex-button-group"> |
| 38 | { |
| 39 | flexOptions[ attributeName ].map( ( flexOption, index ) => { |
| 40 | return ( |
| 41 | <Fragment key={ attributeName + index }> |
| 42 | { !! flexOption.icon |
| 43 | ? <Tooltip text={ flexOption.label || flexOption.value }> |
| 44 | { ButtonElement( flexOption ) } |
| 45 | </Tooltip> |
| 46 | : ButtonElement( flexOption ) |
| 47 | } |
| 48 | </Fragment> |
| 49 | ); |
| 50 | } ) |
| 51 | } |
| 52 | </ButtonGroup> |
| 53 | </BaseControl> |
| 54 | ); |
| 55 | }; |
| 56 |