• Stars
    star
    3,880
  • Rank 11,299 (Top 0.3 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A build system for creating cross-platform styles.
What's new in Style Dictionary 3.0!

Style Dictionary logo and mascot

npm version license PRs welcome GitHub Workflow Status downloads

Style Dictionary

Style once, use everywhere.

A Style Dictionary uses design tokens to define styles once and use those styles on any platform or language. It provides a single place to create and edit your styles, and exports these tokens to all the places you need - iOS, Android, CSS, JS, HTML, sketch files, style documentation, etc. It is available as a CLI through npm, but can also be used like any normal node module if you want to extend its functionality.

When you are managing user experiences, it can be quite challenging to keep styles consistent and synchronized across multiple development platforms and devices. At the same time, designers, developers, PMs and others must be able to have consistent and up-to-date style documentation to enable effective work and communication. Even then, mistakes inevitably happen and the design may not be implemented accurately. Style Dictionary solves this by automatically generating style definitions across all platforms from a single source - removing roadblocks, errors, and inefficiencies across your workflow.

For detailed usage head to https://amzn.github.io/style-dictionary

Watch the Demo on YouTube

Watch the video

Experiment in the playground

Try the browser-based Style Dictionary playground: https://www.style-dictionary-play.dev/, built by the folks at <div>RIOTS.

Contents

Installation

Note that you must have node (and npm) installed.

If you want to use the CLI, you can install it globally via npm:

$ npm install -g style-dictionary

Or you can install it like a normal npm dependency. This is a build tool and you are most likely going to want to save it as a dev dependency:

$ npm install -D style-dictionary

If you want to install it with yarn:

$ yarn add style-dictionary --dev

Usage

CLI

$ style-dictionary build

Call this in the root directory of your project. The only thing needed is a config.json file. There are also arguments:

Flag Short Flag Description
--config [path] -c Set the config file to use. Must be a .json file
--platform [platform] -p Only build a specific platform defined in the config file.
--help -h Display help content
--version -v Display the version

Node

You can also use the style dictionary build system in node if you want to extend the functionality or use it in another build system like Grunt or Gulp.

const StyleDictionary = require('style-dictionary').extend('config.json');

StyleDictionary.buildAllPlatforms();

The .extend() method is an overloaded method that can also take an object with the configuration in the same format as a config.json file.

const StyleDictionary = require('style-dictionary').extend({
  source: ['tokens/**/*.json'],
  platforms: {
    scss: {
      transformGroup: 'scss',
      buildPath: 'build/',
      files: [{
        destination: 'variables.scss',
        format: 'scss/variables'
      }]
    }
    // ...
  }
});

StyleDictionary.buildAllPlatforms();

Example

Take a look at some of our examples

A style dictionary is a collection of design tokens, key/value pairs that describe stylistic attributes like colors, sizes, icons, motion, etc. A style dictionary defines these design tokens in JSON or Javascript files, and can also include static assets like images and fonts. Here is a basic example of what the package structure can look like:

├── config.json
├── tokens/
│   ├── size/
│       ├── font.json
│   ├── color/
│       ├── font.json
│   ...
├── assets/
│   ├── fonts/
│   ├── images/

config.json

This tells the style dictionary build system how and what to build. The default file path is config.json or config.js in the root of the project, but you can name it whatever you want by passing in the --config flag to the CLI.

{
  "source": ["tokens/**/*.json"],
  "platforms": {
    "scss": {
      "transformGroup": "scss",
      "buildPath": "build/",
      "files": [{
        "destination": "scss/_variables.scss",
        "format": "scss/variables"
      }]
    },
    "android": {
      "transformGroup": "android",
      "buildPath": "build/android/",
      "files": [{
        "destination": "font_dimens.xml",
        "format": "android/fontDimens"
      }]
    }
  }
}
Attribute Type Description
source Array An array of file path globs to design token files. Style Dictionary will do a deep merge of all of the token files, allowing you to organize your files files however you want.
include Array An array of file path globs to design token files that contain default styles. The Style Dictionary uses this as a base collection of tokens. The tokens found using the "source" attribute will overwrite tokens found using include.
platforms Object Sets of platform files to be built.
platform.transformGroup String (optional) Apply a group of transforms to the tokens, must either define this or transforms.
platform.transforms Array (optional) Transforms to apply sequentially to all tokens. Can be a built-in one or you can create your own.
platform.buildPath String (optional) Base path to build the files, must end with a trailing slash.
platform.files Array (optional) Files to be generated for this platform.
platform.file.destination String (optional) Location to build the file, will be appended to the buildPath.
platform.file.format String (optional) Format used to generate the file. Can be a built-in one or you can create your own. More on formats
platform.file.options Object (optional) A set of extra options associated with the file.
platform.file.options.showFileHeader Boolean If the generated file should have a "Do not edit + Timestamp" header (where the format supports it). By default is "true".

Design Tokens

{
  "size": {
    "font": {
      "small" : { "value": "10px" },
      "medium": { "value": "16px" },
      "large" : { "value": "24px" },
      "base"  : { "value": "{size.font.medium.value}" }
    }
  }
}

Here we are creating some basic font size design tokens. The style definition size.font.small.value is "10px" for example. The style definition size.font.base.value is automatically aliased to the value found in size.font.medium.value and both of those resolve to "16px".

Now what the style dictionary build system will do with this information is convert it to different formats, enabling these values to be used in any type of codebase. From this one file you can generate any number of files like:

$size-font-small: 10px;
$size-font-medium: 16px;
$size-font-large: 24px;
$size-font-base: 16px;
<dimen name="font-small">10sp</dimen>
<dimen name="font-medium">16sp</dimen>
<dimen name="font-large">24sp</dimen>
<dimen name="font-base">16sp</dimen>
float const SizeFontSmall = 10.00f;
float const SizeFontMedium = 16.00f;
float const SizeFontLarge = 24.00f;
float const SizeFontBase = 16.00f;

Quick Start

The style dictionary framework comes with some example code to get you started. Install the node module globally, create a directory and cd into it.

$ npm i -g style-dictionary
$ mkdir MyStyleDictionary
$ cd MyStyleDictionary

Now run:

$ style-dictionary init basic

This command will copy over the example files found in example in this repo. Now you have an example project set up. You can make changes to the style dictionary and rebuild the project by running:

$ style-dictionary build

Take a look at the documentation for the example code.

Design Tokens

A design token is an attribute to describe something visually. It is atomic (it cannot be broken down further). Design tokens have a name, a value, and optional attributes or metadata. The name of a token can be anything, but we have a proposed naming structure that we find works really well in the next section.

Category/Type/Item Structure

While not exactly necessary, we feel this classification structure of design tokens makes the most sense semantically. Design tokens can be organized into a hierarchical tree structure with the top level, category, defining the primitive nature of the token. For example, we have the color category and every token underneath is always a color. As you proceed down the tree to type, item, sub-item, and state, you get more specific about what that color is. Is it a background color, a text color, or a border color? What kind of text color is it? You get the point. Now you can structure your token json files like simple objects:

{
  "size": {
    "font": {
      "base":  { "value": "16" },
      "large": { "value": "20" }
    }
  }
}

The CTI is implicit in the structure, the category and type is 'size' and 'font', and there are 2 tokens 'base' and 'large'.

Structuring design tokens in this manner gives us consistent naming and accessing of these tokens. You don't need to remember if it is button_color_error or error_button_color, it is color_background_button_error!

You can organize and name your design tokens however you want, there are no restrictions. But we have a good amount of helpers if you do use this structure, like the 'attribute/cti' transform which adds attributes to the token of its CTI based on the path in the object. There are a lot of name transforms as well for when you want a flat structure like for Sass variables.

Also, the CTI structure provides a good mechanism to target transforms for specific kinds of tokens. All of the transforms provided by the framework use the CTI of a token to know if it should be applied. For instance, the 'color/hex' transform only applies to tokens of the category 'color'.

You can also add a comment to a design token:

{
  "size": {
    "font": {
      "base":  {
        "value": "16",
        "comment": "the base size of the font"
      },
      "large": {
        "value": "20",
        "comment": "the large size of the font"
      }
    }
  }
}

The comment will appear in the output files, where relevant or the output format supports comments.

Extending

The style dictionary build system is made to be extended. We don't know exactly how everyone will want to use style dictionaries in their project, which is why you can create custom transforms and formats.

const StyleDictionary = require('style-dictionary').extend('config.json');

StyleDictionary.registerTransform({
  name: 'time/seconds',
  type: 'value',
  matcher: function(token) {
    return token.attributes.category === 'time';
  },
  transformer: function(token) {
    return (parseInt(token.original.value) / 1000).toString() + 's';
  }
});

StyleDictionary.buildAllPlatforms();

For more information on creating your own transforms and formats, take a look at our docs.

Mascot

The mascot for Style Dictionary is "Pascal" the chameleon (seen below). You can also find them blending in as the logo throughout the documentation.

Style Dictionary logo and mascot

Contributing

Please help make this framework better. For more information take a look at CONTRIBUTING.md

License

Apache 2.0

More Repositories

1

computer-vision-basics-in-microsoft-excel

Computer Vision Basics in Microsoft Excel (using just formulas)
2,394
star
2

selling-partner-api-docs

This repository contains documentation for developers to use to call Selling Partner APIs.
1,543
star
3

smoke-framework

A light-weight server-side service framework written in the Swift programming language.
Swift
1,443
star
4

alexa-skills-kit-js

SDK and example code for building voice-enabled skills for the Amazon Echo.
1,134
star
5

ion-java

Java streaming parser/serializer for Ion.
Java
840
star
6

selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Mustache
590
star
7

sketch-constructor

Read/write/manipulate Sketch files in Node without Sketch plugins!
JavaScript
542
star
8

pecos

PECOS - Prediction for Enormous and Correlated Spaces
Python
509
star
9

amzn-drivers

Official AWS drivers repository for Elastic Network Adapter (ENA) and Elastic Fabric Adapter (EFA)
C
455
star
10

ion-js

A JavaScript implementation of Amazon Ion.
TypeScript
323
star
11

convolutional-handwriting-gan

ScrabbleGAN: Semi-Supervised Varying Length Handwritten Text Generation (CVPR20)
Python
265
star
12

xfer

Transfer Learning library for Deep Neural Networks.
Python
253
star
13

awsssmchaosrunner

Amazon's light-weight library for chaos engineering on AWS. It can be used for EC2 and ECS (with EC2 launch type).
Kotlin
249
star
14

ion-python

A Python implementation of Amazon Ion.
Python
210
star
15

amazon-pay-sdk-php

Amazon Pay PHP SDK
PHP
209
star
16

kotlin-inject-anvil

Extensions for the kotlin-inject dependency injection framework
Kotlin
191
star
17

fire-app-builder

Fire App Builder is a framework for building java media apps for Fire TV, allowing you to add your feed of media content to a configuration file and build an app to browse and play it quickly.
Java
182
star
18

exoplayer-amazon-port

Official port of ExoPlayer for Amazon devices
Java
173
star
19

oss-dashboard

A dashboard for viewing many GitHub organizations at once.
Ruby
159
star
20

ion-c

A C implementation of Amazon Ion.
C
149
star
21

metalearn-leap

Original PyTorch implementation of the Leap meta-learner (https://arxiv.org/abs/1812.01054) along with code for running the Omniglot experiment presented in the paper.
Python
148
star
22

ion-go

A Go implementation of Amazon Ion.
Go
146
star
23

auction-gym

AuctionGym is a simulation environment that enables reproducible evaluation of bandit and reinforcement learning methods for online advertising auctions.
Jupyter Notebook
144
star
24

distance-assistant

Pedestrian monitor that provides visual feedback to help ensure proper social distancing guidelines are being observed
Python
135
star
25

hawktracer

HawkTracer is a highly portable, low-overhead, configurable profiling tool built in Amazon Video for getting performance metrics from low-end devices.
C++
133
star
26

trans-encoder

Trans-Encoder: Unsupervised sentence-pair modelling through self- and mutual-distillations
Python
133
star
27

smoke-aws

AWS services integration for the Smoke Framework
Swift
111
star
28

amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
PHP
108
star
29

MXFusion

Modular Probabilistic Programming on MXNet
Python
103
star
30

amazon-weak-ner-needle

Named Entity Recognition with Small Strongly Labeled and Large Weakly Labeled Data
Python
100
star
31

amazon-advertising-api-php-sdk

⛔️ DEPRECATED - Amazon Advertising API PHP Client Library
PHP
93
star
32

ads-advanced-tools-docs

Code samples and supplements for the Amazon Ads advanced tools center
Jupyter Notebook
91
star
33

ion-rust

Rust implementation of Amazon Ion
Rust
86
star
34

image-to-recipe-transformers

Code for CVPR 2021 paper: Revamping Cross-Modal Recipe Retrieval with Hierarchical Transformers and Self-supervised Learning
Python
81
star
35

oss-attribution-builder

The OSS Attribution Builder is a website that helps teams create attribution documents (notices, "open source screens", credits, etc) commonly found in software products.
TypeScript
80
star
36

smoke-http

Specialised HTTP Client for service operations abstracted from the HTTP protocol.
Swift
70
star
37

amazon-ray

Staging area for ongoing enhancements to Ray focused on improving integration with AWS and other Amazon technologies.
Python
66
star
38

alexa-coho

Sample code for building skill adapters for Alexa Connected Home using the Lighting API
JavaScript
62
star
39

amazon-pay-sdk-ruby

Amazon Pay Ruby SDK
Ruby
58
star
40

selling-partner-api-samples

Sample code for Amazon Selling Partner API use cases
Java
56
star
41

amazon-pay-sdk-python

Amazon Pay Python SDK
Python
53
star
42

amazon-pay-sdk-java

Amazon Pay Java SDK
Java
53
star
43

zero-shot-rlhr

Python
51
star
44

supply-chain-simulation-environment

Python
50
star
45

amazon-pay-api-sdk-php

Amazon Pay API SDK (PHP)
PHP
48
star
46

amazon-pay-sdk-csharp

Amazon Pay C# SDK
C#
47
star
47

ion-dotnet

A .NET implementation of Amazon Ion.
C#
47
star
48

multiconer-baseline

Python
47
star
49

zeek-plugin-enip

Zeek network security monitor plugin that enables parsing of the Ethernet/IP and Common Industrial Protocol standards
Zeek
44
star
50

amazon-pay-sdk-samples

Amazon Pay SDK Sample Code
PHP
43
star
51

oss-contribution-tracker

Track contributions made to external projects and manage CLAs
TypeScript
40
star
52

amazon-s3-gst-plugin

A collection of Amazon S3 GStreamer elements.
C
40
star
53

fashion-attribute-disentanglement

Python
39
star
54

zeek-plugin-s7comm

Zeek network security monitor plugin that enables parsing of the S7 protocol
Zeek
39
star
55

milan

Milan is a Scala API and runtime infrastructure for building data-oriented systems, built on top of Apache Flink.
Scala
39
star
56

orthogonal-additive-gaussian-processes

Light-weighted code for Orthogonal Additive Gaussian Processes
Python
38
star
57

jekyll-doc-project

This repository contains an open-source Jekyll theme for authoring and publishing technical documentation. This theme is used by Appstore/Alexa tech writers and other community members. Most of the theme's files are stored in a Ruby Gem (called jekyll-doc-project).
HTML
37
star
58

amazon-pay-api-sdk-nodejs

Amazon Pay API SDK (Node.js)
JavaScript
36
star
59

smoke-dynamodb

SmokeDynamoDB is a library to make it easy to use DynamoDB from Swift-based applications, with a particular focus on usage with polymorphic database tables (tables that do not have a single schema for all rows).
Swift
34
star
60

chalet-charging-location-for-electric-trucks

Optimization tool to identify charging locations for electric trucks
Python
34
star
61

sparse-vqvae

Experimental implementation for a sparse-dictionary based version of the VQ-VAE2 paper
Python
31
star
62

ss-aga-kgc

Python
31
star
63

amazon-pay-api-sdk-java

Amazon Pay API SDK (Java)
Java
30
star
64

zeek-plugin-bacnet

Zeek network security monitor plugin that enables parsing of the BACnet standard building controls protocol
Zeek
29
star
65

credence-to-causal-estimation

A framework for generating complex and realistic datasets for use in evaluating causal inference methods.
Python
29
star
66

basis-point-sets

Python
28
star
67

buy-with-prime-cdk-constructs

This package extends common CDK constructs with opinionated defaults to help create an organization strategy around infrastructure as code.
TypeScript
28
star
68

zeek-plugin-profinet

Zeek network security monitor plugin that enables parsing of the Profinet protocol
Zeek
27
star
69

differential-privacy-bayesian-optimization

This repo contains the underlying code for all the experiments from the paper: "Automatic Discovery of Privacy-Utility Pareto Fronts"
Python
26
star
70

ion-tests

Test vectors for testing compliant Ion implementations.
25
star
71

ion-hive-serde

A Apache Hive SerDe (short for serializer/deserializer) for the Ion file format.
Java
24
star
72

zeek-plugin-tds

Zeek network security monitor plugin that enables parsing of the Tabular Data Stream (TDS) protocol
Zeek
24
star
73

smoke-framework-application-generate

Code generator to generate SmokeFramework-based applications from service models.
Swift
24
star
74

ion-intellij-plugin

Support for Ion in Intellij IDEA.
Kotlin
23
star
75

ion-schema-kotlin

A Kotlin reference implementation of the Ion Schema Specification.
Kotlin
23
star
76

ftv-livetv-sample-tv-app

Java
23
star
77

emukit-playground

A web page explaining concepts of statistical emulation and making decisions under uncertainty in an interactive way.
JavaScript
22
star
78

ion-hash-go

A Go implementation of Amazon Ion Hash.
Go
22
star
79

pretraining-or-self-training

Codebase for the paper "Rethinking Semi-supervised Learning with Language Models"
Python
22
star
80

smoke-framework-examples

Sample applications showing the usage of the SmokeFramework and related libraries.
Swift
21
star
81

confident-sinkhorn-allocation

Pseudo-labeling for tabular data
Jupyter Notebook
21
star
82

tiny-attribution-generator

A small tool and library to create attribution notices from various formats
TypeScript
20
star
83

smoke-aws-generate

Code generator to generate the SmokeAWS library from service models.
Swift
19
star
84

ion-docs

Source for the GitHub Pages for Ion.
Java
19
star
85

autotrail

AutoTrail is a highly modular, partial automation workflow engine providing run time execution control
Python
19
star
86

smoke-aws-credentials

A library to obtain and assume automatically rotating AWS IAM roles written in the Swift programming language.
Swift
19
star
87

amazon-codeguru-profiler-for-spark

A Spark plugin for CPU and memory profiling
Java
18
star
88

git-commit-template

Set commit templates for git
JavaScript
18
star
89

service-model-swift-code-generate

Modular code generator to generate Swift applications from service models.
Swift
18
star
90

amazon-pay-api-sdk-dotnet

Amazon Pay API SDK (.NET)
C#
18
star
91

sample-fire-tv-app-video-skill

This sample Fire TV app shows how to integrate an Alexa video skill in a simple, basic way.
Java
16
star
92

amazon-template-library

A collection of general purpose C++ utilities that play well with the Standard Library and Boost.
C++
16
star
93

rheoceros

Cloud-based AI / ML workflow and data application development framework
Python
16
star
94

ion-cli

Rust
15
star
95

refuel-open-domain-qa

Python
15
star
96

amazon-instant-access-sdk-php

PHP SDK to aid in 3p integration with Instant Access
PHP
14
star
97

amazon-mcf-plugin-for-magento-1

Plugin code to enable Amazon MCF in Magento 1.
PHP
14
star
98

login-with-amazon-wordpress

A pre-integrated plugin that can be installed into a Wordpress powered website to integrate with Login with Amazon.
PHP
14
star
99

firetv-sample-touch-app

This sample Android project demonstrates how to build the main UI of a Fire TV application in order to support both Touch interactions and Remote D-Pad controls.
Java
14
star
100

amzn-ec2-ena-utilities

Python
14
star