Icon
An icon as data, an image with a name when it means something and ornament when it does not.
Previews are drawn in the theme you made.
Edit itNamed and decorative #
import { Icon, IconSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
import { icons } from '../../view/iconData.js'
// An icon is data (here from `icons.json`, built by the icons plugin). With a
// `label` it is an image that has a name; without one it is ornament and a
// screen reader skips it. Two copies of one icon on a page need a `key`.
export default example({
title: 'Named and decorative',
slots: IconSlots,
recipe: Recipes.Icon,
view: ({ style, h }) =>
row(h, [
Icon.view({ icon: icons.check, label: 'Saved', style }, h),
Icon.view({ icon: icons.link, label: 'Linked', key: 'link', style }, h),
h.span([], ['Copy ', Icon.view({ icon: icons.copy, key: 'copy', style }, h)]),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Sizes #
import { Icon, IconSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
import { icons } from '../../view/iconData.js'
const Sizes = (['xs', 'sm', 'md', 'lg', 'xl'] as const).map(size => Recipes.Icon.style({ size }))
// With no size an icon stands on the size ladder, so it steps with the control
// it sits in; a size fixes it to the type scale, `xs` to `xl`.
export default example({
title: 'Sizes',
slots: IconSlots,
recipe: Recipes.Icon,
pins: { size: 'md' },
view: ({ h }) =>
row(
h,
Sizes.map((style, index) => Icon.view({ icon: icons.check, key: `size-${index}`, style }, h)),
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Tiles #
import { Icon, IconSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
import { icons } from '../../view/iconData.js'
const Surfaces = (['outline', 'soft', 'solid', 'raised'] as const).map(surface =>
Recipes.Icon.style({ surface, tone: 'accent', size: 'lg' }),
)
// A `surface` makes the box a tile around the icon, twice its size; `tone`
// inks the icon and colours the tile. Pick a surface and a tone above.
export default example({
title: 'Tiles',
slots: IconSlots,
recipe: Recipes.Icon,
pins: { surface: 'soft', size: 'lg' },
view: ({ style, h }) =>
row(h, [
Icon.view({ icon: icons.check, key: 'tile', label: 'Saved', style }, h),
...Surfaces.map((tile, index) =>
Icon.view({ icon: icons.link, key: `surface-${index}`, style: tile }, h),
),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Your own drawing #
import { Icon, IconSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// `glyph` is a drawing of your own in the box instead of icon data: initials,
// a count, an emoji. It is as large as an icon of the same size would be.
export default example({
title: 'Your own drawing',
slots: IconSlots,
recipe: Recipes.Icon,
pins: { surface: 'soft', shape: 'circle', size: 'md' },
view: ({ style, h }) =>
row(h, [
Icon.view({ glyph: h.span([], ['AL']), label: 'Ada Lovelace', style }, h),
Icon.view({ glyph: h.span([], ['12']), label: '12 unread', style }, h),
Icon.view({ glyph: h.span([], ['🎉']), label: 'Celebration', style }, h),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A corner mark #
import { Badge, Icon, IconSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { icons } from '../../view/iconData.js'
const Count = Recipes.Badge.style({ appearance: 'solid', size: 'sm' })
// A `mark` sits on the corner of the box. It is inside the image, so what it
// means goes into the `label` too.
export default example({
title: 'A corner mark',
slots: IconSlots,
recipe: Recipes.Icon,
pins: { surface: 'outline', tone: 'neutral', size: 'lg' },
view: ({ style, h }) =>
Icon.view(
{
icon: icons.link,
label: 'Links, 3 broken',
mark: Badge.view({ text: '3', tone: 'danger', style: Count }, h),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Usage
Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.
Keyboard and accessibility
- With a
labelthe icon isrole="img"named by it; without one it isaria-hidden, which is right beside words. - An icon alone in a control needs the label on the control or on the icon: a glyph with neither says nothing.