Reference sections
Reference āŗ Icons
In your Kitten app, you can access the icons as stateless Kitten components at the following namespace:
kitten.icons
In that namespace, you browse the icons in three ways:
- Directly, by name, e.g.,
kitten.icons.cat - In categories, e.g.,
kitten.icons.categories.nature.cat - Using tags, e.g.,
kitten.icons.tags.kitten.cat
The categories and tags objects are authoring-time aids. While you can use them in your code, itās better practice to reference the icons directly from the root namespace. These two properties are marked as unenumerable so they do not pollute the namespace and will not show up if youāre iterating over all the icons in the root namespace.
To get autocompletion in your editor, your editor must support the TypeScript language server (any modern code editor worth using will e.g., Helix editor, etc.) Beyond that, please see the type-safety section for how to set up your project so it uses Kittenās types.
Kitten includes a subset of the Phosphor icon set by Helena Zhang and Tobias Fried as Kitten components.
The main difference with the original set is that some icons have been removed and some have been renamed to bring the library in line with the Small Technology Principles.
Specifically:
All brand icons for Big Tech/Silicon Valley/surveillance capitalists/people farmers have been removed.
The words āuserā and āusersā have been replaced with āpersonā and āpeopleā. (In Small Tech and on the Small Web we donāt have users, we have people, and we treat them as such.)
e.g., The Phosphor icon called
user-checkexists as a Kitten component atkitten.icons.personCheck. The icon āuserā has been renamed to āperson-close-upā (as there is already a āpersonā icon) and may be found atkitten.icons.personCloseUp.The BTC icon has been removed (proof of work; environmental concerns).
You can use the components in your kitten.html as you would any other Kitten component.
e.g., A simple Kitten page that displays a large, pink cat icon in duotone:
export default function () {
return kitten.html`
<${kitten.icons.cat}
size=40%
weight=duotone
colour=deeppink
/>
`
}
As the icons are Kitten components, you can customise how they appear by passing properties (āpropsā) to them:
alt: Alternative text (alt-text). Provide this to explain the purpose of the icon for people who use screen readers. If no alt text is provided, it will default to the name of the icon.colour: Pass a CSS colour. Defaults tocurrentColor, which will pick up the colour of its context.weight: One ofregular,light,thin,bold,fill, orduotone. Defaults toregular.size: Pass a CSS measurement to use as the width/height (the icons are square). Defaults to1em.mirror: Pass a boolean. Mirroring can be useful in right-to-left layouts. Defaults tofalse.
And other props you provide will be passed as attributes to the SVG tag of the icon.
You can extend the SVG (e.g., to add animation, etc.) by slotting any valid SVG content into it.
e.g., This makes the cat into a Cheshire cat (fades in and out):
export default function () {
return kitten.html`
<${kitten.icons.cat}
size=40%
weight=duotone
colour=deeppink
>
<animate
attributeName="opacity"
values="0;1;0"
dur="3s"
repeatCount="indefinite"
/>
</>
`
}
While the above example is good for a one-time use modification, you can, of course also make a reusable cheshireCat component.
Hereās one that has all the same defaults as the one in the above example but is fully configurable via props.
Notice how it passes any other props it receives to the base component itās extending via composition.
const cheshireCat = ({duration = 3, minOpacity = 0, maxOpacity = 1, ...props}) => {
return kitten.html`
<${kitten.icons.cat} ...${props}>
<animate
attributeName="opacity"
values="${minOpacity};${maxOpacity};${minOpacity}"
dur="${duration}s"
repeatCount="indefinite"
/>
</div>
`
}
export default function () {
return kitten.html`
<${cheshireCat}
size=40%
weight=duotone
colour=deeppink
/>
`
}
Hereās a simple example that displays all the icons, separated alphabetically, with their component names appearing in a tooltip when you hover over them.
export default function () {
return kitten.html`
<page css>
<markdown>
# All icons
These are all the icons in the [code]kitten.icons[code] namespace.
</markdown>
${Object.entries(kitten.icons).map(([name, icon]) => kitten.html`
<${icon} size=2em weight=duotone colour=deeppink>
<title>${name}</title>
</>
`)}
`
}