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

153 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, 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 Inspector from "./inspect";
6 import dynamicCssFn from "./dynamicCss";
7 import Render from "./render";
8 import { EditorWrapper } from "../shared/wrapper";
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 GridOneEdit = ({ attributes, setAttributes, isSelected }) => {
16 const [posts, setPosts] = useState([]);
17 const {
18 blockName,
19 contentAreaBg,
20 // gridOneMasonryEnable,
21 postCardBg,
22 fontListsEditPage,
23 postGridLayout,
24 imageHeight,
25 titleFontSize,
26 largeItemTitleFontSize,
27 contentAreaPadding,
28 customCss,
29 socialPopupShareColor,
30 } = attributes;
31
32 const blockProps = useBlockProps();
33 const deviceType = useDeviceType();
34
35 useEffect(() => {
36 if (!blockName) {
37 setAttributes({
38 contentAreaBg: {
39 ...contentAreaBg,
40 hover: {
41 ...contentAreaBg.hover,
42 style: "",
43 },
44 },
45 postCardBg: {
46 ...postCardBg,
47 color: {
48 ...postCardBg.color,
49 style: "",
50 },
51 hover: {
52 ...postCardBg.hover,
53 style: "",
54 },
55 },
56 imageSize: "smart-post-landscape",
57 imageHeight: {
58 ...imageHeight,
59 device: {
60 ...imageHeight.device,
61 Desktop: 244,
62 },
63 },
64 titleFontSize: {
65 ...titleFontSize,
66 device: {
67 ...titleFontSize.device,
68 Tablet: 18,
69 Mobile: 18,
70 },
71 },
72 largeItemTitleFontSize: {
73 ...largeItemTitleFontSize,
74 device: {
75 ...largeItemTitleFontSize.device,
76 Tablet: 22,
77 Mobile: 22,
78 },
79 },
80 contentAreaPadding: {
81 ...contentAreaPadding,
82 device: {
83 ...contentAreaPadding.device,
84 Desktop: {
85 ...contentAreaPadding.device.Desktop,
86 top: 0,
87 right: 0,
88 bottom: 0,
89 left: 0,
90 },
91 Tablet: {
92 ...contentAreaPadding.device.Desktop,
93 top: 0,
94 right: 0,
95 bottom: 0,
96 left: 0,
97 },
98 Mobile: {
99 ...contentAreaPadding.device.Desktop,
100 top: 0,
101 right: 0,
102 bottom: 0,
103 left: 0,
104 },
105 },
106 },
107 socialPopupShareColor: {
108 ...socialPopupShareColor,
109 color: "#333",
110 },
111 });
112 }
113 }, []);
114
115 const blockStyling = useMemo(
116 () => dynamicCssFn(attributes, "frontend", deviceType),
117 [...cssDependency(attributes), deviceType]
118 );
119
120 useEffect(() => {
121 setAttributes({ currentScreen: deviceType });
122 }, [deviceType]);
123
124 useEffect(() => {
125 setAttributes({ blockLayoutName: postGridLayout });
126 }, [postGridLayout]);
127
128 return (
129 <div {...blockProps}>
130 <style>
131 {fontListsEditPage}
132 {blockStyling}
133 {customCss}
134 </style>
135 <TogglePanelBodyProvider>
136 <InspectorControl
137 TitleIcon={panelBodyTitleIcon}
138 RightIcon={panelBodyRightIcon}
139 Inspector={Inspector}
140 attributes={attributes}
141 setAttributes={setAttributes}
142 isSelected={isSelected}
143 />
144 <EditorWrapper setPosts={setPosts} setAttributes={setAttributes}>
145 <Render posts={posts} attributes={attributes} page={"editor"} />
146 </EditorWrapper>
147 </TogglePanelBodyProvider>
148 </div>
149 );
150 };
151
152 export default compose(addInitialAttr)(GridOneEdit);
153