-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7901 from callezenwaka/add_pagitation
Add pagitation
- Loading branch information
Showing
7 changed files
with
239 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte'; | ||
const dispatch = createEventDispatcher(); | ||
export let variant: 'gray' | 'primary-light' | 'primary-dark' = 'gray'; | ||
export let index: number; | ||
export let filter: number; | ||
export let filters: number[] = []; | ||
const onChange = () => { | ||
index = 0; | ||
dispatch('setFilter'); | ||
} | ||
</script> | ||
|
||
<span class={variant}> | ||
<button | ||
type="button" | ||
title="filter" | ||
class="flex justify-center items-center" | ||
style="" | ||
aria-pressed="false" | ||
aria-label="Search filters" | ||
> | ||
<div class="relative"> | ||
<svg enable-background="new 0 0 24 24" height="24" viewBox="0 0 24 24" width="24" focusable="false" style="fill: currentcolor; pointer-events: none; display: block; width: 24px; height: 24px;;"> | ||
<path d="M15 17h6v1h-6v-1zm-4 0H3v1h8v2h1v-5h-1v2zm3-9h1V3h-1v2H3v1h11v2zm4-3v1h3V5h-3zM6 14h1V9H6v2H3v1h3v2zm4-2h11v-1H10v1z"></path> | ||
</svg> | ||
</div> | ||
<slot /> | ||
<div> | ||
<select class={variant} bind:value={filter} on:change={onChange}> | ||
{#each filters as filter (filter)} | ||
<option value={filter}>{ filter }</option> | ||
{/each} | ||
</select> | ||
</div> | ||
</button> | ||
</span> | ||
|
||
<style lang="postcss"> | ||
span { | ||
@apply h-5; | ||
} | ||
.gray { | ||
@apply bg-gray-100 text-gray-800 px-1.5 py-0.5 rounded-sm items-center inline-flex font-bold font-roboto text-xs leading-normal; | ||
} | ||
.primary-light { | ||
@apply bg-primary-100 text-primary-600 px-1.5 py-0.5 rounded-sm items-center inline-flex font-bold font-roboto text-xs leading-normal w-fit; | ||
} | ||
.primary-dark { | ||
@apply bg-gray-800 text-primary-200 px-1.5 py-0.5 rounded-sm items-center inline-flex font-bold font-roboto text-xs leading-normal w-fit; | ||
} | ||
</style> |
114 changes: 114 additions & 0 deletions
114
packages/grid/frontend/src/lib/components/Pagination.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte'; | ||
const dispatch = createEventDispatcher(); | ||
export let variant: 'gray' | 'primary-light' | 'primary-dark' = 'gray'; | ||
export let total: number; | ||
export let page_size: number; | ||
export let page_index: number; | ||
export let page_row: number; | ||
const pageNumbers = (total: number, max: number, current: number) => { | ||
const half = Math.floor(max / 2); | ||
let to = max; | ||
if(current + half >= total) { | ||
to = total; | ||
} else if(current > half) { | ||
to = current + half ; | ||
} | ||
let from = Math.max(to - max, 0); | ||
return Array.from({length: Math.min(total, max)}, (_, i) => (i + 1) + from); | ||
} | ||
$: paginators = Math.ceil(total / page_size) || 0; | ||
$: paginations = pageNumbers(total, page_row, page_index); | ||
const handlePaginate = (index: number) => { | ||
page_index = index; | ||
dispatch('setPagination', page_index); | ||
}; | ||
const handlePrev = () => { | ||
if ((page_index - 1) < 0) return; | ||
else dispatch('setPagination', page_index--); | ||
}; | ||
const handleNext = () => { | ||
if ((page_index + 1) >= paginators) return; | ||
else dispatch('setPagination', page_index++); | ||
}; | ||
</script> | ||
|
||
<span class="flex gap-2.5"> | ||
<button | ||
type="button" | ||
title="Previous" | ||
class={`${variant} pagination-button`} | ||
style="" | ||
style:cursor={(page_index) === 0 ? 'not-allowed' : 'pointer'} | ||
aria-pressed="false" | ||
aria-label="LEFT-POINTING ANGLE" | ||
disabled='{(page_index) === 0}' | ||
on:click={handlePrev} | ||
> | ||
❮ | ||
</button> | ||
{#each paginations as pagination} | ||
<button | ||
type="button" | ||
title="Paginate" | ||
class={`${variant} pagination-button ${(pagination - 1) === page_index ? 'primary-light' : ''}`} | ||
style="" | ||
aria-pressed="false" | ||
aria-label="Paginate" | ||
on:click={() => {handlePaginate(pagination - 1)}} | ||
> | ||
{ pagination } | ||
</button> | ||
{/each} | ||
<button | ||
type="button" | ||
title="Next" | ||
class={`${variant} pagination-button`} | ||
style="" | ||
style:cursor={(page_index+1) === paginators ? 'not-allowed' : 'pointer'} | ||
aria-pressed="false" | ||
aria-label="RIGHT-POINTING ANGLE" | ||
disabled='{(page_index+1) === paginators}' | ||
on:click={handleNext} | ||
> | ||
❯ | ||
</button> | ||
</span> | ||
|
||
<style lang="postcss"> | ||
span { | ||
@apply h-5; | ||
} | ||
.gray { | ||
@apply bg-gray-100 text-gray-800 px-1.5 py-0.5 rounded-sm items-center inline-flex font-bold font-roboto text-xs leading-normal; | ||
} | ||
.primary-light { | ||
@apply bg-primary-100 text-primary-600 px-1.5 py-0.5 rounded-sm items-center inline-flex font-bold font-roboto text-xs leading-normal w-fit; | ||
} | ||
.primary-dark { | ||
@apply bg-gray-800 text-primary-200 px-1.5 py-0.5 rounded-sm items-center inline-flex font-bold font-roboto text-xs leading-normal w-fit; | ||
} | ||
.pagination-button { | ||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
padding-top: 0.75rem; | ||
padding-bottom: 0.75rem; | ||
font-size: 1rem; | ||
line-height: 1.25rem; | ||
font-weight: 800; | ||
} | ||
</style> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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