3.
namespace App\Http\Livewire;
4.
use Livewire\Component;
7.
class Calendar extends Component
11.
public function mount($date = null)
13.
$this->date = Carbon::today();
15.
$this->date = Carbon::parse($date);
19.
public function render()
21.
return view('livewire.calendar');
23.
public function previousMonth()
25.
$this->date = $this->date->subMonth();
27.
public function nextMonth()
29.
$this->date = $this->date->addMonth();
2.
<div class="px-2 py-1 flex w-full">
3.
<div class="w-4/6 font-bold">
4.
{{ $date->format('F Y') }}
7.
<div wire:click.prefetch="previousMonth()" class="w-1/6 text-right hover:text-gray-900 cursor-pointer" >
8.
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 float-right">
9.
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" />
13.
<div wire:click.prefetch="nextMonth()" class="w-1/6 text-right hover:text-gray-900 cursor-pointer" >
14.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 float-right">
15.
<path fill-rule="evenodd" d="M16.28 11.47a.75.75 0 010 1.06l-7.5 7.5a.75.75 0 01-1.06-1.06L14.69 12 7.72 5.03a.75.75 0 011.06-1.06l7.5 7.5z" clip-rule="evenodd" />
20.
<div class="flex flex-wrap text-xs text-center transition" wire:loading.class="opacity-20">
22.
<div class="flex w-full py-2">
23.
<div style="width: 14.28%">Su</div>
24.
<div style="width: 14.28%">Mo</div>
25.
<div style="width: 14.28%">Tu</div>
26.
<div style="width: 14.28%">We</div>
27.
<div style="width: 14.28%">Th</div>
28.
<div style="width: 14.28%">Fr</div>
29.
<div style="width: 14.28%">Sa</div>
33.
$startdate = $date->clone()->startOfMonth()->startOfWeek()->subDay();
34.
$enddate = $date->clone()->endOfMonth()->endOfWeek()->subDay();
35.
$loopdate = $startdate->clone();
36.
$month = $date->clone();
39.
@while ($loopdate < $enddate)
40.
<div style="width: 14.28%"
41.
class="h-10 hover:font-bold
42.
@if ($loopdate < $month->startOfMonth() || $loopdate > $month->endOfMonth())
46.
{{ $loopdate->format('j') }}
48.
@php($loopdate->addDay())