GitXplorerGitXplorer
c

dark-mode-switch

public
559 stars
111 forks
12 issues

Commits

List of commits on branch main.
Verified
4dc6c702f5461109a1814afddf7d3058a7f6c799

Merge pull request #191 from coliff/dependabot/github_actions/super-linter/super-linter-7

ccoliff committed a month ago
Verified
ef2752af42e3478e28342230a4cbb500084f1ed2

Update linter.yml

ccoliff committed a month ago
Verified
95d23bbfe3cf512430e00c0449f501f30d8eedb3

Bump super-linter/super-linter from 6 to 7

ddependabot[bot] committed a month ago
Verified
d6818734bf08d96619f81976d1f00d775844f91c

Merge pull request #187 from coliff/dependabot/github_actions/github/super-linter-6

ccoliff committed 3 months ago
Verified
dd09c5b12f0e1acd0a519f41938ade4c2ef35212

Update linter.yml

ccoliff committed 3 months ago
Verified
bf2154748c47002abdacbca93463d012065d5b25

Bump github/super-linter from 5 to 6

ddependabot[bot] committed 5 months ago

README

The README file for this repository.

LICENSE GitHub Super-Linter code style: prettier Best of JS GitHub Stars NPM Downloads

🌓 Dark Mode Switch

Add a dark-mode theme toggle with a Bootstrap Custom Switch.

  • Uses local storage to save preference
  • Only 383 Bytes minified and gzipped!

Quick start

Several quick start options are available:

  • Download the latest release
  • Clone the repo git clone https://github.com/coliff/dark-mode-switch.git
  • Install with npm npm install dark-mode-switch
  • Install with yarn yarn add dark-mode-switch

Usage

  1. Add your custom switch for the Dark Mode toggle followed by the dark-mode-switch.min.js script:

Bootstrap 4.x

<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" id="darkSwitch" />
  <label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
<script src="dark-mode-switch.min.js"></script>

Bootstrap 5.x

<div class="form-check form-switch">
  <input type="checkbox" class="form-check-input" id="darkSwitch" />
  <label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
<script src="dark-mode-switch.min.js"></script>
  1. Edit the dark-mode.css to suit your site - the one included here is a basic example.

How it works

Turning dark mode on will add data-theme="dark" to the body tag. You can use CSS to target the elements on the page like so:

[data-theme="dark"] {
  background-color: #111 !important;
  color: #eee;
}

Demo

Bootstrap 5 Demo page

Browser Support

Works well with all the browsers supported by Bootstrap 4 and Bootstrap 5

To Enable DarkMode in Android Webview

WebSettings.setDomStorageEnabled(true)

Credits

Created thanks to the excellent dark-theme and local storage tutorials over at codyhouse.co.