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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <template> ... <button aria-label="auto" aria-live="polite" class="relative sun-and-moon-box" @click="handleSetDarkMode"> <svg aria-hidden="true" class="sun-and-moon rounded-full" height="24" viewBox="0 0 24 24" width="24"> <circle class="sun text-yellow-300 shadow-sm shadow-amber-300 dark:text-gray-100" cx="12" cy="12" fill="currentColor" mask="url(#moon-mask)" r="6"/> <g class="sun-beams text-yellow-300 dark:text-gray-100" stroke="currentColor"> <line x1="12" x2="12" y1="1" y2="3"/> <line x1="12" x2="12" y1="21" y2="23"/> <line x1="4.22" x2="5.64" y1="4.22" y2="5.64"/> <line x1="18.36" x2="19.78" y1="18.36" y2="19.78"/> <line x1="1" x2="3" y1="12" y2="12"/> <line x1="21" x2="23" y1="12" y2="12"/> <line x1="4.22" x2="5.64" y1="19.78" y2="18.36"/> <line x1="18.36" x2="19.78" y1="5.64" y2="4.22"/> </g> <mask id="moon-mask" class="moon text-gray-darkest dark:text-gray-100"> <rect fill="white" height="100%" width="100%" x="0" y="0"/> <circle cx="24" cy="10" fill="black" r="6"/> </mask> </svg> </button> ... </template>
<script setup> import store from "@/store"; import {computed, inject} from "vue"; ... let darkMode = computed(() => store.state.settings.darkMode) const handleSetDarkMode = () => { console.log('handleSetDarkMode') store.dispatch('settings/toggleDarkMode', { value: !darkMode.value }) } ... </script> <style lang="scss" scoped> .sun-and-moon-box { width: 24px; height: 24px; }
.sun-and-moon { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; outline-offset: 5px;
& > svg { inline-size: 100%; block-size: 100%; stroke-linecap: round; }
& > * { transform-origin: center center;; }
& > .sun { transition: transform .5s cubic-bezier(.5, 1.25, .75, 1.25); }
& > .sun-beams { transition: transform .5s cubic-bezier(.5, 1.5, .75, 1.25), opacity .5s cubic-bezier(.25, 0, .3, 1);
& > line { color: inherit; } }
& > .moon > circle { transition-delay: .25s; transition-duration: .5s; } }
.dark .sun-and-moon { & > .sun { transform: scale(1.5); transition-timing-function: cubic-bezier(.25, 0, .3, 1); transition-duration: .25s; }
& > .sun-beams { opacity: 0; transition-duration: .15s }
& > .moon > circle { transform: translateX(-7px); transition: transform .25s cubic-bezier(0, 0, 0, 1);
@supports (cx: 1) { transform: translateX(0); cx: 17; transition: cx .25s cubic-bezier(0, 0, 0, 1); } } } </style>
|