Package detail

@primer/primitives

primer262.4kMIT10.7.0

Typography, spacing, and color primitives for Primer design system

primitives, colors, spacing, typography

readme

Primer Primitives

npm package Storybook A11y contrast check

This repo contains values for color, spacing, and typography primitives for use with Primer, GitHub's design system.

primer primitives diagram showing how the package connects with other primer libraries primer primitives diagram showing how the package connects with other primer libraries

Install

This repository is distributed on npm. After installing npm, you can install @primer/primitives with this command.

npm install --save @primer/primitives

Usage

Storybook | Docs

See Primitives documentation for more information on theming and using CSS variables.

Data is served from the dist/ folder:

  • dist/css contains CSS files with values available as CSS variables

All available imports:

/* size/typography */
@import '@primer/primitives/dist/css/base/size/size.css';
@import '@primer/primitives/dist/css/base/typography/typography.css';
@import '@primer/primitives/dist/css/functional/size/border.css';
@import '@primer/primitives/dist/css/functional/size/breakpoints.css';
@import '@primer/primitives/dist/css/functional/size/size.css';
@import '@primer/primitives/dist/css/functional/size/viewport.css';
@import '@primer/primitives/dist/css/functional/typography/typography.css';

/* color */
@import '@primer/primitives/dist/css/functional/themes/light.css';
@import '@primer/primitives/dist/css/functional/themes/light-tritanopia.css';
@import '@primer/primitives/dist/css/functional/themes/light-high-contrast.css';
@import '@primer/primitives/dist/css/functional/themes/light-colorblind.css';
@import '@primer/primitives/dist/css/functional/themes/dark.css';
@import '@primer/primitives/dist/css/functional/themes/dark-colorblind.css';
@import '@primer/primitives/dist/css/functional/themes/dark-dimmed.css';
@import '@primer/primitives/dist/css/functional/themes/dark-high-contrast.css';
@import '@primer/primitives/dist/css/functional/themes/dark-tritanopia.css';

Design token data

Design token data is stored in the src/tokens directory. These tokens are compiled with style dictionary in scripts/buildTokens.ts.

To make working with tokens easier, we added some additional functionality on top of what style dictionary comes with:

Extending and Overwriting

We have two main color modes: light and dark. Additionally we have specific accessibility modes based on those, such as light high contrast.

We added a way to create a mode by only including the changes from the main mode. We call this overrides. Overrides are created in src/tokens/functional/color/[light|dark]/overrides/ and have to be added to themes.config.ts to work. In the individual files, e.g. light.high-contrast.json5 you can now add tokens in the same structure as in any main file, e.g. primitives-light.json5 to replace them.

Transforming Colors with Alpha and Mix

Alpha

You can create color tokens that inherit a color but have a different alpha value by adding the alpha property. Note: The original alpha value will be replaced by your value. If you add alpha: 0.4 to a color, it doesn't matter if the color you reference has no alpha or alpha: 0.7, the new token will always have newly the defined value of alpha: 0.4.

{
  muted: {
    $value: '{base.color.blue.3}',
    alpha: 0.4, // the opacity value of the color === 40% opaque
    $type: 'color',
  },
}

Extensions property

According to the w3c design token specs, the $extensions property is used for additional meta data.

For our Figma export we use the following meta data:

  • collection the collection that the token is added to within Figma
  • mode the mode that the token is added to within the collection in Figma
  • scopes the scopes that are assigned to the token in Figma, the actual Figma compatible scopes are retrieved from an object in the figmaAttributes transformer

Code example

  bgColor: {
    $value: '{borderColor.accent.muted}',
    $type: 'color',
    $extensions: {
      'org.primer.figma': {
        collection: 'pattern/mode',
        mode: 'light',
        scopes: ['bgColor'],
      },
    },
  }

Token names and @-hack

Token names have to be in camelCase or kebab-case and may only include letters, numbers and -. This is enforced by the token validation (npm run lint:tokens). The only exception is the @-hack. This is used when you want to have a default value and sub-values, e.g. bgColor.accent and bgColor.accent.muted. In this case you can create the following structure. The @ will be removed from the name and act as the default value.

{
  bgColor: {
    accent: {
      '@': {
        // values for bgColor-accent (default)
      },
      muted: {
        // values for bgColor-accent-muted
      },
    },
  },
}

License

MIT © GitHub

changelog

@primer/primitives

10.7.0

Minor Changes

Patch Changes

10.6.0

Minor Changes

Patch Changes

  • #1200 72cf27d Thanks @langermank! - Bug fixes:
    • High contrast danger color on hover
    • High contrast translucent border
    • High contrast danger button hover border-color

10.5.0

Minor Changes

Patch Changes

10.4.0

Minor Changes

Patch Changes

10.3.4

