mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
66 lines
1.1 KiB
JavaScript
66 lines
1.1 KiB
JavaScript
import React, {Component, PropTypes} from 'react'
|
|
import classnames from 'classnames'
|
|
|
|
import Mousetrap from '../../lib/mousetrap'
|
|
|
|
class Dropdown extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
open: false
|
|
};
|
|
}
|
|
|
|
_handleClick(e) {
|
|
e.preventDefault();
|
|
|
|
this.toggle();
|
|
}
|
|
|
|
hide() {
|
|
Mousetrap.unbind('esc');
|
|
this.setState({open: false});
|
|
}
|
|
|
|
show() {
|
|
Mousetrap.bind('esc', () => {
|
|
this.hide();
|
|
});
|
|
|
|
this.setState({open: true});
|
|
}
|
|
|
|
toggle() {
|
|
if (this.state.open) {
|
|
this.hide();
|
|
} else {
|
|
this.show();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const className = classnames(
|
|
'dropdown',
|
|
this.props.className,
|
|
{'dropdown--open': this.state.open},
|
|
{'dropdown--right': this.props.right}
|
|
);
|
|
|
|
return (
|
|
<div
|
|
className={className}
|
|
onClick={this._handleClick.bind(this)}>
|
|
|
|
{this.props.children}
|
|
<div className="dropdown__backdrop"></div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
Dropdown.propTypes = {
|
|
right: PropTypes.bool
|
|
};
|
|
|
|
export default Dropdown;
|