desktop.js
66 lines
| 1 | import buildCSS from '../../../utils/build-css'; |
| 2 | import shorthandCSS from '../../../utils/shorthand-css'; |
| 3 | import flexboxAlignment from '../../../utils/flexbox-alignment'; |
| 4 | |
| 5 | const { Component } = wp.element; |
| 6 | const { applyFilters } = wp.hooks; |
| 7 | |
| 8 | export default class DesktopCSS extends Component { |
| 9 | render() { |
| 10 | const { |
| 11 | attributes, |
| 12 | } = this.props; |
| 13 | |
| 14 | const { |
| 15 | uniqueId, |
| 16 | alignment, |
| 17 | marginTop, |
| 18 | marginRight, |
| 19 | marginBottom, |
| 20 | marginLeft, |
| 21 | marginUnit, |
| 22 | stack, |
| 23 | fillHorizontalSpace, |
| 24 | } = attributes; |
| 25 | |
| 26 | let cssObj = []; |
| 27 | |
| 28 | cssObj[ '.gb-button-wrapper-' + uniqueId ] = [ { |
| 29 | 'display': fillHorizontalSpace ? 'block' : false, // eslint-disable-line quote-props |
| 30 | 'margin': shorthandCSS( marginTop, marginRight, marginBottom, marginLeft, marginUnit ), // eslint-disable-line quote-props |
| 31 | 'justify-content': flexboxAlignment( alignment ), |
| 32 | 'flex-direction': stack ? 'column' : false, |
| 33 | 'align-items': stack ? flexboxAlignment( alignment ) : false, |
| 34 | } ]; |
| 35 | |
| 36 | cssObj[ '.gb-button-wrapper-' + uniqueId + ' > .block-editor-inner-blocks > .block-editor-block-list__layout' ] = [ { |
| 37 | 'flex-direction': stack ? 'column' : false, |
| 38 | } ]; |
| 39 | |
| 40 | if ( fillHorizontalSpace ) { |
| 41 | cssObj[ '.gb-button-wrapper-' + uniqueId + ' > .block-editor-inner-blocks > .block-editor-block-list__layout > .wp-block' ] = [ { |
| 42 | 'flex': '1', // eslint-disable-line quote-props |
| 43 | } ]; |
| 44 | |
| 45 | cssObj[ '.gb-button-wrapper-' + uniqueId + ' > .components-button' ] = [ { |
| 46 | 'background': '#fff', // eslint-disable-line quote-props |
| 47 | 'border': '1px solid #ddd', // eslint-disable-line quote-props |
| 48 | 'margin-top': '10px', |
| 49 | } ]; |
| 50 | } |
| 51 | |
| 52 | if ( stack && fillHorizontalSpace ) { |
| 53 | cssObj[ '.gb-button-wrapper-' + uniqueId + ' > .block-editor-inner-blocks > .block-editor-block-list__layout > .wp-block' ] = [ { |
| 54 | 'width': '100% !important', // eslint-disable-line quote-props |
| 55 | 'box-sizing': 'border-box', |
| 56 | } ]; |
| 57 | } |
| 58 | |
| 59 | cssObj = applyFilters( 'generateblocks.editor.desktopCSS', cssObj, 'button-container', this.props ); |
| 60 | |
| 61 | return ( |
| 62 | <style>{ buildCSS( cssObj ) }</style> |
| 63 | ); |
| 64 | } |
| 65 | } |
| 66 |