|
| 1 | +<div |
| 2 | + class="theme-selector relative h-11 w-11 cursor-pointer select-none hover:text-slate-600 dark:text-[#ABB0DD] dark:hover:text-[#bcc1ef]" |
| 3 | + x-on:click="darkMode = !darkMode" |
| 4 | + x-data="{ |
| 5 | + nightToDay: [ |
| 6 | + [ |
| 7 | + '.theme-selector-moon', |
| 8 | + { |
| 9 | + opacity: [1, 0], |
| 10 | + transform: |
| 11 | + 'translate(0%, -50%) translate(12px, 0px) rotate(70deg) scale(0.6, 0.6)', |
| 12 | + }, |
| 13 | + { duration: 0.3, ease: motion.easeOut }, |
| 14 | + ], |
| 15 | +
|
| 16 | + [ |
| 17 | + '.theme-selector-mini-star', |
| 18 | + { opacity: [1, 0], scale: [1, 0] }, |
| 19 | + { duration: 0.3, ease: motion.easeOut, at: 0 }, |
| 20 | + ], |
| 21 | +
|
| 22 | + [ |
| 23 | + '.theme-selector-micro-star', |
| 24 | + { opacity: [1, 0], scale: [1, 0] }, |
| 25 | + { duration: 0.3, ease: motion.easeOut, at: 0 }, |
| 26 | + ], |
| 27 | +
|
| 28 | + [ |
| 29 | + '.theme-selector-sunball', |
| 30 | + { opacity: [0, 1], x: [-5, 0], y: [-5, 0], scale: [0, 1] }, |
| 31 | + { |
| 32 | + duration: 0.3, |
| 33 | + ease: motion.easeOut, |
| 34 | + at: 0.15, |
| 35 | + }, |
| 36 | + ], |
| 37 | +
|
| 38 | + [ |
| 39 | + '.theme-selector-sunshine', |
| 40 | + { opacity: [0, 1], scale: [0, 1], rotate: [-180, 0] }, |
| 41 | + { |
| 42 | + duration: 0.3, |
| 43 | + ease: motion.easeOut, |
| 44 | + at: 0.15, |
| 45 | + }, |
| 46 | + ], |
| 47 | + ], |
| 48 | + dayToNight: [ |
| 49 | + [ |
| 50 | + '.theme-selector-sunshine', |
| 51 | + { opacity: [1, 0], scale: [1, 0], rotate: [0, -180] }, |
| 52 | + { |
| 53 | + duration: 0.3, |
| 54 | + ease: motion.easeOut, |
| 55 | + }, |
| 56 | + ], |
| 57 | +
|
| 58 | + [ |
| 59 | + '.theme-selector-sunball', |
| 60 | + { opacity: [1, 0], x: [0, -5], y: [0, -5], scale: [1, 0] }, |
| 61 | + { |
| 62 | + duration: 0.3, |
| 63 | + ease: motion.easeOut, |
| 64 | + at: 0.15, |
| 65 | + }, |
| 66 | + ], |
| 67 | +
|
| 68 | + [ |
| 69 | + '.theme-selector-micro-star', |
| 70 | + { opacity: [0, 1], scale: [0, 1] }, |
| 71 | + { duration: 0.3, ease: motion.easeOut, at: 0 }, |
| 72 | + ], |
| 73 | +
|
| 74 | + [ |
| 75 | + '.theme-selector-mini-star', |
| 76 | + { opacity: [0, 1], scale: [0, 1] }, |
| 77 | + { duration: 0.3, ease: motion.easeOut, at: 0 }, |
| 78 | + ], |
| 79 | +
|
| 80 | + [ |
| 81 | + '.theme-selector-moon', |
| 82 | + { |
| 83 | + opacity: [0, 1], |
| 84 | + transform: 'translate(0%, -50%) translate(12px, 0px)', |
| 85 | + }, |
| 86 | + { duration: 0.3, ease: motion.easeOut, at: 0 }, |
| 87 | + ], |
| 88 | + ], |
| 89 | + setInitialState() { |
| 90 | + // Set initial state directly without animation |
| 91 | + if (! darkMode) { |
| 92 | + document.querySelector('.theme-selector-sunball').style.opacity = |
| 93 | + '0' |
| 94 | + document.querySelector('.theme-selector-sunshine').style.opacity = |
| 95 | + '0' |
| 96 | + } else { |
| 97 | + document.querySelector('.theme-selector-moon').style.opacity = '0' |
| 98 | + document.querySelector('.theme-selector-mini-star').style.opacity = |
| 99 | + '0' |
| 100 | + document.querySelector('.theme-selector-micro-star').style.opacity = |
| 101 | + '0' |
| 102 | + } |
| 103 | + }, |
| 104 | + init() { |
| 105 | + motion.animate($el, { scale: 1 }, { duration: 0.1 }) |
| 106 | +
|
| 107 | + this.setInitialState() |
| 108 | +
|
| 109 | + // Watch for dark mode changes |
| 110 | + $watch('darkMode', (value) => { |
| 111 | + if (value) { |
| 112 | + motion.animate(this.nightToDay) |
| 113 | + } else { |
| 114 | + motion.animate(this.dayToNight) |
| 115 | + } |
| 116 | + }) |
| 117 | + }, |
| 118 | + }" |
| 119 | +> |
| 120 | + {{-- Moon --}} |
| 121 | + <div |
| 122 | + class="theme-selector-moon absolute right-1/2 top-1/2 -translate-y-1/2 translate-x-1/2" |
| 123 | + > |
| 124 | + <div class="-scale-x-100 transition duration-300"> |
| 125 | + <svg |
| 126 | + xmlns="http://www.w3.org/2000/svg" |
| 127 | + width="24" |
| 128 | + height="24" |
| 129 | + viewBox="0 0 16 16" |
| 130 | + > |
| 131 | + <path |
| 132 | + fill="currentColor" |
| 133 | + d="M6 .278a.768.768 0 0 1 .08.858a7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277c.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316a.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71C0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z" |
| 134 | + /> |
| 135 | + </svg> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + {{-- Mini star --}} |
| 139 | + <div class="theme-selector-mini-star absolute left-[.6rem] top-[.6rem]"> |
| 140 | + <div class="transition duration-300"> |
| 141 | + <svg |
| 142 | + xmlns="http://www.w3.org/2000/svg" |
| 143 | + width="7" |
| 144 | + height="7" |
| 145 | + viewBox="0 0 256 256" |
| 146 | + > |
| 147 | + <path |
| 148 | + fill="currentColor" |
| 149 | + d="M240 128a15.79 15.79 0 0 1-10.5 15l-63.44 23.07L143 229.5a16 16 0 0 1-30 0L89.93 166L26.5 143a16 16 0 0 1 0-30L90 89.93l23-63.43a16 16 0 0 1 30 0L166.07 90l63.43 23a15.79 15.79 0 0 1 10.5 15Z" |
| 150 | + /> |
| 151 | + </svg> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + {{-- Micro star --}} |
| 155 | + <div class="theme-selector-micro-star absolute left-[1rem] top-[1rem]"> |
| 156 | + <div class="transition duration-300"> |
| 157 | + <svg |
| 158 | + xmlns="http://www.w3.org/2000/svg" |
| 159 | + width="5" |
| 160 | + height="5" |
| 161 | + viewBox="0 0 256 256" |
| 162 | + > |
| 163 | + <path |
| 164 | + fill="currentColor" |
| 165 | + d="M240 128a15.79 15.79 0 0 1-10.5 15l-63.44 23.07L143 229.5a16 16 0 0 1-30 0L89.93 166L26.5 143a16 16 0 0 1 0-30L90 89.93l23-63.43a16 16 0 0 1 30 0L166.07 90l63.43 23a15.79 15.79 0 0 1 10.5 15Z" |
| 166 | + /> |
| 167 | + </svg> |
| 168 | + </div> |
| 169 | + </div> |
| 170 | + {{-- Sun ball --}} |
| 171 | + <div class="absolute right-1/2 top-1/2 -translate-y-1/2 translate-x-1/2"> |
| 172 | + <div class="theme-selector-sunball"> |
| 173 | + <div |
| 174 | + class="h-4 w-4 rounded-full bg-current transition duration-300" |
| 175 | + ></div> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + {{-- sunShine --}} |
| 179 | + <div class="theme-selector-sunshine absolute inset-0 grid h-full w-full"> |
| 180 | + <div class="relative h-full w-full"> |
| 181 | + {{-- Top --}} |
| 182 | + <div |
| 183 | + class="absolute right-1/2 top-[0.5rem] h-[0.22rem] w-0.5 translate-x-1/2 rounded-full bg-current transition duration-300" |
| 184 | + ></div> |
| 185 | + {{-- Right --}} |
| 186 | + <div |
| 187 | + class="absolute right-[0.5rem] top-1/2 h-[0.22rem] w-0.5 -translate-y-1/2 rotate-[90deg] rounded-full bg-current transition duration-300" |
| 188 | + ></div> |
| 189 | + {{-- Bottom --}} |
| 190 | + <div |
| 191 | + class="absolute bottom-[0.5rem] right-1/2 h-[0.22rem] w-0.5 translate-x-1/2 rounded-full bg-current transition duration-300" |
| 192 | + ></div> |
| 193 | + {{-- Left --}} |
| 194 | + <div |
| 195 | + class="absolute left-[0.5rem] top-1/2 h-[0.22rem] w-0.5 -translate-y-1/2 rotate-[90deg] rounded-full bg-current transition duration-300" |
| 196 | + ></div> |
| 197 | + {{-- Top Right --}} |
| 198 | + <div |
| 199 | + class="absolute right-[0.75rem] top-[0.75rem] h-[0.22rem] w-0.5 rotate-[45deg] rounded-full bg-current transition duration-300" |
| 200 | + ></div> |
| 201 | + {{-- Top Left --}} |
| 202 | + <div |
| 203 | + class="absolute left-[0.75rem] top-[0.75rem] h-[0.22rem] w-0.5 rotate-[-45deg] rounded-full bg-current transition duration-300" |
| 204 | + ></div> |
| 205 | + |
| 206 | + {{-- Bottom Right --}} |
| 207 | + <div |
| 208 | + class="absolute bottom-[0.75rem] right-[0.75rem] h-[0.22rem] w-0.5 rotate-[-45deg] rounded-full bg-current transition duration-300" |
| 209 | + ></div> |
| 210 | + {{-- Bottom Left --}} |
| 211 | + <div |
| 212 | + class="absolute bottom-[0.75rem] left-[0.75rem] h-[0.22rem] w-0.5 rotate-[45deg] rounded-full bg-current transition duration-300" |
| 213 | + ></div> |
| 214 | + </div> |
| 215 | + </div> |
| 216 | +</div> |
0 commit comments