@rei/cdr-component-variables v3.0.0-beta.0
cdr-component-variables
Component variables provide a versioned method for teams to import the exact CSS styles being used in the Cedar vue components and apply them to elements in their project. See the Cedar docs for more high level information about component variables.
Supported Components
See the docs page for a list of supported components and examples of how they can be used. If there is a component that you would like to see supported, please open an issue here. If you are trying to build a component that is not in Cedar, you should instead use the design tokens.
Install
The component variables inherit values from the design tokens, so you will need to install both packages:
npm install --save-dev @rei/cdr-tokens @rei/cdr-component-variables
Your project must be able to compile SCSS or LESS in order to make use of this package.
This package contains /dist/less and /dist/scss folders, each of which contains *.vars.{less|scss} for each component, as well as an index.{scss|less} that imports all of those files. It is recommended that you use the index file to ensure that all variables are loaded in the correct order. A dist/{scss|less}/cedar-component-variables.{scss|less} file is also available which concatenates all of the variable files together.
Usage
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;
}
.your-other-button-class {
/* use variables if you need to apply specific properties */
border-radius: $cdr-button-border-radius;
}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();
}
.your-other-button-class {
/* use variables if you need to apply specific properties */
border-radius: @cdr-button-border-radius;
}The docs page demonstrates which mixins to use to achieve various styles for each supported component.
You can find all of the exported variables and mixins in the /dist directory.
If you are unsure of how a variable or mixin is intended to be used, you can search for the variable name in the Cedar component source.
Development
The /dist folder in this project should never be edited directly as it is meant to stay in sync with Cedar. This package should be updated whenever component variable support is added to a new component, or whenever the markup/styling for a supported component changes.
Update steps:
- Ensure that your copy of
rei-cedarandrei-cedar-component-variablesare in the same directory - Run the
build:variablesscript inrei-cedarto copy the variable files for all supported components into this repository. If you are adding support for a component, you will need to update that build script. If there are no changes to the/distdirectory, then there is no need to do anything else. - Run the
build:lessscript inside this repository to create a LESS copy of the previous SASS export - Update the
cdr-tokensdependencies in this project'spackage.jsonso that the version exactly matches the version currently being used inrei-cedar - Update
/examplesas needed. Note that you will need to re-start thedevscript any time the example SCSS code changes. - Bump the version of this package
- Run the
build:docsscript in this project
Adding Examples to the Doc-site
The examples generated by this project demonstrate how the component variables can be used to re-create the Vue.js Cedar components. Note that you must re-run the npm run build:stylesheet command any time you change the name or styles properties for any of the examples
That data is stored as JSON which uses the following structure:
{
"name": "Example Name (i.e, default, primary, secondary).",
"tag": "HTML tag to use for variables example (i.e, div, button, a)",
"styles": [
"SCSS code used to build variables example CSS",
"another line of SCSS"
],
"preContent": "HTML to append before the `name` inside of the variables example",
"postContent": "HTML to append after the `name` inside of the variables example",
"props": {
"id": "HTML attributes applied to the variables example tag",
"href": "#foo"
},
"slot": "used to set v-html on the Vue example.",
"attrs": {
"label": "arbitrary props applied to the Vue example component",
"modifier": "primary"
}
}See the examples directory for more instances of how this JSON is constructed, or the Example component to see how this JSON is translated into the doc site.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago