Installing Cedar

Cedar components are built using Vue 3 and can only be used in Vue projects.

All components are available using an NPM package.

Terminal

npm install --save @rei/cedar

Once installed, you can import individual Cedar components from the main package into your project:

Vue SFC

<script setup>
// import packages from Cedar
import { CdrText, CdrButton, CdrLink } from '@rei/cedar'

</script>

<template>
  // use the registered Cedar components in your template
  <CdrText>Foo</CdrText>
  <CdrButton>Bar</CdrButton>
  <CdrLink>Baz</CdrLink>
</template>

<style>
  // no need to import any Cedar related CSS here
</style>

App entry point

/* import the Cedar CSS reset and fonts first,
   these files only needs to be loaded once on each page,
   components should expect that the app consuming
   them will load the fonts and reset */
@import '@rei/cedar/dist/cdr-fonts.css';
@import '@rei/cedar/dist/cdr-reset.css';

/* import each component used in your project  */
@import '@rei/cedar/dist/style/cdr-text.css';
@import '@rei/cedar/dist/style/cdr-button.css';
@import '@rei/cedar/dist/style/cdr-link.css';

All components depend upon core reset and font assets. Without these assets included, components will not render correctly. These files are distributed as part of the Cedar NPM package.

Install Vue components package

Terminal

npm install --save @rei/cedar

Install required core styles

Cedar requires a core reset stylesheet to render properly. This file should be loaded once per application/route, and it should be the first CSS file loaded.

To include the stylesheet, import the cdr-reset.css file:

App entry point

@import '@rei/cedar/dist/cdr-reset.css';

Install required fonts

Cedar uses specific fonts (Stuart and Graphik) required for your project. These fonts are available in the Cedar NPM package and mapped using the cdr-fonts.css file.

To include these fonts, import cdr-fonts.css:

App entry point

@import '@rei/cedar/dist/cdr-fonts.css';

How you include CSS depends on your tech stack and varies from project to project. The following instructions apply to REI Vue 3/Vite apps

  1. In your app's client entry, bring in the reset, fonts, and any component styles used in that app.

entry-client.js


import '@rei/cedar/dist/cdr-reset.css';
import '@rei/cedar/dist/cdr-fonts.css';

/* import each component used in your project  */
@import '@rei/cedar/dist/style/cdr-text.css';
@import '@rei/cedar/dist/style/cdr-button.css';
@import '@rei/cedar/dist/style/cdr-link.css';

Cedar CSS assets can all be found inside node_modules/@rei/cedar/dist/style/. Filenames for component CSS match the kebab-case name of the component.

Include full CSS

For public facing production micro-sites always optimize your Cedar CSS imports by only loading the assets you need. However, for some projects it may make sense to skip that process and just load all of the Cedar assets.

entry-client.js

import '@rei/cedar/dist/cdr-reset.css';
import '@rei/cedar/dist/cdr-style.css';

Using components

The examples in our documentation demonstrate usage in a Single File Component. If you aren’t using SFCs, read the Vue.js documentation for registering components.

Examples below demonstrate the CdrButton component. Refer to each component’s documentation for a complete component API and advanced examples.

Loading a component in Vue

  1. Import the component within the script block.

local.vue

import { CdrButton } from '@rei/cedar';
  1. Register the component in the components: object.

local.vue

components: {
  CdrButton
}
  1. Add the component element, such as <CdrButton> into the template.

local.vue

<CdrButton>I'm a button</CdrButton>
  1. Load Cedar CSS assets in your client entry:

entry-client.js

/* import the button CSS file */
@import url('@rei/cedar/dist/style/cdr-button.css');

Final file:

local.vue

<script>
import { CdrButton } from '@rei/cedar';
export default {
  ...
  components: {
    CdrButton
  }
}
</script>

<template>
    <CdrButton>I'm a button</CdrButton>
</template>

Configure component props

Props are custom attributes registered on a component. For more information about props, read Vue's Props documentation.

Most Cedar components provide props to configure component data, display and logic. For example, the CdrButton component provides a size prop to configure the button’s size.

<CdrButton size="large">I'm a large button</CdrButton>

Refer to each component’s API documentation for a full list of available properties.

Bind dynamic data to components

Props can be static or dynamic. To provide dynamic data (or non-string data) add a colon (:) before the prop name.

Prop names are also documented and referenced in JavaScript as camel case, but used in the template as kebab-case.

In this example, the size prop accepts a string denoting size at different breakpoints.

<CdrButton size="small@xs large@sm">I'm a responsive button</CdrButton>

Add content using slots

Some components use slots for content distribution. Most components will have a single default slot; others will have named slots or scoped slots. Slots are listed as part of the API for all components. For more information about slots, read Vue's Slots documentation.

Adding content to a component that has a default slot:

<CdrButton>I'm content in the default slot</CdrButton>

Adding content to a component that has named slots:

<MyComponent>
  <template #header>I'm content in the header slot</template>

  <template #footer>I'm content in the footer slot</template>
</MyComponent>

Adding content to a scoped slot:

Parent.vue

<MyComponent v-slot="slotProps">
  {{ slotProps.text }} {{ slotProps.count }}
</MyComponent>

MyComponent.vue

<div>
  <slot :text="greetingMessage" :count="1"></slot>
</div>

CSS Modules and custom class names

Component CSS class names use CSS Modules reflecting the package version. For example, @rei/cedar@42.1.3 will have classes ending in _42.1.3. This allows for using multiple versions of Cedar together on the same page.

Never use Cedar class names within your own CSS or target them in JavaScript; they will change as you upgrade the package and break any functionality or styling you attach to them.

