Package Exports
- bootstrap-darkmode
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bootstrap-darkmode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Bootstrap Dark Mode
This project provides a stylesheet and two scripts that allow you to implement Dark Mode on your website.
It is initially loaded based on user preference, can be toggled via a switch, and is saved via localStorage.
You can view the test page with all default bootstrap components in light and dark (thanks to juzraai!).
Note that not all components are fully supported yet. Mostly the contextual color classes can cause problems.
Usage
With NPM/Yarn/PNPM
Install the npm package:
$ npm install bootstrap-darkmode
$ yarn install bootstrap-darkmode
$ pnpm install bootstrap-darkmodeInclude the stylesheet, e.g. in styles.scss:
@import "~bootstrap-darkmode/darktheme";Via unpkg.com
Put the stylesheet link in
<head>. Do not forget to add bootstrap.<head> <!-- ... --> <!-- Bootstrap CSS ... --> <!-- Dark mode CSS --> <link rel="stylesheet" href="https://unpkg.com/bootstrap-darkmode@0.6.0/dist/darktheme.css"/> <!-- ... --> </head>
Load the theme script as the first thing in
<body>.<body> <script src="https://unpkg.com/bootstrap-darkmode@0.6.0/dist/theme.js"></script> <!-- ... --->
Setup
Theme
As soon as possible after <body>, initialize the config and load the theme:
const themeConfig = new ThemeConfig();
// place customizations here
themeConfig.initTheme();Loading the theme early shortens the time until the white default background becomes dark.
Dark Switch
If you want to use the default dark switch, load the switch script and add the element using this code:
// this will write the html to the document and return the element.
const darkSwitch = writeDarkSwitch(themeConfig);Configuration
You can listen to theme changes by registering a callback with themeChangeHandlers:
config.themeChangeHandlers.push(theme => console.log(`using theme: ${theme}`));To change the way the theme is persisted, you can change the loadTheme and saveTheme functions:
themeConfig.loadTheme = () => {
// custom logic
return 'dark';
};
themeConfig.saveTheme = theme => {
// custom logic
console.log(theme);
};