Anatomy
The Icon consists of two primary elements that work together to act as visual aids.
- Icon
- Bounding area
Options
The Icon supports multiple sizes, SVG support, and color configurations to accommodate various visual aid scenarios.Sizes
SVG support
Icon accepts SVGs. This typically involves using Anvil’s provided icon library but also supports custom SVGs.Color
Icons inherit a color provided to them. When providing a color, use a token value.Behavior
The Icon responds to different size and color requirements while maintaining consistent visual representation.Usage Guidelines
How to Use
Provide a label for Icons
An Icon’s label takes two forms: as a text label next to an icon, or as a Tooltip. A text label is generally preferred as most icons do not have an obvious meaning.Do
Do
Do
Provide information without action
Icon provides indication for users and can be focused or hovered to convey more details. In these use cases, addtabIndex={0} to make icon focusable and use Tooltip with it.
Consistent icon usage
Consistent icon usage of status and actions brings familiarity. Use the standard that a product has adopted.Don’t
Use semantic token colors for Icons
When using color for Icons, use a semantic token value. This ensures an icon is both themeable and internally consistent with other UI’s color usage.Avoid custom icon resizing
Icons have a consistent set of dimensions. Resizing breaks the internal consistency and creates awkward vector scaling.Content
Content within the Icon should be clear and recognizable, helping users understand the concept being represented.Keyboard Interaction
Users can navigate the Icon using standard keyboard controls.Accessibility
Non-interactive Icons
Pair Icons with a text label when possible. When using an Icon without text, provide anaria-label to the Icon directly, describing what the icon is.
For more guidance on icon accessibility, see accessible icon usage best practices.
Code
- Implementation
- Icon Props
Common Examples
SVGR Config
Anvil2 icons are pure SVGs, and require a special loader to properly handle imports and rendering – SVGR. Any project using the@servicetitan/startup package version 23.5.0 or later will already have this configured. To use Anvil2 in a standalone app or other project, the SVGR plugin needs to be configured to properly render Anvil2 icons.Use the examples below for common build tools. For other build tools, check out the SVGR docs (or the specific build tool docs) for how to update the config object, and be sure to disable the removeViewbox option in the svgoConfig (see the examples for more details).Webpack SVGR Config
Vite SVGR Config
React Accessibility
Non-interactive Icons
Icons that lack interaction and have no accompanying text only need anaria-label to describe what the Icon is. If paired with text, no additional elements are needed.Decorative icon paired with a text label<div><Icon svg={Warning} size="large" /> <BodyText>Label Text</BodyText> </div>Standalone icon with no text label<Icon svg={Warning} size="large" aria-label="Warning" />Interactive Icons
Icon can be used to provide indication for users which can be focused or hovered to convey more details. In these use cases, addtabIndex={0} to make icon focusable and use Tooltip with it.For more guidance on icon accessibility, see accessible icon usage best practices.