Kitten

Reference sections

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:

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:

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:

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>
      </>
    `)}
  `
}

Like this? Fund us!

Small Technology Foundation is a tiny, independent not-for-profit.

We exist in part thanks to patronage by people like you. If you share our vision and want to support our work, please become a patron or donate to us today and help us continue to exist.