Set up Storybook again

This commit is contained in:
Robin
2026-03-30 17:59:29 +02:00
parent 40fdef89eb
commit 2de151d94d
9 changed files with 1030 additions and 49 deletions

View File

@@ -15,6 +15,7 @@ module.exports = {
"plugin:matrix-org/typescript", "plugin:matrix-org/typescript",
"prettier", "prettier",
"plugin:rxjs/recommended", "plugin:rxjs/recommended",
"plugin:storybook/recommended"
], ],
parserOptions: { parserOptions: {
ecmaVersion: "latest", ecmaVersion: "latest",

3
.gitignore vendored
View File

@@ -30,3 +30,6 @@ yarn-error.log
/playwright-report/ /playwright-report/
/blob-report/ /blob-report/
/playwright/.cache/ /playwright/.cache/
*storybook.log
storybook-static

8
.storybook/main.ts Normal file
View File

@@ -0,0 +1,8 @@
import type { StorybookConfig } from "@storybook/react-vite";
const config: StorybookConfig = {
stories: ["../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: ["@storybook/addon-docs"],
framework: "@storybook/react-vite",
};
export default config;

24
.storybook/manager.ts Normal file
View File

@@ -0,0 +1,24 @@
import { create } from "storybook/theming";
import { addons } from "storybook/manager-api";
addons.setConfig({
theme: create({
base: "light",
colorPrimary: "#1b1d22",
colorSecondary: "#0467dd",
// Typography
fontBase: '"Inter", sans-serif',
fontCode: '"Inconsolata", monospace',
// Text colors
textColor: "#1b1d22",
appBg: "#ffffff",
barBg: "#ffffff",
brandTitle: "Element Call",
brandUrl: "https://element.io/",
brandImage: "/src/icons/Logo.svg",
brandTarget: "_self",
}),
});

49
.storybook/preview.tsx Normal file
View File

@@ -0,0 +1,49 @@
import type { Preview } from "@storybook/react-vite";
import { TooltipProvider } from "@vector-im/compound-web";
import i18n from "i18next";
import { logger } from "matrix-js-sdk/lib/logger";
import EN from "../locales/en/app.json";
import { initReactI18next } from "react-i18next";
import "../src/index.css";
// Bare-minimum i18n config
i18n
.use(initReactI18next)
.init({
lng: "en",
fallbackLng: "en",
supportedLngs: ["en"],
// We embed the translations, so that it never needs to fetch
resources: {
en: {
translation: EN,
},
},
interpolation: {
escapeValue: false, // React has built-in XSS protections
},
})
.catch((e) => logger.warn("Failed to init i18n for stories", e));
const preview: Preview = {
parameters: {
layout: "centered",
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
tags: ["autodocs"],
decorators: [
(Story) => (
<TooltipProvider>
<Story />
</TooltipProvider>
),
],
};
export default preview;

View File

@@ -33,7 +33,9 @@
"test:playwright": "playwright test", "test:playwright": "playwright test",
"test:playwright:open": "yarn test:playwright --ui", "test:playwright:open": "yarn test:playwright --ui",
"links:enable": "mv .links.disabled.yaml .links.yaml & touch .links.yaml", "links:enable": "mv .links.disabled.yaml .links.yaml & touch .links.yaml",
"links:disable": "mv .links.yaml .links.disabled.yaml" "links:disable": "mv .links.yaml .links.disabled.yaml",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.16.5", "@babel/core": "^7.16.5",
@@ -57,6 +59,8 @@
"@react-spring/web": "^10.0.0", "@react-spring/web": "^10.0.0",
"@sentry/react": "^8.0.0", "@sentry/react": "^8.0.0",
"@sentry/vite-plugin": "^3.0.0", "@sentry/vite-plugin": "^3.0.0",
"@storybook/addon-docs": "^10.3.3",
"@storybook/react-vite": "^10.3.3",
"@stylistic/eslint-plugin": "^3.0.0", "@stylistic/eslint-plugin": "^3.0.0",
"@testing-library/dom": "^10.1.0", "@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.6.3", "@testing-library/jest-dom": "^6.6.3",
@@ -94,6 +98,7 @@
"eslint-plugin-react": "^7.29.4", "eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-rxjs": "^5.0.3", "eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-storybook": "^10.3.3",
"eslint-plugin-unicorn": "^56.0.0", "eslint-plugin-unicorn": "^56.0.0",
"fetch-mock": "11.1.5", "fetch-mock": "11.1.5",
"global-jsdom": "^26.0.0", "global-jsdom": "^26.0.0",
@@ -123,6 +128,7 @@
"react-use-measure": "^2.1.1", "react-use-measure": "^2.1.1",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"sass": "^1.42.1", "sass": "^1.42.1",
"storybook": "^10.3.3",
"typescript": "^5.8.3", "typescript": "^5.8.3",
"typescript-eslint-language-service": "^5.0.5", "typescript-eslint-language-service": "^5.0.5",
"unique-names-generator": "^4.6.0", "unique-names-generator": "^4.6.0",

12
src/@types/mdx.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { JSX as ReactJSX } from "react";
declare module "mdx/types.js" {
export import JSX = ReactJSX;
}

View File

@@ -66,17 +66,19 @@ export default ({
); );
} }
plugins.push( if (!process.env.STORYBOOK) {
createHtmlPlugin({ plugins.push(
entry: "src/main.tsx", createHtmlPlugin({
inject: { entry: "src/main.tsx",
data: { inject: {
brand: env.VITE_PRODUCT_NAME || "Element Call", data: {
packageType: process.env.VITE_PACKAGE, brand: env.VITE_PRODUCT_NAME || "Element Call",
packageType: process.env.VITE_PACKAGE,
},
}, },
}, }),
}), );
); }
// The crypto WASM module is imported dynamically. Since it's common // The crypto WASM module is imported dynamically. Since it's common
// for developers to use a linked copy of matrix-js-sdk or Rust // for developers to use a linked copy of matrix-js-sdk or Rust

952
yarn.lock

File diff suppressed because it is too large Load Diff