Bug 1092007 part 2: Treat a flex item's main-size as indefinite if the item and the...
[gecko.git] / devtools / client / responsive / setting-onboarding-tooltip.js
blob21a2f5d7334d369aab8c2e6237e6a50ad1119ca7
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/. */
5 "use strict";
7 const Services = require("Services");
8 const {
9   HTMLTooltip,
10 } = require("devtools/client/shared/widgets/tooltip/HTMLTooltip");
12 const { getStr } = require("./utils/l10n");
14 const SHOW_SETTING_TOOLTIP_PREF = "devtools.responsive.show-setting-tooltip";
16 const CONTAINER_WIDTH = 270;
18 /**
19  * Setting onboarding tooltip that is shown on the setting menu button in the RDM toolbar
20  * when the pref is on.
21  */
22 class SettingOnboardingTooltip {
23   constructor(doc) {
24     this.doc = doc;
25     this.tooltip = new HTMLTooltip(this.doc, {
26       consumeOutsideClicks: false,
27       type: "arrow",
28     });
30     this.onCloseButtonClick = this.onCloseButtonClick.bind(this);
32     const container = doc.createElement("div");
33     container.className = "onboarding-container";
35     const icon = doc.createElement("span");
36     icon.className = "onboarding-icon";
37     container.appendChild(icon);
39     const content = doc.createElement("div");
40     content.className = "onboarding-content";
41     content.textContent = getStr("responsive.settingOnboarding.content");
42     container.appendChild(content);
44     this.closeButton = doc.createElement("button");
45     this.closeButton.className = "onboarding-close-button devtools-button";
46     container.appendChild(this.closeButton);
48     this.closeButton.addEventListener("click", this.onCloseButtonClick);
50     this.tooltip.panel.appendChild(container);
51     this.tooltip.setContentSize({ width: CONTAINER_WIDTH });
52     this.tooltip.show(this.doc.getElementById("settings-button"), {
53       position: "bottom",
54     });
55   }
57   destroy() {
58     this.closeButton.removeEventListener("click", this.onCloseButtonClick);
60     this.tooltip.destroy();
62     this.closeButton = null;
63     this.doc = null;
64     this.tooltip = null;
65   }
67   /**
68    * Handler for the "click" event on the close button. Hides the onboarding tooltip
69    * and sets the show three pane onboarding tooltip pref to false.
70    */
71   onCloseButtonClick() {
72     Services.prefs.setBoolPref(SHOW_SETTING_TOOLTIP_PREF, false);
73     this.tooltip.hide();
74   }
77 module.exports = SettingOnboardingTooltip;