@redvars/peacock 3.14.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/custom-elements-jsdocs.json +170 -19
- package/dist/custom-elements.json +1171 -249
- package/dist/modal.js +178 -99
- package/dist/modal.js.map +1 -1
- package/dist/pagination.js +408 -110
- package/dist/pagination.js.map +1 -1
- package/dist/src/modal/modal.d.ts +23 -8
- package/dist/src/pagination/page-items.d.ts +14 -0
- package/dist/src/pagination/pagination.d.ts +46 -7
- package/dist/src/table/table.d.ts +125 -27
- package/dist/table.js +1001 -337
- package/dist/table.js.map +1 -1
- package/dist/test/modal.test.d.ts +1 -0
- package/dist/test/pagination.test.d.ts +1 -0
- package/dist/test/table.test.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +2 -2
- package/src/modal/modal.scss +45 -11
- package/src/modal/modal.ts +148 -96
- package/src/pagination/page-items.ts +50 -0
- package/src/pagination/pagination.scss +159 -44
- package/src/pagination/pagination.ts +275 -74
- package/src/table/table.scss +331 -109
- package/src/table/table.ts +810 -271
|
@@ -5,69 +5,184 @@
|
|
|
5
5
|
:host {
|
|
6
6
|
display: block;
|
|
7
7
|
container-type: inline-size;
|
|
8
|
+
--pagination-background: var(--color-surface, #fff);
|
|
9
|
+
--_pagination-target-size: 2.5rem;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
.pagination {
|
|
11
13
|
display: flex;
|
|
12
|
-
align-items: center;
|
|
13
|
-
justify-content: space-between;
|
|
14
14
|
flex-wrap: wrap;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: var(--spacing-100, 0.5rem) var(--spacing-300, 1.5rem);
|
|
17
|
+
padding: var(--spacing-100, 0.5rem) var(--spacing-200, 1rem);
|
|
18
|
+
background: var(--pagination-background);
|
|
19
|
+
color: var(--color-on-surface-variant);
|
|
20
|
+
|
|
21
|
+
@include mixin.get-typography-not-important('body-medium');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Status on the start side, actions on the end side.
|
|
25
|
+
.range {
|
|
26
|
+
flex: 1 1 auto;
|
|
27
|
+
white-space: nowrap;
|
|
28
|
+
font-variant-numeric: tabular-nums;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.page-size {
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: var(--spacing-100, 0.5rem);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.page-size-label {
|
|
38
|
+
white-space: nowrap;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.page-size-select {
|
|
42
|
+
inline-size: 5.5rem;
|
|
43
|
+
--field-height: var(--_pagination-target-size);
|
|
44
|
+
--field-padding-block: 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.controls {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: var(--spacing-050, 0.25rem);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.nav-button {
|
|
54
|
+
--button-container-shape: var(--shape-corner-full);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.page-list {
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
gap: var(--spacing-025, 0.125rem);
|
|
61
|
+
margin: 0;
|
|
62
|
+
padding: 0;
|
|
63
|
+
list-style: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.page-button {
|
|
67
|
+
@include mixin.reset-button-styles;
|
|
68
|
+
@include mixin.get-typography-not-important('label-large');
|
|
69
|
+
|
|
70
|
+
display: inline-flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
min-inline-size: var(--_pagination-target-size);
|
|
74
|
+
block-size: var(--_pagination-target-size);
|
|
75
|
+
padding: 0 var(--spacing-100, 0.5rem);
|
|
76
|
+
border-radius: var(--shape-corner-full);
|
|
77
|
+
color: var(--color-on-surface-variant);
|
|
78
|
+
font-variant-numeric: tabular-nums;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
transition: background-color var(--duration-short2, 100ms) ease;
|
|
81
|
+
|
|
82
|
+
&:hover {
|
|
83
|
+
background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
24
84
|
}
|
|
25
85
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
align-items: center;
|
|
29
|
-
gap: var(--spacing-100, 0.5rem);
|
|
30
|
-
min-inline-size: max-content;
|
|
86
|
+
&:active {
|
|
87
|
+
background: color-mix(in srgb, var(--color-on-surface) 12%, transparent);
|
|
31
88
|
}
|
|
32
89
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
white-space: nowrap;
|
|
90
|
+
&:focus-visible {
|
|
91
|
+
outline: 2px solid var(--color-primary);
|
|
92
|
+
outline-offset: 2px;
|
|
37
93
|
}
|
|
38
94
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
95
|
+
&.current {
|
|
96
|
+
background: var(--color-secondary-container);
|
|
97
|
+
color: var(--color-on-secondary-container);
|
|
98
|
+
cursor: default;
|
|
43
99
|
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.page-ellipsis {
|
|
103
|
+
display: inline-flex;
|
|
104
|
+
align-items: center;
|
|
105
|
+
justify-content: center;
|
|
106
|
+
min-inline-size: var(--_pagination-target-size);
|
|
107
|
+
block-size: var(--_pagination-target-size);
|
|
108
|
+
user-select: none;
|
|
109
|
+
}
|
|
44
110
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
111
|
+
.page-jump {
|
|
112
|
+
display: inline-flex;
|
|
113
|
+
align-items: center;
|
|
114
|
+
gap: var(--spacing-100, 0.5rem);
|
|
115
|
+
padding-inline: var(--spacing-050, 0.25rem);
|
|
116
|
+
white-space: nowrap;
|
|
117
|
+
font-variant-numeric: tabular-nums;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.page-input {
|
|
121
|
+
@include mixin.get-typography-not-important('body-medium');
|
|
122
|
+
|
|
123
|
+
inline-size: 3.5rem;
|
|
124
|
+
block-size: 2rem;
|
|
125
|
+
padding: 0 var(--spacing-100, 0.5rem);
|
|
126
|
+
border: 1px solid var(--color-outline-variant);
|
|
127
|
+
border-radius: var(--shape-corner-small);
|
|
128
|
+
background: var(--color-surface);
|
|
129
|
+
color: var(--color-on-surface);
|
|
130
|
+
text-align: center;
|
|
131
|
+
font-variant-numeric: tabular-nums;
|
|
132
|
+
appearance: textfield;
|
|
133
|
+
|
|
134
|
+
&::-webkit-inner-spin-button,
|
|
135
|
+
&::-webkit-outer-spin-button {
|
|
136
|
+
appearance: none;
|
|
137
|
+
margin: 0;
|
|
57
138
|
}
|
|
58
139
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
color: var(--color-on-surface-variant);
|
|
140
|
+
&:hover {
|
|
141
|
+
border-color: var(--color-outline);
|
|
62
142
|
}
|
|
63
143
|
|
|
64
|
-
|
|
144
|
+
&:focus-visible {
|
|
145
|
+
outline: 2px solid var(--color-primary);
|
|
146
|
+
outline-offset: -1px;
|
|
147
|
+
border-color: transparent;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// In the full variant the jump field is the narrow-screen fallback for the page list.
|
|
152
|
+
.variant-full .page-jump {
|
|
153
|
+
display: none;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@container (max-width: 40rem) {
|
|
157
|
+
.variant-full .page-list {
|
|
158
|
+
display: none;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.variant-full .page-jump {
|
|
65
162
|
display: inline-flex;
|
|
66
|
-
align-items: center;
|
|
67
|
-
gap: var(--spacing-025, 0.125rem);
|
|
68
163
|
}
|
|
69
164
|
|
|
70
|
-
.
|
|
71
|
-
|
|
165
|
+
.page-size-label {
|
|
166
|
+
display: none;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Phone width: range and rows per page share the first line, page controls take the second.
|
|
171
|
+
@container (max-width: 26rem) {
|
|
172
|
+
.controls {
|
|
173
|
+
flex-basis: 100%;
|
|
174
|
+
justify-content: space-between;
|
|
72
175
|
}
|
|
73
176
|
}
|
|
177
|
+
|
|
178
|
+
.visually-hidden {
|
|
179
|
+
position: absolute;
|
|
180
|
+
inline-size: 1px;
|
|
181
|
+
block-size: 1px;
|
|
182
|
+
margin: -1px;
|
|
183
|
+
padding: 0;
|
|
184
|
+
overflow: hidden;
|
|
185
|
+
clip-path: inset(50%);
|
|
186
|
+
white-space: nowrap;
|
|
187
|
+
border: 0;
|
|
188
|
+
}
|
|
@@ -1,31 +1,43 @@
|
|
|
1
|
-
import { html, LitElement } from 'lit';
|
|
1
|
+
import { html, LitElement, nothing } from 'lit';
|
|
2
2
|
import type { PropertyValues } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
5
|
import styles from './pagination.scss';
|
|
5
6
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
7
|
+
import { getPageItems } from './page-items.js';
|
|
6
8
|
|
|
7
9
|
const DEFAULT_PAGE_SIZES = [10, 25, 50, 100];
|
|
8
10
|
|
|
11
|
+
export type PaginationVariant = 'full' | 'compact' | 'simple';
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* @label Pagination
|
|
11
15
|
* @tag wc-pagination
|
|
12
16
|
* @rawTag pagination
|
|
13
|
-
* @summary A pagination control with page
|
|
17
|
+
* @summary A pagination control with page numbers, a rows-per-page selector and the current item range.
|
|
14
18
|
* @overview
|
|
15
|
-
* <p>The pagination component
|
|
19
|
+
* <p>The pagination component moves through paged data. It shows the current item range, the pages and a rows-per-page selector.</p>
|
|
20
|
+
* <p>Three variants cover different data sets: <code>full</code> lists page numbers with ellipses, <code>compact</code> shows "Page [n] of N" with a field to jump to a page, and <code>simple</code> shows previous and next only. When <code>total-items</code> is not set, the total is unknown (cursor-based APIs): the control shows previous and next, and <code>has-next</code> says whether another page exists.</p>
|
|
21
|
+
* <p>On a narrow container the <code>full</code> variant collapses to <code>compact</code>.</p>
|
|
16
22
|
*
|
|
17
23
|
* @fires {CustomEvent} page - Dispatched when the page or page size changes. Detail: `{ page, pageSize }`.
|
|
18
24
|
*
|
|
25
|
+
* @cssprop --pagination-background - Background of the control. Defaults to the surface color.
|
|
26
|
+
*
|
|
19
27
|
* @example
|
|
20
28
|
* ```html
|
|
21
|
-
* <wc-pagination style="width: 100%;" page="1" page-size="10" total-items="
|
|
29
|
+
* <wc-pagination style="width: 100%;" page="1" page-size="10" total-items="240"></wc-pagination>
|
|
22
30
|
* ```
|
|
23
31
|
* @tags navigation, data
|
|
24
32
|
*/
|
|
25
33
|
@IndividualComponent
|
|
26
34
|
export class Pagination extends LitElement {
|
|
35
|
+
// ── Static ───────────────────────────────────────────────────────────────
|
|
36
|
+
|
|
27
37
|
static styles = [styles];
|
|
28
38
|
|
|
39
|
+
// ── Properties ───────────────────────────────────────────────────────────
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* The current page number (1-based). Defaults to `1`.
|
|
31
43
|
*/
|
|
@@ -39,10 +51,11 @@ export class Pagination extends LitElement {
|
|
|
39
51
|
pageSize: number = 10;
|
|
40
52
|
|
|
41
53
|
/**
|
|
42
|
-
* Total number of items.
|
|
54
|
+
* Total number of items. Leave it unset when the total is unknown; the control then shows
|
|
55
|
+
* previous and next only, and `has-next` decides whether next is enabled.
|
|
43
56
|
*/
|
|
44
57
|
@property({ type: Number, attribute: 'total-items' })
|
|
45
|
-
totalItems: number
|
|
58
|
+
totalItems: number | undefined;
|
|
46
59
|
|
|
47
60
|
/**
|
|
48
61
|
* Supported page size options.
|
|
@@ -50,16 +63,51 @@ export class Pagination extends LitElement {
|
|
|
50
63
|
@property({ type: Array, attribute: 'page-sizes' })
|
|
51
64
|
pageSizes: number[] = DEFAULT_PAGE_SIZES;
|
|
52
65
|
|
|
66
|
+
/**
|
|
67
|
+
* How the pages are shown: `full` (page numbers), `compact` ("Page [n] of N") or `simple`
|
|
68
|
+
* (previous and next only). Defaults to `full`.
|
|
69
|
+
*/
|
|
70
|
+
@property({ type: String, reflect: true })
|
|
71
|
+
variant: PaginationVariant = 'full';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether another page exists after this one. Used only when `total-items` is unset.
|
|
75
|
+
*/
|
|
76
|
+
@property({ type: Boolean, attribute: 'has-next' })
|
|
77
|
+
hasNext: boolean = false;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Shows buttons that jump to the first and the last page.
|
|
81
|
+
*/
|
|
82
|
+
@property({ type: Boolean, attribute: 'show-first-last' })
|
|
83
|
+
showFirstLast: boolean = false;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Hides the rows-per-page selector.
|
|
87
|
+
*/
|
|
88
|
+
@property({ type: Boolean, attribute: 'hide-page-size' })
|
|
89
|
+
hidePageSize: boolean = false;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Accessible name of the navigation landmark. Defaults to `"Pagination"`.
|
|
93
|
+
*/
|
|
94
|
+
@property({ type: String })
|
|
95
|
+
label: string = 'Pagination';
|
|
96
|
+
|
|
97
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
98
|
+
|
|
53
99
|
protected override willUpdate(
|
|
54
100
|
changedProperties: PropertyValues<Pagination>,
|
|
55
101
|
): void {
|
|
56
102
|
// Normalize page-size options so the select always has valid numeric values.
|
|
57
|
-
const normalizedPageSizes = [
|
|
58
|
-
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
103
|
+
const normalizedPageSizes = [
|
|
104
|
+
...new Set(
|
|
105
|
+
this.pageSizes
|
|
106
|
+
.map(size => Number(size))
|
|
107
|
+
.filter(size => Number.isFinite(size) && size > 0)
|
|
108
|
+
.map(size => Math.trunc(size)),
|
|
109
|
+
),
|
|
110
|
+
];
|
|
63
111
|
|
|
64
112
|
if (!normalizedPageSizes.length) {
|
|
65
113
|
normalizedPageSizes.push(...DEFAULT_PAGE_SIZES);
|
|
@@ -68,7 +116,9 @@ export class Pagination extends LitElement {
|
|
|
68
116
|
if (
|
|
69
117
|
changedProperties.has('pageSizes') &&
|
|
70
118
|
(this.pageSizes.length !== normalizedPageSizes.length ||
|
|
71
|
-
this.pageSizes.some(
|
|
119
|
+
this.pageSizes.some(
|
|
120
|
+
(size, index) => size !== normalizedPageSizes[index],
|
|
121
|
+
))
|
|
72
122
|
) {
|
|
73
123
|
this.pageSizes = normalizedPageSizes;
|
|
74
124
|
}
|
|
@@ -77,7 +127,11 @@ export class Pagination extends LitElement {
|
|
|
77
127
|
this.pageSize = this.pageSizes[0] ?? DEFAULT_PAGE_SIZES[0];
|
|
78
128
|
}
|
|
79
129
|
|
|
80
|
-
if (
|
|
130
|
+
if (
|
|
131
|
+
this.totalItems !== undefined &&
|
|
132
|
+
this.totalItems !== null &&
|
|
133
|
+
(!Number.isFinite(this.totalItems) || this.totalItems < 0)
|
|
134
|
+
) {
|
|
81
135
|
this.totalItems = 0;
|
|
82
136
|
}
|
|
83
137
|
|
|
@@ -85,20 +139,59 @@ export class Pagination extends LitElement {
|
|
|
85
139
|
this.page = 1;
|
|
86
140
|
}
|
|
87
141
|
|
|
88
|
-
const
|
|
89
|
-
if (this.page >
|
|
90
|
-
this.page =
|
|
142
|
+
const totalPages = this.getTotalPages();
|
|
143
|
+
if (totalPages !== undefined && this.page > totalPages) {
|
|
144
|
+
this.page = totalPages;
|
|
91
145
|
}
|
|
92
146
|
}
|
|
93
147
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
148
|
+
// ── Private methods ──────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
/** True when the total is known. */
|
|
151
|
+
private get hasTotal(): boolean {
|
|
152
|
+
return this.totalItems !== undefined && this.totalItems !== null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The number of pages, or `undefined` when the total is unknown. */
|
|
156
|
+
private getTotalPages(): number | undefined {
|
|
157
|
+
if (!this.hasTotal) return undefined;
|
|
158
|
+
const total = this.totalItems ?? 0;
|
|
159
|
+
if (total <= 0) return 1;
|
|
160
|
+
return Math.max(1, Math.ceil(total / this.pageSize));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private get isFirstPage(): boolean {
|
|
164
|
+
return this.page <= 1;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private get isLastPage(): boolean {
|
|
168
|
+
const totalPages = this.getTotalPages();
|
|
169
|
+
return totalPages === undefined ? !this.hasNext : this.page >= totalPages;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The variant actually rendered: an unknown total can only go previous and next. */
|
|
173
|
+
private get effectiveVariant(): PaginationVariant {
|
|
174
|
+
return this.hasTotal ? this.variant : 'simple';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private getRangeText(): string {
|
|
178
|
+
const total = this.totalItems ?? 0;
|
|
179
|
+
if (this.hasTotal && total === 0) return '0 of 0';
|
|
180
|
+
const start = this.pageSize * (this.page - 1) + 1;
|
|
181
|
+
if (!this.hasTotal) return `${start}–${this.pageSize * this.page}`;
|
|
182
|
+
const end = Math.min(this.pageSize * this.page, total);
|
|
183
|
+
return `${start}–${end} of ${total}`;
|
|
97
184
|
}
|
|
98
185
|
|
|
99
186
|
private setPage(nextPage: number) {
|
|
100
|
-
const
|
|
101
|
-
|
|
187
|
+
const totalPages = this.getTotalPages() ?? Number.MAX_SAFE_INTEGER;
|
|
188
|
+
const lastAllowed =
|
|
189
|
+
this.hasTotal || this.hasNext ? totalPages : Math.max(1, this.page);
|
|
190
|
+
const clampedPage = Math.min(
|
|
191
|
+
Math.max(1, Math.trunc(nextPage)),
|
|
192
|
+
lastAllowed,
|
|
193
|
+
);
|
|
194
|
+
if (!Number.isFinite(clampedPage) || clampedPage === this.page) return;
|
|
102
195
|
this.page = clampedPage;
|
|
103
196
|
this.dispatchPageEvent();
|
|
104
197
|
}
|
|
@@ -110,18 +203,29 @@ export class Pagination extends LitElement {
|
|
|
110
203
|
if (!Number.isFinite(parsedPageSize) || parsedPageSize <= 0) {
|
|
111
204
|
return;
|
|
112
205
|
}
|
|
206
|
+
if (parsedPageSize === this.pageSize) return;
|
|
113
207
|
|
|
208
|
+
// Keep the first visible item on screen instead of jumping back to page 1.
|
|
209
|
+
const firstItemIndex = this.pageSize * (this.page - 1);
|
|
114
210
|
this.pageSize = parsedPageSize;
|
|
115
|
-
this.page = 1;
|
|
211
|
+
this.page = Math.floor(firstItemIndex / parsedPageSize) + 1;
|
|
116
212
|
this.dispatchPageEvent();
|
|
117
213
|
}
|
|
118
214
|
|
|
119
|
-
private
|
|
120
|
-
|
|
215
|
+
private handlePageInput = (event: Event) => {
|
|
216
|
+
const input = event.target as HTMLInputElement;
|
|
217
|
+
const value = Number.parseInt(input.value, 10);
|
|
218
|
+
if (Number.isFinite(value)) {
|
|
219
|
+
this.setPage(value);
|
|
220
|
+
}
|
|
221
|
+
// Show the page actually used, for example after clamping 99 to the last page.
|
|
222
|
+
input.value = String(this.page);
|
|
121
223
|
};
|
|
122
224
|
|
|
123
|
-
private
|
|
124
|
-
|
|
225
|
+
private handlePageInputKeydown = (event: KeyboardEvent) => {
|
|
226
|
+
if (event.key === 'Enter') {
|
|
227
|
+
this.handlePageInput(event);
|
|
228
|
+
}
|
|
125
229
|
};
|
|
126
230
|
|
|
127
231
|
private dispatchPageEvent() {
|
|
@@ -134,59 +238,156 @@ export class Pagination extends LitElement {
|
|
|
134
238
|
);
|
|
135
239
|
}
|
|
136
240
|
|
|
241
|
+
// ── Render helpers ───────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
private renderNavButton(
|
|
244
|
+
icon: string,
|
|
245
|
+
label: string,
|
|
246
|
+
disabled: boolean,
|
|
247
|
+
target: () => number,
|
|
248
|
+
className: string,
|
|
249
|
+
) {
|
|
250
|
+
return html`
|
|
251
|
+
<wc-icon-button
|
|
252
|
+
class="nav-button ${className}"
|
|
253
|
+
color="secondary"
|
|
254
|
+
variant="text"
|
|
255
|
+
size="sm"
|
|
256
|
+
aria-label=${label}
|
|
257
|
+
title=${label}
|
|
258
|
+
?disabled=${disabled}
|
|
259
|
+
@click=${() => this.setPage(target())}
|
|
260
|
+
>
|
|
261
|
+
<wc-icon name=${icon}></wc-icon>
|
|
262
|
+
</wc-icon-button>
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private renderPageList(totalPages: number) {
|
|
267
|
+
return html`
|
|
268
|
+
<ol class="page-list">
|
|
269
|
+
${getPageItems(this.page, totalPages).map(item =>
|
|
270
|
+
item === 'ellipsis'
|
|
271
|
+
? html`<li class="page-ellipsis" aria-hidden="true">…</li>`
|
|
272
|
+
: html`
|
|
273
|
+
<li>
|
|
274
|
+
<button
|
|
275
|
+
type="button"
|
|
276
|
+
class=${classMap({
|
|
277
|
+
'page-button': true,
|
|
278
|
+
current: item === this.page,
|
|
279
|
+
})}
|
|
280
|
+
aria-label="Page ${item}"
|
|
281
|
+
aria-current=${item === this.page ? 'page' : nothing}
|
|
282
|
+
@click=${() => this.setPage(item)}
|
|
283
|
+
>
|
|
284
|
+
${item}
|
|
285
|
+
</button>
|
|
286
|
+
</li>
|
|
287
|
+
`,
|
|
288
|
+
)}
|
|
289
|
+
</ol>
|
|
290
|
+
`;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private renderPageJump(totalPages: number) {
|
|
294
|
+
return html`
|
|
295
|
+
<div class="page-jump">
|
|
296
|
+
<span>Page</span>
|
|
297
|
+
<input
|
|
298
|
+
class="page-input"
|
|
299
|
+
type="number"
|
|
300
|
+
inputmode="numeric"
|
|
301
|
+
min="1"
|
|
302
|
+
max=${totalPages}
|
|
303
|
+
.value=${String(this.page)}
|
|
304
|
+
aria-label="Page number, ${totalPages} pages"
|
|
305
|
+
@change=${this.handlePageInput}
|
|
306
|
+
@keydown=${this.handlePageInputKeydown}
|
|
307
|
+
/>
|
|
308
|
+
<span>of ${totalPages}</span>
|
|
309
|
+
</div>
|
|
310
|
+
`;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
private renderPageSize() {
|
|
314
|
+
if (this.hidePageSize) return nothing;
|
|
315
|
+
return html`
|
|
316
|
+
<div class="page-size">
|
|
317
|
+
<span class="page-size-label" aria-hidden="true">Rows per page</span>
|
|
318
|
+
<wc-select
|
|
319
|
+
class="page-size-select"
|
|
320
|
+
.value=${String(this.pageSize)}
|
|
321
|
+
aria-label="Rows per page"
|
|
322
|
+
@change=${this.handlePageSizeChange}
|
|
323
|
+
>
|
|
324
|
+
${this.pageSizes.map(
|
|
325
|
+
size => html`<wc-option value=${String(size)}>${size}</wc-option>`,
|
|
326
|
+
)}
|
|
327
|
+
</wc-select>
|
|
328
|
+
</div>
|
|
329
|
+
`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ── Render ───────────────────────────────────────────────────────────────
|
|
333
|
+
|
|
137
334
|
render() {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
335
|
+
const variant = this.effectiveVariant;
|
|
336
|
+
const totalPages = this.getTotalPages() ?? 1;
|
|
337
|
+
const rangeText = this.getRangeText();
|
|
338
|
+
const showFirstLast = this.showFirstLast && this.hasTotal;
|
|
142
339
|
|
|
143
340
|
return html`
|
|
144
|
-
<
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
>
|
|
153
|
-
${this.pageSizes.map(
|
|
154
|
-
size => html`<wc-option value=${String(size)}>${size}</wc-option>`,
|
|
155
|
-
)}
|
|
156
|
-
</wc-select>
|
|
157
|
-
</div>
|
|
341
|
+
<nav
|
|
342
|
+
class=${classMap({ pagination: true, [`variant-${variant}`]: true })}
|
|
343
|
+
aria-label=${this.label}
|
|
344
|
+
>
|
|
345
|
+
<div class="range" aria-hidden="true">${rangeText}</div>
|
|
346
|
+
<span class="visually-hidden" aria-live="polite">
|
|
347
|
+
Showing ${rangeText}
|
|
348
|
+
</span>
|
|
158
349
|
|
|
159
|
-
|
|
160
|
-
<span class="pagination-text">
|
|
161
|
-
${startItem} - ${endItem} of ${this.totalItems}
|
|
162
|
-
</span>
|
|
163
|
-
</div>
|
|
350
|
+
${this.renderPageSize()}
|
|
164
351
|
|
|
165
|
-
<div class="
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
352
|
+
<div class="controls">
|
|
353
|
+
${showFirstLast
|
|
354
|
+
? this.renderNavButton(
|
|
355
|
+
'first_page',
|
|
356
|
+
'First page',
|
|
357
|
+
this.isFirstPage,
|
|
358
|
+
() => 1,
|
|
359
|
+
'first',
|
|
360
|
+
)
|
|
361
|
+
: nothing}
|
|
362
|
+
${this.renderNavButton(
|
|
363
|
+
'chevron_left',
|
|
364
|
+
'Previous page',
|
|
365
|
+
this.isFirstPage,
|
|
366
|
+
() => this.page - 1,
|
|
367
|
+
'previous',
|
|
368
|
+
)}
|
|
369
|
+
${variant === 'full' ? this.renderPageList(totalPages) : nothing}
|
|
370
|
+
${variant === 'full' || variant === 'compact'
|
|
371
|
+
? this.renderPageJump(totalPages)
|
|
372
|
+
: nothing}
|
|
373
|
+
${this.renderNavButton(
|
|
374
|
+
'chevron_right',
|
|
375
|
+
'Next page',
|
|
376
|
+
this.isLastPage,
|
|
377
|
+
() => this.page + 1,
|
|
378
|
+
'next',
|
|
379
|
+
)}
|
|
380
|
+
${showFirstLast
|
|
381
|
+
? this.renderNavButton(
|
|
382
|
+
'last_page',
|
|
383
|
+
'Last page',
|
|
384
|
+
this.isLastPage,
|
|
385
|
+
() => totalPages,
|
|
386
|
+
'last',
|
|
387
|
+
)
|
|
388
|
+
: nothing}
|
|
188
389
|
</div>
|
|
189
|
-
</
|
|
390
|
+
</nav>
|
|
190
391
|
`;
|
|
191
392
|
}
|
|
192
393
|
}
|