-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
81 lines (67 loc) · 2.18 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<script setup lang="ts">
import ColorPicker from "./components/ColorPicker.vue";
import {onMounted, onUnmounted, ref, watchEffect} from "vue";
const useColorMode = () => {
const mediaQuery = window?.matchMedia('(prefers-color-scheme: dark)')
const isDark = ref(
typeof window !== 'undefined'
? mediaQuery.matches
: false
)
const toggle = () => isDark.value = !isDark.value
const setToLight = () => isDark.value = false
const setToDark = () => isDark.value = true
const listener = () => isDark.value = mediaQuery.matches
onMounted(() => {
watchEffect(() => {
if (isDark.value) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}
})
mediaQuery.addEventListener('change', listener)
})
onUnmounted(() => {
mediaQuery.removeEventListener('change', listener)
})
return {
isDark,
toggle,
setToLight,
setToDark
}
}
const colorMode = useColorMode()
const color = ref('#4037A9')
</script>
<template>
<div class="relative w-screen h-screen grid place-items-center bg-gray-50 dark:bg-gray-950 text-black dark:text-white">
<div class="">
<ColorPicker v-model="color" :show-eye-dropper="true" :show-palette="true"/>
<div class="flex gap-2 items-center mt-3 justify-center">
<span>Selection:</span>
<div class="inline-block size-6" :style="{backgroundColor: color}"></div>
<span>{{color}}</span>
</div>
</div>
<div class="absolute right-6 bottom-6 flex gap-2">
<button @click="colorMode.setToDark()" class="border px-2 rounded-md">dark</button>
<button @click="colorMode.setToLight()" class="border px-2 rounded-md">light</button>
</div>
</div>
</template>
<style scoped>
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
filter: drop-shadow(0 0 2em #42b883aa);
}
</style>