-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathSelect.js
57 lines (48 loc) · 1.24 KB
/
Select.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
import React from 'react';
import styled from 'styled-components';
import { COLORS } from '../../constants';
import Icon from '../Icon';
import { getDisplayedValue } from './Select.helpers';
const InternalSelect = styled.select`
appearance: none;
padding: 12px 52px 12px 16px;
color: ${COLORS.gray700};
&:hover {
color: ${COLORS.black};
}
width: ${p => p.displayedValue.length * 8 + 68 - 8}px;
background-color: ${COLORS.transparentGray15};
border-radius: 8px;
`
const Wrapper = styled.div`
position: relative;
color: ${COLORS.gray700};
&:hover {
color: ${COLORS.black};
${InternalSelect} {
color: ${COLORS.black};
}
}
`
const IconWrapper = styled(Icon)`
position: absolute;
top: 8px;
left: ${p => p.displayedValue.length * 8 + 24}px;
pointer-events: none;
`
const Select = ({ label, value, onChange, children }) => {
const displayedValue = getDisplayedValue(value, children);
return (
<Wrapper>
<InternalSelect
aria-label={label}
displayedValue={displayedValue}
value={value}
onChange={onChange}>
{children}
</InternalSelect>
<IconWrapper displayedValue={displayedValue} id={"chevron-down"} />
</Wrapper>
);
};
export default Select;