summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/components/shared/Dropdown.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/debugger/src/components/shared/Dropdown.js')
-rw-r--r--devtools/client/debugger/src/components/shared/Dropdown.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/components/shared/Dropdown.js b/devtools/client/debugger/src/components/shared/Dropdown.js
new file mode 100644
index 0000000000..7051cec9c5
--- /dev/null
+++ b/devtools/client/debugger/src/components/shared/Dropdown.js
@@ -0,0 +1,71 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import "./Dropdown.css";
+
+export class Dropdown extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ dropdownShown: false,
+ };
+ }
+
+ static get propTypes() {
+ return {
+ icon: PropTypes.node.isRequired,
+ panel: PropTypes.node.isRequired,
+ };
+ }
+
+ toggleDropdown = e => {
+ this.setState(prevState => ({
+ dropdownShown: !prevState.dropdownShown,
+ }));
+ };
+
+ renderPanel() {
+ return (
+ <div
+ className="dropdown"
+ onClick={this.toggleDropdown}
+ style={{ display: this.state.dropdownShown ? "block" : "none" }}
+ >
+ {this.props.panel}
+ </div>
+ );
+ }
+
+ renderButton() {
+ return (
+ <button className="dropdown-button" onClick={this.toggleDropdown}>
+ {this.props.icon}
+ </button>
+ );
+ }
+
+ renderMask() {
+ return (
+ <div
+ className="dropdown-mask"
+ onClick={this.toggleDropdown}
+ style={{ display: this.state.dropdownShown ? "block" : "none" }}
+ />
+ );
+ }
+
+ render() {
+ return (
+ <div className="dropdown-block">
+ {this.renderPanel()}
+ {this.renderButton()}
+ {this.renderMask()}
+ </div>
+ );
+ }
+}
+
+export default Dropdown;