{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "label",
"type": "registry:ui",
"title": "Label",
"description": "Form label text.",
"registryDependencies": [
"https://raw.githubusercontent.com/truongnat/rnui/main/registry/dist/nativewind/utils.json",
"https://raw.githubusercontent.com/truongnat/rnui/main/registry/dist/nativewind/text.json",
"https://raw.githubusercontent.com/truongnat/rnui/main/registry/dist/nativewind/theme.json"
],
"files": [
{
"path": "registry/shared/ui/label.tsx",
"type": "registry:ui",
"target": "components/ui/label.tsx",
"content": "import { useContext } from 'react';\nimport {\n Pressable,\n StyleSheet,\n Text as RNText,\n type TextStyle,\n} from 'react-native';\nimport { Text, type TextProps } from '@/components/ui/text';\nimport { cn, FormFieldContext, useThemeColor } from '@/lib/utils';\n\nexport interface LabelProps extends TextProps {\n className?: string;\n /** Appends a red asterisk `*` indicating the field is required. */\n required?: boolean;\n /** Appends a muted `(Optional)` text indicating the field is optional. */\n optional?: boolean;\n /** Dims the label — mirrors shadcn peer-disabled:opacity-50. */\n disabled?: boolean;\n /** Wrap in Pressable that focuses the sibling input via onPress */\n onPress?: () => void;\n}\n\nexport function Label({\n className,\n required = false,\n optional = false,\n disabled = false,\n onPress,\n children,\n style,\n ...props\n}: LabelProps) {\n const field = useContext(FormFieldContext);\n const theme = useThemeColor();\n const hasError = !!field?.error;\n\n const labelContent = (\n \n {children}\n {required ? (\n \n {' *'}\n \n ) : null}\n {optional ? (\n \n {' (Optional)'}\n \n ) : null}\n \n );\n\n if (onPress) {\n return (\n \n {labelContent}\n \n );\n }\n\n return labelContent;\n}\n\nconst styles = StyleSheet.create({\n requiredStar: {\n fontWeight: '700',\n },\n optionalText: {\n fontSize: 12,\n fontWeight: '400',\n },\n pressableWrapper: {\n alignSelf: 'flex-start',\n },\n});\n"
}
]
}