Spectrum Workshop - Tips & Troubleshooting

Useful information to use while developing your add-on UI's with Spectrum.

Tips

Using icons

You can import and use an icon from the Spectrum icon libraries provided in the icons-workflow and icons-ui libraries.

To use these icons, first add the associated library to your project by installing them from the command line, or via the package.json, then import them into your JS. For example:

"@spectrum-web-components/icons-ui": "1.7.0",
"@spectrum-web-components/icons-workflow": "1.7.0",

Then import and use them; for instance:

import "@spectrum-web-components/icons-workflow/icons/sp-icon-play-circle.js;";
import "@spectrum-web-components/icons-ui/icons/sp-icon-arrow75.js";
<sp-icon-play-circle size="s"></sp-icon-play-circle>
<sp-icon-arrow75 size="m"></sp-icon-arrow75>

NOTE: Icons adhere to the Spectrum Design t-shirt sizing, with a default of size="m" (for medium).

You can also use the [sp-icon] package and specify an image directly via the src attribute, either with the image reference, or a data URL. Both are shown below for an example:

<sp-icon src="icon-144x144.png" />

<sp-icon
  size="l"
  label="Previous"
  src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii0yOTU3Ljk5NSAtNTUzMC4wMzIgNiAxMCI+PGRlZnM+PHN0eWxlPi5he2ZpbGw6bm9uZTtzdHJva2U6IzE0NzNlNjtzdHJva2UtbGluZWNhcDpyb3VuZDtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6MTA7c3Ryb2tlLXdpZHRoOjJweDt9PC9zdHlsZT48L2RlZnM+PHBhdGggY2xhc3M9ImEiIGQ9Ik0yNTEuMywzMzNsNC00LTQtNCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTI3MDEuNjk1IC01MTk2LjAzMikgcm90YXRlKDE4MCkiLz48L3N2Zz4="
/>

You can also supply an svg to the <sp-icon> component, as shown below:

<sp-icon>
  <svg
    xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 22 22"
    role="img"
    fill="currentColor"
    height="18"
    width="18"
    aria-hidden="true"
  >
    <path
      d="M19.75,10.04h-15l5.97-5.97a.483.483,0,0,0,0-.7l-.35-.36a.513.513,0,0,0-.71,0L2.24,10.44a.513.513,0,0,0,0,.71l7.39,7.84a.513.513,0,0,0,.71,0l.35-.35a.513.513,0,0,0,0-.71L4.76,11.5H19.75a.25.25,0,0,0,.25-.25v-.96A.25.25,0,0,0,19.75,10.04Z"
    ></path>
  </svg>
</sp-icon>
data-slots=text
data-variant=warning
Using an iconset reference from one of the icons-workflow or icons-ui packages in the name on an sp-icon should no longer be used (ie: <sp-icon name="ui:Arrow100"></sp-icon>), since it's deprecated. Use the specific named import mentioned in the first bullet above, instead.

Spectrum sizing

In Spectrum, there are two main sizing concepts to understand:

Fonts

There are a set of Adobe Clean fonts automatically injected by the Add-on UI SDK for use in your add-ons. You can see which are available by checking the documentation. You can also see them while running an add-on via the browser developer tools, as shown in the following:

Injected fonts screenshot

Debugging

Styling with Spectrum CSS

Use Spectrum CSS variables for padding, gaps between controls, and general layout. In addition, since Spectrum Web Components do not include any specific components for typography, you can also use variables to style the typography.

Some benefits to using Spectrum CSS variables to style your components over absolute values:

Layout and typography styling

Component modifier variables

Components have a set of variables defined to use for modifying properties specific to that particular component. They are prefixed with --mod-*, and should be used when you want to customize the styling of a specific component.

These variables are particularly useful in cases where you want to use a component in multiple places with different styles. By using custom variables, you can easily adjust the styling of a component in one place, and have those changes apply to all instances of the component throughout your application.

In the sample app, you used custom modifiers for a few of the components, including to modify the Slider font size, some Swatch border properties and to adjust the Switch component, for reference.

A list of the prefixed custom properties for each UI component can be found in the Spectrum CSS repo's mods.md file for each component. For instance the swatch component modifiers are listed here, and the slider component modifiers here.

An example of their usage to modify the Slider is provided below for a reminder of what they look like:

.color-well {
  cursor: pointer;
  --mod-swatch-border-thickness: var(--spectrum-divider-thickness-small);
  --mod-swatch-border-color: var(--spectrum-global-color-gray-200);
}

Troubleshooting

Known issues

FAQ & Troubleshooting

This section provides answers to common questions and helps troubleshoot errors you may encounter while following this tutorial.

Q: What's the difference between --spectrum-global-dimension-static-size and --spectrum-global-static-size variables?

A: Use --spectrum-global-dimension-static-size for layout dimensions like width, height, padding, margin, and spacing. Use --spectrum-global-static-size for content-related styles like font-size, line-height, and border-radius. The dimension variables are for consistent layout, while static-size variables are for content that may vary based on context.

Q: How do I find available Spectrum CSS variables?

A: Check the /node_modules/@spectrum-web-components/styles/express/spectrum-core-global.css file in your project for available global variables. For component-specific modifiers, look at the Spectrum CSS repo's mods.md files for each component.

Q: Can I override Spectrum CSS variables?

A: Yes! You can override any Spectrum CSS variable by setting it to a new value in your CSS:

--spectrum-global-dimension-font-size-150: 16px;

This ensures your customizations remain consistent with the design system.

Q: What's the best way to debug Spectrum Web Component issues?

A: Use browser developer tools to:

Q: Should I use theme-specific or static color variables?

A: Use theme-specific variables (like --spectrum-global-color-purple-600) for text, icons, and component borders that should adapt to light/dark themes. Use static variables (like --spectrum-global-color-static-purple-600) when the color should remain fixed regardless of theme.

Still having issues? Message our team on discord for help.

Resources

The following list of resources can be used to learn more about using Adobe's Spectrum Design System: