Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
15817cf
Very first pass at shared component views
dbkr Jun 26, 2025
ddbe098
Remove old TextualEvent
dbkr Jun 26, 2025
0179284
Pass showHiddenEvents
dbkr Jun 26, 2025
84d34e1
Factor out common view model stuff
dbkr Jun 26, 2025
b96da8d
Move ViewModel interface into the shared components
dbkr Jun 26, 2025
455ca44
Add tiny wrapper hook
dbkr Jun 26, 2025
73d78f4
Move showHiddenEvents into props fully
dbkr Jun 26, 2025
2125415
Fill in stories / test
dbkr Jun 30, 2025
a597221
chore: setup storybook
florianduros Jun 20, 2025
3d724ff
Add TextualEvent component to storybook
dbkr Jun 30, 2025
11f9849
Add mock view model & snapshot
dbkr Jun 30, 2025
4709656
Remove old style stories entry
dbkr Jun 30, 2025
5638dd7
Merge branch 'develop' into dbkr/textualevent_sharedcomponent
dbkr Jul 1, 2025
9318006
Change import
dbkr Jul 1, 2025
a936433
Change import
dbkr Jul 1, 2025
472de3b
Prettier
dbkr Jul 1, 2025
073d97e
Add paxckage patch to @types/mdx
dbkr Jul 1, 2025
f2fc88f
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr Jul 3, 2025
862aaff
Pass getSnapshot as getServerSnapshot too
dbkr Jul 3, 2025
82d08df
Maybe make sonar regognise tests as tests
dbkr Jul 3, 2025
b1edabe
Typo
dbkr Jul 3, 2025
3285007
Use storybook reacvt-vite
dbkr Jul 3, 2025
4fddd23
Change here too
dbkr Jul 3, 2025
703ba8d
Workaround for incomatible types in rollup
dbkr Jul 3, 2025
fbe6a06
Remove webpack styling addon
dbkr Jul 7, 2025
c8bd639
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr Jul 7, 2025
7e4ff89
Hopefully do screenshot testing...
dbkr Jul 7, 2025
d3300ac
need newer node
dbkr Jul 7, 2025
5f3fae2
quote issues
dbkr Jul 7, 2025
d3c5971
Make it an npm script
dbkr Jul 7, 2025
f47673c
colons
dbkr Jul 7, 2025
0c3830f
use right port
dbkr Jul 7, 2025
41612d3
Install playwright browsers
dbkr Jul 7, 2025
fd9253d
Try without the if
dbkr Jul 8, 2025
2f62c15
Oh right, we need the headless shell
dbkr Jul 8, 2025
d2c632f
Pass flag to store received screenshots
dbkr Jul 8, 2025
b632a61
Update snapshot from received
dbkr Jul 8, 2025
80ed90a
Include platform in snapshot / received dir
dbkr Jul 8, 2025
a56cf55
Suffix snapshots with platform instead
dbkr Jul 8, 2025
917f85e
Remove unnecessary env vars
dbkr Jul 8, 2025
6171d2a
Add some comments
dbkr Jul 8, 2025
94b7adc
Prettier
dbkr Jul 8, 2025
5a2cb98
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr Jul 8, 2025
f424599
Fix yarn.lock
dbkr Jul 8, 2025
e6dbe93
Memoise vm creation
dbkr Jul 9, 2025
7347d55
Add implements
dbkr Jul 9, 2025
b4ea530
Fix listener interface
dbkr Jul 9, 2025
3077be3
Add implements
dbkr Jul 9, 2025
9621f79
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr Jul 9, 2025
03ee035
Fix types
dbkr Jul 9, 2025
fbd9af6
Fix more types
dbkr Jul 9, 2025
8878c7b
Revert useMemo
dbkr Jul 9, 2025
553724b
Unused import
dbkr Jul 9, 2025
ead893c
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr Jul 9, 2025
fa300af
Add missing playwright step
dbkr Jul 9, 2025
dc47abb
Add return type annotation
dbkr Jul 9, 2025
f62177a
Change to add / remove subscription callback
dbkr Jul 9, 2025
049a3ae
Change to 'add' rather than 'subs.subscribe'
dbkr Jul 9, 2025
c16fd3d
Add cache specifier for only shell playwright browsers
dbkr Jul 9, 2025
c3e53aa
Add copyright headers
dbkr Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
plugins: ["matrix-org", "eslint-plugin-react-compiler"],
extends: ["plugin:matrix-org/babel", "plugin:matrix-org/react", "plugin:matrix-org/a11y"],
extends: [
"plugin:matrix-org/babel",
"plugin:matrix-org/react",
"plugin:matrix-org/a11y",
"plugin:storybook/recommended",
],
parserOptions: {
project: ["./tsconfig.json"],
},
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/shared-component-visual-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Shared Component Visual Tests
on:
pull_request: {}
merge_group:
types: [checks_requested]
push:
branches: [develop, master]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions: {} # No permissions required

