1.0.0 • Published 5 months ago

react-native-unified-icons v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

React Native Unified Icons

A unified interface for various icon sets in React Native, leveraging @expo/vector-icons (which internally uses react-native-vector-icons). This package provides type-safe icon selection across multiple icon libraries with a clean, consistent API.

Installation

npm install react-native-unified-icons
# or
yarn add react-native-unified-icons

Prerequisites

This package requires the following peer dependencies:

  • react
  • react-native
  • @expo/vector-icons

Note: @expo/vector-icons internally uses react-native-vector-icons, so you'll get all the benefits of both libraries.

Usage

Basic Usage

import { Icon } from 'react-native-unified-icons';

// Using AntDesign icons
<Icon
  select={{
    from: "antdesign",
    name: "stepforward"
  }}
  size={24}
  color="black"
/>

// Using Material icons
<Icon
  select={{
    from: "material-icons",
    name: "access-alarm"
  }}
  size={24}
  color="red"
/>

With NativeWind

If you're using NativeWind for styling, you can utilize Tailwind classes for colors and other styles. This is particularly useful when working with custom themes:

// Basic NativeWind usage
<Icon
  select={{
    from: "antdesign",
    name: "heart"
  }}
  className="!text-primary"  // Using your theme's primary color
  size={24}
/>

// Using important modifier for style precedence
<Icon
  select={{
    from: "material-icons",
    name: "favorite"
  }}
  className="!text-secondary"  // Forces the secondary color
  size={24}
/>

// Complex styling example
<Icon
  select={{
    from: "ionicons",
    name: "notifications"
  }}
  className="text-warning dark:text-warning-dark !font-bold"
  size={24}
/>

Supported Props

PropTypeRequiredDescriptionExample
select.fromIconTypeYesThe icon library to use. Options: 'antdesign', 'material-icons', 'ionicons', 'feather', 'evilicons', 'entypo', 'fontawesome6'from: "antdesign"
select.nameIconNameType<T>YesThe name of the icon from the selected library. Type-safe based on the chosen library.name: "stepforward"
sizenumberNoThe size of the icon in pixels.size={24}
colorstringNoThe color of the icon. Can be any valid color string.color="red"
classNamestringNoNativeWind classes for styling (if using NativeWind).className="text-primary"
styleStyleProp<TextStyle>NoAdditional React Native styles.style={{ marginRight: 10 }}

All other TextProps from React Native's Text component are also supported, except for 'children'.

Supported Icon Libraries

This package provides access to all icon sets available in @expo/vector-icons:

LibraryImport KeyExample UsageDescription
AntDesignantdesignfrom: "antdesign"Clean and modern icons from Ant Design
Material Iconsmaterial-iconsfrom: "material-icons"Google's Material Design icons
Ioniconsioniconsfrom: "ionicons"Premium icons for iOS, Android & Web
Featherfeatherfrom: "feather"Simply beautiful open source icons
EvilIconseviliconsfrom: "evilicons"Simple and clean icon set
Entypoentypofrom: "entypo"Over 250 carefully crafted premium icons
FontAwesome 6fontawesome6from: "fontawesome6"Latest version of FontAwesome icons
FontAwesome 5fontawesome5from: "fontawesome5"FontAwesome 5 icon set
FontAwesomefontawesomefrom: "fontawesome"Original FontAwesome icon set
Fontistofontiscofrom: "fontisco"The iconic font and CSS toolkit
Foundationfoundationfrom: "foundation"Iconic fonts for Foundation Framework
Octiconsocticonsfrom: "octicons"GitHub's icon set
Simple Line Iconssimple-line-iconsfrom: "simple-line-icons"Simple and elegant line icons
Zocialzocialfrom: "zocial"Social and brand icons

TypeScript Support

The package is written in TypeScript and provides full type safety. The icon names are typed based on the selected library, providing autocomplete and type checking in supported IDEs.

// This will show type errors if the icon name doesn't exist in the selected library
<Icon
  select={{
    from: "antdesign",
    name: "invalid-icon-name", // TypeScript error
  }}
/>

License

MIT