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

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