Skip to content

Instantly share code, notes, and snippets.

@mazedlx
Created November 5, 2017 12:54
Show Gist options
  • Save mazedlx/86512703b1dbcb987b2815c31e5173a3 to your computer and use it in GitHub Desktop.
Save mazedlx/86512703b1dbcb987b2815c31e5173a3 to your computer and use it in GitHub Desktop.
Tailwind CSS template for Laravel pagination
@if ($paginator->hasPages())
<div class="flex items-center">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<span class="rounded-l rounded-sm border border-brand-light px-3 py-2 cursor-not-allowed no-underline">&laquo;</span>
@else
<a
class="rounded-l rounded-sm border-t border-b border-l border-brand-light px-3 py-2 text-brand-dark hover:bg-brand-light no-underline"
href="{{ $paginator->previousPageUrl() }}"
rel="prev"
>
&laquo;
</a>
@endif
{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<span class="border-t border-b border-l border-brand-light px-3 py-2 cursor-not-allowed no-underline">{{ $element }}</span>
@endif
{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<span class="border-t border-b border-l border-brand-light px-3 py-2 bg-brand-light no-underline">{{ $page }}</span>
@else
<a class="border-t border-b border-l border-brand-light px-3 py-2 hover:bg-brand-light text-brand-dark no-underline" href="{{ $url }}">{{ $page }}</a>
@endif
@endforeach
@endif
@endforeach
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<a class="rounded-r rounded-sm border border-brand-light px-3 py-2 hover:bg-brand-light text-brand-dark no-underline" href="{{ $paginator->nextPageUrl() }}" rel="next">&raquo;</a>
@else
<span class="rounded-r rounded-sm border border-brand-light px-3 py-2 hover:bg-brand-light text-brand-dark no-underline cursor-not-allowed">&raquo;</span>
@endif
</div>
@endif
@mohamedsabil83
Copy link

@Abbaty, as you are using Laravel 8, did you try the default pagination based on Tailwindcss that comes with it?

@abbaty48
Copy link

@mohamedsab.il83 thanks you for you reply, I don't want to use tailwind in my project. but i ready have made my style using sass.

@abbaty48
Copy link

To any who doesn't want to use bootstrap or tailwindcss you can use this to customize Laravel pagination. this is a scss style.

.pagination{
margin: 5px;
.px-4 {padding-left: 1rem; padding-right: 1rem;}
.px-2 {padding-left: 0.5rem; padding-right: 0.5rem;}
.py-2 {padding-top: 0.5rem; padding-bottom: 0.5rem;}
.ml {margin-left: 3px;}
.ml-3 {margin-left: 0.75rem;}
.-ml-px {margin-left: -1px;}
.w-5 {width: 1.25rem}
.h-5 {height: 1.25rem}
.text-sm {font-size: 0.875rem;}
.font-medium {font-weight: 500;}
.border {border: 1px solid;}
.cursor-default {cursor: default;}
.leading-5 {line-height: 1.25rem;}
.rounded-md {border-radius: 0.375rem;}
.rounded-1-md {
border-top-left-radius: 0.375rem;
border-bottom-left-radius: 0.375rem;
}
.flex {display: flex;}
.items-center {align-items: center;}
.justify-between {justify-content: space-between;}
.flex-1 {flex: 1;}
.inline-flex {display: inline-flex;}
.items-center {justify-items: center;}
.border-gray-300 {border-color: rgba(209, 213, 219, 100);}
.text-gray-700 {color:rgba(55, 65, 81, 1);}
.text-gray-500 {color: rgba(107, 114, 128, 1)}
.z-0 {z-index: 0;}
.relative {position: relative;}
.bg-white {background: white;}
.sm:hidden {display: none;}

.shadow-sm {
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.hover:text-gray-500 {color: #505050;}
.transition {
    transition-property:  background-color, border-color, color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;
}
.easy-in-out {transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);}
.duration-150 {transition-duration: 150ms;}
.bg-white {background: white;}

} // end pagination

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment