Checkbox Component

A highly customizable and animated checkbox component for React Native applications with built-in label support and smooth animations.

Features

  • Animated Interactions - Smooth bounce and scale animations
  • 🎨 Highly Customizable - Full control over colors, sizes, and styling
  • 📝 Label Support - Built-in text label with custom styling options
  • 🎯 Flexible State Management - Controlled and uncontrolled modes
  • Accessibility Ready - Screen reader support and proper semantics
  • 🔧 TypeScript Support - Full type safety and IntelliSense

Installation

💻Bash
npm install rn-base-component
# or
yarn add rn-base-component

Basic Usage

⚛️TSX
import React from 'react'
import { Checkbox } from 'rn-base-component'

export default function App() {
  return (
     console.log('Checked:', checked)}
    />
  )
}

Controlled Component

⚛️TSX
import React, { useState } from 'react'
import { Checkbox } from 'rn-base-component'

export default function ControlledCheckbox() {
  const [isChecked, setIsChecked] = useState(false)

  return (
    
  )
}

Advanced Usage

Custom Styling

⚛️TSX
 console.log(checked)}
/>

Different Sizes

⚛️TSX

  
  
  

With Icons

⚛️TSX

  }
  onChange={checked => console.log(checked)}
/>

API Reference

CheckboxProps

PropTypeDefaultDescription
valuebooleanfalseCurrent checked state
onChange(checked: boolean) => voidRequiredCallback when state changes
labelstringundefinedText label for the checkbox
sizenumber20Size of the checkbox
checkedColorstringtheme.primaryColorColor when checked
uncheckedColorstringtheme.borderColorColor when unchecked
borderRadiusnumber4Border radius of the checkbox
animationDurationnumber200Animation duration in milliseconds
customIconReact.ReactNodeundefinedCustom icon when checked
textStyleStyleProp<TextStyle>undefinedStyle for the label text
styleStyleProp<ViewStyle>undefinedStyle for the container
disabledbooleanfalseDisable the checkbox
testIDstringundefinedTest identifier for testing

Animation

The checkbox includes smooth scaling and color transition animations that can be customized with the animationDuration prop.

Form Integration

Registration Form

⚛️TSX
import React, { useState } from 'react'
import { View } from 'react-native'
import { Checkbox, Button } from 'rn-base-component'

export default function RegistrationForm() {
  const [acceptTerms, setAcceptTerms] = useState(false)
  const [newsletter, setNewsletter] = useState(false)

  const handleSubmit = () => {
    if (!acceptTerms) {
      alert('Please accept the terms and conditions')
      return
    }
    console.log('Form submitted', { acceptTerms, newsletter })
  }

  return (
    
      
      
      
      
      
    
  )
}

const styles = StyleSheet.create({
  form: {
    padding: 20,
  },
  checkbox: {
    marginBottom: 16,
  },
})

Best Practices

  1. Clear Labels - Use descriptive, action-oriented labels
  2. Consistent Styling - Maintain consistent size and colors across your app
  3. Form Validation - Provide clear feedback for required checkboxes
  4. Accessibility - Ensure proper accessibility labels and states
  5. Touch Target - Maintain adequate touch target size (minimum 44px)
  6. Visual Feedback - Use animations to provide clear state feedback

Performance

Avoid complex animations or heavy operations in the onChange callback for better performance.