Installation

No MCP yet? Connect your agent.

Inheritance system

In React Native, child components don't automatically get styles from their parent. This causes issues for things like buttons, where the text inside should change based on the button's style.

To fix this, we use something called TextClassContext to pass styles down. The parent (like a Button) wraps its content with this context, and the Text component uses the styles from it.

import { Text, TextClassContext } from '@/components/ui/text';
import { View } from 'react-native';

export function TextCascadePreview() {
  return (
    <View className="items-center gap-2">
      {/* Default behavior without a parent `TextClassContext.Provider` */}
      <Text>
        Default: <Text variant="code">text-foreground</Text>
      </Text>
      <Parent>
        {/* Inherits the `TextClassContext.Provider` value from the `Parent` component and overrides the default `Text` component `className` */}
        <Text>
          Inherited from Parent: <Text variant="code">text-emerald-500</Text>
        </Text>
        <Text>
          {/* This `className` will override the `TextClassContext.Provider` value */}
          <Text className="text-purple-500">Overridden:</Text>{' '}
          <Text variant="code" className="text-purple-500">
            text-purple-500
          </Text>
        </Text>
        <NestedParent>
          {/* Inherits the `TextClassContext.Provider` value from the `OtherParent` component overrides the `TextClassContext.Provider` value from the `Parent` */}
          <Text>
            Inherited from NestedParent: <Text variant="code">text-sky-500</Text>
          </Text>
        </NestedParent>
      </Parent>
    </View>
  );
}

// Parent component that provides a `TextClassContext.Provider` value
function Parent({ children }: React.ComponentProps<typeof View>) {
  return (
    <TextClassContext.Provider value="text-emerald-500">
      <View className="items-center gap-2">{children}</View>
    </TextClassContext.Provider>
  );
}

// Nested parent component that overrides the `TextClassContext.Provider` value from the `Parent` component
function NestedParent({ children }: React.ComponentProps<typeof View>) {
  return (
    <TextClassContext.Provider value="text-sky-500">
      <View className="items-center gap-2">{children}</View>
    </TextClassContext.Provider>
  );
}

Usage

import { Text } from "@/components/ui/text"
<Text>Hello, world!</Text>

Typography

import { ScrollView, View } from 'react-native';
import { Text } from '@/components/ui/text';

export function TextTypographyPreview() {
  return (
    <ScrollView contentContainerClassName="p-6 native:pb-safe">
      <View className="native:pb-12 max-w-lg">
        <Text variant="h1">The Rainbow Forest Adventure</Text>
        <View className="p-1.5" />
        <Text variant="p">
          Once upon a time, in a magical forest, there lived a curious rabbit named Whiskers.
          Whiskers loved exploring and discovering new things every day.
        </Text>
        <View className="p-3" />
        <Text variant="h2">Whiskers' Discovery</Text>
        <Text variant="p">
          One day, while hopping through the forest, Whiskers stumbled upon{' '}
          <Text variant="p" className="font-medium">
            a mysterious rainbow-colored flower
          </Text>
          . The flower had the power to make the forest come alive with vibrant colors and happy
          creatures.
        </Text>
        <Text variant="blockquote">
          "Oh, what a wonderful discovery!" exclaimed Whiskers. "I must share this magic with all my
          forest friends!"
        </Text>
        <View className="p-4" />
        <Text variant="h3">The Colorful Transformation</Text>
        <View className="p-0.5" />
        <Text variant="p">
          Whiskers excitedly gathered all the animals in the forest and showed them the magical
          rainbow flower. The animals were amazed and decided to plant more of these flowers to make
          their home even more magical.
        </Text>
        <View className="p-1.5" />
        <Text variant="p">
          As the rainbow flowers bloomed, the entire forest transformed into a kaleidoscope of
          colors. Birds chirped in harmony, butterflies danced in the air, and even the trees swayed
          to the rhythm of the wind.
        </Text>
        <View className="p-3" />
        <Text variant="h3">The Enchanted Celebration</Text>
        <View className="p-0.5" />
        <Text variant="p">
          The animals decided to celebrate their enchanted forest with a grand feast. They gathered
          nuts, berries, and fruits from the colorful trees and shared stories of their adventures.
          The joyous laughter echoed through the Rainbow Forest.
        </Text>
        <View className="p-1.5" />
        <Text variant="lead">
          And so, the Rainbow Forest became a place of wonder and happiness, where Whiskers and all
          the animals lived together in harmony.
        </Text>
        <View className="p-3" />
        <Text variant="h3">The Never-ending Magic</Text>
        <View className="p-0.5" />
        <Text variant="p">
          The magic of the rainbow flowers continued to spread, reaching other parts of the world.
          Soon, forests everywhere became vibrant and alive, thanks to the discovery of Whiskers and
          the enchanted Rainbow Forest.
        </Text>
        <View className="p-1.5" />
        <Text variant="large">
          The moral of the story is: embrace the magic of discovery, share joy with others, and
          watch as the world transforms into a colorful and beautiful place.
        </Text>
        <View className="p-3" />
      </View>
    </ScrollView>
  );
}

