@redvars/peacock 3.15.0 → 3.17.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.
Files changed (157) hide show
  1. package/dist/assets/styles.css +1 -1
  2. package/dist/assets/styles.css.map +1 -1
  3. package/dist/assets/theme.js +19 -19
  4. package/dist/assets/tokens.css +1 -1
  5. package/dist/assets/tokens.css.map +1 -1
  6. package/dist/card-content.js +8 -7
  7. package/dist/card-content.js.map +1 -1
  8. package/dist/card.js +142 -98
  9. package/dist/card.js.map +1 -1
  10. package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
  11. package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
  12. package/dist/chart-area.js +78 -0
  13. package/dist/chart-area.js.map +1 -0
  14. package/dist/chart-bar.js +283 -213
  15. package/dist/chart-bar.js.map +1 -1
  16. package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
  17. package/dist/chart-base-C2qRMF48.js.map +1 -0
  18. package/dist/chart-doughnut.js +55 -287
  19. package/dist/chart-doughnut.js.map +1 -1
  20. package/dist/chart-line.js +626 -0
  21. package/dist/chart-line.js.map +1 -0
  22. package/dist/chart-pie.js +637 -195
  23. package/dist/chart-pie.js.map +1 -1
  24. package/dist/code-editor.js +704 -131
  25. package/dist/code-editor.js.map +1 -1
  26. package/dist/code-group.js +188 -0
  27. package/dist/code-group.js.map +1 -0
  28. package/dist/code-highlighter.js +895 -257
  29. package/dist/code-highlighter.js.map +1 -1
  30. package/dist/custom-elements-jsdocs.json +2278 -677
  31. package/dist/custom-elements.json +13962 -3690
  32. package/dist/image.js +5 -1
  33. package/dist/image.js.map +1 -1
  34. package/dist/index.js +8 -7
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader-full.js +1 -1
  37. package/dist/loader.js +9 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
  40. package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
  41. package/dist/pagination.js +408 -110
  42. package/dist/pagination.js.map +1 -1
  43. package/dist/path-CJ0Arqcy.js +166 -0
  44. package/dist/path-CJ0Arqcy.js.map +1 -0
  45. package/dist/snackbar.js +89 -34
  46. package/dist/snackbar.js.map +1 -1
  47. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  48. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  49. package/dist/src/__internal/chart/paths.d.ts +5 -0
  50. package/dist/src/__internal/chart/types.d.ts +42 -0
  51. package/dist/src/card/card-content.d.ts +2 -3
  52. package/dist/src/card/card.d.ts +31 -17
  53. package/dist/src/chart-area/chart-area.d.ts +54 -0
  54. package/dist/src/chart-area/index.d.ts +1 -0
  55. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  56. package/dist/src/chart-bar/index.d.ts +0 -1
  57. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  58. package/dist/src/chart-line/chart-line.d.ts +69 -0
  59. package/dist/src/chart-line/index.d.ts +1 -0
  60. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  61. package/dist/src/code-editor/code-editor.d.ts +52 -13
  62. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  63. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  64. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  65. package/dist/src/code-highlighter/index.d.ts +1 -0
  66. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  67. package/dist/src/code-highlighter/local.d.ts +4 -1
  68. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  69. package/dist/src/index.d.ts +4 -2
  70. package/dist/src/pagination/page-items.d.ts +14 -0
  71. package/dist/src/pagination/pagination.d.ts +46 -7
  72. package/dist/src/snackbar/snackbar.d.ts +13 -1
  73. package/dist/src/table/table.d.ts +125 -27
  74. package/dist/src/toolbar/toolbar.d.ts +56 -51
  75. package/dist/table.js +1007 -338
  76. package/dist/table.js.map +1 -1
  77. package/dist/test/chart.test.d.ts +1 -0
  78. package/dist/test/code-highlighter.test.d.ts +1 -0
  79. package/dist/test/pagination.test.d.ts +1 -0
  80. package/dist/test/table.test.d.ts +1 -0
  81. package/dist/token-colors-0TFHWbcq.js +81 -0
  82. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  83. package/dist/toolbar.js +195 -184
  84. package/dist/toolbar.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -2
  87. package/readme.md +7 -6
  88. package/scss/_code-block.scss +139 -0
  89. package/scss/tokens.css +24 -0
  90. package/src/__internal/chart/cartesian-chart.ts +404 -0
  91. package/src/__internal/chart/chart-base.scss +252 -0
  92. package/src/__internal/chart/chart-base.ts +474 -0
  93. package/src/__internal/chart/paths.ts +28 -0
  94. package/src/__internal/chart/types.ts +49 -0
  95. package/src/card/card-content.ts +12 -9
  96. package/src/card/card.scss +66 -54
  97. package/src/card/card.ts +109 -73
  98. package/src/chart-area/chart-area.ts +82 -0
  99. package/src/chart-area/index.ts +1 -0
  100. package/src/chart-bar/chart-bar.ts +336 -250
  101. package/src/chart-bar/index.ts +0 -1
  102. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  103. package/src/chart-doughnut/demo/index.html +14 -22
  104. package/src/chart-line/chart-line.scss +25 -0
  105. package/src/chart-line/chart-line.ts +346 -0
  106. package/src/chart-line/index.ts +1 -0
  107. package/src/chart-pie/chart-pie.scss +35 -16
  108. package/src/chart-pie/chart-pie.ts +282 -188
  109. package/src/chart-pie/demo/index.html +13 -21
  110. package/src/code-editor/code-editor.scss +132 -36
  111. package/src/code-editor/code-editor.ts +308 -88
  112. package/src/code-editor/demo/index.html +39 -12
  113. package/src/code-editor/editor-theme.ts +213 -0
  114. package/src/code-highlighter/code-group.scss +34 -0
  115. package/src/code-highlighter/code-group.ts +173 -0
  116. package/src/code-highlighter/code-highlighter.scss +226 -111
  117. package/src/code-highlighter/code-highlighter.ts +554 -199
  118. package/src/code-highlighter/demo/index.html +68 -4
  119. package/src/code-highlighter/index.ts +1 -0
  120. package/src/code-highlighter/line-ranges.ts +81 -0
  121. package/src/code-highlighter/local.ts +9 -3
  122. package/src/code-highlighter/token-colors.ts +42 -0
  123. package/src/index.ts +4 -2
  124. package/src/loader.ts +8 -2
  125. package/src/pagination/page-items.ts +50 -0
  126. package/src/pagination/pagination.scss +159 -44
  127. package/src/pagination/pagination.ts +275 -74
  128. package/src/snackbar/demo/index.html +39 -4
  129. package/src/snackbar/snackbar.scss +27 -10
  130. package/src/snackbar/snackbar.ts +80 -37
  131. package/src/table/table.scss +337 -109
  132. package/src/table/table.ts +812 -272
  133. package/src/toolbar/toolbar-colors.scss +6 -7
  134. package/src/toolbar/toolbar.scss +35 -106
  135. package/src/toolbar/toolbar.ts +180 -80
  136. package/dist/array-D5vjT2Xm.js +0 -14
  137. package/dist/array-D5vjT2Xm.js.map +0 -1
  138. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  139. package/dist/chart-stacked-bar.js +0 -403
  140. package/dist/chart-stacked-bar.js.map +0 -1
  141. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  142. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  143. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  144. package/dist/pie-Dz0IDiPt.js +0 -537
  145. package/dist/pie-Dz0IDiPt.js.map +0 -1
  146. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  147. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  148. package/dist/pierre-light-BEkAPImt.js +0 -4
  149. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  150. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  151. package/dist/src/code-highlighter/constants.d.ts +0 -1
  152. package/dist/transform-DSwFSqzD.js.map +0 -1
  153. package/src/chart-bar/chart-bar.scss +0 -58
  154. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  155. package/src/chart-doughnut/chart-donut.scss +0 -37
  156. package/src/code-highlighter/constants.ts +0 -117
  157. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -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 size selector, item count display, and previous/next navigation.
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 provides controls for navigating through paged data sets.</p>
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="100"></wc-pagination>
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 = 0;
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 = [...new Set(
58
- this.pageSizes
59
- .map(size => Number(size))
60
- .filter(size => Number.isFinite(size) && size > 0)
61
- .map(size => Math.trunc(size)),
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((size, index) => size !== normalizedPageSizes[index]))
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 (!Number.isFinite(this.totalItems) || this.totalItems < 0) {
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 maxPage = this.getTotalPages();
89
- if (this.page > maxPage) {
90
- this.page = maxPage;
142
+ const totalPages = this.getTotalPages();
143
+ if (totalPages !== undefined && this.page > totalPages) {
144
+ this.page = totalPages;
91
145
  }
92
146
  }
93
147
 
94
- private getTotalPages(): number {
95
- if (this.totalItems <= 0) return 1;
96
- return Math.max(1, Math.ceil(this.totalItems / this.pageSize));
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 clampedPage = Math.min(Math.max(1, nextPage), this.getTotalPages());
101
- if (clampedPage === this.page) return;
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 handlePreviousPage = () => {
120
- this.setPage(this.page - 1);
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 handleNextPage = () => {
124
- this.setPage(this.page + 1);
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 startItem = this.totalItems === 0 ? 0 : this.pageSize * (this.page - 1) + 1;
139
- const endItem = Math.min(this.pageSize * this.page, this.totalItems);
140
- const isFirstPage = this.page === 1;
141
- const isLastPage = this.pageSize * this.page >= this.totalItems;
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
- <div class="pagination">
145
- <div class="page-size">
146
- <span class="page-size-label">Items per page:</span>
147
- <wc-select
148
- class="page-size-select"
149
- .value=${String(this.pageSize)}
150
- aria-label="Items per page"
151
- @change=${this.handlePageSizeChange}
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
- <div class="pagination-item-count">
160
- <span class="pagination-text">
161
- ${startItem} - ${endItem} of ${this.totalItems}
162
- </span>
163
- </div>
350
+ ${this.renderPageSize()}
164
351
 
165
- <div class="pagination-actions">
166
- <wc-icon-button
167
- class="nav-button"
168
- color="secondary"
169
- variant="text"
170
- size="sm"
171
- title="Previous page"
172
- ?disabled=${isFirstPage}
173
- @click=${this.handlePreviousPage}
174
- >
175
- <wc-icon name="keyboard_arrow_left"></wc-icon>
176
- </wc-icon-button>
177
- <wc-icon-button
178
- class="nav-button"
179
- color="secondary"
180
- variant="text"
181
- size="sm"
182
- title="Next page"
183
- ?disabled=${isLastPage}
184
- @click=${this.handleNextPage}
185
- >
186
- <wc-icon name="keyboard_arrow_right"></wc-icon>
187
- </wc-icon-button>
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
- </div>
390
+ </nav>
190
391
  `;
191
392
  }
192
393
  }
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset='utf-8'>
5
5
  <meta name='viewport' content='width=device-width, initial-scale=1.0, viewport-fit=cover' />
6
- <link rel='stylesheet' href='/dist/assets/styles/tokens.css' />
6
+ <link rel='stylesheet' href='/dist/assets/tokens.css' />
7
7
  <style>
8
8
  body {
9
9
  background: #fafafa;
@@ -11,19 +11,54 @@
11
11
  display: grid;
12
12
  gap: 1rem;
13
13
  }
14
+
15
+ /* A fixed bar with a very high z-index: the open snackbar must still draw above it. */
16
+ .cover {
17
+ position: fixed;
18
+ inset-inline: 0;
19
+ bottom: 0;
20
+ height: 6rem;
21
+ z-index: 2147483647;
22
+ background: #d0e4ff;
23
+ }
14
24
  </style>
15
25
  </head>
16
26
  <body>
17
- <wc-snackbar open message="File archived" action-label="Undo"></wc-snackbar>
18
- <wc-snackbar open multiline show-close-icon>
27
+ <wc-snackbar preview message="File archived" action-label="Undo"></wc-snackbar>
28
+ <wc-snackbar preview multiline show-close-icon>
19
29
  Network connection was lost. Please try again when you are back online.
20
30
  </wc-snackbar>
21
31
 
32
+ <div>
33
+ <wc-button id='show-snackbar'>Show snackbar</wc-button>
34
+ <wc-button id='open-modal' variant='outlined'>Open modal</wc-button>
35
+ </div>
36
+
37
+ <div class='cover'></div>
38
+
39
+ <wc-snackbar id='live' message='Draft saved' action-label='Undo' show-close-icon duration='0'></wc-snackbar>
40
+
41
+ <wc-modal id='modal' heading='Edit profile'>
42
+ <p>Saving from inside the modal shows a snackbar above it.</p>
43
+ <wc-button slot='footer' id='save-in-modal'>Save</wc-button>
44
+ </wc-modal>
45
+
22
46
  <script type='module'>
23
- import { Snackbar, Icon } from '/dist/index.js';
47
+ import { Snackbar, Modal, Button, IconButton, Icon } from '/dist/index.js';
24
48
 
25
49
  window.customElements.define('wc-snackbar', Snackbar);
50
+ window.customElements.define('wc-modal', Modal);
51
+ window.customElements.define('wc-button', Button);
52
+ window.customElements.define('wc-icon-button', IconButton);
26
53
  window.customElements.define('wc-icon', Icon);
54
+
55
+ const snackbar = document.getElementById('live');
56
+ const modal = document.getElementById('modal');
57
+ snackbar.duration = 0;
58
+
59
+ document.getElementById('show-snackbar').addEventListener('click', () => snackbar.show());
60
+ document.getElementById('open-modal').addEventListener('click', () => modal.show());
61
+ document.getElementById('save-in-modal').addEventListener('click', () => snackbar.show());
27
62
  </script>
28
63
  </body>
29
64
  </html>
@@ -27,13 +27,7 @@
27
27
  }
28
28
 
29
29
  :host {
30
- display: flex;
31
- inset-block-end: calc(var(--snackbar-offset-bottom, 1rem) + env(safe-area-inset-bottom, 0px));
32
- inset-inline: var(--snackbar-offset-inline, 1rem);
33
- justify-content: center;
34
- pointer-events: none;
35
- position: fixed;
36
- z-index: var(--snackbar-z-index, 1000);
30
+ display: contents;
37
31
 
38
32
  --snackbar-container-color: var(--color-inverse-surface);
39
33
  --snackbar-label-text-color: var(--color-inverse-on-surface);
@@ -42,6 +36,26 @@
42
36
  --snackbar-border-radius: var(--shape-corner-extra-small);
43
37
  }
44
38
 
39
+ // Fixed to the bottom of the viewport. While open it is a manual popover in the top layer,
40
+ // so these rules also undo the browser's default popover styles.
41
+ .layer {
42
+ background: transparent;
43
+ border: 0;
44
+ color: inherit;
45
+ display: flex;
46
+ height: auto;
47
+ inset: auto var(--snackbar-offset-inline, 1rem)
48
+ calc(var(--snackbar-offset-bottom, 1rem) + env(safe-area-inset-bottom, 0px));
49
+ justify-content: center;
50
+ margin: 0;
51
+ overflow: visible;
52
+ padding: 0;
53
+ pointer-events: none;
54
+ position: fixed;
55
+ width: auto;
56
+ z-index: var(--snackbar-z-index, 1000);
57
+ }
58
+
45
59
  .snackbar {
46
60
  @include mixin.get-typography(body-medium);
47
61
  align-items: center;
@@ -93,9 +107,12 @@
93
107
  }
94
108
 
95
109
  :host([preview]) {
96
- position: relative;
97
- inset-inline: unset;
98
- inset-block-end: unset;
110
+ display: flex;
111
+
112
+ .layer {
113
+ position: relative;
114
+ inset: auto;
115
+ }
99
116
 
100
117
  .snackbar {
101
118
  display: inline-flex;