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

135 lines 3.6 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 InspectorControl from "../../components/inspectorControls/inspectorControls";
3 import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons";
4 import { useBlockProps } from "@wordpress/block-editor";
5 import Inspector from "./inspect";
6 import dynamicCssFn from "./dynamicCss";
7 import { useDeviceType } from "../../controls/controls";
8 import { EditorWrapper } from "../shared/wrapper";
9 import Render from "./render";
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 GridTwoEdit = ({ attributes, setAttributes, isSelected }) => {
16 const [posts, setPosts] = useState([]);
17 const { blockName, contentAreaBg, fontListsEditPage, smallItemHeight, contentAreaPadding, customCss } = attributes;
18
19 const blockProps = useBlockProps();
20
21 const deviceType = useDeviceType();
22
23 useEffect(() => {
24 if (!blockName) {
25 setAttributes({
26 // align: 'wide',
27 // Set default attributes value for this block.
28 // excerptColor: { ...excerptColor, color: '#EEEEEE' },
29 contentHorizontalPosition: "left",
30 contentAreaBg: {
31 ...contentAreaBg,
32 color: {
33 ...contentAreaBg.color,
34 solidColor: "transparent",
35 },
36 },
37 // titleColor: { ...titleColor, color: '#ffffff' },
38 // metaColors: { ...metaColors, color: '#ffffff' },
39 showReadMoreButton: false,
40 imagePosition: "background",
41 imageOverlayColor: "default",
42 contentVerticalPosition: "bottom",
43 smallItemHeight: {
44 ...smallItemHeight,
45 device: {
46 ...smallItemHeight.device,
47 Desktop: 260,
48 Tablet: 210,
49 Mobile: 210,
50 },
51 },
52 contentAreaPadding: {
53 ...contentAreaPadding,
54 device: {
55 ...contentAreaPadding.device,
56 Desktop: {
57 top: 0,
58 right: 20,
59 bottom: 20,
60 left: 20,
61 },
62 },
63 },
64 // paginationMargin: {
65 // ...paginationMargin,
66 // device: {
67 // ...paginationMargin.device,
68 // Desktop: {
69 // ...paginationMargin.device.Desktop,
70 // top: 48,
71 // },
72 // Tablet: {
73 // ...paginationMargin.device.Tablet,
74 // top: 30,
75 // },
76 // Mobile: {
77 // ...paginationMargin.device.Mobile,
78 // top: 30,
79 // },
80 // },
81 // },
82 // catTabCategoryBg: {
83 // ...catTabCategoryBg,
84 // color: {
85 // ...catTabCategoryBg.color,
86 // solidColor: '#FFFFFF',
87 // },
88 // hover: {
89 // ...catTabCategoryBg.hover,
90 // solidColor: '#EF5D30',
91 // },
92 // },
93 // catTabCategoryColor: {
94 // ...catTabCategoryColor,
95 // color: '#222222',
96 // hoverColor: '#FFFFFF',
97 // },
98 });
99 }
100 }, []);
101
102 const blockStyling = useMemo(
103 () => dynamicCssFn(attributes, "frontend", deviceType),
104 [...cssDependency(attributes), deviceType, attributes]
105 );
106 useEffect(() => {
107 setAttributes({ currentScreen: deviceType });
108 }, [deviceType]);
109
110 return (
111 <div {...blockProps}>
112 <style>
113 {fontListsEditPage}
114 {blockStyling}
115 {customCss}
116 </style>
117 <TogglePanelBodyProvider>
118 <InspectorControl
119 TitleIcon={panelBodyTitleIcon}
120 RightIcon={panelBodyRightIcon}
121 Inspector={Inspector}
122 attributes={attributes}
123 setAttributes={setAttributes}
124 isSelected={isSelected}
125 />
126 <EditorWrapper setPosts={setPosts} setAttributes={setAttributes}>
127 <Render posts={posts} attributes={attributes} page={"editor"} />
128 </EditorWrapper>
129 </TogglePanelBodyProvider>
130 </div>
131 );
132 };
133
134 export default compose(addInitialAttr)(GridTwoEdit);
135