Files
thrillwiki_laravel/app/Livewire/ThemeToggleComponent.php

27 lines
564 B
PHP

<?php
namespace App\Livewire;
use Livewire\Component;
class ThemeToggleComponent extends Component
{
public bool $isDark = false;
public function mount()
{
$this->isDark = session('theme') === 'dark';
}
public function toggleTheme()
{
$this->isDark = !$this->isDark;
session(['theme' => $this->isDark ? 'dark' : 'light']);
$this->dispatch('theme-changed', theme: $this->isDark ? 'dark' : 'light');
}
public function render()
{
return view('livewire.theme-toggle-component');
}
}