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

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

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Fragment, useEffect, useRef, useState } from "@wordpress/element";
2 import TemplateOne from "../shared/templates/templateCards/templateOne";
3
4 const Render = ({ attributes, posts }) => {
5 const { postListLayout, contentVerticalPosition, showHideDivider, catTabCategoryPosition } = attributes;
6 const containerRef = useRef(null);
7
8 const [selectedPostId, setSelectedPostId] = useState(null);
9
10 useEffect(() => {
11 const handleClickOutside = (event) => {
12 if (containerRef.current && !containerRef.current.contains(event.target)) {
13 setSelectedPostId(null);
14 }
15 };
16
17 document.addEventListener("mousedown", handleClickOutside);
18 return () => document.removeEventListener("mousedown", handleClickOutside);
19 }, []);
20
21 return (
22 <div
23 className={`sp-smart-post-list-one-block ${postListLayout} sp-cat-position-${catTabCategoryPosition}`}
24 ref={containerRef}
25 >
26 <div className={`sp-smart-post-list-one-container ${postListLayout}`}>
27 {posts?.map((post, i) => {
28 return (
29 <Fragment key={post?.post_id}>
30 <div className={`sp-smart-post-show-list-one-card-wrapper`}>
31 <TemplateOne
32 data={post}
33 attributes={attributes}
34 posts={posts}
35 contentPosition={contentVerticalPosition}
36 isSelected={selectedPostId === post?.post_id}
37 onSelect={() => setSelectedPostId(post?.post_id)}
38 />
39 </div>
40 {showHideDivider && <div className="sp-smart-post-list-divider"></div>}
41 </Fragment>
42 );
43 })}
44 </div>
45 </div>
46 );
47 };
48
49 export default Render;
50