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 / components / iconPicker / iconPicker.js

iconPicker.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/components/iconPicker/iconPicker.js

168 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Dropdown, Tooltip } from "@wordpress/components";
2 import { useRef, useState } from "@wordpress/element";
3 import "./editor.scss";
4 import { DropdownIcon } from "../../icons/icons";
5
6 const SPIconPicker = ({
7 attributes,
8 attributesKey,
9 setAttributes,
10 label,
11 closeBtn = true,
12 iconType = "socialIcon",
13 }) => {
14 const socialIcon = [
15 "facebook",
16 "x",
17 "linkedin",
18 "pinterest",
19 "instagram",
20 "vkontakte",
21 "digg",
22 "tumblr",
23 "reddit",
24 "whatsapp",
25 "pocket",
26 "xing",
27 "mail",
28 ];
29
30 const arrowIcon = [
31 "right-circled2",
32 "left-circled2",
33 "right-open",
34 "right-open-mini",
35 "right-open-big",
36 "right-open-one",
37 "left-open-one",
38 "right-open-outline",
39 "left-open",
40 "left-open-mini",
41 "left-open-big",
42 "left-open-outline",
43 "left-dir",
44 "right-dir",
45 "left-one",
46 "right-one",
47 "angles-right-solid",
48 "arrow-right-solid",
49 "forward-solid",
50 "right-long-solid",
51 "angle-up",
52 ];
53
54 const icons = iconType === "socialIcon" ? socialIcon : arrowIcon;
55
56 const activeIconRef = useRef(null);
57 const [isDropdownOpen, setIsDropdownOpen] = useState(false);
58
59 const handleChange = (newIcon) => {
60 setAttributes({ [attributesKey]: newIcon });
61 };
62
63 const handleClose = () => {
64 setAttributes({ [attributesKey]: "" });
65 };
66
67 return (
68 <div className="sp-smart-post-icon-picker-area sp-smart-post-component-mb">
69 <div className="sp-smart-post-component-title">{label}</div>
70 {/* modal */}
71 <Dropdown
72 // position="top right"
73 popoverProps={{ placement: "top-right" }}
74 renderToggle={({ isOpen, onToggle }) => (
75 <div
76 onClick={() => {
77 setIsDropdownOpen((prev) => !prev);
78 onToggle();
79 }}
80 aria-expanded={isOpen}
81 className="sp-smart-post-icon-picker-dropdown-input"
82 >
83 <div className="sp-smart-post-media-control__wrapper sp-smart-post-icon-picker">
84 {attributes ? (
85 <>
86 <div className="sp-smart-post-icon-picker-active-icon">
87 <i className={`sp-icon-${attributes}`}></i>
88 </div>
89 {closeBtn && (
90 <button
91 className="sp-smart-post-icon-picker-close-btn sp-smart-post-icon-picker-btn"
92 onClick={handleClose}
93 >
94 <i className="fa fa-times" />
95 </button>
96 )}
97 </>
98 ) : (
99 <button className="sp-smart-post-icon-picker-add-btn sp-smart-post-icon-picker-btn">
100 <i className="fa fa-plus" />
101 </button>
102 )}
103 </div>
104 <div className={`sp-smart-post-iconPicker-dropdown-btn ${isOpen ? "is-open" : "is-close"}`}>
105 <DropdownIcon />
106 </div>
107 </div>
108 )}
109 onClose={(event, isInside) => {
110 setIsDropdownOpen(false);
111 if (isInside) {
112 event.stopPropagation();
113 }
114 }}
115 renderContent={({ onToggle }) => (
116 <div
117 onMouseDown={(event) => {
118 event.stopPropagation();
119 }}
120 className="sp-smart-post-icon-picker-popup"
121 >
122 <div className="sp-smart-post-popup-heading">
123 <div className="sp-smart-post-icon-picker-popup-top-section">
124 <span className="sp-smart-post-icon-search-heading">Select an Icon</span>
125 <span className="sp-smart-post-icon-search-sub-heading">
126 Choose an icon for this collection.
127 </span>
128 </div>
129 <button
130 className="sp-smart-post-icon-picker-close-btn sp-smart-post-icon-picker-btn"
131 onClick={() => {
132 setIsDropdownOpen(false);
133 onToggle();
134 }}
135 >
136 <i className="fa fa-times" />
137 </button>
138 </div>
139 <div className="sp-smart-post-icon-picker-list">
140 {icons?.map((icon, index) => (
141 <Tooltip
142 key={index}
143 text={attributes}
144 className="sp-smart-post-component-tooltip"
145 position="top"
146 >
147 <span
148 key={index}
149 ref={attributes === icon ? activeIconRef : null}
150 className={`sp-smart-post-icon-picker-item ${
151 attributes === icon ? "active" : ""
152 }`}
153 onClick={() => handleChange(icon)}
154 >
155 <i className={`sp-icon-${icon}`}></i>
156 </span>
157 </Tooltip>
158 ))}
159 </div>
160 </div>
161 )}
162 />
163 </div>
164 );
165 };
166
167 export default SPIconPicker;
168