Socket
Socket
Sign inDemoInstall

@mijnoverheid/design-tokens

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mijnoverheid/design-tokens

MijnOverheid design tokens


Version published
Maintainers
2
Install size
40.7 kB
Created

Readme

Source

Design Tokens for the MijnOverheid Design System

This project is very much WORK IN PROGRESS and is released as alpha version. Always define the exact version you want to use, and test for breaking changes before upgrading to a newer alpha release.

Design tokens are design decisions for our design system, in this case maintained in JSON files, and distributed in various other code languages for easy reuse.

The design tokens in this package serve as single source of truth for the look and feel for our websites, apps and designs of new products and services.

List of all design tokens

To find out what design tokens are available, browser through the .style-dictionary.json files in the src/ directory.

We currently don't have any additional documentation for every specific design token.

Brand design tokens

Brand design tokens describe design choices regarding color and typography. We provide a limited choice of fonts and a limited color palette, please avoid choosing other fonts and colors.

Common design tokens

Common design tokens are relevant to a wide range of components and situations. They help provide a consistent user experience. We provide design tokens for feedback colors (error, success, et cetera), the focus state, spacing, and so on. Components should reuse design tokens from the common layer where possible, to achieve a consistent look and feel.

Component design tokens

Design decisions at a component level, to make components look a very specific way. They are applied by the component library of the design system.

Files in this package

dist/theme/index.css

Opt-in way to apply all the CSS variables to HTML elements with the mijnoverheid-theme class name:

<!DOCTYPE html>
<html class="mijnoverheid-theme">
  <!-- var(--mijnoverheid-typography-sans-serif-font-family) works here...! -->
</html>

This method is the preferred way to style the page.

dist/index.css

Automatically applies all the CSS variables to HTML elements to the :root element:

<!DOCTYPE html>
<html>
  <!-- var(--mijnoverheid-typography-sans-serif-font-family) works here...! -->
</html>

This method should only be used in case there is no control over the HTML template and the mijnoverheid-theme class name cannot be included.

dist/properties.css

Experimental CSS @property definitions for the design tokens that are configurable via CSS custom properties. Including these definitions is not necessarily side-effect free: with syntax invalid values for custom properties will be ignored, and inherits and initial-value declarations can influence behavior. Because not all browsers support the @property declaration, including this file can result in rendering differences between browsers.

<link rel="stylesheet" href="https://unpkg.com/@mijnoverheid/design-tokens/dist/properties.css" />

This file should only be included when you have visual regression test for both browsers that do and don't support @property.

dist/index.js

Use files from this package in JavaScript projects, for example in React Native or Storybook:

import { MijnoverheidButtonFontSize } from "@mijnoverheid/design-tokens/dist/index.js";

dist/_variables.scss

@import "~@mijnoverheid/design-tokens/dist/variables";

button {
  font-size: $mijnoverheid-button-font-size;
}

SCSS variables are not the preferred way to style components, it is better to use CSS variables, because they can be configured differently in a specific context, whereas SCSS variables are given a fixed value at build-time.

However, SCSS variables could be very useful to re-use values where CSS variables cannot be used, like inside CSS media queries:

@import "~@mijnoverheid/design-tokens/dist/variables";

@media (min-width: $mijnoverheid-viewport-scale-xl-width) {
  --mijnoverheid-heading-1-font-size: 3rem;
}

SCSS variables are also useful in the process of incrementally migrating away from your a codebase that currently uses SCSS, such as a website built with Bootstrap 4 components, by already using the design tokens as single source of truth. For example:

@import "../node_modules/bootstrap/scss/bootstrap";

$body-bg: $mijnoverheid-document-background-color;
$body-color: $mijnoverheid-document-color;

CSS variables

To use the design tokens in your site via CSS variables, first include the design token definitions in the <head> section of your HTML page:

<link rel="stylesheet" href="https://unpkg.com/@mijnoverheid/design-tokens/dist/index.css" />

Now the CSS variables will be available and you can use of all the design tokens:

.my-button {
  background-color: var(--mijnoverheid-color-red-50);
  color: var(--mijnoverheid-color-white);
}

SCSS variables

Contributing

The design tokens are stored in JSON files so we can use the design token translation tool Style Dictionary to make them available in many code languages. We use .style-dictionary.json as file extension for our design token definitions, to tell them apart from regular and unrelated .json files.

Style Dictionary only recognizes one nesting level per file, so be careful to not to mix nesting levels in one file and separate them into multiple files.

The following example doesn't work, because the CSS output would only be --mijnoverheid-button-focus-background-color: navy.

{
  "mijnoverheid": {
    "button": {
      "background-color": "blue",
      "focus": {
        "background-color": "navy"
      }
    }
  }
}

Organize the design tokens in multiple files instead:

block.style-dictionary.json:

{
  "mijnoverheid": {
    "button": {
      "background-color": "blue",
      "focus": {
        "background-color": "navy"
      }
    }
  }
}

modifier.style-dictionary.json:

{
  "mijnoverheid": {
    "button": {
      "background-color": "blue",
      "focus": {
        "background-color": "navy"
      }
    }
  }
}

CSS property definitions

Design tokens in Style Dictionary JSON files can include CSS custom property definitions. Using a custom formatter we output a CSS file with corresponding @property declarations.

{
  "mijnoverheid-color": {
    "css": { "syntax": "<color>", "inherits": true }
  },
  "mijnoverheid-font-family": {
    "css": { "syntax": "*", "inherits": true }
  },
  "mijnoverheid-text-align": {
    "css": { "syntax": "start | end", "inherits": true }
  }
}

syntax: any supported name, a list of tokens and * are allowed. Required.

inherits: typically set to true. While "inherits": false is supported, it is discouraged because not all target browsers support this yet. Required.

initialValue: also supported, but currently discouraged because not all browsers support @property yet and it would result in significant rendering differences between supporting and non-supporting target browsers.

License

Copyright © 2021 Logius. All rights reserved.

The open source license does NOT apply to files in this directory.

Applying design elements from this project is strictly prohibited for organisations that are not part of the central Government of The Netherlands.

This project is part of a community iniative to use NL Design System components for projects that need to adhere to Rijkshuisstijl. Organisations from the central Government of the Netherlands (for example: Belastingdienst, DUO, Logius, SVB), as well as those who are contracted by them to develop websites and apps, are able to collaborate via this project.

FAQs

Last updated on 27 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc