This repository was archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathBlockchainActionSelector.tsx
More file actions
104 lines (96 loc) · 2.3 KB
/
Copy pathBlockchainActionSelector.tsx
File metadata and controls
104 lines (96 loc) · 2.3 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react'
import { useDispatch } from 'react-redux'
import styled from 'styled-components'
import PopperRenderer from 'omg-popper'
import withDropdownState from 'omg-uikit/dropdown/withDropdownState'
import { openModal } from 'omg-modal/action'
import { Icon, Button } from 'omg-uikit'
import { DropdownBox } from 'omg-uikit/dropdown'
const DropdownItem = styled.div`
padding: 7px 10px;
padding-right: 20px;
font-size: 12px;
color: ${props => props.theme.colors.B100};
cursor: pointer;
i,
span {
vertical-align: middle;
display: inline-block;
}
:hover {
color: ${props => props.theme.colors.B400};
}
i {
margin-right: 5px;
}
`
const ButtonStyle = styled(Button)`
margin-left: 10px;
i {
margin-left: 10px;
margin-right: 0 !important;
}
`
interface BlockchainActionSelectorProps {
name: string
onClickButton: React.MouseEventHandler
open: boolean
actions: Array<{
name: string
modal: { id: string; args: {} }
icon: string
}>
fromAddress: string
}
const BlockchainActionSelector = ({
name,
actions,
open,
onClickButton,
fromAddress
}: BlockchainActionSelectorProps) => {
const dispatch = useDispatch()
const renderDropdown = () => {
return (
<DropdownBox>
{actions.map((action, index) => {
const onClick = () =>
dispatch(
openModal({
id: action.modal.id,
fromAddress,
...action.modal.args
})
)
return (
<DropdownItem key={index} onClick={onClick}>
<Icon name={action.icon} />
<span>{action.name}</span>
</DropdownItem>
)
})}
</DropdownBox>
)
}
const renderButton = () => {
return (
<ButtonStyle size="small" styleType="primary" onClick={onClickButton}>
<span>{name}</span>
{open ? <Icon name="Chevron-Up" /> : <Icon name="Chevron-Down" />}
</ButtonStyle>
)
}
return (
<PopperRenderer
offset="0px, 5px"
modifiers={{
flip: { enabled: false },
preventOverflow: { enabled: false }
}}
renderReference={renderButton}
open={open}
renderPopper={renderDropdown}
/>
)
}
export default withDropdownState(BlockchainActionSelector)