jobs:
testStorybook:
name: "Run Visual Tests"
runs-on: ubuntu-24.04
permissions:
actions: read
issues: read
pull-requests: read
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
persist-credentials: false
repository: element-hq/element-web

- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
cache: "yarn"
node-version: "lts/*"

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Get installed Playwright version
id: playwright
run: echo "version=$(yarn list --pattern @playwright/test --depth=0 --json --non-interactive --no-progress | jq -r '.data.trees[].name')" >> $GITHUB_OUTPUT

- name: Cache playwright binaries
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-${{ runner.arch }}-playwright-${{ steps.playwright.outputs.version }}-onlyshell

- name: Install Playwright browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: "yarn playwright install --with-deps --only-shell"

- name: Run Visual tests
run: "yarn test:storybook:ci"

- name: Upload received images & diffs
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: received-images
path: playwright/shared-component-received
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ electron/pub
/index.html
# version file and tarball created by `npm pack` / `yarn pack`
/git-revision.txt

*storybook.log
storybook-static
28 changes: 28 additions & 0 deletions .storybook/ElementTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { create } from "storybook/theming";

export default create({
base: "light",

// Colors
textColor: "#1b1d22",
colorSecondary: "#111111",

// UI
appBg: "#ffffff",
appContentBg: "#ffffff",

// Toolbar
barBg: "#ffffff",

brandTitle: "Element Web",
brandUrl: "https://github.com/element-hq/element-web",
brandImage: "https://element.io/images/logo-ele-secondary.svg",
brandTarget: "_self",
});
21 changes: 21 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../src/shared-components/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: ["@storybook/addon-docs", "@storybook/addon-designs"],
framework: "@storybook/react-vite",
core: {
disableTelemetry: true,
},
typescript: {
reactDocgen: "react-docgen-typescript",
},
};
export default config;
13 changes: 13 additions & 0 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { addons } from "storybook/manager-api";
import ElementTheme from "./ElementTheme";

addons.setConfig({
theme: ElementTheme,
});
10 changes: 10 additions & 0 deletions .storybook/preview.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

.docs-story {
background: var(--cpd-color-bg-canvas-default);
}
56 changes: 56 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { ArgTypes, Preview, Decorator } from "@storybook/react-vite";

import "../res/css/shared.pcss";
import "./preview.css";
import React, { useLayoutEffect } from "react";

export const globalTypes = {
theme: {
name: "Theme",
defaultValue: "system",
description: "Global theme for components",
toolbar: {
icon: "circlehollow",
title: "Theme",
items: [
{ title: "System", value: "system", icon: "browser" },
{ title: "Light", value: "light", icon: "sun" },
{ title: "Light (high contrast)", value: "light-hc", icon: "sun" },
{ title: "Dark", value: "dark", icon: "moon" },
{ title: "Dark (high contrast)", value: "dark-hc", icon: "moon" },
],
},
},
} satisfies ArgTypes;

