Giter Club home page Giter Club logo

polaris-tokens's Introduction

LEGACY Polaris design tokens

Colors, spacing, animation, and typography for all platforms

JavaScript · JSON · CSS · SCSS · Android · Sketch · macOS · iOS · Adobe Swatch

npm version CI


Design tokens for Polaris, 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

Installation

Polaris design tokens are available as both a npm package (@shopify/polaris-tokens) on npm, and as a Ruby gem (polaris_tokens) on RubyGems.

The recommended way to use and install design tokens may vary depending on your project; the most common are documented below.

Using npm:

npm install @shopify/polaris-tokens --save

Using yarn:

yarn add @shopify/polaris-tokens

Using Bundler:

bundle add polaris_tokens

JavaScript

In JavaScript, design token names are formatted in lower camelCase.

const tokens = require('@shopify/polaris-tokens');
console.log(tokens.colorBlueLighter); // rgb(235, 245, 250)

In JSON, design token names are formatted in kebab-case.

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.

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.

// 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.

// 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.

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 (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.

<div>
  No background, no filter
</div>

<div style="background-color: #fff">
  White background, no filter
</div>

<div style="filter: brightness(0) saturate(100%) invert(28%) sepia(67%) saturate(3622%) hue-rotate(353deg) brightness(89%) contrast(95%)">
  No background, red filter
</div>

<div style="background-color: #fff; filter: brightness(0) saturate(100%) invert(28%) sepia(67%) saturate(3622%) hue-rotate(353deg) brightness(89%) contrast(95%)">
  White background, red filter
</div>

text and non-transparent backgrounds become red when filter is applied

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 <img src="circle.svg" alt="" />); 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.

<div>
  <img src="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><circle cx='20' cy='20' r='16' /></svg>" alt="" /> black circle, no filter
</div>
<div>
  <img src="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><circle cx='20' cy='20' r='16' /></svg>" style="filter: brightness(0) saturate(100%) invert(28%) sepia(67%) saturate(3622%) hue-rotate(353deg) brightness(89%) contrast(95%)" alt="" /> black circle, red filter
</div>

the filter turns the black circle red

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.

<div>
  <img src="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><circle cx='20' cy='20' r='16' stroke='green' stroke-width='4' /></svg>" alt="" /> black circle with green border, no filter
</div>
<div>
  <img src="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><circle cx='20' cy='20' r='16' stroke='green' stroke-width='4' /></svg>" style="filter: brightness(0) saturate(100%) invert(28%) sepia(67%) saturate(3622%) hue-rotate(353deg) brightness(89%) contrast(95%)" alt="" /> black circle with green border, red filter
</div>

the filter turns the entire circle red, including the border

If you need to generate new filter values, you can do so with this CodePen.


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.

We have a code of conduct, please follow it in all your interactions with the project.

The polaris-tokens project is available under the MIT license.

Parts of the code in this repository are directly inspired or borrowed from the Theo project, property of Salesforce.com, Inc., licensed under BSD 3-Clause.

polaris-tokens's People

Contributors

ashwinnarayanan2001 avatar beefchimi avatar bpscott avatar danrosenthal avatar dependabot[bot] avatar emmaorhun avatar kaelig avatar kyledurand avatar martenbjork avatar nwtn avatar sambostock avatar sarahill avatar services-db[bot] avatar shopify-services avatar tmlayton avatar yurm04 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polaris-tokens's Issues

Unhide dist-modern in VSCode file tree

.vscode/settings.json hides dist-modern from the file tree. This caused me a real headache when trying to see the results of my adjustments. Is there a reason for this?

"files.exclude": {
  "**/.DS_Store": true,
  "**/.git": true,
  "**/node_modules": true,
  ".{bundle,dev,shadowenv.d}": true,
  "{tmp,dist-modern}/": true
},

Update red-base

From #ED6347 to #DE3618.

See https://github.com/Shopify/polaris-ux/issues/87 for the reasoning behind this change.

Open issues / mention people in:

Thoughts on polaris-tokens ahead of refactor

Hey! 👋

Having now worked with colors and polaris-tokens for a while, I wanted to get some thoughts out of my head. Happy to discuss all of this as we move forward!

JSON and pure, exported functions

When building tooling for tokens, you need the inputs and the token functions to be separate.

For instance, you can have a tool read the base.ts file, run the transformations in the browser. You can then push the new base.ts file to github and rest assured that the same transformation will happen on the tokens server. The tool is essentially a GUI for the same function that exists in polaris-tokens.