Patch Changes

  • #1154 f86174b Thanks @lukasoppermann! - Fix borderColor-closed-muted in dark-protanopia-deuteranopia and revert protanopia-deuteranopia open color to be orange again

    • borderColor-closed-muted in dark-protanopia-deuteranopia is now gray instead of orange
    • borderColor-open-[muted|emphasis] in protanopia-deuteranopia is now orange again (instead of blue)
    • fgColor-open in protanopia-deuteranopia is now orange again (instead of blue)
    • bgColor-open-[muted|emphasis] in protanopia-deuteranopia is now orange again (instead of blue)

10.3.3

Patch Changes

10.3.2

Patch Changes

10.3.1

Patch Changes

10.3.0

Minor Changes

  • #1100 b995538 Thanks @lukasoppermann! - Changing the way we use references in css output, to keep all references to tokens that are present in the final output

Patch Changes

10.2.0

Minor Changes

10.1.0

Minor Changes

Patch Changes

10.0.0

Major Changes

Minor Changes

Patch Changes

9.1.2

Patch Changes

9.1.1

Patch Changes

9.1.0

Minor Changes

Patch Changes

9.0.3

Patch Changes

9.0.2

Patch Changes

9.0.1

Patch Changes

9.0.0

Major Changes

  • #1021 8b015a0 Thanks @langermank! - Update invisible button variant text color to be default instead of link blue

  • #1025 9ab8102 Thanks @langermank! - Fix inconsistent HC transparent colors

  • #1023 0f5625e Thanks @langermank! - Change fgColor-onEmphasis to white in dark high contrast theme

  • #1016 39862e9 Thanks @langermank! - # Updated neutral base color scales

    Changes

    • Theme specific neutral scales have been replaced with two new scales: light and dark.
    • The new light and dark scales are inverted, where 0 is the lightest shade in light and the darkest shade in dark.
    • Functional color tokens have been updated to use the new light and dark scales, and several overrides have been removed due to the new inverted design.

    Migration

    • Functional color tokens all work as expected and have been tested to meet minimum contrast requirements.
    • If you are using primer/primitives base color scales directly, you may need to update how those colors are applied. See the migration table which outlines approximately how the new colors map to the old colors.

    Light scale migration

    | Old color | New color | | --------- | --------- | | 0 | 0 | | 1 | 2 | | 2 | 5 | | 3 | 7 | | 4 | 7 | | 5 | 8 | | 6 | 8 | | 7 | 9 | | 8 | 10 | | 9 | 11 |

    Dark scale migration

    | Old color | New color | | --------- | --------- | | 9 | 0 | | 8 | 1 | | 7 | 2 | | 6 | 4 | | 5 | 6 | | 4 | 7 | | 3 | 8 | | 2 | 9 | | 1 | 10 | | 0 | 11 |

    Dark high contrast scale migration

    | Old color | New color | | --------- | --------- | | 9 | 0 | | 8 | 3 | | 7 | 5 | | 6 | 6 | | 5 | 7 | | 4 | 8 | | 3 | 9 | | 2 | 10 | | 1 | 11 |

    Dark dimmed scale migration

    | Old color | New color | | --------- | --------- | | 9 | 1 | | 8 | 2 | | 7 | 4 | | 6 | 5 | | 5 | 6 | | 4 | 7 | | 3 | 7 | | 2 | 8 | | 1 | 9 | | 0 | 10 |

    Light high contrast scale migration

    | Old color | New color | | --------- | --------- | | 0 | white | | 1 | 2 | | 2 | 5 | | 3 | 7 | | 4 | 7 | | 5 | 8 | | 6 | 9 | | 7 | 10 | | 8 | 11 | | 9 | black |

  • #1024 2348455 Thanks @langermank! - Extend neutral scale to include white/black (0-13)

  • #956 13f62d5 Thanks @lukasoppermann! - Removed space tokens

  • #1026 401fef1 Thanks @langermank! - - Update counter bg styles

    • Contrast fixes
  • #968 d845fdf Thanks @lukasoppermann! - Rename data-[colorName]-color to data-[colorName]-color-emphasis

8.2.4

Patch Changes

8.2.3

Patch Changes

8.2.2

Patch Changes

8.2.1

Patch Changes

8.2.0

Minor Changes

Patch Changes

8.1.0

Minor Changes

Patch Changes

8.0.0

Major Changes

7.17.0

Minor Changes

Patch Changes

7.16.0

Minor Changes

Patch Changes

7.15.15

Patch Changes

7.15.14

Patch Changes

7.15.13

Patch Changes

7.15.12

Patch Changes

7.15.11

Patch Changes

7.15.10

Patch Changes

7.15.9

Patch Changes

7.15.8

Patch Changes

7.15.7

Patch Changes

7.15.6

Patch Changes

7.15.5

Patch Changes

7.15.4

Patch Changes

7.15.3

