-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme-default): support dark mode (close #29)
BREAKING CHANGE: most sass variables are migrated to css variables
- Loading branch information
Showing
23 changed files
with
428 additions
and
221 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/@vuepress/theme-default/src/client/components/ToggleDarkButton.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<button class="toggle-dark-button" @click="toggleDark"> | ||
<svg v-show="!isDark" class="icon" focusable="false" viewBox="0 0 32 32"> | ||
<path | ||
d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" | ||
fill="currentColor" | ||
/> | ||
<path | ||
d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" | ||
fill="currentColor" | ||
/> | ||
<path d="M2 15.005h5v2H2z" fill="currentColor" /> | ||
<path | ||
d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" | ||
fill="currentColor" | ||
/> | ||
<path d="M15 25.005h2v5h-2z" fill="currentColor" /> | ||
<path | ||
d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" | ||
fill="currentColor" | ||
/> | ||
<path d="M25 15.005h5v2h-5z" fill="currentColor" /> | ||
<path | ||
d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" | ||
fill="currentColor" | ||
/> | ||
<path d="M15 2.005h2v5h-2z" fill="currentColor" /> | ||
</svg> | ||
|
||
<svg v-show="isDark" class="icon" focusable="false" viewBox="0 0 32 32"> | ||
<path | ||
d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, ref, watch } from 'vue' | ||
const isDark = ref(false) | ||
const toggleDark = (): void => { | ||
isDark.value = !isDark.value | ||
} | ||
const setDarkClass = (): void => { | ||
const htmlEl = window?.document.querySelector('html') | ||
htmlEl?.classList.toggle('dark', isDark.value) | ||
} | ||
onMounted(() => { | ||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)') | ||
isDark.value = mediaQuery.matches | ||
mediaQuery.addEventListener('change', (event) => { | ||
isDark.value = event.matches | ||
}) | ||
watch(isDark, setDarkClass, { immediate: true }) | ||
}) | ||
</script> |
27 changes: 1 addition & 26 deletions
27
packages/@vuepress/theme-default/src/client/styles/_variables.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,11 @@ | ||
@import '@vuepress/plugin-palette/palette'; | ||
|
||
// base colors | ||
$accentColor: #3eaf7c !default; | ||
$textColor: #2c3e50 !default; | ||
$borderColor: #eaecef !default; | ||
$arrowBgColor: #ccc !default; | ||
$tipColor: #42b983 !default; | ||
$warningColor: #e7c000 !default; | ||
$dangerColor: #cc0000 !default; | ||
|
||
// badge component colors | ||
$badgeTipColor: $tipColor !default; | ||
$badgeWarningColor: $warningColor !default; | ||
$badgeDangerColor: $dangerColor !default; | ||
|
||
// layout | ||
$navbarHeight: 3.6rem !default; | ||
$sidebarWidth: 20rem !default; | ||
$mobileSidebarWidth: $sidebarWidth * 0.82 !default; | ||
$contentWidth: 740px !default; | ||
$homePageWidth: 960px !default; | ||
|
||
// responsive breakpoints | ||
$MQNarrow: 959px !default; | ||
$MQMobile: 719px !default; | ||
$MQMobileNarrow: 419px !default; | ||
|
||
// code blocks | ||
$codeBgColor: #282c34 !default; | ||
$highlightLineBgColor: rgba(0, 0, 0, 66%) !default; | ||
$lineNumbersColor: rgba(255, 255, 255, 0.3) !default; | ||
$lineNumbersWrapperWidth: 3.5rem !default; | ||
// code languages | ||
$codeLang: 'c' 'cpp' 'cs' 'css' 'dart' 'docker' 'fs' 'go' 'html' 'java' 'js' | ||
'json' 'kt' 'less' 'makefile' 'md' 'php' 'py' 'rb' 'rs' 'sass' 'scss' 'sh' | ||
'styl' 'ts' 'toml' 'vue' 'yml' !default; |
2 changes: 1 addition & 1 deletion
2
packages/@vuepress/theme-default/src/client/styles/_wrapper.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 8 additions & 11 deletions
19
packages/@vuepress/theme-default/src/client/styles/badge.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.