项目作者: ui-js

项目描述 :
A build system for managing cross-platform design systems using design tokens.
高级语言: TypeScript
项目地址: git://github.com/ui-js/chromatic.git
创建时间: 2019-11-26T18:02:19Z
项目社区:https://github.com/ui-js/chromatic

开源协议:MIT License

下载


Chromatic

A tool to help manage design systems by generating platform-specific files from
a source file describing design tokens.

Expressive Design Tokens

Tokens can contain rich expressions in a natural syntax, including arithmetic
operations, units (12px), function (rgb(), mix(), saturate()…) and
references to other tokens.

  1. tokens:
  2. primary-hue: '210deg'
  3. primary: 'hsl({primary-hue}, 100%, 40%)'
  4. primary-dark: 'darken({primary}, 20%)'
  5. line-height: '18pt + 5px'

Themes

Each token can have a theme variant, such as dark/light, or compact/cozy
layouts. The necessary output artifacts are generated automatically.

  1. tokens:
  2. cta-button-background:
  3. value:
  4. dark: '#004082'
  5. light: '#0066ce'

Zero-conf

Get going quickly. A simple token file written YAML or JSON file is all you
need.

But Chromatic is also customizable when you need to. You can write or modify the
format of the output files to suit your needs.

Chromatic is also available as an API that can be invoked from a build system.

Multi-platform

From a single token file, generate platform specific artifacts:

  • for the web (Sass, CSS)
  • for iOS (JSON, plist)
  • for Android (XML)

Chromatic can also generate a style guide as a HTML file.

Getting started with Chromatic

  1. $ npm install -g @arnog/chromatic

To create a directory with an example:

  1. $ chromatic example ./test
  2. $ chromatic ./test -o tokens.scss
  3. $ chromatic ./test -o tokens.html

Or writing your own token file:

  1. # tokens.yaml
  2. tokens:
  3. background: '#f1f1f1'
  4. body-color: '#333'
  1. $ chromatic tokens.yaml -o tokens.scss
  1. $background: #f1f1f1 !default;
  2. $body-color: #333 !default;

Now, let’s create a dark theme:

  1. # tokens-dark.yaml
  2. theme: dark
  3. tokens:
  4. background: '#222'
  5. body-color: '#a0a0a0'
  1. # tokens.yaml
  2. import: ./tokens-dark.yaml
  3. tokens:
  4. background: '#f1f1f1'
  5. body-color: '#333'
  1. $ chromatic tokens.yaml -o tokens.scss
  1. :root {
  2. --background: #f1f1f1;
  3. --body-color: #333;
  4. }
  5. body[data-theme='dark'] {
  6. --background: #222;
  7. --body-color: #a0a0a0;
  8. }