Dark Mode
Quantum provides a built in dark theme which can be loaded and dynamically enabled in the browser. The @qtm/tokens
package contains the tokens-dark.css to use.
Usage
# with npm
npm install @qtm/tokens
# with yarn
yarn add @qtm/tokens
@import '@qtm/tokens/dist/tokens-dark.css';
The dark mode can be enabled by adding the .dark
class.
<!-- Dark mode not enabled -->
<!-- Dark mode not enabled -->
<html lang="en">
...
<body>
<app-root></app-root>
</body>
</html>
<!-- Dark mode enabled -->
<html lang="en" class="dark">
...
<body>
<app-root></app-root>
</body>
</html>
You can also set the dark mode for a specific section or a component.
<qtm-button color="primary" variant="filled" classes="dark"
>Dark button</qtm-button
>
How to bind the dark mode with the system preferences ?
On page load dark mode can be set with the user system preferences using the media caracteristic (prefers-color-scheme: dark)
.
// On page load dark mode can be set with the user system preferences
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}