Design Tokens and Styles for the OpenGov Capital Design System.
npm install @opengov/capital-styleyarn add @opengov/capital-styleTokens are individual variables that can be used to build styles, such as colors, fonts, or size units. We build in JSON under the /tokens folder. From there they are exported to scss. A few mixins are added to these tokens as well to build more complex styles (such as focus).
To import just the tokens into your scss file, place this line at the top of every file you want to use your tokens:@import “~@opengov/capital-style/scss/tokens;
If your SCSS is compiled all together, this should only be needed once. If you are using CSS Modules in React, this will be needed for every scss file you need to use the tokens in.
color: $color-primary-selection;To reference a token within a function:width: calc(100vw - #{$unit-20});
To use media queries:@media #{$mq-small} { ... }
To use mixins:@include focus-wrap;
Tokens are not currently available in JS.
@import “~@opengov/capital-style/scss/tokens;
* Token and mixin definitions
@import “~@opengov/capital-style/scss/font;
* Font definitions
@import “~@opengov/capital-style/scss/base;
* Imports tokens, mixins and fonts
* Imports normalize.css
* A few base styles for your application: setting the font, basic focus, and bold font weight
@import “~@opengov/capital-style/scss/components;
* Styles for basic components: Component Stylesheet Documentation
@import “~@opengov/capital-style/scss/capital;
* Everything
The capital stylesheet is also compiled as CSS and can be pointed to with:
.cds- to avoid conflicts with any existing styles. All children styles will only be affective with the correct parent style.Styles are written with BEM. Children objects are prefixed with __ and modifiers are prefixed with --. Modifiers should state what is being modified and then the modification. For example:
``
.cds-button {
&.cds-button--variantPrimary {}
&.cds-button--sizeDefault {}
svg.cds-button__icon {}
}
`
and can be imported with:
@import “~@opengov/capital-style/scss/font;Visualization Colors
You can see all of the token on this Github Page:
https://opengov.github.io/Capital-Style/
`
import { vizColors } from '@opengov/capital-style/js';
import { getVizColors } from '@opengov/capital-style/js';
`Adding Tokens, Mixins or Styles
$3
Tokens should be added within the /tokens folder to the appropriate json file. Update the docs/index.html to list any new tokens added.$3
Mixins should be added to the /scss/tokens/mixins file. Update the docs/index.html to list any new mixins added.$3
Component Styles are maintained under /scss/components`.#### Style Namespacing
Please see the above notes on how classes are named and follow this pattern.
#### Targeting HTML elements
NEVER target an HTML element directly without a class used as an identifier.
#### Nesting Styles
Styles should always be nested under one parent style for the component.