You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -590,6 +590,89 @@ startIdleTimer(10, () => {
590
590
* Lock app after idle timeout in sensitive dashboards
591
591
---
592
592
593
+
# 🌙 Dark Mode API – webdev-power-kit
594
+
595
+
This module detects whether the user prefers dark or light mode, and lets you listen to theme changes in real-time using the system’s color scheme preference.
596
+
597
+
---
598
+
599
+
## ✨ Features
600
+
601
+
* Detect if dark mode is enabled by system/browser
602
+
* Listen for real-time theme changes
603
+
* Useful for automatic theming or toggles
604
+
* Uses native `window.matchMedia`
605
+
606
+
---
607
+
608
+
## ✅ Functions
609
+
610
+
### 1. `isDarkMode()`
611
+
612
+
📌 Returns whether the user’s system prefers dark mode.
613
+
614
+
```js
615
+
import { isDarkMode } from"webdev-power-kit";
616
+
617
+
if (isDarkMode()) {
618
+
console.log("🌙 Dark mode is enabled");
619
+
} else {
620
+
console.log("☀️ Light mode is enabled");
621
+
}
622
+
```
623
+
624
+
#### 🔁 Returns:
625
+
626
+
*`true` → if user prefers dark mode
627
+
*`false` → if light mode is preferred
628
+
629
+
---
630
+
631
+
### 2. `listenDarkMode(callback)`
632
+
633
+
📌 Listen to changes in the system theme (dark ↔️ light) in real-time.
This module detects whether the user prefers dark or light mode, and lets you listen to theme changes in real-time using the system’s color scheme preference.
5
+
6
+
---
7
+
8
+
## ✨ Features
9
+
10
+
* Detect if dark mode is enabled by system/browser
11
+
* Listen for real-time theme changes
12
+
* Useful for automatic theming or toggles
13
+
* Uses native `window.matchMedia`
14
+
15
+
---
16
+
17
+
## ✅ Functions
18
+
19
+
### 1. `isDarkMode()`
20
+
21
+
📌 Returns whether the user’s system prefers dark mode.
22
+
23
+
```js
24
+
import { isDarkMode } from"webdev-power-kit";
25
+
26
+
if (isDarkMode()) {
27
+
console.log("🌙 Dark mode is enabled");
28
+
} else {
29
+
console.log("☀️ Light mode is enabled");
30
+
}
31
+
```
32
+
33
+
#### 🔁 Returns:
34
+
35
+
*`true` → if user prefers dark mode
36
+
*`false` → if light mode is preferred
37
+
38
+
---
39
+
40
+
### 2. `listenDarkMode(callback)`
41
+
42
+
📌 Listen to changes in the system theme (dark ↔️ light) in real-time.
0 commit comments