6 | Go to
7 |
6 | Forcing a color mode is great to implement dark mode to a website incrementally, learn more about it. 7 |
8 |
9 |
16 |
15 | Live demo 16 |
17 | 18 | - [✨ Release Notes](https://color-mode.nuxtjs.org/releases) 19 | - [📖 Documentation](https://color-mode.nuxtjs.org) 20 | - [▶️ Online playground](https://stackblitz.com/edit/nuxt-color-mode) 21 | 22 | ## Features 23 | 24 | - Nuxt 3 and Nuxt Bridge support 25 | - Add `.${color}-mode` class to `` for easy CSS theming 26 | - Force a page to a specific color mode (perfect for incremental development) 27 | - Works with client-side and universal rendering 28 | - Auto detect system [color-mode](https://drafts.csswg.org/mediaqueries-5/#descdef-media-prefers-color-mode) 29 | - Sync dark mode across tabs and windows 🔄 30 | - Supports IE9+ 👴 31 | 32 | [📖 Read more](https://color-mode.nuxtjs.org) 33 | 34 | **Note**: v3 of `@nuxtjs/color-mode` is compatible with [Nuxt 3 and Nuxt Bridge](https://v3.nuxtjs.org/). If you're looking for the previous version of this module, check out [the previous docs](https://v2.color-mode.nuxtjs.org/), or [read more about the differences](https://color-mode.nuxtjs.org/#migrating-to-v3). 35 | 36 | ## Contributing 37 | 38 | You can contribute to this module online with CodeSandBox: 39 | 40 | [](https://codesandbox.io/s/github/nuxt-community/color-mode-module/tree/master/?fontsize=14&hidenavigation=1&theme=dark) 41 | 42 | Or locally: 43 | 44 | 1. Clone this repository 45 | 2. Install dependencies using `yarn install` or `npm install` 46 | 3. Start development server using `yarn dev` or `npm run dev` 47 | 48 | ## License 49 | 50 | [MIT License](./LICENSE) 51 | 52 | Copyright (c) Nuxt Team 53 | 54 | 55 | [npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/color-mode/latest.svg 56 | [npm-version-href]: https://npmjs.com/package/@nuxtjs/color-mode 57 | 58 | [npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/color-mode.svg 59 | [npm-downloads-href]: https://npmjs.com/package/@nuxtjs/color-mode 60 | 61 | [github-actions-ci-src]: https://github.com/nuxt-community/color-mode-module/workflows/ci/badge.svg 62 | [github-actions-ci-href]: https://github.com/nuxt-community/color-mode-module/actions?query=workflow%3Aci 63 | 64 | [codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/color-mode-module.svg 65 | [codecov-href]: https://codecov.io/gh/nuxt-community/color-mode-module 66 | 67 | [license-src]: https://img.shields.io/npm/l/@nuxtjs/color-mode.svg 68 | [license-href]: https://npmjs.com/package/@nuxtjs/color-mode 69 | -------------------------------------------------------------------------------- /src/runtime/plugin.client.ts: -------------------------------------------------------------------------------- 1 | import { computed, reactive, watch } from 'vue' 2 | 3 | import type { ColorModeInstance } from './types' 4 | import { defineNuxtPlugin, isVue2, isVue3, useRouter, useHead, useState } from '#imports' 5 | import { globalName, storageKey, dataValue } from '#color-mode-options' 6 | 7 | const helper = window[globalName] as unknown as { 8 | preference: string 9 | value: string 10 | getColorScheme: () => string 11 | addColorScheme: (className: string) => void 12 | removeColorScheme: (className: string) => void 13 | } 14 | 15 | export default defineNuxtPlugin((nuxtApp) => { 16 | const colorMode = useState