- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
import {
Pressable,
type PressableProps,
Text,
type TextStyle,
type ViewStyle,
} from "react-native";
import { type ThemeColors, useThemeColors } from "@/lib/theme";
import { cn } from "@/lib/utils";
type SizeKey =
| "xs"
| "sm"
| "default"
| "lg"
| "icon-xs"
| "icon-sm"
| "icon"
| "icon-lg";
const sizeDim: Record<SizeKey, { height: number; width?: number }> = {
default: { height: 48 },
icon: { height: 48, width: 48 },
"icon-lg": { height: 51, width: 51 },
"icon-sm": { height: 44, width: 44 },
"icon-xs": { height: 40, width: 40 },
lg: { height: 51 },
sm: { height: 44 },
xs: { height: 40 },
};
const shadowXs: ViewStyle = {
boxShadow: "0px 1px 2px 0px rgba(0, 0, 0, 0.05)",
};
const buttonVariants = cva(
"shrink-0 flex-row items-center justify-center gap-2 rounded-md",
{
defaultVariants: { size: "default" },
variants: {
size: {
default: "px-6",
icon: "p-0",
"icon-lg": "p-0",
"icon-sm": "p-0",
"icon-xs": "p-0",
lg: "px-8",
sm: "gap-1.5 px-5",
xs: "gap-1 px-4",
},
},
}
);
interface VariantStyle {
base: ViewStyle;
pressed: ViewStyle;
textBase: TextStyle;
textPressed: TextStyle;
}
export type ButtonVariant =
| "default"
| "secondary"
| "outline"
| "ghost"
| "destructive"
| "link";
function getVariantStyle(variant: ButtonVariant, c: ThemeColors): VariantStyle {
switch (variant) {
case "secondary":
return {
base: { backgroundColor: c.secondary, ...shadowXs },
pressed: { backgroundColor: c.secondaryHover },
textBase: { color: c.secondaryForeground },
textPressed: { color: c.secondaryForeground },
};
case "outline":
return {
base: {
backgroundColor: "transparent",
borderColor: c.border,
borderWidth: 1,
...shadowXs,
},
pressed: { backgroundColor: c.accent },
textBase: { color: c.foreground },
textPressed: { color: c.accentForeground },
};
case "ghost":
return {
base: { backgroundColor: "transparent" },
pressed: { backgroundColor: c.accent },
textBase: { color: c.foreground },
textPressed: { color: c.accentForeground },
};
case "destructive":
return {
base: { backgroundColor: c.destructive, ...shadowXs },
pressed: { backgroundColor: c.destructiveHover },
textBase: { color: c.destructiveForeground },
textPressed: { color: c.destructiveForeground },
};
case "link":
return {
base: { backgroundColor: "transparent" },
pressed: {},
textBase: {
borderBottomColor: "transparent",
borderBottomWidth: 1,
color: c.primary,
paddingBottom: 1,
},
textPressed: {
borderBottomColor: c.primary,
},
};
default:
return {
base: { backgroundColor: c.primary, ...shadowXs },
pressed: { backgroundColor: c.primaryHover },
textBase: { color: c.primaryForeground },
textPressed: { color: c.primaryForeground },
};
}
}
export interface ButtonProps
extends Omit<PressableProps, "children" | "style">,
VariantProps<typeof buttonVariants> {
children?: React.ReactNode;
style?: ViewStyle;
variant?: ButtonVariant;
}
function Button({
className,
variant = "default",
size,
children,
disabled,
style,
onPressIn,
onPressOut,
...props
}: ButtonProps) {
const colors = useThemeColors();
const [pressed, setPressed] = React.useState(false);
const vs = getVariantStyle(variant, colors);
const dim = sizeDim[(size ?? "default") as SizeKey] ?? sizeDim.default;
const containerStyle: ViewStyle = {
borderRadius: 8,
height: dim.height,
...(dim.width === undefined ? null : { width: dim.width }),
...vs.base,
...(pressed && !disabled ? vs.pressed : null),
...style,
};
const finalTextStyle: TextStyle = {
...vs.textBase,
...(pressed && !disabled ? vs.textPressed : null),
};
return (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: !!disabled }}
className={cn(
buttonVariants({ size }),
disabled && "opacity-50",
className
)}
disabled={disabled}
onPressIn={(e) => {
setPressed(true);
onPressIn?.(e);
}}
onPressOut={(e) => {
setPressed(false);
onPressOut?.(e);
}}
style={containerStyle}
{...props}
>
{React.Children.map(children, (child) =>
typeof child === "string" || typeof child === "number" ? (
<Text style={finalTextStyle}>{child}</Text>
) : (
child
)
)}
</Pressable>
);
}
export { Button, buttonVariants };Buttons for React Native apps that run on Android and iOS via Expo. They share the design tokens and variants of the web Button, with interaction adapted for touch.
Installation
$ bunx --bun frakment add button --expo$ npx frakment add button --expo$ pnpm dlx frakment add button --expo$ yarn dlx frakment add button --expo
Install the following dependencies:
$ bun add class-variance-authority clsx tailwind-merge$ npm install class-variance-authority clsx tailwind-merge$ pnpm add class-variance-authority clsx tailwind-merge$ yarn add class-variance-authority clsx tailwind-merge
Configure NativeWind in your Expo project.
Skip this step if your project already uses NativeWind v5. The project needs a babel.config.js with babel-preset-expo, a metro.config.js wrapped with withNativewind, and a global.css that imports tailwindcss/theme.css, tailwindcss/utilities.css, and nativewind/theme. Import global.css in the root layout.
Copy lib/utils.ts into your project.
import type { ClassValue } from "clsx";
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));Copy lib/theme.ts into your project.
import { useColorScheme } from "react-native";
export interface ThemeColors {
accent: string;
accentForeground: string;
background: string;
border: string;
destructive: string;
destructiveForeground: string;
destructiveHover: string;
foreground: string;
input: string;
mutedForeground: string;
primary: string;
primaryForeground: string;
primaryHover: string;
secondary: string;
secondaryForeground: string;
secondaryHover: string;
}
const lightColors: ThemeColors = {
accent: "rgba(245, 245, 245, 1)",
accentForeground: "rgba(23, 23, 23, 1)",
background: "rgba(255, 255, 255, 1)",
border: "rgba(229, 229, 229, 1)",
destructive: "rgba(239, 68, 68, 1)",
destructiveForeground: "rgba(255, 255, 255, 1)",
destructiveHover: "rgba(240, 86, 86, 1)",
foreground: "rgba(10, 10, 10, 1)",
input: "rgba(227, 227, 227, 1)",
mutedForeground: "rgba(102, 102, 102, 1)",
primary: "rgba(23, 23, 23, 1)",
primaryForeground: "rgba(250, 250, 250, 1)",
primaryHover: "rgba(46, 46, 46, 1)",
secondary: "rgba(245, 245, 245, 1)",
secondaryForeground: "rgba(23, 23, 23, 1)",
secondaryHover: "rgba(247, 247, 247, 1)",
};
const darkColors: ThemeColors = {
accent: "rgba(64, 64, 64, 1)",
accentForeground: "rgba(250, 250, 250, 1)",
background: "rgba(10, 10, 10, 1)",
border: "rgba(255, 255, 255, 0.1)",
destructive: "rgba(248, 113, 113, 1)",
destructiveForeground: "rgba(255, 255, 255, 1)",
destructiveHover: "rgba(224, 102, 102, 1)",
foreground: "rgba(250, 250, 250, 1)",
input: "rgba(255, 255, 255, 0.15)",
mutedForeground: "rgba(163, 163, 163, 1)",
primary: "rgba(229, 229, 229, 1)",
primaryForeground: "rgba(23, 23, 23, 1)",
primaryHover: "rgba(207, 207, 207, 1)",
secondary: "rgba(38, 38, 38, 1)",
secondaryForeground: "rgba(250, 250, 250, 1)",
secondaryHover: "rgba(33, 33, 33, 1)",
};
export function useThemeColors(): ThemeColors {
const scheme = useColorScheme();
return scheme === "dark" ? darkColors : lightColors;
}Copy the button into your project.
import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
import {
Pressable,
type PressableProps,
Text,
type TextStyle,
type ViewStyle,
} from "react-native";
import { type ThemeColors, useThemeColors } from "@/lib/theme";
import { cn } from "@/lib/utils";
type SizeKey =
| "xs"
| "sm"
| "default"
| "lg"
| "icon-xs"
| "icon-sm"
| "icon"
| "icon-lg";
const sizeDim: Record<SizeKey, { height: number; width?: number }> = {
default: { height: 48 },
icon: { height: 48, width: 48 },
"icon-lg": { height: 51, width: 51 },
"icon-sm": { height: 44, width: 44 },
"icon-xs": { height: 40, width: 40 },
lg: { height: 51 },
sm: { height: 44 },
xs: { height: 40 },
};
const shadowXs: ViewStyle = {
boxShadow: "0px 1px 2px 0px rgba(0, 0, 0, 0.05)",
};
const buttonVariants = cva(
"shrink-0 flex-row items-center justify-center gap-2 rounded-md",
{
defaultVariants: { size: "default" },
variants: {
size: {
default: "px-6",
icon: "p-0",
"icon-lg": "p-0",
"icon-sm": "p-0",
"icon-xs": "p-0",
lg: "px-8",
sm: "gap-1.5 px-5",
xs: "gap-1 px-4",
},
},
}
);
interface VariantStyle {
base: ViewStyle;
pressed: ViewStyle;
textBase: TextStyle;
textPressed: TextStyle;
}
export type ButtonVariant =
| "default"
| "secondary"
| "outline"
| "ghost"
| "destructive"
| "link";
function getVariantStyle(variant: ButtonVariant, c: ThemeColors): VariantStyle {
switch (variant) {
case "secondary":
return {
base: { backgroundColor: c.secondary, ...shadowXs },
pressed: { backgroundColor: c.secondaryHover },
textBase: { color: c.secondaryForeground },
textPressed: { color: c.secondaryForeground },
};
case "outline":
return {
base: {
backgroundColor: "transparent",
borderColor: c.border,
borderWidth: 1,
...shadowXs,
},
pressed: { backgroundColor: c.accent },
textBase: { color: c.foreground },
textPressed: { color: c.accentForeground },
};
case "ghost":
return {
base: { backgroundColor: "transparent" },
pressed: { backgroundColor: c.accent },
textBase: { color: c.foreground },
textPressed: { color: c.accentForeground },
};
case "destructive":
return {
base: { backgroundColor: c.destructive, ...shadowXs },
pressed: { backgroundColor: c.destructiveHover },
textBase: { color: c.destructiveForeground },
textPressed: { color: c.destructiveForeground },
};
case "link":
return {
base: { backgroundColor: "transparent" },
pressed: {},
textBase: {
borderBottomColor: "transparent",
borderBottomWidth: 1,
color: c.primary,
paddingBottom: 1,
},
textPressed: {
borderBottomColor: c.primary,
},
};
default:
return {
base: { backgroundColor: c.primary, ...shadowXs },
pressed: { backgroundColor: c.primaryHover },
textBase: { color: c.primaryForeground },
textPressed: { color: c.primaryForeground },
};
}
}
export interface ButtonProps
extends Omit<PressableProps, "children" | "style">,
VariantProps<typeof buttonVariants> {
children?: React.ReactNode;
style?: ViewStyle;
variant?: ButtonVariant;
}
function Button({
className,
variant = "default",
size,
children,
disabled,
style,
onPressIn,
onPressOut,
...props
}: ButtonProps) {
const colors = useThemeColors();
const [pressed, setPressed] = React.useState(false);
const vs = getVariantStyle(variant, colors);
const dim = sizeDim[(size ?? "default") as SizeKey] ?? sizeDim.default;
const containerStyle: ViewStyle = {
borderRadius: 8,
height: dim.height,
...(dim.width === undefined ? null : { width: dim.width }),
...vs.base,
...(pressed && !disabled ? vs.pressed : null),
...style,
};
const finalTextStyle: TextStyle = {
...vs.textBase,
...(pressed && !disabled ? vs.textPressed : null),
};
return (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: !!disabled }}
className={cn(
buttonVariants({ size }),
disabled && "opacity-50",
className
)}
disabled={disabled}
onPressIn={(e) => {
setPressed(true);
onPressIn?.(e);
}}
onPressOut={(e) => {
setPressed(false);
onPressOut?.(e);
}}
style={containerStyle}
{...props}
>
{React.Children.map(children, (child) =>
typeof child === "string" || typeof child === "number" ? (
<Text style={finalTextStyle}>{child}</Text>
) : (
child
)
)}
</Pressable>
);
}
export { Button, buttonVariants };Update the import paths to match your project setup.
Usage
import { Button } from "@/components/ui/button";<Button onPress={() => {}}>Click me</Button>Variants
Default
The primary variant, intended for the most important action on a screen.
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonDefaultExample() {
return (
<View className="gap-2">
<Button>Button</Button>
</View>
);
}Secondary
Intended for actions of lesser prominence.
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonSecondaryExample() {
return (
<View className="gap-2">
<Button variant="secondary">Secondary</Button>
</View>
);
}Outline
Renders with a border and a transparent background.
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonOutlineExample() {
return (
<View className="gap-2">
<Button variant="outline">Outline</Button>
</View>
);
}Ghost
Renders without a border. Background applies only on press.
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonGhostExample() {
return (
<View className="gap-2">
<Button variant="ghost">Ghost</Button>
</View>
);
}Destructive
Intended for destructive or irreversible actions.
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonDestructiveExample() {
return (
<View className="gap-2">
<Button variant="destructive">Destructive</Button>
</View>
);
}Link
Renders as inline text with an underline on press.
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonLinkExample() {
return (
<View className="gap-2">
<Button variant="link">Link</Button>
</View>
);
}Custom radius
Pass className="rounded-full" to render a pill button.
import { ArrowUpIcon } from "lucide-react-native";
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonRoundedExample() {
return (
<View className="flex-row gap-2">
<Button style={{ borderRadius: 9999 }}>Get Started</Button>
<Button
accessibilityLabel="Submit"
size="icon"
style={{ borderRadius: 9999 }}
variant="outline"
>
<ArrowUpIcon />
</Button>
</View>
);
}Size
Use the size prop to control the dimensions of a text button.
The preview above renders at the web size scale. On iOS and Android the component applies the larger values in the table below, sized to meet touch target guidance.
import { ArrowUpRightIcon } from "lucide-react-native";
import { View } from "react-native";
import { Button } from "@/components/ui/button";
export function ButtonSizeExample() {
return (
<View className="gap-8">
<View className="flex-row items-start gap-2">
<Button size="xs" variant="outline">
Extra Small
</Button>
<Button accessibilityLabel="Submit" size="icon-xs" variant="outline">
<ArrowUpRightIcon />
</Button>
</View>
<View className="flex-row items-start gap-2">
<Button size="sm" variant="outline">
Small
</Button>
<Button accessibilityLabel="Submit" size="icon-sm" variant="outline">
<ArrowUpRightIcon />
</Button>
</View>
<View className="flex-row items-start gap-2">
<Button variant="outline">Default</Button>
<Button accessibilityLabel="Submit" size="icon" variant="outline">
<ArrowUpRightIcon />
</Button>
</View>
<View className="flex-row items-start gap-2">
<Button size="lg" variant="outline">
Large
</Button>
<Button accessibilityLabel="Submit" size="icon-lg" variant="outline">
<ArrowUpRightIcon />
</Button>
</View>
</View>
);
}| Size | Height | Padding |
|---|---|---|
xs | 40dp | px-4 |
sm | 44dp | px-5 |
default | 48dp | px-6 |
lg | 51dp | px-8 |
Icon size
Icon buttons use a separate size system. Each produces a square button sized to fit its icon.
| Size | Dimensions |
|---|---|
icon-xs | 40×40 |
icon-sm | 44×44 |
icon | 48×48 |
icon-lg | 51×51 |
Icons & With Icons
Buttons accept an icon next to a label or render as a square icon-only button. Icons are sized by [&_svg]:size-4. Provide the icon as a child of the button.
import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
import {
Pressable,
type PressableProps,
Text,
type TextStyle,
type ViewStyle,
} from "react-native";
import { type ThemeColors, useThemeColors } from "@/lib/theme";
import { cn } from "@/lib/utils";
type SizeKey =
| "xs"
| "sm"
| "default"
| "lg"
| "icon-xs"
| "icon-sm"
| "icon"
| "icon-lg";
const sizeDim: Record<SizeKey, { height: number; width?: number }> = {
default: { height: 48 },
icon: { height: 48, width: 48 },
"icon-lg": { height: 51, width: 51 },
"icon-sm": { height: 44, width: 44 },
"icon-xs": { height: 40, width: 40 },
lg: { height: 51 },
sm: { height: 44 },
xs: { height: 40 },
};
const shadowXs: ViewStyle = {
boxShadow: "0px 1px 2px 0px rgba(0, 0, 0, 0.05)",
};
const buttonVariants = cva(
"shrink-0 flex-row items-center justify-center gap-2 rounded-md",
{
defaultVariants: { size: "default" },
variants: {
size: {
default: "px-6",
icon: "p-0",
"icon-lg": "p-0",
"icon-sm": "p-0",
"icon-xs": "p-0",
lg: "px-8",
sm: "gap-1.5 px-5",
xs: "gap-1 px-4",
},
},
}
);
interface VariantStyle {
base: ViewStyle;
pressed: ViewStyle;
textBase: TextStyle;
textPressed: TextStyle;
}
export type ButtonVariant =
| "default"
| "secondary"
| "outline"
| "ghost"
| "destructive"
| "link";
function getVariantStyle(variant: ButtonVariant, c: ThemeColors): VariantStyle {
switch (variant) {
case "secondary":
return {
base: { backgroundColor: c.secondary, ...shadowXs },
pressed: { backgroundColor: c.secondaryHover },
textBase: { color: c.secondaryForeground },
textPressed: { color: c.secondaryForeground },
};
case "outline":
return {
base: {
backgroundColor: "transparent",
borderColor: c.border,
borderWidth: 1,
...shadowXs,
},
pressed: { backgroundColor: c.accent },
textBase: { color: c.foreground },
textPressed: { color: c.accentForeground },
};
case "ghost":
return {
base: { backgroundColor: "transparent" },
pressed: { backgroundColor: c.accent },
textBase: { color: c.foreground },
textPressed: { color: c.accentForeground },
};
case "destructive":
return {
base: { backgroundColor: c.destructive, ...shadowXs },
pressed: { backgroundColor: c.destructiveHover },
textBase: { color: c.destructiveForeground },
textPressed: { color: c.destructiveForeground },
};
case "link":
return {
base: { backgroundColor: "transparent" },
pressed: {},
textBase: {
borderBottomColor: "transparent",
borderBottomWidth: 1,
color: c.primary,
paddingBottom: 1,
},
textPressed: {
borderBottomColor: c.primary,
},
};
default:
return {
base: { backgroundColor: c.primary, ...shadowXs },
pressed: { backgroundColor: c.primaryHover },
textBase: { color: c.primaryForeground },
textPressed: { color: c.primaryForeground },
};
}
}
export interface ButtonProps
extends Omit<PressableProps, "children" | "style">,
VariantProps<typeof buttonVariants> {
children?: React.ReactNode;
style?: ViewStyle;
variant?: ButtonVariant;
}
function Button({
className,
variant = "default",
size,
children,
disabled,
style,
onPressIn,
onPressOut,
...props
}: ButtonProps) {
const colors = useThemeColors();
const [pressed, setPressed] = React.useState(false);
const vs = getVariantStyle(variant, colors);
const dim = sizeDim[(size ?? "default") as SizeKey] ?? sizeDim.default;
const containerStyle: ViewStyle = {
borderRadius: 8,
height: dim.height,
...(dim.width === undefined ? null : { width: dim.width }),
...vs.base,
...(pressed && !disabled ? vs.pressed : null),
...style,
};
const finalTextStyle: TextStyle = {
...vs.textBase,
...(pressed && !disabled ? vs.textPressed : null),
};
return (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: !!disabled }}
className={cn(
buttonVariants({ size }),
disabled && "opacity-50",
className
)}
disabled={disabled}
onPressIn={(e) => {
setPressed(true);
onPressIn?.(e);
}}
onPressOut={(e) => {
setPressed(false);
onPressOut?.(e);
}}
style={containerStyle}
{...props}
>
{React.Children.map(children, (child) =>
typeof child === "string" || typeof child === "number" ? (
<Text style={finalTextStyle}>{child}</Text>
) : (
child
)
)}
</Pressable>
);
}
export { Button, buttonVariants };Button Group
For grouped actions, see Button Group. A quick example:
import { ArrowLeftIcon, MoreHorizontalIcon } from "lucide-react-native";
import { View } from "react-native";
import { Button } from "@/components/ui/button";
import { ButtonGroup } from "@/components/ui/button-group";
export function ButtonGroupDemoExample() {
return (
<View>
<ButtonGroup>
<ButtonGroup>
<Button accessibilityLabel="Go Back" size="icon" variant="outline">
<ArrowLeftIcon />
</Button>
</ButtonGroup>
<ButtonGroup>
<Button variant="outline">Archive</Button>
<Button variant="outline">Report</Button>
</ButtonGroup>
<ButtonGroup>
<Button variant="outline">Snooze</Button>
<Button
accessibilityLabel="More Options"
size="icon"
variant="outline"
>
<MoreHorizontalIcon />
</Button>
</ButtonGroup>
</ButtonGroup>
</View>
);
}API Reference
Button
| Prop | Type | Default | Description |
|---|---|---|---|
variant | defaultsecondaryoutlineghostdestructivelink | default | The visual style of the button. |
size | xssmdefaultlgicon-xsicon-smiconicon-lg | default | The dimensions of the button. |
disabled | boolean | false | Prevents interaction. Passed to accessibilityState.disabled. |
onPressIn | function | — | Called when the press starts. Used by the component to track the pressed state. |
onPressOut | function | — | Called when the press ends. |
accessibilityLabel | string | — | Required for icon-only buttons. Read by screen readers. |
className | string | — | Additional NativeWind classes merged with the variant classes. |
Accessibility
- The component sets
accessibilityRole="button"on the underlyingPressable. - The
disabledprop setsaccessibilityState={{ disabled: true }}. - Provide
accessibilityLabelon icon-only buttons. - Press feedback uses
onPressInandonPressOut, not hover.
Best Practices
- Use one primary button per screen.
- Prefer
size="default"or larger for touch-critical actions. - Never rely on color alone.
- Provide
accessibilityLabelon icon-only buttons. - Reserve
destructivefor irreversible actions.
Platform notes
- Press, not hover. Native devices have no hover state. The button renders its pressed state through
onPressInandonPressOut. - No anchor mode. React Native has no
<a>element. Use the router link fromexpo-routerfor navigation, and style it with the exportedbuttonVariantshelper. - No
motionprop. The web Button exposes amotionprop for CSS transition overrides. Native does not need it because press feedback is instant and driven by the platform. - Touch target. Visual size equals tap area. The
defaultandlgsizes meet the 44dp minimum guidance on iOS and the 48dp guidance on Android. Forxsandsm, prefer a larger size for touch-critical actions.