Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

2.3 KB
Raw Blame
import * as React from "react";
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";

import { cn } from "../../utils";

function RadioGroup({
  className,
  ...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
  return (
    <RadioGroupPrimitive.Root
      data-slot="radio-group"
      className={cn("grid w-full gap-2", className)}
      {...props}
    />
  );
}

type RadioGroupItemProps = React.ComponentProps<typeof RadioGroupPrimitive.Item> & {
  isError?: boolean;
};

function RadioGroupItem({ className, isError, ...props }: RadioGroupItemProps) {
  return (
    <RadioGroupPrimitive.Item
      data-slot="radio-group-item"
      aria-invalid={isError}
      className={cn(
        "peer relative flex aspect-square size-4 shrink-0 cursor-pointer items-center justify-center rounded-full border border-border bg-transparent text-foreground shadow-xs transition-colors outline-none",
        "after:absolute after:-inset-x-3 after:-inset-y-2",
        "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
        "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
        "aria-invalid:border-danger aria-invalid:ring-danger/40",
        "hover:border-foreground/30",
        "data-[state=checked]:border-project data-[state=checked]:bg-project",
        "in-data-[slot=button]:border-(--control-variant-border-color) in-data-[slot=button]:hover:border-(--control-variant-border-color)",
        "in-data-[slot=button]:data-[state=checked]:border-(--control-variant-color) in-data-[slot=button]:data-[state=checked]:bg-(--control-variant-color)",
        "in-data-[slot=field-label]:border-(--control-variant-border-color) in-data-[slot=field-label]:hover:border-(--control-variant-border-color)",
        "in-data-[slot=field-label]:data-[state=checked]:border-(--control-variant-color) in-data-[slot=field-label]:data-[state=checked]:bg-(--control-variant-color)",
        className
      )}
      {...props}
    >
      <RadioGroupPrimitive.Indicator
        data-slot="radio-group-indicator"
        className="flex size-4 items-center justify-center"
      >
        <span className="size-2 rounded-full bg-black" />
      </RadioGroupPrimitive.Indicator>
    </RadioGroupPrimitive.Item>
  );
}

export { RadioGroup, RadioGroupItem };