docsify-dark-mode-toggle 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/index.css +20 -0
- package/index.js +16 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,8 @@ in the top-left corner of the page.
|
|
|
99
99
|
The script adds the class `dark-mode` to `<html>` when dark mode is active, so
|
|
100
100
|
your custom CSS can target either `html.dark-mode` or any of the variables
|
|
101
101
|
defined in `index.css`. The button exposes its state to assistive technology
|
|
102
|
-
with `aria-pressed` (`"true"` while dark mode is on)
|
|
102
|
+
with `aria-pressed` (`"true"` while dark mode is on) and a constant accessible
|
|
103
|
+
name (`label`, e.g. "Dark mode"); the tooltip says what a click will do.
|
|
103
104
|
|
|
104
105
|
## Configuration
|
|
105
106
|
|
|
@@ -114,6 +115,7 @@ All options are optional and read from `window.$docsify.darkMode`:
|
|
|
114
115
|
messages: {
|
|
115
116
|
// merged with built-in en/pl
|
|
116
117
|
de: {
|
|
118
|
+
label: "Dunkles Design",
|
|
117
119
|
enable: "Dunkles Design aktivieren",
|
|
118
120
|
disable: "Dunkles Design deaktivieren",
|
|
119
121
|
},
|
|
@@ -125,12 +127,12 @@ All options are optional and read from `window.$docsify.darkMode`:
|
|
|
125
127
|
</script>
|
|
126
128
|
```
|
|
127
129
|
|
|
128
|
-
| Option | Type
|
|
129
|
-
| ------------ |
|
|
130
|
-
| `storageKey` | `string`
|
|
131
|
-
| `messages` | `Record<string, { enable, disable }>` | English + Polish | Per-locale
|
|
132
|
-
| `sunIcon` | `string \| SVGElement`
|
|
133
|
-
| `moonIcon` | `string \| SVGElement`
|
|
130
|
+
| Option | Type | Default | Description |
|
|
131
|
+
| ------------ | -------------------------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
132
|
+
| `storageKey` | `string` | `"color-scheme"` | `localStorage` key under which the user's choice is stored (`"dark"` / `"light"`). |
|
|
133
|
+
| `messages` | `Record<string, { label, enable, disable }>` | English + Polish | Per-locale texts: `label` is the button's accessible name (falls back to `enable`), `enable`/`disable` are the tooltips. Locale is taken from `<html lang>` (falling back to `navigator.language`). |
|
|
134
|
+
| `sunIcon` | `string \| SVGElement` | built-in sun | Icon shown when dark mode is **active** (click switches to light). |
|
|
135
|
+
| `moonIcon` | `string \| SVGElement` | built-in moon | Icon shown when dark mode is **inactive** (click switches to dark). |
|
|
134
136
|
|
|
135
137
|
## Styling
|
|
136
138
|
|
package/index.css
CHANGED
|
@@ -42,6 +42,12 @@ html.dark-mode {
|
|
|
42
42
|
--dm-search-clear-bg: var(--dm-border);
|
|
43
43
|
--dm-search-clear-icon: var(--dm-text);
|
|
44
44
|
|
|
45
|
+
/* Docsify 5 themes read their colors from these properties. */
|
|
46
|
+
--color-bg: var(--dm-bg);
|
|
47
|
+
--color-text: var(--dm-text);
|
|
48
|
+
--heading-color: var(--dm-text-strong);
|
|
49
|
+
--strong-color: var(--dm-text-strong);
|
|
50
|
+
|
|
45
51
|
background: var(--dm-bg);
|
|
46
52
|
color: var(--dm-text);
|
|
47
53
|
}
|
|
@@ -72,6 +78,16 @@ html.dark-mode {
|
|
|
72
78
|
opacity: 0.7;
|
|
73
79
|
}
|
|
74
80
|
|
|
81
|
+
/* Docsify 5 styles every button[type], which would turn the icon into a pill. */
|
|
82
|
+
button.dark-mode-toggle[type],
|
|
83
|
+
button.dark-mode-toggle[type]:hover {
|
|
84
|
+
margin: 0;
|
|
85
|
+
padding: 0;
|
|
86
|
+
border: none;
|
|
87
|
+
background: transparent;
|
|
88
|
+
color: var(--dm-toggle-color);
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
.dark-mode-toggle svg {
|
|
76
92
|
display: block;
|
|
77
93
|
width: 100%;
|
|
@@ -186,6 +202,10 @@ html.dark-mode .markdown-section .tip {
|
|
|
186
202
|
border-color: var(--dm-border);
|
|
187
203
|
}
|
|
188
204
|
|
|
205
|
+
html.dark-mode .markdown-section .callout[class] {
|
|
206
|
+
--callout-bg: var(--dm-tip-bg);
|
|
207
|
+
}
|
|
208
|
+
|
|
189
209
|
html.dark-mode details > summary {
|
|
190
210
|
background-color: var(--dm-summary-bg);
|
|
191
211
|
color: var(--dm-text);
|
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* darkMode: {
|
|
10
10
|
* storageKey: "color-scheme", // localStorage key
|
|
11
11
|
* messages: { // merged with built-in en/pl
|
|
12
|
-
* pl: { enable: "...", disable: "..." },
|
|
12
|
+
* pl: { label: "...", enable: "...", disable: "..." },
|
|
13
13
|
* },
|
|
14
14
|
* sunIcon: "<svg ...>...</svg>", // SVG string (overrides default)
|
|
15
15
|
* moonIcon: "<svg ...>...</svg>",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
(function () {
|
|
20
20
|
/**
|
|
21
|
-
* @typedef {{ enable: string; disable: string }} DarkModeMessages
|
|
21
|
+
* @typedef {{ label?: string; enable: string; disable: string }} DarkModeMessages
|
|
22
22
|
* @typedef {{
|
|
23
23
|
* storageKey?: string;
|
|
24
24
|
* messages?: Record<string, Partial<DarkModeMessages>>;
|
|
@@ -31,8 +31,16 @@
|
|
|
31
31
|
storageKey: "color-scheme",
|
|
32
32
|
/** @type {Record<string, DarkModeMessages>} */
|
|
33
33
|
messages: {
|
|
34
|
-
en: {
|
|
35
|
-
|
|
34
|
+
en: {
|
|
35
|
+
label: "Dark mode",
|
|
36
|
+
enable: "Enable dark mode",
|
|
37
|
+
disable: "Disable dark mode",
|
|
38
|
+
},
|
|
39
|
+
pl: {
|
|
40
|
+
label: "Tryb nocny",
|
|
41
|
+
enable: "Włącz tryb nocny",
|
|
42
|
+
disable: "Wyłącz tryb nocny",
|
|
43
|
+
},
|
|
36
44
|
},
|
|
37
45
|
};
|
|
38
46
|
const DARK_CLASS = "dark-mode";
|
|
@@ -168,10 +176,11 @@
|
|
|
168
176
|
*/
|
|
169
177
|
function render(button, isDark) {
|
|
170
178
|
document.documentElement.classList.toggle(DARK_CLASS, isDark);
|
|
171
|
-
|
|
179
|
+
// A toggle button keeps a constant name; its state is in aria-pressed.
|
|
180
|
+
// The tooltip still says what a click will do.
|
|
172
181
|
button.replaceChildren(isDark ? sunIcon : moonIcon);
|
|
173
|
-
button.setAttribute("aria-label", label);
|
|
174
|
-
button.setAttribute("title",
|
|
182
|
+
button.setAttribute("aria-label", i18n.label || i18n.enable);
|
|
183
|
+
button.setAttribute("title", isDark ? i18n.disable : i18n.enable);
|
|
175
184
|
button.setAttribute("aria-pressed", String(isDark));
|
|
176
185
|
}
|
|
177
186
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docsify-dark-mode-toggle",
|
|
3
3
|
"description": "Dark mode toggle button for Docsify - vanilla JS, no dependencies, configurable storage key, i18n, custom SVG icons.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Piotr Kowalski",
|