-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Implement a shared Banner component.
#31266
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
kaylendog
merged 8 commits into
element-hq:develop
from
kaylendog:kaylendog/shared-components/banner
Nov 26, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9fc03fd
feat: Create composer `Banner` shared component.
kaylendog 2c13354
fix: Yarn resolution issues corrupting package store.
kaylendog b738dd2
chore: Revert "fix: Yarn resolution issues corrupting package store."
kaylendog c2495bc
fix: Revert lockfile changes.
kaylendog d3ebec2
chore: Resolve linting errors.
kaylendog b6bfd89
Merge remote-tracking branch 'upstream/develop' into kaylendog/shared…
kaylendog 83c8751
Merge remote-tracking branch 'upstream/develop' into kaylendog/shared…
kaylendog 5f91c95
chore: Update playwright screenshots.
kaylendog 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
Binary file added
BIN
+12.6 KB
packages/shared-components/playwright/snapshots/room-banner--critical-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.3 KB
packages/shared-components/playwright/snapshots/room-banner--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.
Binary file added
BIN
+13.1 KB
packages/shared-components/playwright/snapshots/room-banner--info-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.7 KB
packages/shared-components/playwright/snapshots/room-banner--success-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.9 KB
packages/shared-components/playwright/snapshots/room-banner--with-action-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.51 KB
...shared-components/playwright/snapshots/room-banner--with-avatar-image-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions
93
packages/shared-components/src/composer/Banner/Banner.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations 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. | ||
| */ | ||
|
|
||
| :root { | ||
| --cpd-color-gradient-critical-linear: linear-gradient( | ||
| 180deg, | ||
| var(--cpd-color-alpha-red-500) 0%, | ||
| var(--cpd-color-alpha-red-400) 20%, | ||
| var(--cpd-color-alpha-red-300) 40%, | ||
| var(--cpd-color-alpha-red-200) 60%, | ||
| var(--cpd-color-alpha-red-100) 80%, | ||
| var(--cpd-color-transparent) 100% | ||
| ); | ||
| } | ||
|
|
||
| .banner { | ||
| container-type: inline-size; | ||
| container-name: banner; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: start; | ||
| gap: var(--cpd-space-3x); | ||
| padding: var(--cpd-space-4x); | ||
|
|
||
| border-top: 1px solid var(--cpd-color-gray-400); | ||
|
|
||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .banner[data-type="success"] { | ||
| background: var(--cpd-color-gradient-subtle-linear); | ||
| border-color: var(--cpd-color-green-900); | ||
| } | ||
|
|
||
| .banner[data-type="critical"] { | ||
| background: var(--cpd-color-gradient-critical-linear); | ||
| border-color: var(--cpd-color-border-critical-primary); | ||
| } | ||
|
|
||
| .banner[data-type="info"] { | ||
| background: var(--cpd-color-gradient-info-linear); | ||
| border-color: var(--cpd-color-blue-900); | ||
| } | ||
|
|
||
| .banner[data-type="info"] :is(svg) { | ||
| color: var(--cpd-color-blue-900); | ||
| } | ||
|
|
||
| .banner[data-type="success"] :is(.content, svg) { | ||
| color: var(--cpd-color-green-900); | ||
| } | ||
|
|
||
| .banner[data-type="critical"] :is(.content, svg) { | ||
| color: var(--cpd-color-red-900); | ||
| } | ||
|
|
||
| .banner p { | ||
| margin: 0; | ||
| } | ||
|
|
||
| .icon { | ||
| /* lock icon dimensions */ | ||
| min-width: 32px; | ||
| min-height: 32px; | ||
| max-width: 32px; | ||
| max-height: 32px; | ||
|
|
||
| margin: 4px; | ||
|
|
||
| /* centre svg icons, as they are not full width */ | ||
| flex: 0; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .icon img { | ||
| border-radius: 50%; | ||
| } | ||
|
|
||
| .actions { | ||
| margin-left: auto; | ||
|
|
||
| flex: 0; | ||
| display: flex; | ||
| flex-direction: row; | ||
| gap: var(--cpd-space-1x); | ||
| align-self: center; | ||
| } | ||
67 changes: 67 additions & 0 deletions
67
packages/shared-components/src/composer/Banner/Banner.stories.tsx
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,67 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations 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 React from "react"; | ||
| import { fn } from "storybook/test"; | ||
| import { type Meta, type StoryObj } from "@storybook/react-vite"; | ||
| import { Button } from "@vector-im/compound-web"; | ||
|
|
||
| import { Banner } from "./Banner"; | ||
| import { _t } from "../../utils/i18n"; | ||
|
|
||
| const meta = { | ||
| title: "room/Banner", | ||
| component: Banner, | ||
| tags: ["autodocs"], | ||
| args: { | ||
| children: <p>Hello! This is a status banner.</p>, | ||
| onClose: fn(), | ||
| }, | ||
| } satisfies Meta<typeof Banner>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = {}; | ||
| export const Info: Story = { | ||
| args: { | ||
| type: "info", | ||
| }, | ||
| }; | ||
| export const Success: Story = { | ||
| args: { | ||
| type: "success", | ||
| }, | ||
| }; | ||
| export const Critical: Story = { | ||
| args: { | ||
| type: "critical", | ||
| }, | ||
| }; | ||
| export const WithAction: Story = { | ||
| args: { | ||
| children: ( | ||
| <p> | ||
| {_t( | ||
| "encryption|pinned_identity_changed", | ||
| { displayName: "Alice", userId: "@alice:example.org" }, | ||
| { | ||
| a: (sub) => <a href="https://example.org">{sub}</a>, | ||
| b: (sub) => <b>{sub}</b>, | ||
| }, | ||
| )} | ||
| </p> | ||
| ), | ||
| actions: <Button kind="primary">{_t("encryption|withdraw_verification_action")}</Button>, | ||
| }, | ||
| }; | ||
|
|
||
| export const WithAvatarImage: Story = { | ||
| args: { | ||
| avatar: <img alt="Example" src="https://picsum.photos/32/32" />, | ||
| }, | ||
| }; |
41 changes: 41 additions & 0 deletions
41
packages/shared-components/src/composer/Banner/Banner.test.tsx
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,41 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations 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 React from "react"; | ||
| import { render } from "jest-matrix-react"; | ||
| import { composeStories } from "@storybook/react-vite"; | ||
|
|
||
| import * as stories from "./Banner.stories.tsx"; | ||
|
|
||
| const { Default, Info, Success, WithAction, WithAvatarImage, Critical } = composeStories(stories); | ||
|
|
||
| describe("AvatarWithDetails", () => { | ||
| it("renders a default banner", () => { | ||
| const { container } = render(<Default />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| it("renders a info banner", () => { | ||
| const { container } = render(<Info />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| it("renders a success banner", () => { | ||
| const { container } = render(<Success />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| it("renders a critical banner", () => { | ||
| const { container } = render(<Critical />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| it("renders a banner with an action", () => { | ||
| const { container } = render(<WithAction />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| it("renders a banner with an avatar iamge", () => { | ||
| const { container } = render(<WithAvatarImage />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| }); |
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,91 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations 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 classNames from "classnames"; | ||
| import React, { | ||
| type MouseEventHandler, | ||
| type ReactElement, | ||
| type ReactNode, | ||
| type PropsWithChildren, | ||
| useMemo, | ||
| } from "react"; | ||
| import { Button } from "@vector-im/compound-web"; | ||
| import CheckCircleIcon from "@vector-im/compound-design-tokens/assets/web/icons/check-circle"; | ||
| import ErrorIcon from "@vector-im/compound-design-tokens/assets/web/icons/error-solid"; | ||
| import InfoIcon from "@vector-im/compound-design-tokens/assets/web/icons/info"; | ||
|
|
||
| import styles from "./Banner.module.css"; | ||
| import { _t } from "../../utils/i18n"; | ||
|
|
||
| interface BannerProps { | ||
| /** | ||
| * The type of the status banner. | ||
| */ | ||
| type?: "success" | "info" | "critical"; | ||
|
|
||
| /** | ||
| * The banner avatar. | ||
| */ | ||
| avatar?: React.ReactNode; | ||
|
|
||
| className?: string; | ||
|
|
||
| /** | ||
| * Actions presented to the user in the right-hand side of the banner alongside the dismiss button. | ||
| */ | ||
| actions?: ReactNode; | ||
| /** | ||
| * Called when the user presses the "dismiss" button. | ||
| */ | ||
| onClose: MouseEventHandler<HTMLButtonElement>; | ||
| } | ||
|
|
||
| /** | ||
| * A banner component used for displaying user-facing information above the message composer. | ||
| * | ||
| * @example | ||
| * ```tsx | ||
| * <Banner onClose={onCloseHandler} /> | ||
| * ``` | ||
| */ | ||
| export function Banner({ | ||
| type, | ||
| children, | ||
| avatar, | ||
| className, | ||
| actions, | ||
| onClose, | ||
| ...props | ||
| }: PropsWithChildren<BannerProps>): ReactElement { | ||
| const classes = classNames(styles.banner, className); | ||
|
|
||
| const icon = useMemo(() => { | ||
| switch (type) { | ||
| case "critical": | ||
| return <ErrorIcon fontSize={24} {...props} />; | ||
| case "info": | ||
| return <InfoIcon fontSize={24} {...props} />; | ||
| case "success": | ||
| return <CheckCircleIcon fontSize={24} {...props} />; | ||
| default: | ||
| return <InfoIcon fontSize={24} {...props} />; | ||
| } | ||
| }, [type, props]); | ||
|
|
||
| return ( | ||
| <div {...props} className={classes} data-type={type}> | ||
| <div className={styles.icon}>{avatar ?? icon}</div> | ||
| <span className={styles.content}>{children}</span> | ||
| <div className={styles.actions}> | ||
| {actions} | ||
| <Button kind="secondary" size="sm" onClick={onClose}> | ||
| {_t("action|dismiss")} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compound doesn't have an existing gradient for the critical colour palette, so I made one with identical colour stops to the existing info gradient.