Icons
How buttery draws icons, at which sizes, and when an icon needs a label.
Icon draws an icon from lucide-react at one of buttery's sizes, with the stroke weight and color of the text around it. Use it for every icon, and give it a label when nothing next to it says what it means.
Sizes
size="sm" (16px, the default) is for icons inside controls and beside text. size="md" (20px) is for icons that stand on their own, such as an empty state's.
import type { ReactElement } from "react";
import { Icon, Inline, Text } from "@butteryui/core";
import { Truck } from "lucide-react";
export function ShippingNote(): ReactElement {
return (
<Inline gap={2} align="center">
<Icon icon={Truck} />
<Text variant="body-sm">Ships in two days</Text>
</Inline>
);
}Labels
An icon is hidden from screen readers unless it has a label, because the text beside it usually says the same thing. When an icon stands alone and means something, give it a label and it becomes an image named by it.
import type { ReactElement } from "react";
import { Icon } from "@butteryui/core";
import { TriangleAlert } from "lucide-react";
export function PaymentFailed(): ReactElement {
return <Icon icon={TriangleAlert} label="Payment failed" />;
}An icon that means something on its own says what.
import type { ReactElement } from "react";
import { Icon, Inline, Text } from "@butteryui/core";
import { Truck } from "lucide-react";
export function Shipping(): ReactElement {
return (
<Inline gap={2} align="center">
<Icon icon={Truck} label="Shipping" />
<Text variant="body-sm">Shipping</Text>
</Inline>
);
}A label that repeats the text beside it is read twice.
Icon buttons. A button that's only an icon is an IconButton, which takes a required label and shows it as a tooltip.
The arrow and the spinner
Two drawn parts sit beside the icon set. Reach for them through Button's props first, and on their own only inside a control of your own.
Arrow
Arrowis the navigation arrow thatButtonandArrowLinkdraw beside their label: a chevron,direction="forward"or"back", that grows a stem into an arrow while the control holding it, markeddata-arrow, is hovered or focused. Only transforms change, so the control never changes size. On aButton, it's thearrowprop.Spinner
Spinneris the small turning ring a busy control shows over its label, and it holds still with reduced motion. On aButton, it's theloadingprop, which keeps the button's size while it's busy.
Icon
When to use it
Use it for
- Icons inside buttons, rows and empty states
Not for
- An icon as the only content of a button: use IconButton, which requires a label
Examples
Control icons
Header buttons that show only an icon at the control size, each icon labelled so it names its button.
Nothing yet
Empty state icon
The larger icon size above an empty state's title.
Add your first photo
Sizes
The two sizes, 16px for controls and 20px for empty states, both with a 1.75 stroke.
sm, 16px
md, 20px
Variants and states
Sizes
16px inside controls, 20px in empty states; stroke 1.75 at both.
sm
md
labelled
Props
Icon
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<SVGSVGElement> | The rendered svg. | |
iconrequired | ComponentType<IconComponentProps> | The icon to draw, such as Undo2 from lucide-react. | |
size | "sm" | "md" | "sm" | "sm" (16px, the default) inside controls; "md" (20px) in empty states. Stroke is 1.75 at both sizes. |
label | string | What the icon means, for screen readers. Leave it out when the icon sits next to text that already says the same thing: the icon is then hidden from assistive technology. |
It also takes Omit<SVGProps<SVGSVGElement>, "children">.
Accessibility
Hidden from screen readers unless it has a label, in which case it's an image with that name.
It takes no keyboard input of its own.
Motion
It doesn't move.
With reduced motion: Nothing changes.
Layout
A square of --bt-icon-sm (16px) or, at size md, --bt-icon-md (20px), stroked at 1.75, that never grows or shrinks in a row. It has no hit area of its own: a pressable icon takes its size and name from the button around it, as IconButton does.
Related
Related
- IconButton
A square button that shows only an icon, named by a label that also appears as its tooltip.
- Typography
buttery's type roles, the fonts behind them, and the Text and TextStack primitives that set them.