DropdownButton.js
2 KB
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
import React, { useState, useEffect } from 'react';
import { TiArrowSortedDown } from 'react-icons/ti';
import { Menu, MenuItem } from '@mantine/core';
import styled from 'styled-components';
import { dropdownHeaderColorMap } from '../../lib/styles/palette';
const DropDownBlock = styled.div`
margin: 0 auto;
float: ${props => props.float || ''};
`;
const DropDownHeader = styled(Menu)``;
const DropDownWrap = styled.button`
display: flex;
justify-content: space-around;
align-items: center;
color: ${props => dropdownHeaderColorMap[props.color].color};
background-color: ${props => dropdownHeaderColorMap[props.color].background};
cursor: pointer;
&:hover {
background-color: ${props =>
dropdownHeaderColorMap[props.color].hoverBackground};
}
margin-bottom: 0.8em;
width: ${props => props.width || '100px'};
height: ${props => props.height || '30px'};
padding-right: 7%;
font-size: ${props => props.fontsize || '20px'};
border: 1px ${props => dropdownHeaderColorMap[props.color].background};
`;
const DropDown = ({
options,
float,
color = 'blue',
fontsize,
width,
height,
title = '전체',
menuPosition,
size,
}) => {
const [menuTitle, setTitle] = useState('');
useEffect(() => {
setTitle(title);
}, []);
return (
<DropDownBlock float={float} color={color} title={title}>
<DropDownHeader
menuPosition={menuPosition}
size={size}
control={
<DropDownWrap
options={options}
color={color}
fontsize={fontsize}
width={width}
height={height}
>
{menuTitle}
<TiArrowSortedDown />
</DropDownWrap>
}
>
{options.map(friend => (
<MenuItem
value={friend.id}
onClick={() => {
setTitle(friend.name);
}}
>
{friend.name}
</MenuItem>
))}
</DropDownHeader>
</DropDownBlock>
);
};
export default DropDown;