Spectrum Web Components
repository·main·Indexed 23 days ago
https://github.com/adobe/spectrum-web-componentsA library of reusable, accessible, and customizable web components that implement Adobe's Spectrum design system. Version 0.0.9 provides a consistent UI foundation for web applications, including components such as Accordion, Action Bar, Action Button, and Action Group.
What's inside Spectrum Web Components
- Spectrum Web Components (SWC) is a library of web components that implements Adobe's Spectrum design system. While primarily used by Adobe product teams, it is open-sourced and available for general use. The library is currently undergoing a transition from its first generation (1st-gen) to its second generation (2nd-gen).
Overview of testing types in Spectrum Web Components
mainTesting for 2nd-gen components is categorized into three main types to ensure functional correctness, accessibility, and visual consistency.
- Interaction tests: Use Storybook play functions to verify properties, slots, events, and warnings. These are defined in
*.test.tsfiles. - Accessibility tests: Use Playwright combined with aXe to verify the ARIA tree and WCAG compliance. These are defined in
*.a11y.spec.tsfiles. - Visual regression tests: Use Storybook and Chromatic to ensure correct rendering across different browsers and themes. These are defined in
test/vrt/*.vrt.tsfiles.
- Interaction tests: Use Storybook play functions to verify properties, slots, events, and warnings. These are defined in
Overview of Linting Tools
mainThe repository uses centralized linting and formatting configurations located at the root. The primary tools are:
- ESLint: Handles JavaScript and TypeScript linting using a flat config (
eslint.config.js). - Stylelint: Handles CSS linting (
stylelint.config.js), including a customswc/headerplugin. - Prettier: Handles code formatting (
.prettierrc.yaml).
Pre-commit hooks are managed via
lint-staged, which automatically runs linting and formatting on staged files during a commit.- ESLint: Handles JavaScript and TypeScript linting using a flat config (
Overview of @adobe/swc-tokens
mainThe
@adobe/swc-tokenspackage is responsible for ingesting Spectrum design token source data and converting it into usable assets for@adobe/spectrum-wccomponents.Key outputs include:
- CSS Custom Properties: A unified stylesheet for component use.
lookupToken(): An exported function used by@adobe/postcss-tokento resolve token names to computed values or composed custom properties.- Typography Stylesheet: A generated stylesheet containing typography classes.
Terminology
- Token: A named design value (e.g.,
gray-500). - Alias: A reference to another token (e.g.,
{gray-500}). - Set: A token with multiple contextual values (e.g.,
light/dark). - Resolved value: A final primitive value.
- Custom property: A CSS variable (e.g.,
var(--swc-gray-500)).
Overview of Spectrum Web Components
mainSpectrum Web Components is an implementation of Adobe's Spectrum design system. The components are built using the
LitElementbase class and follow Web Component standards, making them lightweight and framework-agnostic. They are designed to work with any web framework or even without one, as they are encapsulated at the browser level. Key features include:- Accessible by default: Built with browser specifications to support screen readers, keyboard navigation, and customized contrast.
- Lightweight: Uses
LitElementto minimize overhead. - Standards-based: Uses standard Web Component technologies to create custom elements that behave like native HTML elements.
- Framework agnostic: Can be integrated into any existing web development environment.
Overview of Spectrum Web Components 2nd Generation packages
mainThe 2nd generation of Spectrum Web Components is split into two primary packages:
@adobe/spectrum-wc-core: Provides abstract base classes that define the behavior and API for 2nd-gen components.@adobe/spectrum-wc: Contains the concrete component implementations including their associated styling.
Testing overview for 2nd gen components
mainSecond generation (2nd gen) components utilize three distinct testing methodologies:
- Interaction Tests: Implemented using Storybook play functions.
- Accessibility Tests: Implemented using Playwright.
- Visual Regression Testing: Performed through Storybook stories.
For detailed information on file structure, assertion conventions, coverage thresholds, and flaky test prevention, refer to the full Testing guide.
Use the swc-message-feedback component
mainThe<swc-message-feedback>component provides a control for users to provide feedback (positive or negative) on a message. It consists of two toggle buttons: a 'Positive response' button and a 'Negative response' button. The selected button is visually indicated by a dark filled background.Check component availability in Spectrum CSS and Web Components
mainThe Spectrum component inventory tracks the availability of design tokens, CSS implementations, and Web Component implementations for various Spectrum components.
When choosing a component, note that:
- Design tokens are available for most components (marked with ✅).
- CSS implementations can be found in the Spectrum CSS repository.
- Web Components are available in the Spectrum Web Components repository.
Some components may have CSS and design token support but lack a Web Component implementation (marked with ❌).
Use Token Intellisense for autocomplete and diagnostics
mainThe
swc-vscode-tokenextension provides autocomplete and diagnostics fortoken("...")values sourced from@adobe/swc-tokens.Features
- Autocomplete: Partial, case-insensitive completion for
token("...")values. - Typography Snippets: Typing a grouped typography token (e.g.,
type-component-m-regular) and pressingTabexpands into multiple CSS declarations (font-family, font-size, etc.). - Smart Editing: Quote balancing, automatic trimming of trailing whitespace, and the ability to resume completions after editing inside existing quotes.
- Diagnostics:
- Deprecated tokens: Shows "renamed to..." diagnostics and hover guidance.
- Deleted tokens: Provides hover guidance suggesting replacements or indicating if a value should be hardcoded to
0. - Unknown tokens: Suggests candidates, including renamed tokens.
Supported Languages
- CSS
- PostCSS
- SCSS
- JavaScript
- TypeScript
/* Example of typography snippet expansion in CSS */ font-family: token("sans-serif-font-family"); font-size: token("font-size-100"); font-weight: token("regular-font-weight"); letter-spacing: token("letter-spacing"); line-height: token("line-height-font-size-100");- Autocomplete: Partial, case-insensitive completion for
Use the `<swc-color-loupe>` component
mainThe
<swc-color-loupe>is a visual-only component used to display a color preview in a teardrop-shaped container. It is designed to assist users (primarily during touch interactions) by showing the selected color over an opacity checkerboard, preventing the user's finger from obscuring the selection.Key Characteristics
- Visual-only: It is decorative and does not have its own accessibility semantics or keyboard interaction.
- Parent-managed: The component does not manage its own visibility. A parent color component (like
<swc-color-area>,<swc-color-slider>, or<swc-color-wheel>) must control theopenstate. - Adaptive Contrast: The loupe uses a white-first adaptive border system to maintain a 3:1 non-text contrast ratio (WCAG 1.4.11) against the underlying color.
What is the swc-color-handle component?
mainThe
swc-color-handle(formerlysp-color-handle) is a non-interactive primitive used as a draggable dot on top of color selection components likesp-color-area,sp-color-slider, orsp-color-wheel.It serves to show the currently selected color (over an opacity checkerboard) and automatically displays a
swc-color-loupewhen touched or interacted with. It does not have its own public methods, events, or slots; instead, it relies on reflected properties to communicate state.