|
1 | 1 | @props([ |
2 | 2 | 'primaryLabel', |
3 | 3 | 'secondaryLabel', |
4 | | - 'footer' => null |
| 4 | + 'footer' => null, |
| 5 | + 'showViewAll' => false, |
| 6 | + 'modalTitle' => null, |
| 7 | + 'allItems' => [], |
| 8 | + 'modalId' => null |
5 | 9 | ]) |
6 | 10 |
|
| 11 | +@php |
| 12 | + $modalId = $modalId ?? 'modal-' . Str::random(8); |
| 13 | + $modalTitle = $modalTitle ?? $primaryLabel; |
| 14 | +@endphp |
| 15 | + |
7 | 16 | <div class="p-6 min-h-[400px] flex flex-col"> |
8 | 17 | <div class="flex items-center justify-between mb-4"> |
9 | 18 | <h3 class="text-lg font-semibold text-gray-900">{{ $primaryLabel }}</h3> |
10 | | - <span class="text-sm font-medium text-gray-500">{{ $secondaryLabel }}</span> |
| 19 | + <div class="flex items-center gap-3"> |
| 20 | + @if($showViewAll && count($allItems) > 0) |
| 21 | + <button |
| 22 | + type="button" |
| 23 | + onclick="openModal('{{ $modalId }}')" |
| 24 | + class="text-xs font-medium text-blue-600 hover:text-blue-800 transition-colors duration-150" |
| 25 | + > |
| 26 | + View All |
| 27 | + </button> |
| 28 | + @endif |
| 29 | + <span class="text-sm font-medium text-gray-500">{{ $secondaryLabel }}</span> |
| 30 | + </div> |
11 | 31 | </div> |
12 | 32 | <div class="flex-1 flex flex-col space-y-3"> |
13 | 33 | {{ $slot }} |
|
18 | 38 | </div> |
19 | 39 | @endif |
20 | 40 | </div> |
| 41 | + |
| 42 | +@if($showViewAll && count($allItems) > 0) |
| 43 | +<!-- Modal --> |
| 44 | +<div id="{{ $modalId }}" class="modal-overlay fixed inset-0 bg-black bg-opacity-50 z-50 hidden items-center justify-center p-4"> |
| 45 | + <div class="modal-content bg-white rounded-lg shadow-xl max-w-2xl w-full max-h-[80vh] overflow-hidden"> |
| 46 | + <div class="modal-header flex items-center justify-between p-6 border-b border-gray-200"> |
| 47 | + <h2 class="text-xl font-semibold text-gray-900">{{ $modalTitle }}</h2> |
| 48 | + <button |
| 49 | + type="button" |
| 50 | + onclick="closeModal('{{ $modalId }}')" |
| 51 | + class="text-gray-400 hover:text-gray-600 transition-colors duration-150" |
| 52 | + > |
| 53 | + <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 54 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path> |
| 55 | + </svg> |
| 56 | + </button> |
| 57 | + </div> |
| 58 | + <div class="modal-body p-6 overflow-y-auto max-h-[60vh]"> |
| 59 | + <div class="space-y-3"> |
| 60 | + @foreach($allItems as $item) |
| 61 | + <x-request-analytics::stats.item |
| 62 | + :label="$item['label']" |
| 63 | + :count="$item['count']" |
| 64 | + :percentage="$item['percentage']" |
| 65 | + :imgSrc="$item['imgSrc'] ?? null" |
| 66 | + /> |
| 67 | + @endforeach |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | +</div> |
| 72 | +@endif |
| 73 | + |
| 74 | +@once |
| 75 | +<script> |
| 76 | +function openModal(modalId) { |
| 77 | + const modal = document.getElementById(modalId); |
| 78 | + if (modal) { |
| 79 | + modal.classList.remove('hidden'); |
| 80 | + modal.classList.add('flex'); |
| 81 | + document.body.style.overflow = 'hidden'; |
| 82 | + } |
| 83 | +} |
| 84 | +
|
| 85 | +function closeModal(modalId) { |
| 86 | + const modal = document.getElementById(modalId); |
| 87 | + if (modal) { |
| 88 | + modal.classList.add('hidden'); |
| 89 | + modal.classList.remove('flex'); |
| 90 | + document.body.style.overflow = 'auto'; |
| 91 | + } |
| 92 | +} |
| 93 | +
|
| 94 | +// Close modal when clicking outside |
| 95 | +document.addEventListener('click', function(e) { |
| 96 | + if (e.target.classList.contains('modal-overlay')) { |
| 97 | + closeModal(e.target.id); |
| 98 | + } |
| 99 | +}); |
| 100 | +
|
| 101 | +// Close modal with Escape key |
| 102 | +document.addEventListener('keydown', function(e) { |
| 103 | + if (e.key === 'Escape') { |
| 104 | + const visibleModal = document.querySelector('.modal-overlay:not(.hidden)'); |
| 105 | + if (visibleModal) { |
| 106 | + closeModal(visibleModal.id); |
| 107 | + } |
| 108 | + } |
| 109 | +}); |
| 110 | +</script> |
| 111 | +@endonce |
0 commit comments