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-list-one / generalTab.js

generalTab.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/blocks/post-list-one/generalTab.js

374 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from "@wordpress/i18n";
2 import { Toggle, Layouts, SPRangeControl, SelectField, TabControls, Background, InputControl } from "../../components";
3 import { openLinksOptions } from "../../controls/constants";
4 import useLayouts from "../../hooks/useLayouts";
5 import { getPaginationBlock } from "../shared/helpFn";
6 import { AlignCenter, AlignLeft, AlignRight } from "../../icons/icons";
7 import SPToggleGroupControl from "../../components/toggleGroupControl/toggleGroupControl";
8 import { BgIcon, GradientIcon } from "../../components/background/svgIcon";
9 import { useMemo } from "@wordpress/element";
10 import { useDeviceType } from "../../controls/controls";
11 import ProInfo from "../../components/proInfo/proInfo";
12
13 export const PostListGeneralTab = ({ attributes, setAttributes }) => {
14 const {
15 itemsPerPage,
16 equalHeightEnable,
17 blockName,
18 generalLinkOpen,
19 verticalGap,
20 postListLayout,
21 preloaderEnable,
22 contentAlignment,
23 postLimit,
24 metaDisplayType,
25 paginationEnable,
26 contentAreaPadding,
27 imageHeight,
28 imageWidth,
29 postCardBorder,
30 contentAreaBorder,
31 liveFilterEnable,
32 clientId,
33 } = attributes;
34 const layouts = useLayouts(blockName, postListLayout);
35 const deviceType = useDeviceType();
36
37 const layoutsObject = useMemo(() => {
38 const typeOne = {
39 imageWidth: {
40 ...imageWidth,
41 device: {
42 ...imageWidth.device,
43 [deviceType]: 364,
44 },
45 unit: {
46 ...imageWidth.unit,
47 [deviceType]: "px",
48 },
49 },
50 imageHeight: {
51 ...imageHeight,
52 device: {
53 ...imageHeight.device,
54 [deviceType]: 244,
55 },
56 },
57 contentVerticalPosition: "top",
58 contentAreaBorder: { ...contentAreaBorder, style: "none" },
59 contentAreaPadding: {
60 ...contentAreaPadding,
61 device: {
62 ...contentAreaPadding.device,
63 Desktop: {
64 ...contentAreaPadding.device.Desktop,
65 top: 15,
66 right: 0,
67 bottom: 0,
68 left: 0,
69 },
70 },
71 },
72 showHideDivider: true,
73 };
74 const typeTwo = {
75 imageWidth: {
76 ...imageWidth,
77 device: {
78 ...imageWidth.device,
79 [deviceType]: 446,
80 },
81 unit: {
82 ...imageWidth.unit,
83 [deviceType]: "px",
84 },
85 },
86 imageHeight: {
87 ...imageHeight,
88 device: {
89 ...imageHeight.device,
90 [deviceType]: 298,
91 },
92 },
93 contentVerticalPosition: "center",
94 contentAreaBorder: { ...contentAreaBorder, style: "solid" },
95 contentAreaPadding: {
96 ...contentAreaPadding,
97 device: {
98 ...contentAreaPadding.device,
99 Desktop: {
100 ...contentAreaPadding.device.Desktop,
101 top: 15,
102 right: 15,
103 bottom: 15,
104 left: 15,
105 },
106 },
107 },
108 showHideDivider: false,
109 };
110 const typeThree = {
111 imageWidth: {
112 ...imageWidth,
113 device: {
114 ...imageWidth.device,
115 [deviceType]: 364,
116 },
117 unit: {
118 ...imageWidth.unit,
119 [deviceType]: "px",
120 },
121 },
122 imageHeight: {
123 ...imageHeight,
124 device: {
125 ...imageHeight.device,
126 [deviceType]: 220,
127 },
128 },
129 contentVerticalPosition: "top",
130 contentAreaBorder: { ...contentAreaBorder, style: "none" },
131 contentAreaPadding: {
132 ...contentAreaPadding,
133 device: {
134 ...contentAreaPadding.device,
135 Desktop: {
136 ...contentAreaPadding.device.Desktop,
137 top: 15,
138 right: 0,
139 bottom: 0,
140 left: 0,
141 },
142 },
143 },
144 showHideDivider: true,
145 };
146 const updatedObject = {
147 "list-one-layout-one": typeOne,
148 "list-one-layout-two": typeOne,
149 "list-one-layout-three": typeTwo,
150 "list-one-layout-four": typeTwo,
151 "list-one-layout-five": typeThree,
152 "list-one-layout-six": typeThree,
153 };
154 return updatedObject;
155 }, []);
156
157 const layoutsChangeHandler = (newValue) => {
158 if (postListLayout === newValue) {
159 return;
160 }
161
162 const updatedWidthHeight = layoutsObject[newValue];
163 const updatedAttributes = {
164 postListLayout: newValue,
165 ...updatedWidthHeight,
166 };
167 // Apply all updates at once
168 setAttributes(updatedAttributes);
169 };
170
171 const paginationBlock = getPaginationBlock(clientId);
172
173 const paginationToggle = (newValue) => {
174 setAttributes({ paginationEnable: !newValue });
175
176 if (!newValue && paginationBlock) {
177 const { block, select } = paginationBlock;
178 select(block?.clientId);
179 }
180 };
181
182 return (
183 <>
184 <Layouts
185 label={__("Post List Layout", "post-carousel")}
186 attributes={postListLayout}
187 attributesKey={"postListLayout"}
188 setAttributes={setAttributes}
189 displayActive={true}
190 showDemoTitle={true}
191 grid={3}
192 items={layouts}
193 onChange={layoutsChangeHandler}
194 />
195 <Toggle
196 label={__("Smart Frontend Filter", "post-carousel")}
197 attributes={liveFilterEnable}
198 setAttributes={setAttributes}
199 attributesKey={"liveFilterEnable"}
200 />
201 <Toggle
202 label={__("Smart Pagination", "post-carousel")}
203 attributes={paginationEnable}
204 // attributesKey={ 'paginationEnable' }
205 // setAttributes={ setAttributes }
206 onChange={paginationToggle}
207 />
208 <InputControl
209 label={__("Posts Per Page", "post-carousel")}
210 className="sp-smart-limit-field"
211 ajax={true}
212 attributes={postLimit}
213 min={1}
214 max={500}
215 attributesKey={"postLimit"}
216 setAttributes={setAttributes}
217 />
218 <SPRangeControl
219 label={__("Vertical Gap", "post-carousel")}
220 attributes={verticalGap}
221 attributesKey={"verticalGap"}
222 setAttributes={setAttributes}
223 max={150}
224 units={["PX", "%", "EM"]}
225 defaultValue={{ unit: "px", value: 24 }}
226 />
227 <SPToggleGroupControl
228 label={__("Content Alignment", "post-carousel")}
229 attributes={contentAlignment}
230 attributesKey={"contentAlignment"}
231 setAttributes={setAttributes}
232 items={[
233 { label: <AlignLeft />, value: "left" },
234 { label: <AlignCenter />, value: "center" },
235 { label: <AlignRight />, value: "right" },
236 ]}
237 />
238 <SelectField
239 label={__("Link Open In", "post-carousel")}
240 attributes={generalLinkOpen}
241 attributesKey={"generalLinkOpen"}
242 setAttributes={setAttributes}
243 items={openLinksOptions}
244 />
245 <Toggle
246 label={__("Preloader", "post-carousel")}
247 attributes={preloaderEnable}
248 attributesKey={"preloaderEnable"}
249 setAttributes={setAttributes}
250 />
251 {/* <Toggle
252 label={ __( 'Enable Equal Height', 'post-carousel' ) }
253 attributes={ equalHeightEnable }
254 attributesKey={ 'equalHeightEnable' }
255 setAttributes={ setAttributes }
256 /> */}
257 <ProInfo>
258 <span>Unlock exclusive layouts and advanced display controls.</span> <a href="https://wpsmartpost.com/pricing/?ref=1" target="_blank" rel="noopener noreferrer">Upgrade to Pro!</a>
259 </ProInfo>
260 </>
261 );
262 };
263
264 const DividerGeneralTab = ({ attributes, setAttributes }) => {
265 const { showHideDivider, dividerBorderStyle, dividerAlignment } = attributes;
266
267 const setBorderStyle = (newValue) => {
268 setAttributes({ dividerBorderStyle: newValue });
269 };
270
271 return (
272 <>
273 <Toggle
274 label={__("Divider", "post-carousel")}
275 attributes={showHideDivider}
276 attributesKey={"showHideDivider"}
277 setAttributes={setAttributes}
278 />
279
280 {showHideDivider && (
281 <>
282 <SelectField
283 label={__("Position", "post-carousel")}
284 attributes={dividerBorderStyle}
285 onChange={(newValue) => setBorderStyle(newValue)}
286 items={[
287 { label: "None", value: "none" },
288 { label: "Solid", value: "solid" },
289 { label: "Dotted", value: "dotted" },
290 { label: "Dashed", value: "dashed" },
291 { label: "Double", value: "double" },
292 { label: "Groove", value: "groove" },
293 { label: "Inset", value: "inset" },
294 { label: "Outset", value: "outset" },
295 { label: "Ridge", value: "ridge" },
296 ]}
297 flexStyle={true}
298 />
299
300 <SPToggleGroupControl
301 label={__("Alignment", "post-carousel")}
302 attributes={dividerAlignment}
303 attributesKey={"dividerAlignment"}
304 setAttributes={setAttributes}
305 items={[
306 { label: <AlignLeft />, value: "left" },
307 { label: <AlignCenter />, value: "center" },
308 { label: <AlignRight />, value: "right" },
309 ]}
310 />
311 </>
312 )}
313 </>
314 );
315 };
316 const DividerStyleTab = ({ attributes, setAttributes }) => {
317 const { dividerBg, dividerWidth, dividerHeight } = attributes;
318
319 return (
320 <>
321 <Background
322 label={__("Color Type", "post-carousel")}
323 colorLabel="Solid Color"
324 defaultColor="#1E1E1E99"
325 attributes={dividerBg}
326 attributesKey={"dividerBg"}
327 setAttributes={setAttributes}
328 colorType={"color"}
329 items={[
330 {
331 label: <BgIcon />,
332 value: "bgColor",
333 tooltip: "Solid",
334 },
335 {
336 label: <GradientIcon />,
337 value: "gradient",
338 tooltip: "Gradient",
339 },
340 ]}
341 />
342 <SPRangeControl
343 label={__("Width", "post-carousel")}
344 attributes={dividerWidth}
345 attributesKey={"dividerWidth"}
346 setAttributes={setAttributes}
347 max={1200}
348 units={["PX", "%", "EM"]}
349 defaultValue={{ unit: "%", value: 100 }}
350 />
351 <SPRangeControl
352 label={__("Thickness", "post-carousel")}
353 attributes={dividerHeight}
354 attributesKey={"dividerHeight"}
355 setAttributes={setAttributes}
356 max={100}
357 units={["PX", "%", "EM"]}
358 defaultValue={{ unit: "pa", value: 1 }}
359 />
360 </>
361 );
362 };
363
364 export const Divider = ({ attributes, setAttributes }) => {
365 return (
366 <TabControls
367 attributes={attributes}
368 setAttributes={setAttributes}
369 GeneralTab={DividerGeneralTab}
370 StyleTab={DividerStyleTab}
371 />
372 );
373 };
374