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

@onfido/castor-tokens

v1.0.0

Published

Design tokens for Castor.

Downloads

73,289

Readme

Castor Tokens

npm version Bundle size

This is Castor addition providing design tokens, including (CSS/Sass) themes.

Get started

Install package:

npm install @onfido/castor-tokens

Then add a theme by following either approach from examples below.

Setup using CSS

In order to use a theme with plain HTML + CSS, you must make the source available to public, and include it.

For example, if you serve your app from "public" directory, you can copy day.css and/or night.css files from node_modules/@onfido/castor-tokens/dist to public (or your root assets folder), then choose and include one theme in your HTML file from the following options:

<link rel="stylesheet" href="./day.css" />
<link rel="stylesheet" href="./night.css" />

Setup using Sass

@use Castor Tokens within your main Sass file:

@use '~@onfido/castor-tokens' as theme;

One time only, choose and include one theme within your root element from the following options:

:root {
  // "day" theme
  @include theme.day();

  // OR "night" theme
  @include theme.night();
}

Setup using CSS-in-JS (for example Emotion)

Choose and import one theme from the following options in your root JS file:

import '@onfido/castor-tokens/dist/day.css';
import '@onfido/castor-tokens/dist/night.css';

Switch theme

To be able to switch between one and another, use "classed" themes when importing, and switch with the helper:

import { switchTheme } from '@onfido/castor-tokens';

// switch to "day" theme
import '@onfido/castor-tokens/dist/day-class.css';
switchTheme('day');

// OR to "night" theme
import '@onfido/castor-tokens/dist/night-class.css';
switchTheme('night');

You can also include class themes within your Sass file instead:

@use '~@onfido/castor-tokens' as theme;

@include theme.day('class');
@include theme.night('class');

These themes are not applied to the root element but instead theme variables are scoped to CSS classes, which are then applied to the body element.

If you're using CSS modules, you must use a global scope when including class themes. For example, for PostCSS:

:global {
  @include theme.day('class');
  @include theme.night('class');
}

You can also switch a theme on any selectable elements, for example switching on a section using the custom theme:

.castor-theme--custom {
  // ...theme CSS variables
}
switchTheme('custom', document.querySelector('.section'));

If you do not use JavaScript, you might consider including a different CSS theme file based on URL parameter.

Lastly, if you're extremely concerned about efficiency, you can shave off 1-3 KBs by not including base tokens twice, if they're shared between the themes you're switching:

@use '~@onfido/castor-tokens' as castor;

:root {
  @include castor.tokens();
}

@include castor.day('class', 'raw');
@include castor.night('class', 'raw');