summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/src/components/manifest/ManifestIconItem.js
blob: a525fbcdb9c99034157a4a28dc2f49ac6d33cd8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const {
  createFactory,
  PureComponent,
} = require("resource://devtools/client/shared/vendor/react.js");
const {
  br,
  code,
  img,
  span,
} = require("resource://devtools/client/shared/vendor/react-dom-factories.js");

const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
const Localized = createFactory(FluentReact.Localized);
const {
  l10n,
} = require("resource://devtools/client/application/src/modules/l10n.js");

const Types = require("resource://devtools/client/application/src/types/index.js");
const ManifestItem = createFactory(
  require("resource://devtools/client/application/src/components/manifest/ManifestItem.js")
);

/**
 * This component displays a Manifest member which holds a color value
 */
class ManifestIconItem extends PureComponent {
  static get propTypes() {
    return {
      // {
      //   label: { contentType, sizes },
      //   value: { src, purpose }
      // }
      ...Types.manifestItemIcon,
    };
  }

  getLocalizedImgTitle() {
    const { sizes } = this.props.label;

    return sizes && sizes.length
      ? l10n.getString("manifest-icon-img-title", { sizes })
      : l10n.getString("manifest-icon-img-title-no-sizes");
  }

  renderLabel() {
    const { contentType, sizes } = this.props.label;

    // sinze both `contentType` and `sizes` may be undefined, we don't need to
    // render the <br> if one –or both– are not to be displayed
    const shallRenderBr = contentType && sizes;

    return [
      sizes ? sizes : null,
      shallRenderBr ? br({ key: "label-br" }) : null,
      contentType ? contentType : null,
    ];
  }

  render() {
    const { src, purpose } = this.props.value;

    return ManifestItem(
      {
        label: this.renderLabel(),
      },
      Localized(
        {
          id: "manifest-icon-img",
          attrs: {
            alt: true,
          },
        },
        img({
          className: "manifest-item__icon",
          src,
          title: this.getLocalizedImgTitle(),
        })
      ),
      br({}),
      Localized(
        {
          id: "manifest-icon-purpose",
          code: code({}),
          $purpose: purpose,
        },
        span({})
      )
    );
  }
}

module.exports = ManifestIconItem;