tor-browser

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

grip-length-bubble.mjs (1509B)


      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 /* eslint no-shadow: ["error", { "allow": ["length"] }] */
      6 
      7 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs";
      8 import { wrapRender } from "../reps/rep-utils.mjs";
      9 import { MODE } from "../reps/constants.mjs";
     10 import * as dom from "resource://devtools/client/shared/vendor/react-dom-factories.mjs";
     11 
     12 const { span } = dom;
     13 
     14 const ModePropType = PropTypes.oneOf(Object.values(MODE));
     15 
     16 GripLengthBubble.propTypes = {
     17  object: PropTypes.object.isRequired,
     18  maxLengthMap: PropTypes.instanceOf(Map).isRequired,
     19  getLength: PropTypes.func.isRequired,
     20  mode: ModePropType,
     21  visibilityThreshold: PropTypes.number,
     22 };
     23 
     24 function GripLengthBubble(props) {
     25  const {
     26    object,
     27    mode = MODE.SHORT,
     28    visibilityThreshold = 2,
     29    maxLengthMap,
     30    getLength,
     31    showZeroLength = false,
     32  } = props;
     33 
     34  const length = getLength(object);
     35  const isEmpty = length === 0;
     36  const isObvious =
     37    [MODE.SHORT, MODE.LONG].includes(mode) &&
     38    length > 0 &&
     39    length <= maxLengthMap.get(mode) &&
     40    length <= visibilityThreshold;
     41  if ((isEmpty && !showZeroLength) || isObvious) {
     42    return "";
     43  }
     44 
     45  return span(
     46    {
     47      className: "objectLengthBubble",
     48    },
     49    `(${length})`
     50  );
     51 }
     52 
     53 const lengthBubble = wrapRender(GripLengthBubble);
     54 
     55 export { lengthBubble };