All files / src/ahuora-design-system/ui ui-status-indicator.tsx

80% Statements 4/5
75% Branches 3/4
100% Functions 1/1
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65              33x                                                             17468x   17468x 17468x                                              
import * as React from "react";
import { cn } from "@/lib/utils";
import { ToolTipCover } from "./tooltip.tsx";
import { cva, type VariantProps } from "class-variance-authority";
import { AlertIcon } from "../componentIcons/AlertIcon.tsx";
import { CheckIcon } from "../componentIcons/CheckIcon.tsx";
 
const statusIndicatorVariants = cva("inline-flex items-center justify-center", {
  variants: {
    variant: {
      success: "text-[hsl(var(--success))]",
      error: "text-[hsl(var(--destructive))]",
    },
    size: {
      sm: "h-4 w-4",
      md: "h-6 w-6",
      lg: "h-8 w-8",
    },
  },
  defaultVariants: {
    variant: "success",
    size: "md",
  },
});
 
interface StatusIndicatorProps
  extends React.HTMLAttributes<HTMLDivElement>,
    VariantProps<typeof statusIndicatorVariants> {
  tooltip?: React.ReactNode;
}
 
function StatusIndicator({
  className,
  variant = "success",
  size,
  tooltip,
  ...props
}: StatusIndicatorProps) {
  const icon = variant === "success" ? <CheckIcon /> : <AlertIcon />;
 
  if (tooltip) {
    return (
      <ToolTipCover asChild content={tooltip} variant={variant}>
        <div
          className={cn(statusIndicatorVariants({ variant, size }), className)}
          {...props}
        >
          {icon}
        </div>
      </ToolTipCover>
    );
  }
 
  return (
    <div
      className={cn(statusIndicatorVariants({ variant, size }), className)}
      {...props}
    >
      {icon}
    </div>
  );
}
 
export { StatusIndicator, type StatusIndicatorProps };