Skip to main content
Version: 0.4.3

Configuring the theme

Considering a component without any specific configurations, by default, the theme will be configured as "default".

not_themed_example.py
import dash
import dash_json_grid as djg


app = dash.Dash("demo")
app.layout = djg.DashJsonGrid(
data=[
{"key1": 1, "key2": "str"},
{"key1": True, "key2": None},
{"key1": 3.0},
{"key1": False, "key2": None, "key3": 4.0},
{"key5": "?"},
]
)

if __name__ == "__main__":
app.run()

Specify a theme by a name

The theme can be spcified by a theme name (str). Given the above example, we only need to add one property theme="moonLight" to make the theme different.

...
app.layout = djg.DashJsonGrid(
data=[
{"key1": 1, "key2": "str"},
{"key1": True, "key2": None},
{"key1": 3.0},
{"key1": False, "key2": None, "key3": 4.0},
{"key5": "?"},
],
theme="moonLight",
)
...

The available theme names are

[
"default", "dracula", "monokai", "oceanicPark", "panda",
"gruvboxMaterial", "tokyoNight", "remedy", "atlanticNight",
"defaultLight", "defaultLight2", "slime", "spacegray",
"blueberryDark", "nord", "nightOwl", "oneMonokai", "cobaltNext",
"shadesOfPurple", "codeBlue", "softEra", "atomMaterial",
"evaDark", "moonLight", "unset", "inherit"
]

The following small demo can be used as a tool to quick overviewing each theme:

Theme:

key1key2key3key5
11strundefinedundefined
2truenullundefinedundefined
33undefinedundefinedundefined
4falsenull4undefined
5undefinedundefinedundefined?

Specify a theme by a dictionary

To customize any special styles of the themes, users can specify the following typed dictionary:

...
app.layout = djg.DashJsonGrid(
data=[
{"key1": 1, "key2": "str"},
{"key1": True, "key2": None},
{"key1": 3.0},
{"key1": False, "key2": None, "key3": 4.0},
{"key5": "?"},
],
theme=djg.ThemeConfigs(
bgColor="#f5f5f5",
booleanColor="#007acc",
borderColor="#d3d3d3",
cellBorderColor="#c0c0c0",
indexColor="#666666",
keyColor="#333333",
numberColor="#007acc",
objectColor="#333333",
searchHighlightBgColor="#cccccc",
selectHighlightBgColor="#e0e0e0",
stringColor="#2ca22c",
tableHeaderBgColor="#dddddd",
tableIconColor="#333333",
),
)
...

where the highlighted djg.ThemeConfigs(...) is a TypedDict.

Specify a theme by theme=inherit and a global stylesheet

If users prefer to provide the styles by a global CSS/SCSS stylesheet, a good approach is to let theme=inherit and specify the theme properties like this:

body .special-djg-style {
--jg-bg-color: #fff;
--jg-border-color: #a5a5a5;
--jg-cell-border-color: #ddd;
--jg-key-color: #32373b;
--jg-index-color: #00f;
--jg-number-color: #007acc;
--jg-boolean-color: #00f;
--jg-string-color: #a31515;
--jg-object-color: #00009f;
--jg-table-header-bg-color: #ddd;
--jg-table-icon-color: #333;
--jg-select-highlight-bg-color: #c1def133;
--jg-search-highlight-bg-color: #8885;
}

After that, the component can be specified like this:

from dash import html
...
app.layout = html.Div(
className="special-djg-style",
children=djg.DashJsonGrid(
data=[
{"key1": 1, "key2": "str"},
{"key1": True, "key2": None},
{"key1": 3.0},
{"key1": False, "key2": None, "key3": 4.0},
{"key5": "?"},
],
theme="inherit",
)
)
...
info

Using "inherit" | "unset" is a new feature provided by dash-json-grid since v0.3.2. The original component (react-json-grid) does not support this feature yet.