If one of these parts isn't available, you can't build a tool. I ran into this problem several times during the creation of the color factory:

  • Inputs: base.ts - Beause it's not JSON, I have to parse this using regular expressions after reading it from Github 😬
  • Color factory: Hard-wired into Polaris at first. Then we exported it and it enabled me to run the factory in other contexts. Huge enabler.

Suggestions:

  • All inputs are JSON files. We loose Typescript type checking, but we could replace that linting/tests on import.
  • All transformations are simple, exported, pure functions, like so: let tokens = createColorTokens(inputsJson).
  • In general, think tooling-first. How can a third party implement polaris-tokens in their code base and get the same results?

Dynamic outputs?

One big motivation behind GraphQL is that "what if you didn't have to implement an endpoint every time you wanted data in a new way?". Maybe that thinking applies to polaris-tokens as well?

Could we offer a dynamic format, like so:

?type=colors&fields=name,figmaName,hsla&format=xml

Update: Kaelig shared this with me. Looks great!

Theo and Gulp

  • The Gulp pipeline makes it hard to reason about code, because there is so much abstraction going on.
  • Theo's docs are quite limited. I found myself guessing and trying random things to get the right result. (Like, Tim and I, throwing the includeMeta flag in here)
  • We have to jump through some pretty complicated hoops just to conform with Theo's way of doing things. Here we are iterating over JS, creating a YML string(!), feeding it to Theo to finally get some JSON output.

Remove `-base` suffix from base color variables

Right now we use variable names like $color-ink-base for the default Ink color value. We should remove the -base suffix because it's confusing. It should follow the color name and the way it's used in the color function: color('ink').

Beta (next release) of Tokens not found in rubygems

https://rubygems.org/gems/polaris_tokens/versions only lists 2.x.x and before releases, nothing from the 3.0.0-beta.x releases we've been doing from the next branch.

When trying to upgrade in a rails project, we run into this problem:

Could not find gem 'polaris_tokens (= 3.0.0.pre.beta.7)' in rubygems repository https://rubygems.org/ or installed
locally.
The source contains 'polaris_tokens' at: 1.1.0.pre.beta.1, 1.1.0.pre.beta.3, 1.1.0.pre.beta.7, 1.1.0, 1.2.0, 1.3.0,
1.3.1, 2.0.0, 2.1.1, 2.2.0, 2.3.0, 2.4.0.pre.beta.1, 2.4.0.pre.beta.2, 2.4.0, 2.5.0, 2.6.0, 2.7.0

Motion tokens

Johan will:

  • Create and validate a concept for motion tokens
  • Rationale added to the polaris-styleguide for motion tokens
  • Add them to the polaris-tokens

What Johan needs:

  • Components use the tokens
  • Review process for token implementation
  • A dedicated time to audit the implementation of components in context

Update color names 🎨

🎨 Colors were updated on https://shopify.invisionapp.com/dsm/shopify/design-tokens, please update this repository!

Changes

Updated Polaris color names in InVision DSM. #22

Follow these steps

  • If you haven’t yet, clone this repository
    dev clone polaris-tokens
    dev up
    
  • Fetch tokens from Invision
    dev cd polaris-tokens
    git checkout master
    git pull
    git checkout -B update-color-tokens
    yarn getTokensFromInvision
    yarn dist
    yarn test -u
    
  • Update CHANGELOG.md
  • Commit & push the changes
    git commit -am "Update color tokens to the latest version"
    git push origin update-color-tokens
    
  • Open a pull request

[Design Language] Motion token

This token needs a lot of context that is now missing. Not sure when but @johanstromqvist will be looking into this. It might even be multiple tokens, such as easing curves and duration.

Known values

What does motion look like in the masterbrand?

Suggested tokens

What are the token values and names?

Color discrepancies across codebases

red-light

project value pr fix / resource
✅ Sketch file #FA9A88
polaris-styleguide #FEAD9A https://github.com/Shopify/polaris-styleguide/pull/1298
polaris-rails #FEAF9A
polaris-react #FEAD9A

ink-base

project value pr fix / resource
✅ Sketch file #212B36
polaris-styleguide #212B36 https://github.com/Shopify/polaris-styleguide/pull/1298
polaris-rails #212b35
polaris-react #212B36

sky-base

