Component variables provide a versioned method for teams to:
Component variables are only available for a core subset of Cedar components, and are distributed in SCSS and LESS format.
Component variables include mixins such as @include cdr-button-base-mixin
which sets many properties on an element. Each component has a base
mixin which sets properties that apply to all components of that type, as well as modifier
mixins which only apply to a specific variant of that component
For example, you can import the styling for a Cedar primary button component using a mixin:
.your-button-component {
@include cdr-button-base-mixin;
@include cdr-button-primary-mixin;
}
Test out what you can do with the component variables in this CodeSandbox (opens new window).
See the component variables example project (opens new window) for a template demonstrating how to use Cedar tokens and component variables to generate a unique CSS stylesheet that applies Cedar styles to arbitrary HTML markup.
Versioning
Semantic naming
vue-router
link component that looks like a CdrLink
componentcdr-button-base-mixin
should only ever be used to style a button elementThe naming structure for component variables and mixins is as follows:
cdr
base-
) indicates variables that apply to all instances of that Cedar componentbase
, primary
, and large
modifierscdr-input-base-label-color
indicates the color of the label element used inside the input component:focus
, :active
, :hover
, :disabled
, etc.Namespace | Component | Modifier | Sub-Element | State | Mixin |
---|---|---|---|---|---|
cdr- | input- | base- | mixin | ||
cdr- | button- | secondary- | mixin | ||
cdr- | breadcrumb- | item- | linked- | mixin | |
cdr- | select- | base- | label- | disabled- | mixin |
The component variables inherit values from the Cedar design tokens, so you will need to install both packages and keep them in sync when updating:
npm install --save-dev @rei/cdr-tokens @rei/cdr-component-variables
SCSS example:
@import '@rei/cdr-tokens/dist/scss/cdr-tokens.scss'; /* import the tokens file */
@import '@rei/cdr-component-variables/dist/scss/index.scss'; /* import the component variables */
.your-button-class {
/* use mixins to apply many properties at once */
@include cdr-button-base-mixin;
@include cdr-button-primary-mixin;
}
LESS example:
@import '@rei/cdr-tokens/dist/less/cdr-tokens.less'; /* import the tokens file */
@import '@rei/cdr-component-variables/dist/less/index.less'; /* import the component variables */
.your-button-class {
/* use mixins to apply many properties at once */
.cdr-button-base-mixin();
.cdr-button-primary-mixin();
}
Example | HTML | SCSS |
---|---|---|
breadcrumb | <a href="cdr-breadcrumb-default"> breadcrumb </a> | .cdr-breadcrumb-default { @include cdr-breadcrumb-item-mixin; @include cdr-breadcrumb-item-linked-mixin; @include cdr-breadcrumb-base-text-mixin; } |
Example | HTML | SCSS |
---|---|---|
<button class="cdr-button-primary">primary</button> | .cdr-button-primary { @include cdr-button-base-mixin; @include cdr-button-primary-mixin; } | |
<button class="cdr-button-secondary">secondary</button> | .cdr-button-secondary { @include cdr-button-base-mixin; @include cdr-button-secondary-mixin; } | |
<button class="cdr-button-sale"> sale </button> | .cdr-button-sale { @include cdr-button-base-mixin; @include cdr-button-sale-mixin; } | |
<button class="cdr-button-dark"> dark </button> | .cdr-button-dark { @include cdr-button-base-mixin; @include cdr-button-dark-mixin; } | |
<button class="cdr-button-primary-small"> primary-small </button> | .cdr-button-primary-small { @include cdr-button-base-mixin; @include cdr-button-primary-mixin; @include cdr-button-small-mixin; } | |
<button class="cdr-button-secondary-medium"> secondary-medium </button> | .cdr-button-secondary-medium { @include cdr-button-base-mixin; @include cdr-button-secondary-mixin; @include cdr-button-medium-mixin; } | |
<button class="cdr-button-primary-large"> primary-large </button> | .cdr-button-primary-large { @include cdr-button-base-mixin; @include cdr-button-primary-mixin; @include cdr-button-large-mixin; } |
Example | HTML | SCSS |
---|---|---|
<div class="cdr-card-default"> <a href="#" class="link">default card</a> </div> | .cdr-card-default { @include cdr-card-base-mixin; .link { @include cdr-card-link-mixin; } } |
Example | HTML | SCSS |
---|---|---|
<button class="cdr-chip-default">Default Chip</button> | .cdr-chip-default { @include cdr-chip-base-mixin; } | |
<button class="cdr-chip-icon-left"><span class="cdr-chip-icon-left-icon">๐</span> <span class="cdr-chip-content-right">Chip with Icon Left<span></button> | .cdr-chip-icon-left { @include cdr-chip-base-mixin; .cdr-chip-content-right { @include cdr-chip-content-right-mixin; } .cdr-chip-icon-left-icon { @include cdr-chip-icon-left-mixin; } } | |
<button class="cdr-chip-icon-right"><span class="cdr-chip-content-left">Chip with Icon Right<span> <span class="cdr-chip-icon-right-icon">๐ฎ</span></button> | .cdr-chip-icon-right { @include cdr-chip-base-mixin; .cdr-chip-content-left { @include cdr-chip-content-left-mixin; } .cdr-chip-icon-right-icon { @include cdr-chip-icon-right-mixin; } } |
Example | HTML | SCSS |
---|---|---|
<div class="cdr-form-error-default"> <span class="cdr-form-error-icon">๐ฆ</span> Form Error </div> | .cdr-form-error-default { @include cdr-form-error-base-mixin; .cdr-form-error-icon { @include cdr-form-error-icon-mixin; } } |
Example | HTML | SCSS |
---|---|---|
<fieldset class="cdr-form-group-default"> <legend>form group title</legend> <div class="cdr-form-group-content"><input/><input/></div> </fieldset> | .cdr-form-group-default { @include cdr-form-group-base-mixin; .cdr-form-group-content { @include cdr-form-group-content-mixin; } } | |
<fieldset class="cdr-form-group-error"> <legend>form group title</legend> <div class="cdr-form-group-content"><input/><input/></div> </fieldset> | .cdr-form-group-error { @include cdr-form-group-base-mixin; .cdr-form-group-content { @include cdr-form-group-content-mixin; @include cdr-form-group-error-mixin; } } |
Example | HTML | SCSS |
---|---|---|
a b c | <div class="cdr-grid-default"><div>a</div><div>b</div><div>c</div></div> | .cdr-grid-default { @include cdr-grid-base-mixin; grid-template-columns: 1fr 1fr 1fr; } |
a b c | <div class="cdr-grid-gutter-none"><div>a</div><div>b</div><div>c</div></div> | .cdr-grid-gutter-none { @include cdr-grid-base-mixin; @include cdr-grid-gutter-none-mixin; grid-template-columns: 1fr 1fr 1fr; } |
a b c | <div class="cdr-grid-gutter-small"><div>a</div><div>b</div><div>c</div></div> | .cdr-grid-guttter-small { @include cdr-grid-base-mixin; @include cdr-grid-gutter-small-mixin; grid-template-columns: 1fr 1fr 1fr; } |
a b c | <div class="cdr-grid-guttter-medium"><div>a</div><div>b</div><div>c</div></div> | .cdr-grid-guttter-medium { @include cdr-grid-base-mixin; @include cdr-grid-gutter-medium-mixin; grid-template-columns: 1fr 1fr 1fr; } |
a b c | <div class="cdr-grid-gutter-large"><div>a</div><div>b</div><div>c</div></div> | .cdr-grid-guttter-large { @include cdr-grid-base-mixin; @include cdr-grid-gutter-large-mixin; grid-template-columns: 1fr 1fr 1fr; } |
Example | HTML | SCSS |
---|---|---|
<input class="cdr-input-default"/> | .cdr-input-default { @include cdr-input-base-mixin; @include cdr-input-primary-mixin; } | |
<input class="cdr-input-error"/> | .cdr-input-error { @include cdr-input-base-mixin; @include cdr-input-primary-mixin; @include cdr-input-error-mixin; } | |
<input class="cdr-input-large"/> | .cdr-input-large { @include cdr-input-base-mixin; @include cdr-input-primary-mixin; @include cdr-input-large-mixin; } | |
<input class="cdr-input-on-secondary-bg"/> | .cdr-input-on-secondary-bg { @include cdr-input-base-mixin; @include cdr-input-secondary-mixin; } |
Example | HTML | SCSS |
---|---|---|
<label class="cdr-label-standalone-default"> Default label </label> | .cdr-label-standalone-default { @include cdr-label-standalone-label-mixin; } | |
<label class="cdr-label-standalone-required"> Required label * </label> | .cdr-label-standalone-required { @include cdr-label-standalone-label-mixin; } | |
<label class="cdr-label-standalone-optional"> Optional label <span class="optional-label">(optional)</span> </label> | .cdr-label-standalone-optional { @include cdr-label-standalone-label-mixin; .optional-label { @include cdr-label-standalone-optional-mixin; } } | |
<label class="cdr-label-standalone-disabled"> Disabled label </label> | .cdr-label-standalone-disabled { @include cdr-label-standalone-disabled-mixin; } | |
Helper text
| <div class="cdr-label-standalone-helper-text"> Helper text </div> | .cdr-label-standalone-helper-text { @include cdr-label-standalone-helper-mixin; } |
Info text
| <div class="cdr-label-standalone-info"> Info text </div> | .cdr-label-standalone-info { @include cdr-label-standalone-info-mixin; } |
Example | HTML | SCSS |
---|---|---|
<label class="cdr-label-wrapper-default"> <input type="checkbox"/> Default label </label> | .cdr-label-wrapper-default { @include cdr-label-wrapper-base-mixin; @include cdr-label-wrapper-primary-mixin; } | |
<label class="cdr-label-wrapper-secondary-bg"> <input type="radio"/> Label on secondary background </label> | .cdr-label-wrapper-secondary-bg { @include cdr-label-wrapper-base-mixin; @include cdr-label-wrapper-secondary-mixin; } | |
<label class="cdr-label-wrapper-disabled"> <input type="checkbox" disabled/> Disabled label </label> | .cdr-label-wrapper-disabled { @include cdr-label-wrapper-base-mixin; @include cdr-label-wrapper-disabled-mixin; } |
Example | HTML | SCSS |
---|---|---|
link default | <a href="#" class="cdr-link-default"> link default </a> | .cdr-link-default { @include cdr-link-base-mixin; } |
link standalone | <a href="#" class="cdr-link-standalone"> link standalone </a> | .cdr-link-standalone { @include cdr-link-base-mixin; @include cdr-link-standalone-mixin; } |
Example | HTML | SCSS |
---|---|---|
| <ol class="cdr-list-ordered"> <li>one</li> <li>two</li> <li>three</li> </ol> | .cdr-list-ordered { @include cdr-list-base-mixin; @include cdr-list-ordered-mixin; } |
| <ul class="cdr-list-unordered"> <li>one</li> <li>two</li> <li>three</li> </ul> | .cdr-list-unordered { @include cdr-list-base-mixin; @include cdr-list-unordered-mixin; } |
Example | HTML | SCSS |
---|---|---|
<select class="cdr-select-default"/> | .cdr-select-default { @include cdr-select-base-mixin; @include cdr-select-primary-mixin; } | |
<select class="cdr-select-error"/> | .cdr-select-error { @include cdr-select-base-mixin; @include cdr-select-primary-mixin; @include cdr-select-error-mixin; } | |
<select class="cdr-select-large"/> | .cdr-select-large { @include cdr-select-base-mixin; @include cdr-select-primary-mixin; @include cdr-select-large-mixin; } | |
<select class="cdr-select-on-secondary-bg"/> | .cdr-select-on-secondary-bg { @include cdr-select-base-mixin; @include cdr-select-secondary-mixin; } |
Example | HTML | SCSS | ||
---|---|---|---|---|
| <table class="cdr-table-default"> <tr><th>Test head</th></tr> <tr><td>Test content</td></tr> </table> | .cdr-table-default { @include cdr-table-base-mixin; } |
Questions about when to use component variables? Ask the Cedar team in #cedar-user-support (opens new window)