Working paginator
This commit is contained in:
@@ -1,50 +1,50 @@
|
|||||||
<!-- Tailwind CSS Pagination -->
|
|
||||||
{{ $paginator := . }}
|
{{ $paginator := . }}
|
||||||
{{ if gt $paginator.TotalPages 1 }}
|
{{ $currentPage := .PageNumber }}
|
||||||
<nav class="bg-white rounded-lg shadow-lg mx-auto max-w-2xl my-8 px-4 py-3">
|
{{ $totalPages := .TotalPages }}
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<div class="flex w-0 flex-1">
|
{{ if gt $totalPages 1 }}
|
||||||
{{ if $paginator.HasPrev }}
|
<nav aria-label="Pagination" class="bg-white shadow-lg rounded-lg p-6 sm:p-8 my-4">
|
||||||
<a href="{{ $paginator.Prev.URL }}" class="relative inline-flex items-center px-3 py-2 text-sm font-medium text-gray-700 bg-white rounded-md hover:bg-gray-100 transition-colors duration-200">
|
<div class="flex items-center justify-center">
|
||||||
<svg class="w-5 h-5 mr-2" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
<div class="flex items-center space-x-2 sm:space-x-3">
|
||||||
<path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd" />
|
<!-- Previous Button -->
|
||||||
|
{{ if .HasPrev }}
|
||||||
|
<a href="{{ .Prev.URL }}" class="relative inline-flex items-center px-4 py-2 rounded-lg bg-gray-100 text-sm font-medium text-gray-700 hover:bg-gray-200 focus:z-10 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors duration-150">
|
||||||
|
<span class="sr-only">Précédent</span>
|
||||||
|
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||||
</svg>
|
</svg>
|
||||||
Précédent
|
<span class="ml-1 hidden sm:inline">Précédent</span>
|
||||||
</a>
|
</a>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<span class="relative inline-flex items-center px-3 py-2 text-sm font-medium text-gray-400 bg-gray-50 rounded-md cursor-not-allowed">
|
<span class="relative inline-flex items-center px-4 py-2 rounded-lg bg-gray-100 text-sm font-medium text-gray-400 cursor-not-allowed">
|
||||||
<svg class="w-5 h-5 mr-2" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
<path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd" />
|
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||||
</svg>
|
</svg>
|
||||||
Précédent
|
<span class="ml-1 hidden sm:inline">Précédent</span>
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Desktop pagination - hidden on mobile -->
|
<!-- First Page -->
|
||||||
<div class="hidden md:flex items-center space-x-1">
|
{{ if gt $totalPages 1 }}
|
||||||
{{ $currentPage := $paginator.PageNumber }}
|
<a href="{{ .First.URL }}" class="relative inline-flex items-center px-4 py-2 rounded-lg {{ if eq $currentPage 1 }}bg-blue-600 text-white shadow-sm{{ else }}bg-gray-100 text-gray-700 hover:bg-gray-200{{ end }} text-sm font-medium transition-colors duration-150">
|
||||||
{{ $totalPages := $paginator.TotalPages }}
|
|
||||||
|
|
||||||
<!-- Always show first page -->
|
|
||||||
<a href="{{ $paginator.First.URL }}" class="relative inline-flex items-center justify-center w-10 h-10 text-sm font-medium rounded-full transition-colors duration-200 {{ if eq $currentPage 1 }}text-white bg-blue-600{{ else }}text-gray-700 hover:bg-gray-100{{ end }}">
|
|
||||||
1
|
1
|
||||||
</a>
|
</a>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<!-- Show ellipsis if current page is > 4 -->
|
<!-- Ellipsis after first page if current page > 4 -->
|
||||||
{{ if gt $currentPage 4 }}
|
{{ if gt $currentPage 4 }}
|
||||||
<span class="relative inline-flex items-center px-2 text-sm font-medium text-gray-500">
|
<span class="relative inline-flex items-center px-3 py-2 text-sm font-medium text-gray-500">
|
||||||
...
|
...
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<!-- Show pages around current page -->
|
<!-- Pages around current page -->
|
||||||
{{ range $paginator.Pagers }}
|
{{ range .Pagers }}
|
||||||
{{ $pageNumber := .PageNumber }}
|
{{ $pageNumber := .PageNumber }}
|
||||||
{{ if and (gt $pageNumber 1) (lt $pageNumber $totalPages) (ge $pageNumber (sub $currentPage 1)) (le $pageNumber (add $currentPage 1)) }}
|
{{ if and (gt $pageNumber 1) (lt $pageNumber $totalPages) (ge $pageNumber (sub $currentPage 1)) (le $pageNumber (add $currentPage 1)) }}
|
||||||
{{ if ne $pageNumber 1 }}
|
{{ if ne $pageNumber 1 }}
|
||||||
{{ if ne $pageNumber $totalPages }}
|
{{ if ne $pageNumber $totalPages }}
|
||||||
<a href="{{ .URL }}" class="relative inline-flex items-center justify-center w-10 h-10 text-sm font-medium rounded-full transition-colors duration-200 {{ if eq $pageNumber $currentPage }}text-white bg-blue-600{{ else }}text-gray-700 hover:bg-gray-100{{ end }}">
|
<a href="{{ .URL }}" class="relative inline-flex items-center px-4 py-2 rounded-lg {{ if eq $pageNumber $currentPage }}bg-blue-600 text-white shadow-sm{{ else }}bg-gray-100 text-gray-700 hover:bg-gray-200{{ end }} text-sm font-medium transition-colors duration-150">
|
||||||
{{ $pageNumber }}
|
{{ $pageNumber }}
|
||||||
</a>
|
</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@@ -52,41 +52,34 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<!-- Show ellipsis if current page is < totalPages - 3 -->
|
<!-- Ellipsis before last page if current page < totalPages - 3 -->
|
||||||
{{ if lt $currentPage (sub $totalPages 3) }}
|
{{ if lt $currentPage (sub $totalPages 3) }}
|
||||||
<span class="relative inline-flex items-center px-2 text-sm font-medium text-gray-500">
|
<span class="relative inline-flex items-center px-3 py-2 text-sm font-medium text-gray-500">
|
||||||
...
|
...
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<!-- Always show last page -->
|
<!-- Last Page -->
|
||||||
{{ if gt $totalPages 1 }}
|
{{ if gt $totalPages 1 }}
|
||||||
<a href="{{ $paginator.Last.URL }}" class="relative inline-flex items-center justify-center w-10 h-10 text-sm font-medium rounded-full transition-colors duration-200 {{ if eq $currentPage $totalPages }}text-white bg-blue-600{{ else }}text-gray-700 hover:bg-gray-100{{ end }}">
|
<a href="{{ .Last.URL }}" class="relative inline-flex items-center px-4 py-2 rounded-lg {{ if eq $currentPage $totalPages }}bg-blue-600 text-white shadow-sm{{ else }}bg-gray-100 text-gray-700 hover:bg-gray-200{{ end }} text-sm font-medium transition-colors duration-150">
|
||||||
{{ $totalPages }}
|
{{ $totalPages }}
|
||||||
</a>
|
</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Mobile current page display -->
|
<!-- Next Button -->
|
||||||
<div class="md:hidden">
|
{{ if .HasNext }}
|
||||||
<span class="relative inline-flex items-center justify-center w-10 h-10 text-sm font-medium text-white bg-blue-600 rounded-full">
|
<a href="{{ .Next.URL }}" class="relative inline-flex items-center px-4 py-2 rounded-lg bg-gray-100 text-sm font-medium text-gray-700 hover:bg-gray-200 focus:z-10 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors duration-150">
|
||||||
{{ $paginator.PageNumber }}
|
<span class="mr-1 hidden sm:inline">Suivant</span>
|
||||||
</span>
|
<span class="sr-only">Suivant</span>
|
||||||
</div>
|
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||||
<div class="flex w-0 flex-1 justify-end">
|
|
||||||
{{ if $paginator.HasNext }}
|
|
||||||
<a href="{{ $paginator.Next.URL }}" class="relative inline-flex items-center px-3 py-2 text-sm font-medium text-gray-700 bg-white rounded-md hover:bg-gray-100 transition-colors duration-200">
|
|
||||||
Suivant
|
|
||||||
<svg class="w-5 h-5 ml-2" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
||||||
<path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<span class="relative inline-flex items-center px-3 py-2 text-sm font-medium text-gray-400 bg-gray-50 rounded-md cursor-not-allowed">
|
<span class="relative inline-flex items-center px-4 py-2 rounded-lg bg-gray-100 text-sm font-medium text-gray-400 cursor-not-allowed">
|
||||||
Suivant
|
<span class="mr-1 hidden sm:inline">Suivant</span>
|
||||||
<svg class="w-5 h-5 ml-2" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
<path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" />
|
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user