{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rating-group",
  "title": "Rating Group",
  "description": "A shadcn-style rating group component built with Ark UI primitives.",
  "dependencies": ["@ark-ui/react", "lucide-react"],
  "files": [
    {
      "path": "src/components/ui/rating-group.tsx",
      "content": "\"use client\";\n\nimport {\n  RatingGroup as RatingGroupPrimitive,\n  useRatingGroup,\n  useRatingGroupContext,\n} from \"@ark-ui/react/rating-group\";\nimport { StarIcon } from \"lucide-react\";\nimport { type ComponentProps, type CSSProperties, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport { useRatingGroup, useRatingGroupContext };\n\nexport type RatingGroupProps = ComponentProps<typeof RatingGroupPrimitive.Root>;\n\nexport const RatingGroup = ({\n  className,\n  children,\n  ...props\n}: RatingGroupProps) => (\n  <RatingGroupPrimitive.Root\n    className={cn(\n      \"group/rating-group flex flex-col gap-1.5 text-foreground\",\n      \"data-readonly:pointer-events-none\",\n      className,\n    )}\n    data-slot=\"rating-group\"\n    {...props}\n  >\n    {children}\n    <RatingGroupPrimitive.HiddenInput />\n  </RatingGroupPrimitive.Root>\n);\n\nexport type RatingGroupLabelProps = ComponentProps<\n  typeof RatingGroupPrimitive.Label\n>;\n\nexport const RatingGroupLabel = ({\n  className,\n  ...props\n}: RatingGroupLabelProps) => (\n  <RatingGroupPrimitive.Label\n    className={cn(\n      \"text-sm font-medium text-foreground leading-none select-none\",\n      \"data-disabled:pointer-events-none data-disabled:opacity-50\",\n      className,\n    )}\n    data-slot=\"rating-group-label\"\n    {...props}\n  />\n);\n\nexport type RatingGroupControlProps = ComponentProps<\n  typeof RatingGroupPrimitive.Control\n>;\n\nexport const RatingGroupControl = ({\n  className,\n  ...props\n}: RatingGroupControlProps) => (\n  <RatingGroupPrimitive.Control\n    className={cn(\"inline-flex items-center gap-0.5\", className)}\n    data-slot=\"rating-group-control\"\n    {...props}\n  />\n);\n\nexport type RatingGroupItemProps = ComponentProps<\n  typeof RatingGroupPrimitive.Item\n>;\n\nexport const RatingGroupItem = ({\n  className,\n  ...props\n}: RatingGroupItemProps) => (\n  <RatingGroupPrimitive.Item\n    className={cn(\n      \"inline-flex cursor-pointer items-center justify-center rounded-sm outline-none\",\n      \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n      \"data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n      className,\n    )}\n    data-slot=\"rating-group-item\"\n    {...props}\n  />\n);\n\nexport type RatingGroupItemContextProps = ComponentProps<\n  typeof RatingGroupPrimitive.ItemContext\n>;\n\nexport const RatingGroupItemContext = (props: RatingGroupItemContextProps) => (\n  <RatingGroupPrimitive.ItemContext {...props} />\n);\n\nexport type RatingGroupContextProps = ComponentProps<\n  typeof RatingGroupPrimitive.Context\n>;\n\nexport const RatingGroupContext = (props: RatingGroupContextProps) => (\n  <RatingGroupPrimitive.Context {...props} />\n);\n\nexport type RatingGroupRootProviderProps = ComponentProps<\n  typeof RatingGroupPrimitive.RootProvider\n>;\n\nexport const RatingGroupRootProvider = ({\n  className,\n  children,\n  ...props\n}: RatingGroupRootProviderProps) => (\n  <RatingGroupPrimitive.RootProvider\n    className={cn(\n      \"group/rating-group flex flex-col gap-1.5 text-foreground\",\n      \"data-readonly:pointer-events-none\",\n      className,\n    )}\n    data-slot=\"rating-group-root-provider\"\n    {...props}\n  >\n    {children}\n    <RatingGroupPrimitive.HiddenInput />\n  </RatingGroupPrimitive.RootProvider>\n);\n\n/** Layout + colors only; fg fill clip is `style.clipPath` (Tailwind rule order is unreliable for this cascade). */\nexport const ratingGroupStarIndicatorClassName = cn(\n  \"relative inline-flex size-5 shrink-0\",\n  \"[&_svg]:pointer-events-none [&_svg]:absolute [&_svg]:inset-0 [&_svg]:size-full\",\n  \"**:data-bg:text-muted-foreground\",\n  \"**:data-fg:text-chart-1\",\n);\n\n/** Same result as Ark `.ItemIndicator` clip rules, without relying on stylesheet order. */\nconst ratingStarForegroundClipPath = (\n  highlighted: boolean,\n  half: boolean,\n): NonNullable<CSSProperties[\"clipPath\"]> =>\n  !highlighted\n    ? \"inset(0 100% 0 0)\"\n    : half\n      ? \"inset(0 50% 0 0)\"\n      : \"inset(0 0 0 0)\";\n\nconst RatingStarIndicator = ({\n  half,\n  highlighted,\n}: {\n  half?: boolean;\n  highlighted?: boolean;\n}) => {\n  const hi = Boolean(highlighted);\n  const h = Boolean(half);\n  return (\n    <span className={ratingGroupStarIndicatorClassName}>\n      <StarIcon aria-hidden data-bg=\"\" />\n      <StarIcon\n        aria-hidden\n        data-fg=\"\"\n        fill=\"currentColor\"\n        style={{ clipPath: ratingStarForegroundClipPath(hi, h) }}\n      />\n    </span>\n  );\n};\n\nexport const RatingStars = ({\n  withHalf = false,\n  children,\n}: {\n  withHalf?: boolean;\n  children?: (item: number, half: boolean, highlighted: boolean) => ReactNode;\n}) => (\n  <RatingGroupControl>\n    <RatingGroupContext>\n      {({ items }) =>\n        items.map((item) => (\n          <RatingGroupItem index={item} key={item}>\n            <RatingGroupItemContext>\n              {children\n                ? ({ half, highlighted }) => children(item, half, highlighted)\n                : withHalf\n                  ? ({ half, highlighted }) => (\n                      <RatingStarIndicator\n                        half={half}\n                        highlighted={highlighted}\n                      />\n                    )\n                  : ({ highlighted }) => (\n                      <RatingStarIndicator highlighted={highlighted} />\n                    )}\n            </RatingGroupItemContext>\n          </RatingGroupItem>\n        ))\n      }\n    </RatingGroupContext>\n  </RatingGroupControl>\n);\n",
      "type": "registry:ui",
      "target": "src/components/ui/rating-group.tsx"
    }
  ],
  "type": "registry:ui"
}
