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

99 lines
2.2 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 () {
const { isOpen, onClickOutside, style, innerStyle, children, useCssTransition } = 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,
{
useCssTransition,
2017-07-13 09:40:00 +02:00
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); }
2017-08-10 02:40:01 +02:00
li.dropdown-menu-item { color: rgb(185, 185, 185); position: relative }
2017-07-14 07:39:44 +02:00
`
),
...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,
useCssTransition: false,
2017-07-18 14:25:16 +02:00
}
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-10-02 20:08:34 +02:00
onClickOutside: PropTypes.func,
innerStyle: PropTypes.object,
useCssTransition: PropTypes.bool,
2017-07-13 09:40:00 +02:00
}
class DropdownMenuItem extends Component {
2017-07-18 14:25:16 +02:00
render () {
2017-08-04 03:50:29 +02:00
const { onClick, closeMenu, children, style } = 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()
},
style: Object.assign({
2017-07-13 09:40:00 +02:00
listStyle: 'none',
padding: '8px 0px 8px 0px',
fontSize: '18px',
2017-07-13 09:40:00 +02:00
fontStyle: 'normal',
fontFamily: 'Montserrat Regular',
cursor: 'pointer',
display: 'flex',
justifyContent: 'flex-start',
2017-07-18 14:25:16 +02:00
alignItems: 'center',
}, style),
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-10-02 20:08:34 +02:00
style: PropTypes.object,
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
}