From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- browser/components/firefoxview/card-container.mjs | 93 +++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 browser/components/firefoxview/card-container.mjs (limited to 'browser/components/firefoxview/card-container.mjs') diff --git a/browser/components/firefoxview/card-container.mjs b/browser/components/firefoxview/card-container.mjs new file mode 100644 index 0000000000..6d2fa0c600 --- /dev/null +++ b/browser/components/firefoxview/card-container.mjs @@ -0,0 +1,93 @@ +/* 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/. */ + +import { html, ifDefined } from "chrome://global/content/vendor/lit.all.mjs"; +import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; + +/** + * A collapsible card container to be used throughout Firefox View + * + * @property {string} sectionLabel - The aria-label used for the section landmark if the header is hidden with hideHeader + * @property {boolean} hideHeader - Optional property given if the card container should not display a header + * @property {boolean} preserveCollapseState - Whether or not the expanded/collapsed state should persist + * @property {string} viewAllPage - The location hash for the 'View all' header link to navigate to + */ +class CardContainer extends MozLitElement { + constructor() { + super(); + this.isExpanded = true; + } + + static properties = { + sectionLabel: { type: String }, + hideHeader: { type: Boolean }, + preserveCollapseState: { type: Boolean }, + viewAllPage: { type: String }, + }; + + static queries = { + detailsEl: "details", + summaryEl: "summary", + viewAllLink: ".view-all-link", + }; + + get detailsExpanded() { + return this.detailsEl.hasAttribute("open"); + } + + connectedCallback() { + super.connectedCallback(); + if (this.preserveCollapseState && this.viewAllPage) { + this.openStatePref = `browser.tabs.firefox-view.ui-state.${this.viewAllPage}.open`; + this.isExpanded = Services.prefs.getBoolPref(this.openStatePref, true); + } + } + + disconnectedCallback() {} + + onToggleContainer() { + this.isExpanded = this.detailsExpanded; + if (this.preserveCollapseState && this.viewAllPage) { + Services.prefs.setBoolPref(this.openStatePref, this.isExpanded); + } + } + + render() { + return html` + +
+
+ + + + + + + +
+
+ `; + } +} +customElements.define("card-container", CardContainer); -- cgit v1.2.3