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-four / loopContent.js

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

103 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { gridFourLargeItemPosition, skipItemsForGridFourTopSection } from "../../controls/constants";
2 import { Fragment, useEffect, useState } from "@wordpress/element";
3 import { breakpoint } from "../../controls/controls";
4 import TemplateOne from "../shared/templates/templateCards/templateOne";
5
6 const LoopContent = ({
7 posts,
8 attributes,
9 bottomStyle = false,
10 Masonry = false,
11 ResponsiveMasonry = Fragment,
12 containerRef,
13 }) => {
14 const { postGridLayout, contentVerticalPosition, gridFourColumns, masonryGap } = attributes;
15
16 const deviceType = breakpoint();
17
18 const skipPostForLargeLayouts = "Mobile" !== deviceType ? skipItemsForGridFourTopSection[postGridLayout] : 0;
19
20 const largeItemPosition = gridFourLargeItemPosition[postGridLayout];
21
22 const masonryGapCss = `${masonryGap?.device?.Desktop}${masonryGap?.unit?.Desktop}`;
23
24 const columnsBreakPoints = Masonry
25 ? {
26 columnsCountBreakPoints: {
27 350: gridFourColumns?.device?.Mobile,
28 750: gridFourColumns?.device?.Tablet,
29 900: gridFourColumns?.device?.Desktop,
30 },
31 }
32 : {};
33
34 const gutter = Masonry
35 ? {
36 gutter: masonryGapCss,
37 }
38 : {};
39
40 const [selectedPostId, setSelectedPostId] = useState(null);
41
42 useEffect(() => {
43 const handleClickOutside = (event) => {
44 if (containerRef.current && !containerRef.current.contains(event.target)) {
45 setSelectedPostId(null);
46 }
47 };
48
49 document.addEventListener("mousedown", handleClickOutside);
50 return () => document.removeEventListener("mousedown", handleClickOutside);
51 }, []);
52
53 return (
54 <>
55 {Masonry && (
56 <ResponsiveMasonry {...columnsBreakPoints}>
57 <Masonry {...gutter}>
58 {posts
59 ?.slice(
60 bottomStyle ? skipPostForLargeLayouts : 0,
61 bottomStyle ? posts?.length : skipPostForLargeLayouts
62 )
63 ?.map((post, i) => (
64 <TemplateOne
65 key={post?.post_id}
66 index={i}
67 data={post}
68 posts={posts}
69 contentPosition={contentVerticalPosition}
70 attributes={attributes}
71 largeItemIndex={bottomStyle ? "" : i === largeItemPosition ? "large" : "no"}
72 isSelected={selectedPostId === post?.post_id}
73 onSelect={() => setSelectedPostId(post?.post_id)}
74 />
75 ))}
76 </Masonry>
77 </ResponsiveMasonry>
78 )}
79 {!Masonry &&
80 posts
81 ?.slice(
82 bottomStyle ? skipPostForLargeLayouts : 0,
83 bottomStyle ? posts?.length : skipPostForLargeLayouts
84 )
85 ?.map((post, i) => (
86 <TemplateOne
87 key={post?.post_id}
88 index={i}
89 data={post}
90 posts={posts}
91 contentPosition={contentVerticalPosition}
92 attributes={attributes}
93 largeItemIndex={bottomStyle ? "" : i === largeItemPosition ? "large" : "no"}
94 isSelected={selectedPostId === post?.post_id}
95 onSelect={() => setSelectedPostId(post?.post_id)}
96 />
97 ))}
98 </>
99 );
100 };
101
102 export default LoopContent;
103