11<script setup lang="ts">
2- import { useVModel } from ' @vueuse/core'
3- import { computed , nextTick } from ' vue'
4- import { useDevToolsColorMode } from ' ../composables'
2+ import { useDark , useToggle } from ' @vueuse/core'
3+ import { nextTick } from ' vue'
54
65const props = withDefaults (defineProps <{
76 isDark? : boolean
@@ -13,19 +12,8 @@ const props = withDefaults(defineProps<{
1312 animationDuration: 400 ,
1413})
1514
16- const isDarkModel = useVModel (props , ' isDark' )
17-
18- const { colorMode : mode } = useDevToolsColorMode ({
19- initialValue: isDarkModel .value ? ' dark' : ' light' ,
20- onChanged : (value ) => {
21- isDarkModel .value = value === ' dark'
22- },
23- })
24-
25- const isDark = computed ({
26- get : () => mode .value === ' dark' ,
27- set : v => mode .value = v ? ' dark' : ' light' ,
28- })
15+ const isDark = useDark ()
16+ const toggleDark = useToggle (isDark )
2917
3018const isAppearanceTransition = !! document .startViewTransition
3119 && ! window .matchMedia (' (prefers-reduced-motion: reduce)' ).matches
@@ -35,7 +23,7 @@ const isAppearanceTransition = !!document.startViewTransition
3523 */
3624function toggle(event ? : MouseEvent ) {
3725 if (! isAppearanceTransition || ! event || ! props .animation ) {
38- isDark . value = ! isDark . value
26+ toggleDark ()
3927 return
4028 }
4129 const x = event .clientX
@@ -44,10 +32,12 @@ function toggle(event?: MouseEvent) {
4432 Math .max (x , innerWidth - x ),
4533 Math .max (y , innerHeight - y ),
4634 )
35+
4736 const transition = document .startViewTransition (async () => {
4837 isDark .value = ! isDark .value
4938 await nextTick ()
5039 })
40+
5141 transition .ready .then (() => {
5242 const clipPath = [
5343 ` circle(0px at ${x }px ${y }px) ` ,
@@ -73,6 +63,6 @@ function toggle(event?: MouseEvent) {
7363
7464<template >
7565 <span class =" $ui-dark-toggle-vtr" >
76- <slot v-bind =" { mode, isDark, toggle }" />
66+ <slot v-bind =" { isDark, toggle }" />
7767 </span >
7868</template >
0 commit comments