-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInputField.jsx
More file actions
90 lines (88 loc) · 4.16 KB
/
InputField.jsx
File metadata and controls
90 lines (88 loc) · 4.16 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
83
84
85
86
87
88
89
90
import React from "react";
import ArrowRight from "@surfnet/sds/icons/functional-icons/arrow-right-2.svg";
import {Tooltip} from "@surfnet/sds";
import "./InputField.scss";
import {isEmpty} from "../utils/Utils";
import ClipBoardCopy from "./ClipBoardCopy";
import {validUrlRegExp} from "../validations/regExps";
import {useNavigate} from "react-router-dom";
export default function InputField({
onChange,
name,
value,
placeholder = "",
disabled = false,
toolTip = null,
onBlur = () => true,
onEnter = null,
multiline = false,
copyClipBoard = false,
link = null,
externalLink = false,
large = false,
noInput = false,
error = false,
cols = 5,
maxLength = 255,
onRef = null,
displayLabel = true,
button = null,
isInteger = false
}) {
const navigate = useNavigate();
placeholder = disabled ? "" : placeholder;
let className = "sds--text-field--input";
if (error) {
className += "error ";
}
const validExternalLink = externalLink && !isEmpty(value) && validUrlRegExp.test(value);
return (
<div className={`input-field sds--text-field ${error ? "sds--text-field--status-error" : ""}`}>
{(name && displayLabel) && <label htmlFor={name}>{name}
{toolTip && <Tooltip tip={toolTip}/>}
</label>}
<div className="inner-input-field">
{(!multiline && !noInput) &&
<input type={isInteger ? "number" : "text"}
disabled={disabled}
value={value || ""}
onChange={onChange}
onBlur={onBlur}
maxLength={maxLength}
min={0}
ref={onRef}
placeholder={placeholder}
className={`${className} sds--text-field--input`}
onKeyDown={e => {
if (onEnter && e.keyCode === 13) {//enter
onEnter(e);
}
}}/>}
{(multiline && !noInput) &&
<textarea disabled={disabled}
value={value}
onChange={onChange}
onBlur={onBlur}
className={`${className} sds--text-area ${large ? "large" : ""}`}
onKeyDown={e => {
if (onEnter && e.keyCode === 13) {//enter
onEnter(e);
}
}}
placeholder={placeholder} cols={cols}/>}
{button && button}
{copyClipBoard && <ClipBoardCopy txt={value} right={true} input={true}/>}
{link && <div className="input-field-link" onClick={() => navigate(link)}>
<ArrowRight/>
</div>}
{validExternalLink &&
<div className={`input-field-link`}>
<a href={value} rel="noopener noreferrer" target="_blank">
<ArrowRight/>
</a>
</div>}
{noInput && <span className="no-input">{value}</span>}
</div>
</div>
);
}