Icons
@clawscale/react/icons holds Blueprint's UI icons, drawn on a 16px and a 20px grid. Render one by name with the Icon component, or import it as a component of its own.
Usage#
import { Icon } from "@clawscale/react";
import { DatabaseIcon, IconNames } from "@clawscale/react/icons";<Icon icon="database" />Browse every name in the Icons list. To render icons on the server, read Loading icons.
Examples#
Basic#
icon takes an icon name. Names are typed, so editors complete them and typos fail to compile. Components with an icon prop, such as Button and Tag, take the same names. Screen readers skip an icon unless you give it a title.
import { Icon } from "@clawscale/react";
const stages = [
{ icon: "import", label: "Ingest" },
{ icon: "data-lineage", label: "Transform" },
{ icon: "database", label: "Load" },
{ icon: "cloud-upload", label: "Publish" },
] as const;
export default function IconsBasic() {
return (
<>
{stages.map(({ icon, label }) => (
<span key={label} style={{ alignItems: "center", display: "inline-flex", gap: 6 }}>
<Icon icon={icon} />
{label}
</span>
))}
<Icon icon="lock" title="Encrypted at rest" />
</>
);
}Sizes#
size sets the width and height in pixels, 16 by default. Below 20, an icon uses its 16px paths. From 20 up, it uses its 20px paths, which have more detail. IconSize.STANDARD is 16 and IconSize.LARGE is 20.
import { Icon } from "@clawscale/react";
export default function IconsSizes() {
return (
<div style={{ alignItems: "flex-end", display: "flex", gap: 24 }}>
{[12, 16, 20, 32, 48].map((size) => (
<div key={size} style={{ display: "grid", gap: 8, justifyItems: "center" }}>
<Icon icon="globe-network" size={size} />
<span style={{ color: "var(--cs-color-text-muted)", fontSize: "var(--cs-font-size-xs)" }}>{size}px</span>
</div>
))}
</div>
);
}Intent and color#
intent colors an icon like any other component. color takes any CSS color, tokens included, and overrides intent. Without either, an icon takes the text color.
import { Icon } from "@clawscale/react";
const statuses = [
{ icon: "tick-circle", intent: "success", label: "Healthy" },
{ icon: "warning-sign", intent: "warning", label: "Degraded" },
{ icon: "error", intent: "danger", label: "Down" },
{ icon: "wrench", intent: "primary", label: "Maintenance" },
] as const;
export default function IconsIntent() {
return (
<>
{statuses.map(({ icon, intent, label }) => (
<span key={label} style={{ alignItems: "center", display: "inline-flex", gap: 6 }}>
<Icon icon={icon} intent={intent} />
{label}
</span>
))}
<span style={{ alignItems: "center", display: "inline-flex", gap: 6 }}>
<Icon icon="pause" color="var(--cs-color-text-muted)" />
Paused
</span>
</>
);
}Icon components#
Every icon is also a component, named after it with an Icon suffix: database is DatabaseIcon. Its paths ship inside the component, so it renders without loading anything, and tree-shaking bundlers keep only the icons you import. Pass it to any icon prop. Icon components take size, color and title, but not intent. The names without the suffix, such as Database, are deprecated.
import { Button, Tag } from "@clawscale/react";
import { CloudUploadIcon, DatabaseIcon, GitBranchIcon } from "@clawscale/react/icons";
export default function IconsComponents() {
return (
<>
<DatabaseIcon />
<CloudUploadIcon size={20} color="var(--cs-color-primary)" />
<Button icon={<GitBranchIcon />} text="Create branch" />
<Tag minimal icon={<DatabaseIcon />}>
warehouse-prod
</Tag>
</>
);
}Icon name constants#
IconNames maps constants to names: IconNames.DataLineage is "data-lineage". Use it when you build icon maps in code. Uppercase keys, such as IconNames.DATA_LINEAGE, are the older style.
orders_raworders_dailyfinance_extractimport { Code, Icon } from "@clawscale/react";
import { type IconName, IconNames } from "@clawscale/react/icons";
type JobKind = "ingest" | "transform" | "export";
const jobIcons: Record<JobKind, IconName> = {
ingest: IconNames.Import,
transform: IconNames.DataLineage,
export: IconNames.Export,
};
const jobs: { name: string; kind: JobKind }[] = [
{ name: "orders_raw", kind: "ingest" },
{ name: "orders_daily", kind: "transform" },
{ name: "finance_extract", kind: "export" },
];
export default function IconsIconNames() {
return (
<div style={{ display: "grid", gap: 8 }}>
{jobs.map(({ name, kind }) => (
<span key={name} style={{ alignItems: "center", display: "flex", gap: 8 }}>
<Icon icon={jobIcons[kind]} />
<Code>{name}</Code>
</span>
))}
</div>
);
}Interactive playground#
Props interface#
type IconProps@clawscale/reactGeneric interface for the <Icon> component which may be parameterized by its root element type.
| Props | Description |
|---|---|
autoLoad | boolean = trueWhether the component should automatically load icon contents using an async import. Inherited from IconOwnProps |
children | neverThis component does not support child nodes. Inherited from SVGIconOwnProps |
className | stringA space-delimited list of class names to pass along to a child element. A space-delimited list of class names to pass along to the SVG element. Inherited from Props |
color | stringColor of icon. This is used as the Inherited from fill attribute on the <svg> image so it will override any CSS color property, including that set by intent. If this prop is omitted, icon color is inherited from surrounding text.SVGIconOwnProps |
htmlTitle | stringString for the Inherited from title attribute on the rendered element, which will appear on hover as a native browser tooltip.SVGIconOwnProps |
iconrequired | IconName | MaybeElementName of a Blueprint UI icon, or an icon element, to render. This prop is required because it determines the content of the component, but it can be explicitly set to falsy values to render nothing. Inherited from IconOwnProps |
intent | IntentVisual intent color to apply to element. Inherited from IntentProps |
size | number = 16Size of the icon, in pixels. Blueprint contains 16px and 20px SVG icon images, and chooses the appropriate resolution based on this prop. Inherited from SVGIconOwnProps |
style | React.CSSPropertiesCSS style properties. Inherited from SVGIconOwnProps |
svgProps | React.HTMLAttributes<SVGElement>Props to apply to the Inherited from SVG elementSVGIconOwnProps |
tagName | keyof React.JSX.IntrinsicElements | null = "span"HTML tag to use for the rendered element. Commonly "span" or "div". If Inherited from null, no wrapper will be rendered, just the <svg> element.SVGIconOwnProps |
title | string | false | nullDescription string. This string does not appear in normal browsers, but it increases accessibility. For instance, screen readers will use it for aural feedback. Inherited from SVGIconOwnProps |
The per-icon components, such as DatabaseIcon, take these props.
type SVGIconProps@clawscale/react/iconsInterface for generated icon components which have their name and icon paths statically defined inside their JS implementation.
| Props | Description |
|---|---|
children | neverThis component does not support child nodes. Inherited from SVGIconOwnProps |
className | stringA space-delimited list of class names to pass along to the SVG element. Inherited from SVGIconOwnProps |
color | stringColor of icon. This is used as the Inherited from fill attribute on the <svg> image so it will override any CSS color property, including that set by intent. If this prop is omitted, icon color is inherited from surrounding text.SVGIconOwnProps |
htmlTitle | stringString for the Inherited from title attribute on the rendered element, which will appear on hover as a native browser tooltip.SVGIconOwnProps |
size | number = 16Size of the icon, in pixels. Blueprint contains 16px and 20px SVG icon images, and chooses the appropriate resolution based on this prop. Inherited from SVGIconOwnProps |
style | React.CSSPropertiesCSS style properties. Inherited from SVGIconOwnProps |
svgProps | React.HTMLAttributes<SVGElement>Props to apply to the Inherited from SVG elementSVGIconOwnProps |
tagName | keyof React.JSX.IntrinsicElements | null = "span"HTML tag to use for the rendered element. Commonly "span" or "div". If Inherited from null, no wrapper will be rendered, just the <svg> element.SVGIconOwnProps |
title | string | false | nullDescription string. This string does not appear in normal browsers, but it increases accessibility. For instance, screen readers will use it for aural feedback. Inherited from SVGIconOwnProps |