import {type CSSResultGroup, html, unsafeCSS} from 'lit'; import {property} from 'lit/decorators.js'; import ZincElement from '../../internal/zinc-element'; import styles from './pagination.scss'; /** * @summary Pagination component for navigating through pages of content. * @documentation https://zinc.style/components/pagination * @status experimental * @since 1.0 */ export default class ZnPagination extends ZincElement { static styles: CSSResultGroup = unsafeCSS(styles); @property({attribute: 'limit', type: Number, reflect: true}) limit: number = 10; // Per-page limit @property({attribute: 'total', type: Number, reflect: true}) total: number = 0; // Total number of items @property({attribute: 'page', type: Number, reflect: true}) page: number = 1; // Current page @property({attribute: 'uri', type: String, reflect: true}) uri: string = ""; // Uri to call replacing #page# with page number protected _createLink(page: number): string { if (page === this.page) return ""; return this.uri.replace('#page#', page.toString()); } protected _calculatePages() { return Math.ceil(this.total / this.limit); } protected render() { const numberOfPages = this._calculatePages(); const prevButton = html`