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 / utility / index.js

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

81 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { memo } from "@wordpress/element";
2 import { Button } from "@wordpress/components";
3 import { ResetIcon } from "../../icons/icons";
4 import { useDeviceType } from "../../controls/controls";
5
6 export const Units = memo(({ attributes, setAttributes, attributesKey, units, onUnitChange }) => {
7 const deviceType = useDeviceType();
8 // Set unit function.
9 const setUnit = (newValue) => {
10 if (onUnitChange) {
11 onUnitChange(newValue);
12 return;
13 }
14 if (attributes.unit?.[deviceType]) {
15 setAttributes({
16 [attributesKey]: {
17 ...attributes,
18 unit: {
19 ...attributes.unit,
20 [deviceType]: newValue.toLowerCase(),
21 },
22 },
23 });
24 } else {
25 setAttributes({
26 [attributesKey]: {
27 ...attributes,
28 unit: newValue.toLowerCase(),
29 },
30 });
31 }
32 };
33
34 const unit = "object" === typeof attributes?.unit ? attributes.unit?.[deviceType] : attributes?.unit;
35
36 return (
37 <div className="sp-smart-post-units">
38 <span className="sp-smart-post-units-indicator-label">{unit}</span>
39 <div className="sp-smart-post-units-btn">
40 {units?.map((item, i) => (
41 <Button
42 className={unit === item.toLowerCase() ? "active" : ""}
43 key={i}
44 value={item}
45 onClick={(e) => setUnit(e.target.value)}
46 >
47 {" "}
48 {item}{" "}
49 </Button>
50 ))}
51 </div>
52 </div>
53 );
54 });
55
56 export const ResetButton = memo(({ onClick }) => {
57 return (
58 <Button className="sp-smart-post-header-control-reset" onClick={onClick}>
59 <ResetIcon />
60 </Button>
61 );
62 });
63
64 export const SpLinkedButton = ({ attributes, attributesKey, setAttributes, Icon, updateAllChange }) => {
65 const linked = attributes?.allChange || false;
66 return (
67 <div
68 className={`sp-link-btn${linked ? "" : " active"}`}
69 onClick={() =>
70 updateAllChange
71 ? updateAllChange(!linked)
72 : setAttributes({
73 [attributesKey]: { ...attributes, allChange: !linked },
74 })
75 }
76 >
77 <span className="sp-link-side-icon">{Icon}</span>
78 </div>
79 );
80 };
81