2023-03-14 12:34:41 +00:00
|
|
|
import type { VariantProps } from "class-variance-authority";
|
|
|
|
import { cva } from "class-variance-authority";
|
|
|
|
import type { ComponentProps, ReactNode } from "react";
|
2022-11-04 15:40:46 +00:00
|
|
|
import { GoPrimitiveDot } from "react-icons/go";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { SVGComponent } from "@calcom/types/SVGComponent";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2023-03-14 12:34:41 +00:00
|
|
|
const badgeStyles = cva("font-medium inline-flex items-center justify-center rounded gap-x-1", {
|
|
|
|
variants: {
|
|
|
|
variant: {
|
|
|
|
default: "bg-orange-100 text-orange-800",
|
|
|
|
warning: "bg-orange-100 text-orange-800",
|
|
|
|
orange: "bg-orange-100 text-orange-800",
|
|
|
|
success: "bg-green-100 text-green-800",
|
|
|
|
green: "bg-green-100 text-green-800",
|
|
|
|
gray: "bg-gray-100 text-gray-800 dark:bg-darkgray-200 dark:text-darkgray-800 group-hover:bg-gray-200 dark:group-hover:bg-darkgray-300",
|
|
|
|
blue: "bg-blue-100 text-blue-800",
|
|
|
|
red: "bg-red-100 text-red-800",
|
|
|
|
error: "bg-red-100 text-red-800",
|
|
|
|
},
|
|
|
|
size: {
|
2023-03-16 11:51:40 +00:00
|
|
|
sm: "px-1 py-0.5 text-xs leading-3",
|
|
|
|
md: "py-1 px-1.5 text-xs leading-3",
|
|
|
|
lg: "py-1 px-2 text-sm leading-4",
|
2023-03-14 12:34:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
defaultVariants: {
|
|
|
|
variant: "default",
|
2023-03-16 11:51:40 +00:00
|
|
|
size: "md",
|
2023-03-14 12:34:41 +00:00
|
|
|
},
|
|
|
|
});
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2023-03-14 12:34:41 +00:00
|
|
|
type InferredBadgeStyles = VariantProps<typeof badgeStyles>;
|
|
|
|
|
|
|
|
type IconOrDot =
|
|
|
|
| {
|
|
|
|
startIcon?: SVGComponent;
|
|
|
|
withDot?: unknown;
|
|
|
|
}
|
|
|
|
| { startIcon?: unknown; withDot?: boolean };
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2023-03-14 12:34:41 +00:00
|
|
|
export type BadgeProps = InferredBadgeStyles &
|
|
|
|
ComponentProps<"div"> & { children: ReactNode; rounded?: boolean } & IconOrDot;
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
export const Badge = function Badge(props: BadgeProps) {
|
2023-03-14 12:34:41 +00:00
|
|
|
const { variant, className, size, startIcon, withDot, children, rounded, ...passThroughProps } = props;
|
|
|
|
const StartIcon = startIcon ? (startIcon as SVGComponent) : undefined;
|
2022-07-23 00:39:50 +00:00
|
|
|
return (
|
|
|
|
<div
|
2023-03-14 12:34:41 +00:00
|
|
|
className={classNames(badgeStyles({ variant, size }), rounded && "h-5 w-5 rounded-full p-0", className)}
|
|
|
|
{...passThroughProps}>
|
|
|
|
{withDot ? <GoPrimitiveDot className="h-3 w-3 stroke-[3px]" /> : null}
|
|
|
|
{StartIcon ? <StartIcon className="h-3 w-3 stroke-[3px]" /> : null}
|
|
|
|
<div>{children}</div>
|
2022-07-23 00:39:50 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|