tor-browser

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

Badges.js (2125B)


      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 "use strict";
      5 
      6 // React
      7 const {
      8  Component,
      9  createFactory,
     10 } = require("resource://devtools/client/shared/vendor/react.mjs");
     11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     12 const {
     13  span,
     14 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     15 
     16 const {
     17  L10N,
     18 } = require("resource://devtools/client/accessibility/utils/l10n.js");
     19 
     20 const {
     21  accessibility: { AUDIT_TYPE },
     22 } = require("resource://devtools/shared/constants.js");
     23 
     24 loader.lazyGetter(this, "ContrastBadge", () =>
     25  createFactory(
     26    require("resource://devtools/client/accessibility/components/ContrastBadge.js")
     27  )
     28 );
     29 
     30 loader.lazyGetter(this, "KeyboardBadge", () =>
     31  createFactory(
     32    require("resource://devtools/client/accessibility/components/KeyboardBadge.js")
     33  )
     34 );
     35 
     36 loader.lazyGetter(this, "TextLabelBadge", () =>
     37  createFactory(
     38    require("resource://devtools/client/accessibility/components/TextLabelBadge.js")
     39  )
     40 );
     41 
     42 function getComponentForAuditType(type) {
     43  const auditTypeToComponentMap = {
     44    [AUDIT_TYPE.CONTRAST]: ContrastBadge,
     45    [AUDIT_TYPE.KEYBOARD]: KeyboardBadge,
     46    [AUDIT_TYPE.TEXT_LABEL]: TextLabelBadge,
     47  };
     48 
     49  return auditTypeToComponentMap[type];
     50 }
     51 
     52 class Badges extends Component {
     53  static get propTypes() {
     54    return {
     55      checks: PropTypes.object,
     56    };
     57  }
     58 
     59  render() {
     60    const { checks } = this.props;
     61    if (!checks) {
     62      return null;
     63    }
     64 
     65    const items = [];
     66    for (const type in checks) {
     67      const component = getComponentForAuditType(type);
     68      if (checks[type] && component) {
     69        items.push(component({ key: type, ...checks[type] }));
     70      }
     71    }
     72 
     73    if (items.length === 0) {
     74      return null;
     75    }
     76 
     77    return span(
     78      {
     79        className: "badges",
     80        role: "group",
     81        "aria-label": L10N.getStr("accessibility.badges"),
     82      },
     83      items
     84    );
     85  }
     86 }
     87 
     88 module.exports = Badges;