Icons

Use Lucide, Heroicons, Phosphor, or your own SVG icons, and replace the icons that matix renders.

matix/ui has no icon package. You bring an icon library, and matix works with each library that renders an SVG. There are two cases: the icons that you put in a component, and the small set of icons that matix renders itself.


Icons that you put in a component

Pass the icon as a child, or to a prop such as the icon prop of Badge. Set the size to 1em, so the icon follows the font size of the component.

import { Trash2 } from 'lucide-react';
import { Button } from '@matix/components/button';
import { IconButton } from '@matix/components/icon-button';

<Button variant="destructive">
  <Trash2 size="1em" />
  Delete
</Button>

<IconButton aria-label="Delete">
  <Trash2 size="1em" />
</IconButton>

Each library has its own way to set the size:

// Lucide and Phosphor take a size prop.
<ChevronDown size="1em" />
<CaretDown size="1em" />

// Heroicons take width and height.
<ChevronDownIcon width="1em" height="1em" />

// Your own SVG: use 1em, and currentColor for the stroke or the fill.
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor">
  <path d="m6 9 6 6 6-6" />
</svg>

Icons that matix renders

Some components render an icon of their own: the chevron of a Select, the check of a Checkbox, the status icon of a toast. These built-in icons use the Lucide style. If your app uses a different library, replace them with the icons prop.

import { ChevronsUpDown, Check } from 'lucide-react';
import { Select } from '@matix/components/select';

<Select
  options={options}
  icons={{
    trigger: <ChevronsUpDown size="1em" />,
    selected: <Check size="1em" />,
  }}
/>
  • Each key takes an element, not a component. An element can pass from a Server Component to a client component.
  • Set the size to 1em. The component sets the font size of each slot, so the icon gets the same size as the built-in icon.
  • A key that you leave out keeps its built-in icon. The component keeps the color, the open rotation, and the right-to-left flip of the slot.

Example

Select a library. Each component below gets its icons from that library through the icons prop.

The icons match your library

Slots

ComponentKeys of iconsSize in px
Accordion.Triggerindicator16
AlertBannerinfo, warning, error, success16
Calendarprevious, next14
Checkboxchecked, indeterminate10
Comboboxtrigger, selected16, 14
DataTablesortAscending, sortDescending, unsorted14
DatePicker, DateRangePickertrigger, previous, next14
NavigationMenu.Triggerindicator12
NumberFielddecrement, increment14
Pagination.Previousprevious14
Pagination.Nextnext14
Selecttrigger, selected16, 14
SelectItemselected14
ToastProviderinfo, success, warning, error, loading, close16, close 14

Parts that are only an icon

A part that renders only an icon takes the new icon as its child. These parts are Dialog.Close, Drawer.Close, Popover.Close, the Menu item indicators, and Breadcrumb.Separator. These parts do not set a font size for the icon, so give the icon a size in pixels. The built-in icons of these parts are 14 px.

<Dialog.Close>
  <XMarkIcon width={14} height={14} />
</Dialog.Close>

Set the icons one time

matix has no global icon setting, because a global setting needs React context in each component. Wrap the component one time in your app, and import the wrapper.

// components/select.tsx
import { ChevronDownIcon, CheckIcon } from '@heroicons/react/16/solid';
import { Select as MatixSelect } from '@matix/components/select';
import type { ComponentProps } from 'react';

const icons = {
  trigger: <ChevronDownIcon width="1em" height="1em" />,
  selected: <CheckIcon width="1em" height="1em" />,
};

export function Select(props: ComponentProps<typeof MatixSelect>) {
  return <MatixSelect icons={icons} {...props} />;
}

For toasts, pass icons to ToastProvider. It applies to each toast.


Match the stroke weight

If you keep the built-in icons, you can change their stroke weight to match your library. Set --mtx-icon-stroke-width in your CSS, or use the Icon Stroke control on the Customize page. The variable changes only the built-in icons.

:root {
  /* 1.5 matches Heroicons. 2 matches Lucide. The default is 1.75. */
  --mtx-icon-stroke-width: 1.5;
}

Accessibility

  • Each slot is decorative. The component gives the control its name, for example through labels, so the icon needs no text.
  • Set aria-hidden on your own SVG. Lucide, Heroicons, and Phosphor set it for you.
  • An IconButton has only an icon, so it must have an aria-label.