2026-01-27 13:54:22 +05:30
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
* See the LICENSE file for details.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-11-25 21:21:03 +05:30
|
|
|
import * as React from "react";
|
2024-04-29 00:51:31 +05:30
|
|
|
// helpers
|
2025-08-11 18:42:51 +05:30
|
|
|
import { cn } from "../utils";
|
2025-11-13 04:11:06 -08:00
|
|
|
import type { TBadgeVariant, TBadgeSizes } from "./helper";
|
|
|
|
|
import { getIconStyling, getBadgeStyling } from "./helper";
|
2023-11-25 21:21:03 +05:30
|
|
|
|
2023-12-10 15:48:10 +05:30
|
|
|
export interface BadgeProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
2023-11-25 21:21:03 +05:30
|
|
|
variant?: TBadgeVariant;
|
|
|
|
|
size?: TBadgeSizes;
|
|
|
|
|
className?: string;
|
|
|
|
|
loading?: boolean;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
appendIcon?: any;
|
|
|
|
|
prependIcon?: any;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-20 19:09:40 +07:00
|
|
|
const Badge = React.forwardRef(function Badge(props: BadgeProps, ref: React.ForwardedRef<HTMLButtonElement>) {
|
2023-11-25 21:21:03 +05:30
|
|
|
const {
|
|
|
|
|
variant = "primary",
|
|
|
|
|
size = "md",
|
|
|
|
|
className = "",
|
|
|
|
|
type = "button",
|
|
|
|
|
loading = false,
|
|
|
|
|
disabled = false,
|
|
|
|
|
prependIcon = null,
|
|
|
|
|
appendIcon = null,
|
|
|
|
|
children,
|
|
|
|
|
...rest
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const buttonStyle = getBadgeStyling(variant, size, disabled || loading);
|
|
|
|
|
const buttonIconStyle = getIconStyling(size);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-04-29 00:51:31 +05:30
|
|
|
<button ref={ref} type={type} className={cn(buttonStyle, className)} disabled={disabled || loading} {...rest}>
|
2023-12-10 15:48:10 +05:30
|
|
|
{prependIcon && <div className={buttonIconStyle}>{React.cloneElement(prependIcon, { strokeWidth: 2 })}</div>}
|
2023-11-25 21:21:03 +05:30
|
|
|
{children}
|
2023-12-10 15:48:10 +05:30
|
|
|
{appendIcon && <div className={buttonIconStyle}>{React.cloneElement(appendIcon, { strokeWidth: 2 })}</div>}
|
2023-11-25 21:21:03 +05:30
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Badge.displayName = "plane-ui-badge";
|
|
|
|
|
|
|
|
|
|
export { Badge };
|