|
1 | 1 | <script lang="ts">
|
2 | 2 | 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'; |
11 | 6 |
|
12 | 7 | export let itemCount;
|
13 | 8 | export let pageConfig;
|
|
17 | 12 |
|
18 | 13 | let indexInformation = '';
|
19 | 14 |
|
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; |
39 | 16 |
|
40 | 17 | let pageSizeDropdownValue: string = $pageSize;
|
41 | 18 |
|
|
50 | 27 | if (pageIndexStringType === 'pages') {
|
51 | 28 | return $pageCount > 0 ? `Page ${$pageIndex + 1} of ${$pageCount}` : 'No pages';
|
52 | 29 | } 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)}`; |
57 | 36 | }
|
58 | 37 | };
|
59 | 38 |
|
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 | + }; |
64 | 45 | $: $pageSize = pageSizeDropdownValue;
|
65 | 46 | $: $pageCount, $pageIndex, $pageSize, itemCount, (indexInformation = getIndexInfomationString());
|
66 | 47 | </script>
|
67 | 48 |
|
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"> |
69 | 50 | <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 |
| - |
81 | 51 | <button
|
82 | 52 | 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" |
84 | 54 | use:popup={pageSizePopup}
|
85 | 55 | >
|
86 | 56 | <span class="capitalize font-semibold">{pageSizeDropdownValue}</span>
|
87 | 57 | <Fa icon={faChevronDown} size="xs" />
|
88 | 58 | </button>
|
89 |
| - |
90 | 59 | <div class="card w-20 shadow-xl py-2" data-popup={`#${id}-pageSizeDropdown`}>
|
91 | 60 | <ListBox rounded="rounded-none">
|
92 | 61 | {#each pageSizes as size}
|
|
98 | 67 | <div class="arrow bg-surface-100-800-token" />
|
99 | 68 | </div>
|
100 | 69 | </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 |
126 | 79 | />
|
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 |
| - > |
141 | 80 | </div>
|
142 | 81 | <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> |
144 | 83 | </div>
|
145 | 84 | </div>
|
0 commit comments