mirror of
https://github.com/shaack/bootstrap-auto-dark-mode.git
synced 2025-12-06 07:42:03 +01:00
auto dark mode is now only enabled, if you set the data-bs-theme to auto
This commit is contained in:
parent
e3892b149c
commit
c7ccd49930
17
README.md
17
README.md
|
|
@ -1,12 +1,19 @@
|
|||
# bootstrap-auto-dark-mode
|
||||
|
||||
Include this script to set the bootstrap >= 5.3 dark-mode automatically based on system settings.
|
||||
This script adds the missing auto-dark mode to the new theme feature of Bootstrap 5.3.
|
||||
|
||||
The mode will switch automatically, also when the user changes the system settings while the page is shown.
|
||||
It switches the Bootstrap theme automatically between light and dark mode, depending on the system settings, if you set the `data-bs-theme` attribute of your <html> to `auto`.
|
||||
|
||||
## Usage
|
||||
|
||||
```html
|
||||
<script src="./src/bootstrap-auto-dark-mode.js"></script>
|
||||
```
|
||||
Use it by just including `bootstrap-auto-dark-mode.js` in your header and setting `data-bs-theme` to `auto`.
|
||||
|
||||
```html
|
||||
<html data-bs-theme="auto">
|
||||
<head>
|
||||
<!-- you code -->
|
||||
<script src="./src/bootstrap-auto-dark-mode.js"></script>
|
||||
</head>
|
||||
<!-- your code -->
|
||||
…
|
||||
```
|
||||
|
|
|
|||
27
index.html
27
index.html
|
|
@ -1,5 +1,5 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="en" data-bs-theme="auto">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
|
@ -12,14 +12,33 @@
|
|||
|
||||
<h1>bootstrap-auto-dark-mode</h1>
|
||||
|
||||
<p>This script automatically switches the Bootstrap theme between light and dark mode, depending on the system settings.</p>
|
||||
<p>This script adds an auto-dark mode to the new theme feature of Bootstrap 5.3.</p>
|
||||
|
||||
<p>Use it by just including <code>bootstrap-auto-dark-mode.js</code> in your header.</p>
|
||||
<p>It switches the Bootstrap theme automatically between light and dark mode, depending on the system settings, if
|
||||
you set the <code>data-bs-theme</code> attribute of your <code><html></code> to <code>auto</code>.</p>
|
||||
|
||||
<p>Use it by just including <code>bootstrap-auto-dark-mode.js</code> in your header and setting <code>data-bs-theme</code> to <code></code>auto</code>.</p>
|
||||
|
||||
<code>
|
||||
<script src="./src/bootstrap-auto-dark-mode.js"></script>
|
||||
<pre>
|
||||
<html data-bs-theme="<b class="text-success">auto</b>">
|
||||
<head>
|
||||
[…]
|
||||
<b class="text-success"><script src="./src/bootstrap-auto-dark-mode.js"></script></b>
|
||||
</head>
|
||||
[…]
|
||||
</pre>
|
||||
</code>
|
||||
|
||||
<h2>Switch manually</h2>
|
||||
|
||||
<button class="btn btn-primary" onclick="document.documentElement.setAttribute('data-bs-theme', 'light')">Light
|
||||
mode
|
||||
</button>
|
||||
<button class="btn btn-primary" onclick="document.documentElement.setAttribute('data-bs-theme', 'dark')">Dark
|
||||
mode
|
||||
</button>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
|
||||
crossorigin="anonymous"></script>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "bootstrap-auto-dark-mode",
|
||||
"version": "1.0.1",
|
||||
"description": "Switches the bootstrap >= 5.3 dark-mode automatically based on system settings.",
|
||||
"description": "Adds the missing auto dark mode to Bootstrap >= 5.3, which switches automatically, based on system settings.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
|
|
|||
Loading…
Reference in a new issue