Skip to content

CdsIcon

An icon is a short visual mark next to the text: the status of a record, the type of a file, the direction of a transition. The component takes an icon by name from a connected pack and subordinates its size, color and spacing to the design system tokens.

Storybook GitLab Figma
Test coverage: 100% — good coverage
API in specs
15 / 15 props, events, slots and exposed members with a test
Test cases
24 unit · 0 browser · 2 planned
Known bugs
4 pinned by an it.fails test
Code coverage
100% lines · 100% branches measured in v4.0.0-alpha.13
A11y (axe)
3 recommendations in 11 stories measured in v4.0.0-alpha.11

Inside other components you do not assemble an icon separately: CdsButton, CdsTextInput, CdsList and others have the icon, prepend-icon and append-icon props. For a standalone action take CdsFunctionalButton — an icon button with a label and states. All the available icons are in the gallery, and connecting your own pack is described in the guide.

Variations ​

Icon ​

The icon prop takes the name of an icon from the default pack — add or search, for example. The name prop does the same and reads more naturally when the icon is set by a string. Besides a name, icon also accepts an icon component and an array of SVG paths, so you can pass your own graphics into it.

An icon from another connected pack is written with the prefix of that pack — i-ri:settings-3-line. How to connect a pack is described in the icons guide.

Sizes ​

The size prop takes one of the scale values — from xs to xl — or a number in pixels when the icon works as an illustration. The default is md, level with the body text.

Color ​

Without color the icon inherits the text color of its parent — this is the default behavior and the right one in most cases. The color prop takes a palette token (content-secondary, brand-primary), a status color alias (green, red, lemon) or a hex/rgb value. The opacity prop mutes the icon without changing its color.

Spacing from the text ​

The start and end props add spacing on the side of the text: start for an icon before the label, end for one after it. This saves you from picking margins by hand.

Reacting to a click ​

If you attach a @click handler to an icon, it gets role="button", joins the Tab order and changes the cursor; disabled removes it from the order and stops it from accepting clicks. This is handy for small toggles inside your own components — for a full-fledged action CdsFunctionalButton fits better.

Slot ​

The name of the icon can be passed as text into the default slot — the result is the same as with icon. Useful when the name comes from an expression in the template.

Guidelines ​

Scenarios ​

Statuses in a list ​

An icon to the left of a label sets the status by color and shape, while the text names it in words. The colors come from the status aliases, size="sm" fits the icon to small text, and start adds the spacing before the label.

List of attachments ​

The icon shows the type of a file and keeps the eye on the left edge of the list. The lg size makes it more noticeable than the label, and the content-secondary color keeps it from competing with the file name. The action next to it is already a button: CdsFunctionalButton with an aria-label.

Progress of an operation ​

The icon reflects the state of a process: the request is ready, is being sent, has been sent. Only icon and color change — the component repaints in place and the status line does not jump.

A note inside text ​

Inside a paragraph the icon aligns to the middle of the line, so you can put it right into the text. The sm size and start keep it from breaking the line.

API ​

Props

NameTypeDefaultDescription
activeColorstring | undefined—Color of the component in its active state
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
colorstring | undefined—Component color
disabledboolean | null | undefinednullDisabled state
endboolean | undefined—Adds spacing to the left of the icon — for an icon after the text
iconIconValue | undefined—Name of the icon or the icon component to render
namestring | undefined—String name of an icon from a registered pack (an alias for icon)
opacitystring | number | undefined—Opacity of the icon — a number between 0 and 1
sizenumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined'md'Size of the component
startboolean | undefined—Adds spacing to the right of the icon — for an icon before the text
tagstring | JSXComponent<any> | undefined'i'Custom HTML tag or component to render
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme

Slots

NameTypeDescription
defaultanyName of the icon as text — an alternative to the icon prop