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:
| Variable | Used for |
|---|---|
--color-primary, --color-primary-dark, --color-primary-light | Buttons, links, focus rings and highlights |
--color-primary-reverse | Text on top of the primary colour |
--font-main | All 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):
.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 components | Component bundles | |
|---|---|---|
| Built by | Salla | You, as a partner |
| For | Theme developers, inside a theme | Merchants, who buy and install them |
| Lives in | Every theme, loaded by the engine | The store, on any theme. It stays when the merchant changes theme. |
| Earns | Nothing on its own | Its own price in the themes marketplace |
| In your theme | Use the tag or its React wrapper | Shown 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.