Introduction
Components
- Accordion
- Action Sheet
- Alert
- Audio Player
- Audio Recorder
- Audio Waveform
- Avatar
- AvoidKeyboard
- Badge
- BottomSheet
- Button
- Camera
- Camera Preview
- Card
- Carousel
- Checkbox
- Collapsible
- Color Picker
- Combobox
- Date Picker
- File Picker
- Gallery
- Hello Wave
- Icon
- Image
- Input
- Input OTP
- Link
- MediaPicker
- Mode Toggle
- Onboarding
- ParallaxScrollView
- Picker
- Popover
- Progress
- Radio
- ScrollView
- SearchBar
- Separator
- Share
- Sheet
- Skeleton
- Spinner
- Switch
- Table
- Tabs
- Text
- Toast
- Toggle
- Video
- View
Charts
Installation
pnpm dlx bna-ui add color-picker
Usage
import { ColorPicker, ColorSwatch } from '@/components/ui/color-picker';
<ColorPicker
value='#ff0000'
onColorChange={(color) => console.log('Color changed:', color)}
onColorSelect={(color) => console.log('Color selected:', color)}
/>
Examples
Default
Different Sizes
With Initial Colors
Disabled State
Color Swatch Only
Custom Styling
Color Palette
With Labels
API Reference
ColorPicker
The main color picker component that displays a swatch and opens a modal for color selection.
Prop | Type | Default | Description |
---|---|---|---|
value | string | '#ff0000' | The current color value in hex format. |
onColorChange | (color: string) => void | - | Callback fired when the color changes during selection. |
onColorSelect | (color: string) => void | - | Callback fired when the user confirms color selection. |
swatchSize | number | HEIGHT | The size of the color swatch in pixels. |
disabled | boolean | false | Whether the color picker is disabled. |
style | ViewStyle | - | Additional styles to apply to the container. |
ColorSwatch
A standalone color swatch component that can be used independently.
Prop | Type | Default | Description |
---|---|---|---|
color | string | - | The color to display in hex format. |
size | number | 32 | The size of the swatch in pixels. |
style | ViewStyle | - | Additional styles to apply to the swatch. |
onPress | () => void | - | Callback fired when the swatch is pressed. |
Color Utilities
The component includes several utility functions for color manipulation:
hsvToRgb(h, s, v)
- Converts HSV values to RGBrgbToHex(r, g, b)
- Converts RGB values to hex stringhexToRgb(hex)
- Converts hex string to RGB valuesrgbToHsv(r, g, b)
- Converts RGB values to HSV
Features
- HSV Color Space: Uses HSV (Hue, Saturation, Value) color model for intuitive color selection
- Interactive Gestures: Pan gestures for hue bar and saturation/brightness picker
- Real-time Preview: Live color preview as you drag the selectors
- Modal Interface: Full-screen modal with cancel and confirm actions
- Customizable: Configurable swatch sizes and styling
- Accessible: Proper contrast and readable color values
- Smooth Animations: Powered by react-native-reanimated for smooth interactions
Accessibility
The ColorPicker component is built with accessibility in mind:
- Color values are displayed in uppercase hex format for easy reading
- High contrast knobs for better visibility
- Proper touch targets for gesture interactions
- Modal provides clear cancel and confirm actions
- Color preview shows the selected color prominently
Notes
- The component uses
expo-linear-gradient
for smooth color gradients - Gesture handling is powered by
react-native-gesture-handler
- Animations use
react-native-reanimated
for optimal performance - The hue bar uses SVG gradients for precise color representation
- Color calculations maintain precision across different color spaces