Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/components/pager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
## ➤ Properties

| Property | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| :-- | :-- | :-- | :-- | :-- |
| totalPages | total-pages | Number | | Total number of pages |
| activePage | active-page | Number | 1 | Currently active page |
| perPage | per-page | Number | | Determining maximum number of items in the page, should be either of 10,20,30,40,50 |
| perPageOptions | per-page-options | Array | | Custom list of per-page options, overrides the default [10,20,30,40,50] |
| translations | translations | Object | | Translated messages for the user locale |

## ➤ Events

| Name | Description | Payload |
| --- | --- | --- |
| :-- | :-- | :-- |
| page-change | Emitted on page change, either by navigation button, arrow keys or typing in the input | {oldVal, newVal} |
| per-page-change | Emitted on items per page select value change | {per_page} |

Expand Down
13 changes: 7 additions & 6 deletions packages/components/pager/src/pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
activePage: { type: Number, reflect: true, attribute: 'active-page' },
/** Determining maximum number of items in the page, should be either of 10,20,30,40,50 */
perPage: { type: Number, reflect: true, attribute: 'per-page' },
/** Custom list of per-page options, overrides the default [10,20,30,40,50] */
perPageOptions: { type: Array, attribute: 'per-page-options' },
/** Translated messages for the user locale */
translations: { type: Object, reflect: true }
};
Expand Down Expand Up @@ -107,18 +109,17 @@
if (!this.perPage) {
return;
}
if (perPageSelectValues.indexOf(this.perPage) === -1) {
const errorMessage = `Wrong items per page value: ${
this.perPage
}. per-page should be either of these ${perPageSelectValues.join()}`;
const options = this.perPageOptions && this.perPageOptions.length ? this.perPageOptions : perPageSelectValues;
if (options.indexOf(this.perPage) === -1) {
const errorMessage = `Wrong items per page value: ${this.perPage}. per-page should be either of these ${options.join()}`;

Check notice on line 114 in packages/components/pager/src/pager.js

View check run for this annotation

TS Sonarqube / SonarQube Code Analysis

packages/components/pager/src/pager.js#L114

This line has a length of 124. Maximum allowed is 120.
throw new Error(errorMessage);
}

return html`
<label class="item-per-page-container">
${this.translations.items_per_page}
<select id="itemsPerPage" @change="${this.handlePerPageChange}">
${perPageSelectValues.map(
${options.map(
value => html` <option value="${value}" ?selected="${value === this.perPage}">${value}</option> `
)}
</select>
Expand Down Expand Up @@ -192,7 +193,7 @@
return html`
<div class="container">
${this.itemsPerPageSelector}
<menu> ${this.toStart} ${this.prev} ${this.pageInput} ${this.next} ${this.toEnd} </menu>
<menu>${this.toStart} ${this.prev} ${this.pageInput} ${this.next} ${this.toEnd}</menu>
</div>
`;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/components/pager/types/pager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface TSPagerHTMLAttributes {
/** Determining maximum number of items in the page, should be either of 10,20,30,40,50 */
"per-page"?: number | string;

/** Custom list of per-page options, overrides the default [10,20,30,40,50] */
"per-page-options"?: string;

/** Translated messages for the user locale */
translations?: string;

Expand All @@ -25,6 +28,9 @@ export interface TSPager {
/** Determining maximum number of items in the page, should be either of 10,20,30,40,50 */
perPage?: number;

/** Custom list of per-page options, overrides the default [10,20,30,40,50] */
perPageOptions?: number[];

/** Translated messages for the user locale */
translations?: Record<string, unknown>;

Expand Down