desktop.js
4 years ago
main.js
3 years ago
mobile.js
3 years ago
tablet-only.js
4 years ago
tablet.js
3 years ago
main.js
76 lines
| 1 | import buildCSS from '../../../utils/build-css'; |
| 2 | import { applyFilters } from '@wordpress/hooks'; |
| 3 | import shorthandCSS from '../../../utils/shorthand-css'; |
| 4 | import SpacingCSS from '../../../extend/inspector-control/controls/spacing/components/SpacingCSS'; |
| 5 | |
| 6 | export default function MainCSS( props ) { |
| 7 | const attributes = applyFilters( 'generateblocks.editor.cssAttrs', props.attributes, props ); |
| 8 | |
| 9 | const { |
| 10 | uniqueId, |
| 11 | paddingTop, |
| 12 | paddingRight, |
| 13 | paddingBottom, |
| 14 | paddingLeft, |
| 15 | paddingUnit, |
| 16 | borderSizeTop, |
| 17 | borderSizeRight, |
| 18 | borderSizeBottom, |
| 19 | borderSizeLeft, |
| 20 | borderRadiusTopRight, |
| 21 | borderRadiusBottomRight, |
| 22 | borderRadiusBottomLeft, |
| 23 | borderRadiusTopLeft, |
| 24 | borderRadiusUnit, |
| 25 | borderColor, |
| 26 | objectFit, |
| 27 | width, |
| 28 | height, |
| 29 | alignment, |
| 30 | } = attributes; |
| 31 | |
| 32 | let cssObj = []; |
| 33 | |
| 34 | const floats = { |
| 35 | floatLeft: 'left', |
| 36 | floatRight: 'right', |
| 37 | floatNone: 'none', |
| 38 | }; |
| 39 | |
| 40 | cssObj[ '.editor-styles-wrapper .gb-block-image-' + uniqueId ] = [ { |
| 41 | padding: shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), |
| 42 | 'text-align': ! alignment.startsWith( 'float' ) ? alignment : null, |
| 43 | float: alignment.startsWith( 'float' ) ? floats[ alignment ] : 'none', |
| 44 | position: alignment.startsWith( 'float' ) ? 'relative' : null, |
| 45 | 'z-index': alignment.startsWith( 'float' ) ? '22' : null, |
| 46 | 'max-width': 'unset', |
| 47 | } ]; |
| 48 | |
| 49 | SpacingCSS( cssObj, '.editor-styles-wrapper .gb-block-image-' + uniqueId, attributes ); |
| 50 | |
| 51 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId ] = [ { |
| 52 | 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ), |
| 53 | 'border-color': borderColor, |
| 54 | width, |
| 55 | height, |
| 56 | 'object-fit': objectFit, |
| 57 | } ]; |
| 58 | |
| 59 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId + ' + .components-placeholder__illustration' ] = [ { |
| 60 | 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ), |
| 61 | } ]; |
| 62 | |
| 63 | if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) { |
| 64 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId ].push( { |
| 65 | 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ), |
| 66 | 'border-style': 'solid', |
| 67 | } ); |
| 68 | } |
| 69 | |
| 70 | cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, props, 'image' ); |
| 71 | |
| 72 | return ( |
| 73 | <style>{ buildCSS( cssObj ) }</style> |
| 74 | ); |
| 75 | } |
| 76 |