PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.7
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.7
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-four / dynamicCss.js

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

214 lines 8.7 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 { 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 gridFourHorizontalGap,
9 gridFourVerticalGap,
10 gridFourColumns,
11 contentVerticalPosition,
12 largeItemTitleTypography,
13 largeItemTitleFontSize,
14 postGridLayout,
15 largeItemTitleLineHeight,
16 largeItemTitleLatterSpacing,
17 metaLargeFontSize,
18 metaLargeLineHeight,
19 metaLargeFontSpacing,
20 smallItemHeight,
21 largeItemHeight,
22 // gridSixMasonryEnable,
23 metaLargeTypography,
24 largeItemTitleWordSpacing,
25 metaLargeWordSpacing,
26 globalBreakPointData,
27 } = attributes;
28
29 const contentAreaVerticalPosition = {
30 top: "start",
31 center: "center",
32 bottom: "end",
33 }[contentVerticalPosition];
34
35 const gridFourLargeItem = {
36 "grid-four-layout-one": 2,
37 "grid-four-layout-two": 1,
38 "grid-four-layout-three": 3,
39 "grid-four-layout-four": 1,
40 "grid-four-layout-five": 1,
41 "grid-four-layout-six": 1,
42 }[postGridLayout];
43
44 const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page);
45
46 const gridCss = (device) => {
47 const css = [
48 {
49 class: `#${uniqueId} .sp-smart-post-dynamic-grid-contents`,
50 styles: {
51 display: "grid",
52 "grid-template-columns": `repeat(${gridFourColumns.device?.[device]},1fr)`,
53 "column-gap": `${gridFourHorizontalGap.device?.[device]}${gridFourHorizontalGap.unit?.[device]}`,
54 "row-gap": `${gridFourVerticalGap.device?.[device]}${gridFourVerticalGap.unit?.[device]}`,
55 },
56 },
57 {
58 class: `#${uniqueId} .grid-four-container .sp-smart-post-grid-four-static-contents`,
59 styles: {
60 height: `${largeItemHeight.device?.[device]}${largeItemHeight.unit?.[device]}`,
61 },
62 },
63 {
64 class: `#${uniqueId} .grid-four-container .sp-smart-post-dynamic-grid-contents .sp-smart-post-card`,
65 styles: {
66 height: `${smallItemHeight.device?.[device]}${smallItemHeight.unit?.[device]}`,
67 },
68 },
69 {
70 class: `#${uniqueId} .sp-smart-post-grid-four-static-contents`,
71 styles: {
72 "column-gap": `${gridFourHorizontalGap.device?.[device]}${gridFourHorizontalGap.unit?.[device]}`,
73 "row-gap": `${gridFourVerticalGap.device?.[device]}${gridFourVerticalGap.unit?.[device]}`,
74 // 'margin-bottom': `${ gridFourVerticalGap.device[ device ] }${ gridFourVerticalGap.unit[ device ] }`,
75 },
76 },
77 {
78 class: `#${uniqueId} .sp-smart-show-pro.grid-four-container:has(.sp-smart-post-dynamic-grid-contents .sp-smart-post-card)`,
79 styles: {
80 display: "grid",
81 "row-gap": `${gridFourVerticalGap.device?.[device] + gridFourVerticalGap.unit?.[device]}`,
82 },
83 },
84 {
85 class: `#${uniqueId} .grid-four-container .sp-smart-post-grid-four-static-contents`,
86 styles: {
87 "margin-bottom": "0",
88 },
89 },
90 {
91 class: `#${uniqueId} .template-two:not(.large) .sp-smart-post-card-content`,
92 styles: {
93 "justify-content": "end",
94 },
95 },
96 // large item
97 {
98 class: `#${uniqueId} .template-two.large`,
99 styles: {
100 display: "flex",
101 "align-items": contentAreaVerticalPosition,
102 },
103 },
104 {
105 class: `#${uniqueId} .sp-smart-show-pro .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-title`,
106 styles: {
107 "font-size":
108 largeItemTitleFontSize?.device?.[device] +
109 largeItemTitleFontSize?.unit?.[device] +
110 "!important",
111 "font-weight": largeItemTitleTypography?.typography?.fontWeight + "!important",
112 "font-style": largeItemTitleTypography?.typography?.style + "!important",
113 "text-transform": largeItemTitleTypography?.typography?.transform + "!important",
114 "text-decoration": largeItemTitleTypography?.typography?.decoration + "!important",
115 "line-height": largeItemTitleLineHeight?.device?.[device] + "!important",
116 "letter-spacing":
117 largeItemTitleLatterSpacing?.device?.[device] +
118 largeItemTitleLatterSpacing?.unit?.[device] +
119 "!important",
120 "word-spacing":
121 largeItemTitleWordSpacing?.device?.[device] +
122 largeItemTitleWordSpacing?.unit?.[device] +
123 "!important",
124 },
125 },
126 ...removeEmptyCss(
127 `#${uniqueId} .sp-smart-show-pro .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-title`,
128 "font-family",
129 largeItemTitleTypography?.typography?.family,
130 false
131 ),
132 // Metadata Large items Typography.
133 {
134 class: `#${uniqueId} .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-author .sp-smart-post-author-name,
135 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-date span,
136 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-post-show-comment span,
137 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-view span,
138 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-like span,
139 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-like i,
140 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-reading-time span`,
141 styles: {
142 "font-size": `${metaLargeFontSize.device?.[device]}${metaLargeFontSize.unit?.[device]} !important`,
143 "font-weight": `${metaLargeTypography?.typography?.fontWeight} !important`,
144 "font-style": `${metaLargeTypography?.typography?.style} !important`,
145 "letter-spacing": `${metaLargeFontSpacing.device?.[device]}${metaLargeFontSpacing.unit?.[device]}`,
146 "word-spacing": `${metaLargeWordSpacing.device?.[device]}${metaLargeWordSpacing.unit?.[device]}`,
147 "line-height": `${metaLargeLineHeight.device?.[device]} !important`,
148 display: "flex",
149 "align-items": "center",
150 },
151 },
152 {
153 class: `#${uniqueId} .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-author svg,
154 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-date .sp-smart-post-release-date,
155 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-post-show-comment span,
156 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-view span:first-of-type,
157 .sp-smart-post-grid-four-static-contents .sp-smart-post-card:nth-of-type(${gridFourLargeItem}) .sp-smart-post-card-content .sp-smart-post-reading-time span:first-of-type`,
158 styles: {
159 height: `${metaLargeFontSize.device?.[device]}${metaLargeFontSize.unit?.[device]} !important`,
160 width: `${metaLargeFontSize.device?.[device]}${metaLargeFontSize.unit?.[device]} !important`,
161 display: "flex",
162 "align-items": "center",
163 },
164 },
165 ];
166 return css;
167 };
168
169 // desktop styles
170 const desktopCss = [...sharedDesktopCss, ...gridCss("Desktop")];
171
172 cacheCss.desktop = objectToCssString(desktopCss);
173
174 if ("Tablet" === currentDevice || "all" === currentDevice) {
175 // Tablet styles
176 const tabletCss = [...sharedTabletCss, ...gridCss("Tablet")];
177 cacheCss.tablet = wrapInMediaQuery(
178 objectToCssString(tabletCss),
179 `only screen and (max-width: ${globalBreakPointData?.tablet}px)`
180 );
181 }
182 if ("Mobile" === currentDevice || "all" === currentDevice) {
183 // Mobile styles
184 const mobileCss = [
185 ...sharedMobileCss,
186 ...gridCss("Mobile"),
187 {
188 class: `#${uniqueId} .sp-smart-post-dynamic-grid-contents, #${uniqueId} .sp-smart-post-grid-four-static-contents`,
189 styles: {
190 display: "grid",
191 "grid-template-columns": `repeat(${gridFourColumns.device.Mobile || 1}, 1fr)`,
192 },
193 },
194 {
195 class: `#${uniqueId} .sp-smart-show-pro.grid-four-container .sp-smart-post-grid-four-static-contents .sp-smart-post-card`,
196 styles: {
197 // 'grid-column': '1 / 1',
198 // 'grid-row': 'auto',
199 height: `${smallItemHeight.device.Mobile + smallItemHeight.unit.Mobile}`,
200 },
201 },
202 ];
203
204 cacheCss.mobile = wrapInMediaQuery(
205 objectToCssString(mobileCss),
206 `only screen and (max-width: ${globalBreakPointData?.mobile}px)`
207 );
208 }
209
210 return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`;
211 };
212
213 export default dynamicCss;
214