Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Shopify/polaris-tokens
Design tokens for Polaris, Shopify’s design system
https://github.com/Shopify/polaris-tokens
design-systems design-tokens polaris shopify shopify-polaris
Last synced: 3 months ago
JSON representation
Design tokens for Polaris, Shopify’s design system
- Host: GitHub
- URL: https://github.com/Shopify/polaris-tokens
- Owner: Shopify
- License: mit
- Archived: true
- Created: 2017-12-08T20:06:42.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2022-01-11T22:20:14.000Z (almost 3 years ago)
- Last Synced: 2024-08-02T05:32:22.857Z (3 months ago)
- Topics: design-systems, design-tokens, polaris, shopify, shopify-polaris
- Language: TypeScript
- Homepage: https://polaris.shopify.com
- Size: 6.99 MB
- Stars: 234
- Watchers: 221
- Forks: 35
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
LEGACY Polaris design tokens
Colors, spacing, animation, and typography for all platforms
JavaScript · JSON · CSS · SCSS · Android · Sketch · macOS · iOS · Adobe Swatch
[![npm version](https://img.shields.io/npm/v/@shopify/polaris-tokens.svg)](https://www.npmjs.com/package/@shopify/polaris-tokens) [![CI](https://github.com/shopify/polaris-tokens/workflows/CI/badge.svg)](https://github.com/shopify/polaris-tokens/actions?query=workflow%3ACI)
---
[Design tokens](https://medium.com/eightshapes-llc/tokens-in-design-systems-25dd82d58421) for [Polaris](https://polaris.shopify.com), Shopify’s design system.
Design tokens originated at Salesforce, and the best way to describe them is to simply quote their documentation:
> Design tokens are the visual design atoms of the design system — specifically, they are named entities that store visual design attributes. We use them in place of hard-coded values (such as hex values for color or pixel values for spacing) in order to maintain a scalable and consistent visual system for UI development – [Salesforce UX](https://www.lightningdesignsystem.com/design-tokens/)
## Installation
Polaris design tokens are available as both a npm package (`@shopify/polaris-tokens`) on [npm](https://www.npmjs.com/), and as a Ruby gem (`polaris_tokens`) on [RubyGems](https://rubygems.org/).
The recommended way to use and install design tokens may vary depending on your project; the most common are documented below.
Using [npm](https://www.npmjs.com/):
```console
npm install @shopify/polaris-tokens --save
```Using [yarn](https://yarnpkg.com/en/):
```console
yarn add @shopify/polaris-tokens
```Using [Bundler](https://bundler.io/):
```console
bundle add polaris_tokens
```### JavaScript
In JavaScript, design token names are formatted in [lower camelCase](http://wiki.c2.com/?CamelCase).
```js
const tokens = require('@shopify/polaris-tokens');
console.log(tokens.colorBlueLighter); // rgb(235, 245, 250)
```In JSON, design token names are formatted in [kebab-case](http://wiki.c2.com/?KebabCase).
```js
const tokens = require('@shopify/polaris-tokens/dist/index.json');
console.log(tokens['color-blue-lighter']); // rgb(235, 245, 250)
```Note that, if your project supports ECMAScript Modules, you can also use the `import` syntax.
```js
import * as tokens from '@shopify/polaris-tokens';
// or
import {colorBlueLighter} from '@shopify/polaris-tokens';
```### Sass
Sass variables and map keys are formatted in [kebab-case](http://wiki.c2.com/?KebabCase).
```scss
// Using variables
@import '~@shopify/polaris-tokens/dist/index';a {
color: $color-blue-text;
}// Using the map of all tokens
@import '~@shopify/polaris-tokens/dist/index.map';a {
color: map-get($polaris-index-map, 'color-blue-text');
}// Using the map for a specific type of tokens (here: spacing)
@import '~@shopify/polaris-tokens/dist/spacing.spacing-map';a {
color: map-get($polaris-spacing-map, 'loose');
}
```### Sass, with CSS Custom Properties
Custom properties are formatted in [kebab-case](http://wiki.c2.com/?KebabCase).
```scss
// Omit .css at the end of the file
@import '~@shopify/polaris-tokens/dist/colors.custom-properties';a {
color: var(--color-blue-text);
}
```### Rails
Token files are added to the assets pipeline. In JSON, design token names are formatted in [kebab-case](http://wiki.c2.com/?KebabCase).
```ruby
require 'json'
polaris_token_file = Rails.application.assets_manifest.find_sources('colors.json').first
polaris_colors = JSON.parse(polaris_token_file)
polaris_colors['color-blue-lighter'] # "rgb(235, 245, 250)"
```### CSS Filters
Color tokens include a [CSS Filter](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) (`filter`) value as part of their metadata. When this filter is applied to an element, it will change that element’s color to _approximate_ the target token color.
```
No background, no filter
White background, no filter
No background, red filter
White background, red filter
```![text and non-transparent backgrounds become red when filter is applied](.github/filter-example-1.png)
In general, these filters shouldn’t be used unless absolutely necessary. The main use case for the filters is to apply a color to an unsafe (as in: user-provided) SVG. Since SVGs can contain arbitrary code, we should be careful about how they are displayed. The safest option is to render SVGs as an `img` (for example ``); when SVGs are rendered like this, browsers will block code execution. Unfortunately, it also means that the SVGs cannot be styled with external CSS (applying `fill: red` to the `img` won’t do anything.)
CSS filters allow us the safety of rendering SVGs inside `img` elements, but still give us control over their appearance.
```
black circle, no filter
black circle, red filter
```![the filter turns the black circle red](.github/filter-example-2.png)
Note that _all_ filled areas of an SVG will change color with this approach, including borders/strokes. For that reason it should only be used with monochromatic SVGs.
```
black circle with green border, no filter
black circle with green border, red filter
```![the filter turns the entire circle red, including the border](.github/filter-example-3.png)
If you need to generate new filter values, you can do so with [this CodePen](https://codepen.io/kaelig/full/jeObGP/).
---
## Contributing
The purpose of this repository is to see the core design elements of the Polaris design system
evolve and improve over time with the needs of developers, designers and partners in mind.This project is now deprecated and no longer accepting contributions.
### [Code of conduct](https://github.com/Shopify/polaris-tokens/blob/main/.github/CODE_OF_CONDUCT.md)
We have a [code of conduct](https://github.com/Shopify/polaris-tokens/blob/main/.github/CODE_OF_CONDUCT.md),
please follow it in all your interactions with the project.### [License](https://github.com/Shopify/polaris-tokens/blob/main/LICENSE.md)
The polaris-tokens project is available under the [MIT license](https://github.com/Shopify/polaris-tokens/blob/main/LICENSE.md).
Parts of the code in this repository are directly inspired or borrowed
from the [Theo project](https://github.com/salesforce-ux/theo),
property of Salesforce.com, Inc., [licensed under BSD 3-Clause](https://git.io/sfdc-license).