diff --git a/resources/views/calendar.blade.php b/resources/views/calendar.blade.php index f84b9c4..47a95b2 100644 --- a/resources/views/calendar.blade.php +++ b/resources/views/calendar.blade.php @@ -4,39 +4,81 @@ @elseif($pollMillis !== null) wire:poll.{{ $pollMillis }}ms @endif + x-data="{ touchStartX: 0, touchStartY: 0 }" + x-on:touchstart="touchStartX = $event.touches[0].clientX; touchStartY = $event.touches[0].clientY" + x-on:touchend=" + const dx = $event.changedTouches[0].clientX - touchStartX; + const dy = $event.changedTouches[0].clientY - touchStartY; + if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 50) { + if (dx > 0) $wire.goToPreviousMonth(); + else $wire.goToNextMonth(); + } + " > -
+
+
+ + + + +
+ @if(!$startsAt->isSameMonth(now())) + + @endif + + +
+
+
+ + -
-
-
+
+
+
+ @foreach($monthGrid->first() as $day) + @include($dayOfWeekView, ['day' => $day]) + @endforeach +
+ @foreach($monthGrid as $week)
- @foreach($monthGrid->first() as $day) - @include($dayOfWeekView, ['day' => $day]) + @foreach($week as $day) + @include($dayView, [ + 'componentId' => $componentId, + 'day' => $day, + 'dayInMonth' => $day->isSameMonth($startsAt), + 'isToday' => $day->isToday(), + 'events' => $getEventsForDay($day, $events), + ]) @endforeach
- - @foreach($monthGrid as $week) -
- @foreach($week as $day) - @include($dayView, [ - 'componentId' => $componentId, - 'day' => $day, - 'dayInMonth' => $day->isSameMonth($startsAt), - 'isToday' => $day->isToday(), - 'events' => $getEventsForDay($day, $events), - ]) - @endforeach -
- @endforeach -
+ @endforeach
-
+
+ @include('livewire-calendar::mobile-day-detail', [ + 'day' => $selectedDay, + 'events' => $selectedDay ? $getEventsForDay($selectedDay, $events) : collect(), + ]) +
+ +
diff --git a/resources/views/day-of-week.blade.php b/resources/views/day-of-week.blade.php index f141b4e..990d68b 100644 --- a/resources/views/day-of-week.blade.php +++ b/resources/views/day-of-week.blade.php @@ -1,8 +1,7 @@ -
- -

- {{ $day->format('l') }} +

+

+ {{ substr($day->format('l'), 0, 1) }} + +

-
diff --git a/resources/views/day.blade.php b/resources/views/day.blade.php index 0a7a436..dd178af 100644 --- a/resources/views/day.blade.php +++ b/resources/views/day.blade.php @@ -1,10 +1,10 @@ -
- - {{-- Wrapper for Drag and Drop --}} -
- + class="flex-1 h-10 md:h-40 lg:h-48 border border-gray-200 -mt-px -ml-px" +> +
+ class="w-full h-full p-0.5 md:p-2 flex flex-col {{ $dayInMonth ? '' : 'opacity-30 md:opacity-100 md:bg-gray-100' }} {{ $dayInMonth ? ($isToday ? 'md:bg-yellow-100' : 'bg-white') : '' }} {{ $selectedDay && $selectedDay->isSameDay($day) ? 'bg-blue-50 md:bg-inherit' : '' }}" + > +
+ + {{ $day->format('j') }} + - {{-- Number of Day --}} -
-

+

-

+ +

- {{-- Events --}} -
+ @if($events->isNotEmpty()) +
+ @foreach($events->take(3) as $event) +
+ @endforeach + @if($events->count() > 3) + +{{ $events->count() - 3 }} + @endif + {{ $events->count() }} {{ Str::plural('event', $events->count()) }} +
+ @endif + + -
diff --git a/resources/views/mobile-day-detail.blade.php b/resources/views/mobile-day-detail.blade.php new file mode 100644 index 0000000..4c0e8f4 --- /dev/null +++ b/resources/views/mobile-day-detail.blade.php @@ -0,0 +1,42 @@ +@if($day) +
+

+ {{ $day->format('l, M j') }} +

+ + @if($events->isEmpty()) +

No events

+ @else +
+ @foreach($events as $event) +
+
+ +
+

{{ $event['title'] }}

+ + @if(($event['is_multiday'] ?? false)) +

+ Day {{ $event['day_position'] ?? 1 }} of {{ $event['total_days'] ?? 1 }} +

+ @endif + + @if(isset($event['start_time']) || isset($event['end_time'])) +

+ {{ $event['start_time'] ?? 'All day' }}@if(isset($event['end_time'])) – {{ $event['end_time'] }}@endif +

+ @endif +
+
+ @endforeach +
+ @endif +
+@else +
Tap a day to see events
+@endif diff --git a/src/LivewireCalendar.php b/src/LivewireCalendar.php index bc42118..7292305 100755 --- a/src/LivewireCalendar.php +++ b/src/LivewireCalendar.php @@ -58,12 +58,14 @@ class LivewireCalendar extends Component public $dragAndDropEnabled; public $dayClickEnabled; public $eventClickEnabled; + public $selectedDay; protected $casts = [ 'startsAt' => 'date', 'endsAt' => 'date', 'gridStartsAt' => 'date', 'gridEndsAt' => 'date', + 'selectedDay' => 'date', ]; public function mount($initialYear = null, @@ -107,6 +109,8 @@ public function mount($initialYear = null, $this->dayClickEnabled = $dayClickEnabled; $this->eventClickEnabled = $eventClickEnabled; + $this->selectedDay = Carbon::today()->startOfDay(); + $this->afterMount($extras); } @@ -157,6 +161,7 @@ public function goToCurrentMonth() { $this->startsAt = Carbon::today()->startOfMonth()->startOfDay(); $this->endsAt = $this->startsAt->clone()->endOfMonth()->startOfDay(); + $this->selectedDay = Carbon::today()->startOfDay(); $this->calculateGridStartsEnds(); } @@ -270,9 +275,14 @@ protected function enrichEventForDay(array $event, Carbon $day): array return $event; } + public function selectDay($year, $month, $day) + { + $this->selectedDay = Carbon::createFromDate($year, $month, $day)->startOfDay(); + } + public function onDayClick($year, $month, $day) { - // + $this->selectDay($year, $month, $day); } public function onEventClick($eventId)