Examples

import { Text } from '@/components/ui/text';

export function TextPreview() {
  return <Text>Hello, world!</Text>;
}

Agent guide

Add the cn helper and the theme color variables the files useWhen: The project has no components.json file.From the collection

The files import cn from @/lib/utils:

import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

Class names such as bg-background, text-muted-foreground, border-border, bg-primary, and rounded-lg resolve through these theme variables. Define them in the global CSS and map each color in the Tailwind theme as hsl(var(--name)), with --radius mapped to borderRadius.lg (md is calc(var(--radius) - 2px), sm is calc(var(--radius) - 4px)).

Light:

VariableValue
--backgroundhsl(0 0% 100%)
--foregroundhsl(0 0% 3.9%)
--cardhsl(0 0% 100%)
--card-foregroundhsl(0 0% 3.9%)
--popoverhsl(0 0% 100%)
--popover-foregroundhsl(0 0% 3.9%)
--primaryhsl(0 0% 9%)
--primary-foregroundhsl(0 0% 98%)
--secondaryhsl(0 0% 96.1%)
--secondary-foregroundhsl(0 0% 9%)
--mutedhsl(0 0% 96.1%)
--muted-foregroundhsl(0 0% 45.1%)
--accenthsl(0 0% 96.1%)
--accent-foregroundhsl(0 0% 9%)
--destructivehsl(0 84.2% 60.2%)
--borderhsl(0 0% 89.8%)
--inputhsl(0 0% 89.8%)
--ringhsl(0 0% 63%)
--radius0.625rem

Dark:

VariableValue
--backgroundhsl(0 0% 3.9%)
--foregroundhsl(0 0% 98%)
--cardhsl(0 0% 3.9%)
--card-foregroundhsl(0 0% 98%)
--popoverhsl(0 0% 3.9%)
--popover-foregroundhsl(0 0% 98%)
--primaryhsl(0 0% 98%)
--primary-foregroundhsl(0 0% 9%)
--secondaryhsl(0 0% 14.9%)
--secondary-foregroundhsl(0 0% 98%)
--mutedhsl(0 0% 14.9%)
--muted-foregroundhsl(0 0% 63.9%)
--accenthsl(0 0% 14.9%)
--accent-foregroundhsl(0 0% 98%)
--destructivehsl(0 70.9% 59.4%)
--borderhsl(0 0% 14.9%)
--inputhsl(0 0% 14.9%)
--ringhsl(300 0% 45%)
--radius0.625rem

Nativewind projects: the files assume 1rem is 16px, so pass inlineRem: 16 to Nativewind in metro.config.js:

module.exports = withNativeWind(config, { input: './global.css', inlineRem: 16 });