Skip to content

Icons

The network's icons in one place, one path each on a 24-unit grid.

<ul class="ic-grid" id="ic-ui"></ul>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/icons.css";
import { iconSvg } from "capsomer/behavior/icons";

Usage

import { Icon, iconArrowRight, iconExternal, iconSearch, markFacebook } from "capsomer/react/icons";

<button type="button" className="cap-btn" aria-label="Search"><Icon d={iconSearch} /></button>
<a href="https://example.com/team"><Icon {...markFacebook} /> Example Co on Facebook</a>
<Icon d={iconExternal} label="Opens another site" />
<button type="submit" className="cap-btn">Continue<Icon d={iconArrowRight} data-icon="end" /></button>
<Icon d="M3 13h2l7-7-2-2-7 7z" box={16} />
import { iconSvg, iconSearch, markX } from "capsomer/behavior/icons";

button.append(iconSvg(iconSearch));
link.append(iconSvg(markX.d, markX));

Examples

Social marks

<ul class="ic-grid" id="ic-social"></ul>

In a button, labeled, and in a link

<div class="cap-specimen-row">
  <button type="button" class="cap-btn" aria-label="Search" id="ic-button"><svg class="cap-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14zM20 20l-3.2-3.2" /></svg></button>
  <button type="button" class="cap-btn" data-variant="secondary"><svg class="cap-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 4v11M7 10l5 5 5-5M5 20h14" /></svg> Download</button>
  <svg class="cap-icon" id="ic-labeled" viewBox="0 0 24 24" role="img" aria-label="Opens another site" focusable="false"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5" /></svg>
</div>

API reference

Icon

PropTypeRequiredDoes
dstringYes
boxnumber
fillboolean
labelstring
classNamestring
data-icon"start" | "end"

Functions

FunctionSignatureDoes
iconSvg(d: string, options?: { label?: string | undefined; fill?: boolean | undefined; box?: number | undefined; }): SVGSVGElementAn icon as an <svg> element, built with the DOM (no markup string, so no Trusted Types sink), from its path: iconSvg(iconSearch), or a social mark iconSvg(markX.d, markX). It is hidden from assistive technology unless it is given a label, which names it as an image.

Parts and data attributes

ClassIs
.cap-iconthe root
.cap-icon-flipa part
AttributeValues
data-fillpresent or absent
data-flippresent or absent

Accessibility

  • An icon beside words or inside a named button is decoration (aria-hidden="true"); one that stands alone and says something gets label, which makes it role="img".
  • It takes the text's size and color (currentColor), so it follows its button or link through hover, focus, disabled and forced colors.
  • Right to left: data-flip mirrors an icon that points (arrows, chevrons).