desktop.js
4 years ago
main.js
2 years ago
mobile.js
2 years ago
tablet-only.js
4 years ago
tablet.js
2 years ago
tablet.js
74 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 | import BorderCSS from '../../../extend/inspector-control/controls/borders/BorderCSS'; |
| 6 | |
| 7 | export default function TabletCSS( props ) { |
| 8 | const attributes = applyFilters( 'generateblocks.editor.cssAttrs', props.attributes, props ); |
| 9 | |
| 10 | const { |
| 11 | uniqueId, |
| 12 | borderColor, |
| 13 | objectFitTablet, |
| 14 | widthTablet, |
| 15 | heightTablet, |
| 16 | alignment, |
| 17 | alignmentTablet, |
| 18 | } = attributes; |
| 19 | |
| 20 | const { |
| 21 | borderTopLeftRadiusTablet, |
| 22 | borderTopRightRadiusTablet, |
| 23 | borderBottomRightRadiusTablet, |
| 24 | borderBottomLeftRadiusTablet, |
| 25 | } = attributes.borders; |
| 26 | |
| 27 | let cssObj = []; |
| 28 | |
| 29 | const floats = { |
| 30 | floatLeft: 'left', |
| 31 | floatRight: 'right', |
| 32 | floatNone: 'none', |
| 33 | }; |
| 34 | |
| 35 | let float = alignmentTablet.startsWith( 'float' ) ? floats[ alignmentTablet ] : null; |
| 36 | |
| 37 | if ( |
| 38 | alignmentTablet && |
| 39 | ! float && |
| 40 | alignment.startsWith( 'float' ) |
| 41 | ) { |
| 42 | // We have a tablet alignment and desktop is set to float, so let's disable it. |
| 43 | float = 'none'; |
| 44 | } |
| 45 | |
| 46 | cssObj[ '.editor-styles-wrapper .gb-block-image-' + uniqueId ] = [ { |
| 47 | 'text-align': ! alignmentTablet.startsWith( 'float' ) ? alignmentTablet : null, |
| 48 | float, |
| 49 | position: float && 'none' !== float ? 'relative' : null, |
| 50 | 'z-index': float && 'none' !== float ? '22' : null, |
| 51 | } ]; |
| 52 | |
| 53 | SpacingCSS( cssObj, '.editor-styles-wrapper .gb-block-image-' + uniqueId, attributes.spacing, 'Tablet' ); |
| 54 | |
| 55 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId ] = [ { |
| 56 | 'border-color': borderColor, |
| 57 | width: widthTablet, |
| 58 | height: heightTablet, |
| 59 | 'object-fit': objectFitTablet, |
| 60 | } ]; |
| 61 | |
| 62 | BorderCSS( cssObj, '.editor-styles-wrapper .gb-image-' + uniqueId, attributes.borders, 'Tablet' ); |
| 63 | |
| 64 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId + ' + .components-placeholder__illustration' ] = [ { |
| 65 | 'border-radius': shorthandCSS( borderTopLeftRadiusTablet, borderTopRightRadiusTablet, borderBottomRightRadiusTablet, borderBottomLeftRadiusTablet ), |
| 66 | } ]; |
| 67 | |
| 68 | cssObj = applyFilters( 'generateblocks.editor.tabletCSS', cssObj, props, 'image' ); |
| 69 | |
| 70 | return ( |
| 71 | <style>{ buildCSS( cssObj ) }</style> |
| 72 | ); |
| 73 | } |
| 74 |