Style web components

How salla-* web components get their look, how to restyle them from your theme, and when to build a component bundle instead.

Read this when a salla-* web component does not match your design, or you are deciding between a web component and a component bundle.

They bring their own CSS

The salla-* web components ship their own styles, so they look right without any setup. Your Tailwind config does not need their class list. They draw with the same colour and font variables as your theme, so they follow the merchant's choice:

VariableUsed for
--color-primary, --color-primary-dark, --color-primary-lightButtons, links, focus rings and highlights
--color-primary-reverseText on top of the primary colour
--font-mainAll text

Change these and every component changes with them. See Styling.

Restyle a component

Almost every component draws into the page itself, not into a hidden shadow root, so your stylesheet reaches its parts. Each part has a class that starts with s- and the component's name, such as s-button-btn inside salla-button. Find the class in the browser's element inspector, then style it.

The starter theme turns the wishlist button on the product page into a round icon like this (shortened):

app/styles/04-components/product.scss
.s-product-card-wishlist-btn {
  @apply w-9 h-9 shrink-0 m-0;

  button,
  .s-button-btn,
  .s-button-element {
    @apply w-9 h-9 min-w-0 m-0 p-0 inline-flex items-center justify-center rounded-full border border-gray-200 bg-white;
  }
}

Nest your rules under the part you want, as here, so you change only the buttons you mean to.

The component pages list each component's properties, and many have properties for the look too, such as fill, color and size on salla-button. Try those before you write CSS.

salla-hook and the options popup of salla-multiple-bundle-product use a shadow root. Outside CSS cannot reach inside them.

Know when a component is ready

A component's tag works once its code has loaded. To run code after that, wait for it:

await window.customElements.whenDefined('salla-button');

Each component's own events are listed on its page, such as the open and close events of salla-modal.

Web components or component bundles

They sound alike but are different products:

Web componentsComponent bundles
Built bySallaYou, as a partner
ForTheme developers, inside a themeMerchants, who buy and install them
Lives inEvery theme, loaded by the engineThe store, on any theme. It stays when the merchant changes theme.
EarnsNothing on its ownIts own price in the themes marketplace
In your themeUse the tag or its React wrapperShown by the built-in bundle-component home block

Use web components for what belongs to your theme's design. Build a component bundle when the block is a product of its own that should work on every theme: see Component Bundle: get started.

Gotchas

  • A new release of the components can change their inner classes. Check your overrides after the components update.
  • Styles you write for an s- class apply on every page where that component appears. Scope them.

See also

On this page