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.
There is nothing to copy: the Phosphor Swift package from the Command tab is all SwiftUI needs.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy and paste the following code into
components/ui/icon.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy and paste the following code into
components/ui/icon.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy and paste the following code into
components/ui/icon.tsx:
- Update the import paths to match your project setup.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 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
Examples
Sizes
Set the size with a size-* class in className, such as size-6.
Colors
Icons in different color tokens.
Weights
The available Phosphor weights.
Accessibility
- Icons have no label of their own. When an icon is the only content of a pressable, give the pressable an
accessibilityLabel.
API Reference
Icon
Styled Phosphor icon.
| Prop | Type | Default |
|---|---|---|
as | PhosphorIcon | Required |
Also accepts the props of IconProps from phosphor-react-native.
Pass the Phosphor icon component to render in as, 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. The default color is the text-foreground token, so icons follow light and dark mode. Wrap a subtree in IconClassContext.Provider to set default classes for the icons inside your own components.
Icon
Styled Phosphor icon.
| Parameter | Type | Default |
|---|---|---|
imageVector | ImageVector | - |
contentDescription | String? | - |
modifier | Modifier | Modifier |
size | Dp | LocalIconSize.current |
tint | Color | LocalContentColor.current.takeOrElse { EsuissTheme.colors.foreground } |