-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathIconInput.js
73 lines (65 loc) · 1.58 KB
/
IconInput.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
67
68
69
70
71
72
73
import React from "react";
import styled from "styled-components";
import { COLORS } from "../../constants";
import Icon from "../Icon";
import VisuallyHidden from "../VisuallyHidden";
const SIZES = {
small: {
iconSize: 16 + "px",
"--textOffset": 16 + 8 + "px",
"--height": 24 + "px",
"--iconTopOffset": (24 - 16) / 2 + "px",
"--fontSize": 1 + "em",
},
large: {
iconSize: 24 + "px",
"--textOffset": 24 + 8 + "px",
"--height": 36 + "px",
"--iconTopOffset": (36 - 24) / 2 + "px",
"--fontSize": 1.3125 + "em",
},
};
const Input = styled.input`
appearance: none;
border: none;
border-bottom: 1px solid ${COLORS.black};
width: ${(p) => p.width}px;
height: var(--height);
padding-left: var(--textOffset);
outline-offset: 2px;
font-size: var(--fontSize);
font-weight: 700;
color: ${COLORS.gray700};
&::placeholder {
color: ${COLORS.gray500};
font-weight: 400;
}
`;
const IconWrapper = styled(Icon)`
position: absolute;
left: 0;
top: var(--iconTopOffset);
pointer-events: none;
color: ${COLORS.gray700};
`;
const Wrapper = styled.div`
position: relative;
:hover {
${IconWrapper}, ${Input} {
color: ${COLORS.black};
}
}
`;
const IconInput = ({ label, icon, width = 250, size, placeholder }) => {
const styles = SIZES[size];
return (
<>
<Wrapper>
{icon && <IconWrapper style={styles} size={styles.iconSize} id={icon} />}
<Input width={width} style={styles} placeholder={placeholder} />
</Wrapper>
<VisuallyHidden>{label}</VisuallyHidden>
</>
);
};
export default IconInput;