@fluid-topics/ft-pager 1.3.22 → 1.3.24

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.
@@ -1,16 +1,21 @@
1
1
  import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
2
  import { FtPagerProperties } from "./ft-pager.properties";
3
- export declare class FtPager extends FtLitElement implements FtPagerProperties {
3
+ declare const FtPager_base: typeof FtLitElement & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
4
+ export declare class FtPager extends FtPager_base implements FtPagerProperties {
4
5
  static elementDefinitions: ElementDefinitionsMap;
5
- static styles: import("lit").CSSResult;
6
+ static styles: import("lit").CSSResult[];
6
7
  currentPage: number;
7
8
  maxPage?: number;
8
9
  itemsPerPage?: number;
9
10
  totalItemsCount?: number;
10
- nextLabel: string;
11
- previousLabel: string;
11
+ nextLabel?: string;
12
+ previousLabel?: string;
13
+ private announcement;
14
+ constructor();
12
15
  get resolvedMaxPage(): number;
13
16
  protected render(): import("lit-html").TemplateResult<1>;
14
17
  private onChange;
15
18
  private setPage;
19
+ private resolveAnnouncement;
16
20
  }
21
+ export {};
package/build/ft-pager.js CHANGED
@@ -5,22 +5,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html } from "lit";
8
- import { property } from "lit/decorators.js";
9
- import { FtLitElement } from "@fluid-topics/ft-wc-utils";
8
+ import { property, state } from "lit/decorators.js";
9
+ import { FtLitElement, screenReaderStyles } from "@fluid-topics/ft-wc-utils";
10
10
  import { styles } from "./ft-pager.styles";
11
11
  import { FtButton } from "@fluid-topics/ft-button";
12
12
  import { FtIcons } from "@fluid-topics/ft-icon";
13
13
  import { FtNumberField } from "@fluid-topics/ft-number-field";
14
14
  import { FtTypography } from "@fluid-topics/ft-typography";
15
- class FtPager extends FtLitElement {
15
+ import { defaultMessages, pager } from "./ft-pager.messages";
16
+ import { withI18n } from "@fluid-topics/ft-i18n";
17
+ class FtPager extends withI18n(FtLitElement) {
16
18
  constructor() {
17
- super(...arguments);
19
+ super();
18
20
  this.currentPage = 1;
19
- this.nextLabel = "Next";
20
- this.previousLabel = "Previous";
21
+ this.announcement = "";
22
+ this.addI18nContext(pager, defaultMessages);
21
23
  }
22
24
  get resolvedMaxPage() {
23
- if (!!this.maxPage) {
25
+ if (this.maxPage) {
24
26
  return Math.max(1, this.maxPage);
25
27
  }
26
28
  if (!!this.totalItemsCount && !!this.itemsPerPage) {
@@ -29,7 +31,8 @@ class FtPager extends FtLitElement {
29
31
  return 1;
30
32
  }
31
33
  render() {
32
- let maxPage = this.resolvedMaxPage;
34
+ var _a, _b;
35
+ const maxPage = this.resolvedMaxPage;
33
36
  return html `
34
37
  <style>
35
38
  ft-number-field::part(input) {
@@ -37,27 +40,31 @@ class FtPager extends FtLitElement {
37
40
  }
38
41
 
39
42
  </style>
40
- <div part="container">
41
- <ft-button icon=${FtIcons.THIN_ARROW_LEFT}
42
- ?disabled="${this.currentPage == 1}"
43
- @click="${() => this.setPage(this.currentPage - 1)}"
44
- label="${this.previousLabel}"
43
+ <nav part="container" aria-label="pagination">
44
+ <ft-button icon="${FtIcons.THIN_ARROW_LEFT}"
45
+ ?disabled=${this.currentPage === 1}
46
+ @click=${() => this.setPage(this.currentPage - 1)}
47
+ label="${(_a = this.previousLabel) !== null && _a !== void 0 ? _a : pager.messages.previousLabel()}"
45
48
  tooltipPosition="top">
46
49
  </ft-button>
47
50
  <ft-number-field outlined
48
51
  value="${this.currentPage}"
49
52
  min="1"
50
53
  max="${maxPage}"
51
- @change="${this.onChange}">
54
+ aria-label="${pager.messages.currentPageNumberLabel()}"
55
+ @change=${this.onChange}>
52
56
  </ft-number-field>
53
57
  <ft-typography variant="body1"> / ${maxPage}</ft-typography>
54
- <ft-button icon=${FtIcons.THIN_ARROW_RIGHT}
55
- ?disabled="${this.currentPage == maxPage}"
56
- @click="${() => this.setPage(this.currentPage + 1)}"
57
- label="${this.nextLabel}"
58
+ <ft-button icon="${FtIcons.THIN_ARROW_RIGHT}"
59
+ ?disabled=${this.currentPage === maxPage}
60
+ @click=${() => this.setPage(this.currentPage + 1)}
61
+ label="${(_b = this.nextLabel) !== null && _b !== void 0 ? _b : pager.messages.nextLabel()}"
58
62
  tooltipPosition="top">
59
63
  </ft-button>
60
- </div>
64
+ <div aria-live="polite" aria-atomic="true" class="sr-only">
65
+ ${this.announcement}
66
+ </div>
67
+ </nav>
61
68
  `;
62
69
  }
63
70
  onChange(event) {
@@ -66,15 +73,24 @@ class FtPager extends FtLitElement {
66
73
  }
67
74
  setPage(page) {
68
75
  this.currentPage = page;
76
+ this.announcement = this.resolveAnnouncement();
69
77
  this.dispatchEvent(new CustomEvent("change", { detail: page }));
70
78
  }
79
+ resolveAnnouncement() {
80
+ const announcement = pager.messages.openingPageAnnouncement(this.currentPage);
81
+ const isLastPage = this.currentPage === this.maxPage;
82
+ if (isLastPage) {
83
+ return announcement + pager.messages.lastPageSuffix();
84
+ }
85
+ return announcement;
86
+ }
71
87
  }
72
88
  FtPager.elementDefinitions = {
73
89
  "ft-button": FtButton,
74
90
  "ft-number-field": FtNumberField,
75
- "ft-typography": FtTypography
91
+ "ft-typography": FtTypography,
76
92
  };
77
- FtPager.styles = styles;
93
+ FtPager.styles = [styles, screenReaderStyles];
78
94
  __decorate([
79
95
  property({ type: Number, reflect: true })
80
96
  ], FtPager.prototype, "currentPage", void 0);
@@ -93,4 +109,7 @@ __decorate([
93
109
  __decorate([
94
110
  property()
95
111
  ], FtPager.prototype, "previousLabel", void 0);
112
+ __decorate([
113
+ state()
114
+ ], FtPager.prototype, "announcement", void 0);
96
115
  export { FtPager };