Components
Light/Dark Toggle
A sleek, animated toggle component for switching between light and dark modes in your SvelteLaunch application.
Features
- Smooth transition between light and dark icons
- Accessible design with screen reader support
- Seamless integration with Tailwind CSS and shadcn UI
- Pre-configured with Lucide icons for a modern look
Usage
Import the component in your Svelte file:
Examples
In Navigation Bar
Add the component to your app's navigation:
Floating Toggle
Position the toggle as a floating element:
Within Settings Panel
Integrate the toggle into a settings or preferences panel:
How It Works
- The component renders a button with sun and moon icons from Lucide.
- Clicking the button triggers the
toggleMode
function frommode-watcher
. - Icons animate smoothly to indicate the current mode:
- Light mode: Sun visible, moon hidden
- Dark mode: Moon visible, sun hidden
Accessibility
Includes a visually hidden "Toggle theme" text for screen reader compatibility.
Customization
To modify the component's appearance:
- Edit Tailwind classes in the component's markup.
- Adjust the
Button
component from shadcn UI in your SvelteLaunch setup.
Example of customizing button size:
API Reference
Props:
class
(optional): String to add custom CSS classes to the component
SvelteLaunch Integration
This component is pre-configured in your SvelteLaunch app:
- Located in:
src/lib/components/LightDarkToggle.svelte
- Auto-imported: Available from
$lib/components
- Theme switching: Utilizes SvelteLaunch's built-in dark mode support