|
10 | 10 | export let pageSize; |
11 | 11 | export let totalCount; |
12 | 12 | export let currentPage; |
| 13 | + export let singleLine = false; |
13 | 14 |
|
14 | 15 | $: numberOfPages = Math.ceil(totalCount / pageSize); |
15 | 16 | $: pageNumbers = getPageNumbers(currentPage, numberOfPages); |
|
77 | 78 | } |
78 | 79 | </script> |
79 | 80 |
|
80 | | -<div class="row justify-content-center"> |
81 | | - {#if numberOfPages > 1} |
82 | | - <div class="col"> |
83 | | - <nav aria-label="Page navigation"> |
84 | | - <ul class="pagination justify-content-center"> |
85 | | - <li class="page-item"> |
86 | | - <button |
87 | | - class="page-link" |
88 | | - type="button" |
89 | | - aria-label="Previous" |
90 | | - disabled={currentPage === 1} |
91 | | - on:click={() => setCurrentPage(currentPage - 1)} |
92 | | - class:disabled={currentPage === 1} |
93 | | - > |
94 | | - <span aria-hidden="true">«</span> |
95 | | - </button> |
96 | | - </li> |
97 | | - {#each pageNumbers as pageNumber} |
98 | | - {#if typeof pageNumber === 'number'} |
99 | | - <li class="page-item" class:active={pageNumber === currentPage}> |
| 81 | +<div class="row"> |
| 82 | + <div class={singleLine ? 'col-6' : 'col-12'}> |
| 83 | + <div class="justify-content-center" class:row={!singleLine}> |
| 84 | + {#if numberOfPages > 1} |
| 85 | + <div class="col"> |
| 86 | + <nav aria-label="Page navigation"> |
| 87 | + <ul class="pagination justify-content-center"> |
| 88 | + <li class="page-item"> |
100 | 89 | <button |
101 | | - type="button" |
102 | 90 | class="page-link" |
103 | | - on:click={() => setCurrentPage(/** @type {number} */ (pageNumber))} |
| 91 | + type="button" |
| 92 | + aria-label="Previous" |
| 93 | + disabled={currentPage === 1} |
| 94 | + on:click={() => setCurrentPage(currentPage - 1)} |
| 95 | + class:disabled={currentPage === 1} |
104 | 96 | > |
105 | | - {pageNumber} |
| 97 | + <span aria-hidden="true">«</span> |
106 | 98 | </button> |
107 | 99 | </li> |
108 | | - {:else} |
| 100 | + {#each pageNumbers as pageNumber} |
| 101 | + {#if typeof pageNumber === 'number'} |
| 102 | + <li class="page-item" class:active={pageNumber === currentPage}> |
| 103 | + <button |
| 104 | + type="button" |
| 105 | + class="page-link" |
| 106 | + on:click={() => setCurrentPage(/** @type {number} */ (pageNumber))} |
| 107 | + > |
| 108 | + {pageNumber} |
| 109 | + </button> |
| 110 | + </li> |
| 111 | + {:else} |
| 112 | + <li class="page-item"> |
| 113 | + <span class="page-link disabled">{pageNumber}</span> |
| 114 | + </li> |
| 115 | + {/if} |
| 116 | + {/each} |
109 | 117 | <li class="page-item"> |
110 | | - <span class="page-link disabled">{pageNumber}</span> |
| 118 | + <button |
| 119 | + class="page-link" |
| 120 | + type="button" |
| 121 | + aria-label="Next" |
| 122 | + disabled={currentPage === numberOfPages} |
| 123 | + on:click={() => setCurrentPage(currentPage + 1)} |
| 124 | + class:disabled={currentPage === numberOfPages} |
| 125 | + > |
| 126 | + <span aria-hidden="true">»</span> |
| 127 | + </button> |
111 | 128 | </li> |
112 | | - {/if} |
113 | | - {/each} |
114 | | - <li class="page-item"> |
115 | | - <button |
116 | | - class="page-link" |
117 | | - type="button" |
118 | | - aria-label="Next" |
119 | | - disabled={currentPage === numberOfPages} |
120 | | - on:click={() => setCurrentPage(currentPage + 1)} |
121 | | - class:disabled={currentPage === numberOfPages} |
122 | | - > |
123 | | - <span aria-hidden="true">»</span> |
124 | | - </button> |
125 | | - </li> |
126 | | - </ul> |
127 | | - </nav> |
128 | | - </div> |
129 | | - {/if} |
130 | | -</div> |
131 | | -<div class="row row-cols-lg-auto justify-content-center"> |
132 | | - <div class="col-6"> |
133 | | - <div class="input-group"> |
134 | | - <label class="input-group-text" for="page_size">Page size</label> |
135 | | - <select |
136 | | - class="form-select" |
137 | | - id="page_size" |
138 | | - bind:value={pageSize} |
139 | | - on:change={() => setPageSize()} |
140 | | - > |
141 | | - {#each availablePageSizes as pageSize} |
142 | | - <option value={pageSize}>{pageSize}</option> |
143 | | - {/each} |
144 | | - </select> |
| 129 | + </ul> |
| 130 | + </nav> |
| 131 | + </div> |
| 132 | + {/if} |
145 | 133 | </div> |
146 | 134 | </div> |
147 | | - <div class="col-6 mt-2"> |
148 | | - <p class="text-center">Total results: {totalCount}</p> |
| 135 | + <div class={singleLine ? 'col-6' : 'col-12'}> |
| 136 | + <div class="row row-cols-lg-auto justify-content-center"> |
| 137 | + <div class="col-6"> |
| 138 | + <div class="input-group"> |
| 139 | + <label class="input-group-text" for="page_size">Page size</label> |
| 140 | + <select |
| 141 | + class="form-select" |
| 142 | + id="page_size" |
| 143 | + bind:value={pageSize} |
| 144 | + on:change={() => setPageSize()} |
| 145 | + > |
| 146 | + {#each availablePageSizes as pageSize} |
| 147 | + <option value={pageSize}>{pageSize}</option> |
| 148 | + {/each} |
| 149 | + </select> |
| 150 | + </div> |
| 151 | + </div> |
| 152 | + <div class="col-6 mt-2"> |
| 153 | + <p class="text-center">Total results: {totalCount}</p> |
| 154 | + </div> |
| 155 | + </div> |
149 | 156 | </div> |
150 | 157 | </div> |
0 commit comments