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-three / edit.js

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

183 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useRef, useState, useMemo } from "@wordpress/element";
2 import { useBlockProps } from "@wordpress/block-editor";
3 import InspectorControl from "../../components/inspectorControls/inspectorControls";
4 import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons";
5 import { EditorWrapper } from "../shared/wrapper";
6 import dynamicCssFn from "./dynamicCss";
7 import Inspector from "./inspect";
8 import Render from "./render";
9 import { useDeviceType } from "../../controls/controls";
10 import { TogglePanelBodyProvider } from "../../context";
11 import { cssDependency } from "../shared/cssDependency";
12 import { compose } from "@wordpress/compose";
13 import addInitialAttr from "../shared/addInitialAttr";
14
15 const ListThreeEdit = ({ attributes, setAttributes, isSelected }) => {
16 const [posts, setPosts] = useState([]);
17 const {
18 blockName,
19 postListLayout,
20 contentAreaBg,
21 postCardBg,
22 customCss,
23 fontListsEditPage,
24 imageSpace,
25 contentAreaPadding,
26 largeItemHeight,
27 imageHeight,
28 } = attributes;
29 const blockProps = useBlockProps();
30 const reloadRef = useRef(true);
31 const deviceType = useDeviceType();
32
33 useEffect(() => {
34 if (!blockName) {
35 setAttributes({
36 largeItemTitleColor: {
37 color: "",
38 hover: "",
39 },
40 largeMetaColors: {
41 color: "",
42 hoverColor: "",
43 },
44 // align: 'wide',
45 imagePosition: "left",
46 imageSize: "smart-post-landscape",
47 contentAreaBg: {
48 ...contentAreaBg,
49 color: {
50 ...contentAreaBg?.color,
51 style: "",
52 solidColor: "",
53 },
54 hover: {
55 ...contentAreaBg?.hover,
56 style: "",
57 solidColor: "",
58 },
59 },
60 contentVerticalPosition: "bottom",
61 contentAreaPadding: {
62 ...contentAreaPadding,
63 device: {
64 ...contentAreaPadding.device,
65 Desktop: {
66 ...contentAreaPadding.device.Desktop,
67 top: 15,
68 right: 0,
69 bottom: 0,
70 left: 0,
71 },
72 },
73 },
74
75 imageSpace: {
76 ...imageSpace,
77 device: {
78 ...imageSpace.device,
79 Desktop: 16,
80 },
81 },
82 postCardBg: {
83 ...postCardBg,
84 color: {
85 ...postCardBg?.color,
86 style: "",
87 solidColor: "",
88 },
89 hover: {
90 ...postCardBg?.hover,
91 style: "",
92 solidColor: "",
93 },
94 },
95 largeItemHeight: {
96 ...largeItemHeight,
97 device: {
98 ...largeItemHeight.device,
99 Desktop: 372,
100 },
101 },
102 // imageWidth: {
103 // ...imageWidth,
104 // device: {
105 // ...imageWidth.device,
106 // Desktop: 240,
107 // },
108 // unit: {
109 // ...imageWidth.unit,
110 // Desktop: "px",
111 // },
112 // },
113 imageHeight: {
114 ...imageHeight,
115 device: {
116 ...imageHeight.device,
117 Desktop: 161,
118 },
119 unit: {
120 ...imageHeight.unit,
121 Desktop: "px",
122 },
123 },
124 imageOverlay: "custom",
125 socialPopupShareColor: {
126 color: "",
127 hoverColor: "",
128 },
129 });
130 }
131 }, []);
132
133 // useEffect( () => {
134 // setAttributes( {
135 // dynamicCss: dynamicCssFn( attributes, 'frontend', setAttributes ),
136 // } );
137 // }, cssDependency(attributes));
138 const blockStyling = useMemo(
139 () => dynamicCssFn(attributes, "frontend", deviceType),
140 [...cssDependency(attributes), deviceType]
141 );
142
143 useEffect(() => {
144 setAttributes({ currentScreen: deviceType });
145 }, [deviceType]);
146
147 useEffect(() => {
148 if (reloadRef.current) {
149 reloadRef.current = false;
150 } else {
151 setAttributes({
152 contentOrientation: postListLayout,
153 });
154 }
155 }, [postListLayout]);
156
157 return (
158 <div {...blockProps}>
159 <style>
160 {fontListsEditPage}
161 {blockStyling}
162 {customCss}
163 </style>
164 <TogglePanelBodyProvider>
165 <InspectorControl
166 TitleIcon={panelBodyTitleIcon}
167 RightIcon={panelBodyRightIcon}
168 Inspector={Inspector}
169 attributes={attributes}
170 setAttributes={setAttributes}
171 isSelected={isSelected}
172 />
173 {/* Render Html here */}
174 <EditorWrapper setPosts={setPosts} setAttributes={setAttributes}>
175 <Render posts={posts} attributes={attributes} page={"editor"} />
176 </EditorWrapper>
177 </TogglePanelBodyProvider>
178 </div>
179 );
180 };
181
182 export default compose(addInitialAttr)(ListThreeEdit);
183