React

Composition

Explains how to use icons.

Overview

Karrot icon library is designed to be independent (agnostic) of the design system and does not include Crispy's opinions. Sometimes you need to use icon composition patterns while using custom icons that are not in the library.

For this purpose, we provide utility components that accept icons through the svg attribute and connect them to the design system:

  • Icon: Use when using icons independently or in components that display icons only.
  • PrefixIcon, SuffixIcon: Use when placing icons and text together within a component.

Icon Component

The Icon component is used when using icons independently or in components that display icons only.

import { Icon } from "@seed-design/react";
import { IconHeartFill } from "@karrotmarket/react-monochrome-icon";

// Standalone icon
<Icon svg={<IconHeartFill />} />

// Button displaying only an icon
<ActionButton layout="iconOnly">
  <Icon svg={<IconPlusLine />} />
</ActionButton>

PrefixIcon and SuffixIcon

When placing icons and text together within a component, place PrefixIcon and SuffixIcon components as children.

import { PrefixIcon, SuffixIcon } from "@seed-design/react";
import { ActionButton } from "seed-design/ui/action-button";
import { IconPlusFill, IconChevronRightFill } from "@karrotmarket/react-monochrome-icon";

// Place icon in front
<ActionButton>
  <PrefixIcon svg={<IconPlusFill />} />
  Label
</ActionButton>

// Place icon at the back
<ActionButton>
  Label
  <SuffixIcon svg={<IconChevronRightFill />} />
</ActionButton>

// Place icons on both sides
<ActionButton>
  <PrefixIcon svg={<IconPlusFill />} />
  Label
  <SuffixIcon svg={<IconChevronRightFill />} />
</ActionButton>

This pattern is used consistently in the following components:

  • ActionButton: Icon placement within a button
  • Button: Icon placement within a regular button
  • ToggleButton: Icon placement within a toggle button
  • ActionChip: Icon placement within an action chip
  • ControlChip: Icon placement within a control chip

Table of contents