Patch Changes

  • #778 f546c45 Thanks @mperrotti! - Updates inactive button text colors to meet contrast against the inactive button background color.

7.15.2

Patch Changes

7.15.1

Patch Changes

  • #774 3a6d736 Thanks @mperrotti! - Adds color tokens for the "inactive" button state. Tokens are added to the old and new builds so we can still support styling with styled-components

7.15.0

Minor Changes

  • #744 5f9eb77 Thanks @mperrotti! - Introduces design tokens for motion properties, and adds tokens to support loading indicators.

Patch Changes

7.14.1

Patch Changes

  • #743 5125c62 Thanks @langermank! - - Disabled state for transparent type controls is now transparent

    • Reverted the selected color for transparent type controls back to the original (pulled from old source file)
    • Fixed the disabled fgColor for ToggleSwitch
  • #742 efa8b1c Thanks @lukasoppermann! - buttonCounter color hotfix

  • #739 04a316c Thanks @lukasoppermann! - Fix contrast for bgColor-neutral-muted

7.14.0

Minor Changes

Patch Changes

7.13.1

Patch Changes

  • #733 f431e7e Thanks @langermank! - - Remove the default button inset shadow (its basically invisible)

    • Switch danger button to use the same border strategy as primary for hover/active
  • #735 0d982b1 Thanks @langermank! - Add missing fallbacks for disabled buttons

  • #731 5ebfafe Thanks @lukasoppermann! - change scss output from css variables to scss variables

  • #734 df91f47 Thanks @langermank! - - Add iconColor tokens for the invisible button variant

    • Remove highlight shadow token as its no longer used for Button

7.13.0

Minor Changes

  • #682 a082224 Thanks @langermank! - - Add inverse color options for semantic color tokens to support Toast
    • Update the default emphasis background color to white in dark mode
    • Add overlay size tokens

Patch Changes

7.12.0

Minor Changes

Patch Changes

7.11.14

Patch Changes

7.11.13

Patch Changes

7.11.12

Patch Changes

7.11.11

Patch Changes

7.11.10

Patch Changes

7.11.9

Patch Changes

7.11.8

Patch Changes

7.11.7

Patch Changes

  • ad20369 Thanks @lukasoppermann! - ## Updated workflow for v8 tokens

    • size-fine and size-coarse tokens are now wrapped in media queries

7.11.6

Patch Changes

7.11.5

Patch Changes

7.11.4

Patch Changes

7.11.3

Patch Changes

  • #542 9df92a7 Thanks @lukasoppermann! - - accent.subtle in dark is less opaque to have a 4.5 contrast with new accent color
    • danger and close fg slightly changed in light mode to contrast with fg.default (as we have some red links)
    • attention.emphasis darker to have 4.5:1 contrast with fg.onEmphasis

7.11.2

Patch Changes

7.11.1

Patch Changes

7.11.0

Minor Changes

  • #485 4e408ca Thanks @lukasoppermann! - Adds control.borderColor.emphasis color token

  • #449 7130392 Thanks @rezrah! - Deprecated marketing design tokens for Button components

    Marketing tokens will be served from @primer/brand-primitives in future.

    npm install --save @primer/brand-primitives
    
    - ---color-mktg-btn-bg
    + --brand-Button-background-base
    
    - --color-mktg-btn-shadow-outline
    + --brand-Button-shadow-default
    
    - --color-mktg-btn-shadow-focus
    + --brand-Button-shadow-focus
    
    - --color-mktg-btn-shadow-hover
    + --brand-Button-shadow-primary-hover
    
    - --color-mktg-btn-shadow-muted
    + --color-mktg-btn-shadow-hover-muted
    

    :link: See the 0.9.0 for all other tokens.

  • #385 e03c7fd Thanks @simurai! - Add Noto Sans to the font stack

  • #384 8b76794 Thanks @langermank! - - Remove deprecated focus color tokens in favor of "global" styles from Primer CSS

7.10.0

Minor Changes

Patch Changes

7.9.0

Minor Changes

Patch Changes

7.8.4

Patch Changes

7.8.3

Patch Changes

7.8.2

Patch Changes

7.8.1

Patch Changes

7.8.0

Minor Changes

  • #317 45359ea Thanks @langermank! - - Initial design tokens release for interal Primer team use only
    • Private docs that can be accessed at /typography and /size
    • Separate dist for testing purposes only

7.7.0

Minor Changes

7.6.0

Minor Changes

Patch Changes

7.5.1

Patch Changes

7.5.0

Minor Changes

Patch Changes

7.4.1

Patch Changes

7.4.0

Minor Changes

7.3.0

Minor Changes

7.2.0

Minor Changes

Patch Changes

7.1.1

Patch Changes

7.1.0

Minor Changes

7.0.1

Patch Changes

7.0.0

Major Changes

6.1.0

