-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Initial structure for shared component views #30216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 ddbe098
Remove old TextualEvent
dbkr 0179284
Pass showHiddenEvents
dbkr 84d34e1
Factor out common view model stuff
dbkr b96da8d
Move ViewModel interface into the shared components
dbkr 455ca44
Add tiny wrapper hook
dbkr 73d78f4
Move showHiddenEvents into props fully
dbkr 2125415
Fill in stories / test
dbkr a597221
chore: setup storybook
florianduros 3d724ff
Add TextualEvent component to storybook
dbkr 11f9849
Add mock view model & snapshot
dbkr 4709656
Remove old style stories entry
dbkr 5638dd7
Merge branch 'develop' into dbkr/textualevent_sharedcomponent
dbkr 9318006
Change import
dbkr a936433
Change import
dbkr 472de3b
Prettier
dbkr 073d97e
Add paxckage patch to @types/mdx
dbkr f2fc88f
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr 862aaff
Pass getSnapshot as getServerSnapshot too
dbkr 82d08df
Maybe make sonar regognise tests as tests
dbkr b1edabe
Typo
dbkr 3285007
Use storybook reacvt-vite
dbkr 4fddd23
Change here too
dbkr 703ba8d
Workaround for incomatible types in rollup
dbkr fbe6a06
Remove webpack styling addon
dbkr c8bd639
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr 7e4ff89
Hopefully do screenshot testing...
dbkr d3300ac
need newer node
dbkr 5f3fae2
quote issues
dbkr d3c5971
Make it an npm script
dbkr f47673c
colons
dbkr 0c3830f
use right port
dbkr 41612d3
Install playwright browsers
dbkr fd9253d
Try without the if
dbkr 2f62c15
Oh right, we need the headless shell
dbkr d2c632f
Pass flag to store received screenshots
dbkr b632a61
Update snapshot from received
dbkr 80ed90a
Include platform in snapshot / received dir
dbkr a56cf55
Suffix snapshots with platform instead
dbkr 917f85e
Remove unnecessary env vars
dbkr 6171d2a
Add some comments
dbkr 94b7adc
Prettier
dbkr 5a2cb98
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr f424599
Fix yarn.lock
dbkr e6dbe93
Memoise vm creation
dbkr 7347d55
Add implements
dbkr b4ea530
Fix listener interface
dbkr 3077be3
Add implements
dbkr 9621f79
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr 03ee035
Fix types
dbkr fbd9af6
Fix more types
dbkr 8878c7b
Revert useMemo
dbkr 553724b
Unused import
dbkr ead893c
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr fa300af
Add missing playwright step
dbkr dc47abb
Add return type annotation
dbkr f62177a
Change to add / remove subscription callback
dbkr 049a3ae
Change to 'add' rather than 'subs.subscribe'
dbkr c16fd3d
Add cache specifier for only shell playwright browsers
dbkr c3e53aa
Add copyright headers
dbkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]>; | ||
| } | ||
| & { | ||
| /** |
Binary file added
BIN
+6.95 KB
playwright/shared-component-snapshots/event-textualevent--default-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.