Gathering detailed insights and metrics for @spectrum-web-components/theme
Gathering detailed insights and metrics for @spectrum-web-components/theme
Gathering detailed insights and metrics for @spectrum-web-components/theme
Gathering detailed insights and metrics for @spectrum-web-components/theme
@swc-react/theme
React and Next.js wrapper of the @spectrum-web-components/theme component
@spectrum-web-components/themes
An **sp-theme** sets the rendering theme for all child components. The Spectrum design system supports four color themes and two different scales. `spectrum-web-components` currently supports two of the four color themes (dark and light) one one of the sc
greenwoodspectrumtheme
A theme pack for Greenwood using Adobe Spectrum CSS and Web Components
npm install @spectrum-web-components/theme
Typescript
Module System
Node Version
NPM Version
TypeScript (66.41%)
CSS (31.37%)
JavaScript (2.07%)
HTML (0.08%)
Handlebars (0.06%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
1,405 Stars
4,923 Commits
229 Forks
46 Watchers
249 Branches
342 Contributors
Updated on Jul 17, 2025
Latest Version
1.7.0
Package Id
@spectrum-web-components/theme@1.7.0
Unpacked Size
8.70 MB
Size
954.24 kB
File Count
438
NPM Version
10.8.1
Node Version
20.16.0
Published on
Jun 11, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
sp-theme
applies a Spectrum theme by using CSS custom properties to set default sizes & colors for all of the components in its scope. The Spectrum design system provides four color themes (lightest
, light
, dark
, and darkest
) and two different scales (medium
and large
) to support desktop & mobile UI.
yarn add @spectrum-web-components/theme
import '@spectrum-web-components/theme/sp-theme.js';
import '@spectrum-web-components/theme/src/themes.js';
The above import statements do two things: the first will get you started using the <sp-theme>
wrapper element, and the second includes all four (4) color options (lightest
, light
, dark
, and darkest
) and both (2) scale options (medium
and large
) for the Spectrum Classic theme. Having all of these options available together is the easiest way to get a handle on the theming possibilities offered by the package and empowers you to prototype and test various deliveries of your application. However, reserving the download and parse time for all of the variants may not be required for all applications. See the "Advanced usage" section below for instructions on tuning the performance of an application that leverages this package.
Below are more ways to import the different scale and color options individually, in case you didn't want to import all of them as we did above. You'll use these statements in combination with the side effectful registration import statement import '@spectrum-web-components/theme/sp-theme.js'
.
The various Classic themes can be imported en masse, as in the example above:
import '@spectrum-web-components/theme/src/themes.js';
The various Spectrum Express themes can also be imported en masse:
import '@spectrum-web-components/theme/src/express/themes.js';
Or you can import the themes and scales individually:
import '@spectrum-web-components/theme/theme-darkest.js';
import '@spectrum-web-components/theme/theme-dark.js';
import '@spectrum-web-components/theme/theme-light.js';
import '@spectrum-web-components/theme/theme-lightest.js';
import '@spectrum-web-components/theme/scale-medium.js';
import '@spectrum-web-components/theme/scale-large.js';
import '@spectrum-web-components/theme/express/theme-darkest.js';
import '@spectrum-web-components/theme/express/theme-dark.js';
import '@spectrum-web-components/theme/express/theme-light.js';
import '@spectrum-web-components/theme/express/theme-lightest.js';
import '@spectrum-web-components/theme/express/scale-medium.js';
import '@spectrum-web-components/theme/express/scale-large.js';
When looking to leverage the Theme
base class as a type and/or for extension purposes, do so via:
import { Theme } from '@spectrum-web-components/theme';
Visually, all Spectrum Web Components are an expression of the design tokens specified by Spectrum, Adobe's design system. On the web, these tokens are made available as CSS Custom Properties. Using sp-theme
as a parent element for your components ensures that those CSS Custom Properties can be leveraged by the elements within your application. This ensures consistent delivery of not only the color and scale you've specified in your particular instance, but for all the other color, scale, and content direction specifications across Spectrum.
Additionally, the sp-theme
element manages the content direction applied to the elements in its DOM scope. By default, an sp-theme
element resolves its initial content direction from the value specified by its first sp-theme
or document
ancestor; otherwise, it uses the value dir="ltr"
if a content direction isn't present in those elements. When a value for dir
is manually supplied to sp-theme
, the default value is overridden. In all cases, though, sp-theme
manages the dir
value of its SpectrumElement
descendents, unless another sp-theme
element is placed into its scope and overrides that management.
To make the above concepts a little more concrete, take a look at the table below. Try selecting another color
in the picker, and notice how that changes the values of the colors. The token names for the variables persist, but the RGB values under the hood change! Considering that sp-theme
also manages all the other theme and size options, sp-theme
reveals itself to be a pretty powerful component.
When you're ready to look into more advanced usage of the components and themes in your application, there are vanilla CSS implementations of these tokens available in the @spectrum-web-components/styles
package.
An <sp-theme>
element expects a value for each of its color
and scale
attributes to be provided on the element. While not required, you can also use the system
attribute to specify whether the theme you're using is Spectrum Classic (the default), Spectrum 2 (upcoming release) or Spectrum Express.
1<sp-theme 2 system="spectrum" 3 color="light" 4 scale="medium" 5 style="background-color: var(--spectrum-gray-100)" 6> 7 <sp-button onclick="spAlert(this, 'Themed <sp-button> clicked!')"> 8 Click me! 9 </sp-button> 10</sp-theme>
Once you've moved beyond the prototype phase of an application, it is likely that you will only use one combination of color
and scale
in your application, and even if not, you'll likely benefit from lazily loading the variants you don't leverage by default. For single combination applications, or to power a default theme, the following imports can be used to ensure only the code your application requires is loaded:
1/** 2 * Power a site using 3 * 4 * <sp-theme 5 * system="spectrum" 6 * color="darkest" 7 * scale="large" 8 * > 9 **/ 10import '@spectrum-web-components/theme/theme-darkest.js'; 11import '@spectrum-web-components/theme/scale-large.js'; 12 13import '@spectrum-web-components/theme/sp-theme.js';
1/** 2 * Power a site using 3 * 4 * <sp-theme 5 * system="express" 6 * color="light" 7 * scale="medium" 8 * > 9 **/ 10import '@spectrum-web-components/theme/express/theme-light.js'; 11import '@spectrum-web-components/theme/express/scale-medium.js'; 12 13import '@spectrum-web-components/theme/sp-theme.js';
When subsequent theme variants are needed, you can ensure those are lazily loaded by leveraging dynamic imports via something like:
1const themeElement = document.querySelector('sp-theme'); 2 3const updateTheme = async (color, scale) => { 4 Promise.all([ 5 import(`@spectrum-web-components/theme/theme-${color}.js`), 6 import(`@spectrum-web-components/theme/scale-${scale}.js`), 7 ]).then(() => { 8 themeElement.color = color; 9 themeElement.scale = scale; 10 }); 11}; 12 13updateTheme('light', 'medium');
When bundling your application, be sure to consult the documentation of your bundler for the correct way to ensure proper packaging of the programatic dependency graph that this will create.
1<style type="text/css"> 2 #example { 3 max-width: 500px; 4 padding: 3em; 5 background-color: var(--spectrum-gray-100); 6 color: var(--spectrum-gray-800); 7 } 8 9 #buttons { 10 margin-top: 2em; 11 } 12</style> 13<sp-theme system="express" color="light" scale="medium"> 14 <hzn-app-stuff></hzn-app-stuff> 15</sp-theme> 16 17<express-app> 18 <hzn-app-stuff></hzn-app-stuff> 19</express-app>
1<style type="text/css"> 2 #example { 3 max-width: 500px; 4 padding: 3em; 5 background-color: var(--spectrum-gray-100); 6 color: var(--spectrum-gray-800); 7 } 8 9 #buttons { 10 margin-top: 2em; 11 } 12</style> 13<sp-theme system="express" color="dark" scale="large"> 14 <hzn-app-stuff></hzn-app-stuff> 15</sp-theme> 16 17<express-app> 18 <hzn-app-stuff></hzn-app-stuff> 19</express-app>
The large scale of <sp-theme>
will switch to using Spectrum's larger mobile Platform Scale
1<style type="text/css"> 2 #example { 3 max-width: 500px; 4 padding: 1em; 5 background-color: var(--spectrum-gray-100); 6 color: var(--spectrum-gray-800); 7 } 8 9 #buttons { 10 margin-top: 2em; 11 } 12</style> 13<sp-theme color="darkest" scale="large"> 14 <div id="example"> 15 <div> 16 <sp-slider 17 value="5" 18 step="1" 19 min="1" 20 max="11" 21 label="Volume" 22 id="volume-slider" 23 ></sp-slider> 24 </div> 25 <div><sp-switch>Overdrive</sp-switch></div> 26 <sp-button-group id="buttons"> 27 <sp-button variant="primary">Cancel</sp-button> 28 <sp-button variant="accent">Continue</sp-button> 29 </sp-button-group> 30 </div> 31</sp-theme>
There are a few cases where it is necessary to embed one theme within another. For example, if you have an application that is using a dark theme with a left to right text direction that is previewing or editing content that will be displayed in a light theme with a right to left text direction.
1<style type="text/css"> 2 #outer { 3 max-width: 500px; 4 padding: 1em; 5 background-color: var(--spectrum-gray-100); 6 color: var(--spectrum-gray-800); 7 } 8 9 #inner { 10 margin-top: 2em; 11 padding: 1em; 12 background-color: var(--spectrum-gray-100); 13 color: var(--spectrum-gray-800); 14 } 15 16 #buttons { 17 margin-top: 2em; 18 } 19</style> 20<sp-theme color="dark" dir="ltr"> 21 <div id="outer"> 22 <div> 23 <sp-slider 24 value="5" 25 step="1" 26 min="1" 27 max="11" 28 label="Volume" 29 id="volume-slider" 30 ></sp-slider> 31 </div> 32 <div><sp-switch>Overdrive</sp-switch></div> 33 <sp-button-group id="buttons"> 34 <sp-button variant="primary">Cancel</sp-button> 35 <sp-button variant="accent">Continue</sp-button> 36 </sp-button-group> 37 <sp-theme color="light" dir="rtl"> 38 <div id="inner"> 39 <div> 40 <sp-slider 41 value="5" 42 step="1" 43 min="1" 44 max="11" 45 label="Volume" 46 id="volume-slider" 47 ></sp-slider> 48 </div> 49 <div><sp-switch>Overdrive</sp-switch></div> 50 <sp-button-group id="buttons"> 51 <sp-button variant="primary">Cancel</sp-button> 52 <sp-button variant="accent">Continue</sp-button> 53 </sp-button-group> 54 </div> 55 </sp-theme> 56 </div> 57</sp-theme>
The <sp-theme>
element provides a language context for its descendents in the DOM. Descendents can resolve this context by dispatching an sp-language-context
DOM event and supplying a callback(lang: string) => void
method in the detail
entry of the Custom Event. These callbacks will be reactively envoked when the lang
attribute on the <sp-theme>
element is updated. This way, you can control the resolved language in <sp-number-field>
, <sp-slider>
, and other elements in one centralized place.
The
Components can consume the system context by using the SystemResolutionController
. This controller encapsulates the logic for resolving the system context, allowing it to be integrated into any component in few steps.
SystemResolutionController
and the necessary types:1import { 2 SystemResolutionController, 3 systemResolverUpdatedSymbol, 4} from './SystemResolutionController.js'; 5import type { SystemVariant } from '@spectrum-web-components/theme';
Instantiate the SystemResolutionController
:
In your component class, create an instance of SystemResolutionController, passing this
as the host element.
1export class MyComponent extends LitElement { 2 private systemResolver = new SystemResolutionController(this); 3 4 // Rest of your component code... 5}
Respond to system context changes:
Override the update
lifecycle method to detect changes in the system context using the systemResolverUpdatedSymbol
.
1protected update(changes: Map<PropertyKey, unknown>): void { 2 super.update(changes); 3 if (changes.has(systemResolverUpdatedSymbol)) { 4 this.handleSystemChange(); 5 } 6}
Implement the handler for system changes:
Create a method that will be called whenever the system context changes. Use this.systemResolver.system
to access the current system variant.
1private handleSystemChange(): void { 2 const currentSystem: SystemVariant = this.systemResolver.system; 3 // Implement logic based on the current system variant. 4 // For example, update styles, states or re-render parts of the component. 5}
Use the system context in other parts of your component logic and/or template:
You can now use this.systemResolver.system
anywhere in your component to adjust behavior or rendering based on the system variant.
1render() { 2 return html` 3 <div> 4 <!-- Use the system context in your rendering logic --> 5 Current system variant: ${this.systemResolver.system} 6 </div> 7 `; 8}
No vulnerabilities found.
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
Found 24/28 approved changesets -- score normalized to 8
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
36 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More