Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit edc5e87

Browse files
committed
chore: setup storybook
1 parent 2034f8b commit edc5e87

12 files changed

Lines changed: 1160 additions & 53 deletions

File tree

.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
module.exports = {
22
plugins: ["matrix-org", "eslint-plugin-react-compiler"],
3-
extends: ["plugin:matrix-org/babel", "plugin:matrix-org/react", "plugin:matrix-org/a11y"],
3+
extends: [
4+
"plugin:matrix-org/babel",
5+
"plugin:matrix-org/react",
6+
"plugin:matrix-org/a11y",
7+
"plugin:storybook/recommended",
8+
],
49
parserOptions: {
510
project: ["./tsconfig.json"],
611
},

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ electron/pub
3131
/index.html
3232
# version file and tarball created by `npm pack` / `yarn pack`
3333
/git-revision.txt
34+
35+
*storybook.log
36+
storybook-static

.storybook/ElementTheme.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { create } from "storybook/theming";
2+
3+
export default create({
4+
base: "light",
5+
6+
// Colors
7+
textColor: "#1b1d22",
8+
colorSecondary: "#111111",
9+
10+
// UI
11+
appBg: "#ffffff",
12+
appContentBg: "#ffffff",
13+
14+
// Toolbar
15+
barBg: "#ffffff",
16+
17+
brandTitle: "Element Web",
18+
brandUrl: "https://github.com/element-hq/element-web",
19+
brandImage: "https://element.io/images/logo-ele-secondary.svg",
20+
brandTarget: "_self",
21+
});

.storybook/main.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { StorybookConfig } from "@storybook/react-webpack5";
2+
3+
const config: StorybookConfig = {
4+
stories: ["../src/shared/**/*.mdx", "../src/shared/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
5+
addons: [
6+
"@storybook/addon-webpack5-compiler-swc",
7+
"@storybook/addon-docs",
8+
"@storybook/addon-designs",
9+
{
10+
name: "@storybook/addon-styling-webpack",
11+
options: {
12+
rules: [
13+
{
14+
test: /\.module.css$/,
15+
use: [
16+
"style-loader",
17+
{
18+
loader: "css-loader",
19+
options: {
20+
importLoaders: 1,
21+
modules: {
22+
namedExport: false,
23+
},
24+
},
25+
},
26+
],
27+
},
28+
// Replaces existing CSS rules with given rule
29+
{
30+
test: /\.p?css$/,
31+
exclude: /\.module.css$/,
32+
use: ["style-loader", "css-loader"],
33+
},
34+
],
35+
},
36+
},
37+
],
38+
framework: "@storybook/react-webpack5",
39+
core: {
40+
disableTelemetry: true,
41+
},
42+
typescript: {
43+
reactDocgen: "react-docgen-typescript",
44+
},
45+
};
46+
export default config;

.storybook/manager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { addons } from "storybook/manager-api";
2+
import ElementTheme from "./ElementTheme";
3+
4+
addons.setConfig({
5+
theme: ElementTheme,
6+
});

.storybook/preview.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.docs-story {
2+
background: var(--cpd-color-bg-canvas-default);
3+
}

.storybook/preview.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { ArgTypes, Preview, Decorator } from "@storybook/react-webpack5";
2+
3+
import "../res/css/shared.pcss";
4+
import "./preview.css";
5+
import React, { useLayoutEffect } from "react";
6+
7+
export const globalTypes = {
8+
theme: {
9+
name: "Theme",
10+
defaultValue: "system",
11+
description: "Global theme for components",
12+
toolbar: {
13+
icon: "circlehollow",
14+
title: "Theme",
15+
items: [
16+
{ title: "System", value: "system", icon: "browser" },
17+
{ title: "Light", value: "light", icon: "sun" },
18+
{ title: "Light (high contrast)", value: "light-hc", icon: "sun" },
19+
{ title: "Dark", value: "dark", icon: "moon" },
20+
{ title: "Dark (high contrast)", value: "dark-hc", icon: "moon" },
21+
],
22+
},
23+
},
24+
} satisfies ArgTypes;
25+
26+
const allThemesClasses = globalTypes.theme.toolbar.items.map(({ value }) => `cpd-theme-${value}`);
27+
28+
const ThemeSwitcher: React.FC<{
29+
theme: string;
30+
}> = ({ theme }) => {
31+
useLayoutEffect(() => {
32+
document.documentElement.classList.remove(...allThemesClasses);
33+
if (theme !== "system") {
34+
document.documentElement.classList.add(`cpd-theme-${theme}`);
35+
}
36+
return () => document.documentElement.classList.remove(...allThemesClasses);
37+
}, [theme]);
38+
39+
return null;
40+
};
41+
42+
const withThemeProvider: Decorator = (Story, context) => {
43+
return (
44+
<>
45+
<ThemeSwitcher theme={context.globals.theme} />
46+
<Story />
47+
</>
48+
);
49+
};
50+
51+
const preview: Preview = {
52+
tags: ["autodocs"],
53+
decorators: [withThemeProvider],
54+
};
55+
56+
export default preview;

declaration.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
declare module "*.module.css";

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
"coverage": "yarn test --coverage",
6666
"analyse:webpack-bundles": "webpack-bundle-analyzer webpack-stats.json webapp",
6767
"update:jitsi": "curl -s https://meet.element.io/libs/external_api.min.js > ./res/jitsi_external_api.min.js",
68-
"postinstall": "patch-package"
68+
"postinstall": "patch-package",
69+
"storybook": "storybook dev -p 6007",
70+
"build-storybook": "storybook build"
6971
},
7072
"resolutions": {
7173
"**/pretty-format/react-is": "19.1.0",
@@ -187,6 +189,11 @@
187189
"@principalstudio/html-webpack-inject-preload": "^1.2.7",
188190
"@rrweb/types": "^2.0.0-alpha.18",
189191
"@sentry/webpack-plugin": "^3.0.0",
192+
"@storybook/addon-designs": "^10.0.1",
193+
"@storybook/addon-docs": "^9.0.12",
194+
"@storybook/addon-styling-webpack": "^2.0.0",
195+
"@storybook/addon-webpack5-compiler-swc": "^3.0.0",
196+
"@storybook/react-webpack5": "^9.0.12",
190197
"@stylistic/eslint-plugin": "^4.0.0",
191198
"@svgr/webpack": "^8.0.0",
192199
"@testing-library/dom": "^10.4.0",
@@ -246,6 +253,7 @@
246253
"eslint-plugin-react": "^7.28.0",
247254
"eslint-plugin-react-compiler": "^19.0.0-beta-df7b47d-20241124",
248255
"eslint-plugin-react-hooks": "^5.0.0",
256+
"eslint-plugin-storybook": "^9.0.12",
249257
"eslint-plugin-unicorn": "^56.0.0",
250258
"express": "^5.0.0",
251259
"fake-indexeddb": "^6.0.0",
@@ -286,6 +294,7 @@
286294
"rimraf": "^6.0.0",
287295
"semver": "^7.5.2",
288296
"source-map-loader": "^5.0.0",
297+
"storybook": "^9.0.12",
289298
"stylelint": "^16.13.0",
290299
"stylelint-config-standard": "^38.0.0",
291300
"stylelint-scss": "^6.0.0",

res/css/shared.pcss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
@import url("@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css") layer(compound);
9+
@import url("@vector-im/compound-web/dist/style.css");

0 commit comments

Comments
 (0)