Button

Displays a button or a component that looks like a button.

Installation

Terminal
npx flexnative-cli add "https://registry.flexnative.com/c/button.json"

Usage


Importing
import { Button } from "@/components/ui/button";
Using
<Button variant="default" label="Default" />

Examples

Default

<Button variant="default" label="Default" />

Secondary

<Button variant="secondary" label="Secondary" />

Destructive

<Button variant="destructive" label="Destructive" />

Outline

<Button variant="outline" label="Outline" />

Ghost

<Button variant="ghost" label="Ghost" />

Icon

<Button icon={<Icon name="home" />} label="With Icon" />

Icon Only

<Button icon={<Ionicons name="add" />} size="icon" />

API

Button

The Button component allows you to create interactive, styled buttons with various variants and sizes.

PropTypeDescriptionDefault
labelstringThe text label displayed inside the button.undefined
iconReact.ReactNodeAn icon element displayed alongside the button label or as the only content.undefined
onPress() => voidCallback triggered when the button is pressed.undefined
styleStyleProp<ViewStyle>Additional styles for the button container.undefined
labelStyleStyleProp<TextStyle>Custom styles for the button label.undefined
iconStyleStyleProp<ViewStyle>Styles applied to the icon container (not the icon itself).undefined
variantdefault, secondary, destructive, ghost, outlineDetermines the visual style of the button.'default'
sizedefault, sm, lg, iconAdjusts the size of the button.'default'
disabledbooleanDisables the button, making it unclickable and visually indicating its disabled state.false
accessibilityLabelstringA label used for screen readers to describe the button.undefined
testIDstringAn identifier for testing purposes.undefined
...TouchableOpacityPropsAll other TouchableOpacity propsInherits all additional props from TouchableOpacity, such as onPressIn, onPressOut, etc.

Variants

VariantDescription
defaultStandard button with primary colors.
secondaryMuted button with secondary styling.
destructiveStyled to indicate a destructive action (e.g., delete).
ghostTransparent button with minimal styling, for secondary actions.
outlineTransparent button with a border, styled for subtle emphasis.

Sizes

SizeDescription
defaultStandard button size, suitable for most use cases.
smSmaller button for compact spaces.
lgLarger button for high emphasis.
iconCircular button containing only an icon.

Accessibility

Ensure that your buttons are accessible by providing proper labels, roles, and other attributes.

PropTypeDescriptionDefault
accessibilityLabelstringA descriptive label used by screen readers to explain the button's purpose or action.undefined
accessibilityRole'button'Identifies the element as a button for accessibility tools (automatically set to 'button').'button'
disabledbooleanIndicates that the button is disabled, preventing interaction and signaling the state to assistive technologies.false

Best Practices for Accessibility

  • Provide meaningful labels: Always use accessibilityLabel to describe what the button does, especially for buttons with only icons.
  • Consistent roles: The accessibilityRole is automatically set to 'button' but can be overridden if needed.
  • Handle disabled states: Ensure that disabled buttons are visually distinct and announce their state via assistive technologies.

Example

Example
import { Button } from "@/components/ui/button";
import { Ionicons } from "@expo/vector-icons";

<Button 
icon={<Ionicons name="add" />}
size="icon"
accessibilityLabel="Add new item"
onPress={() => console.log('Button pressed')} 
/>