Text
A universal text component with consistent styling.
Installation
bash npx @moe/cli add text Copy/paste the following code to @/components/ui/text.tsx
import * as Slot from "@rn-primitives/slot";
import * as React from "react";
import { Text as RNText } from "react-native";
import { cn } from "@/lib/utils";
const TextClassContext = React.createContext<string | undefined>(undefined);
const Text = React.forwardRef<
React.ElementRef<typeof RNText>,
React.ComponentPropsWithoutRef<typeof RNText> & {
asChild?: boolean;
}
>(({ className, asChild = false, ...props }, ref) => {
const textClass = React.useContext(TextClassContext);
const Component = asChild ? Slot.Text : RNText;
return (
<Component
className={cn(
"text-base text-foreground web:select-text",
textClass,
className,
)}
ref={ref}
{...props}
/>
);
});
Text.displayName = "Text";
export { Text, TextClassContext };Usage
import { Text } from "@moe/registry/ui/text";
export function TextDemo() {
return <Text>Hello World</Text>;
}Variants
<Text className="text-xl font-bold">Large Bold</Text>
<Text className="text-muted-foreground">Muted text</Text>
<Text className="text-destructive">Error text</Text>Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |