Chip
A versatile chip component for displaying filters, tags, or selections.
Chip
The Chip component is a compact UI element that can be used for displaying filters, tags, categories, or selection options. It supports multiple sizes, selected states, icons, and images, making it versatile for various UI needs.
Features
- Selection State: Visual indication of selected/unselected states
- Multiple Sizes: Six size options from extra small to extra-extra large
- Icon Support: Can include icons from the Icon component
- Image Support: Can include small images as visual indicators
- Custom Content: Accepts custom React elements for the left content
- Interactive: Optional press handlers and link navigation
- Customizable: Control for styling and appearance
- Dark Mode Support: Automatic light/dark mode styles
Import
Props
Core Props
Prop | Type | Default | Description |
---|---|---|---|
label | string | Required | The text displayed in the chip |
isSelected | boolean | false | Whether the chip appears in selected state |
onPress | () => void | — | Function called when the chip is pressed |
href | string | — | If provided, chip acts as a navigation link |
Styling Props
Prop | Type | Default | Description |
---|---|---|---|
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'md' | The size of the chip |
className | string | — | Additional Tailwind classes for the container |
style | ViewStyle | — | React Native style object for the container |
Content Props
Prop | Type | Default | Description |
---|---|---|---|
icon | IconName | — | Icon to display before the label |
iconSize | number | Based on chip size | Custom size for the icon |
iconColor | string | Based on selection state | Custom color for the icon |
image | ImageSourcePropType | — | Image to display before the label |
imageSize | number | Based on chip size | Custom size for the image |
leftContent | ReactNode | — | Custom content to display before the label |
Sizes
The size
prop affects padding, text size, and default icon/image sizes:
Size | Padding | Text Size | Default Icon Size | Default Image Size |
---|---|---|---|---|
'xs' | px-1.5 py-0.5 | xs | 12px | 16px |
'sm' | px-2 py-0.5 | xs | 14px | 18px |
'md' | px-3 py-1 | sm | 16px | 20px |
'lg' | px-4 py-1.5 | base | 18px | 24px |
'xl' | px-5 py-2 | lg | 20px | 28px |
'xxl' | px-6 py-2.5 | xl | 24px | 32px |
Usage Examples
Basic Chip
Selected Chip
Interactive Chip
Navigation Chip
Chip with Icon
Chip with Image
Custom Sized Chip
Custom Styled Chip
Filter Selection Example
Tag List Example
Best Practices
Visual Consistency
Maintain consistent size and styling for related chips:
Clear Selection States
Ensure selection states are visually distinct:
Appropriate Content
Keep chip labels concise and use icons to enhance meaning:
Implementation Details
The Chip component uses React Native's View
, Text
, TouchableOpacity
, and optionally Image
components for rendering. When the href
prop is provided, it uses Expo Router's Link
component for navigation.
For the left content, the component can render an icon (using the Icon component), an image, or custom content provided via the leftContent
prop. The component automatically adjusts the size of icons and images based on the chip size, but these can be overridden with the iconSize
and imageSize
props.
The component supports both light and dark mode through Tailwind classes that apply different styles based on the active theme.
Notes
- The
isSelected
prop changes the background color and text color - When both
href
andonPress
are provided,href
takes precedence - When both custom
leftContent
andicon
/image
are provided,leftContent
takes precedence - The chip is automatically wrapped in a
TouchableOpacity
when eitheronPress
orhref
is provided - If none of
onPress
orhref
is provided, the chip will not be interactive