-
Notifications
You must be signed in to change notification settings - Fork 2
/
Textfield.tsx
94 lines (90 loc) · 1.91 KB
/
Textfield.tsx
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
91
92
93
94
import { TextField as MuiTextfield } from '@mui/material';
import './textfield.css';
type TextfieldProps = {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: 'outlined' | 'filled';
/**
* If `true`, the component is disabled.
* @default false
*/
disabled?: boolean;
/**
* If `true`, the label is displayed in an error state.
* @default false
*/
error?: boolean;
/**
* If `true`, the input will take up the full width of its container.
* @default false
*/
fullWidth?: boolean;
/**
* The helper text content.
*/
helperText?: string;
/**
* The label content.
*/
label?: string;
/**
* The short hint displayed in the `input` before the user enters a value.
*/
placeholder?: string;
/**
* If `true`, the label is displayed as required and the `input` element is required.
* @default false
*/
required?: boolean;
/**
* Additional css classes to help with unique styling of the button
*/
className?: string[];
/**
* Triggers when content of textfield is changed
*/
onChange?: () => void;
/**
* Triggers when textfield gets focus
*/
onFocus?: () => void;
/**
* Triggers when textfield loses focus
*/
onBlur?: () => void;
};
function Textfield({
variant = 'outlined',
disabled = false,
error = false,
fullWidth = false,
helperText,
label,
placeholder,
required = false,
className,
onChange,
onFocus,
onBlur,
}: TextfieldProps) {
const classNameString = className?.join(' ') ?? '';
return (
<MuiTextfield
variant={variant}
disabled={disabled}
error={error}
fullWidth={fullWidth}
helperText={helperText}
label={label}
placeholder={placeholder}
required={required}
className={['papi-textfield', classNameString].join(' ')}
onChange={onChange}
onFocus={onFocus}
onBlur={onBlur}
/>
);
}
export default Textfield;