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.
Slots
| Component | Keys of icons | Size in px |
|---|---|---|
Accordion.Trigger | indicator | 16 |
AlertBanner | info, warning, error, success | 16 |
Calendar | previous, next | 14 |
Checkbox | checked, indeterminate | 10 |
Combobox | trigger, selected | 16, 14 |
DataTable | sortAscending, sortDescending, unsorted | 14 |
DatePicker, DateRangePicker | trigger, previous, next | 14 |
NavigationMenu.Trigger | indicator | 12 |
NumberField | decrement, increment | 14 |
Pagination.Previous | previous | 14 |
Pagination.Next | next | 14 |
Select | trigger, selected | 16, 14 |
SelectItem | selected | 14 |
ToastProvider | info, success, warning, error, loading, close | 16, 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-hiddenon your own SVG. Lucide, Heroicons, and Phosphor set it for you. - An
IconButtonhas only an icon, so it must have anaria-label.