1import { cva, type VariantProps } from "class-variance-authority";
2import { Slot as SlotPrimitive } from "radix-ui";
3import type * as React from "react";
4import { cn } from "@/lib/utils";
5
6const statusVariants = cva(
7 "inline-flex w-fit shrink-0 items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-full border px-2.5 py-1 font-medium text-xs transition-colors",
8 {
9 variants: {
10 variant: {
11 default:
12 "border-transparent bg-muted text-muted-foreground **:data-[slot=status-indicator]:bg-muted-foreground",
13 success:
14 "border-green-500/20 bg-green-500/10 text-green-600 **:data-[slot=status-indicator]:bg-green-600 dark:text-green-400 **:data-[slot=status-indicator]:dark:bg-green-400",
15 error:
16 "border-destructive/20 bg-destructive/10 text-destructive **:data-[slot=status-indicator]:bg-destructive",
17 warning:
18 "border-orange-500/20 bg-orange-500/10 text-orange-600 **:data-[slot=status-indicator]:bg-orange-600 dark:text-orange-400 **:data-[slot=status-indicator]:dark:bg-orange-400",
19 info: "border-blue-500/20 bg-blue-500/10 text-blue-600 **:data-[slot=status-indicator]:bg-blue-600 dark:text-blue-400 **:data-[slot=status-indicator]:dark:bg-blue-400",
20 },
21 },
22 defaultVariants: {
23 variant: "default",
24 },
25 },
26);
27
28interface StatusProps
29 extends VariantProps<typeof statusVariants>,
30 React.ComponentProps<"div"> {
31 asChild?: boolean;
32}
33
34function Status(props: StatusProps) {
35 const { className, variant = "default", asChild, ...rootProps } = props;
36
37 const RootPrimitive = asChild ? SlotPrimitive.Slot : "div";
38
39 return (
40 <RootPrimitive
41 data-slot="status"
42 data-variant={variant}
43 {...rootProps}
44 className={cn(statusVariants({ variant }), className)}
45 />
46 );
47}
48
49function StatusIndicator(props: React.ComponentProps<"div">) {
50 const { className, ...indicatorProps } = props;
51
52 return (
53 <div
54 data-slot="status-indicator"
55 {...indicatorProps}
56 className={cn(
57 "relative flex size-2 shrink-0 rounded-full",
58 "before:absolute before:inset-0 before:animate-ping before:rounded-full before:bg-inherit",
59 "after:absolute after:inset-[2px] after:rounded-full after:bg-inherit",
60 className,
61 )}
62 />
63 );
64}
65
66function StatusLabel(props: React.ComponentProps<"div">) {
67 const { className, ...labelProps } = props;
68
69 return (
70 <div
71 data-slot="status-label"
72 {...labelProps}
73 className={cn("leading-none", className)}
74 />
75 );
76}
77
78export { Status, StatusIndicator, StatusLabel, statusVariants };
79