Created
February 5, 2025 17:35
-
-
Save oli-laban/7ee51cc2c1aac4b955dc5a02b7073fc4 to your computer and use it in GitHub Desktop.
Pagination component for Statamic and Tailwind 3.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@props(['paginate']) | |
@if(!empty($paginate) && $paginate['total_pages'] > 1) | |
@php | |
$hasSlider = count($paginate['links']['segments']['slider']) > 0; | |
$hasLast = count($paginate['links']['segments']['last']) > 0; | |
@endphp | |
<nav class="isolate inline-flex -space-x-px rounded-md shadow-xs" aria-label="Pagination"> | |
@if($paginate['prev_page']) | |
<a | |
href="{{ $paginate['prev_page'] }}" | |
class="relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0" | |
> | |
<span class="sr-only">Previous</span> | |
<svg class="size-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon"> | |
<path fill-rule="evenodd" d="M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd" /> | |
</svg> | |
</a> | |
@else | |
<span class="relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300"> | |
<svg class="size-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon"> | |
<path fill-rule="evenodd" d="M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd" /> | |
</svg> | |
</span> | |
@endif | |
@foreach(Arr::get($paginate, 'links.segments.first', []) as $segment) | |
<x-pagination.segment :url="$segment['url']" :page="$segment['page']" :current="$paginate['current_page']" /> | |
@endforeach | |
@if($hasSlider) | |
<x-pagination.slider /> | |
@endif | |
@foreach(Arr::get($paginate, 'links.segments.slider', []) as $segment) | |
<x-pagination.segment :url="$segment['url']" :page="$segment['page']" :current="$paginate['current_page']" /> | |
@endforeach | |
@if($hasSlider || $hasLast) | |
<x-pagination.slider /> | |
@endif | |
@foreach(Arr::get($paginate, 'links.segments.last', []) as $segment) | |
<x-pagination.segment :url="$segment['url']" :page="$segment['page']" :current="$paginate['current_page']" /> | |
@endforeach | |
@if($paginate['next_page']) | |
<a | |
href="{{ $paginate['next_page'] }}" | |
class="relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0" | |
> | |
<span class="sr-only">Next</span> | |
<svg class="size-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon"> | |
<path fill-rule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd" /> | |
</svg> | |
</a> | |
@else | |
<span class="relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300"> | |
<svg class="size-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon"> | |
<path fill-rule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd" /> | |
</svg> | |
</span> | |
@endif | |
</nav> | |
@endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@props(['url', 'page', 'current']) | |
@if($page === $current) | |
<a | |
href="{{ $url }}" | |
aria-current="page" | |
class="relative z-10 inline-flex items-center bg-indigo-600 px-4 py-2 text-sm font-semibold text-white focus:z-20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" | |
> | |
{{ $page }} | |
</a> | |
@else | |
<a | |
href="{{ $url }}" | |
class="relative inline-flex items-center px-4 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0" | |
> | |
{{ $page }} | |
</a> | |
@endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="relative inline-flex items-center px-4 py-2 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300">…</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment