Button

A versatile, accessible button component

A flexible button component designed for all user interactions. It supports multiple variants, sizes, loading states, and comes with full accessibility support out of the box.

Overview

The Button component is the foundation of interactive elements in your app. It handles touch feedback, accessibility, and visual feedback automatically.

Use it for:

  • Primary and secondary actions
  • Form submissions
  • Navigation triggers
  • Any interactive element requiring user feedback

Basic Usage

import { Button } from 'prizmux'

export default function App() {
  return (
    <Button 
      title="Press Me" 
      onPress={() => console.log('Pressed!')}
    />
  )
}

Variants

The Button component supports two visual variants:

Filled (Default)

<Button 
  title="Filled Button" 
  variant="filled"
  onPress={() => {}}
/>

Outline

<Button 
  title="Outline Button" 
  variant="outline"
  onPress={() => {}}
/>

Sizes

Choose the right size for your layout:

Small

<Button 
  title="Small" 
  size="small"
  onPress={() => {}}
/>

Medium (Default)

<Button 
  title="Medium" 
  size="medium"
  onPress={() => {}}
/>

Large

<Button 
  title="Large" 
  size="large"
  onPress={() => {}}
/>

With Icons

Add icons to buttons for better visual communication:

import { Button } from 'prizmux'
import { Settings } from 'lucide-react-native'

export default function App() {
  return (
    <>
      {/* Icon on the left */}
      <Button 
        title="Settings"
        icon={<Settings size={20} />}
        iconPosition="left"
        onPress={() => {}}
      />
      
      {/* Icon on the right */}
      <Button 
        title="Next"
        icon={<ChevronRight size={20} />}
        iconPosition="right"
        onPress={() => {}}
      />
      
      {/* Icon only */}
      <Button 
        icon={<Menu size={24} />}
        onPress={() => {}}
      />
    </>
  )
}

Loading State

Show loading feedback during async operations:

import { Button } from 'prizmux'
import { useState } from 'react'

export default function App() {
  const [isLoading, setIsLoading] = useState(false)

  const handleSubmit = async () => {
    setIsLoading(true)
    try {
      await submitForm()
    } finally {
      setIsLoading(false)
    }
  }

  return (
    <Button 
      title="Submit"
      isLoading={isLoading}
      onPress={handleSubmit}
    />
  )
}

Disabled State

Disable buttons when they shouldn't be interactive:

<Button 
  title="Disabled" 
  disabled={true}
  onPress={() => {}}
/>

Full Width

Make buttons stretch to fill their container:

<Button 
  title="Full Width Button"
  fullWidth={true}
  onPress={() => {}}
/>

Custom Styling

Customize the button appearance with style props:

<Button 
  title="Custom"
  borderRadius={20}
  style={{ backgroundColor: '#FF6B6B' }}
  textStyle={{ fontSize: 18, fontWeight: '700' }}
  onPress={() => {}}
/>

Accessibility

The Button component is fully accessible:

<Button 
  title="Like"
  accessibilityLabel="Like this post"
  onPress={() => {}}
/>

Props Reference

PropTypeDefaultDescription
titlestring-Button label text (optional for icon-only buttons)
onPress() => voidRequiredCallback when button is pressed
variant'filled' | 'outline''filled'Visual variant
size'small' | 'medium' | 'large''medium'Button size
disabledbooleanfalseDisables interactions and shows disabled state
isLoadingbooleanfalseShows loading indicator
iconReactNode-Icon to display
iconPosition'left' | 'right''left'Position of icon relative to title
fullWidthbooleanfalseStretch button to full width
borderRadiusnumber0Border radius in pixels
hitSlopnumber-Increase tap target area (mobile accessibility)
accessibilityLabelstring-Screen reader label
styleViewStyle-Custom button container styles
contentStyleViewStyle-Custom inner content wrapper styles
textStyleTextStyle-Custom button text styles
onLongPress() => void-Callback for long press gestures
<Button title="Primary" variant="primary" />
<Button title="Secondary" variant="secondary" />
<Button title="Outline" variant="outline" />

Sizes

<Button title="Small" size="sm" />
<Button title="Medium" size="md" />
<Button title="Large" size="lg" />

With Icon

import { Button } from 'prizmux'
import { ChevronRight } from 'lucide-react-native'

export default function App() {
  return (
    <Button 
      title="Next" 
      icon={<ChevronRight size={18} />}
      iconPosition="right"
    />
  )
}

Loading State

const [loading, setLoading] = useState(false)

const handleSubmit = async () => {
  setLoading(true)
  await submitForm()
  setLoading(false)
}

<Button 
  title="Submit" 
  loading={loading}
  onPress={handleSubmit}
/>

Notes

  • The button automatically handles opacity changes on press
  • Loading state disables user interaction automatically
  • Accessibility features are built-in (press states, labels)
  • Works with custom icon libraries (Lucide, Font Awesome, etc.)
  • Full TypeScript support with IntelliSense