Themes
tg2 components take their colours from CSS custom properties, so the theme is picked at runtime. Changing it needs no SCSS rebuild.
Include the tokens
The theme tokens come with Tangram's global styles. If your app already includes them, there's nothing to add.
// styles.scss
@use '@trademe/tangram/tangram';The themes
| Theme | Use it for | How it's set |
|---|---|---|
tg2-light | The tg2 design. The default | Nothing to set: it's the :root |
tg2-dark | The tg2 design in dark mode | data-tg-theme="tg2-dark"[theme] |
tg-light | Keeping the existing Tangram look while you migrate to tg2 components | data-tg-theme="tg-light"[theme] |
tg-dark | The existing Tangram look in dark mode | data-tg-theme="tg-dark"[theme] |
Apply a theme
There are two ways to apply a theme. Both rely on CSS custom property inheritance, so no SCSS rebuild is needed.
Option 1 — per component
Set [theme]
<button tg2Button [theme]="'tg2-dark'">Button</button>
<tg2-input-container label="Title" [theme]="'tg2-dark'">
<input tg2Input required />
</tg2-input-container>Option 2 — whole page or container
Set data-tg-theme="tg2-dark"<html>[theme]
// Toggle dark mode on the whole page
document.documentElement.setAttribute('data-tg-theme', 'tg2-dark');
// Reset to light mode
document.documentElement.removeAttribute('data-tg-theme');
// Or scope to a container element
containerElement.setAttribute('data-tg-theme', 'tg2-dark');Components
| Component | [theme] | Themes |
|---|---|---|
| Button | Yes | All four |
| Input | Yes | All four |
| Table | No: set data-tg-theme | tg2-lighttg2-dark |