/* * 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, type HTMLAttributes, } 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"; import InfoIcon from "@vector-im/compound-design-tokens/assets/web/icons/info"; import styles from "./Banner.module.css"; import { _t } from "../../core/i18n/i18n"; interface BannerProps { /** * The type of the status banner. */ type?: "success" | "info" | "critical"; /** * The banner avatar. */ avatar?: React.ReactNode; /** * 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; } /** * A banner component used for displaying user-facing information above the message composer. * * @example * ```tsx * * ``` */ export function Banner({ type, children, avatar, className, actions, onClose, ...props }: PropsWithChildren>): ReactElement { const classes = classNames(styles.banner, className); const icon = useMemo((): ReactElement => { switch (type) { case "critical": return ; case "info": return ; case "success": return ; default: return ; } }, [type]); return (
{avatar ?? icon}
{children}
{actions} {onClose && ( )}
); }