project value pr fix / resource
✅ Sketch file #DFE3E8
polaris-styleguide #DFE3E8 https://github.com/Shopify/polaris-styleguide/pull/1298
polaris-rails #DFE4E8
polaris-react #DFE3E8 Shopify/polaris#518

Spinner color variation

Spinner is used in a lot of different places, the current application is tied to other colors that may not align with it.

We might want to decouple it to allow it to be themed freely.

Update color yellow dark for accessibility

Update color-yellow-dark for accessibility

Problem

Yellow dark is currently used for text and icons to convey a warning to the merchant in the UI. It doesn't currently pass WCAG constrast standards of 4.5:1.

We started to run into the issue when updating the ExceptionList. See for details Shopify/polaris#813

Solution

I slightly adjusted the brightness to help with contrast. Update yellow dark to use #8A6116 instead of #9c6f19.

image


Follow these steps

  • If you haven’t yet, clone this repository
    dev clone polaris-tokens
    dev up
    
  • Fetch tokens from Invision DSM (Design System Manager)
    dev cd polaris-tokens
    git checkout master
    git pull
    git checkout -B update-color-tokens
    yarn getTokensFromInvisionDSM
    yarn dist
    yarn test -u
    
  • Update CHANGELOG.md
  • Commit & push the changes
    git commit -am "Update color tokens to the latest version"
    git push origin update-color-tokens
    
  • Open a pull request

Font custom css var should not be wrapped in quotes

When using the current build of custom properties for fonts, it results in quotes around the value:

.foo {
  font-family: "-apple-system, 'BlinkMacSystemFont', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', sans-serif";
}

But it should not have quotes around the value:

.foo {
-  font-family: "-apple-system, 'BlinkMacSystemFont', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', sans-serif";
+  font-family: -apple-system, 'BlinkMacSystemFont', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', sans-serif;
}

https://github.com/Shopify/polaris-tokens/blob/master/dist/typography.custom-properties.css

[Color system] Adjust variant values

Updated variants

• -iconActionHovered- -> iconHovered
• -iconActionPressed- -> iconPressed
• -actionInteractive- -> interactive
• -actionInteractiveDisabled- -> interactiveDisabled
• -actionInteractiveHovered- -> interactionHovered
• -actionInteractivePressed- -> interactionPressed
• -primarySelected- -> surfacePrimarySelected
• -primarySelected- -> surfacePrimarySelectedHovered
• -primarySelected- -> surfacePrimarySelectedPressed
• remove -secondary- from icon, iconHovered, and iconPressed, text, textSubdued, textDisabled descriptions
• updated description of interactive
• remove actionInteractiveSubdued -> not being used in Polaris-react or Figma
• updated description of surfaceSelected examples to reference actionList instead of optionList
linkCritical -> interactiveCritical
linkCriticalDisabled -> interactiveCriticalDisabled
linkCriticalHovered -> interactiveCriticalHovered
linkCriticalPressed -> interactiveCriticalPressed
• Updated the description for interactiveCritical

Adjusted lightness of

• iconWarning
• iconCritical
• surfaceHovered
• surfacePressed
• surfacePrimarySelected


Figma changes

• remove icon/data negative #D92800
• remove icon/data positive #008060
• remove icon/interactive #2C6FCD
• remove border/interactive subdued #6792D2
• remove border/interactive #2C6FCD


Proposed changes

• Add inverse value, inverse would be used to indicate something that needs to stand out out from everything else on the page. guaranteed to contrast with whatever you want to contrast against on the screen
• Contextual save bar, indicating data needs to be saved inverse surface
• Toast, indicating an important event just occurred or there is a server error - inverse surface critical
• What about pressed and hover states for actions on top of toasts?
• Add Icon/Primary for navigation
• Add Text/Primary


ToDo

• toast - needs dark background color
• tooltip - needs dark background color
• check thumbnail
• Buttons - auto layout
• Card - update banner buttons (basic destructive)


Questions

• Should we add a Text/Primary variant

[testing issue template] Update colors 🎨

🎨 Colors were updated on https://shopify.invisionapp.com/dsm/shopify/design-tokens, please update this repository!

Changes

Follow these steps

  • If you haven’t yet, clone this repository
    dev clone polaris-tokens
    dev up
    
  • Fetch tokens from Invision
    dev cd polaris-tokens
    git checkout master
    git pull
    git checkout -B update-color-tokens
    yarn getTokensFromInvision
    yarn dist
    yarn test -u
    
  • Update CHANGELOG.md
  • Commit & push the changes
    git commit -am "Update color tokens to the latest version"
    git push origin update-color-tokens
    
  • Open a pull request

