Installation

No MCP yet? Connect your agent.

Usage

import { Checkbox } from "@/components/ui/checkbox"
<Checkbox />

Examples

import { Checkbox } from '@/components/ui/checkbox';
import { Label } from '@/components/ui/label';
import { Text } from '@/components/ui/text';
import { cn } from '@/lib/utils';
import * as Haptics from 'expo-haptics';
import * as React from 'react';
import { Platform, View } from 'react-native';

export function CheckboxPreview() {
  const [state, setState] = React.useState({
    termsChecked: true,
    terms2Checked: true,
    toggleChecked: false,
    toggle2Checked: false,
  });

  function toggleCheckedState(key: keyof typeof state) {
    return () => {
      Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
      setState((prev) => ({
        ...prev,
        [key]: !prev[key],
      }));
    };
  }

  return (
    <View className="flex flex-col gap-6">
      <View className="flex flex-row items-center gap-3">
        <Checkbox
          id="terms"
          checked={state.termsChecked}
          onCheckedChange={toggleCheckedState('termsChecked')}
        />
        <Label
          onPress={Platform.select({ native: toggleCheckedState('termsChecked') })}
          htmlFor="terms">
          Accept terms and conditions
        </Label>
      </View>
      <View className="flex flex-row items-start gap-3">
        <Checkbox
          id="terms-2"
          checked={state.terms2Checked}
          onCheckedChange={toggleCheckedState('terms2Checked')}
        />
        <View className="flex-1 gap-2">
          <Label
            onPress={Platform.select({ native: toggleCheckedState('terms2Checked') })}
            htmlFor="terms-2">
            Accept terms and conditions
          </Label>
          <Text className="text-muted-foreground text-sm">
            By clicking this checkbox, you agree to the terms and conditions.
          </Text>
        </View>
      </View>
      <View className="flex flex-row items-start gap-3">
        <Checkbox
          id="toggle"
          disabled
          checked={state.toggleChecked}
          onCheckedChange={toggleCheckedState('toggleChecked')}
        />
        <Label
          onPress={Platform.select({ native: toggleCheckedState('toggleChecked') })}
          htmlFor="toggle"
          disabled>
          Enable notifications
        </Label>
      </View>
      <Label
        onPress={Platform.select({ native: toggleCheckedState('toggle2Checked') })}
        htmlFor="toggle-2"
        className={cn(
          'web:hover:bg-accent/50 border-border flex flex-row rounded-lg border p-3',
          state.toggle2Checked &&
            'web:hover:bg-blue-50 border-blue-600 bg-blue-50 dark:border-blue-900 dark:bg-blue-950'
        )}>
        <View className="flex flex-1 flex-row items-start gap-3">
          <Checkbox
            id="toggle-2"
            checked={state.toggle2Checked}
            onCheckedChange={toggleCheckedState('toggle2Checked')}
            checkedClassName="border-blue-600 bg-blue-600 dark:border-blue-700"
            indicatorClassName="bg-blue-600 dark:bg-blue-700"
            iconClassName="text-white"
          />
          <View className="flex-1">
            <Text className="text-sm font-medium leading-none">Enable notifications</Text>
            <Text className="text-muted-foreground text-sm">
              You can enable or disable notifications at any time.
            </Text>
          </View>
        </View>
      </Label>
    </View>
  );
}

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 });

Related items

Requires

  • A wrapper that renders any Lucide icon with utility classes and inherits the surrounding text color.

    ExpoUniversalExpo Go