desktop.js
5 years ago
main.js
4 years ago
mobile.js
4 years ago
tablet-only.js
5 years ago
tablet.js
4 years ago
main.js
53 lines
| 1 | import buildCSS from '../../../utils/build-css'; |
| 2 | import valueWithUnit from '../../../utils/value-with-unit'; |
| 3 | |
| 4 | import { |
| 5 | Component, |
| 6 | } from '@wordpress/element'; |
| 7 | |
| 8 | import { |
| 9 | applyFilters, |
| 10 | } from '@wordpress/hooks'; |
| 11 | |
| 12 | export default class MainCSS extends Component { |
| 13 | render() { |
| 14 | const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props ); |
| 15 | |
| 16 | const { |
| 17 | uniqueId, |
| 18 | horizontalGap, |
| 19 | verticalGap, |
| 20 | verticalAlignment, |
| 21 | horizontalAlignment, |
| 22 | isQueryLoop, |
| 23 | } = attributes; |
| 24 | |
| 25 | let cssObj = []; |
| 26 | |
| 27 | const gridSelector = isQueryLoop |
| 28 | ? '.gb-post-template-' + uniqueId + ' > .gb-post-template-wrapper' |
| 29 | : '.gb-grid-wrapper-' + uniqueId + ' > .block-editor-inner-blocks > .block-editor-block-list__layout'; |
| 30 | |
| 31 | const gridItemSelector = isQueryLoop |
| 32 | ? gridSelector + ' > .block-editor-inner-blocks' |
| 33 | : gridSelector + ' > .gb-grid-column'; |
| 34 | |
| 35 | cssObj[ gridSelector ] = [ { |
| 36 | 'align-items': verticalAlignment, |
| 37 | 'justify-content': horizontalAlignment, |
| 38 | 'margin-left': horizontalGap || 0 === horizontalGap ? '-' + horizontalGap + 'px' : null, |
| 39 | } ]; |
| 40 | |
| 41 | cssObj[ gridItemSelector ] = [ { |
| 42 | 'padding-left': valueWithUnit( horizontalGap, 'px' ), |
| 43 | 'margin-bottom': valueWithUnit( verticalGap, 'px' ), |
| 44 | } ]; |
| 45 | |
| 46 | cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'grid' ); |
| 47 | |
| 48 | return ( |
| 49 | <style>{ buildCSS( cssObj ) }</style> |
| 50 | ); |
| 51 | } |
| 52 | } |
| 53 |