1
mirror of https://github.com/jakejarvis/dark-mode.git synced 2025-09-11 09:37:23 -04:00

add onInit and onChange callback function options

This commit is contained in:
2021-08-05 07:54:47 -04:00
parent 8b40221791
commit cfa1f575e3
6 changed files with 53 additions and 38 deletions

View File

@@ -20,6 +20,8 @@ Very simple CSS dark/light mode toggler with saved preference via local storage
- **classes:** An object containing the `<body>` class names for the light and dark themes. (optional, default: `{ light: "light", dark: "dark" }`)
- **default:** The initial `<body>` class hard-coded into the HTML template. (optional, default: `"light"`)
- **storageKey:** Name of the `localStorage` key holding the user's preference. (optional, default: `"dark_mode_pref"`)
- **onInit(toggle?)** Callback function executed at the end of initialization. The toggle above is passed in if set. (optional, default: `null`)
- **onChange(theme?, toggle?)** Callback function executed when theme is switched. The new theme and the toggle above (if set) are passed in. (optional, default: `null`)
### Browser
@@ -83,8 +85,8 @@ darkMode.init({
## To-Do
- [ ] Support more than two themes
- [ ] Add callback function `onChange` (or `onToggle` etc.) passed in as an option
- [ ] Better readme docs
- [x] Add callback function `onChange` (or `onToggle` etc.) passed in as an option
## License