|
1 | | -## Description |
| 1 | +## Overview |
2 | 2 |
|
3 | | -Spectrum Web Components are a [`LitElement`](https://lit-element.polymer-project.org)-powered web component library of patterns built on top of the [Spectrum CSS](https://opensource.adobe.com/spectrum-css) specification. Styles for these components are made available (and, in some cases, customizable) via CSS Custom Properties, e.g. `var(--spectrum-black)`. In this package, you will find the CSS Custom Properties that power the various color and size themes defined by Spectrum CSS. |
| 3 | +Spectrum Web Components are a [`LitElement`](https://lit-element.polymer-project.org)-powered web component library implementing Adobe's Spectrum design system. This package defines the CSS custom properties that implement design tokens from [Spectrum Tokens](https://github.com/adobe/spectrum-tokens). Spectrum Web Components consume these properties in their styles. These include colors, spacing, typography, and sizing values like `--spectrum-gray-100`, `--spectrum-component-height-200`, and `--spectrum-font-size-100`. In this package, you will find the CSS custom properties that Spectrum Web Components reference in their stylesheets, with values that vary across different system variants, color options, and scales. |
4 | 4 |
|
5 | | -The easiest way to consume these values is via the `<sp-theme>` element. However, in some cases, it can be useful to have direct access to the files outlining the CSS Custom Properties, on top of which the rest of the component system is built. |
| 5 | +### Relationship to `<sp-theme>` |
| 6 | + |
| 7 | +The `<sp-theme>` element is built on top of this styles package. It consumes the CSS custom properties provided here and wraps them in a Web Component that manages theme switching, directionality, and other runtime behaviors. |
| 8 | + |
| 9 | +**For most applications**, we recommend using `<sp-theme>` rather than directly importing these CSS files. The theme element provides a more flexible and maintainable way to manage systems, colors, and scales using attributes like `system="spectrum"`, `color="dark"`, and `scale="medium"` (e.g., `<sp-theme system="spectrum" color="dark" scale="medium">`). |
| 10 | + |
| 11 | +**Use this styles package directly** when you need: |
| 12 | + |
| 13 | +- Fine-grained control over which CSS files are loaded |
| 14 | +- To integrate Spectrum styles into non-web component contexts |
| 15 | +- To build custom components outside the `<sp-theme>` wrapper |
| 16 | +- Direct access to unthemed design tokens for advanced use cases |
| 17 | + |
| 18 | +See the `@spectrum-web-components/theme` [documentation](../theme) for more information about using the theme element. |
6 | 19 |
|
7 | 20 | ### Usage |
8 | 21 |
|
9 | 22 | [](https://www.npmjs.com/package/@spectrum-web-components/styles) |
10 | 23 | [](https://bundlephobia.com/result?p=@spectrum-web-components/styles) |
11 | 24 |
|
12 | | -``` |
| 25 | +```zsh |
13 | 26 | yarn add @spectrum-web-components/styles |
14 | 27 | ``` |
15 | 28 |
|
16 | | -## Theme packages |
| 29 | +## System variants |
17 | 30 |
|
18 | | -``` |
19 | | -@import '@spectrum-web-components/styles/all-medium-darkest.css'; |
20 | | -``` |
| 31 | +This package provides styles for three Adobe design system variants (referred to as "systems"). Each system has different available color options: |
21 | 32 |
|
22 | | -This file brings together the global variables and font settings with the "Darkest" color set and "Medium" scale system specification. |
| 33 | +- **Spectrum Legacy** (system: `spectrum`) - The original Spectrum design system with four color options: `dark`, `light`, and deprecated `darkest` and `lightest` |
| 34 | +- **Express** (system: `express`) - The Adobe Express design system with two color options: `dark` and `light` |
| 35 | +- **Spectrum 2** (system: `spectrum-two`) - The next generation Spectrum design system with two color options: `dark` and `light` |
23 | 36 |
|
24 | | -``` |
| 37 | +## Combined theme packages (Spectrum Legacy) |
| 38 | + |
| 39 | +If you're not using `<sp-theme>`, the styles package provides convenience bundles for Spectrum Legacy that combine everything you need in a single import. Each `all-*` file combines core global styles, typography, a color option, and a scale specification. Express and Spectrum 2 do not have equivalent combined packages; use manual theme composition instead (see below). |
| 40 | + |
| 41 | +> **Note:** The `darkest` and `lightest` colors are deprecated and will be removed in a future release. Use `dark` or `light` instead. |
| 42 | +
|
| 43 | +```ts |
25 | 44 | @import '@spectrum-web-components/styles/all-medium-dark.css'; |
26 | 45 | ``` |
27 | 46 |
|
28 | 47 | This file brings together the global variables and font settings with the "Dark" color set and "Medium" scale system specification. |
29 | 48 |
|
30 | | -``` |
| 49 | +```ts |
31 | 50 | @import '@spectrum-web-components/styles/all-medium-light.css'; |
32 | 51 | ``` |
33 | 52 |
|
34 | 53 | This file brings together the global variables and font settings with the "Light" color set and "Medium" scale system specification. |
35 | 54 |
|
36 | | -``` |
37 | | -@import '@spectrum-web-components/styles/all-medium-lightest.css'; |
38 | | -``` |
| 55 | +Other available combinations: `all-large-dark.css`, `all-large-light.css`, and the deprecated `all-medium-darkest.css`, `all-medium-lightest.css`, `all-large-darkest.css`, `all-large-lightest.css`. |
39 | 56 |
|
40 | | -This file brings together the global variables and font settings with the "Lightest" color set and "Medium" scale system specification. |
| 57 | +## Manual theme composition (Express and Spectrum 2) |
41 | 58 |
|
42 | | -``` |
43 | | -@import '@spectrum-web-components/styles/all-large-darkest.css'; |
44 | | -``` |
| 59 | +If you're not using `<sp-theme>`, you can manually compose a complete theme for Express or Spectrum 2 (equivalent to the `all-*` convenience packages for Spectrum Legacy) by importing four files: core global styles, typography, a color option, and a scale. |
45 | 60 |
|
46 | | -This file brings together the global variables and font settings with the "Darkest" color set and "Large" scale system specification. |
| 61 | +**Express example (large, dark):** |
47 | 62 |
|
48 | | -``` |
49 | | -@import '@spectrum-web-components/styles/all-large-dark.css'; |
| 63 | +```css |
| 64 | +@import '@spectrum-web-components/styles/express/core-global.css'; |
| 65 | +@import '@spectrum-web-components/styles/typography.css'; |
| 66 | +@import '@spectrum-web-components/styles/express/theme-dark.css'; |
| 67 | +@import '@spectrum-web-components/styles/express/scale-large.css'; |
50 | 68 | ``` |
51 | 69 |
|
52 | | -This file brings together the global variables and font settings with the "Dark" color set and "Large" scale system specification. |
| 70 | +**Spectrum 2 example (medium, light):** |
53 | 71 |
|
54 | | -``` |
55 | | -@import '@spectrum-web-components/styles/all-large-light.css'; |
| 72 | +```css |
| 73 | +@import '@spectrum-web-components/styles/spectrum-two/core-global.css'; |
| 74 | +@import '@spectrum-web-components/styles/typography.css'; |
| 75 | +@import '@spectrum-web-components/styles/spectrum-two/theme-light.css'; |
| 76 | +@import '@spectrum-web-components/styles/spectrum-two/scale-medium.css'; |
56 | 77 | ``` |
57 | 78 |
|
58 | | -This file brings together the global variables and font settings with the "Light" color set and "Large" scale system specification. |
| 79 | +> **Note:** For most use cases, we recommend using `<sp-theme>` instead of manually managing these imports. The theme element handles composition and switching automatically. |
59 | 80 |
|
60 | | -``` |
61 | | -@import '@spectrum-web-components/styles/all-large-lightest.css'; |
62 | | -``` |
| 81 | +## Individual theme and scale files |
63 | 82 |
|
64 | | -This file brings together the global variables and font settings with the "Lightest" color set and "Large" scale system specification. |
| 83 | +For more control over bundle size or to manually compose themes, you can import color and scale files individually. These provide only the CSS custom properties specific to color or scale, without the combined overhead of the `all-*` packages. |
65 | 84 |
|
66 | | -## Color sets |
| 85 | +### Color |
67 | 86 |
|
68 | | -### Darkest |
| 87 | +Import a single color option to set color values: |
69 | 88 |
|
70 | | -``` |
71 | | -@import '@spectrum-web-components/styles/theme-darkest.css'; |
| 89 | +```css |
| 90 | +/* Spectrum Legacy */ |
| 91 | +@import '@spectrum-web-components/styles/theme-light.css'; |
| 92 | + |
| 93 | +/* Express */ |
| 94 | +@import '@spectrum-web-components/styles/express/theme-dark.css'; |
| 95 | + |
| 96 | +/* Spectrum 2 */ |
| 97 | +@import '@spectrum-web-components/styles/spectrum-two/theme-light.css'; |
72 | 98 | ``` |
73 | 99 |
|
74 | | -This file provides only the variables needed to power a color palette featuring colors found in the "Darkest" theme. |
| 100 | +**Available color options:** |
75 | 101 |
|
76 | | -### Dark |
| 102 | +| System | Available colors | |
| 103 | +| ------------------- | -------------------------------------------------------------------------------------------------------- | |
| 104 | +| **Spectrum Legacy** | `theme-dark.css`, `theme-light.css`, `theme-darkest.css` (deprecated), `theme-lightest.css` (deprecated) | |
| 105 | +| **Express** | `express/theme-dark.css`, `express/theme-light.css` | |
| 106 | +| **Spectrum 2** | `spectrum-two/theme-dark.css`, `spectrum-two/theme-light.css` | |
77 | 107 |
|
78 | | -``` |
79 | | -@import '@spectrum-web-components/styles/theme-dark.css'; |
80 | | -``` |
| 108 | +> **Note:** All color theme files automatically set the CSS `color-scheme` property (`light` or `dark`) for accessibility. This helps browsers render native form controls appropriately, adjusts scrollbar colors to match the theme, and improves compatibility with system UI elements. |
81 | 109 |
|
82 | | -This file provides only the variables needed to power a color palette featuring colors found in the "Dark" theme. |
| 110 | +### Scale |
83 | 111 |
|
84 | | -### Light |
| 112 | +Import a single scale to set sizing values: |
85 | 113 |
|
86 | | -``` |
87 | | -@import '@spectrum-web-components/styles/theme-light.css'; |
| 114 | +```css |
| 115 | +/* Spectrum Legacy */ |
| 116 | +@import '@spectrum-web-components/styles/scale-medium.css'; |
| 117 | + |
| 118 | +/* Express */ |
| 119 | +@import '@spectrum-web-components/styles/express/scale-medium.css'; |
| 120 | + |
| 121 | +/* Spectrum 2 */ |
| 122 | +@import '@spectrum-web-components/styles/spectrum-two/scale-large.css'; |
88 | 123 | ``` |
89 | 124 |
|
90 | | -This file provides only the variables needed to power a color palette featuring colors found in the "Light" theme. |
| 125 | +**Available scales:** |
91 | 126 |
|
92 | | -### Lightest |
| 127 | +| System | Available scales | |
| 128 | +| ------------------- | --------------------------------------------------------------- | |
| 129 | +| **Spectrum Legacy** | `scale-medium.css`, `scale-large.css` | |
| 130 | +| **Express** | `express/scale-medium.css`, `express/scale-large.css` | |
| 131 | +| **Spectrum 2** | `spectrum-two/scale-medium.css`, `spectrum-two/scale-large.css` | |
93 | 132 |
|
94 | | -``` |
95 | | -@import '@spectrum-web-components/styles/theme-lightest.css'; |
| 133 | +## Typography |
| 134 | + |
| 135 | +```ts |
| 136 | +@import '@spectrum-web-components/styles/typography.css'; |
96 | 137 | ``` |
97 | 138 |
|
98 | | -This file provides only the variables needed to power a color palette featuring colors found in the "Lightest" theme. |
| 139 | +This file provides the complete [Spectrum Typography system](https://opensource.adobe.com/spectrum-css/?path=/docs/components-typography--docs). The typography system is shared across all design systems (Spectrum Legacy, Express, and Spectrum 2). |
99 | 140 |
|
100 | | -## Scale |
| 141 | +**What's included:** |
101 | 142 |
|
102 | | -### Medium |
| 143 | +- **Heading** styles (`.spectrum-Heading`) - Multiple sizes from XXS to XXXL with weight variants (light, regular, heavy) and serif options |
| 144 | +- **Body** styles (`.spectrum-Body`) - Multiple sizes from XS to XXXL with serif options for body copy and longer text |
| 145 | +- **Detail** styles (`.spectrum-Detail`) - Uppercase labels and metadata text in sizes S through XL with light weight option |
| 146 | +- **Code** styles (`.spectrum-Code`) - Monospace inline code snippets in sizes XS through XL |
| 147 | +- **Language support** - Automatic font family selection for Arabic (`:lang(ar)`), Hebrew (`:lang(he)`), and CJK languages (Chinese, Japanese, Korean) |
| 148 | +- **Emphasis and strong** - Proper italic and bold styling for `<em>` and `<strong>` elements within each typography class |
| 149 | +- **High contrast mode support** - Ensures text remains readable when Windows High Contrast Mode is enabled |
103 | 150 |
|
104 | | -``` |
105 | | -@import '@spectrum-web-components/styles/scale-medium.css'; |
106 | | -``` |
| 151 | +### TypeScript/JavaScript exports for Lit components |
107 | 152 |
|
108 | | -This file provides only the variables needed to power the "Medium" scale system specification. |
| 153 | +For use in Lit-based components, you can import typography styles as JavaScript modules: |
109 | 154 |
|
110 | | -### Large |
| 155 | +```ts |
| 156 | +import typographyStyles from '@spectrum-web-components/styles/typography.js'; |
| 157 | +import bodyStyles from '@spectrum-web-components/styles/body.js'; |
| 158 | +import headingStyles from '@spectrum-web-components/styles/heading.js'; |
| 159 | +import detailStyles from '@spectrum-web-components/styles/detail.js'; |
| 160 | +import codeStyles from '@spectrum-web-components/styles/code.js'; |
111 | 161 |
|
112 | | -``` |
113 | | -@import '@spectrum-web-components/styles/scale-large.css'; |
| 162 | +// Use in your component's static styles |
| 163 | +static styles = [typographyStyles]; |
114 | 164 | ``` |
115 | 165 |
|
116 | | -This file provides only the variables needed to power the "Large" scale system specification. |
| 166 | +- **`typography.js`** - Complete typography system with all classes |
| 167 | +- **`body.js`** - Body text styles only (base + lang + body classes) |
| 168 | +- **`heading.js`** - Heading styles only (base + lang + heading classes) |
| 169 | +- **`detail.js`** - Detail/label styles only (base + lang + detail classes) |
| 170 | +- **`code.js`** - Code styles only (base + lang + code classes) |
117 | 171 |
|
118 | | -## Typography |
| 172 | +Import individual exports when you only need specific typography components to reduce bundle size. |
| 173 | + |
| 174 | +## Design tokens |
119 | 175 |
|
| 176 | +For advanced use cases where you need direct access to design token CSS custom properties, this package exposes token files: |
| 177 | + |
| 178 | +### Spectrum Legacy tokens |
| 179 | + |
| 180 | +```ts |
| 181 | +@import '@spectrum-web-components/styles/tokens/global-vars.css'; |
| 182 | +@import '@spectrum-web-components/styles/tokens/light-vars.css'; |
| 183 | +@import '@spectrum-web-components/styles/tokens/dark-vars.css'; |
| 184 | +@import '@spectrum-web-components/styles/tokens/medium-vars.css'; |
| 185 | +@import '@spectrum-web-components/styles/tokens/large-vars.css'; |
120 | 186 | ``` |
121 | | -@import '@spectrum-web-components/styles/typography.css'; |
| 187 | + |
| 188 | +### Express tokens |
| 189 | + |
| 190 | +```ts |
| 191 | +@import '@spectrum-web-components/styles/tokens/express/global-vars.css'; |
| 192 | +@import '@spectrum-web-components/styles/tokens/express/light-vars.css'; |
| 193 | +@import '@spectrum-web-components/styles/tokens/express/dark-vars.css'; |
| 194 | +@import '@spectrum-web-components/styles/tokens/express/medium-vars.css'; |
| 195 | +@import '@spectrum-web-components/styles/tokens/express/large-vars.css'; |
| 196 | +``` |
| 197 | + |
| 198 | +### Spectrum 2 tokens |
| 199 | + |
| 200 | +```ts |
| 201 | +@import '@spectrum-web-components/styles/tokens-v2/global-vars.css'; |
| 202 | +@import '@spectrum-web-components/styles/tokens-v2/light-vars.css'; |
| 203 | +@import '@spectrum-web-components/styles/tokens-v2/dark-vars.css'; |
| 204 | +@import '@spectrum-web-components/styles/tokens-v2/medium-vars.css'; |
| 205 | +@import '@spectrum-web-components/styles/tokens-v2/large-vars.css'; |
122 | 206 | ``` |
123 | 207 |
|
124 | | -This file provides a `lit-html` compliant version of the [Spectrum Typography classes](https://opensource.adobe.com/spectrum-css/?path=/docs/components-typography--docs). |
| 208 | +## Migrating to Spectrum 2 |
| 209 | + |
| 210 | +If you're migrating to Spectrum 2, see the [Spectrum 2 migration guide](../../projects/documentation/content/migrating-to-spectrum2.md) for detailed instructions. |
0 commit comments