48 lines
2.3 KiB
Plaintext
48 lines
2.3 KiB
Plaintext
<div class="flex justify-center items-center my-6">
|
|
<div class="join shadow-sm border border-base-300">
|
|
<button disabled="@(PaginationModel.CurrentPage == 1)"
|
|
class="join-item btn btn-sm md:btn-md @(PaginationModel.CurrentPage == 1 ? "btn-disabled opacity-50" : "btn-ghost text-primary")"
|
|
@onclick="() => ChangePage((PaginationModel.CurrentPage ?? 1) - 1)">
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24"
|
|
stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
|
</svg>
|
|
</button>
|
|
|
|
@if (PaginationModel.TotalPages.HasValue)
|
|
{
|
|
var currentPage = PaginationModel.CurrentPage ?? 1;
|
|
var totalPages = PaginationModel.TotalPages ?? 0;
|
|
|
|
@for (int i = Math.Max(1, currentPage - 2); i <= Math.Min(totalPages, currentPage + 2); i++)
|
|
{
|
|
var x = i;
|
|
<button @onclick="() => ChangePage(x)"
|
|
class="join-item btn btn-sm md:btn-md @(i == currentPage ? "btn-primary text-white" : "btn-ghost text-primary")">
|
|
@i
|
|
</button>
|
|
}
|
|
}
|
|
|
|
<button
|
|
disabled="@(PaginationModel.CurrentPage == (PaginationModel.TotalPages ?? 0) || (PaginationModel.TotalPages ?? 0) == 0)"
|
|
class="join-item btn btn-sm md:btn-md @(PaginationModel.CurrentPage == (PaginationModel.TotalPages ?? 0) || (PaginationModel.TotalPages ?? 0) == 0 ? "btn-disabled opacity-50" : "btn-ghost text-primary")"
|
|
@onclick="() => ChangePage((PaginationModel.CurrentPage ?? 1) + 1)">
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24"
|
|
stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public Pagination PaginationModel { get; set; } = new();
|
|
[Parameter] public EventCallback<int> OnSearch { get; set; }
|
|
|
|
async Task ChangePage(int pageNumber)
|
|
{
|
|
if (pageNumber < 1 || pageNumber > (PaginationModel.TotalPages ?? 0)) return;
|
|
await OnSearch.InvokeAsync(pageNumber);
|
|
}
|
|
} |