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 / live-filter / dynamicCss.js

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

330 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { objectToCssString, rangerCss, spacingGenerate, wrapInMediaQuery } from "../shared/helpFn";
2
3 const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => {
4 const cacheCss = { desktop: "", tablet: "", mobile: "" };
5
6 const {
7 uniqueId,
8 gap,
9 titleTypography,
10 titleFontSize,
11 titleLineHeight,
12 optionTypography,
13 optionFontSize,
14 optionLineHeight,
15 titleColor,
16 optionColor,
17 bgColor,
18 borderNormal,
19 borderWidthNormal,
20 borderRadiusNormal,
21 padding,
22 margin,
23 fieldAlignment,
24 hideOnDesktop,
25 hideOnTablet,
26 hideOnMobile,
27 globalBreakPointData,
28 menuAlignment,
29 menuTypography,
30 menuFontSize,
31 menuLatterSpacing,
32 menuLineHeight,
33 menuWordSpacing,
34 menuColor,
35 activeBottomLine,
36 headingTypography,
37 headingLineHeight,
38 headingWordSpacing,
39 headingLatterSpacing,
40 headingFontSize,
41 headingGlobalTypography,
42 widthLineThickness,
43 headingColor,
44 headingBg,
45 headingBorder,
46 headingBorderWidth,
47 headingBorderRadius,
48 headingPadding,
49 widthLineColor,
50 headingStyle,
51 } = attributes;
52
53 // Safe fallback breakpoints
54 const tabletBp = globalBreakPointData?.tablet || 1024;
55 const mobileBp = globalBreakPointData?.mobile || 767;
56
57 // Simplified typography function (flat structure)
58 const typographyCss = (attr) => {
59 return {
60 "font-family": attr.typography.family,
61 "font-weight": attr.typography.fontWeight,
62 "font-style": attr.typography.style,
63 "text-decoration": attr.typography.decoration,
64 "text-transform": attr.typography.transform,
65 };
66 };
67
68 // Responsive inner width
69 const innerBlockWidth = {
70 Desktop: "33.33%",
71 Tablet: "50%",
72 Mobile: "100%",
73 };
74
75 // Base CSS (shared for all devices)
76 const baseLiveFilterCss = () => [
77 {
78 class: `#${uniqueId} .block-editor-block-list__layout, #${uniqueId} .wp-block-sp-smart-post-show-live-filter`,
79 styles: {
80 display: "flex",
81 "justify-content": fieldAlignment === "full" ? "stretch" : fieldAlignment,
82 },
83 },
84 {
85 class: `#${uniqueId}.sp-smart-full.sp-width-33 .block-editor-block-list__layout .block-editor-block-list__block, #${uniqueId}.sp-smart-full.sp-width-33 .wp-block-sp-smart-post-show-live-filter > .sp-smart-post-live-filter`,
86 styles: {
87 width: `calc(${innerBlockWidth["Desktop"]} - ${rangerCss(gap, "Desktop")})`,
88 },
89 },
90 {
91 class: `#${uniqueId}`,
92 styles: {
93 margin: spacingGenerate(margin),
94 },
95 },
96 {
97 class: `#${uniqueId} .sp-smart-post-live-filter-label`,
98 styles: {
99 ...typographyCss(titleTypography),
100 color: titleColor?.color,
101 },
102 },
103 {
104 class: `#${uniqueId} .sp-smart-post-live-filter-button li a,
105 #${uniqueId} .sp-smart-post-live-filter-dropdown li a,
106 #${uniqueId} .sp-smart-post-live-filter-btn,
107 #${uniqueId} .sp-smart-post-live-filter-btn svg path`,
108 styles: {
109 ...typographyCss(optionTypography),
110 color: optionColor?.color,
111 stroke: optionColor?.color,
112 },
113 },
114 {
115 class: `#${uniqueId} .sp-smart-post-live-filter-btn`,
116 styles: {
117 "border-color": borderNormal?.color,
118 "border-style": borderNormal?.style,
119 },
120 },
121 {
122 class: `#${uniqueId} .sp-smart-post-live-filter-btn input,
123 #${uniqueId} .sp-smart-post-live-filter-btn input::placeholder, #${uniqueId} .sp-smart-post-live-filter-button li a`,
124 styles: {
125 ...typographyCss(optionTypography),
126 color: optionColor?.color,
127 background: bgColor?.color,
128 },
129 },
130 {
131 class: `#${uniqueId} .sp-smart-post-live-filter-dropdown,
132 #${uniqueId} .sp-smart-post-live-filter-btn`,
133 styles: {
134 background: bgColor?.color,
135 },
136 },
137 {
138 class: `#${uniqueId}.layoutOne .sp-smart-post-live-filter-button li a.active,
139 #${uniqueId}.layoutOne .sp-smart-post-live-filter-dropdown li a.active,
140 #${uniqueId}.layoutOne .sp-smart-post-live-filter-button li a:hover,
141 #${uniqueId}.layoutOne .sp-smart-post-live-filter-dropdown li a:hover`,
142 styles: {
143 color: optionColor?.hover,
144 stroke: optionColor?.hover,
145 background: bgColor?.hover,
146 },
147 },
148 {
149 class: `#${uniqueId} .sps-live-filter-nav-menu`,
150 styles: { gap: rangerCss(gap, currentDevice) },
151 },
152 {
153 class: `#${uniqueId} .sps-live-filter-nav-container`,
154 styles: {
155 "justify-content": menuAlignment,
156
157 "border-bottom": ["styleOne", "styleThree"].includes(headingStyle)
158 ? `${widthLineColor} solid ${widthLineThickness}px`
159 : "",
160 },
161 },
162 {
163 class: `#${uniqueId} .sps-live-filter-nav-link, #${uniqueId} .sps-live-filter-dropdown-item`,
164 styles: {
165 ...typographyCss(menuTypography),
166 color: menuColor?.color,
167 },
168 },
169 {
170 class: `#${uniqueId} .sps-live-filter-dropdown-item.active`,
171 styles: {
172 color: menuColor?.color,
173 background: menuColor?.hover,
174 },
175 },
176
177 {
178 class: `#${uniqueId} .sps-live-filter-nav-link:hover, #${uniqueId} .sps-live-filter-dropdown-item:hover`,
179 styles: {
180 color: menuColor?.hover,
181 },
182 },
183
184 // base (non-active)
185 {
186 class: `#${uniqueId}.layoutTwo .sps-live-filter-nav-link`,
187 styles: {
188 color: menuColor?.color,
189 // "border-bottom": `${widthLineThickness}px solid transparent`,
190 // "margin-bottom": `-${widthLineThickness}px`,
191 // transition: "color 0.5s ease, border-color 0.5s ease",
192 },
193 },
194
195 {
196 class: `#${uniqueId}.layoutTwo .sps-live-filter-nav-link.active `,
197 styles: {
198 color: menuColor?.hover,
199 "border-bottom": activeBottomLine ? `${widthLineThickness}px solid ${menuColor?.hover}` : "",
200 "margin-bottom": `-${widthLineThickness}px`,
201 },
202 },
203
204 {
205 class: `#${uniqueId}.layoutTwo .sps-live-filter-dropdown-menu .sps-live-filter-nav-link.active `,
206 styles: {
207 color: menuColor?.hover,
208 "border-bottom": activeBottomLine ? ` 0px solid ${menuColor?.hover}` : "",
209 },
210 },
211
212 {
213 class: `#${uniqueId} .sps-live-filter-latest-post-btn `,
214 styles: {
215 ...typographyCss(headingTypography),
216 color: headingColor?.color,
217 background: headingBg.color,
218 "border-color": headingBorder?.color,
219 "border-style": headingBorder?.style,
220 "border-bottom": ["styleTwo", "styleThree"].includes(headingStyle) ? `4px solid #503AA8` : "",
221 "border-left": "styleFour" === headingStyle ? "4px solid #503AA8" : "",
222 },
223 },
224
225 {
226 class: `#${uniqueId} .sps-live-filter-latest-post-btn:hover `,
227 styles: {
228 color: headingColor?.hover,
229 background: headingBg.hover,
230 },
231 },
232 ];
233
234 const responsiveCss = (deviceType) => {
235 return [
236 {
237 class: `#${uniqueId} .sps-live-filter-nav-link, #${uniqueId} .sps-live-filter-dropdown-item`,
238 styles: {
239 "font-size": rangerCss(menuFontSize, deviceType),
240 "line-height": menuLineHeight?.device?.[deviceType],
241 "letter-spacing": rangerCss(menuLatterSpacing),
242 "word-spacing": rangerCss(menuWordSpacing),
243 },
244 },
245 {
246 class: `#${uniqueId} .sps-live-filter-latest-post-btn `,
247 styles: {
248 "font-size": rangerCss(headingFontSize, deviceType),
249 "line-height": headingLineHeight?.device?.[deviceType],
250 "letter-spacing": rangerCss(headingLatterSpacing),
251 "word-spacing": rangerCss(headingWordSpacing),
252 "border-width": spacingGenerate(headingBorderWidth, deviceType),
253 "border-radius": spacingGenerate(headingBorderRadius, deviceType),
254 padding: spacingGenerate(headingPadding, deviceType),
255 },
256 },
257 {
258 class: `#${uniqueId} .block-editor-block-list__layout, #${uniqueId} .wp-block-sp-smart-post-show-live-filter`,
259 styles: {
260 gap: rangerCss(gap, deviceType),
261 },
262 },
263 {
264 class: `#${uniqueId}.sp-smart-full.sp-width-33 .block-editor-block-list__layout .block-editor-block-list__block,
265 #${uniqueId}.sp-smart-full.sp-width-33 .wp-block-sp-smart-post-show-live-filter > .sp-smart-post-live-filter`,
266 styles: {
267 width: `calc(${innerBlockWidth[deviceType]} - ${rangerCss(gap, deviceType)})`,
268 },
269 },
270 {
271 class: `#${uniqueId} .sp-smart-post-live-filter-label`,
272 styles: {
273 "font-size": rangerCss(titleFontSize, deviceType),
274 "line-height": titleLineHeight?.device?.[deviceType],
275 },
276 },
277 {
278 class: `#${uniqueId} .sp-smart-post-live-filter-button li a,
279 #${uniqueId} .sp-smart-post-live-filter-dropdown li a,
280 #${uniqueId} .sp-smart-post-live-filter-btn,
281 #${uniqueId} .sp-smart-post-live-filter-btn svg path`,
282 styles: {
283 "font-size": rangerCss(optionFontSize, deviceType),
284 "line-height": optionLineHeight?.device?.[deviceType],
285 padding: spacingGenerate(padding, deviceType),
286 },
287 },
288 {
289 class: `#${uniqueId} .sp-smart-post-live-filter-btn`,
290 styles: {
291 "border-width": spacingGenerate(borderWidthNormal, deviceType),
292 "border-radius": spacingGenerate(borderRadiusNormal, deviceType),
293 },
294 },
295 ];
296 }
297
298 // Desktop
299 if (["Desktop", "all"].includes(currentDevice)) {
300 const desktopCss = [
301 ...baseLiveFilterCss(),
302 ...responsiveCss("Desktop"),
303 ];
304 cacheCss.desktop = objectToCssString(desktopCss);
305 }
306
307 // Tablet
308 if (["Tablet", "all"].includes(currentDevice)) {
309 const tabletCss = [
310 ...baseLiveFilterCss(),
311 ...responsiveCss("Tablet"),
312 ];
313 cacheCss.tablet = wrapInMediaQuery(objectToCssString(tabletCss), `only screen and (max-width: ${tabletBp}px)`);
314 }
315
316 // Mobile
317 if (["Mobile", "all"].includes(currentDevice)) {
318 const mobileCss = [
319 ...baseLiveFilterCss(),
320 ...responsiveCss("Mobile"),
321 ];
322 cacheCss.mobile = wrapInMediaQuery(objectToCssString(mobileCss), `only screen and (max-width: ${mobileBp}px)`);
323 }
324
325 // Return final combined CSS
326 return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`;
327 };
328
329 export default dynamicCss;
330