-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.js
66 lines (61 loc) · 1.61 KB
/
input.js
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
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
/**
* Input
* @param {string} type
* @param {string} placeholder
* @param {string} variant
* @param {bool} disabled
* @param {string} validation
* @param {className} className
*/
const Input = ({
type,
placeholder,
variant,
disabled,
validation,
className,
...restProps
}) => {
const isDisabled = disabled;
const inputVariants = {
text: "font-normal text-sm outline-none focus:outline-none",
contained: `w-full text-gray-800 bg-gray-200 font-normal text-sm px-6 py-3 outline-none focus:outline-none`,
outlined: `w-full bg-transparent text-gray-700 font-normal text-sm px-6 py-3 border-border hover:border-border-hover border-2 outline-none focus:outline-none`
};
return (
<>
<input
type={type || "text"}
placeholder={placeholder}
className={classNames(
inputVariants[variant],
{
"opacity-50 cursor-not-allowed": isDisabled
},
`rounded-md transition ease-in-out duration-150 ${className}`
)}
{...restProps}
/>
{validation && validation.message}
</>
);
};
Input.propTypes = {
type: PropTypes.oneOf(["text", "number", "email", "date", "number", "tel"]),
placeholder: PropTypes.string,
variant: PropTypes.oneOf(["contained", "outlined", "text"]),
disabled: PropTypes.bool,
validation: PropTypes.object,
className: PropTypes.string
};
Input.defaultProps = {
type: "text",
placeholder: "",
variant: "contained",
disabled: false,
validation: {}
};
export default Input;