Styling Components

This document outlines the details of the CSS styling for Spectrum Web Components.

Component Styling

Section titled Component Styling

For each component in the project, there are upto 3 CSS files:

How to update the component styling

Section titled How to update the component styling

We will try to keep the concerns separate for the component styling and so depending on the changes, we will need to update the component styling in the following ways:

The process to update these two css files is the same and is as follows:

Example:

:host {
    - --spectrum-accordion-item-height: var(--spectrum-component-height-200);
    + --spectrum-accordion-item-height: var(--spectrum-component-height-300);
}

This will just work! As long as the --spectrum-component-height-300 variable exists in the tokens package.

The process to update the overrides file involves a few extra steps:

  1. Update the [component-name]-overrides.css file to contain the new styles.
  2. Make sure the new --system- variable exists in the tokens package. This variable can be found in the tools/styles/tokens/[express | spectrum]/system-theme-bridge.css file or the tools/styles/tokens-v2/system-theme-bridge.css file depending on the theme.
  3. If the variable doesn't exist, we will need to add it to the correct file.

Global styling

Section titled Global styling

SWC project uses styles package to manage the global css tokens for all three themes. The styles package can be found in tools/styles. There is one very small caveat in the way we manage the styles package. We have two different tokens packages, one for the express + spectrum theme and one for the spectrum 2 theme.

NOTE: In all likelihood, you would only need to do minor changes to the styles package. However, if you feel like you need to make major changes to the styles package, the correct approach would be to start a discussion among the team and figure out a plan together.

How to update the global styling

Section titled How to update the global styling

In our styles package, we have separation of separate variables for different contexts i.e, size and color.

Updating size-specific css variables

Section titled Updating size-specific css variables

If you're updating a size (e.g. --spectrum-accordion-item-height) variable, you'll need to update the tools/styles/tokens/[express | spectrum]/[large | medium]-vars.css file or the tools/styles/tokens-v2/[large | medium]-vars.css file depending on the theme.

Updating color-specific css variables

Section titled Updating color-specific css variables

If you're updating a color (e.g. --spectrum-accordion-background-color) variable, you'll need to update the tools/styles/tokens/[express | spectrum]/[dark | light]-vars.css file or the tools/styles/tokens-v2/[dark | light]-vars.css file depending on the theme.

NOTE: If the variable that you're updating is not present in those files, chances are that this variable had the same value for both contexts in that tokens package. In that case, if you want the variable to continue to have the same value then you can update the tools/styles/[tokens | tokens-v2]/index.css file. Or if you want to make the variable context-specific, then you can add those new values in both of the files like we talked about above.