1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/ui/components/app/dropdowns/dropdown.js

108 lines
2.4 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import MenuDroppo from '../menu-droppo';
2017-07-18 14:25:16 +02:00
export class Dropdown extends Component {
2020-11-03 00:41:28 +01:00
render() {
2017-09-05 00:55:14 +02:00
const {
containerClassName,
isOpen,
onClickOutside,
style,
innerStyle,
children,
useCssTransition,
} = this.props;
2017-07-13 09:40:00 +02:00
const innerStyleDefaults = {
2017-07-27 00:10:50 +02:00
borderRadius: '4px',
padding: '8px 16px',
background: 'rgba(0, 0, 0, 0.8)',
2020-11-03 00:41:28 +01:00
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
...innerStyle,
};
2017-07-27 00:10:50 +02:00
return (
<MenuDroppo
containerClassName={containerClassName}
useCssTransition={useCssTransition}
isOpen={isOpen}
zIndex={55}
onClickOutside={onClickOutside}
style={style}
innerStyle={innerStyleDefaults}
>
<style>
{`
li.dropdown-menu-item:hover {
color:rgb(225, 225, 225);
background-color: rgba(255, 255, 255, 0.05);
border-radius: 4px;
}
li.dropdown-menu-item { color: rgb(185, 185, 185); }
`}
</style>
2020-11-03 00:41:28 +01:00
{children}
</MenuDroppo>
);
2017-07-13 09:40:00 +02:00
}
}
2017-07-18 14:25:16 +02:00
Dropdown.defaultProps = {
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
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-11-02 03:30:33 +01:00
containerClassName: PropTypes.string,
};
2017-07-13 09:40:00 +02:00
export class DropdownMenuItem extends Component {
2020-11-03 00:41:28 +01:00
render() {
const { onClick, closeMenu, children, style } = this.props;
2017-07-13 09:40:00 +02:00
return (
<li
className="dropdown-menu-item"
onClick={() => {
onClick();
closeMenu();
}}
onKeyPress={(event) => {
if (event.key === 'Enter') {
onClick();
closeMenu();
}
}}
2020-11-03 00:41:28 +01:00
style={{
2017-07-13 09:40:00 +02:00
listStyle: 'none',
padding: '8px 0px',
fontSize: '18px',
2017-07-13 09:40:00 +02:00
fontStyle: 'normal',
cursor: 'pointer',
display: 'flex',
justifyContent: 'flex-start',
2017-07-18 14:25:16 +02:00
alignItems: 'center',
2020-11-03 00:41:28 +01:00
color: 'white',
...style,
}}
tabIndex="0"
>
{children}
</li>
);
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,
};