-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathConfigDropdown.tsx
More file actions
82 lines (76 loc) · 2.2 KB
/
Copy pathConfigDropdown.tsx
File metadata and controls
82 lines (76 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { useState } from "react";
import { ConfigWrapper } from "./ConfigComponents";
import ConfigItemTitle from "./ConfigItemTitle";
import Icon from "@components/Icon";
import Markdown from "../shared/Markdown";
import { isEmpty } from "lodash";
const ConfigDropdown = (props) => {
const [selectedValue, setSelectedValue] = useState(
props.value || props.default || ""
);
let options = [{ value: "", label: "Select an option" }];
props.items.map((item) => {
if (isEmpty(item)) {
return null;
}
options.push({ value: item.name, label: item.title });
});
const handleChange = (val) => {
setSelectedValue(val);
props.handleOnChange(props.name, val);
};
var hidden = props.hidden || props.when === "false";
return (
<ConfigWrapper
id={`${props.name}-group`}
className={`field-type-dropdown`}
marginTop={hidden || props.affix ? "0" : "15px"}
hidden={hidden}
>
{props.title !== "" ? (
<ConfigItemTitle
title={props.title}
recommended={props.recommended}
required={props.required}
name={props.name}
error={props.error}
/>
) : null}
{props.help_text !== "" ? (
<div className="field-section-help-text help-text-color">
<Markdown
options={{
linkTarget: "_blank",
linkify: true,
}}
>
{props.help_text}
</Markdown>
</div>
) : null}
<select
className="Input tw-mt-4"
value={selectedValue}
onChange={(e) => handleChange(e.target.value)}
>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
{props.repeatable && (
<div
className="u-marginTop--10"
onClick={() => props.handleAddItem(props.name)}
>
<span className="add-btn u-fontSize--small u-fontWeight--bold link">
<Icon icon="plus" size={14} className="clickable" />
Add another {props.title}
</span>
</div>
)}
</ConfigWrapper>
);
};
export default ConfigDropdown;