{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "rating", "type": "registry:ui", "title": "Rating", "description": "Star rating input/display.", "registryDependencies": [ "https://raw.githubusercontent.com/truongnat/rnui/main/registry/dist/nativewind/utils.json", "https://raw.githubusercontent.com/truongnat/rnui/main/registry/dist/nativewind/theme.json" ], "dependencies": [ "lucide-react-native" ], "files": [ { "path": "registry/shared/ui/rating.tsx", "type": "registry:ui", "target": "components/ui/rating.tsx", "content": "import { useState } from 'react';\nimport { Pressable, View, type ViewProps } from 'react-native';\nimport { Star } from 'lucide-react-native';\nimport { cn, useThemeColor } from '@/lib/utils';\n\nexport interface RatingProps extends ViewProps {\n value?: number;\n defaultValue?: number;\n onChange?: (value: number) => void;\n max?: number;\n size?: number;\n /** Read-only display mode. */\n readonly?: boolean;\n /** Filled star color — defaults to amber (#f59e0b). */\n color?: string;\n /** Empty star color — defaults to `border` theme token. */\n emptyColor?: string;\n disabled?: boolean;\n className?: string;\n}\n\nexport function Rating({\n value: controlledValue,\n defaultValue = 0,\n onChange,\n max = 5,\n size = 24,\n readonly = false,\n color = '#f59e0b',\n emptyColor,\n disabled = false,\n className,\n ...props\n}: RatingProps) {\n const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);\n const isControlled = controlledValue !== undefined;\n const value = isControlled ? controlledValue : uncontrolledValue;\n\n const colors = useThemeColor();\n const empty = emptyColor ?? colors.border;\n const interactive = !readonly && !disabled;\n\n const handleSelect = (starVal: number) => {\n if (!interactive) return;\n const next = value === starVal ? 0 : starVal;\n if (!isControlled) {\n setUncontrolledValue(next);\n }\n onChange?.(next);\n };\n\n return (\n \n {Array.from({ length: max }).map((_, i) => {\n const starVal = i + 1;\n const filled = starVal <= Math.round(value);\n const star = (\n \n );\n return interactive ? (\n handleSelect(starVal)}\n >\n {star}\n \n ) : (\n // biome-ignore lint/suspicious/noArrayIndexKey: star positions are stable\n {star}\n );\n })}\n \n );\n}\n" } ] }