Label
Renders an accessible label associated with controls.
Installation
bash npx @moe/cli add label Install the following dependency:
npx expo install @rn-primitives/labelCopy/paste the following code to @/components/ui/label.tsx
import * as LabelPrimitive from "@rn-primitives/label";
import * as React from "react";
import { cn } from "@/lib/utils";
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Text>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Text>
>(
(
{ className, onPress, onLongPress, onPressIn, onPressOut, ...props },
ref,
) => (
<LabelPrimitive.Root
className="web:cursor-default"
onPress={onPress}
onLongPress={onLongPress}
onPressIn={onPressIn}
onPressOut={onPressOut}
>
<LabelPrimitive.Text
ref={ref}
className={cn(
"text-sm text-foreground native:text-base font-medium leading-none web:peer-disabled:cursor-not-allowed web:peer-disabled:opacity-70",
className,
)}
{...props}
/>
</LabelPrimitive.Root>
),
);
Label.displayName = LabelPrimitive.Root.displayName;
export { Label };Usage
import { Label } from "@moe/registry/ui/label";
import { Input } from "@moe/registry/ui/input";
import { View } from "react-native";
export function LabelDemo() {
return (
<View className="w-full max-w-sm items-start gap-1.5">
<Label nativeID="email">Email</Label>
<Input aria-labelledby="email" placeholder="Enter email" />
</View>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
nativeID | string | - | ID used to associate with input via aria-labelledby |