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 / post-grid-two / dynamicCss.js

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

270 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import sharedDynamicCss from "../shared/dynamicCss";
2 import { bgColor, convertToClassName, objectToCssString, removeEmptyCss, wrapInMediaQuery } from "../shared/helpFn";
3
4 const cacheCss = { desktop: "", mobile: "", tablet: "" };
5 const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => {
6 const {
7 uniqueId,
8 gridTwoHorizontalGap,
9 gridTwoVerticalGap,
10 gridTwoColumns,
11 largeItemHeight,
12 smallItemHeight,
13 largeItemTitleTypography,
14 equalHeightEnable,
15 globalBreakPointData,
16 contentOnHover,
17 contentHoverAnimate,
18 titleOnHover,
19 taxonomyOnHover,
20 metaOnHover,
21 readMoreOnHover,
22 excerptOnHover,
23 socialShareOnHover,
24 imageOverlayCustomColor,
25 // titleEffect,
26 // titleUnderlineEffect,
27 // titleEffectColor,
28 } = attributes;
29
30 const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page);
31
32 const animationTransforms = {
33 fadeInDown: "translateY(-20px)",
34 fadeInUp: "translateY(20px)",
35 fadeInRight: "translateX(20px)",
36 fadeInLeft: "translateX(-20px)",
37 slideInUp: "translateY(20px)",
38 slideInDown: "translateY(-20px)",
39 zoomIn: "scale(0.8)",
40 zoomOut: "scale(1.2)",
41 none: "translateY(0)", // fallback
42 };
43
44 const commonHiddenStyles = {
45 "max-height": 0,
46 overflow: "hidden",
47
48 transition: "opacity 1s ease-out, all 1s ease, max-height 1s ease-out, margin 1s;",
49 };
50
51 const responsiveCss = (deviceType) => {
52 return [
53 {
54 class: `.sp-h-gap-${convertToClassName(
55 gridTwoHorizontalGap.device.Desktop + gridTwoHorizontalGap.unit.Desktop
56 )}`,
57 property: "column-gap",
58 value: gridTwoHorizontalGap.device?.[deviceType] + gridTwoHorizontalGap.unit?.[deviceType],
59 },
60 {
61 class: `.sp-v-gap-${convertToClassName(
62 gridTwoVerticalGap.device.Desktop + gridTwoVerticalGap.unit.Desktop
63 )}`,
64 property: "row-gap",
65 value: gridTwoVerticalGap.device?.[deviceType] + gridTwoVerticalGap.unit?.[deviceType],
66 },
67 {
68 class: `#${uniqueId} .sp-smart-post-grid-two-contents`,
69 styles: {
70 display: "grid",
71 "row-gap": gridTwoVerticalGap.device?.[deviceType] + gridTwoVerticalGap.unit?.[deviceType],
72 },
73 },
74
75 {
76 class: `#${uniqueId} .sp-smart-post-grid-two-contents .sp-smart-post-dynamic-grid-contents`,
77 styles: {
78 "grid-template-columns": `repeat(${
79 gridTwoColumns.device?.[deviceType] ? gridTwoColumns.device?.[deviceType] : 2
80 }, 1fr)`,
81 },
82 },
83 {
84 class: `#${uniqueId} .sp-smart-post-static-grid-contents`,
85 styles: {
86 "column-gap": `${gridTwoHorizontalGap.device?.[deviceType]}${gridTwoHorizontalGap.unit?.[deviceType]}`,
87 "row-gap": `${gridTwoVerticalGap.device?.[deviceType]}${gridTwoVerticalGap.unit?.[deviceType]}`,
88 },
89 },
90 {
91 class: `#${uniqueId} .sp-smart-post-dynamic-grid-contents`,
92 styles: {
93 "column-gap": `${gridTwoHorizontalGap.device?.[deviceType]}${gridTwoHorizontalGap.unit?.[deviceType]}`,
94 "row-gap": `${gridTwoVerticalGap.device?.[deviceType]}${gridTwoVerticalGap.unit?.[deviceType]}`,
95 },
96 },
97 {
98 class: `#${uniqueId} .grid-two-container .sp-smart-post-static-grid-contents:not(.grid-two-layout-four)`,
99 styles: {
100 height: `${largeItemHeight.device?.[deviceType]}${largeItemHeight.unit?.[deviceType]}`,
101 },
102 },
103 {
104 class: `#${uniqueId} .grid-two-container .sp-smart-post-dynamic-grid-contents .sp-smart-post-card`,
105 styles: {
106 "min-height": equalHeightEnable
107 ? "auto"
108 : `${smallItemHeight.device?.[deviceType]}${smallItemHeight.unit?.[deviceType]}`,
109 },
110 },
111
112 // on hover content..............
113 {
114 class: `#${uniqueId} .sp-smart-post-card .sp-smart-post-card-content`,
115 styles: {
116 opacity: contentOnHover ? 0 : 1,
117 transform: contentOnHover
118 ? animationTransforms[contentHoverAnimate] || "translateY(0)"
119 : "translateY(0)",
120 transition: "opacity 0.3s ease, transform 0.3s ease",
121 },
122 },
123 {
124 class: `#${uniqueId} .sp-smart-post-card:hover .sp-smart-post-card-content`,
125 styles: {
126 opacity: contentOnHover ? 1 : 1,
127 },
128 },
129
130 {
131 class: `#${uniqueId} .sp-smart-post-template-one-content .sp-smart-post-title`,
132 styles: {
133 ...commonHiddenStyles,
134 opacity: titleOnHover && !contentOnHover ? 0 : 1,
135 "max-height": titleOnHover && !contentOnHover ? "0" : "auto",
136 },
137 },
138
139 {
140 class: `#${uniqueId} .sp-smart-post-grid-two .sp-smart-post-card .sp-smart-post-category`,
141 styles: {
142 ...commonHiddenStyles,
143 opacity: taxonomyOnHover && !contentOnHover ? 0 : 1,
144 "max-height": taxonomyOnHover && !contentOnHover ? "0" : "auto",
145 },
146 },
147
148 {
149 class: `#${uniqueId} .sp-smart-post-grid-two .sp-smart-post-template-one-content .sp-meta-data`,
150 styles: {
151 ...commonHiddenStyles,
152 opacity: metaOnHover && !contentOnHover ? 0 : 1,
153 "max-height": metaOnHover && !contentOnHover ? "0" : "auto",
154 },
155 },
156
157 {
158 class: `#${uniqueId} .sp-smart-post-grid-two .sp-smart-post-template-one-content .sp-smart-post-read-more-button`,
159 styles: {
160 ...commonHiddenStyles,
161 opacity: readMoreOnHover && !contentOnHover ? 0 : 1,
162 "max-height": readMoreOnHover && !contentOnHover ? "0" : "auto",
163 },
164 },
165
166 {
167 class: `#${uniqueId} .sp-smart-post-grid-two .sp-smart-post-template-one-content .sp-smart-post-excerpt-wrapper`,
168 styles: {
169 ...commonHiddenStyles,
170 opacity: excerptOnHover && !contentOnHover ? 0 : 1,
171 "max-height": excerptOnHover && !contentOnHover ? "0" : "auto",
172 },
173 },
174
175 {
176 class: `#${uniqueId} .sp-smart-post-grid-two .sp-smart-post-template-one-content .sp-smart-post-social-share`,
177 styles: {
178 ...commonHiddenStyles,
179 opacity: socialShareOnHover && !contentOnHover ? 0 : 1,
180 "max-height": socialShareOnHover && !contentOnHover ? "0" : "auto",
181 },
182 },
183 ];
184 };
185
186 const gridTwoStyles = [...removeEmptyCss("font-family", largeItemTitleTypography.typography.family, true)];
187
188 // Add Tablet styles
189
190 // Add Mobile styles
191
192 const desktopCss = [
193 ...sharedDesktopCss,
194 ...responsiveCss("Desktop"),
195 ...gridTwoStyles,
196 {
197 class: `#${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientation-three .sp-smart-post-card-content, #${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientations-four .sp-smart-post-card-content`,
198 styles: {
199 background: bgColor( imageOverlayCustomColor )
200 },
201 },
202
203 ];
204 if ( imageOverlayCustomColor.hover.style === "bgColor" ) {
205 desktopCss.push(...[
206 {
207 class: `#${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientation-three:hover .sp-smart-post-card-content, #${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientations-four:hover .sp-smart-post-card-content`,
208 styles: {
209 background: bgColor( imageOverlayCustomColor, "hover" )
210 },
211 },
212 ])
213 }
214 if ( imageOverlayCustomColor.hover.style !== "bgColor" ) {
215 desktopCss.push(...[
216 {
217 class: `#${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientation-three:hover .sp-smart-post-card-content:after, #${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientations-four:hover .sp-smart-post-card-content:after, #${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientation-three .sp-smart-post-card-content:after, #${uniqueId}.sp-smart-post-grid-two .sp-smart-post-card.overlay-type-orientations-four .sp-smart-post-card-content:after`,
218 styles: {
219 background: bgColor( imageOverlayCustomColor, "hover" )
220 },
221 },
222 ])
223 }
224
225 cacheCss.desktop = objectToCssString(desktopCss);
226
227 if ("Tablet" === currentDevice || "all" === currentDevice) {
228 const tabletCss = [...sharedTabletCss, ...responsiveCss("Tablet"), ...gridTwoStyles];
229 cacheCss.tablet = wrapInMediaQuery(
230 objectToCssString(tabletCss),
231 `only screen and (max-width: ${globalBreakPointData?.tablet}px)`
232 );
233 }
234 if ("Mobile" === currentDevice || "all" === currentDevice) {
235 const mobileCss = [
236 ...sharedMobileCss,
237 ...gridTwoStyles,
238 ...responsiveCss("Mobile"),
239 {
240 class: `#${uniqueId} .grid-two-container .sp-smart-post-grid-two-contents .sp-smart-post-dynamic-grid-contents`,
241 styles: {
242 "grid-template-columns": `repeat(${gridTwoColumns.device.Mobile || 1}, 1fr) !important`,
243 },
244 },
245 {
246 class: `#${uniqueId} .grid-two-container .sp-smart-post-grid-two-contents .sp-smart-post-static-grid-contents`,
247 styles: {
248 "grid-template-columns": `repeat(${gridTwoColumns.device.Mobile || 1}, 1fr) !important`,
249 },
250 },
251 {
252 class: `#${uniqueId} .grid-two-container .sp-smart-post-grid-two-contents .sp-smart-post-static-grid-contents .sp-smart-post-card`,
253 styles: {
254 "grid-column": `1 / 1`,
255 "grid-row": `auto`,
256 },
257 },
258 ];
259
260 cacheCss.mobile = wrapInMediaQuery(
261 objectToCssString(mobileCss),
262 `only screen and (max-width: ${globalBreakPointData?.mobile}px)`
263 );
264 }
265
266 return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`;
267 };
268
269 export default dynamicCss;
270