/* * 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 React, { type MouseEventHandler, type JSX, type PropsWithChildren, type HTMLAttributes, useId } from "react"; import classNames from "classnames"; import { IconButton } from "@vector-im/compound-web"; import CloseIcon from "@vector-im/compound-design-tokens/assets/web/icons/close"; import { Flex } from "../../utils/Flex"; import styles from "./Pill.module.css"; import { _t } from "../../utils/i18n"; export interface PillProps extends Omit, "onClick"> { /** * The text label to display inside the pill. */ label: string; /** * Optional click handler for a close button. * If provided, a close button will be rendered. */ onClick?: MouseEventHandler; } /** * A pill component that can display a label and an optional close button. * The badge can also contain child elements, such as icons or avatars. * * @example * ```tsx * console.log("Closed")}> * * * ``` */ export function Pill({ className, children, label, onClick, ...props }: PropsWithChildren): JSX.Element { const id = useId(); return ( {children} {label} {onClick && ( )} ); }