suiss/ui · Component
Icon
Renders a Phosphor icon with size and color set through class names.
Icon is an open-source component from suiss/ui for React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
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-foreground.
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.
SwiftUI has no Icon view to install. Use the images from the Phosphor Swift package directly, and set their size and color with SwiftUI modifiers, as the examples on this page do.
Installation
Add the Phosphor Swift package to your app:
The CLI also adds what it builds on: Text.
Manual
- Install the dependencies:
-
Add the pieces it builds on: Text.
-
Copy the source into
components/ui/icon.tsx:
- Update the import paths to match your project.
- Install the dependencies:
-
Add the pieces it builds on: Text.
-
Copy the source into
components/ui/icon.tsx:
- Update the import paths to match your project.
- Install the dependencies:
-
Add the pieces it builds on: Text.
-
Copy the source into
components/ui/icon.tsx:
- Update the import paths to match your project.
- Set
minSdkto 24 or higher and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Pass the icon component, not an element: <Icon as={HeartIcon} />. Override the size and color with className, such as size-6 text-destructive. 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.
Colors
Icons in different color tokens.
Weights
The available Phosphor weights.
API Reference
Icon
Styled Phosphor icon.
| Prop | Type | Default | Description |
|---|---|---|---|
as | PhosphorIcon | Required | The Phosphor icon component to render. |
Also accepts the props of IconProps.
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-foregroundtoken, so icons follow light and dark mode with the system appearance.