Minor Changes

6.0.0

Major Changes

5.1.0

Minor Changes

5.0.0

Major Changes

  • #245 65ad2df Thanks @colebemis! - All deprecated color variables have been removed. See removed variables for the complete list of removed variables.

  • #245 65ad2df Thanks @colebemis! - The deprecations directory in the dist directory has been renamed to deprecated:

    dist/
    - deprecations/
    + deprecated/
    

    You'll need to update your imports accordingly:

    - import deprecatedColors from '@primer/primitives/dist/deprecations/colors.json'
    + import deprecatedColors from '@primer/primitives/dist/deprecated/colors.json'
    

Minor Changes

  • #245 65ad2df Thanks @colebemis! - The dist directory now contains a removed directory with data about removed variables organized by category:

      dist/
        js/
        ts/
        json/
        scss/
        deprecated/
    +   removed/
    +     colors.json
    

    Each JSON file in the removed directory contains a mapping of removed variables to replacement variables. Example:

    // dist/removed/colors.json
    {
      "text.primary": "fg.default", // this means: `text.primary` is deprecated. Use `fg.default` instead
      "auto.blue.4": ["accent.fg, accent.emphasis"], // this means: `auto.blue.4` is deprecated. Use `accent.fg` or `accent.emphasis` instead
      "text.white": null // this means: `text.white` is deprecated. We don't have a replacement for it
    }
    

    This data will allow you to write linters to prevent usage of removed variables.

Patch Changes

4.8.1

Patch Changes

4.8.0

Minor Changes

Patch Changes

4.7.1

Patch Changes

4.7.0

Minor Changes

4.6.9

Patch Changes

4.6.8

Patch Changes

4.6.7

Patch Changes

4.6.6

Patch Changes

4.6.5

Patch Changes

4.6.4

Patch Changes

4.6.3

Patch Changes

4.6.2

Patch Changes

4.6.1

Patch Changes

4.6.0

Minor Changes

  • #202 25a91d9 Thanks @colebemis! - The dist directory now contains a deprecations directory with variable deprecation data organized by category:

      dist/
        js/
        ts/
        json/
        scss/
    +   deprecations/
    +     colors.json
    

    Each JSON file in the deprecations directory contains a mapping of deprecated variables to replacement variables. Example:

    // dist/deprecations/colors.json
    {
      "text.primary": "fg.default", // this means: `text.primary` is deprecated. Use `fg.default` instead
      "auto.blue.4": ["accent.fg, accent.emphasis"], // this means: `auto.blue.4` is deprecated. Use `accent.fg` or `accent.emphasis` instead
      "text.white": null // this means: `text.white` is deprecated. We don't have a replacement for it
    }
    

    This data will allow consumers of @primer/primitives (e.g. Primer React and Primer ViewComponents) to write linters to prevent usage of deprecated variables.

4.5.4

Patch Changes

4.5.3

Patch Changes

4.5.2

Patch Changes

4.5.1

Patch Changes

4.5.0

Minor Changes

Patch Changes

4.4.4

Patch Changes

4.4.3

Patch Changes

4.4.2

Patch Changes

4.4.1

Patch Changes

4.4.0

Minor Changes

Patch Changes

4.3.11

Patch Changes

4.3.10

Patch Changes

4.3.9

Patch Changes

4.3.8

Patch Changes

4.3.7

Patch Changes

4.3.6

Patch Changes

4.3.5

Patch Changes

4.3.4

Patch Changes

4.3.3

Patch Changes

4.3.2

Patch Changes

4.3.1

Patch Changes

  • #83 beeaeb7 Thanks @simurai! - Change icon-info to blue-3 in dark mode

  • #85 d5b4305 Thanks @simurai! - Add experimental color variables to colors_v2 directory. Warning: Do not use these color variables

4.3.0

Minor Changes

Patch Changes

4.2.2

Patch Changes

4.2.1

Patch Changes

4.2.0

Minor Changes

Patch Changes

4.1.0

Minor Changes

4.0.2

Patch Changes

4.0.1

Major Changes

Patch Changes

3.0.1 (2020-04-28)

:rotating_light: Breaking Changes

  • #14 Convert the package from JSON to TypeScript (@smockle)

2.0.0 (2019-10-21)

:rotating_light: Breaking Changes

  • #14 Rename npm package to @primer/primitives and deprecate old primer-* packages (@BinaryMuse)

1.0.2 (2018-07-20)

:bug: Bug Fix

  • #6 Fix spacing to be an array instead of an object. (@broccolini)

:memo: Documentation

1.0.1 (2018-05-10)

:bug: Bug Fix

:house: Internal

1.0.0 (2018-04-29)

:rocket: Enhancement

  • #1 Add color, typography, and spacing packages. (@broccolini)
  • #1 Add primer-primitives package that imports all primitives. (@broccolini)