1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/app/components/dropdown.js

93 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-07-18 14:25:16 +02:00
const Component = require('react').Component
const PropTypes = require('react').PropTypes
const h = require('react-hyperscript')
const MenuDroppo = require('menu-droppo')
2017-07-27 00:10:50 +02:00
const extend = require('xtend')
2017-07-18 14:25:16 +02:00
const noop = () => {}
2017-07-13 09:40:00 +02:00
class Dropdown extends Component {
2017-07-18 14:25:16 +02:00
render () {
2017-07-26 22:02:08 +02:00
const { isOpen, onClickOutside, style, innerStyle, children } = this.props
2017-07-13 09:40:00 +02:00
2017-07-27 00:10:50 +02:00
const innerStyleDefaults = extend({
borderRadius: '4px',
padding: '8px 16px',
background: 'rgba(0, 0, 0, 0.8)',
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
}, innerStyle)
2017-07-13 09:40:00 +02:00
return h(
MenuDroppo,
{
isOpen,
zIndex: 11,
onClickOutside,
style,
2017-07-27 00:10:50 +02:00
innerStyle: innerStyleDefaults,
2017-07-13 09:40:00 +02:00
},
2017-07-14 07:39:44 +02:00
[
h(
'style',
`
li.dropdown-menu-item:hover { color:rgb(225, 225, 225); }
li.dropdown-menu-item { color: rgb(185, 185, 185); }
`
),
...children,
2017-07-18 14:25:16 +02:00
]
)
2017-07-13 09:40:00 +02:00
}
}
2017-07-18 14:25:16 +02:00
Dropdown.defaultProps = {
isOpen: false,
onClick: noop,
}
2017-07-13 09:40:00 +02:00
Dropdown.propTypes = {
2017-07-18 14:25:16 +02:00
isOpen: PropTypes.bool.isRequired,
2017-07-13 09:40:00 +02:00
onClick: PropTypes.func.isRequired,
children: PropTypes.node,
2017-07-18 14:25:16 +02:00
style: PropTypes.object.isRequired,
2017-07-13 09:40:00 +02:00
}
class DropdownMenuItem extends Component {
2017-07-18 14:25:16 +02:00
render () {
const { onClick, closeMenu, children } = this.props
2017-07-13 09:40:00 +02:00
return h(
2017-07-14 07:39:44 +02:00
'li.dropdown-menu-item',
2017-07-13 09:40:00 +02:00
{
2017-07-18 14:25:16 +02:00
onClick: () => {
onClick()
closeMenu()
},
2017-07-13 09:40:00 +02:00
style: {
listStyle: 'none',
padding: '8px 0px 8px 0px',
fontSize: '12px',
fontStyle: 'normal',
fontFamily: 'Montserrat Regular',
cursor: 'pointer',
display: 'flex',
justifyContent: 'flex-start',
2017-07-18 14:25:16 +02:00
alignItems: 'center',
2017-07-13 09:40:00 +02:00
},
},
children
2017-07-18 14:25:16 +02:00
)
2017-07-13 09:40:00 +02:00
}
}
DropdownMenuItem.propTypes = {
closeMenu: PropTypes.func.isRequired,
onClick: PropTypes.func.isRequired,
children: PropTypes.node,
2017-07-18 14:25:16 +02:00
}
2017-07-13 09:40:00 +02:00
module.exports = {
Dropdown,
DropdownMenuItem,
2017-07-18 14:25:16 +02:00
}