npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@balena/design-tokens

v0.11.0

Published

## What's this?

Downloads

4,721

Readme

Balena Design Tokens

What's this?

Design tokens are small bits of design decisions that can be used across different platforms and projects. They define the visual language of a product, and help create a consistent experience across different platforms.

Practically, this package will serve two purposes:

  • Be the source of truth for design decisions: instead of using absolute values in your project, you can import this package and reference tokens in a variety of ways (currently with an ES module and CSS custom properties).
  • Add a layer of semantics: tokens are more descriptive and convey meaning. For example, instead of relying on abstract naming such as primary.main or quartenary.lightest, tokens convey meaning and context. Examples: color.text.accent or color.bg.success.strong.

Usage

Install the package in your project

npm install @balena/design-tokens

TypeScript

import tokens from '@balena/design-tokens';

console.log(tokens.color.text.accent.value); // outputs '#1496e1'

You can also import categories directly:

import { color } from '@balena/design-tokens';

console.log(color.text.accent.value); // outputs '#1496e1'

CSS

The file @balena/design-tokens/build/css/tokens.css contains all the tokens as CSS custom properties.

The way you would import this file depends on the project. In a typical create-react-app project (or similar) you should be able to import it in a tsx file:

import '@balena/design-tokens/build/css/tokens.css';

The custom properties will be added to the :root element, and you can use them anywhere like so:

.alert.success {
	border: solid 1px var(--color-border-success);
	background-color: var(--color-bg-success);
	color: var(--color-text-success);
}

Note

A JSON object containing all tokens with extra information is also available for documentation purposes.

Update tokens

The tokens are exported from our Figma Design System library: https://www.figma.com/file/P7wVVPymUK4ekV6QOa3i0s/Design-System?type=design&t=hi4n82bo8vGO8noO-6

The export is a 3 steps process:

  1. Download a JSON file using the Design Tokens plugin to export the tokens from Figma.
  2. Replace the existing file in tokens/design-tokens.json with the one you downloaded
  3. (Optional) Run npm run build to generate the new tokens in the build folder
  4. Create a new branch and open a PR with the changes

TODO: this process can be greatly improved by using the "Send Design Tokens to URL" feature of the plugin, which would allow for a more streamlined process.

Plugin settings

Please replicate the settings exactly as shown in the screenshots below:

plugin_settings.png plugin_export_settings.png

Contribute

How it works

This package uses Style Dictionary to generate the tokens. The tokens are defined in tokens/design-tokens.json, and the build process will generate the tokens in the build folder.

Install dependencies

npm install

Develop (watch the token folder)

npm start

Build the tokens

npm run build

Run the tests

npm run test

Custom formats

See scripts/transform.ts.

Custom formats were created to generate the ES module and its typescript declarations, as standard formats didn't meet our requirements:

  • ES module export
  • default exports to single categories for easier imports (import { color } from '@balena/design-tokens')
  • Path simplification (see below)

Path simplification

The goal of this package is to offer engineers the easiest way possible to implement design decisions into their own projects. In this respect, we decided to shorten the path of the tokens as much as possible. So we don't use a "default" modifier, instead we reduce the path to the minimum:

color.bg.accent.default
color.bg.accent

By using a _ prefix, we can also easily filter out the default tokens from the Figma plugin in Style Dictionary CSS transform. But this is not available for JS objects, and that's the point of the flattenDefaultTokens.