]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: load theme
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 9 Apr 2021 10:14:16 +0000 (12:14 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 9 Apr 2021 10:14:16 +0000 (12:14 +0200)
Close #427

docs/.vitepress/theme/index.js

index 6c435a672d1edc4d8cce4cce8ad28198ab203a5e..423cf24f1d2bedce4f2dcd023e082fed43f8efd5 100644 (file)
@@ -2,6 +2,25 @@ import Theme from 'vitepress/theme'
 import './custom.css'
 import './code-theme.css'
 
-export default {
+const { Layout } = Theme
+
+const existingMounted = Layout.mounted || (() => {})
+
+Layout.mounted = function () {
+  existingMounted.call(this)
+
+  const storedTheme = localStorage.getItem('pinia-color-scheme')
+  const mediaQuery = window.matchMedia('(prefers-color-scheme: light)')
+
+  if (mediaQuery.matches || storedTheme === 'light') {
+    const htmlElement = document.body.parentElement
+    htmlElement.classList.add('light')
+  }
+}
+
+/** @type {import('vitepress').Theme} */
+const config = {
   ...Theme,
 }
+
+export default config