tor-browser

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

SourceIcon.js (1534B)


      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 
      8 import { connect } from "devtools/client/shared/vendor/react-redux";
      9 
     10 import DebuggerImage from "./DebuggerImage";
     11 
     12 import { getSourceClassnames } from "../../utils/source";
     13 import { isSourceBlackBoxed } from "../../selectors/index";
     14 
     15 class SourceIcon extends PureComponent {
     16  static get propTypes() {
     17    return {
     18      modifier: PropTypes.func,
     19      location: PropTypes.object.isRequired,
     20      iconName: PropTypes.string,
     21    };
     22  }
     23 
     24  render() {
     25    const { modifier } = this.props;
     26    let { iconName } = this.props;
     27 
     28    if (modifier) {
     29      const modified = modifier(iconName);
     30      if (!modified) {
     31        return null;
     32      }
     33      iconName = modified;
     34    }
     35    return React.createElement(DebuggerImage, {
     36      name: iconName,
     37      className: "source-icon",
     38    });
     39  }
     40 }
     41 
     42 export default connect((state, props) => {
     43  const { location } = props;
     44  const isBlackBoxed = isSourceBlackBoxed(state, location.source);
     45 
     46  // This is the key function that will compute the icon type,
     47  // In addition to the "modifier" implemented by each callsite.
     48  const iconName = getSourceClassnames(location.source, isBlackBoxed);
     49 
     50  return {
     51    iconName,
     52  };
     53 })(SourceIcon);