Themes and colors
The widgets can get their colors, font and light or dark mode from several places. This page explains what those places are, which one wins when they disagree, and how to give a single widget its own look.
Styling a single widget with data-theme-mode and data-theme-palette is not in production yet. Everything marked
with π on this page describes that upcoming feature. The global layers (built-in defaults, operator theme and
lookAndFeel) are available today.
The short versionβ
Think of it as layers of paint. The widgets start with a base coat, and every layer painted on top covers what is underneath, but only where it actually adds paint. If a layer only sets the main color, the font and the background from the layers below stay exactly as they were.
So the rule to remember is:
The layer painted last wins, but only for the things it sets.
The layers, from bottom to topβ
| # | Layer | Who sets it | Where |
|---|---|---|---|
| 1 | Built-in defaults | Gamanza | Inside the widgets, you can't change it |
| 2 | Operator theme | Your Gamanza Engage team | Gamanza Engage settings (widgets_theme) |
| 3 | lookAndFeel | You, the website | The configuration passed to GamanzaEngageClient.init |
| 4 | Light or dark mode π | You, per widget | data-theme-mode on the widget's div |
| 5 | Per-widget colors and theme π | You, per widget | data-theme-palette on the widget's div |
Layers 1 to 3 apply to every widget on the page. Layers 4 and 5 apply only to the widget whose div has them.
1. Built-in defaultsβ
This is what you see if nobody customizes anything: the default font, the purple main color (#8743FF), and the
standard error, warning and success colors.
2. Operator themeβ
A theme saved in the Gamanza Engage backoffice settings for your brand. If it exists, it is painted over the defaults for all widgets. You don't need to send anything from your website for it to apply.
3. lookAndFeelβ
The lookAndFeel object you send in the configuration when you initialize the widgets. It is painted over the operator
theme, so anything you put here wins over layers 1 and 2. This is the normal way to brand all the widgets at once. See
Look and feel for the
available options.
4. Light or dark mode for one widget (data-theme-mode) πβ
Add data-theme-mode="light" or data-theme-mode="dark" to a widget's div to switch only that widget to light or
dark mode.
<div
class="gamification_widget"
data-type="missions"
data-theme-mode="dark"
></div>
Choosing a mode sets the background and text colors to the standard ones for that mode:
| Mode | Main background | Card background | Text |
|---|---|---|---|
light | #FFFFFF | #FAFAFA | #495057 |
dark | #2A2A2A | #19191A | #FFFFFF |
Your main color and font from lookAndFeel are kept, because the mode doesn't touch them.
5. Colors or a full theme for one widget (data-theme-palette) πβ
Add data-theme-palette to a widget's div to give that widget its own colors. This is the top layer, so it wins over
everything else. The value is written as JSON, inside single quotes so the double quotes of the JSON don't break the
HTML.
The simplest form is a list of colors:
<div
class="gamification_widget"
data-type="tournaments"
data-theme-palette='{"mode":"dark","primary":{"main":"#14B8A6"}}'
></div>
You can also pass a bigger theme object, with keys like palette, typography or shape, using the same format as
lookAndFeel:
<div
class="gamification_widget"
data-type="reward-shop"
data-theme-palette='{"palette":{"primary":{"main":"#FF5500"}},"typography":{"fontFamily":"Georgia"}}'
></div>
Which mode wins? πβ
A widget's light or dark mode is decided by the first of these that is set:
modeinsidedata-theme-palettedata-theme-mode- The widget's own default. Only the sidebar's collapsed bar has one, and it is dark
If none of them is set, the widget uses whatever mode the global layers (1 to 3) end up with, for example the mode
in your lookAndFeel palette.
So this widget ends up light, because the JSON wins over the attribute:
<div
class="gamification_widget"
data-type="missions"
data-theme-mode="dark"
data-theme-palette='{"mode":"light"}'
></div>
A worked example πβ
Suppose you set this in your configuration:
lookAndFeel: {
typography: { fontFamily: '"Times New Roman"' },
palette: {
primary: { main: '#C10230' },
background: { default: '#FFF4E5' },
},
},
And you place these two widgets on the page:
<div class="gamification_widget" data-type="reward-shop"></div>
<div
class="gamification_widget"
data-type="missions"
data-theme-mode="dark"
></div>
This is what you get:
| Widget | Font | Main color | Background |
|---|---|---|---|
reward-shop | Times New Roman | #C10230 | #FFF4E5, from lookAndFeel |
missions | Times New Roman | #C10230 | #2A2A2A, from dark mode |
The missions widget keeps your font and your main color, but dark mode replaces the background because it is painted
on top of lookAndFeel.
Good to knowβ
- The sidebar's collapsed bar is dark by default. π Soon you'll be able to add
data-theme-modeordata-theme-paletteto the sidebar'sdivto change it. - Changes apply live. π If you change
data-theme-modeordata-theme-paletteon a widget that is already on the page, the widget updates itself. You don't need to callreloadorreloadOne. - Pop-ups follow their widget. π A dialog opened from a widget uses that widget's theme.
- Small messages don't. π The short pop-up messages (snackbars) that appear outside the widgets always use the global theme, layers 1 to 3.
- Mistakes are ignored, not fatal. π If
data-theme-modeisn'tlightordark, ordata-theme-paletteisn't valid JSON, the widget ignores that value, keeps working, and writes a warning in the browser console.
Once available, the per-widget attributes give you the same power as lookAndFeel, so the same care applies: check that icons and text
are still readable with the colors you choose, especially when mixing light and dark widgets on one page.