Sentre
Searchโ€ฆ
โ˜€
Theme
Light & Dark mode.

How does it work?

The approach of light/dark theme in Sentre is pretty forward. We employ CSS Selector to realize the theme switch with pure css (or sass, less).
The current theme will be depicted by the body id. For example, the current theme is light, then <body id="light"/>. By contrast, <body id="dark">.
To use the body id as a trigger, you can follow the example below to switch the text color corresponding to the current theme.
1
// index.css
2
#light .text-color {
3
color: "black";
4
}
5
#dark .text-color {
6
color: "white";
7
}
Copied!

Theme Detector

For better development experience, the platform set up a postcss process for auto-detection and prepending the correct selector (i.e. either #light or #dark). To activate this feature, you only need to define your styles by less file and rename it to either [filename].light.less or [filename].dark.less; We also accept light.less or dark.less for short. The process will detect its extension and prepend the prefix to all styling within the file.
1
// light.less
2
โ€‹
3
// Before
4
.text-color {
5
color: "black";
6
}
7
// After
8
#light .text-color {
9
color: "black";
10
}
Copied!
1
// dark.less
2
โ€‹
3
// Before
4
.text-color {
5
color: "white";
6
}
7
// After
8
#dark .text-color {
9
color: "white";
10
}
Copied!