Skip to main content

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 palette attribute, 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.

KeyColours
backgroundBehind the box. transparent shows your page
surfaceThe box and popups
surfaceInsetAmount fields, list hovers
surfaceControlSmall buttons, the search box
surfaceChipPills and tags
borderHairlines around the box, fields and pills
dividerLines between rows
textMain text
textMutedLabels and secondary text
textFaintFootnotes, placeholders, timestamps
accentThe main button, selection and focus rings. Its tints are worked out from it
accentHoverMain button, hovered. Default: from accent
accentActiveMain button, pressed. Default: from accent
onAccentText on the main button. Default: black or white, whichever reads better
upPrice up, buy
downPrice down, sell
onTradeText on an up or down fill. Default: black or white, whichever reads better
infoTips. Background and border are worked out from it
warningWarnings, likewise
dangerErrors, likewise
scrimBehind a popup. Give it some transparency

Shape, type and depth​

KeyValue
radiusThe box's corners in pixels, 0 to 32. Default: 16
radiusControlButtons' and fields' corners in pixels, 0 to 32; smaller parts scale with it. Default: 12
fontOne of inter, manrope, dm-sans, ibm-plex-sans, system. Treasures hosts these fonts, so your users' browsers fetch nothing from anyone else
shadownone 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.
  • up and down too 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.