Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: to #736 #737

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions packages/ui/src/components/DarkToggle.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
import { computed, nextTick } from 'vue'
import { useDevToolsColorMode } from '../composables'
import { useDark, useToggle } from '@vueuse/core'
import { nextTick } from 'vue'

const props = withDefaults(defineProps<{
isDark?: boolean
Expand All @@ -13,19 +12,8 @@ const props = withDefaults(defineProps<{
animationDuration: 400,
})

const isDarkModel = useVModel(props, 'isDark')

const { colorMode: mode } = useDevToolsColorMode({
initialValue: isDarkModel.value ? 'dark' : 'light',
onChanged: (value) => {
isDarkModel.value = value === 'dark'
},
})

const isDark = computed({
get: () => mode.value === 'dark',
set: v => mode.value = v ? 'dark' : 'light',
})
const isDark = useDark()
const toggleDark = useToggle(isDark)

const isAppearanceTransition = !!document.startViewTransition
&& !window.matchMedia('(prefers-reduced-motion: reduce)').matches
Expand All @@ -35,7 +23,7 @@ const isAppearanceTransition = !!document.startViewTransition
*/
function toggle(event?: MouseEvent) {
if (!isAppearanceTransition || !event || !props.animation) {
isDark.value = !isDark.value
toggleDark()
return
}
const x = event.clientX
Expand All @@ -44,10 +32,12 @@ function toggle(event?: MouseEvent) {
Math.max(x, innerWidth - x),
Math.max(y, innerHeight - y),
)

const transition = document.startViewTransition(async () => {
isDark.value = !isDark.value
await nextTick()
})

transition.ready.then(() => {
const clipPath = [
`circle(0px at ${x}px ${y}px)`,
Expand All @@ -73,6 +63,6 @@ function toggle(event?: MouseEvent) {

<template>
<span class="$ui-dark-toggle-vtr">
<slot v-bind="{ mode, isDark, toggle }" />
<slot v-bind="{ isDark, toggle }" />
</span>
</template>
Loading