-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathindex.tsx
144 lines (128 loc) · 3.54 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as React from 'react';
import { FormControl, useFormControlContext } from '@mui/base/FormControl';
import { Input, inputClasses } from '@mui/base/Input';
import { useTheme } from '@mui/system';
import clsx from 'clsx';
export default function BasicFormControl() {
return (
<React.Fragment>
<FormControl defaultValue="" required>
<Label>Name</Label>
<Input placeholder="Write your name here" className="CustomInput" />
<HelperText />
</FormControl>
<Styles />
</React.Fragment>
);
}
const Label = React.forwardRef<
HTMLParagraphElement,
{ className?: string; children?: React.ReactNode }
>(({ className: classNameProp, children }, ref) => {
const formControlContext = useFormControlContext();
const [dirty, setDirty] = React.useState(false);
React.useEffect(() => {
if (formControlContext?.filled) {
setDirty(true);
}
}, [formControlContext]);
if (formControlContext === undefined) {
return <p className={clsx('mb-1 text-sm', classNameProp)}>{children}</p>;
}
const { error, required, filled } = formControlContext;
const showRequiredError = dirty && required && !filled;
return (
<p
ref={ref}
className={clsx(
'mb-1 text-sm',
classNameProp,
error || showRequiredError ? 'invalid text-red-500' : '',
)}
>
{children}
{required ? ' *' : ''}
</p>
);
});
const HelperText = React.forwardRef<HTMLParagraphElement, { className?: string }>(
(props, ref) => {
const { className, ...other } = props;
const formControlContext = useFormControlContext();
const [dirty, setDirty] = React.useState(false);
React.useEffect(() => {
if (formControlContext?.filled) {
setDirty(true);
}
}, [formControlContext]);
if (formControlContext === undefined) {
return null;
}
const { required, filled } = formControlContext;
const showRequiredError = dirty && required && !filled;
return showRequiredError ? (
<p ref={ref} className={clsx('text-sm', className)} {...other}>
This field is required.
</p>
) : null;
},
);
const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
function Styles() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<style>
{`
.CustomInput .${inputClasses.input} {
width: 320px;
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.5;
padding: 8px 12px;
border-radius: 8px;
color: ${isDarkMode ? grey[300] : grey[900]};
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]};
}
.CustomInput .${inputClasses.input}:hover {
border-color: ${cyan[400]};
}
.CustomInput .${inputClasses.input}:focus {
outline: 0;
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]};
}
`}
</style>
);
}