IconLabel.js (1449B)
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 { 8 PureComponent, 9 } = require("resource://devtools/client/shared/vendor/react.mjs"); 10 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 12 13 const { 14 ICON_LABEL_LEVEL, 15 } = require("resource://devtools/client/aboutdebugging/src/constants.js"); 16 17 const ICONS = { 18 [ICON_LABEL_LEVEL.INFO]: "chrome://devtools/skin/images/info.svg", 19 [ICON_LABEL_LEVEL.OK]: "chrome://devtools/skin/images/check.svg", 20 }; 21 22 /* This component displays an icon accompanied by some content. It's similar 23 to a message, but it's not interactive */ 24 class IconLabel extends PureComponent { 25 static get propTypes() { 26 return { 27 children: PropTypes.node.isRequired, 28 className: PropTypes.string, 29 level: PropTypes.oneOf(Object.values(ICON_LABEL_LEVEL)).isRequired, 30 }; 31 } 32 33 render() { 34 const { children, className, level } = this.props; 35 return dom.span( 36 { 37 className: `icon-label icon-label--${level} ${className || ""}`, 38 }, 39 dom.img({ 40 className: "icon-label__icon", 41 src: ICONS[level], 42 }), 43 children 44 ); 45 } 46 } 47 48 module.exports = IconLabel;