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 / thumbnail-slider-two / generalTab.js

generalTab.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at src/blocks/thumbnail-slider-two/generalTab.js

614 lines 16.8 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 { useEffect, useMemo, useState } from "@wordpress/element";
3 import { Background, InputControl, Layouts, SelectField, SPRangeControl } from "../../components";
4 import SPToggleGroupControl from "../../components/toggleGroupControl/toggleGroupControl";
5 import useLayouts from "../../hooks/useLayouts";
6 import { AlignCenter, AlignLeft, AlignRight } from "../../icons/icons";
7 import Toggle from "../../components/toggle/toggle";
8 import { BgIcon, GradientIcon, TransparentIcon } from "../../components/background/svgIcon";
9 import { openLinksOptions } from "../../controls/constants";
10 import { useDeviceType } from "../../controls/controls";
11 import ProInfo from "../../components/proInfo/proInfo";
12
13 export const ThumbnailSliderTwoGeneralTab = ({ attributes, setAttributes }) => {
14 const {
15 blockName,
16 thumbnailSliderTwoLayout,
17 thumbnailTwoAlignment,
18 thumbnailTwoPosition,
19 thumbnailSliderTwoHeight,
20 thumbnailTwoItemsHeight,
21 thumbnailItemsToShow,
22 catTabCategoryColor,
23 titleMargin,
24 contentAlignment,
25 generalLinkOpen,
26 thumbnailTwoGeneralPreloader,
27 postLimit,
28 } = attributes;
29
30 const layouts = useLayouts(blockName, thumbnailSliderTwoLayout);
31 const [thumbnailPositionItem, setThumbnailPositionItem] = useState([]);
32 const [layoutName, setLayoutName] = useState("thumbnail-slider-layout-one");
33 const deviceType = useDeviceType();
34
35 const layoutDefault = useMemo(
36 () => ({
37 "thumbnail-slider-two-layout-one": {
38 thumbnailTwoPosition: "bottom",
39 contentVerticalPosition: "top",
40 contentHorizontalPosition: "center",
41 thumbnailItemsToShow: {
42 ...thumbnailItemsToShow,
43 device: {
44 ...thumbnailItemsToShow.device,
45 [deviceType]: 3,
46 },
47 },
48 postLimit: "3",
49 thumbnailTwoItemsHeight: {
50 ...thumbnailTwoItemsHeight,
51 device: { ...thumbnailTwoItemsHeight.device, Desktop: 132 },
52 },
53 carouselNavArrow: false,
54 catTabCategoryColor: {
55 ...catTabCategoryColor,
56 color: "#222222",
57 },
58 titleMargin: {
59 ...titleMargin,
60 device: {
61 ...titleMargin.device,
62 Desktop: {
63 ...titleMargin.device.Desktop,
64 top: 6,
65 bottom: 0,
66 right: 0,
67 left: 0,
68 },
69 },
70 },
71 },
72 "thumbnail-slider-two-layout-two": {
73 contentVerticalPosition: "top",
74 contentHorizontalPosition: "center",
75 thumbnailTwoPosition: "bottom",
76
77 thumbnailItemsToShow: {
78 ...thumbnailItemsToShow,
79 device: {
80 ...thumbnailItemsToShow.device,
81 [deviceType]: 4,
82 },
83 },
84 postLimit: "4",
85 thumbnailTwoItemsHeight: {
86 ...thumbnailTwoItemsHeight,
87 device: { ...thumbnailTwoItemsHeight.device, Desktop: 60 },
88 },
89 carouselNavArrow: false,
90 catTabCategoryColor: {
91 ...catTabCategoryColor,
92 color: "#222222",
93 },
94 },
95 "thumbnail-slider-two-layout-three": {
96 contentVerticalPosition: "bottom",
97 contentHorizontalPosition: "left",
98 thumbnailTwoPosition: "right",
99 thumbnailItemsToShow: {
100 ...thumbnailItemsToShow,
101 device: {
102 ...thumbnailItemsToShow.device,
103 [deviceType]: 3,
104 },
105 },
106 postLimit: "4",
107 thumbnailTwoItemsHeight: {
108 ...thumbnailTwoItemsHeight,
109 device: { ...thumbnailTwoItemsHeight.device, Desktop: 220 },
110 },
111 carouselNavArrow: true,
112 catTabCategoryColor: {
113 ...catTabCategoryColor,
114 color: "#fff",
115 },
116 },
117 "thumbnail-slider-two-layout-four": {
118 contentVerticalPosition: "bottom",
119 contentHorizontalPosition: "left",
120 thumbnailTwoPosition: "right",
121 titleMargin: {
122 ...titleMargin,
123 device: {
124 ...titleMargin.device,
125 Desktop: {
126 ...titleMargin.device.Desktop,
127 top: 0,
128 bottom: 0,
129 right: 0,
130 left: 0,
131 },
132 },
133 },
134
135 thumbnailItemsToShow: {
136 ...thumbnailItemsToShow,
137 device: {
138 ...thumbnailItemsToShow.device,
139 [deviceType]: 4,
140 },
141 },
142 postLimit: "4",
143 thumbnailTwoItemsHeight: {
144 ...thumbnailTwoItemsHeight,
145 device: { ...thumbnailTwoItemsHeight.device, Desktop: 132 },
146 },
147 carouselNavArrow: true,
148 catTabCategoryColor: {
149 ...catTabCategoryColor,
150 color: "#fff",
151 },
152 },
153 "thumbnail-slider-two-layout-five": {
154 contentVerticalPosition: "bottom",
155 contentHorizontalPosition: "left",
156 thumbnailTwoPosition: "right",
157 carouselNavArrow: true,
158 thumbnailItemsToShow: {
159 ...thumbnailItemsToShow,
160 device: {
161 ...thumbnailItemsToShow.device,
162 [deviceType]: 5,
163 },
164 },
165 postLimit: "8",
166 thumbnailTwoItemsHeight: {
167 ...thumbnailTwoItemsHeight,
168 device: { ...thumbnailTwoItemsHeight.device, Desktop: 132 },
169 },
170 catTabCategoryColor: {
171 ...catTabCategoryColor,
172 color: "#fff",
173 },
174 },
175 }),
176 []
177 );
178
179 const layoutsChangeHandler = (newValue) => {
180 if (newValue === thumbnailSliderTwoLayout) return;
181
182 const newData = {
183 ...layoutDefault?.[newValue],
184 thumbnailSliderTwoLayout: newValue,
185 blockLayoutName: newValue,
186 };
187 setAttributes(newData);
188 setLayoutName(newValue);
189 };
190
191 const configThumbPosition = useMemo(
192 () => ({
193 "thumbnail-slider-two-layout-one": [],
194 "thumbnail-slider-two-layout-two": [
195 { label: "Left", value: "left" },
196 { label: "Right", value: "right" },
197 { label: "Bottom", value: "bottom" },
198 ],
199 "thumbnail-slider-two-layout-three": [
200 { label: "Left", value: "left" },
201 { label: "Right", value: "right" },
202 ],
203 "thumbnail-slider-two-layout-four": [
204 { label: "Left", value: "left" },
205 { label: "Right", value: "right" },
206 ],
207 "thumbnail-slider-two-layout-five": [],
208 }),
209 []
210 );
211
212 useEffect(() => {
213 setThumbnailPositionItem(configThumbPosition[thumbnailSliderTwoLayout] || []);
214 }, [thumbnailSliderTwoLayout]);
215
216 useEffect(() => {
217 if (["left", "right"].includes(thumbnailTwoPosition)) {
218 const contentPosition = thumbnailTwoPosition === "left" ? "right" : "left";
219 setAttributes({ contentHorizontalPosition: contentPosition });
220 }
221 }, [thumbnailTwoPosition]);
222
223 return (
224 <>
225 {layouts?.length > 0 && (
226 <Layouts
227 label={__("Thumbnails Slider Layout", "post-carousel")}
228 attributes={thumbnailSliderTwoLayout}
229 attributesKey={"thumbnailSliderTwoLayout"}
230 setAttributes={setAttributes}
231 displayActive={true}
232 showDemoTitle={true}
233 grid={3}
234 items={layouts}
235 onChange={layoutsChangeHandler}
236 />
237 )}
238 {/* <Toggle
239 label={ __( 'Smart Frontend Filter', 'post-carousel' ) }
240 attributes={ liveFilterEnable }
241 setAttributes={ setAttributes }
242 attributesKey={ 'liveFilterEnable' }
243 /> */}
244 {"thumbnail-slider-two-layout-one" === thumbnailSliderTwoLayout && (
245 <SPToggleGroupControl
246 label={__("Thumbnails Alignment", "post-carousel")}
247 attributes={thumbnailTwoAlignment}
248 attributesKey={"thumbnailTwoAlignment"}
249 setAttributes={setAttributes}
250 items={[
251 { label: <AlignLeft />, value: "left" },
252 { label: <AlignCenter />, value: "center" },
253 { label: <AlignRight />, value: "right" },
254 ]}
255 />
256 )}
257 {!["thumbnail-slider-two-layout-one", "thumbnail-slider-two-layout-five"].includes(
258 thumbnailSliderTwoLayout
259 ) && (
260 <SPToggleGroupControl
261 label={__("Thumbnails Position", "post-carousel")}
262 attributes={thumbnailTwoPosition}
263 attributesKey={"thumbnailTwoPosition"}
264 setAttributes={setAttributes}
265 items={thumbnailPositionItem}
266 />
267 )}
268 <InputControl
269 label={__("Number of Slides", "post-carousel")}
270 className="sp-smart-limit-field"
271 ajax={true}
272 attributes={postLimit}
273 min={1}
274 attributesKey={"postLimit"}
275 setAttributes={setAttributes}
276 />
277 <SPRangeControl
278 label={__("Height", "post-carousel")}
279 attributes={thumbnailSliderTwoHeight}
280 attributesKey={"thumbnailSliderTwoHeight"}
281 setAttributes={setAttributes}
282 units={["px", "%", "em"]}
283 max={1200}
284 defaultValue={{ unit: "px", value: 620 }}
285 />
286 {!["thumbnail-slider-two-layout-four", "thumbnail-slider-two-layout-five"].includes(
287 thumbnailSliderTwoLayout
288 ) && (
289 <SPRangeControl
290 key={layoutName}
291 label={__("Thumbnails Height", "post-carousel")}
292 attributes={thumbnailTwoItemsHeight}
293 attributesKey={"thumbnailTwoItemsHeight"}
294 setAttributes={setAttributes}
295 units={["px", "%", "em"]}
296 max={450}
297 defaultValue={{
298 unit: "px",
299 value: 132,
300 }}
301 />
302 )}
303 {!["thumbnail-slider-two-layout-one", "thumbnail-slider-two-layout-five"].includes(
304 thumbnailSliderTwoLayout
305 ) && (
306 <SPRangeControl
307 key={thumbnailItemsToShow}
308 label={__("Thumbnail Items to Show", "post-carousel")}
309 attributes={thumbnailItemsToShow}
310 attributesKey={"thumbnailItemsToShow"}
311 setAttributes={setAttributes}
312 min={1}
313 max={6}
314 defaultValue={{
315 value: 3,
316 }}
317 />
318 )}
319 <SPToggleGroupControl
320 label={__("Content Alignment", "post-carousel")}
321 attributes={contentAlignment}
322 attributesKey={"contentAlignment"}
323 setAttributes={setAttributes}
324 items={[
325 { label: <AlignLeft />, value: "left" },
326 { label: <AlignCenter />, value: "center" },
327 { label: <AlignRight />, value: "right" },
328 ]}
329 />
330 <SelectField
331 label={__("Link Open In", "post-carousel")}
332 attributes={generalLinkOpen}
333 attributesKey={"generalLinkOpen"}
334 setAttributes={setAttributes}
335 items={openLinksOptions}
336 />
337 <Toggle
338 label={__("Preloader", "post-carousel")}
339 attributes={thumbnailTwoGeneralPreloader}
340 attributesKey={"thumbnailTwoGeneralPreloader"}
341 setAttributes={setAttributes}
342 />
343 <ProInfo>
344 <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>
345 </ProInfo>
346 </>
347 );
348 };
349
350 export const ThumbnailTwoSliderTab = ({ attributes, setAttributes }) => {
351 const {
352 carouselAutoPlay,
353 carouselAutoPlayDelay,
354 carouselSpeed,
355 carouselDirection,
356 thumbnailTwoSlideToScroll,
357 carouselPauseOnHover,
358 thumbnailTwoAnimationEffect,
359 thumbnailTwoAdaptiveHeight,
360 infiniteLoop,
361 thumbnailTwoTabKeyNavigation,
362 thumbnailTwoMouseWheelControl,
363 thumbnailTwoFreeScrollMode,
364 // thumbnailTwoNavArrow,
365 carouselNavArrow,
366 } = attributes;
367
368 return (
369 <>
370 <Toggle
371 label={__("AutoPlay", "post-carousel")}
372 attributes={carouselAutoPlay}
373 attributesKey={"carouselAutoPlay"}
374 setAttributes={setAttributes}
375 />
376 {carouselAutoPlay && (
377 <SPRangeControl
378 label={__("AutoPlay Delay", "post-carousel")}
379 attributes={carouselAutoPlayDelay}
380 attributesKey={"carouselAutoPlayDelay"}
381 setAttributes={setAttributes}
382 units={["ms"]}
383 max={6000}
384 defaultValue={{ unit: "ms", value: 2000 }}
385 />
386 )}
387 <SPRangeControl
388 label={__("Slider Speed", "post-carousel")}
389 attributes={carouselSpeed}
390 attributesKey={"carouselSpeed"}
391 setAttributes={setAttributes}
392 units={["ms"]}
393 max={4000}
394 defaultValue={{ unit: "ms", value: 600 }}
395 />
396 {carouselAutoPlay && (
397 <SPToggleGroupControl
398 label={__("Slider Direction", "post-carousel")}
399 attributes={carouselDirection}
400 attributesKey={"carouselDirection"}
401 setAttributes={setAttributes}
402 items={[
403 { label: "Right to Left", value: "right_to_left" },
404 { label: "Left to Right", value: "left_to_right" },
405 ]}
406 />
407 )}
408 <InputControl
409 label={__("Slide to Scroll", "post-carousel")}
410 attributes={thumbnailTwoSlideToScroll}
411 attributesKey={"thumbnailTwoSlideToScroll"}
412 setAttributes={setAttributes}
413 flex={true}
414 inputType={"number"}
415 min={0}
416 max={10}
417 />
418 <Toggle
419 label={__("Pause on Hover", "post-carousel")}
420 attributes={carouselPauseOnHover}
421 attributesKey={"carouselPauseOnHover"}
422 setAttributes={setAttributes}
423 />
424 <SelectField
425 label={__("Animation Effect", "post-carousel")}
426 attributes={thumbnailTwoAnimationEffect}
427 attributesKey={"thumbnailTwoAnimationEffect"}
428 setAttributes={setAttributes}
429 flexStyle={true}
430 items={[
431 { label: "Slide", value: "slide" },
432 { label: "Cube", value: "cube" },
433 { label: "Flip", value: "flip" },
434 { label: "Coverflow", value: "coverflow", disabled: "disabled" },
435 { label: "Fade (Pro)", value: "fade", disabled: "disabled" },
436 ]}
437 />
438 <Toggle
439 label={__("Adaptive Height", "post-carousel")}
440 attributes={thumbnailTwoAdaptiveHeight}
441 attributesKey={"thumbnailTwoAdaptiveHeight"}
442 setAttributes={setAttributes}
443 />
444 <Toggle
445 label={__("Infinite Loop", "post-carousel")}
446 attributes={infiniteLoop}
447 attributesKey={"infiniteLoop"}
448 setAttributes={setAttributes}
449 />
450 <Toggle
451 label={__("Tab and Key Navigation", "post-carousel")}
452 attributes={thumbnailTwoTabKeyNavigation}
453 attributesKey={"thumbnailTwoTabKeyNavigation"}
454 setAttributes={setAttributes}
455 />
456 <Toggle
457 label={__("MouseWheel Control", "post-carousel")}
458 attributes={thumbnailTwoMouseWheelControl}
459 attributesKey={"thumbnailTwoMouseWheelControl"}
460 setAttributes={setAttributes}
461 />
462 <Toggle
463 label={__("Free Scroll Mode", "post-carousel")}
464 attributes={thumbnailTwoFreeScrollMode}
465 attributesKey={"thumbnailTwoFreeScrollMode"}
466 setAttributes={setAttributes}
467 />
468 <Toggle
469 label={__("Navigation Arrow", "post-carousel")}
470 attributes={carouselNavArrow}
471 attributesKey={"carouselNavArrow"}
472 setAttributes={setAttributes}
473 />
474 </>
475 );
476 };
477
478 export const ThumbnailProgressBarTab = ({ attributes, setAttributes }) => {
479 const [colorState, setColorState] = useState("normal");
480 const { thumbnailProgressPosition, thumbnailProgressBarWidth, thumbnailProgressThickness, thumbnailProgressColor } =
481 attributes;
482
483 return (
484 <>
485 <SPToggleGroupControl
486 label={__("Bar Position", "post-carousel")}
487 attributes={thumbnailProgressPosition}
488 attributesKey={"thumbnailProgressPosition"}
489 setAttributes={setAttributes}
490 items={[
491 { label: "Left", value: "left" },
492 { label: "Top", value: "top" },
493 { label: "Bottom", value: "bottom" },
494 ]}
495 />
496 <SPRangeControl
497 label={__(thumbnailProgressPosition === "left" ? "Height" : "Width", "post-carousel")}
498 attributes={thumbnailProgressBarWidth}
499 attributesKey={"thumbnailProgressBarWidth"}
500 setAttributes={setAttributes}
501 units={["px", "%", "em"]}
502 max={400}
503 defaultValue={{ unit: "%", value: 100 }}
504 />
505 <SPRangeControl
506 label={__("Thickness", "post-carousel")}
507 attributes={thumbnailProgressThickness}
508 attributesKey={"thumbnailProgressThickness"}
509 setAttributes={setAttributes}
510 units={["px", "%", "em"]}
511 max={10}
512 defaultValue={{ unit: "%", value: 1 }}
513 />
514 <SPToggleGroupControl
515 attributes={colorState}
516 onClick={(newValue) => setColorState(newValue)}
517 items={[
518 { label: "Normal", value: "normal" },
519 { label: "Active", value: "active" },
520 ]}
521 />
522 {"normal" === colorState && (
523 <Background
524 label={__("Color Type", "post-carousel")}
525 colorLabel="Solid Color"
526 defaultColor="#1E1E1E99"
527 attributes={thumbnailProgressColor}
528 attributesKey={"thumbnailProgressColor"}
529 setAttributes={setAttributes}
530 colorType={"color"}
531 items={[
532 {
533 label: <TransparentIcon />,
534 value: "transparent",
535 tooltip: "Transparent",
536 },
537 {
538 label: <BgIcon />,
539 value: "bgColor",
540 tooltip: "Solid",
541 },
542 {
543 label: <GradientIcon />,
544 value: "gradient",
545 tooltip: "Gradient",
546 },
547 ]}
548 />
549 )}
550 {"active" === colorState && (
551 <Background
552 label={__("Color Type", "post-carousel")}
553 colorLabel="Solid Color"
554 defaultColor="#1E1E1E99"
555 attributes={thumbnailProgressColor}
556 attributesKey={"thumbnailProgressColor"}
557 setAttributes={setAttributes}
558 colorType={"hover"}
559 items={[
560 {
561 label: <TransparentIcon />,
562 value: "transparent",
563 tooltip: "Transparent",
564 },
565 {
566 label: <BgIcon />,
567 value: "bgColor",
568 tooltip: "Solid",
569 },
570 {
571 label: <GradientIcon />,
572 value: "gradient",
573 tooltip: "Gradient",
574 },
575 ]}
576 />
577 )}
578 </>
579 );
580 };
581
582 export const ThumbnailTwoGeneralTab = ({ attributes, setAttributes }) => {
583 const { contentAlignment, generalLinkOpen, thumbnailTwoGeneralPreloader } = attributes;
584
585 return (
586 <>
587 <SPToggleGroupControl
588 label={__("Content Alignment", "post-carousel")}
589 attributes={contentAlignment}
590 attributesKey={"contentAlignment"}
591 setAttributes={setAttributes}
592 items={[
593 { label: <AlignLeft />, value: "left" },
594 { label: <AlignCenter />, value: "center" },
595 { label: <AlignRight />, value: "right" },
596 ]}
597 />
598 <SelectField
599 label={__("Link Open In", "post-carousel")}
600 attributes={generalLinkOpen}
601 attributesKey={"generalLinkOpen"}
602 setAttributes={setAttributes}
603 items={openLinksOptions}
604 />
605 <Toggle
606 label={__("Preloader", "post-carousel")}
607 attributes={thumbnailTwoGeneralPreloader}
608 attributesKey={"thumbnailTwoGeneralPreloader"}
609 setAttributes={setAttributes}
610 />
611 </>
612 );
613 };
614