Customization
Match the widget to your site with two attributes: theme picks light or dark, and palette sets your colours, corners, font and shadow. Give only what you want to change; everything else keeps the Treasures design.
Theme
theme="light" or theme="dark". Left out, the widget follows the user's system setting.
Palette
The palette is an object, given in either of two ways:
- As the
paletteattribute, holding the object as JSON. - From script, with
setPalette(object).setPalette(null)takes the palette away and restores the Treasures design.
Keys at the top level apply in both themes. Keys under light or dark apply in that theme only, on top of the shared ones, which is how you give a widget that follows the user's system a colour per theme.
<treasures-swap
theme="light"
palette='{"accent":"#6d28d9","background":"transparent","radius":12,"font":"inter"}'>
</treasures-swap>
<script>
// The same from script, here with a colour per theme: shared keys first,
// then the shown theme's own.
document.querySelector('treasures-swap').setPalette({
accent: '#6d28d9',
radiusControl: 8,
light: { surface: '#ffffff', text: '#111111' },
dark: { surface: '#17151f', text: '#f4f2ff' },
});
</script>
A palette change applies at once, without reloading the widget or losing what the user typed.
Colours
Colours are #rgb, #rrggbb (with or without alpha) or rgb() / rgba(). Hover shades, tints and the text on a coloured button are worked out for you unless you give them.
| Key | Colours |
|---|---|
background | Behind the box. transparent shows your page |
surface | The box and popups |
surfaceInset | Amount fields, list hovers |
surfaceControl | Small buttons, the search box |
surfaceChip | Pills and tags |
border | Hairlines around the box, fields and pills |
divider | Lines between rows |
text | Main text |
textMuted | Labels and secondary text |
textFaint | Footnotes, placeholders, timestamps |
accent | The main button, selection and focus rings. Its tints are worked out from it |
accentHover | Main button, hovered. Default: from accent |
accentActive | Main button, pressed. Default: from accent |
onAccent | Text on the main button. Default: black or white, whichever reads better |
up | Price up, buy |
down | Price down, sell |
onTrade | Text on an up or down fill. Default: black or white, whichever reads better |
info | Tips. Background and border are worked out from it |
warning | Warnings, likewise |
danger | Errors, likewise |
scrim | Behind a popup. Give it some transparency |
Shape, type and depth
| Key | Value |
|---|---|
radius | The box's corners in pixels, 0 to 32. Default: 16 |
radiusControl | Buttons' and fields' corners in pixels, 0 to 32; smaller parts scale with it. Default: 12 |
font | One of inter, manrope, dm-sans, ibm-plex-sans, system. Treasures hosts these fonts, so your users' browsers fetch nothing from anyone else |
shadow | none for a flat box, or default |
What the palette can't change
- A value that isn't valid is ignored and named in your browser's console; the rest of the palette applies. Invalid JSON in the attribute is ignored as a whole, with a console warning, and the widget keeps its own colours.
- A colour pair too faint to read (under WCAG AA's 4.5:1 contrast) is named in the console too, but still applied: the colours are yours.
upanddowntoo alike to tell apart both keep the Treasures colours.- Some things stay whatever the palette: the "Powered by Treasures" line, every fee line, the Terms, and errors and notices, all at their full size.
Transparent backgrounds
With background: "transparent", your page shows behind the box. The element matches the iframe's colour scheme to theme so that browsers show the transparency rather than painting an opaque backdrop; set theme explicitly if your page has a fixed light or dark design.