Update color (teaching)

Problem

Describe the problem

Solution

describe and show mocks if you have them
reference any other related issue

[Color system] Move Sass variables to polaris-tokens

Context

For context on why we're doing this, see this issue: Shopify/polaris#1982

Why is this part of the Color system project?

Good question. This work unlocks us (starting in version 5) to make changes to our Sass API without an impact on consumers. It will force consumers to stop relying on Polaris for Sass, and to use Tokens and their own internal Sass instead. Basically it paves the road for consumers to start using the Color system as CSS Custom properties, instead of using the color function (which will be removed) provided by Polaris Sass.

Principles

  • tokens should not be aliases to other tokens
  • tokens should not do math for the consumer
  • tokens should return pixel values and be transformed on the consumer
  • tokens should convey only globally-useful data

⚠️ Names used in audit do not represent final names for tokens

[new DL] Define and expose shadows

Designers have access to different levels/depths of shadows in Figma, but these shadows are not defined or exposed for developers and consumers of Polaris to be used.

Depth shadows can be found here on figma: https://www.figma.com/file/4dAAt5iFPSaxUKiYVKrkYj/DL%E2%80%93Polaris-(Web)%3A-Components?node-id=1%3A2

Depth 1: 0px 2px 1px rgba(0, 0, 0, 0.05), 0px 0px 1px rgba(66, 71, 76, 0.45);
Depth 2: 0px 4px 12px rgba(0, 0, 0, 0.1), 0px 0px 1px rgba(0, 0, 0, 0.33);
Depth 3: 0px 6px 15px rgba(33, 43, 54, 0.12), 0px 0px 1px rgba(33, 43, 54, 0.45);
Depth 4: 0px 0px 1px rgba(0, 0, 0, 0.2), 0px 26px 80px rgba(0, 0, 0, 0.2);

This other issue could also be related to this one #78

Polaris.clr unusable in Swift

Issue:

The Polaris.clr file created produces errors when trying to load it in Swift. The file can be found here.

What I've Noticed:

When initializing a NSColorList (the object that represents .clr files in Swift) using the Polaris.clr, I get this error:

 Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864

The interesting thing is that re saving the file using the NSColorListobject and using that instead fixes this issue.

More Info:

I am also able to format the re saved Polaris.clr into XML1 format using mac's built in terminal command:
plutil -convert xml1 /path/to/polaris.clr
however when I use the Polaris.clr in this repo, I get the following error:

 Property List error: Unexpected character  at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.

Remove dist directory

We shouldn't have a dist directory for polaris-tokens.

  • The site doesn't need it as it's shipped on herokuapp
  • Sketch palette is no longer supported
  • No reason for this
  • Has been forgotten about
  • Breaking change?

Publish the polaris_tokens gem to RubyGems.org

At the moment, the gem only available via the private gem registry, which limits it to internal developers.

  • Publish the polaris_tokens gem to RubyGems.org
  • Update README.md installation instructions to mention the gem

Share "breakpoints" values

I've noticed values getting hard copied between JS and CSS. For instance, in polaris-react, we have the SCSS layout value:

page-with-nav: (
  base: rem(769px),
),

and then a breakpoints.ts utility:

const Breakpoints = {
  navigationBarCollapsed: '768px',
  stackedContent: '1043px',
};

I think there is potential to consolidate some of this and reduce the chance of drift.

Simplify colors.yml

Per my comments on #66 (comment), colors.yml could be simplified

  • Make values in colors.yml use the acutal colors instead of aliases (and then we can remove the whole aliases section at the top). So https://github.com/Shopify/polaris-tokens/pull/66/files#diff-331a823dcc461b72db5ed76f9928f5a5R62 changes from value: '{!color-purple-text}' to value: '#50495a'. This changes the output of the build files so is a breaking change.
  • gulpfile.js seems to be the only place where "meta.filter" is used. The filter is generated from the color based on code from https://codepen.io/kaelig/full/jeObGP/. It may be possible to determine the filter color programatically instead of using that tool, and thus allowing us to remove meta.filter. Unfortunately the code used in that tool is currently nondeterministic. We'd need a deterministic version to enable consistent results if we generated this automatically.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.