Skip to content

Commit 29a56fb

Browse files
committed
Redesign pagination component
1 parent abc9cf6 commit 29a56fb

File tree

1 file changed

+28
-89
lines changed

1 file changed

+28
-89
lines changed
Lines changed: 28 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
<script lang="ts">
22
import Fa from 'svelte-fa';
3-
import {
4-
faAnglesRight,
5-
faAngleRight,
6-
faAnglesLeft,
7-
faAngleLeft,
8-
faChevronDown
9-
} from '@fortawesome/free-solid-svg-icons';
10-
import { ListBox, ListBoxItem, popup, type PopupSettings } from '@skeletonlabs/skeleton';
3+
import { faChevronDown } from '@fortawesome/free-solid-svg-icons';
4+
import { ListBox, ListBoxItem, Paginator, popup } from '@skeletonlabs/skeleton';
5+
import type { PopupSettings } from '@skeletonlabs/skeleton';
116
127
export let itemCount;
138
export let pageConfig;
@@ -17,25 +12,7 @@
1712
1813
let indexInformation = '';
1914
20-
const { pageIndex, pageCount, pageSize, hasNextPage, hasPreviousPage } = pageConfig;
21-
22-
const goToFirstPage = () => ($pageIndex = 0);
23-
const goToLastPage = () => ($pageIndex = $pageCount - 1);
24-
const goToNextPage = () => ($pageIndex += 1);
25-
const goToPreviousPage = () => ($pageIndex -= 1);
26-
27-
// Handles the input change event
28-
const handleChange = (e) => {
29-
const value = e.target.value;
30-
31-
if (value > $pageCount) {
32-
$pageIndex = $pageCount - 1;
33-
} else if (value < 1) {
34-
$pageIndex = 0;
35-
} else {
36-
$pageIndex = value - 1;
37-
}
38-
};
15+
const { pageIndex, pageCount, pageSize } = pageConfig;
3916
4017
let pageSizeDropdownValue: string = $pageSize;
4118
@@ -50,43 +27,35 @@
5027
if (pageIndexStringType === 'pages') {
5128
return $pageCount > 0 ? `Page ${$pageIndex + 1} of ${$pageCount}` : 'No pages';
5229
} else {
53-
return itemCount === 0 ? 'No items' : `Displaying items ${$pageIndex * $pageSize + 1} - ${Math.min(
54-
($pageIndex + 1) * $pageSize,
55-
itemCount
56-
)} of ${Math.min($pageCount * $pageSize, itemCount)}`;
30+
return itemCount === 0
31+
? 'No items'
32+
: `Displaying items ${$pageIndex * $pageSize + 1} - ${Math.min(
33+
($pageIndex + 1) * $pageSize,
34+
itemCount
35+
)} of ${Math.min($pageCount * $pageSize, itemCount)}`;
5736
}
5837
};
5938
60-
$: goToFirstPageDisabled = !$pageIndex;
61-
$: goToLastPageDisabled = $pageIndex == $pageCount - 1;
62-
$: goToNextPageDisabled = !$hasNextPage;
63-
$: goToPreviousPageDisabled = !$hasPreviousPage;
39+
$: paginationSettings = {
40+
size: itemCount,
41+
limit: $pageSize,
42+
page: $pageIndex,
43+
amounts: pageSizes
44+
};
6445
$: $pageSize = pageSizeDropdownValue;
6546
$: $pageCount, $pageIndex, $pageSize, itemCount, (indexInformation = getIndexInfomationString());
6647
</script>
6748

68-
<div class="flex justify-between w-full items-stretch gap-10">
49+
<div class="grid grid-cols-3 w-full items-stretch gap-10">
6950
<div class="flex justify-start">
70-
<!-- <select
71-
name="pageSize"
72-
id="{id}-pageSize"
73-
class="select variant-filled-primary w-min font-bold"
74-
bind:value={$pageSize}
75-
>
76-
{#each pageSizes as size}
77-
<option value={size} class="">{size}</option>
78-
{/each}
79-
</select> -->
80-
8151
<button
8252
aria-label="Open menu to select number of items to display per page"
83-
class="btn variant-filled-primary w-20 justify-between"
53+
class="btn variant-filled-primary w-20 !px-3 !py-1.5 justify-between"
8454
use:popup={pageSizePopup}
8555
>
8656
<span class="capitalize font-semibold">{pageSizeDropdownValue}</span>
8757
<Fa icon={faChevronDown} size="xs" />
8858
</button>
89-
9059
<div class="card w-20 shadow-xl py-2" data-popup={`#${id}-pageSizeDropdown`}>
9160
<ListBox rounded="rounded-none">
9261
{#each pageSizes as size}
@@ -98,48 +67,18 @@
9867
<div class="arrow bg-surface-100-800-token" />
9968
</div>
10069
</div>
101-
<div class="flex justify-center gap-1">
102-
<button
103-
class="btn btn-sm variant-filled-primary"
104-
on:click|preventDefault={goToFirstPage}
105-
aria-label="Go to first page"
106-
disabled={goToFirstPageDisabled}
107-
id="{id}-first"
108-
>
109-
<Fa icon={faAnglesLeft} /></button
110-
>
111-
<button
112-
class="btn btn-sm variant-filled-primary"
113-
id="{id}-previous"
114-
aria-label="Go to previous page"
115-
on:click|preventDefault={goToPreviousPage}
116-
disabled={goToPreviousPageDisabled}><Fa icon={faAngleLeft} /></button
117-
>
118-
<input
119-
type="number"
120-
class="input border border-primary-500 rounded flex w-24"
121-
value={$pageIndex + 1}
122-
max={$pageCount}
123-
aria-label="Current page"
124-
min={1}
125-
on:change={handleChange}
70+
<div class="flex justify-center">
71+
<Paginator
72+
on:page={(page) => ($pageIndex = page.detail)}
73+
settings={paginationSettings}
74+
select="hidden"
75+
buttonClasses="disabled:!variant-filled-surface !px-3 !py-1.5 !fill-current !variant-filled-primary"
76+
active="!variant-filled-secondary"
77+
maxNumerals={1}
78+
showNumerals
12679
/>
127-
<button
128-
class="btn btn-sm variant-filled-primary"
129-
id="{id}-next"
130-
aria-label="Go to next page"
131-
on:click|preventDefault={goToNextPage}
132-
disabled={goToNextPageDisabled}><Fa icon={faAngleRight} /></button
133-
>
134-
<button
135-
class="btn btn-sm variant-filled-primary"
136-
aria-label="Go to last page"
137-
id="{id}-last"
138-
on:click|preventDefault={goToLastPage}
139-
disabled={goToLastPageDisabled}><Fa icon={faAnglesRight} /></button
140-
>
14180
</div>
14281
<div class="flex justify-end items-center">
143-
<span class="text-sm text-gray-500">{indexInformation}</span>
82+
<span class="text-xs text-gray-500">{indexInformation}</span>
14483
</div>
14584
</div>

0 commit comments

Comments
 (0)