@fluid-topics/ft-pager 1.1.15

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.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ A pagination component
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ft-pager
7
+ yarn add @fluid-topics/ft-pager
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ft-pager"
15
+
16
+ function render() {
17
+ return html` <ft-pager foo="bar"></ft-pager> `
18
+ }
19
+ ```
@@ -0,0 +1,2 @@
1
+ export declare const FtPagerCssVariables: {};
2
+ export declare const styles: import("lit").CSSResult;
@@ -0,0 +1,13 @@
1
+ import { css } from "lit";
2
+ export const FtPagerCssVariables = {};
3
+ // language=CSS
4
+ export const styles = css `
5
+
6
+ [part="container"] {
7
+ display: flex;
8
+ gap: 4px;
9
+ flex-wrap: nowrap;
10
+ align-items: center;
11
+ justify-content: center;
12
+ }
13
+ `;
@@ -0,0 +1,16 @@
1
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
+ import { FtPagerProperties } from "./ft-pager.properties";
3
+ export declare class FtPager extends FtLitElement implements FtPagerProperties {
4
+ static elementDefinitions: ElementDefinitionsMap;
5
+ static styles: import("lit").CSSResult;
6
+ currentPage: number;
7
+ maxPage?: number;
8
+ itemsPerPage?: number;
9
+ totalItemsCount?: number;
10
+ nextLabel: string;
11
+ previousLabel: string;
12
+ get resolvedMaxPage(): number;
13
+ get resolvedCurrentPage(): number;
14
+ protected render(): import("lit").TemplateResult<1>;
15
+ private setPage;
16
+ }
@@ -0,0 +1,84 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html } from "lit";
8
+ import { property } from "lit/decorators.js";
9
+ import { FtLitElement, minmax } from "@fluid-topics/ft-wc-utils";
10
+ import { styles } from "./ft-pager.css";
11
+ import { FtButton } from "@fluid-topics/ft-button";
12
+ import { FtIcons } from "@fluid-topics/ft-icon";
13
+ import { FtTextField } from "@fluid-topics/ft-text-field";
14
+ import { FtTypography } from "@fluid-topics/ft-typography";
15
+ class FtPager extends FtLitElement {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.currentPage = 1;
19
+ this.nextLabel = "Next";
20
+ this.previousLabel = "Previous";
21
+ }
22
+ get resolvedMaxPage() {
23
+ if (!!this.maxPage) {
24
+ return Math.max(1, this.maxPage);
25
+ }
26
+ if (!!this.totalItemsCount && !!this.itemsPerPage) {
27
+ return Math.ceil(Math.max(1, this.totalItemsCount) / Math.max(1, this.itemsPerPage));
28
+ }
29
+ return 1;
30
+ }
31
+ get resolvedCurrentPage() {
32
+ return minmax(1, this.currentPage, this.resolvedMaxPage);
33
+ }
34
+ render() {
35
+ return html `
36
+ <div part="container">
37
+ <ft-button icon=${FtIcons.THIN_ARROW_LEFT}
38
+ ?disabled="${this.resolvedCurrentPage == 1}"
39
+ @click="${() => this.setPage(this.resolvedCurrentPage - 1)}"
40
+ label="${this.previousLabel}" tooltipPosition="top">
41
+ </ft-button>
42
+ <ft-text-field outlined value="${this.resolvedCurrentPage}"
43
+ type="number" min="1" max="${this.resolvedMaxPage}"
44
+ @change="${(e) => this.setPage(+e.detail)}">
45
+ </ft-text-field>
46
+ <ft-typography variant="body1"> / ${this.resolvedMaxPage}</ft-typography>
47
+ <ft-button icon=${FtIcons.THIN_ARROW_RIGHT}
48
+ ?disabled="${this.resolvedCurrentPage == this.resolvedMaxPage}"
49
+ @click="${() => this.setPage(this.resolvedCurrentPage + 1)}"
50
+ label="${this.nextLabel}" tooltipPosition="top">
51
+ </ft-button>
52
+ </div>
53
+ `;
54
+ }
55
+ setPage(page) {
56
+ this.currentPage = page;
57
+ this.dispatchEvent(new CustomEvent("change", { detail: page }));
58
+ }
59
+ }
60
+ FtPager.elementDefinitions = {
61
+ "ft-button": FtButton,
62
+ "ft-text-field": FtTextField,
63
+ "ft-typography": FtTypography
64
+ };
65
+ FtPager.styles = styles;
66
+ __decorate([
67
+ property({ type: Number, reflect: true })
68
+ ], FtPager.prototype, "currentPage", void 0);
69
+ __decorate([
70
+ property({ type: Number })
71
+ ], FtPager.prototype, "maxPage", void 0);
72
+ __decorate([
73
+ property({ type: Number })
74
+ ], FtPager.prototype, "itemsPerPage", void 0);
75
+ __decorate([
76
+ property({ type: Number })
77
+ ], FtPager.prototype, "totalItemsCount", void 0);
78
+ __decorate([
79
+ property()
80
+ ], FtPager.prototype, "nextLabel", void 0);
81
+ __decorate([
82
+ property()
83
+ ], FtPager.prototype, "previousLabel", void 0);
84
+ export { FtPager };