tor-browser

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

MessageIndent.js (1309B)


      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 "use strict";
      6 
      7 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
      8 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
      9 
     10 const INDENT_WIDTH = 12;
     11 
     12 // Store common indents so they can be used without recreating the element during render.
     13 const CONSTANT_INDENTS = [getIndentElement(1)];
     14 const IN_WARNING_GROUP_INDENT = getIndentElement(1, "warning-indent");
     15 
     16 function getIndentElement(indent, className) {
     17  return dom.span({
     18    className: `indent${className ? " " + className : ""}`,
     19    style: {
     20      width: indent * INDENT_WIDTH,
     21    },
     22  });
     23 }
     24 
     25 function MessageIndent(props) {
     26  const { indent, inWarningGroup } = props;
     27 
     28  if (inWarningGroup) {
     29    return IN_WARNING_GROUP_INDENT;
     30  }
     31 
     32  if (!indent) {
     33    return null;
     34  }
     35 
     36  return CONSTANT_INDENTS[indent] || getIndentElement(indent);
     37 }
     38 
     39 MessageIndent.propTypes = {
     40  indent: PropTypes.number,
     41  inWarningGroup: PropTypes.bool,
     42 };
     43 
     44 module.exports.MessageIndent = MessageIndent;
     45 
     46 // Exported so we can test it with unit tests.
     47 module.exports.INDENT_WIDTH = INDENT_WIDTH;