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 / smart-info-box / edit.js

edit.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/blocks/smart-info-box/edit.js

79 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useMemo } from "@wordpress/element";
2 import { useBlockProps } from "@wordpress/block-editor";
3 import InspectorControl from "../../components/inspectorControls/inspectorControls";
4 import { getBlockShortName, jsonStringify } from "../shared/helpFn";
5 import Inspector from "./inspect";
6 import dynamicCssFn from "./dynamicCss";
7 import { googleFonts } from "../../controls/controls";
8 import { TogglePanelBodyProvider } from "../../context";
9 import EditHtml from "./editHtml";
10 import { compose } from "@wordpress/compose";
11 import addInitialAttr from "../shared/addInitialAttr";
12 import dynamicDependency from "./infoBoxDependency";
13
14 const SmartInfoBoxEdit = ({ attributes, setAttributes, clientId, name }) => {
15 const {
16 ratingTypography,
17 titleTypography,
18 subTitleTypography,
19 descriptionTypography,
20 badgeTypography,
21 additionalCssClass,
22 blockName,
23 } = attributes;
24
25 const googleFontLists = [
26 ratingTypography,
27 titleTypography,
28 subTitleTypography,
29 descriptionTypography,
30 badgeTypography,
31 ];
32
33 useEffect(() => {
34 setAttributes({
35 fontLists: jsonStringify(googleFonts(googleFontLists, "frontend")),
36 });
37 }, googleFontLists);
38
39 const blockProps = useBlockProps({
40 className: additionalCssClass,
41 });
42
43 const googleFontListsEditor = useMemo(() => googleFonts(googleFontLists), googleFontLists);
44
45 const blockStyling = useMemo(() => {
46 return dynamicCssFn(attributes, "frontend");
47 }, dynamicDependency(attributes));
48
49 // BlockName init
50 useEffect(() => {
51 if (!blockName) {
52 setAttributes({ blockName: getBlockShortName(name) });
53 }
54 }, []);
55
56 useEffect(() => {
57 setAttributes({
58 uniqueId: `sp-smart-post-smart-list-${clientId?.split("-").pop()}`,
59 });
60 }, [clientId]);
61
62 return (
63 <div {...blockProps}>
64 <style>
65 {googleFontListsEditor}
66 {blockStyling}
67 </style>
68
69 <TogglePanelBodyProvider>
70 <InspectorControl Inspector={Inspector} attributes={attributes} setAttributes={setAttributes} />
71
72 <EditHtml attributes={attributes} setAttributes={setAttributes} />
73 </TogglePanelBodyProvider>
74 </div>
75 );
76 };
77
78 export default compose(addInitialAttr)(SmartInfoBoxEdit);
79