Import
import { PlusIcon, DoneIcon } from '@contentful/f36-icons';
import * as icons from '@contentful/f36-icons';
import { Icon } from '@contentful/f36-icons';
Examples
Forma 36 provides a list of built-in icons that can be used as regular React components.
Icon variants
The icon components can be configured in different ways using variations in color and size:
function IconVariantsExample() {
return (
<Stack>
<Flex alignItems="center">
<Flex marginRight="spacingS">
<CalendarIcon variant="primary" />
</Flex>{' '}
<Text>Primary</Text>
</Flex>
<Flex alignItems="center">
<Flex marginRight="spacingS">
<CalendarIcon variant="positive" />
</Flex>{' '}
<Text>Positive</Text>
</Flex>
<Flex alignItems="center">
<Flex marginRight="spacingS">
<CalendarIcon variant="negative" />
</Flex>{' '}
<Text>Negative</Text>
</Flex>
<Flex alignItems="center">
<Flex marginRight="spacingS">
<CalendarIcon variant="warning" />
</Flex>{' '}
<Text>Warning</Text>
</Flex>
<Flex alignItems="center">
<Flex marginRight="spacingS">
<CalendarIcon variant="secondary" />
</Flex>{' '}
<Text>Secondary</Text>
</Flex>
<Flex alignItems="center">
<Flex marginRight="spacingS">
<CalendarIcon variant="muted" />
</Flex>{' '}
<Text>Muted</Text>
</Flex>
<Flex
style={{ backgroundColor: '#8091a5' }}
alignItems="center"
padding="spacingS"
>
<Flex marginRight="spacingS">
<CalendarIcon variant="white" />
</Flex>{' '}
<Text>White</Text>
</Flex>
</Stack>
);
}
Icon sizes
function IconSizesExample() {
return (
<Stack>
<Flex alignItems="center">
<CalendarIcon size="tiny" /> <Text>Tiny</Text>
</Flex>
<Flex alignItems="center">
<CalendarIcon size="small" /> <Text>Small</Text>
</Flex>
<Flex alignItems="center">
<CalendarIcon size="medium" /> <Text>Medium</Text>
</Flex>
<Flex alignItems="center">
<CalendarIcon size="large" /> <Text>Large</Text>
</Flex>
<Flex alignItems="center">
<CalendarIcon size="xlarge" /> <Text>Extra large</Text>
</Flex>
</Stack>
);
}
All icons
function AllIconsExample() {
const [deprecatedIcons, availableIcons] = Object.entries(f36icons).reduce(
(result, [name, icon]) => {
result[name.includes('Trimmed') ? 0 : 1].push([name, icon]);
return result;
},
[[], []],
);
return (
<Box>
<Grid columns="repeat(2, 1fr)">
{availableIcons.map(([name, icon]) => {
const Component = icon;
return (
<Flex
key={name}
padding="spacingS"
marginRight="spacingM"
flexDirection="column"
alignItems="flex-start"
>
<Flex marginRight="spacingS" gap="spacingXs">
<Component key={name} size="medium" />
<Text>{name}</Text>
</Flex>
</Flex>
);
})}
</Grid>
<Heading as="h3" marginTop="spacingM" marginBottom="spacingS">
Trimmed Variants <Badge variant="negative">deprecated</Badge>
</Heading>
<Subheading>
Trimmed Icons will no longer be available in the next Iteration
</Subheading>
<Grid columns="repeat(2, 1fr)">
{deprecatedIcons.map(([name, icon]) => {
const Component = icon;
return (
<Flex
key={name}
padding="spacingS"
marginRight="spacingM"
flexDirection="column"
alignItems="flex-start"
>
<Flex marginRight="spacingS" gap="spacingXs">
<Component key={name} size="medium" />
<Text>{name}</Text>
</Flex>
</Flex>
);
})}
</Grid>
</Box>
);
}
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: with as
prop and with an SVG path.
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
:
function IconAsPropExample() {
return <Icon 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:
function IconAsPropExample() {
return (
<Icon variant="secondary">
<path d="M7 10l5 5 5-5z" />
<path d="M0 0h24v24H0z" fill="none" />
</Icon>
);
}
Built-in icons
Custom icons
Name | Type | Default |
---|
as | HTML Tag or React Component (e.g. div, span, etc) | |
children | ReactElement<any, string | JSXElementConstructor<any>> | ReactElement<any, string | JSXElementConstructor<any>>[] | |
className | string CSS class to be appended to the root element | |
color | string Determines the color of the icon | |
isActive | false true Determines the active state of the icon | |
size | "medium" "small" "tiny" Determines the size of the icon | |
testId | string A [data-test-id] attribute used for testing purposes | |
viewBox | string Custom SVG viewBox attribute to use | |
Content guidelines
- Select an icon that accurately represents the subject
- Pair icons with text
- Position buttons consistently in the interface
- Ensure the meaning of the icon is consistent in all use cases
- Consider how the icon fits into the context of the screen and reduce complexity where possible