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/. */
9 } from "chrome://global/content/vendor/lit.all.mjs";
10 import { MozLitElement } from "chrome://global/content/lit-utils.mjs";
11 import { navigateToLink } from "chrome://browser/content/firefoxview/helpers.mjs";
14 * An empty state card to be used throughout Firefox View
16 * @property {string} headerLabel - (Optional) The l10n id for the header text for the empty/error state
17 * @property {object} headerArgs - (Optional) The l10n args for the header text for the empty/error state
18 * @property {string} isInnerCard - (Optional) True if the card is displayed within another card and needs a border instead of box shadow
19 * @property {boolean} isSelectedTab - (Optional) True if the component is the selected navigation tab - defaults to false
20 * @property {Array} descriptionLabels - (Optional) An array of l10n ids for the secondary description text for the empty/error state
21 * @property {object} descriptionLink - (Optional) An object describing the l10n name and url needed within a description label
22 * @property {string} mainImageUrl - (Optional) The chrome:// url for the main image of the empty/error state
23 * @property {string} errorGrayscale - (Optional) The image should be shown in gray scale
24 * @property {boolean} openLinkInParentWindow - (Optional) The link, when clicked, should be opened programatically in the parent window.
26 class FxviewEmptyState extends MozLitElement {
29 this.isSelectedTab = false;
30 this.descriptionLabels = [];
35 headerLabel: { type: String },
36 headerArgs: { type: Object },
37 isInnerCard: { type: Boolean },
38 isSelectedTab: { type: Boolean },
39 descriptionLabels: { type: Array },
40 desciptionLink: { type: Object },
41 mainImageUrl: { type: String },
42 errorGrayscale: { type: Boolean },
43 openLinkInParentWindow: { type: Boolean },
48 descriptionEls: { all: ".description" },
51 linkTemplate(descriptionLink) {
52 if (!descriptionLink) {
56 data-l10n-name=${descriptionLink.name}
57 href=${descriptionLink.url}
58 target=${descriptionLink?.sameTarget ? "_self" : "_blank"}
66 href="chrome://browser/content/firefoxview/fxview-empty-state.css"
71 ?isInnerCard="${this.isInnerCard}"
75 aria-labelledby="header"
76 aria-describedby="description"
82 selectedTab: this.isSelectedTab,
83 imageHidden: !this.mainImageUrl,
86 <div class="image-container" part="image-container">
90 greyscale: this.errorGrayscale,
95 ?hidden=${!this.mainImageUrl}
96 src=${this.mainImageUrl}
99 <div class="main" part="main">
103 class="header heading-large"
104 ?hidden=${!this.headerLabel}
107 data-l10n-id="${this.headerLabel}"
108 data-l10n-args="${JSON.stringify(this.headerArgs)}"
112 <span id="description">
114 this.descriptionLabels,
115 descLabel => descLabel,
116 (descLabel, index) =>
120 secondary: index !== 0,
122 data-l10n-id="${descLabel}"
123 @click=${this.openLinkInParentWindow &&
124 this.linkActionHandler}
125 @keydown=${this.openLinkInParentWindow &&
126 this.linkActionHandler}
128 ${this.linkTemplate(this.descriptionLink)}
132 <slot name="primary-action"></slot>
139 linkActionHandler(e) {
140 const shouldNavigate =
141 (e.type == "click" && !e.altKey) ||
142 (e.type == "keydown" && e.code == "Enter") ||
143 (e.type == "keydown" && e.code == "Space");
144 if (shouldNavigate && e.target.href) {
145 navigateToLink(e, e.target.href);
150 customElements.define("fxview-empty-state", FxviewEmptyState);