PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.8
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.8
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / blocks / column / dynamicCss.js

dynamicCss.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/blocks/column/dynamicCss.js

254 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { backgroundStyle, gradientHoverStyle } from "../../controls/controls";
2 import { boxCss, objectToCssString, rangerCss, spacingGenerate, wrapInMediaQuery } from "../shared/helpFn";
3
4 const cacheCss = { desktop: "", mobile: "", tablet: "" };
5
6 const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => {
7 const {
8 uniqueId,
9 columnWidth,
10 columnBg,
11 columnBgImage,
12 columnBorder,
13 columnZIndex,
14 columnPadding,
15 columnMargin,
16 columnBorderWidth,
17 columnBorderRadius,
18 columnBoxShadowEnable,
19 columnBoxShadow,
20 columnVisibilityHideDesktop,
21 columnVisibilityHideTablet,
22 columnVisibilityHideMobile,
23 columnBgImageHover,
24 columnBoxShadowEnableHover,
25 columnBoxShadowHover,
26 columnOverlayType,
27 columnOverlayBg,
28 columnOverlayOpacity,
29 columnOverlayBlandMode,
30 columnBorderWidthHover,
31 columnBorderRadiusHover,
32 globalBreakPointData,
33 parentColumnGap,
34 reduceColWidth,
35 parentContainerFlexDirection,
36 } = attributes;
37
38 const imageNormalOverlay = (deviceType) => {
39 return ["image", "video"].includes(columnBg.color.style)
40 ? [
41 {
42 class: `#${uniqueId}`,
43 styles: {
44 position: "relative",
45 },
46 },
47 {
48 class: `#${uniqueId}::after`,
49 styles: {
50 position: "absolute",
51 content: '""',
52 top: "0",
53 left: "0",
54 width: "100%",
55 height: "100%",
56 "pointer-events": "none",
57 },
58 },
59 {
60 class: `#${uniqueId}::after`,
61 styles: {
62 ...backgroundStyle(columnOverlayBg, "", false, "no-overlay" !== columnOverlayType),
63 "mix-blend-mode": columnOverlayBlandMode,
64 transition: "all 0.3s ease-in-out",
65 },
66 },
67 {
68 class: `#${uniqueId}::after`,
69 styles: {
70 opacity:
71 "no-overlay" !== columnOverlayType
72 ? columnOverlayOpacity?.device?.[deviceType] +
73 columnOverlayOpacity?.unit?.[deviceType]
74 : "0",
75 },
76 },
77 ]
78 : [];
79 };
80
81 const imageOverlayStyles = (deviceType) => {
82 return [
83 ...imageNormalOverlay(deviceType),
84 // ...imageHoverOverlay( deviceType ),
85 ];
86 };
87 const columnMaxWidth = (deviceType) => {
88 return page === "frontend"
89 ? [
90 {
91 class: `#${uniqueId}`,
92 styles: {
93 "max-width": rangerCss(columnWidth, [deviceType]) ? `calc(${rangerCss(columnWidth, [deviceType])} - ${ (rangerCss(columnWidth, [deviceType]) !== "100%") ? rangerCss(reduceColWidth, [deviceType]) : "0px" })` : "",
94 width: rangerCss(columnWidth, [deviceType]) ? rangerCss(columnWidth, [deviceType]) + "!important" : "",
95 },
96 },
97 ]
98 : [
99 {
100 class: `#${uniqueId}`,
101 styles: {
102 // "flex-basis": columnWidth.device?.[deviceType] + columnWidth.unit?.[deviceType],
103 "flex-basis": rangerCss(columnWidth, [deviceType]) ? `calc(${rangerCss(columnWidth, [deviceType])} - ${ (rangerCss(columnWidth, [deviceType]) !== "100%") ? rangerCss(reduceColWidth, [deviceType]) : "0px" })` : "",
104 "min-width": 0,
105 "max-width": "100%",
106 // width: [ "column", "column-reverse" ].includes( parentContainerFlexDirection?.device?.[ deviceType ] ) ? rangerCss(columnWidth, [deviceType]) + "!important" : "",
107 width: rangerCss(columnWidth, [deviceType]) ? rangerCss(columnWidth, [deviceType]) + "!important" : "",
108 },
109 },
110 {
111 class: `#${uniqueId} .components-resizable-box__container .components-resizable-box__handle-right`,
112 styles: {
113 right: `calc(-11.5px - (${rangerCss(parentColumnGap, [deviceType])} / 2))`,
114 },
115 },
116 {
117 class: `#${uniqueId} .components-resizable-box__container .components-resizable-box__handle-left`,
118 styles: {
119 left: `calc(-11.5px - (${rangerCss(parentColumnGap, [deviceType])} / 2))`,
120 },
121 },
122 ];
123 };
124
125 const responsiveCss = (deviceType) => {
126 return [
127 ...columnMaxWidth(deviceType, page),
128 {
129 class: `#${uniqueId}`,
130 styles: {
131 // 'max-width':
132 // columnWidth.device[ deviceType ] +
133 // columnWidth.unit[ deviceType ],
134 "border-width": spacingGenerate(columnBorderWidth, deviceType),
135 "border-radius": spacingGenerate(columnBorderRadius, deviceType),
136 "box-shadow": boxCss(columnBoxShadowEnable, deviceType, columnBoxShadow, "color"),
137 },
138 },
139 {
140 class: `#${uniqueId}:hover`,
141 styles: {
142 "box-shadow": boxCss(columnBoxShadowEnableHover, deviceType, columnBoxShadowHover, "color"),
143 "border-width": spacingGenerate(columnBorderWidthHover, deviceType),
144 "border-radius": spacingGenerate(columnBorderRadiusHover, deviceType),
145 },
146 },
147 {
148 class: `#${uniqueId} .wp-block-sp-smart-post-show-column`,
149 styles: {
150 padding: spacingGenerate(columnPadding, deviceType),
151 margin: spacingGenerate(columnMargin, deviceType),
152 },
153 },
154 ];
155 };
156
157 const desktopCss = [
158 ...responsiveCss("Desktop"),
159 ...imageOverlayStyles("Desktop"),
160 {
161 class: `#${uniqueId}`,
162 styles: {
163 ...backgroundStyle(columnBg, columnBgImage, false),
164 "border-style": columnBorder.style,
165 "border-color": columnBorder.color,
166 "z-index": columnZIndex !== "" ? columnZIndex : 2,
167 },
168 },
169 {
170 class: `#${uniqueId}:hover`,
171 styles: {
172 "border-color": columnBorder.hoverColor,
173 // ...backgroundStyle( columnBg, {}, true ),
174 },
175 },
176 ...gradientHoverStyle(`.${uniqueId}`, columnBg, columnBgImageHover, columnBgImage),
177 {
178 class: `#${uniqueId} .sp-smart-post-show-column, .${uniqueId} .sp-smart-post-column-wrapper`,
179 styles: {
180 // position: 'relative',
181 // height: '100%',
182 "z-index": columnZIndex || 1,
183 },
184 },
185 {
186 class: `#${uniqueId} .sp-smart-post-column-block-wrapper-link`,
187 styles: {
188 // display: 'block',
189 // position: 'absolute',
190 // top: '0',
191 // left: '0',
192 // width: '100%',
193 // height: '100%',
194 // 'text-decoration': 'none',
195 // 'background-color': 'transparent',
196 "pointer-events": page === "editor" ? "none" : "auto",
197 },
198 },
199 // {
200 // class: `#${uniqueId} .sp-smart-post-column-block-wrapper-link:focus`,
201 // styles: {
202 // outline: 'none',
203 // },
204 // },
205 {
206 class: `#${uniqueId}`,
207 styles: {
208 display: columnVisibilityHideDesktop ? "none" : "block",
209 },
210 },
211 ];
212
213 cacheCss.desktop = objectToCssString(desktopCss);
214
215 if ("Tablet" === currentDevice || "all" === currentDevice) {
216 const tabletCss = [
217 ...responsiveCss("Tablet"),
218 ...imageOverlayStyles("Tablet"),
219 {
220 class: `#${uniqueId}`,
221 styles: {
222 display: columnVisibilityHideTablet ? "none" : "block",
223 },
224 },
225 ];
226 cacheCss.tablet = wrapInMediaQuery(
227 objectToCssString(tabletCss),
228 `only screen and (max-width: ${globalBreakPointData?.tablet}px)`
229 );
230 }
231 if ("Mobile" === currentDevice || "all" === currentDevice) {
232 const mobileCss = [
233 ...responsiveCss("Mobile"),
234 ...imageOverlayStyles("Mobile"),
235 {
236 class: `#${uniqueId}`,
237 styles: {
238 display: columnVisibilityHideMobile ? "none" : "block",
239 // 'max-width': '100%',
240 },
241 },
242 ];
243
244 cacheCss.mobile = wrapInMediaQuery(
245 objectToCssString(mobileCss),
246 `only screen and (max-width: ${globalBreakPointData?.mobile}px)`
247 );
248 }
249
250 return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`;
251 };
252
253 export default dynamicCss;
254