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 / social-profile-item / edit.js

edit.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at src/blocks/social-profile-item/edit.js

153 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useBlockProps } from "@wordpress/block-editor";
2 import { panelBodyRightIcon } from "../../icons/icons";
3 import { useEffect, useMemo } from "@wordpress/element";
4 import dynamicCssFn from "./dynamicCss";
5 import { InspectorControl } from "../../components";
6 import { Inspector } from "./inspector";
7 import { capitalizeWords, useDeviceType } from "../../controls/controls";
8 import { useSelect } from "@wordpress/data";
9 import classNames from "classnames";
10 import { compose } from "@wordpress/compose";
11 import addInitialAttr from "../shared/addInitialAttr";
12
13 const SocialItemEdit = ({ attributes, setAttributes, clientId, isSelected }) => {
14 const {
15 blockName,
16 uniqueId,
17 socialSingleLinkRelation,
18 socialSingleIconType,
19 socialSingleIcon,
20 socialSingleImage,
21 socialSingleLabel,
22 socialSingleSubText,
23 iconEnableParent,
24 labelEnableParent,
25 subTextEnableParent,
26 socialSingleProfile,
27 additionalCssClass,
28 socialLabelGlobalTypographyParent,
29 socialSubTextGlobalTypographyParent,
30 } = attributes;
31
32 const blockProps = useBlockProps({
33 className: additionalCssClass,
34 });
35 const haveLabel = socialSingleLabel.trim();
36 const haveSubText = socialSingleSubText.trim();
37 const deviceType = useDeviceType();
38
39 const parentAttr = useSelect(
40 (select) => {
41 const { getBlock, getBlockRootClientId } = select("core/block-editor");
42 const parentClientId = getBlockRootClientId(clientId);
43 if (!parentClientId) {
44 return null;
45 }
46
47 return getBlock(parentClientId)?.attributes ?? null;
48 },
49 [clientId]
50 );
51
52 useEffect(() => {
53 if (!blockName) {
54 const singleSubText = socialSingleProfile === "facebook" ? "Like" : "Follow";
55 setAttributes({
56 socialSingleLabel: socialSingleLabel ? socialSingleLabel : capitalizeWords(socialSingleProfile),
57 socialSingleSubText: socialSingleSubText ? socialSingleSubText : singleSubText,
58 socialSingleContentAreaBgBlur: { value: 0, unit: "%" },
59 layoutParent: parentAttr?.layout,
60 labelEnableParent: parentAttr?.socialLabelEnable,
61 subTextEnableParent: parentAttr?.socialSubTextEnable,
62 });
63 }
64 }, [parentAttr]);
65
66 const blockStyling = useMemo(() => dynamicCssFn(attributes, "frontend", deviceType), [attributes, deviceType]);
67
68 return (
69 <>
70 {isSelected && (
71 <InspectorControl
72 RightIcon={panelBodyRightIcon}
73 attributes={attributes}
74 setAttributes={setAttributes}
75 Inspector={Inspector}
76 templateLibrary={"google.com"}
77 />
78 )}
79 <style>{blockStyling}</style>
80 <div {...blockProps}>
81 <div id={uniqueId} className={classNames("sp-social-profile-item-container", "sp-pointer")}>
82 <a className="sp-social-profile-item-wrapper" rel={socialSingleLinkRelation}>
83 <div className="sp-social-profile-item">
84 {/** Social Profile Single Item Icon/Image */}
85 {"none" !== socialSingleIconType && iconEnableParent && (
86 <>
87 <div className="sp-social-profile-item-icon-wrapper">
88 {"icon" === socialSingleIconType && (
89 <div
90 className={`sp-social-profile-item-icon sp-social-icon-${socialSingleIcon}`}
91 >
92 <i
93 className={`sp-icon-${socialSingleIcon} sp-social-profile-item-icon-class`}
94 ></i>
95 </div>
96 )}
97 {"image" === socialSingleIconType && socialSingleImage && (
98 <div className={"sp-social-profile-item-image"}>
99 <img
100 src={socialSingleImage.url}
101 alt={socialSingleImage.alt}
102 className="sp-social-image wp-image"
103 />
104 </div>
105 )}
106 </div>
107 </>
108 )}
109 {/* { 'social-profiles-layout-three' ===
110 layoutParent && ( */}
111 <span className="sp-social-profile-icon-divider"></span>
112 {/* ) } */}
113 {(haveLabel || haveSubText) && (
114 <>
115 {/** Social Profile Single Item Label & Sub Text */}
116 <div className="sp-social-profile-item-text">
117 {haveLabel && labelEnableParent && (
118 <span
119 className={classNames(
120 "sp-social-profile-item-label",
121 socialLabelGlobalTypographyParent?.class
122 ? socialLabelGlobalTypographyParent.class
123 : ""
124 )}
125 >
126 {socialSingleLabel}
127 </span>
128 )}
129 {haveSubText && subTextEnableParent && (
130 <span
131 className={classNames(
132 "sp-social-profile-item-sub-text",
133 socialSubTextGlobalTypographyParent?.class
134 ? socialSubTextGlobalTypographyParent.class
135 : ""
136 )}
137 >
138 {socialSingleSubText}
139 </span>
140 )}
141 </div>
142 </>
143 )}
144 </div>
145 </a>
146 </div>
147 </div>
148 </>
149 );
150 };
151
152 export default compose(addInitialAttr)(SocialItemEdit);
153