suiss/uim · React Native Component

Icon

Renders a Phosphor icon with size and color set through class names.

Icon is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Icon on iOS in light mode

Icon takes a Phosphor icon component in as and maps size-* classes to its size and text-* classes to its color. It defaults to size-5 text-label.

Icons inherit text and icon classes from their parent, so an Icon inside a Button, Badge or menu item picks up the right size and color without extra classes. Components provide these through IconClassContext.

Installation

$ pnpm dlx @esuiss/uim@latest add icon

The CLI also adds what it builds on: Text.

Manual

  1. Install the dependencies:
npx expo install cn phosphor-react-native react-native-svg uniwind
  1. Add the pieces it builds on: Text.

  2. Copy the source into components/ui/icon.tsx:

uniwind/components/ui/icon.tsx
import { cn } from "cn"
import type {
  Icon as PhosphorIcon,
  IconProps as PhosphorIconProps,
} from "phosphor-react-native"
import * as React from "react"
import { withUniwind } from "uniwind"
import { TextClassContext } from "@/components/ui/text"

type IconProps = PhosphorIconProps & {
  as: PhosphorIcon
  className?: string
}

const IconClassContext = React.createContext<string | undefined>(undefined)
  1. Update the import paths to match your project.

Usage

import { Icon } from "@/components/ui/icon"
<Icon as={StarIcon} />

Pass the icon component, not an element: <Icon as={HeartIcon} />. Override the size and color with className, such as size-6 text-danger. Other Phosphor props, such as weight and mirrored, are passed through.

Wrap a subtree in IconClassContext.Provider to set default classes for the icons inside your own components.

Examples

Sizes

Icons at several size-* classes.

iOS
Icon (sizes) on iOS in light mode

Colors

Icons in different color tokens.

iOS
Icon (colors) on iOS in light mode

Weights

The available Phosphor weights.

iOS
Icon (weights) on iOS in light mode

API Reference

Icon

Styled Phosphor icon.

ExtendsIconProps

Accessibility

  • Icons have no label of their own. When an icon is the only content of a pressable, give the pressable an accessibilityLabel.

Notes

  • The default color is the text-label token, so icons follow light and dark mode with the system appearance.