import React from "react"; import classNames from "classnames"; import { Icon } from "../icon"; import { StyledProps } from "../_type"; import { useConfig } from "../_util/config-context"; import { createRocket } from "../_util/create-rocket"; import { forwardRefWithStatics } from "../_util/forward-ref-with-statics"; export interface TagProps extends StyledProps { /** * 标签内容 */ children: React.ReactNode; /** * 关闭时回调 * * **传递该参数时将展示关闭按钮** */ onClose?: (event: React.MouseEvent) => void; /** * 颜色主题 * * @default "default" */ theme?: "default" | "primary" | "success" | "warning" | "error"; /** * 是否为深色背景 * * @default false */ dark?: boolean; } export const TagGroup = createRocket("TagGroup", "div.@{prefix}-tag-group"); export const Tag = forwardRefWithStatics( function Tag( { children, onClose, className, theme, dark, ...props }: TagProps, ref: React.Ref ) { const hasCloseHandler = typeof onClose === "function"; const { classPrefix } = useConfig(); const classSuffix = dark ? "-dark" : ""; return (
{children} {hasCloseHandler && }
); }, { Group: TagGroup, } ); Tag.displayName = "Tag";