PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.2
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 / admin / pages / modulePart.js

modulePart.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.2, at src/admin/pages/modulePart.js

550 lines 15.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from "@wordpress/i18n";
2 import {
3 Background,
4 Border,
5 BoxShadow,
6 InputControl,
7 MultiSelectDndKit,
8 SelectField,
9 Spacing,
10 SpColorPicker,
11 SPRangeControl,
12 SPToggleGroupControl,
13 Toggle,
14 TypographyNew,
15 } from "../../components";
16 import {
17 BackToTopArrowFive,
18 BackToTopArrowFour,
19 BackToTopArrowOne,
20 BackToTopArrowThree,
21 BackToTopArrowTwo,
22 } from "../template-parts/icons";
23 import { BgIcon, GradientIcon } from "../../components/background/svgIcon";
24 import { useSelect } from "@wordpress/data";
25 import { useEffect, useMemo, useState } from "@wordpress/element";
26 import classNames from "classnames";
27 import moduleDynamicCss from "../template-parts/moduleDynamicCss";
28 import { googleFonts } from "../../controls/controls";
29
30 export const BackToTopGeneral = ({ attributes, props }) => {
31 const { setSettingsValue } = props;
32 const {
33 display_position,
34 horizontal_position,
35 vertical_position,
36 back_to_top_icon,
37 top_icon_source,
38 icon_size,
39 back_top_label,
40 display_on,
41 exclude_page,
42 include_only,
43 smooth_scroll,
44 transition_delay,
45 entrance_animation,
46 go_to_bottom,
47 back_bottom_label,
48 } = attributes?.options;
49
50 const [pageListItems, setPageListItems] = useState([]);
51
52 const allPagesList = useSelect((select) => {
53 return select("core").getEntityRecords("postType", "page", {
54 per_page: -1,
55 status: "publish",
56 _fields: "id,title,slug",
57 });
58 }, []);
59
60 useEffect(() => {
61 const topTen =
62 allPagesList?.map((item) => ({ id: item.id, label: item.title?.rendered, value: item.slug })) || [];
63 setPageListItems(topTen);
64 }, [allPagesList]);
65
66 const updateStateHandler = (valueKey, value) => {
67 setSettingsValue({ ...attributes, options: { ...attributes.options, [valueKey]: value } });
68 };
69
70 return (
71 <>
72 <SPToggleGroupControl
73 label={__("Display Position", "post-carousel")}
74 attributes={display_position}
75 onClick={(newValue) => updateStateHandler("display_position", newValue)}
76 items={[
77 { label: "Button Left", value: "button-left" },
78 { label: "Button Right", value: "button-right" },
79 ]}
80 />
81 <SPRangeControl
82 label={__("Horizontal Distance", "post-carousel")}
83 attributes={horizontal_position}
84 units={["px", "%", "em"]}
85 defaultValue={{ value: 30, unit: "px" }}
86 onValueChange={(newValue) =>
87 updateStateHandler("horizontal_position", { ...horizontal_position, value: newValue?.value })
88 }
89 onUnitChange={(newUnit) =>
90 updateStateHandler("horizontal_position", { ...horizontal_position, unit: newUnit?.unit })
91 }
92 setCustomReset={true}
93 />
94 <SPRangeControl
95 label={__("Vertical Distance", "post-carousel")}
96 attributes={vertical_position}
97 units={["px", "%", "em"]}
98 defaultValue={{ value: 30, unit: "px" }}
99 onValueChange={(newValue) =>
100 updateStateHandler("vertical_position", { ...vertical_position, value: newValue?.value })
101 }
102 onUnitChange={(newUnit) =>
103 updateStateHandler("vertical_position", { ...vertical_position, unit: newUnit?.unit })
104 }
105 setCustomReset={true}
106 />
107 <Toggle
108 label={__("Icon", "post-carousel")}
109 attributes={back_to_top_icon}
110 onChange={(newToggle) => updateStateHandler("back_to_top_icon", !newToggle)}
111 />
112 {back_to_top_icon && (
113 <>
114 <SPToggleGroupControl
115 label={__("Icon Source", "post-carousel")}
116 extraClass={"sp-module-arrow-icon"}
117 attributes={top_icon_source}
118 onClick={(newValue) => updateStateHandler("top_icon_source", newValue)}
119 items={[
120 { label: <BackToTopArrowOne />, value: "top-arrow-one" },
121 { label: <BackToTopArrowTwo />, value: "top-arrow-two" },
122 { label: <BackToTopArrowThree />, value: "top-arrow-three" },
123 { label: <BackToTopArrowFour />, value: "top-arrow-four" },
124 { label: <BackToTopArrowFive />, value: "top-arrow-five" },
125 ]}
126 />
127 <SPRangeControl
128 label={__("Icon Size", "post-carousel")}
129 attributes={icon_size}
130 units={["px", "%", "em"]}
131 defaultValue={{ value: 24, unit: "px" }}
132 onValueChange={(newValue) =>
133 updateStateHandler("icon_size", { ...icon_size, value: newValue?.value })
134 }
135 onUnitChange={(newUnit) =>
136 updateStateHandler("icon_size", { ...icon_size, unit: newUnit?.unit })
137 }
138 setCustomReset={true}
139 />
140 </>
141 )}
142 <InputControl
143 label={__("Back to Top Text Label", "post-carousel")}
144 attributes={back_top_label}
145 flex={false}
146 inputType="text"
147 onChange={(newValue) => updateStateHandler("back_top_label", newValue)}
148 />
149
150 <SelectField
151 label={__("Display On", "post-carousel")}
152 attributes={display_on}
153 onChange={(newValue) => updateStateHandler("display_on", newValue)}
154 items={[
155 { label: "All Pages", value: "all-pages" },
156 { label: "Only Archive Pages", value: "only-archive-pages" },
157 { label: "Single Post Pages", value: "single-pages" },
158 { label: "Specific Pages", value: "specific-pages" },
159 ]}
160 />
161 {display_on === "specific-pages" && (
162 <MultiSelectDndKit
163 label={__("Select Pages", "post-carousel")}
164 values={include_only}
165 searchable={true}
166 onChange={(e) => updateStateHandler("include_only", e)}
167 items={pageListItems}
168 />
169 )}
170 {display_on === "all-pages" && (
171 <MultiSelectDndKit
172 label={__("Exclude Pages", "post-carousel")}
173 values={exclude_page}
174 searchable={true}
175 onChange={(e) => updateStateHandler("exclude_page", e)}
176 items={pageListItems}
177 />
178 )}
179 <Toggle
180 label={__("Smooth Scroll", "post-carousel")}
181 attributes={smooth_scroll}
182 onChange={(newToggle) => updateStateHandler("smooth_scroll", !newToggle)}
183 />
184 {smooth_scroll && (
185 <SPRangeControl
186 label={__("Transition Delay", "post-carousel")}
187 attributes={transition_delay}
188 units={["s"]}
189 min={0.1}
190 max={2}
191 step={0.1}
192 defaultValue={{ value: 24, unit: "s" }}
193 onValueChange={(newValue) =>
194 updateStateHandler("transition_delay", { ...transition_delay, value: newValue?.value })
195 }
196 onUnitChange={(newUnit) =>
197 updateStateHandler("transition_delay", { ...transition_delay, unit: newUnit?.unit })
198 }
199 setCustomReset={true}
200 />
201 )}
202 <SelectField
203 label={__("Entrance Animation", "post-carousel")}
204 attributes={entrance_animation}
205 onChange={(newValue) => updateStateHandler("entrance_animation", newValue)}
206 items={[
207 { label: "Fade In", value: "fade-in" },
208 { label: "Slide In Left", value: "slide-in-left" },
209 { label: "Slide In Right", value: "slide-in-right" },
210 { label: "Slide In Up", value: "slide-in-up" },
211 ]}
212 />
213 <Toggle
214 label={__("Go to Bottom", "post-carousel")}
215 attributes={go_to_bottom}
216 onChange={(newVal) => updateStateHandler("go_to_bottom", !newVal)}
217 />
218 {go_to_bottom && (
219 <InputControl
220 label={__("Back to Bottom Text Label", "post-carousel")}
221 attributes={back_bottom_label}
222 flex={false}
223 inputType="text"
224 onChange={(newValue) => updateStateHandler("back_bottom_label", newValue)}
225 />
226 )}
227 </>
228 );
229 };
230
231 export const BackToTopStyle = ({ attributes, props }) => {
232 const { setSettingsValue } = props;
233 const {
234 typography,
235 font_size,
236 line_height,
237 letter_spacing,
238 word_spacing,
239 color,
240 background_color,
241 border,
242 border_width,
243 border_radius,
244 box_shadow_enable,
245 box_shadow,
246 box_shadow_enable_hover,
247 box_shadow_hover,
248 padding,
249 } = attributes?.options;
250
251 const [colorState, setColorState] = useState("color");
252
253 const updateStateHandler = (valueKey, value) => {
254 setSettingsValue({ ...attributes, options: { ...attributes.options, [valueKey]: value } });
255 };
256
257 const updateSpacingUtilityHandler = (attrKey, attr, type, newUtility) => {
258 const updateAttr = { ...attr, [type]: newUtility };
259 updateStateHandler(attrKey, updateAttr);
260 };
261
262 const updateValueByColorState = (valueKey, value, attr, state) => {
263 const updateValue = { ...attr, [state]: value };
264 updateStateHandler(valueKey, updateValue);
265 };
266
267 return (
268 <>
269 <TypographyNew
270 attributes={{
271 family: typography,
272 familyKey: "typography",
273 fontSize: font_size,
274 fontSizeKey: "font_size",
275 lineHeight: line_height,
276 lineHeightKey: "line_height",
277 fontSpacing: letter_spacing,
278 fontSpacingKey: "letter_spacing",
279 wordSpacing: word_spacing,
280 wordSpacingKey: "word_spacing",
281 }}
282 onStateUpdate={(valueKey, value) => updateStateHandler(valueKey, value)}
283 />
284 <SPToggleGroupControl
285 attributes={colorState}
286 onClick={(newValue) => setColorState(newValue)}
287 items={[
288 { label: "Normal", value: "color" },
289 { label: "Hover", value: "hover" },
290 ]}
291 />
292 {colorState === "color" ? (
293 <>
294 <SpColorPicker
295 label={__("Color", "post-carousel")}
296 value={color?.color}
297 onChange={(newValue) => updateValueByColorState("color", newValue, color, "color")}
298 />
299 <Background
300 label={__("Background Type", "post-carousel")}
301 colorLabel="Solid Color"
302 defaultColor="#fff"
303 attributes={background_color}
304 attributesKey={"background_color"}
305 onStateUpdate={(key, value) =>
306 updateStateHandler("background_color", value, background_color, "color")
307 }
308 colorType={"color"}
309 items={[
310 {
311 label: <BgIcon />,
312 value: "bgColor",
313 tooltip: "Solid",
314 },
315 {
316 label: <GradientIcon />,
317 value: "gradient",
318 tooltip: "Gradient",
319 },
320 ]}
321 />
322 <Toggle
323 label={__("Box Shadow", "post-carousel")}
324 attributes={box_shadow_enable}
325 attributesKey={"box_shadow_enable"}
326 onChange={(newVal) => updateStateHandler("box_shadow_enable", !newVal)}
327 />
328 {box_shadow_enable && (
329 <BoxShadow
330 label={__("Shadow Type", "post-carousel")}
331 attributes={box_shadow}
332 attributesKey={"box_shadow"}
333 setAttributes={() => {}}
334 onChange={(key, newVal) => updateStateHandler(key, newVal)}
335 />
336 )}
337 </>
338 ) : (
339 <>
340 <SpColorPicker
341 label={__("Color", "post-carousel")}
342 value={color.hoverColor}
343 onChange={(newValue) => updateValueByColorState("color", newValue, color, "hoverColor")}
344 />
345 <Background
346 label={__("Background Type", "post-carousel")}
347 colorLabel="Solid Color"
348 defaultColor="#fff"
349 attributes={background_color}
350 attributesKey={"background_color"}
351 onStateUpdate={(key, value) => updateStateHandler("background_color", value)}
352 colorType={"hover"}
353 items={[
354 {
355 label: <BgIcon />,
356 value: "bgColor",
357 tooltip: "Solid",
358 },
359 {
360 label: <GradientIcon />,
361 value: "gradient",
362 tooltip: "Gradient",
363 },
364 ]}
365 />
366 <Toggle
367 label={__("Hover Box Shadow", "post-carousel")}
368 attributes={box_shadow_enable_hover}
369 attributesKey={"box_shadow_enable_hover"}
370 onChange={(newVal) => updateStateHandler("box_shadow_enable_hover", !newVal)}
371 />
372 {box_shadow_enable_hover && (
373 <BoxShadow
374 label={__("Hover Shadow Type", "post-carousel")}
375 attributes={box_shadow_hover}
376 attributesKey={"box_shadow_hover"}
377 setAttributes={() => {}}
378 onChange={(key, newVal) => updateStateHandler(key, newVal)}
379 />
380 )}
381 </>
382 )}
383 <Border
384 attributes={{
385 border: border,
386 borderWidth: border_width,
387 }}
388 attributesKey={{
389 border: "border",
390 borderWidth: "border_width",
391 }}
392 onStateUpdate={(key, newValue) => updateStateHandler(key, newValue)}
393 />
394 <Spacing
395 label={__("Border Radius", "post-carousel")}
396 attributes={border_radius}
397 attributesKey={"border_radius"}
398 units={["px", "%", "em"]}
399 defaultValue={{ unit: "px", value: { top: 4, right: 4, bottom: 4, left: 4 } }}
400 onChange={(newValue) => updateStateHandler("border_radius", newValue)}
401 onUnitChange={(unit) => updateSpacingUtilityHandler("border_radius", border_radius, "unit", unit)}
402 updateAllChange={(newAllChange) =>
403 updateSpacingUtilityHandler("border_radius", border_radius, "allChange", newAllChange)
404 }
405 />
406 <Spacing
407 label={__("Padding", "post-carousel")}
408 attributes={padding}
409 attributesKey={"padding"}
410 units={["px", "%", "em"]}
411 defaultValue={{ unit: "px", value: { top: 8, right: 16, bottom: 8, left: 12 } }}
412 onChange={(newValue) => updateStateHandler("padding", newValue)}
413 onUnitChange={(unit) => updateSpacingUtilityHandler("padding", padding, "unit", unit)}
414 updateAllChange={(newAllChange) =>
415 updateSpacingUtilityHandler("padding", padding, "allChange", newAllChange)
416 }
417 />
418 </>
419 );
420 };
421
422 export const BackToTopPreview = ({ attributes, props }) => {
423 const { setSettingsValue } = props;
424 const {
425 display_position,
426 back_to_top_icon,
427 top_icon_source,
428 back_top_label,
429 smooth_scroll,
430 entrance_animation,
431 go_to_bottom,
432 back_bottom_label,
433 fontListsEditPage,
434 typography,
435 icon_size,
436 font_size,
437 line_height,
438 letter_spacing,
439 word_spacing,
440 color,
441 background_color,
442 border,
443 border_width,
444 border_radius,
445 box_shadow_enable,
446 box_shadow,
447 padding,
448 margin,
449 horizontal_position,
450 vertical_position,
451 box_shadow_enable_hover,
452 box_shadow_hover,
453 display_on,
454 exclude_page,
455 include_only,
456 transition_delay,
457 } = attributes?.options;
458
459 const dynamicStyle = useMemo(() => {
460 return moduleDynamicCss(attributes?.options);
461 }, [attributes?.options]);
462
463 const iconListObj = {
464 "top-arrow-one": <BackToTopArrowOne />,
465 "top-arrow-two": <BackToTopArrowTwo />,
466 "top-arrow-three": <BackToTopArrowThree />,
467 "top-arrow-four": <BackToTopArrowFour />,
468 "top-arrow-five": <BackToTopArrowFive />,
469 };
470
471 const wrapperClass = classNames(
472 "sp-smart-post-back-to-top-wrapper",
473 `sp-position-${display_position}`,
474 `sp-animation-${entrance_animation}`,
475 smooth_scroll && " sp-scroll-smooth"
476 );
477
478 const updateStateHandler = (valueKey, value) => {
479 setSettingsValue({ ...attributes, options: { ...attributes.options, [valueKey]: value } });
480 };
481
482 useEffect(() => {
483 updateStateHandler("dynamic_style", moduleDynamicCss(attributes?.options));
484 // eslint-disable-next-line
485 }, [
486 icon_size,
487 typography,
488 font_size,
489 line_height,
490 letter_spacing,
491 word_spacing,
492 color,
493 background_color,
494 border,
495 border_width,
496 border_radius,
497 box_shadow_enable,
498 box_shadow,
499 padding,
500 margin,
501 display_position,
502 back_to_top_icon,
503 top_icon_source,
504 back_top_label,
505 smooth_scroll,
506 entrance_animation,
507 go_to_bottom,
508 back_bottom_label,
509 fontListsEditPage,
510 horizontal_position,
511 vertical_position,
512 box_shadow_enable_hover,
513 box_shadow_hover,
514 display_on,
515 exclude_page,
516 include_only,
517 transition_delay,
518 ]);
519
520 const googleFontLists = [typography];
521 useEffect(() => {
522 updateStateHandler("fontListsEditPage", googleFonts(googleFontLists));
523 // eslint-disable-next-line
524 }, [typography]);
525
526 return (
527 <>
528 <style>{dynamicStyle}</style>
529 <style>{fontListsEditPage}</style>
530 <div id="sp-smart-post-back-to-top-btn" className={wrapperClass}>
531 <div className="sp-smart-post-back-to-top-content">
532 <div className="sp-smart-post-back-to-top-button">
533 {back_to_top_icon && (
534 <span className="sp-smart-post-back-to-top-icon">{iconListObj[top_icon_source]}</span>
535 )}
536 {back_top_label && (
537 <span className="sp-smart-post-back-to-top-text sp-back-to-top-text">{back_top_label}</span>
538 )}
539 {/* {go_to_bottom && back_bottom_label && (
540 <span className="sp-smart-post-back-to-top-text sp-go-to-bottom-text">
541 {back_bottom_label}
542 </span>
543 )} */}
544 </div>
545 </div>
546 </div>
547 </>
548 );
549 };
550