Skip to content

Instantly share code, notes, and snippets.

@unekinn
Created June 14, 2024 08:34
Show Gist options
  • Save unekinn/c06effb555326d9ea9b248e8794b9601 to your computer and use it in GitHub Desktop.
Save unekinn/c06effb555326d9ea9b248e8794b9601 to your computer and use it in GitHub Desktop.
Generated README when running create script with themes "First theme" & "Second theme", and light/dark/contrast modes, to the "digdir-tokens-test" directory

Design tokens for @digdir/designsystemet

Getting started

npm install
npm run build

The package is set up for publishing as an NPM library with npm publish. Ensure package.json is satisfactory before you do this.

Next steps

Using the themes in Figma

  1. Initialise a git repository in the current directory
  2. Push the tokens to GitHub, GitLab or Azure DevOps
  3. Open the Figma component library and save it to your project
  4. Install the Tokens Studio plugin in Figma
  5. Set up sync in Tokens Studio for Figma
  6. Use the "Create variables" action in Tokens Studio
  7. Push the resulting variables from Tokens Studio to Git

Customizing the themes

  1. Go to https://theme.designsystemet.no and set up a color theme
  2. Press "Kopier tema"
  3. Under "Json til Figma", copy the contents under Light / Dark / Contrast to the corresponding file under design-tokens:
    First theme, Light: primitives/colors/light/first-theme.json
    First theme, Dark: primitives/colors/dark/first-theme.json
    First theme, Contrast: primitives/colors/contrast/first-theme.json
    Second theme, Light: primitives/colors/light/second-theme.json
    Second theme, Dark: primitives/colors/dark/second-theme.json
    Second theme, Contrast: primitives/colors/contrast/second-theme.json
    This can also be done in Tokens Studio for Figma.
  4. IMPORTANT! In the JSON data you copied, replace theme on line 2 with the correct theme identifier, depending on the theme you're customizing. This is the same as the json filename without extension (e.g. first-theme, second-theme).
  5. Repeat steps 1—4 for the remaining themes

Removing unused themes from Figma components

The "Designsystemet - Core UI Kit" component library is set up with the themes "Theme1" and "Theme2" by default. To ensure our custom themes are used, follow these steps:

  1. Access the Variables modal
  2. Select the "Theme" collection in the upper left dropdown
  3. Select "All variables"
  4. Right click the modes "Theme1" and click "Delete mode"
  5. Repeat for "Theme2"
  6. Publish the library

Using the themes in code

The current directory is set up to easily publish the themes as an npm package.

  1. Check that the package.json file is set up to your liking
  2. npm install
  3. npm run build - builds the css files for each theme and outputs them to ./dist
  4. npm publish - publishes the package to npm as digdir-tokens-test, unless you manually changed package.json

In a different npm package (e.g. a frontend web app), follow the "Get started" instructions at https://github.com/digdir/designsystemet but replace @digdir/designsystemet-theme with digdir-tokens-test. In short:

Install packages

npm i digdir-tokens-test @digdir/designsystemet-css @digdir/designsystemet-react

Import the default theme and use components

import 'digdir-tokens-test';
import '@digdir/designsystemet-css';
import { Button } from '@digdir/designsystemet-react';

Or import a specific theme

import 'digdir-tokens-test/second theme.css';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment