DocsComposantsMode toggle
Mode toggle
Switches between light and dark mode.
Alpine.jsdépend de theme-script1 fichier
<pb-ui.mode-toggle />Installation
pyblade-ui add mode-toggle- Installez les dépendances
theme-script et Alpine.js, chargé dans votre
<head>. - Copiez ce fichier dans votre projetcomponents/ui/mode_toggle.html
<button type="button" data-slot="mode-toggle" aria-label="Toggle theme" x-data="{ dark: document.documentElement.classList.contains('dark') }" x-on:click="dark = !dark; document.documentElement.classList.toggle('dark', dark); try { localStorage.setItem('theme', dark ? 'dark' : 'light') } catch (e) {}" {{ attributes.cn("inline-flex size-9 cursor-pointer items-center justify-center rounded-md border bg-background shadow-xs transition-colors hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 [&_svg]:size-4") }}> <svg x-show="!dark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg> <svg x-show="dark" x-cloak xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg> </button> - Adaptez le chemin à votre projet
Le dossier
componentsest celui déclaré danspyblade.toml.
Utilisation
La balise <pb-ui.mode-toggle> est disponible dans tous vos templates.
<pb-ui.mode-toggle />