/
Input.js
52 lines (47 loc) · 1.15 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
import React from 'react'
import Box from './Box'
import { get } from '@theme-ui/css'
/** @type {import('theme-ui').ThemeUIStyleObject} */
const autofillStyles = {
boxShadow: 'inset 0 0 0 1000px var(--theme-ui-input-autofill-bg)',
fontSize: 'inherit',
':first-line': {
fontSize: '1rem',
},
}
/** @type {import('theme-ui').ThemeUIStyleObject} */
const defaultInputStyles = {
display: 'block',
width: '100%',
p: 2,
appearance: 'none',
fontSize: 'inherit',
lineHeight: 'inherit',
border: '1px solid',
borderRadius: 4,
color: 'inherit',
bg: 'transparent',
':autofill, :autofill:hover, :autofill:focus': autofillStyles,
':-webkit-autofill, :-webkit-autofill:hover, :-webkit-autofill:focus':
autofillStyles,
}
export const Input = React.forwardRef(function Input(
{ sx, autofillBackgroundColor = 'background', ...rest },
ref
) {
return (
<Box
ref={ref}
as="input"
variant="input"
sx={{
'--theme-ui-input-autofill-bg': (theme) =>
get(theme.colors, autofillBackgroundColor, null),
...sx,
}}
{...rest}
__themeKey="forms"
__css={defaultInputStyles}
/>
)
})