PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.4
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.4
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 / selectField / selectField.js

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

76 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { SelectControl } from "@wordpress/components";
2 import "./editor.scss";
3 import { memo } from "@wordpress/element";
4 import { useDeviceType } from "../../controls/controls";
5 import Responsive from "../responsive/responsive";
6
7 const SelectField = ({
8 attributes,
9 attributesKey,
10 setAttributes,
11 label,
12 items,
13 flexStyle = false,
14 onChange = false,
15 value = false,
16 defaultOption = false,
17 extraClassName = "",
18 pro = false,
19 }) => {
20 // Device check fn
21 const deviceType = useDeviceType();
22 // Set Button value
23 const setNewValue = (newValue) => {
24 if (attributes?.device) {
25 setAttributes({
26 [attributesKey]: {
27 device: { ...attributes?.device, [deviceType]: newValue },
28 },
29 });
30 } else {
31 setAttributes({ [attributesKey]: newValue });
32 }
33 };
34
35 // Get active button value
36 const activeValue = attributes?.device ? attributes?.device?.[deviceType] : attributes;
37
38 let selectItems = [];
39 if (defaultOption) {
40 selectItems = [{ label: "Default", value: "" }, ...items];
41 } else {
42 selectItems = items;
43 }
44
45 return (
46 <div
47 className={`sp-smart-post-select-field sp-smart-post-component-mb ${
48 flexStyle ? "sp-smart-post-d-flex" : "sp-smart-post-d-block"
49 }${extraClassName}${pro ? " sp-is-pro" : ""}`}
50 >
51 <div className="sp-smart-post-header">
52 <span
53 className={
54 attributes?.device ? "sp-smart-post-select-component-title" : "sp-smart-post-component-title"
55 }
56 >
57 {" "}
58 {label}
59 {pro && <a target="_blank" href="https://wpsmartpost.com/pricing/?ref=1" className="sp-smart-pro-text"> (Pro) </a>}
60 </span>
61 {attributes?.device && <Responsive />}
62 </div>
63 <SelectControl
64 className="custom-select-control"
65 value={value ? value : activeValue}
66 options={selectItems}
67 onChange={(newField) => (onChange ? onChange(newField) : setNewValue(newField))}
68 __nextHasNoMarginBottom
69 __next40pxDefaultSize
70 />
71 </div>
72 );
73 };
74
75 export default memo(SelectField);
76