/* 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 { Component, createFactory, } = require("resource://devtools/client/shared/vendor/react.js"); const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js"); const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); const { LocalizationHelper } = require("resource://devtools/shared/l10n.js"); const l10n = new LocalizationHelper( "devtools/client/locales/components.properties" ); const { div, span, button } = dom; loader.lazyGetter(this, "MDNLink", function () { return createFactory( require("resource://devtools/client/shared/components/MdnLink.js") ); }); // Priority Levels const PriorityLevels = { PRIORITY_INFO_LOW: 1, PRIORITY_INFO_MEDIUM: 2, PRIORITY_INFO_HIGH: 3, // Type NEW should be used to highlight new features, and should be more // eye-catchy than INFO level notifications. PRIORITY_NEW: 4, PRIORITY_WARNING_LOW: 5, PRIORITY_WARNING_MEDIUM: 6, PRIORITY_WARNING_HIGH: 7, PRIORITY_CRITICAL_LOW: 8, PRIORITY_CRITICAL_MEDIUM: 9, PRIORITY_CRITICAL_HIGH: 10, PRIORITY_CRITICAL_BLOCK: 11, }; /** * This component represents Notification Box - HTML alternative for * binding. * * See also MDN for more info about : * https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/notificationbox * * This component can maintain its own state (list of notifications) * as well as consume list of notifications provided as a prop * (coming e.g. from Redux store). */ class NotificationBox extends Component { static get propTypes() { return { // Optional box ID (used for mounted node ID attribute) id: PropTypes.string, /** * List of notifications appended into the box. Each item of the map is an object * of the following shape: * - {String} label: Label to appear on the notification. * - {String} value: Value used to identify the notification. Should be the same * as the map key used for this notification. * - {String} image: URL of image to appear on the notification. If "" then an * appropriate icon for the priority level is used. * - {Number} priority: Notification priority; see Priority Levels. * - {Function} eventCallback: A function to call to notify you of interesting things that happen with the notification box. - {String} type: One of "info", "warning", or "critical" used to determine what styling and icon are used for the notification. * - {Array} buttons: Array of button descriptions to appear on the * notification. Should be of the following shape: * - {Function} callback: This function is passed 3 arguments: 1) the NotificationBox component the button is associated with. 2) the button description as passed to appendNotification. 3) the element which was the target of the button press event. If the return value from this function is not true, then the notification is closed. The notification is also not closed if an error is thrown. - {String} label: The label to appear on the button. - {String} accesskey: The accesskey attribute set on the