Icon
The Icon
component is a versatile tool for adding Expo Icons to your application. It offers customization options through the use of style props.
#
Importimport { Icon } from "pearl-ui";
#
Usage<Icon iconFamily="AntDesign" iconName="stepforward" />
#
Icon sizesThe size
prop allows you to adjust the size of the icon. You can use the keys available in
<Icon iconFamily="AntDesign" iconName="stepforward" size="xs" />
<Icon iconFamily="AntDesign" iconName="stepforward" size="s" />
<Icon iconFamily="AntDesign" iconName="stepforward" size="m" />
<Icon iconFamily="AntDesign" iconName="stepforward" size="l" />
For more precise control over the size of a single Icon
instance, you can use the rawSize
prop.
<Icon iconFamily="AntDesign" iconName="stepforward" rawSize={43} />
#
Overriding StylesThe Icon
component supports a variety of style props which can be used to override the pre-defined variant style in the theme. Manual style props passed into the component have a higher precedence than the default component configuration.
// passing style prop color="primary.500" overrides the default component config value of color="neutral.900"<Icon iconFamily="AntDesign" iconName="stepforward" size="l" color="primary.500" margin="4"/>
#
Example#
AccessibilityIcon
has therole
oftext
.Icon
has the default label set as{iconName} Icon
. A custom label can be specified using theaccessibilityLabel
prop.
#
Component Properties#
Supported Style PropertiesThe Icon
component supports the following style props:
#
Animation PropertiesThe Icon
component supports animation properties from the Moti library, enabling the creation of dynamic and interactive UI elements. The useMotiWithStyleProps hook from the Moti library is used to manage these animation properties.
Property | Type | Default | Description |
---|---|---|---|
from | Defines the starting state of the animation. | ||
to | Defines the ending state of the animation. | ||
transition | Specifies the type of transition that the animation will use. | ||
exitTransition | Determines the transition type that will be used when the component is unmounted. By default, exit uses transition to configure its animations, so this prop is not required. However, if you pass exitTransition , it will override transition for exit animations. | ||
state | Manages the overall state of the animation, including the from and to states. | ||
delay | Manage the delay for the animate field. (Use the transition prop for more granular control) | ||
onDidAnimate | Callback function called after finishing an animation. | ||
stylePriority | "animate" | This is not a prop you will likely find yourself using. If set to animate prop will take precedent. Otherwise, if set to state prop will take precedent for matching styles. | |
animateInitialState | false | If true , the from prop will be set to animate. This will be noticeable for some spring animations, and might make them jumpy on mount. |
#
Additional PropertiesThe Icon
component also supports the following additional properties:
Name | Required | Type | Default | Description |
---|---|---|---|---|
size | No | "m" | Specifies the size of the icon | |
variant | No | Defines the variant of the icon | ||
rawSize | No | Sets the raw size of the icon | ||
iconFamily | Yes | Specifies the icon family that contains the desired icon | ||
iconName | Yes | Specifies the name of the icon within its icon family | ||
accessibilityLabel | No | Sets the accessibility label of the icon |