This is a svelte + tailwind + typescript component that is meant to be a light switch.…
- User
This is a svelte + tailwind + typescript component that is meant to be a light switch.
Make the following modifications:
- Move the lightbulb chain to the right of the lightbulb with a small gap
- Ease the change from the lit up lightbulb to the unlit one.
- use svelte/animate to animate the motion of the chain
<script lang="ts"> import { onMount } from 'svelte'; import { tick } from 'svelte'; import LightbulbLight from './lightbulb_light.svelte'; import LightbulbDark from './lightbulb_dark.svelte'; let isDarkMode: boolean = false; // Initial mode let isAnimating: boolean = false; // Animation state // Check user's preferred color scheme on component mount onMount(() => { if (window.matchMedia('(prefers-color-scheme: light)').matches) { isDarkMode = true; updateTheme(); } }); // Toggle dark mode and animate chain async function toggleDarkMode() { isDarkMode = !isDarkMode; updateTheme(); await animateChain(); } // Update the theme by adding/removing the 'dark' class on the root element function updateTheme() { const root = document.documentElement; if (isDarkMode) { root.classList.add('dark'); } else { root.classList.remove('dark'); } } // Animate the chain moving down and up async function animateChain() { isAnimating = true; await tick(); // Wait for DOM update setTimeout(() => { isAnimating = false; }, 300); // Duration of the animation in milliseconds } </script> <div class="sticky top-0"> <div class="relative flex justify-center"> <!-- Chain element --> <div class="chain" class:animate-chain={isAnimating} on:click={toggleDarkMode}></div> <!-- Display the appropriate lightbulb icon --> {#if isDarkMode} <LightbulbDark /> {:else} <LightbulbLight /> {/if} </div> </div> <style global> /* Keyframes for chain animation / @keyframes chainAnimation { 0% { transform: translateY(0); } 50% { transform: translateY(50px); } 100% { transform: translateY(0); } } / Apply animation when 'animate-chain' class is added / .animate-chain { animation: chainAnimation 0.3s ease-in-out forwards; } / Style for the chain */ .chain { width: 2px; height: 100px; background-color: gray; position: absolute; top: 0; cursor: pointer; } </style> - Assistant