{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rating",
  "title": "Rating",
  "description": "Stars for giving a score as a radio group, or for showing one read-only with fractional fills.",
  "dependencies": [
    "@radix-ui/react-radio-group",
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@corsair-ui/utils"
  ],
  "files": [
    {
      "path": "registry/default/ui/rating.tsx",
      "content": "\"use client\";\n\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\nimport { cva } from \"class-variance-authority\";\nimport { StarIcon } from \"lucide-react\";\nimport { useState, type ComponentProps } from \"react\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nconst ratingVariants = cva(\"inline-flex w-fit items-center\", {\n  variants: {\n    size: {\n      xs: \"gap-0.5 [&_[data-slot=rating-star]]:size-3\",\n      sm: \"gap-0.5 [&_[data-slot=rating-star]]:size-4\",\n      default: \"gap-0.5 [&_[data-slot=rating-star]]:size-5\",\n      lg: \"gap-1 [&_[data-slot=rating-star]]:size-6\",\n    },\n  },\n  defaultVariants: {\n    size: \"default\",\n  },\n});\n\ntype RatingSize = \"xs\" | \"sm\" | \"default\" | \"lg\";\n\nconst defaultValueLabel = (value: number, max: number) => `${value} out of ${max}`;\nconst defaultStarLabel = (stars: number) => `${stars} ${stars === 1 ? \"star\" : \"stars\"}`;\n\n/**\n * One star. `fill` goes from 0 to 1: the filled copy is clipped to that\n * share of the width, over an empty star. Both copies carry `data-filled`\n * so their colours can be changed from the Rating's className. Exported for\n * the animated variants of the rating, which draw the same star.\n */\nfunction RatingStar({ fill, className }: { fill: number; className?: string }) {\n  return (\n    <span\n      data-slot=\"rating-star\"\n      data-fill={fill >= 1 ? \"full\" : fill > 0 ? \"partial\" : \"empty\"}\n      className={cn(\"relative inline-flex shrink-0\", className)}\n    >\n      <StarIcon\n        aria-hidden=\"true\"\n        data-filled=\"false\"\n        className=\"text-muted-foreground/40 size-full fill-current\"\n      />\n      {fill > 0 ? (\n        <StarIcon\n          aria-hidden=\"true\"\n          data-filled=\"true\"\n          className=\"text-warning absolute inset-0 size-full fill-current\"\n          style={fill < 1 ? { clipPath: `inset(0 ${(1 - fill) * 100}% 0 0)` } : undefined}\n        />\n      ) : null}\n    </span>\n  );\n}\n\ninterface RatingProps extends Omit<\n  ComponentProps<\"div\">,\n  \"defaultValue\" | \"onChange\" | \"dir\" | \"children\"\n> {\n  /** Number of stars picked (controlled). Read-only ratings can be fractional, like 4.5. */\n  value?: number;\n  /** Number of stars picked at first (uncontrolled). */\n  defaultValue?: number;\n  onValueChange?: (value: number) => void;\n  /** Number of stars. */\n  max?: number;\n  /** Show the value without letting it change. */\n  readOnly?: boolean;\n  disabled?: boolean;\n  required?: boolean;\n  size?: RatingSize;\n  /** Submits the value with a form under this name. */\n  name?: string;\n  dir?: \"ltr\" | \"rtl\";\n  /** Accessible name of the rating. */\n  \"aria-label\"?: string;\n  /** Read-only: how the value is read to screen readers. */\n  getValueLabel?: (value: number, max: number) => string;\n  /** Interactive: the accessible name of each star. */\n  starLabel?: (stars: number) => string;\n}\n\n/**\n * Stars for giving or showing a score. Interactive, it is a radio group\n * with one radio per star: Tab reaches it, arrow keys change the score,\n * and each star is read as \"3 stars\"; pointing at a star with a mouse or a\n * pen previews it (`data-hovered`). With `readOnly` it is a single image\n * read as \"Rating: 4.5 out of 5\", and fractional values fill part of a star.\n * Filled stars use `text-warning`, empty ones `text-muted-foreground/40`;\n * restyle them with `[&_[data-filled=true]]:text-primary` on the Rating.\n * Nothing moves, so there is nothing to reduce for reduced motion. For a\n * finger sweeping the row, with motion, use `wave-rating`: same props.\n *\n * @example\n * <Rating defaultValue={3} onValueChange={setScore} aria-label=\"Your rating\" />\n * <Rating readOnly value={4.5} />\n */\nfunction Rating({\n  value: valueProp,\n  defaultValue = 0,\n  onValueChange,\n  max = 5,\n  readOnly = false,\n  disabled,\n  required,\n  size = \"default\",\n  name,\n  dir,\n  \"aria-label\": label = \"Rating\",\n  getValueLabel = defaultValueLabel,\n  starLabel = defaultStarLabel,\n  className,\n  ...props\n}: RatingProps) {\n  const [internal, setInternal] = useState(defaultValue);\n  const [hovered, setHovered] = useState<number | null>(null);\n  const count = Math.max(1, Math.floor(max));\n  const value = Math.min(Math.max(valueProp ?? internal, 0), count);\n  const stars = Array.from({ length: count }, (_, index) => index + 1);\n\n  if (readOnly) {\n    return (\n      <div\n        role=\"img\"\n        aria-label={`${label}: ${getValueLabel(value, count)}`}\n        data-slot=\"rating\"\n        data-readonly=\"\"\n        data-size={size}\n        data-value={value}\n        dir={dir}\n        className={cn(ratingVariants({ size }), className)}\n        {...props}\n      >\n        {stars.map((star) => (\n          <RatingStar key={star} fill={Math.min(Math.max(value - (star - 1), 0), 1)} />\n        ))}\n      </div>\n    );\n  }\n\n  const picked = Math.round(value);\n  const shown = hovered ?? picked;\n\n  const change = (next: string) => {\n    const number = Number(next);\n    if (valueProp === undefined) setInternal(number);\n    onValueChange?.(number);\n  };\n\n  return (\n    <RadioGroupPrimitive.Root\n      data-slot=\"rating\"\n      data-size={size}\n      data-value={picked}\n      data-hovered={hovered !== null ? \"\" : undefined}\n      aria-label={label}\n      value={picked > 0 ? String(picked) : \"\"}\n      onValueChange={change}\n      orientation=\"horizontal\"\n      loop={false}\n      disabled={disabled}\n      required={required}\n      name={name}\n      dir={dir}\n      className={cn(ratingVariants({ size }), className)}\n      onPointerLeave={() => setHovered(null)}\n      {...props}\n    >\n      {stars.map((star) => (\n        <RadioGroupPrimitive.Item\n          key={star}\n          value={String(star)}\n          aria-label={starLabel(star)}\n          data-slot=\"rating-item\"\n          data-hovered={hovered !== null && star <= hovered ? \"\" : undefined}\n          className={cn(\n            \"inline-flex cursor-pointer rounded-[4px] outline-none\",\n            \"focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n            \"disabled:cursor-not-allowed disabled:opacity-50\"\n          )}\n          onPointerEnter={(event) => {\n            // Mice and pens can point without pressing; a finger cannot.\n            if (event.pointerType !== \"touch\" && !disabled) setHovered(star);\n          }}\n        >\n          <RatingStar fill={star <= shown ? 1 : 0} />\n        </RadioGroupPrimitive.Item>\n      ))}\n    </RadioGroupPrimitive.Root>\n  );\n}\n\nexport { Rating, RatingStar, ratingVariants, type RatingProps, type RatingSize };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}