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
+56-54Lines changed: 56 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,18 +4,23 @@ A simple theme toggle for Next.js 13+ that allows switching between light and da
4
4
5
5
```html
6
6
<htmlclass="dark"style="color-scheme:dark">
7
+
<!-- ... -->
8
+
</html>
7
9
```
8
10
9
11
You can then [use different CSS selectors to create styles for dark/light themes](https://www.designcise.com/web/tutorial/how-to-create-non-flickering-dark-or-light-mode-toggle-in-next-js-using-localstorage#adding-the-ability-to-switch-themes).
10
12
11
-
## Goals
13
+
## Features
12
14
13
-
- Provide an easy way of toggling between light and dark themes
14
-
- Auto-switch theme on page load based on system settings
15
-
- Avoid flicker on page load
16
-
- Have no unnecessary bloat
17
-
- Have very minimal configuration
18
-
- Be simple and intuitive
15
+
- Easy implementation with just _two_ lines of code
16
+
- No flicker on page load
17
+
- Toggle between `light`, `dark` and `auto` modes
18
+
- Automatically choose color based on `prefers-color-scheme` when in "`auto`" mode
19
+
- Update color when `prefers-color-scheme` changes in `auto` mode
20
+
- Switch to opposite color when toggling from "`auto`"
21
+
- Data is stored in `localStorage`
22
+
- No unnecessary bloat
23
+
- Well-tested
19
24
20
25
## Installation
21
26
@@ -46,21 +51,19 @@ At a bare minimum you need to do the following:
|`color`| String | The active color (`light` or `dark`). |
194
+
|`colors`| Object | Allowed colors (`{ light: 'light', dark: 'dark', auto: 'dark'|'light' }`). `colors.auto` returns `dark` or `light` based on `prefers-color-scheme`. |
195
+
|`setTheme`| Function | Setter to set new theme. |
196
+
|`toggleTheme`| Function | Toggles the theme between `light` and `dark`. When toggling from `auto`, the opposite color to active color is automatically chosen. |
* File issues at https://github.com/designcise/next-theme-toggle/issues
241
-
* Issue patches to https://github.com/designcise/next-theme-toggle/pulls
242
+
- File issues at https://github.com/designcise/next-theme-toggle/issues
243
+
- Issue patches to https://github.com/designcise/next-theme-toggle/pulls
242
244
243
245
### Troubleshooting Common Issues
244
246
@@ -270,7 +272,7 @@ To fix this, you can add the folder where your CSS or SASS file is located. For
270
272
271
273
#### `Warning: Extra attributes from the server: class,style` in Console
272
274
273
-
This warning _only_ shows on dev build and _not_ in the production build. This happens because the injected script adds _additional_`class` and `style` attributes to the `html` element which _do not_ originally exist on the server-side generated page, leading to a mismatch in the server-side and client-side rendered page.
275
+
You can safely ignore this warning as it _only_ shows on dev build and _not_ in the production build. This happens because the injected inline script adds _additional_`class` and `style` attributes to the `html` element which _do not_ originally exist on the server-side generated page, leading to a _mismatch_ in the server-side and client-side rendered page.
-[How to Create Non-Flickering Dark/Light Mode Toggle in Next.js Using `localStorage`?](https://www.designcise.com/web/tutorial/how-to-create-non-flickering-dark-or-light-mode-toggle-in-next-js-using-localstorage)
288
+
-[How to Create Non-Flickering Dark/Light Mode Toggle in Next.js Using Cookies?](https://www.designcise.com/web/tutorial/how-to-create-non-flickering-dark-or-light-mode-toggle-in-next-js-using-cookies).
0 commit comments