const allThemesClasses = globalTypes.theme.toolbar.items.map(({ value }) => `cpd-theme-${value}`);

const ThemeSwitcher: React.FC<{
theme: string;
}> = ({ theme }) => {
useLayoutEffect(() => {
document.documentElement.classList.remove(...allThemesClasses);
if (theme !== "system") {
document.documentElement.classList.add(`cpd-theme-${theme}`);
}
return () => document.documentElement.classList.remove(...allThemesClasses);
}, [theme]);

return null;
};

const withThemeProvider: Decorator = (Story, context) => {
return (
<>
<ThemeSwitcher theme={context.globals.theme} />
<Story />
</>
);
};

const preview: Preview = {
tags: ["autodocs"],
decorators: [withThemeProvider],
};

export default preview;
37 changes: 37 additions & 0 deletions .storybook/test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { waitForPageReady } from "@storybook/test-runner";
import { toMatchImageSnapshot } from "jest-image-snapshot";

const customSnapshotsDir = `${process.cwd()}/playwright/shared-component-snapshots/`;
const customReceivedDir = `${process.cwd()}/playwright/shared-component-received/`;

/**
* @type {import('@storybook/test-runner').TestRunnerConfig}
*/
const config = {
setup(page) {
expect.extend({ toMatchImageSnapshot });
},
async postVisit(page, context) {
await waitForPageReady(page);

// If you want to take screenshot of multiple browsers, use
// page.context().browser().browserType().name() to get the browser name to prefix the file name
const image = await page.screenshot();
expect(image).toMatchImageSnapshot({
customSnapshotsDir,
customSnapshotIdentifier: `${context.id}-${process.platform}`,
storeReceivedOnFailure: true,
customReceivedDir,
customDiffDir: customReceivedDir,
});
},
};

export default config;
8 changes: 8 additions & 0 deletions declaration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/

