store
2 months ago
GenerateBgImage.js
2 months ago
block-duplicate-helper.js
2 months ago
capitalize.js
2 months ago
color-code-to-class.js
2 months ago
color-slug-to-color-code.js
2 months ago
common.scss
2 weeks ago
convert-to-grid.js
2 months ago
default-color-palette.js
2 months ago
delete-from-array.js
2 months ago
depModules.js
2 months ago
disable-links.js
2 weeks ago
empty-string-to-undefined.js
2 months ago
example-data.js
2 months ago
fixBrokenUnicode.js
2 months ago
font-awesome-new.js
2 weeks ago
font-awesome-version.js
2 months ago
font-awesome.js
2 months ago
formatNumCol.js
2 months ago
gradient-slug-to-gradient-code.js
2 months ago
heading-level-utils.js
2 months ago
hex-to-rgba.js
2 months ago
horizontal-scroll-controls.js
2 months ago
icon-label.js
2 weeks ago
is-excludes-blocks.js
2 months ago
is-gradient-style.js
2 months ago
is-hex-color.js
2 months ago
is-not-json.js
2 months ago
is-parent-reusable-block.js
13 hours ago
merge-colors.js
2 months ago
multi-array-flaten.js
2 months ago
removeProperty.js
2 months ago
replaceClientId.js
2 months ago
sanitizeSlug.js
2 months ago
settings-page-url.js
2 weeks ago
strip-html.js
2 months ago
taxonomy-utils.js
2 months ago
to-number.js
2 months ago
to-preset-spacing-var.js
2 months ago
unit-options.js
2 months ago
wrap-unwrap.js
2 months ago
GenerateBgImage.js
134 lines
| 1 | /** |
| 2 | * GenerateBgImage deprecated |
| 3 | * |
| 4 | * save.jsに反映される� |
| 5 | 容がutils� |
| 6 | にあると互換性対応が出来ないので各ブロック� |
| 7 | に移植 |
| 8 | * |
| 9 | * 以下で使用 |
| 10 | * Outer 0.60.0-1.26.0 |
| 11 | * Slider Item 0.0.0-1.22.1 |
| 12 | * 関連 #925 #950 #1032 |
| 13 | */ |
| 14 | import hex2rgba from './hex-to-rgba'; |
| 15 | const GenerateBgImage = (props) => { |
| 16 | const { attributes, clientId, prefix } = props; |
| 17 | const { bgImageMobile, bgImageTablet, bgImage, bgColor, opacity, bgSize } = |
| 18 | attributes; |
| 19 | |
| 20 | const mobileViewport = 'max-width: 575.98px'; |
| 21 | const tabletViewport = 'min-width: 576px'; |
| 22 | const pcViewport = 'min-width: 1200px'; |
| 23 | const underPcViewport = 'max-width: 1199.98px'; |
| 24 | |
| 25 | let backgroundStyle; |
| 26 | const backgroundPosition = 'background-position:center!important;'; |
| 27 | if ('cover' === bgSize) { |
| 28 | backgroundStyle = `background-size:${bgSize}!important; ${backgroundPosition}`; |
| 29 | } else if ('repeat' === bgSize) { |
| 30 | backgroundStyle = `background-repeat:${bgSize}!important; ${backgroundPosition}`; |
| 31 | } else { |
| 32 | backgroundStyle = ``; |
| 33 | } |
| 34 | |
| 35 | let bgColorWOpacity; |
| 36 | |
| 37 | //hexからrgbaに変換 |
| 38 | if (bgColor) { |
| 39 | bgColorWOpacity = hex2rgba(bgColor, opacity); |
| 40 | } else { |
| 41 | //背景色をクリアした時は、白に変更 |
| 42 | bgColorWOpacity = hex2rgba('#fff', opacity); |
| 43 | } |
| 44 | |
| 45 | //mobile only |
| 46 | if (bgImageMobile && !bgImageTablet && !bgImage) { |
| 47 | return ( |
| 48 | <style>{`.${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageMobile}); ${backgroundStyle}}`}</style> |
| 49 | ); |
| 50 | } |
| 51 | //tablet only |
| 52 | if (!bgImageMobile && bgImageTablet && !bgImage) { |
| 53 | return ( |
| 54 | <style>{`.${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageTablet}); ${backgroundStyle}}`}</style> |
| 55 | ); |
| 56 | } |
| 57 | //pc only |
| 58 | if (!bgImageMobile && !bgImageTablet && bgImage) { |
| 59 | return ( |
| 60 | <style>{`.${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImage}); ${backgroundStyle}}`}</style> |
| 61 | ); |
| 62 | } |
| 63 | //pc -mobile |
| 64 | if (bgImageMobile && !bgImageTablet && bgImage) { |
| 65 | return ( |
| 66 | <style> |
| 67 | {` |
| 68 | @media screen and (${underPcViewport}) { |
| 69 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageMobile}); ${backgroundStyle}} |
| 70 | } |
| 71 | @media screen and (${pcViewport}) { |
| 72 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImage}); ${backgroundStyle}} |
| 73 | } |
| 74 | `} |
| 75 | </style> |
| 76 | ); |
| 77 | } |
| 78 | //pc -tablet |
| 79 | if (!bgImageMobile && bgImageTablet && bgImage) { |
| 80 | return ( |
| 81 | <style> |
| 82 | {` |
| 83 | @media screen and (${underPcViewport}) { |
| 84 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageTablet}); ${backgroundStyle}} |
| 85 | } |
| 86 | @media screen and (${pcViewport}) { |
| 87 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImage}); ${backgroundStyle}} |
| 88 | } |
| 89 | `} |
| 90 | </style> |
| 91 | ); |
| 92 | } |
| 93 | //tablet - mobile |
| 94 | if (bgImageMobile && bgImageTablet && !bgImage) { |
| 95 | return ( |
| 96 | <style> |
| 97 | {` |
| 98 | @media screen and (${mobileViewport}) { |
| 99 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageMobile}); ${backgroundStyle}} |
| 100 | } |
| 101 | @media screen and (${tabletViewport}) { |
| 102 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageTablet}); ${backgroundStyle}} |
| 103 | } |
| 104 | `} |
| 105 | </style> |
| 106 | ); |
| 107 | } |
| 108 | //pc -tablet - mobile |
| 109 | if (bgImageMobile && bgImageTablet && bgImage) { |
| 110 | return ( |
| 111 | <style> |
| 112 | {` |
| 113 | @media screen and (${mobileViewport}) { |
| 114 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageMobile}); ${backgroundStyle}} |
| 115 | } |
| 116 | @media screen and (${tabletViewport}) { |
| 117 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImageTablet}); ${backgroundStyle}} |
| 118 | } |
| 119 | @media screen and (${pcViewport}) { |
| 120 | .${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}), url(${bgImage}); ${backgroundStyle}} |
| 121 | } |
| 122 | `} |
| 123 | </style> |
| 124 | ); |
| 125 | } |
| 126 | //no background image |
| 127 | if (!bgImageMobile && !bgImageTablet && !bgImage) { |
| 128 | return ( |
| 129 | <style>{`.${prefix}-${clientId}{background: linear-gradient(${bgColorWOpacity}, ${bgColorWOpacity}); ${backgroundStyle}}`}</style> |
| 130 | ); |
| 131 | } |
| 132 | }; |
| 133 | export default GenerateBgImage; |
| 134 |