Files
firefox/devtools/client/webconsole/components/MessageIcon.js
T
Nicolas Chevobbe 1de75c386e Bug 1498531 - Localize Webconsole WebReplay Jump icon; r=loganfsmyth,Honza.
This patch adds localization for the WebReplay Jump icon, and uses
the same terminology as the one used in the context menu that triggers
the same action.
The Jump button was used in-place of the existing level icons (Error, Warning, …),
and was only displayed when the message was hovered. We now ensure the
level icon is always visible and that we only show the Jump icon when the
message is hovered.
Finally, the button was styled targeting the title attribute in CSS, which
seemed a little brittle. We now use a dedicated class which should
be safer and more future proof.

Differential Revision: https://phabricator.services.mozilla.com/D8533
2018-10-22 05:26:33 +00:00

60 lines
1.7 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* 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 PropTypes = require("devtools/client/shared/vendor/react-prop-types");
const dom = require("devtools/client/shared/vendor/react-dom-factories");
const {l10n} = require("devtools/client/webconsole/utils/messages");
const l10nLevels = {
"error": "level.error",
"warn": "level.warn",
"info": "level.info",
"log": "level.log",
"debug": "level.debug",
};
// Store common icons so they can be used without recreating the element
// during render.
const CONSTANT_ICONS = Object.entries(l10nLevels).reduce((acc, [key, l10nLabel]) => {
acc[key] = getIconElement(l10nLabel);
return acc;
}, {});
function getIconElement(level, onRewindClick) {
let title = l10n.getStr(l10nLevels[level] || level);
const classnames = ["icon"];
if (onRewindClick) {
title = l10n.getFormatStr("webconsole.jumpButton.tooltip", [title]);
classnames.push("rewindable");
}
return dom.span({
className: classnames.join(" "),
onClick: onRewindClick,
title,
"aria-live": "off",
});
}
MessageIcon.displayName = "MessageIcon";
MessageIcon.propTypes = {
level: PropTypes.string.isRequired,
onRewindClick: PropTypes.function,
};
function MessageIcon(props) {
const { level, onRewindClick } = props;
return onRewindClick
? getIconElement(level, onRewindClick)
: CONSTANT_ICONS[level] || getIconElement(level);
}
module.exports = MessageIcon;