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 --- .../components/storybook/.storybook/preview.mjs | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 browser/components/storybook/.storybook/preview.mjs (limited to 'browser/components/storybook/.storybook/preview.mjs') diff --git a/browser/components/storybook/.storybook/preview.mjs b/browser/components/storybook/.storybook/preview.mjs new file mode 100644 index 0000000000..55e7f00f10 --- /dev/null +++ b/browser/components/storybook/.storybook/preview.mjs @@ -0,0 +1,111 @@ +/* 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 { css, html } from "lit.all.mjs"; +import { MozLitElement } from "toolkit/content/widgets/lit-utils.mjs"; +import { setCustomElementsManifest } from "@storybook/web-components"; +import customElementsManifest from "../custom-elements.json"; +import { insertFTLIfNeeded, connectFluent } from "./fluent-utils.mjs"; + +// Base Fluent set up. +connectFluent(); + +// Any fluent imports should go through MozXULElement.insertFTLIfNeeded. +window.MozXULElement = { + insertFTLIfNeeded, + + // For some reason Storybook doesn't watch the static folder. By creating a + // method with a dynamic import we can pull the desired files into the bundle. + async importCss(resourceName) { + // eslint-disable-next-line no-unsanitized/method + let file = await import( + /* webpackInclude: /.*[\/\\].*\.css$/ */ + `browser/themes/shared/${resourceName}` + ); + // eslint-disable-next-line no-unsanitized/method + file = await import( + /* webpackInclude: /.*[\/\\].*\.css$/ */ + `browser/components/firefoxview/${resourceName}` + ); + return file; + }, +}; + +/** + * Wrapper component used to decorate all of our stories by providing access to + * `in-content/common.css` without leaking styles that conflict Storybook's CSS. + * + * More information on decorators can be found at: + * https://storybook.js.org/docs/web-components/writing-stories/decorators + * + * @property {Function} story + * Storybook uses this internally to render stories. We call `story` in our + * render function so that the story contents have the same shadow root as + * `with-common-styles` and styles from `in-content/common` get applied. + * @property {Object} context + * Another Storybook provided property containing additional data stories use + * to render. If we don't make this a reactive property Lit seems to optimize + * away any re-rendering of components inside `with-common-styles`. + */ +class WithCommonStyles extends MozLitElement { + static styles = css` + :host { + display: block; + height: 100%; + padding: 1rem; + box-sizing: border-box; + } + + :host, + :root { + font: message-box; + appearance: none; + background-color: var(--in-content-page-background); + color: var(--in-content-page-color); + -moz-box-layout: flex; + } + + :host, + :root:not(.system-font-size) { + font-size: 15px; + } + `; + + static properties = { + story: { type: Function }, + context: { type: Object }, + }; + + storyContent() { + if (this.story) { + return this.story(); + } + return html` `; + } + + render() { + return html` + + ${this.storyContent()} + `; + } +} +customElements.define("with-common-styles", WithCommonStyles); + +// Wrap all stories in `with-common-styles`. +export const decorators = [ + (story, context) => + html` + + `, +]; + +// Enable props tables documentation. +setCustomElementsManifest(customElementsManifest); -- cgit v1.2.3