This is version 4 beta of Forma 36Go back to last stable version 3
Forma 36

Icons

Icons are used to indicate actions, statuses and navigation. The icon components can be used in Button, TextLink, Note and other components.

Table of contents

How to use icons

  • Select an icon that accurately represents the subject
  • Pair icons with text
  • Position buttons consistently in the interface
  • Ensure the behavior of the button is consistent in all use cases
  • Consider how the button fits into the context of the screen and reduce complexity where possible

Code examples

Forma 36 provides a list of built-in icons that can be used as regular React components:

import { ArrowDownIcon } from '@contentful/f36-icons';
<ArrowDownIcon />;

Component variations

The icon components can be configured in different ways using variations in color and size:

Icon variants

Icon sizes

Icons

Accessibility

Missing

Custom icons and third-party libraries

Custom icons can be rendered with Forma 36 to take advantage of the same props and styling as the built-in icons. This means you can use a prop like variant="primary" or size="large" on your own icons and they will match the built-in icons from Forma 36.

Custom icons can be used in two ways:

as prop

Passing a React component with an SVG icon to the as prop on Icon makes it render that SVG. This works both with your own icons and with icons from third-party icon libraries such as react-icons:

import { Icon } from '@contentful/f36-icons';
import { MdAccessAlarm } from 'react-icons/md';
const AccessAlarm = (props) => {
return <Icon {...props} as={MdAccessAlarm} variant="secondary" />;
};

Using a loader like SVGR makes it easier to use your own SVG files with the as prop as it helps import them as React components.

SVG paths

Another way to render custom icons is to wrapping SVG paths in the Icon component directly:

import { Icon } from '@contentful/f36-icon';
const CustomIcon = (props) => {
return (
<Icon {...props} variant="secondary">
<path d="M7 10l5 5 5-5z" />,
<path d="M0 0h24v24H0z" fill="none" />
</Icon>
);
};

Props

Built-in icons

Custom icons

NameRequiredDefaultTypeDescription
sizeIconSizeDetermines the size of the icon
trimmed
false
true
Whether or not to trim the icon width, i.e. set `width` to `auto`
variantIconVariantDetermines the fill color used
viewBoxstringCustom SVG viewBox attribute to use
asHTML Tag or React Component, e.g. div, span, etc.
childrenReactElement<any, string | JSXElementConstructor<any>> | ReactElement<any, string | JSXElementConstructor<any>>[]
classNamestringCSS class to be appended to the root element
styleCSSPropertiesAccepts a JavaScript object with camelCased properties rather than a CSS string
testIdstringA [data-test-id] attribute used for testing purposes