To target CSS, create custom selectors such as my-wrapper and my-selector in the following example:

<template>
  <div class="wrapper">
    <CdrButton class="wrapper__button">I'm a button</CdrButton>
  </div>
</template>

<style lang="scss">
.wrapper {
  &__button {
    /* override button styles here */
  }
}
</style>

Some components are more complex and have templates with multiple areas where you may wish to add your own selectors. We try to be mindful of this and add props that will allow you to target your own classes to various elements.

For example with checkbox you may want to target both the label and the content areas.

<template>
  <CdrCheckbox
    label-class="my-label"
    content-class="my-content"
  >
    My checkbox
  </CdrCheckbox>
</template>

...

<style>
.my-label {

}

.my-content {

}
</style>

If you find that a component needs to have a targeted prop class added, please create an issue and let us know.

When using Cedar in a consumed application (e.g. an external npm package), it's important to set Cedar as a peerDependency so that the consuming application can resolve the import. This is especially important when multiple external applications are involved.

Be mindful of where your external application is being consumed when updating Cedar versions. If you are bringing in a major version of Cedar, it's important it coincides with a major version bump in your consumed application so that other apps don't inadavertently bring in breaking changes.

Cedar provides a robust collection of design tokens corresponding to Cedar's foundations. Standard colors, typography, space, size and other properties are available in the cdr-tokens package. Outputs support web, iOS, and Android consumers.

As you create your own components, work with your designer to take advantage of this inventory in your custom classes. Using them this way will ensure your custom styles remain consistent with design guidelines.

Install tokens package

Resources are available within the CdrToken package:

  • SCSS variables at dist/scss/cdr-tokens.scss
  • LESS variables at dist/less/cdr-tokens.less
  • JS as both commonJS and ES module at dist/js. Also noted in package.json as main and module respectively
    • dist/js/cdr-tokens.common.js
    • dist/js/cdr-tokens.mjs

To incorporate the required assets, use the following steps:

  1. Install the CdrToken package using npm in your terminal:

Terminal

npm install --save @rei/cdr-tokens

Using Cedar design tokens

The package contains files for using tokens in both CSS (as SCSS and LESS variables) and JavaScript (as commonJS and ES modules).

Here we’re using a typography mixin and a color token to style .myClass from the SCSS tokens file.

local.vue

<script>
export default {
  ...
}
</script>

<template>
  <p class="myClass">I'm styled with tokens!</p>
</template>

<style lang="scss">
@import '~@rei/cdr-tokens/dist/rei-dot-com/scss/cdr-tokens.scss';

.myClass {
  @include cdr-text-body-300;
  color: $cdr-color-text-primary;
}
</style>

Currently development for iOS and Android is through the usage of Cedar tokens as documented below.

Our mobile development packages include fonts that are licensed and proprietary to REI. For more information or questions regarding Cedar’s support for external consumers using the mobile development packages on GitHub or NPM, please reach out to cedar@rei.com.

iOS

CocoaPods

The preferred way to consume Cedar for iOS is through CocoaPods. View www.cocoapods.org for more information.

To find out if Cocoapods is already installed, open the terminal and run:

Terminal

pod --version

If “command not found” is returned then Cocoapods in not installed.

To install Cocoapods:

Terminal

sudo gem install cocoapods

To set up Cocoapods from the project/workspace directory, run:

Terminal

pod init

The above command will create a Podfile in your current directory.

The Podfile must be modified with the following to include Cedar as a dependency:

1. Prior to the Targets Section of the Podfile:

Terminal

source 'https://git.rei.com/projects/CDR/repos/cedar-iosl/CedarPodSpec.git'

2. In the Targets Section of the Podfile:

Terminal

pod 'CedarTokens', '~> 0.2.0'

Full Podfile Example for Reference:

Terminal

project 'CedarIOSCocoaPodDemo.xcodeproj/'

platform :ios, '12.0'

source 'https://git.rei.com/projects/CDR/repos/cedar-ios-podspec/CedarPodSpec.git'

target 'CedarIOSCocoaPodDemo' do
  # Pods for CedarIOSCocoaPodDemo
  pod 'CedarTokens', '~> 0.2.0'

end

Manual Consumption

If you don’t use Cocoapods, you can manually import files into your iOS project/workspace.

Colors

Color Sets in a .xcasset file. Import the file by dragging the Cedar.xcassets > Colors folder into your project's asset folder.

You can set the colors in Interface Builder, or by:

Terminal

Button1.backgroundColor = UIColor(named: "cdr_color_text_primary");
Text

The package includes Sentinel and Roboto font source files along with Swift Classes for applying Apple's Dynamic Type behavior to the font.

Importing the source font is done by creating a group under your target in xcode and dragging the font files into that group. Add the fonts to the info.plist under Fonts provided by application.

Finally, import the CedarFont.swift file along with the CedarTextStyles.plist. This will allow you to set the fonts by:

Terminal

  // Button Title 1 Style
  Button1.titleLabel?.font = CedarFont().getCedarFont(forTextStyle: .title1)
  Button1.titleLabel?.adjustsFontForContentSizeCategory = true;
Icons

Cedar provides icons in vector PDF format for iOS scaling. According to initial investigation, only one file per icon is needed in this format. There is no need for @1x, @2x, and @3x variants.

Android

Maven

The preferred way to consume Cedar Tokens on Android is to use Maven.

Add the following to the build.gradle file in your Android project:

Terminal

Implementation mvnrepos.rei.com:cedar-android.aar:0.2.0

Manual Consumption

If you don’t use Maven, import the Cedar Tokens into your Android project/workspace manually by dragging the resources into your project within Android Studio. The resources are located at the cedar-android repository on Bitbucket