2020-12-01 16:27:19 +00:00
|
|
|
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
|
2020-11-29 21:14:48 +00:00
|
|
|
import { Table } from "./Table";
|
|
|
|
import { COMMON_STYLES } from "../../common/styles";
|
|
|
|
|
|
|
|
@customElement("pb-table-pagination")
|
|
|
|
export class TablePagination extends LitElement {
|
2020-12-02 14:44:40 +00:00
|
|
|
@property({attribute: false})
|
2020-12-01 16:27:19 +00:00
|
|
|
table?: Table<unknown>;
|
2020-11-29 21:14:48 +00:00
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
static get styles(): CSSResult[] {
|
|
|
|
return COMMON_STYLES;
|
2020-11-29 21:14:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
previousHandler(): void {
|
2020-11-29 21:14:48 +00:00
|
|
|
if (!this.table?.data?.pagination.previous) {
|
2020-12-01 08:15:41 +00:00
|
|
|
console.debug("passbook/tables: no previous");
|
2020-11-29 21:14:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.table.page = this.table?.data?.pagination.previous;
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
nextHandler(): void {
|
2020-11-29 21:14:48 +00:00
|
|
|
if (!this.table?.data?.pagination.next) {
|
2020-12-01 08:15:41 +00:00
|
|
|
console.debug("passbook/tables: no next");
|
2020-11-29 21:14:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.table.page = this.table?.data?.pagination.next;
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
render(): TemplateResult {
|
2020-11-29 21:14:48 +00:00
|
|
|
return html` <div class="pf-c-pagination pf-m-compact pf-m-hidden pf-m-visible-on-md">
|
|
|
|
<div class="pf-c-pagination pf-m-compact pf-m-compact pf-m-hidden pf-m-visible-on-md">
|
|
|
|
<div class="pf-c-options-menu">
|
|
|
|
<div class="pf-c-options-menu__toggle pf-m-text pf-m-plain">
|
|
|
|
<span class="pf-c-options-menu__toggle-text">
|
|
|
|
${this.table?.data?.pagination.start_index} -
|
|
|
|
${this.table?.data?.pagination.end_index} of
|
|
|
|
${this.table?.data?.pagination.count}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<nav class="pf-c-pagination__nav" aria-label="Pagination">
|
|
|
|
<div class="pf-c-pagination__nav-control pf-m-prev">
|
|
|
|
<button
|
|
|
|
class="pf-c-button pf-m-plain"
|
2020-12-01 16:27:19 +00:00
|
|
|
@click=${() => {this.previousHandler();}}
|
2020-12-02 14:44:40 +00:00
|
|
|
?disabled="${(this.table?.data?.pagination.previous || 0) > 0}"
|
2020-11-29 21:14:48 +00:00
|
|
|
aria-label="{% trans 'Go to previous page' %}"
|
|
|
|
>
|
|
|
|
<i class="fas fa-angle-left" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-pagination__nav-control pf-m-next">
|
|
|
|
<button
|
|
|
|
class="pf-c-button pf-m-plain"
|
2020-12-01 16:27:19 +00:00
|
|
|
@click=${() => {this.nextHandler();}}
|
2020-12-02 14:44:40 +00:00
|
|
|
?disabled="${(this.table?.data?.pagination.next || 0) > 0}"
|
2020-11-29 21:14:48 +00:00
|
|
|
aria-label="{% trans 'Go to next page' %}"
|
|
|
|
>
|
|
|
|
<i class="fas fa-angle-right" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
}
|