ExpoStartup

Icon

A versatile icon component that supports Lucide icons with multiple variants and sizes.

Icon

The Icon component is a flexible wrapper around Lucide icons, providing consistent styling and extended functionality such as bordered and contained variants, interactive behaviors, and navigation links.

Features

  • Lucide Icons Integration: Access to the complete set of Lucide icons
  • Multiple Variants: Plain, bordered, and contained styling options
  • Flexible Sizing: Predefined sizes or custom numerical values
  • Interactive: Optional press handlers and link navigation
  • Customizable: Control for color, stroke width, and fill properties
  • Accessibility: Support for disabled states
  • Dark Mode Support: Automatic light/dark mode styles

Import

import Icon, { IconName } from '@/components/Icon';

Props

Core Props

PropTypeDefaultDescription
nameIconNameThe name of the Lucide icon to display
onPress() => voidFunction called when the icon is pressed
disabledbooleanfalseWhether the icon is interactive
hrefstringIf provided, icon acts as a navigation link

Styling Props

PropTypeDefaultDescription
variant'plain' | 'bordered' | 'contained''plain'The visual style of the icon
sizenumber24Custom size for the icon in pixels
iconSize'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'Predefined size options
colorstringTheme text colorThe color of the icon
strokeWidthnumber2Width of the icon stroke
fillstring'none'Fill color for the icon
classNamestringAdditional Tailwind classes for the container
styleViewStyleReact Native style object for the container

Sizes

The iconSize prop maps to the following dimensions:

iconSizeContainer SizeIcon Size
'xs'32x3216px
's'40x4020px
'm'48x4824px
'l'64x6432px
'xl'80x8040px
'xxl'96x9648px

Usage Examples

Basic Icon

<Icon name="home" />

Different Variants

<Icon name="settings" variant="plain" />
<Icon name="settings" variant="bordered" />
<Icon name="settings" variant="contained" />

Custom Sizes

{/* Using predefined sizes */}
<Icon name="user" iconSize="xs" />
<Icon name="user" iconSize="m" />
<Icon name="user" iconSize="xxl" />
 
{/* Using custom numeric size */}
<Icon name="bell" size={36} />

Interactive Icon

<Icon 
  name="heart" 
  onPress={() => console.log('Liked!')} 
  color="red" 
/>
<Icon 
  name="arrow-right" 
  href="/next-page" 
  variant="contained" 
/>

Customized Icon

<Icon 
  name="star" 
  color="#FFD700" 
  strokeWidth={1.5} 
  fill="#FFD700" 
  className="shadow-sm" 
/>

Disabled State

<Icon 
  name="trash" 
  onPress={() => console.log('Delete')} 
  disabled={isDisabled} 
  variant="contained" 
/>

Best Practices

Consistent Sizing

Choose a consistent approach to sizing icons throughout your application:

// Example of consistent icon sizing in a header
<View className="flex-row items-center">
  <Icon name="menu" iconSize="m" />
  <Text className="text-xl font-bold mx-4">Dashboard</Text>
  <Icon name="bell" iconSize="m" />
  <Icon name="user" iconSize="m" />
</View>

Semantic Color Usage

Use colors that reflect the icon's purpose:

<Icon name="check-circle" color="#4CAF50" /> {/* Success */}
<Icon name="alert-circle" color="#F44336" /> {/* Error */}
<Icon name="info" color="#2196F3" /> {/* Information */}
<Icon name="alert-triangle" color="#FF9800" /> {/* Warning */}

Appropriate Variants

Choose variants that match the context:

  • Use plain for inline icons or when space is limited
  • Use bordered to add subtle emphasis or for toggle controls
  • Use contained for important actions or primary navigation

Implementation Details

The Icon component uses React Native's View and Pressable components for rendering. When the href prop is provided, it wraps the icon in an Expo Router Link component for navigation.

The component automatically handles theme colors and applies the correct styles based on the active theme. It supports both light and dark mode through the useThemeColors hook.

Notes

  • The component imports Lucide icons from lucide-react-native
  • When both size and iconSize are provided, iconSize takes precedence
  • Container sizes are only applied when using variants other than plain
  • The IconName type represents all available Lucide icons, excluding utility properties
  • When using the href prop, the component becomes a navigation link using Expo Router

On this page