declare module "*.module.css";
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config: Config = {
// This is needed to be able to load dual CJS/ESM WASM packages e.g. rust crypto & matrix-wywiwyg
customExportConditions: ["browser", "node"],
},
testMatch: ["<rootDir>/test/**/*-test.[tj]s?(x)"],
testMatch: ["<rootDir>/test/**/*-test.[tj]s?(x)", "<rootDir>/src/shared-components/**/*.test.[t]s?(x)"],
globalSetup: "<rootDir>/test/globalSetup.ts",
setupFiles: ["jest-canvas-mock", "web-streams-polyfill/polyfill"],
setupFilesAfterEnv: ["<rootDir>/test/setupTests.ts"],
Expand Down
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
"coverage": "yarn test --coverage",
"analyse:webpack-bundles": "webpack-bundle-analyzer webpack-stats.json webapp",
"update:jitsi": "curl -s https://meet.element.io/libs/external_api.min.js > ./res/jitsi_external_api.min.js",
"postinstall": "patch-package"
"postinstall": "patch-package",
"storybook": "storybook dev -p 6007",
"build-storybook": "storybook build",
"test:storybook": "test-storybook --url http://localhost:6007/",
"test:storybook:ci": "concurrently -k -s first -n \"SB,TEST\" \"yarn storybook\" \"wait-on tcp:6007 && yarn test-storybook --url http://localhost:6007/ --ci --maxWorkers=2\""
},
"resolutions": {
"**/pretty-format/react-is": "19.1.0",
Expand Down Expand Up @@ -187,6 +191,10 @@
"@principalstudio/html-webpack-inject-preload": "^1.2.7",
"@rrweb/types": "^2.0.0-alpha.18",
"@sentry/webpack-plugin": "^3.0.0",
"@storybook/addon-designs": "^10.0.1",
"@storybook/addon-docs": "^9.0.12",
"@storybook/react-vite": "^9.0.15",
"@storybook/test-runner": "^0.23.0",
"@stylistic/eslint-plugin": "^5.0.0",
"@svgr/webpack": "^8.0.0",
"@testing-library/dom": "^10.4.0",
Expand Down Expand Up @@ -246,6 +254,7 @@
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-compiler": "^19.0.0-beta-df7b47d-20241124",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-storybook": "^9.0.12",
"eslint-plugin-unicorn": "^56.0.0",
"express": "^5.0.0",
"fake-indexeddb": "^6.0.0",
Expand All @@ -257,6 +266,7 @@
"jest": "^29.6.2",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"jest-image-snapshot": "^6.5.1",
"jest-mock": "^29.6.2",
"jest-raw-loader": "^1.0.1",
"jsqr": "^1.4.0",
Expand Down Expand Up @@ -285,6 +295,7 @@
"rimraf": "^6.0.0",
"semver": "^7.5.2",
"source-map-loader": "^5.0.0",
"storybook": "^9.0.12",
"stylelint": "^16.13.0",
"stylelint-config-standard": "^38.0.0",
"stylelint-scss": "^6.0.0",
Expand All @@ -294,6 +305,7 @@
"ts-node": "^10.9.1",
"typescript": "5.8.3",
"util": "^0.12.5",
"vite": "^7.0.1",
"web-streams-polyfill": "^4.0.0",
"webpack": "^5.89.0",
"webpack-bundle-analyzer": "^4.8.0",
Expand Down
46 changes: 46 additions & 0 deletions patches/@types+mdx+2.0.13.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/node_modules/@types/mdx/types.d.ts b/node_modules/@types/mdx/types.d.ts
index 498bb69..4e89216 100644
--- a/node_modules/@types/mdx/types.d.ts
+++ b/node_modules/@types/mdx/types.d.ts
@@ -5,7 +5,7 @@
*/
// @ts-ignore JSX runtimes may optionally define JSX.ElementType. The MDX types need to work regardless whether this is
// defined or not.
-type ElementType = any extends JSX.ElementType ? never : JSX.ElementType;
+type ElementType = any extends JSX.ElementType ? never : React.JSX.ElementType;

/**
* This matches any function component types that ar part of `ElementType`.
@@ -20,12 +20,12 @@ type ClassElementType = Extract<ElementType, new(props: Record<string, any>) =>
/**
* A valid JSX string component.
*/
-type StringComponent = Extract<keyof JSX.IntrinsicElements, ElementType extends never ? string : ElementType>;
+type StringComponent = Extract<keyof React.JSX.IntrinsicElements, ElementType extends never ? string : ElementType>;

/**
* A JSX element returned by MDX content.
*/
-export type Element = JSX.Element;
+export type Element = React.JSX.Element;

/**
* A valid JSX function component.
@@ -44,7 +44,7 @@ type FunctionComponent<Props> = ElementType extends never
*/
type ClassComponent<Props> = ElementType extends never
// If JSX.ElementType isn’t defined, the valid return type is a constructor that returns JSX.ElementClass
- ? new(props: Props) => JSX.ElementClass
+ ? new(props: Props) => React.JSX.ElementClass
: ClassElementType extends never
// If JSX.ElementType is defined, but doesn’t allow constructors, function components are disallowed.
? never
@@ -70,7 +70,7 @@ interface NestedMDXComponents {
export type MDXComponents =
& NestedMDXComponents
& {
- [Key in StringComponent]?: Component<JSX.IntrinsicElements[Key]>;
+ [Key in StringComponent]?: Component<React.JSX.IntrinsicElements[Key]>;
}
& {
/**
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions res/css/shared.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/

@import url("@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css") layer(compound);
@import url("@vector-im/compound-web/dist/style.css");
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ sonar.organization=element-hq
#sonar.sourceEncoding=UTF-8

sonar.sources=src,res
sonar.tests=test,playwright
sonar.tests=test,playwright,src
sonar.test.inclusions=test/*,playwright/*,src/**/*.test.tsx
sonar.exclusions=__mocks__,docs,element.io,nginx

sonar.cpd.exclusions=src/i18n/strings/*.json
Expand Down
Loading
Loading