@zanichelli/albe-web-components 3.0.0 → 3.2.0
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/dist/cjs/{icons-30810e62.js → icons-9fc3ff30.js} +101 -70
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/web-components-library.cjs.js +1 -1
- package/dist/cjs/z-app-switcher_12.cjs.entry.js +4 -1
- package/dist/cjs/z-date-picker.cjs.entry.js +104 -4
- package/dist/cjs/z-icon-package.cjs.entry.js +1 -1
- package/dist/cjs/z-navigation-tab-link.cjs.entry.js +1 -1
- package/dist/cjs/z-navigation-tab.cjs.entry.js +1 -1
- package/dist/cjs/z-pagination.cjs.entry.js +229 -0
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/components/buttons/z-button/index.js +3 -0
- package/dist/collection/components/icons/icons.js +101 -70
- package/dist/collection/components/z-date-picker/index.js +111 -4
- package/dist/collection/components/z-date-picker/styles.css +14 -4
- package/dist/collection/components/z-pagination/index.js +447 -0
- package/dist/collection/components/z-pagination/styles.css +204 -0
- package/dist/collection/{components → deprecated}/pagination/z-pagination-bar/index.js +0 -0
- package/dist/collection/{components → deprecated}/pagination/z-pagination-bar/styles.css +0 -0
- package/dist/collection/{components → deprecated}/pagination/z-pagination-page/index.js +0 -0
- package/dist/collection/{components → deprecated}/pagination/z-pagination-page/styles.css +0 -0
- package/dist/esm/{icons-d8a127bf.js → icons-92a7dcde.js} +101 -70
- package/dist/esm/loader.js +1 -1
- package/dist/esm/web-components-library.js +1 -1
- package/dist/esm/z-app-switcher_12.entry.js +4 -1
- package/dist/esm/z-date-picker.entry.js +104 -4
- package/dist/esm/z-icon-package.entry.js +1 -1
- package/dist/esm/z-navigation-tab-link.entry.js +1 -1
- package/dist/esm/z-navigation-tab.entry.js +1 -1
- package/dist/esm/z-pagination.entry.js +225 -0
- package/dist/types/components/buttons/z-button/index.d.ts +1 -0
- package/dist/types/components/icons/icons.d.ts +249 -232
- package/dist/types/components/z-date-picker/index.d.ts +6 -0
- package/dist/types/components/z-pagination/index.d.ts +109 -0
- package/dist/types/components.d.ts +89 -0
- package/dist/types/{components → deprecated}/pagination/z-pagination-bar/index.d.ts +0 -0
- package/dist/types/{components → deprecated}/pagination/z-pagination-page/index.d.ts +0 -0
- package/dist/web-components-library/p-14c9344f.entry.js +1 -0
- package/dist/web-components-library/p-42b0972c.js +1 -0
- package/dist/web-components-library/{p-393c31c0.entry.js → p-56437e20.entry.js} +1 -1
- package/dist/web-components-library/{p-3dba3a83.entry.js → p-bbb0e7a7.entry.js} +2 -2
- package/dist/web-components-library/{p-64b2b415.entry.js → p-d0fea19f.entry.js} +1 -1
- package/dist/web-components-library/p-d3723aa7.entry.js +1 -0
- package/dist/web-components-library/{p-cadcf677.entry.js → p-f3080685.entry.js} +1 -1
- package/dist/web-components-library/web-components-library.esm.js +1 -1
- package/package.json +1 -1
- package/react/components.d.ts +1 -0
- package/react/components.js +3 -2
- package/react/components.js.map +1 -1
- package/www/build/p-14c9344f.entry.js +1 -0
- package/www/build/p-42b0972c.js +1 -0
- package/www/build/{p-393c31c0.entry.js → p-56437e20.entry.js} +1 -1
- package/www/build/p-88b56b6e.css +1 -0
- package/www/build/p-9ebf28f8.js +1 -0
- package/www/build/{p-3dba3a83.entry.js → p-bbb0e7a7.entry.js} +2 -2
- package/www/build/{p-64b2b415.entry.js → p-d0fea19f.entry.js} +1 -1
- package/www/build/p-d3723aa7.entry.js +1 -0
- package/www/build/{p-cadcf677.entry.js → p-f3080685.entry.js} +1 -1
- package/www/build/web-components-library.esm.js +1 -1
- package/www/index.html +49 -49
- package/CHANGELOG.md +0 -1629
- package/dist/web-components-library/p-571e9db9.js +0 -1
- package/dist/web-components-library/p-8b62bd85.entry.js +0 -1
- package/src-react/index.ts +0 -1
- package/www/build/p-2e24f261.js +0 -129
- package/www/build/p-571e9db9.js +0 -1
- package/www/build/p-8b62bd85.entry.js +0 -1
- package/www/build/p-fcff1237.css +0 -812
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-90e18641.js';
|
|
2
|
+
|
|
3
|
+
const stylesCss = "z-pagination{--z-pagination--page-button-width:64px;--z-pagination--pages-container-max-width:100%;display:flex;flex-direction:column;gap:calc(var(--space-unit) * 2) calc(var(--space-unit) * 4);max-width:100%;flex-wrap:wrap;font-family:var(--font-family-sans);font-weight:var(--font-rg)}z-pagination,z-pagination *{box-sizing:border-box}z-pagination button{height:100%}z-pagination z-icon{fill:var(--color-icon01)}z-pagination *:disabled z-icon{fill:var(--color-disabled02)}z-pagination .page-label{margin-right:calc(var(--space-unit) * 3);color:var(--color-text02)}z-pagination .pagination-bar{display:flex;align-items:center;height:48px;max-width:100%}z-pagination .pagination-bar button{display:flex;align-items:center;justify-content:center;margin:0;background-color:var(--color-surface03);transition:background-color .150s ease-out,\n color .150s ease-out,\n border-bottom-color .150s ease-out,\n font-size .150s ease-in-out,\n font-weight .150s ease-in-out;color:var(--color-primary01);border:none;font-family:inherit;font-weight:inherit;cursor:pointer}z-pagination .pagination-bar button:focus-visible{outline:none;box-shadow:inset var(--shadow-focus-primary);background-color:var(--color-hover-surface)}z-pagination .pagination-bar .pagination-button{padding:calc(var(--space-unit) * 2);text-transform:uppercase;white-space:nowrap;font-weight:var(--font-sb)}z-pagination .pagination-bar .navigation-button{padding:calc(var(--space-unit) * 2) calc(var(--space-unit) * 1.5)}z-pagination .pagination-bar .pagination-button:disabled,z-pagination .pagination-bar .navigation-button:disabled{background-color:var(--color-disabled01);color:var(--color-disabled02);cursor:default;pointer-events:none}z-pagination .pagination-bar .page-button,z-pagination .pagination-bar .ellipsis-button{width:var(--z-pagination--page-button-width)}z-pagination .pages-container{position:relative;display:inline-flex;max-width:100%;height:100%;overflow-x:auto;scroll-behavior:smooth;scroll-snap-align:center;scrollbar-width:none}z-pagination .pages-container::-webkit-scrollbar{display:none}z-pagination .pages-chunk{display:flex;scroll-snap-align:center}z-pagination .pagination-bar .page-button{padding-top:var(--border-size-large) solid transparent;border-bottom:var(--border-size-large) solid transparent;font-size:var(--font-size-2);font-weight:var(--font-sb)}z-pagination .pagination-bar .page-button:focus-visible{border-bottom-color:var(--color-hover-light)}z-pagination .pagination-bar .page-button[data-current]{font-size:var(--font-size-7);border-bottom-color:var(--color-primary01)}z-pagination .go-to-page{display:flex;flex-direction:column;row-gap:var(--space-unit)}z-pagination .go-to-page .label{color:var(--color-text02);text-transform:uppercase}z-pagination .go-to-page .inputs{display:flex;column-gap:var(--space-unit)}z-pagination .go-to-page .inputs z-input{width:calc(var(--space-unit) * 11)}z-pagination .go-to-page .inputs z-input input,z-pagination .mobile-go-to-page z-input input{padding:0 calc(var(--space-unit) * 1.5) !important;-moz-appearance:none}z-pagination .mobile-go-to-page{display:flex;justify-content:center;align-items:center;flex:1 auto;height:100%;background-color:var(--color-surface03)}z-pagination .mobile-go-to-page z-input{width:var(--z-pagination--page-button-width);margin-right:var(--space-unit)}z-pagination .mobile-go-to-page z-input input{text-align:center}z-pagination .mobile-go-to-page z-input input::-webkit-outer-spin-button,z-pagination .mobile-go-to-page z-input input::-webkit-inner-spin-button{appearance:none;-webkit-appearance:none}z-pagination .mobile-go-to-page>span{font-size:var(--font-size-2)}@media (hover: hover){z-pagination .pagination-bar button:hover{background-color:var(--color-hover-surface)}z-pagination .pagination-bar .page-button:hover{border-bottom-color:var(--color-hover-light)}}@media (min-width: 768px){z-pagination{--z-pagination--page-button-width:88px;flex-direction:row;align-items:flex-end}z-pagination .pages-container{max-width:var(--z-pagination--pages-container-max-width)}}";
|
|
4
|
+
|
|
5
|
+
const ZPagination = class {
|
|
6
|
+
constructor(hostRef) {
|
|
7
|
+
registerInstance(this, hostRef);
|
|
8
|
+
this.pageChanged = createEvent(this, "pageChanged", 7);
|
|
9
|
+
/** Enable navigation arrows. */
|
|
10
|
+
this.navArrows = true;
|
|
11
|
+
/** Number of pages to skip. */
|
|
12
|
+
this.skip = 0;
|
|
13
|
+
/** Enable buttons to go to the first and last pages. */
|
|
14
|
+
this.edges = false;
|
|
15
|
+
/** Current page. */
|
|
16
|
+
this.currentPage = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Internal visible pages variable.
|
|
19
|
+
* Needed to better handle conflicting props like `visiblePages` and `split`.
|
|
20
|
+
* This state will change based on props values and validation,
|
|
21
|
+
* keeping original `visiblePages` value intact.
|
|
22
|
+
*/
|
|
23
|
+
this._visiblePages = this.visiblePages;
|
|
24
|
+
/** Used to hides/change some functionalities on smaller screen sizes */
|
|
25
|
+
this.isMobile = false;
|
|
26
|
+
/** Value of the go to page input */
|
|
27
|
+
this.goToPageValue = null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Set the max width of the pages container.
|
|
31
|
+
*/
|
|
32
|
+
setPagesContainerWidth() {
|
|
33
|
+
if (!this._visiblePages || this.split) {
|
|
34
|
+
this.host.style.setProperty("--z-pagination--pages-container-max-width", "100%");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const pagesContainerStyle = window.getComputedStyle(this.host);
|
|
38
|
+
const pageButtonWidth = pagesContainerStyle.getPropertyValue("--z-pagination--page-button-width");
|
|
39
|
+
this.host.style.setProperty("--z-pagination--pages-container-max-width", `calc(${pageButtonWidth} * ${this._visiblePages})`);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set visible pages.
|
|
43
|
+
* Ensure that the visible pages are always <= the total pages.
|
|
44
|
+
* If `visiblePages` isn't set, fallback to the total pages.
|
|
45
|
+
*/
|
|
46
|
+
setVisiblePages() {
|
|
47
|
+
this._visiblePages = Math.min(this.visiblePages || this.totalPages, this.totalPages);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* On page changed.
|
|
51
|
+
* @emits pageChanged
|
|
52
|
+
*/
|
|
53
|
+
onPageChanged() {
|
|
54
|
+
this.pageChanged.emit(this.currentPage);
|
|
55
|
+
this.scrollToPage();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* On split changed.
|
|
59
|
+
* Empty `edges` value. The split feature wins over the pages chunks and edges.
|
|
60
|
+
*/
|
|
61
|
+
onSplitChanged() {
|
|
62
|
+
if (this.split) {
|
|
63
|
+
this.edges = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Hide stuff on mobile.
|
|
68
|
+
*/
|
|
69
|
+
onResize() {
|
|
70
|
+
this.setMobile();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Set functionalities according to screen size.
|
|
74
|
+
*/
|
|
75
|
+
setMobile() {
|
|
76
|
+
const mobileMediaQuery = "screen and (max-width: 767px)";
|
|
77
|
+
this.isMobile = window.matchMedia(mobileMediaQuery).matches;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get a list of pages chunks, each of `visiblePages` length.
|
|
81
|
+
* @returns {number[][]}
|
|
82
|
+
*/
|
|
83
|
+
getPagesChunks() {
|
|
84
|
+
// array of numbers from 1 to `totalPages`
|
|
85
|
+
const pages = Array.from({ length: this.totalPages }, (_, i) => i + 1);
|
|
86
|
+
let chunks = [];
|
|
87
|
+
const chunksCount = Math.ceil(pages.length / this._visiblePages);
|
|
88
|
+
for (let index = 0; index < chunksCount; index++) {
|
|
89
|
+
chunks.push(pages.slice(index * this._visiblePages, (index + 1) * this._visiblePages));
|
|
90
|
+
}
|
|
91
|
+
return chunks;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Scroll to the left the chunk of pages containing the current page.
|
|
95
|
+
*/
|
|
96
|
+
scrollToPage() {
|
|
97
|
+
const pageBtn = this.host.querySelector(`[data-page="${this.currentPage}"]`);
|
|
98
|
+
if (!pageBtn) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
pageBtn.scrollIntoView({
|
|
102
|
+
behavior: "smooth",
|
|
103
|
+
block: "nearest",
|
|
104
|
+
inline: "center",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Select a page.
|
|
109
|
+
* Do validations on the passed value before assigning it to `currentPage`.
|
|
110
|
+
* @param {number} page Page number to set
|
|
111
|
+
*/
|
|
112
|
+
selectPage(page) {
|
|
113
|
+
this.currentPage = Math.min(Math.max(page, 1), this.totalPages);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Render page number button.
|
|
117
|
+
* @param {number} page Page number to render
|
|
118
|
+
* @returns {HTMLButtonElement}
|
|
119
|
+
*/
|
|
120
|
+
renderPage(page) {
|
|
121
|
+
return (h("button", { class: "page-button", type: "button", "aria-current": this.currentPage === page ? "page" : "false", title: `Vai alla pagina ${page}`, "data-page": page, "data-current": this.currentPage === page, onClick: () => this.selectPage(page) }, page));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Render split button.
|
|
125
|
+
* @param {number} page Page to select on click.
|
|
126
|
+
* @returns {HTMLButtonElement}
|
|
127
|
+
*/
|
|
128
|
+
renderEllipsisButton(page) {
|
|
129
|
+
return (h("button", { class: "ellipsis-button", type: "button", title: `Vai alla pagina ${page}`, onClick: () => this.selectPage(page) }, "\u2026"));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Render chunked page buttons.
|
|
133
|
+
* @returns {HTMLDivElement}
|
|
134
|
+
*/
|
|
135
|
+
renderPages() {
|
|
136
|
+
const pagesChunks = this.getPagesChunks();
|
|
137
|
+
if (pagesChunks.length <= 0) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return pagesChunks.map((chunk) => (h("div", { class: "pages-chunk" }, chunk.map((page) => this.renderPage(page)))));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Render page buttons when split feature is enabled.
|
|
144
|
+
* @returns {HTMLButtonElement[]}
|
|
145
|
+
*/
|
|
146
|
+
renderSplitPages() {
|
|
147
|
+
// left and right split pages, current page, first and last page, left and right ellipsis button
|
|
148
|
+
if (this.totalPages <= this.split * 2 + 5) {
|
|
149
|
+
// Too few pages: ellipsis will never be rendered, so let's just render all pages and that's it.
|
|
150
|
+
return Array.from({ length: this.totalPages }, (_, i) => this.renderPage(i + 1));
|
|
151
|
+
}
|
|
152
|
+
if (this.currentPage <= this.split * 2 + 2) {
|
|
153
|
+
// Render first (2 * split + 3) pages, ellipsis, then last page.
|
|
154
|
+
return [
|
|
155
|
+
...Array.from({ length: this.split * 2 + 3 }, (_, i) => this.renderPage(i + 1)),
|
|
156
|
+
this.renderEllipsisButton(this.split * 2 + 4),
|
|
157
|
+
this.renderPage(this.totalPages),
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
if (this.currentPage > this.split * 2 + 2 && this.currentPage < this.totalPages - this.split * 2 - 1) {
|
|
161
|
+
// Render first page, ellipsis, current page surrounded by (split) pages both before and after, another ellipsis, then last page.
|
|
162
|
+
return [
|
|
163
|
+
this.renderPage(1),
|
|
164
|
+
this.renderEllipsisButton(this.currentPage - this.split - 1),
|
|
165
|
+
...Array.from({ length: this.split * 2 + 1 }, (_, i) => this.renderPage(this.currentPage - this.split + i)),
|
|
166
|
+
this.renderEllipsisButton(this.currentPage + this.split + 1),
|
|
167
|
+
this.renderPage(this.totalPages),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
// Render first page, ellipsis, then last (2 * split + 3) pages.
|
|
171
|
+
return [
|
|
172
|
+
this.renderPage(1),
|
|
173
|
+
this.renderEllipsisButton(this.totalPages - this.split * 2 - 3),
|
|
174
|
+
...Array.from({ length: this.split * 2 + 3 }, (_, i) => this.renderPage(this.totalPages - this.split * 2 - 2 + i)),
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
renderBackButton() {
|
|
178
|
+
return (h("button", { class: "navigation-button", type: "button", title: "Vai alla pagina precedente", disabled: this.currentPage === 1, onClick: () => this.selectPage(this.currentPage - 1) }, h("z-icon", { name: "chevron-left" })));
|
|
179
|
+
}
|
|
180
|
+
renderForwardButton() {
|
|
181
|
+
return (h("button", { class: "navigation-button", type: "button", title: "Vai alla prossima pagina", disabled: this.currentPage === this.totalPages, onClick: () => this.selectPage(this.currentPage + 1) }, h("z-icon", { name: "chevron-right" })));
|
|
182
|
+
}
|
|
183
|
+
renderMobile() {
|
|
184
|
+
const pagesChunks = this.getPagesChunks();
|
|
185
|
+
return [
|
|
186
|
+
this.label && h("span", { class: "page-label body-1-sb" }, this.label),
|
|
187
|
+
h("div", { class: "pagination-bar" }, this.renderBackButton(), !this.goToPage && (h("div", { class: "pages-container", role: "navigation", tabIndex: -1 }, pagesChunks.length > 0 &&
|
|
188
|
+
pagesChunks.map((chunk) => (h("div", { class: "pages-chunk" }, chunk.map((page) => this.renderPage(page))))))), this.goToPage && (h("form", { class: "mobile-go-to-page", onSubmit: (ev) => {
|
|
189
|
+
ev.preventDefault();
|
|
190
|
+
this.selectPage(this.goToPageValue);
|
|
191
|
+
} }, h("z-input", { class: "go-to-page-input", type: "number", hasmessage: false, onInput: (ev) => { this.goToPageValue = ev.target.value; }, placeholder: this.currentPage.toString(), hasclearicon: false }), h("span", null, `/${this.totalPages}`))), this.renderForwardButton()),
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
componentDidLoad() {
|
|
195
|
+
this.setVisiblePages();
|
|
196
|
+
}
|
|
197
|
+
componentDidRender() {
|
|
198
|
+
if (this.split) {
|
|
199
|
+
this.edges = false;
|
|
200
|
+
}
|
|
201
|
+
this.setPagesContainerWidth();
|
|
202
|
+
this.setMobile();
|
|
203
|
+
}
|
|
204
|
+
render() {
|
|
205
|
+
if (this.isMobile) {
|
|
206
|
+
return this.renderMobile();
|
|
207
|
+
}
|
|
208
|
+
return [
|
|
209
|
+
h("div", { class: "pagination-bar" }, this.label && h("span", { class: "page-label body-1-sb" }, this.label), this.edges && (h("button", { class: "pagination-button", type: "button", title: "Vai alla pagina 1", disabled: this.currentPage === 1, onClick: () => this.selectPage(1) }, "Pagina 1")), this.skip < this.totalPages && this.skip > 1 && (h("button", { class: "pagination-button", type: "button", title: `Vai alla pagina ${this.currentPage - this.skip}`, disabled: this.currentPage <= this.skip, onClick: () => this.selectPage(this.currentPage - this.skip) }, "-", this.skip)), this.navArrows && this.renderBackButton(), h("div", { class: "pages-container", role: "navigation", tabIndex: -1 }, this.split ?
|
|
210
|
+
this.renderSplitPages() :
|
|
211
|
+
this.renderPages()), this.navArrows && this.renderForwardButton(), this.skip < this.totalPages && this.skip > 1 && (h("button", { class: "pagination-button", type: "button", title: `Vai alla pagina ${this.currentPage + this.skip}`, disabled: this.currentPage > this.totalPages - this.skip, onClick: () => this.selectPage(this.currentPage + this.skip) }, "+", this.skip)), this.edges && (h("button", { class: "pagination-button", type: "button", title: `Vai alla pagina ${this.totalPages}`, disabled: this.currentPage === this.totalPages, onClick: () => this.selectPage(this.totalPages) }, "Pagina ", this.totalPages))),
|
|
212
|
+
this.goToPage && (h("div", { class: "go-to-page" }, h("span", { class: "label body-5-sb" }, "Vai a pagina:"), h("div", { class: "inputs" }, h("z-input", { class: "go-to-page-input", type: "number", hasmessage: false, placeholder: "2", hasclearicon: false, onInput: (ev) => { this.goToPageValue = ev.target.value; }, onKeyDown: (ev) => ev.key === "Enter" && this.selectPage(this.goToPageValue) }), h("z-button", { disabled: !this.goToPageValue, title: "Vai alla pagina inserita", onClick: () => this.selectPage(this.goToPageValue) }, "vai")))),
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
get host() { return getElement(this); }
|
|
216
|
+
static get watchers() { return {
|
|
217
|
+
"_visiblePages": ["setPagesContainerWidth"],
|
|
218
|
+
"visiblePages": ["setVisiblePages"],
|
|
219
|
+
"currentPage": ["onPageChanged"],
|
|
220
|
+
"split": ["onSplitChanged"]
|
|
221
|
+
}; }
|
|
222
|
+
};
|
|
223
|
+
ZPagination.style = stylesCss;
|
|
224
|
+
|
|
225
|
+
export { ZPagination as z_pagination };
|