tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PaneToggleButton.js (1752B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 import React, { PureComponent } from "devtools/client/shared/vendor/react";
      6 import PropTypes from "devtools/client/shared/vendor/react-prop-types";
      7 import DebuggerImage from "../DebuggerImage";
      8 import { CommandBarButton } from "./index";
      9 
     10 const classnames = require("resource://devtools/client/shared/classnames.js");
     11 
     12 class PaneToggleButton extends PureComponent {
     13  static defaultProps = {
     14    horizontal: false,
     15    position: "start",
     16  };
     17 
     18  static get propTypes() {
     19    return {
     20      collapsed: PropTypes.bool.isRequired,
     21      handleClick: PropTypes.func.isRequired,
     22      horizontal: PropTypes.bool.isRequired,
     23      position: PropTypes.oneOf(["start", "end"]).isRequired,
     24    };
     25  }
     26 
     27  label(position, collapsed) {
     28    switch (position) {
     29      case "start":
     30        return L10N.getStr(collapsed ? "expandSources" : "collapseSources");
     31      case "end":
     32        return L10N.getStr(
     33          collapsed ? "expandBreakpoints" : "collapseBreakpoints"
     34        );
     35    }
     36    return null;
     37  }
     38 
     39  render() {
     40    const { position, collapsed, horizontal, handleClick } = this.props;
     41    return React.createElement(
     42      CommandBarButton,
     43      {
     44        className: classnames("toggle-button", position, {
     45          collapsed,
     46          vertical: !horizontal,
     47        }),
     48        onClick: () => handleClick(position, !collapsed),
     49        title: this.label(position, collapsed),
     50      },
     51      React.createElement(DebuggerImage, {
     52        name: collapsed ? "pane-expand" : "pane-collapse",
     53      })
     54    );
     55  }
     56 }
     57 
     58 export default PaneToggleButton;