@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, Prop, Element, h, Event, State, } from "@stencil/core";
|
|
1
|
+
import { Component, Prop, Element, h, Event, Listen, State, } from "@stencil/core";
|
|
2
2
|
import flatpickr from "flatpickr";
|
|
3
3
|
import { Italian } from "flatpickr/dist/l10n/it.js";
|
|
4
4
|
import monthSelectPlugin from "flatpickr/dist/plugins/monthSelect";
|
|
@@ -13,16 +13,55 @@ export class ZDatePicker {
|
|
|
13
13
|
emitDateSelect(date) {
|
|
14
14
|
this.dateSelect.emit(date);
|
|
15
15
|
}
|
|
16
|
+
handleKeyDown(ev) {
|
|
17
|
+
if (ev.key === "Enter" || ev.key === " ") {
|
|
18
|
+
let isPrevArrowEntered = document.activeElement.classList.contains("flatpickr-prev-month");
|
|
19
|
+
let isNextArrowEntered = document.activeElement.classList.contains("flatpickr-next-month");
|
|
20
|
+
let arrowPressed = isPrevArrowEntered || isNextArrowEntered;
|
|
21
|
+
arrowPressed && ev.key === " " && ev.preventDefault();
|
|
22
|
+
if (this.mode === ZDatePickerMode.months) {
|
|
23
|
+
isPrevArrowEntered &&
|
|
24
|
+
this.flatpickrInstance.changeYear(this.flatpickrInstance.currentYear - 1);
|
|
25
|
+
isNextArrowEntered &&
|
|
26
|
+
this.flatpickrInstance.changeYear(this.flatpickrInstance.currentYear + 1);
|
|
27
|
+
if (arrowPressed) {
|
|
28
|
+
let calendar = this.element.getElementsByClassName("flatpickr-calendar")[0];
|
|
29
|
+
let months = calendar.querySelectorAll(".flatpickr-monthSelect-month");
|
|
30
|
+
months.forEach((element) => {
|
|
31
|
+
element.setAttribute("aria-label", `${element.innerHTML} ${this.flatpickrInstance.currentYear}`);
|
|
32
|
+
});
|
|
33
|
+
//Force check of the current day
|
|
34
|
+
Array.from(months).forEach((element, index) => {
|
|
35
|
+
let curMonth = new Date().getMonth();
|
|
36
|
+
let curYear = new Date().getFullYear();
|
|
37
|
+
if (index === curMonth) {
|
|
38
|
+
if (this.flatpickrInstance.currentYear === curYear) {
|
|
39
|
+
element.setAttribute("class", "flatpickr-monthSelect-month today");
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
element.setAttribute("class", "flatpickr-monthSelect-month");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
isPrevArrowEntered && this.flatpickrInstance.changeMonth(-1);
|
|
50
|
+
isNextArrowEntered && this.flatpickrInstance.changeMonth(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
16
54
|
componentWillLoad() {
|
|
17
55
|
let customToggle = this.element.querySelector("[slot=toggle]");
|
|
18
56
|
this.hasChildren = !!customToggle;
|
|
19
57
|
this.hasChildren && customToggle.setAttribute("data-toggle", "data-toggle");
|
|
20
58
|
}
|
|
21
59
|
componentDidLoad() {
|
|
22
|
-
flatpickr(`.${this.datepickerid}`, {
|
|
60
|
+
this.flatpickrInstance = flatpickr(`.${this.datepickerid}`, {
|
|
23
61
|
appendTo: this.element.children[0],
|
|
24
62
|
enableTime: this.mode === ZDatePickerMode.dateTime,
|
|
25
63
|
locale: Italian,
|
|
64
|
+
allowInput: true,
|
|
26
65
|
dateFormat: this.mode === ZDatePickerMode.dateTime ? "d-m-Y - H:i" : "d-m-Y",
|
|
27
66
|
ariaDateFormat: this.mode === ZDatePickerMode.months ? "F Y" : "d F Y",
|
|
28
67
|
minuteIncrement: 1,
|
|
@@ -30,6 +69,13 @@ export class ZDatePicker {
|
|
|
30
69
|
onChange: (_selectedDates, dateStr) => {
|
|
31
70
|
this.emitDateSelect(dateStr);
|
|
32
71
|
},
|
|
72
|
+
onOpen: () => {
|
|
73
|
+
this.setAriaOptions();
|
|
74
|
+
this.setFlatpickrPosition();
|
|
75
|
+
},
|
|
76
|
+
onKeyDown: () => {
|
|
77
|
+
this.setAriaOptions();
|
|
78
|
+
},
|
|
33
79
|
wrap: this.hasChildren,
|
|
34
80
|
plugins: this.mode === ZDatePickerMode.months && [
|
|
35
81
|
monthSelectPlugin({
|
|
@@ -42,6 +88,60 @@ export class ZDatePicker {
|
|
|
42
88
|
element.innerHTML = element.innerHTML.trim().charAt(0);
|
|
43
89
|
});
|
|
44
90
|
}
|
|
91
|
+
setAriaOptions() {
|
|
92
|
+
let calendar = this.element.getElementsByClassName("flatpickr-calendar")[0];
|
|
93
|
+
let prevMonthArrow = calendar.getElementsByClassName("flatpickr-prev-month")[0];
|
|
94
|
+
let nextMonthArrow = calendar.getElementsByClassName("flatpickr-next-month")[0];
|
|
95
|
+
let tabindexElements = calendar.querySelectorAll('[tabindex = "-1"]');
|
|
96
|
+
tabindexElements.forEach((element) => element.setAttribute("tabindex", "0"));
|
|
97
|
+
prevMonthArrow.setAttribute("tabindex", "0");
|
|
98
|
+
nextMonthArrow.setAttribute("tabindex", "0");
|
|
99
|
+
prevMonthArrow.setAttribute("role", "button");
|
|
100
|
+
nextMonthArrow.setAttribute("role", "button");
|
|
101
|
+
calendar
|
|
102
|
+
.getElementsByClassName("cur-year")[0]
|
|
103
|
+
.setAttribute("aria-label", "Anno");
|
|
104
|
+
if (this.mode === ZDatePickerMode.months) {
|
|
105
|
+
this.setMonthsAriaOptions(calendar, prevMonthArrow, nextMonthArrow);
|
|
106
|
+
}
|
|
107
|
+
if (this.mode === ZDatePickerMode.date) {
|
|
108
|
+
this.setDateAriaOptions(calendar, prevMonthArrow, nextMonthArrow);
|
|
109
|
+
}
|
|
110
|
+
if (this.mode === ZDatePickerMode.dateTime) {
|
|
111
|
+
this.setDateTimeAriaOptions(calendar, prevMonthArrow, nextMonthArrow);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
setMonthsAriaOptions(calendar, prevMonthArrow, nextMonthArrow) {
|
|
115
|
+
Array.from(calendar.getElementsByClassName("flatpickr-monthSelect-months")).forEach((element) => element.setAttribute("tabindex", "-1"));
|
|
116
|
+
Array.from(calendar.getElementsByClassName("flatpickr-monthSelect-month")).forEach((element) => element.setAttribute("role", "button"));
|
|
117
|
+
prevMonthArrow.setAttribute("aria-label", "Anno precedente");
|
|
118
|
+
nextMonthArrow.setAttribute("aria-label", "Anno successivo");
|
|
119
|
+
}
|
|
120
|
+
setDateAriaOptions(calendar, prevMonthArrow, nextMonthArrow) {
|
|
121
|
+
Array.from(calendar.getElementsByClassName("flatpickr-days")).forEach((element) => element.setAttribute("tabindex", "-1"));
|
|
122
|
+
Array.from(calendar.getElementsByClassName("flatpickr-day")).forEach((element) => element.setAttribute("role", "button"));
|
|
123
|
+
calendar
|
|
124
|
+
.getElementsByClassName("flatpickr-monthDropdown-months")[0]
|
|
125
|
+
.setAttribute("aria-label", "Mese");
|
|
126
|
+
prevMonthArrow.setAttribute("aria-label", "Mese precedente");
|
|
127
|
+
nextMonthArrow.setAttribute("aria-label", "Mese successivo");
|
|
128
|
+
}
|
|
129
|
+
setDateTimeAriaOptions(calendar, prevMonthArrow, nextMonthArrow) {
|
|
130
|
+
Array.from(calendar.getElementsByClassName("flatpickr-days")).forEach((element) => element.setAttribute("tabindex", "-1"));
|
|
131
|
+
Array.from(calendar.getElementsByClassName("flatpickr-day")).forEach((element) => element.setAttribute("role", "button"));
|
|
132
|
+
calendar
|
|
133
|
+
.getElementsByClassName("flatpickr-monthDropdown-months")[0]
|
|
134
|
+
.setAttribute("aria-label", "Mese");
|
|
135
|
+
prevMonthArrow.setAttribute("aria-label", "Mese precedente");
|
|
136
|
+
nextMonthArrow.setAttribute("aria-label", "Mese successivo");
|
|
137
|
+
Array.from(calendar.getElementsByClassName("time24hr")).forEach((element) => element.setAttribute("tabindex", "-1"));
|
|
138
|
+
calendar
|
|
139
|
+
.getElementsByClassName("flatpickr-hour")[0]
|
|
140
|
+
.setAttribute("aria-label", "Ora");
|
|
141
|
+
calendar
|
|
142
|
+
.getElementsByClassName("flatpickr-minute")[0]
|
|
143
|
+
.setAttribute("aria-label", "Minuti");
|
|
144
|
+
}
|
|
45
145
|
setFlatpickrPosition() {
|
|
46
146
|
const toggleHeight = this.element.children[0].clientHeight;
|
|
47
147
|
this.element.style.setProperty("--toggle-height", `${toggleHeight}px`);
|
|
@@ -66,10 +166,10 @@ export class ZDatePicker {
|
|
|
66
166
|
h("slot", { name: "toggle" })));
|
|
67
167
|
}
|
|
68
168
|
renderZInput() {
|
|
69
|
-
return (h("z-input", { class: classNames(this.datepickerid), type: "text",
|
|
169
|
+
return (h("z-input", { class: classNames(this.datepickerid), type: "text", icon: "event", hasmessage: false, tabindex: "0" }));
|
|
70
170
|
}
|
|
71
171
|
render() {
|
|
72
|
-
return (h("div", { class: classNames("flatpickr-toggle-container", this.hasChildren && this.datepickerid, this.flatpickrPosition, this.mode)
|
|
172
|
+
return (h("div", { class: classNames("flatpickr-toggle-container", this.hasChildren && this.datepickerid, this.flatpickrPosition, this.mode) }, this.hasChildren ? this.renderSlottedContent() : this.renderZInput()));
|
|
73
173
|
}
|
|
74
174
|
static get is() { return "z-date-picker"; }
|
|
75
175
|
static get originalStyleUrls() { return {
|
|
@@ -140,4 +240,11 @@ export class ZDatePicker {
|
|
|
140
240
|
}
|
|
141
241
|
}]; }
|
|
142
242
|
static get elementRef() { return "element"; }
|
|
243
|
+
static get listeners() { return [{
|
|
244
|
+
"name": "keydown",
|
|
245
|
+
"method": "handleKeyDown",
|
|
246
|
+
"target": "body",
|
|
247
|
+
"capture": true,
|
|
248
|
+
"passive": false
|
|
249
|
+
}]; }
|
|
143
250
|
}
|
|
@@ -257,11 +257,15 @@ z-date-picker > div > * {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
.flatpickr-next-month:hover,
|
|
260
|
-
.flatpickr-prev-month:hover
|
|
260
|
+
.flatpickr-prev-month:hover,
|
|
261
|
+
.flatpickr-next-month:focus,
|
|
262
|
+
.flatpickr-prev-month:focus {
|
|
261
263
|
border-radius: var(--border-radius);
|
|
262
264
|
background-color: var(--color-primary03) !important;
|
|
263
265
|
border-color: var(--color-primary03) !important;
|
|
264
266
|
color: var(--color-hover-primary) !important;
|
|
267
|
+
border: none !important;
|
|
268
|
+
outline: none !important;
|
|
265
269
|
}
|
|
266
270
|
|
|
267
271
|
.flatpickr-next-month:hover svg,
|
|
@@ -296,7 +300,8 @@ z-date-picker > div > * {
|
|
|
296
300
|
padding-left: var(--space-unit) !important;
|
|
297
301
|
}
|
|
298
302
|
|
|
299
|
-
.flatpickr-monthDropdown-months:hover
|
|
303
|
+
.flatpickr-monthDropdown-months:hover,
|
|
304
|
+
.flatpickr-monthDropdown-months:focus {
|
|
300
305
|
outline: 1px solid var(--color-primary01) !important;
|
|
301
306
|
}
|
|
302
307
|
|
|
@@ -311,7 +316,8 @@ z-date-picker > div > * {
|
|
|
311
316
|
width: calc(var(--space-unit) * 10);
|
|
312
317
|
}
|
|
313
318
|
|
|
314
|
-
.flatpickr-current-month > .numInputWrapper:hover
|
|
319
|
+
.flatpickr-current-month > .numInputWrapper:hover,
|
|
320
|
+
.flatpickr-current-month > .numInputWrapper:focus-within {
|
|
315
321
|
outline: 1px solid var(--color-primary01) !important;
|
|
316
322
|
}
|
|
317
323
|
|
|
@@ -368,7 +374,8 @@ z-date-picker > div > * {
|
|
|
368
374
|
.flatpickr-day:hover,
|
|
369
375
|
.flatpickr-day.prevMonthDay:hover,
|
|
370
376
|
.flatpickr-day.selected:hover,
|
|
371
|
-
.flatpickr-monthSelect-month:hover
|
|
377
|
+
.flatpickr-monthSelect-month:hover,
|
|
378
|
+
.flatpickr-monthSelect-month:focus {
|
|
372
379
|
background-color: var(--myz-blue-dark) !important;
|
|
373
380
|
border-color: var(--myz-blue-dark) !important;
|
|
374
381
|
color: var(--color-white) !important;
|
|
@@ -441,6 +448,9 @@ z-date-picker > div > * {
|
|
|
441
448
|
|
|
442
449
|
.flatpickr-minute,
|
|
443
450
|
.flatpickr-hour {
|
|
451
|
+
font-size: var(--font-size-3) !important;
|
|
452
|
+
font-weight: var(--font-rg) !important;
|
|
453
|
+
|
|
444
454
|
outline: 1px solid black !important;
|
|
445
455
|
}
|
|
446
456
|
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { Component, Prop, h, Element, Event, Watch, State, Listen, } from "@stencil/core";
|
|
2
|
+
/**
|
|
3
|
+
* Pagination bar component.
|
|
4
|
+
*/
|
|
5
|
+
export class ZPagination {
|
|
6
|
+
constructor() {
|
|
7
|
+
/** Enable navigation arrows. */
|
|
8
|
+
this.navArrows = true;
|
|
9
|
+
/** Number of pages to skip. */
|
|
10
|
+
this.skip = 0;
|
|
11
|
+
/** Enable buttons to go to the first and last pages. */
|
|
12
|
+
this.edges = false;
|
|
13
|
+
/** Current page. */
|
|
14
|
+
this.currentPage = 1;
|
|
15
|
+
/**
|
|
16
|
+
* Internal visible pages variable.
|
|
17
|
+
* Needed to better handle conflicting props like `visiblePages` and `split`.
|
|
18
|
+
* This state will change based on props values and validation,
|
|
19
|
+
* keeping original `visiblePages` value intact.
|
|
20
|
+
*/
|
|
21
|
+
this._visiblePages = this.visiblePages;
|
|
22
|
+
/** Used to hides/change some functionalities on smaller screen sizes */
|
|
23
|
+
this.isMobile = false;
|
|
24
|
+
/** Value of the go to page input */
|
|
25
|
+
this.goToPageValue = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set the max width of the pages container.
|
|
29
|
+
*/
|
|
30
|
+
setPagesContainerWidth() {
|
|
31
|
+
if (!this._visiblePages || this.split) {
|
|
32
|
+
this.host.style.setProperty("--z-pagination--pages-container-max-width", "100%");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const pagesContainerStyle = window.getComputedStyle(this.host);
|
|
36
|
+
const pageButtonWidth = pagesContainerStyle.getPropertyValue("--z-pagination--page-button-width");
|
|
37
|
+
this.host.style.setProperty("--z-pagination--pages-container-max-width", `calc(${pageButtonWidth} * ${this._visiblePages})`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set visible pages.
|
|
41
|
+
* Ensure that the visible pages are always <= the total pages.
|
|
42
|
+
* If `visiblePages` isn't set, fallback to the total pages.
|
|
43
|
+
*/
|
|
44
|
+
setVisiblePages() {
|
|
45
|
+
this._visiblePages = Math.min(this.visiblePages || this.totalPages, this.totalPages);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* On page changed.
|
|
49
|
+
* @emits pageChanged
|
|
50
|
+
*/
|
|
51
|
+
onPageChanged() {
|
|
52
|
+
this.pageChanged.emit(this.currentPage);
|
|
53
|
+
this.scrollToPage();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* On split changed.
|
|
57
|
+
* Empty `edges` value. The split feature wins over the pages chunks and edges.
|
|
58
|
+
*/
|
|
59
|
+
onSplitChanged() {
|
|
60
|
+
if (this.split) {
|
|
61
|
+
this.edges = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hide stuff on mobile.
|
|
66
|
+
*/
|
|
67
|
+
onResize() {
|
|
68
|
+
this.setMobile();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set functionalities according to screen size.
|
|
72
|
+
*/
|
|
73
|
+
setMobile() {
|
|
74
|
+
const mobileMediaQuery = "screen and (max-width: 767px)";
|
|
75
|
+
this.isMobile = window.matchMedia(mobileMediaQuery).matches;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get a list of pages chunks, each of `visiblePages` length.
|
|
79
|
+
* @returns {number[][]}
|
|
80
|
+
*/
|
|
81
|
+
getPagesChunks() {
|
|
82
|
+
// array of numbers from 1 to `totalPages`
|
|
83
|
+
const pages = Array.from({ length: this.totalPages }, (_, i) => i + 1);
|
|
84
|
+
let chunks = [];
|
|
85
|
+
const chunksCount = Math.ceil(pages.length / this._visiblePages);
|
|
86
|
+
for (let index = 0; index < chunksCount; index++) {
|
|
87
|
+
chunks.push(pages.slice(index * this._visiblePages, (index + 1) * this._visiblePages));
|
|
88
|
+
}
|
|
89
|
+
return chunks;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Scroll to the left the chunk of pages containing the current page.
|
|
93
|
+
*/
|
|
94
|
+
scrollToPage() {
|
|
95
|
+
const pageBtn = this.host.querySelector(`[data-page="${this.currentPage}"]`);
|
|
96
|
+
if (!pageBtn) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
pageBtn.scrollIntoView({
|
|
100
|
+
behavior: "smooth",
|
|
101
|
+
block: "nearest",
|
|
102
|
+
inline: "center",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Select a page.
|
|
107
|
+
* Do validations on the passed value before assigning it to `currentPage`.
|
|
108
|
+
* @param {number} page Page number to set
|
|
109
|
+
*/
|
|
110
|
+
selectPage(page) {
|
|
111
|
+
this.currentPage = Math.min(Math.max(page, 1), this.totalPages);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Render page number button.
|
|
115
|
+
* @param {number} page Page number to render
|
|
116
|
+
* @returns {HTMLButtonElement}
|
|
117
|
+
*/
|
|
118
|
+
renderPage(page) {
|
|
119
|
+
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));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Render split button.
|
|
123
|
+
* @param {number} page Page to select on click.
|
|
124
|
+
* @returns {HTMLButtonElement}
|
|
125
|
+
*/
|
|
126
|
+
renderEllipsisButton(page) {
|
|
127
|
+
return (h("button", { class: "ellipsis-button", type: "button", title: `Vai alla pagina ${page}`, onClick: () => this.selectPage(page) }, "\u2026"));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Render chunked page buttons.
|
|
131
|
+
* @returns {HTMLDivElement}
|
|
132
|
+
*/
|
|
133
|
+
renderPages() {
|
|
134
|
+
const pagesChunks = this.getPagesChunks();
|
|
135
|
+
if (pagesChunks.length <= 0) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
return pagesChunks.map((chunk) => (h("div", { class: "pages-chunk" }, chunk.map((page) => this.renderPage(page)))));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Render page buttons when split feature is enabled.
|
|
142
|
+
* @returns {HTMLButtonElement[]}
|
|
143
|
+
*/
|
|
144
|
+
renderSplitPages() {
|
|
145
|
+
// left and right split pages, current page, first and last page, left and right ellipsis button
|
|
146
|
+
if (this.totalPages <= this.split * 2 + 5) {
|
|
147
|
+
// Too few pages: ellipsis will never be rendered, so let's just render all pages and that's it.
|
|
148
|
+
return Array.from({ length: this.totalPages }, (_, i) => this.renderPage(i + 1));
|
|
149
|
+
}
|
|
150
|
+
if (this.currentPage <= this.split * 2 + 2) {
|
|
151
|
+
// Render first (2 * split + 3) pages, ellipsis, then last page.
|
|
152
|
+
return [
|
|
153
|
+
...Array.from({ length: this.split * 2 + 3 }, (_, i) => this.renderPage(i + 1)),
|
|
154
|
+
this.renderEllipsisButton(this.split * 2 + 4),
|
|
155
|
+
this.renderPage(this.totalPages),
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
if (this.currentPage > this.split * 2 + 2 && this.currentPage < this.totalPages - this.split * 2 - 1) {
|
|
159
|
+
// Render first page, ellipsis, current page surrounded by (split) pages both before and after, another ellipsis, then last page.
|
|
160
|
+
return [
|
|
161
|
+
this.renderPage(1),
|
|
162
|
+
this.renderEllipsisButton(this.currentPage - this.split - 1),
|
|
163
|
+
...Array.from({ length: this.split * 2 + 1 }, (_, i) => this.renderPage(this.currentPage - this.split + i)),
|
|
164
|
+
this.renderEllipsisButton(this.currentPage + this.split + 1),
|
|
165
|
+
this.renderPage(this.totalPages),
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
// Render first page, ellipsis, then last (2 * split + 3) pages.
|
|
169
|
+
return [
|
|
170
|
+
this.renderPage(1),
|
|
171
|
+
this.renderEllipsisButton(this.totalPages - this.split * 2 - 3),
|
|
172
|
+
...Array.from({ length: this.split * 2 + 3 }, (_, i) => this.renderPage(this.totalPages - this.split * 2 - 2 + i)),
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
renderBackButton() {
|
|
176
|
+
return (h("button", { class: "navigation-button", type: "button", title: "Vai alla pagina precedente", disabled: this.currentPage === 1, onClick: () => this.selectPage(this.currentPage - 1) },
|
|
177
|
+
h("z-icon", { name: "chevron-left" })));
|
|
178
|
+
}
|
|
179
|
+
renderForwardButton() {
|
|
180
|
+
return (h("button", { class: "navigation-button", type: "button", title: "Vai alla prossima pagina", disabled: this.currentPage === this.totalPages, onClick: () => this.selectPage(this.currentPage + 1) },
|
|
181
|
+
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" },
|
|
188
|
+
this.renderBackButton(),
|
|
189
|
+
!this.goToPage && (h("div", { class: "pages-container", role: "navigation", tabIndex: -1 }, pagesChunks.length > 0 &&
|
|
190
|
+
pagesChunks.map((chunk) => (h("div", { class: "pages-chunk" }, chunk.map((page) => this.renderPage(page))))))),
|
|
191
|
+
this.goToPage && (h("form", { class: "mobile-go-to-page", onSubmit: (ev) => {
|
|
192
|
+
ev.preventDefault();
|
|
193
|
+
this.selectPage(this.goToPageValue);
|
|
194
|
+
} },
|
|
195
|
+
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 }),
|
|
196
|
+
h("span", null, `/${this.totalPages}`))),
|
|
197
|
+
this.renderForwardButton()),
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
componentDidLoad() {
|
|
201
|
+
this.setVisiblePages();
|
|
202
|
+
}
|
|
203
|
+
componentDidRender() {
|
|
204
|
+
if (this.split) {
|
|
205
|
+
this.edges = false;
|
|
206
|
+
}
|
|
207
|
+
this.setPagesContainerWidth();
|
|
208
|
+
this.setMobile();
|
|
209
|
+
}
|
|
210
|
+
render() {
|
|
211
|
+
if (this.isMobile) {
|
|
212
|
+
return this.renderMobile();
|
|
213
|
+
}
|
|
214
|
+
return [
|
|
215
|
+
h("div", { class: "pagination-bar" },
|
|
216
|
+
this.label && h("span", { class: "page-label body-1-sb" }, this.label),
|
|
217
|
+
this.edges && (h("button", { class: "pagination-button", type: "button", title: "Vai alla pagina 1", disabled: this.currentPage === 1, onClick: () => this.selectPage(1) }, "Pagina 1")),
|
|
218
|
+
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) },
|
|
219
|
+
"-",
|
|
220
|
+
this.skip)),
|
|
221
|
+
this.navArrows && this.renderBackButton(),
|
|
222
|
+
h("div", { class: "pages-container", role: "navigation", tabIndex: -1 }, this.split ?
|
|
223
|
+
this.renderSplitPages() :
|
|
224
|
+
this.renderPages()),
|
|
225
|
+
this.navArrows && this.renderForwardButton(),
|
|
226
|
+
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) },
|
|
227
|
+
"+",
|
|
228
|
+
this.skip)),
|
|
229
|
+
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) },
|
|
230
|
+
"Pagina ",
|
|
231
|
+
this.totalPages))),
|
|
232
|
+
this.goToPage && (h("div", { class: "go-to-page" },
|
|
233
|
+
h("span", { class: "label body-5-sb" }, "Vai a pagina:"),
|
|
234
|
+
h("div", { class: "inputs" },
|
|
235
|
+
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) }),
|
|
236
|
+
h("z-button", { disabled: !this.goToPageValue, title: "Vai alla pagina inserita", onClick: () => this.selectPage(this.goToPageValue) }, "vai")))),
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
static get is() { return "z-pagination"; }
|
|
240
|
+
static get originalStyleUrls() { return {
|
|
241
|
+
"$": ["styles.css"]
|
|
242
|
+
}; }
|
|
243
|
+
static get styleUrls() { return {
|
|
244
|
+
"$": ["styles.css"]
|
|
245
|
+
}; }
|
|
246
|
+
static get properties() { return {
|
|
247
|
+
"label": {
|
|
248
|
+
"type": "string",
|
|
249
|
+
"mutable": false,
|
|
250
|
+
"complexType": {
|
|
251
|
+
"original": "string",
|
|
252
|
+
"resolved": "string",
|
|
253
|
+
"references": {}
|
|
254
|
+
},
|
|
255
|
+
"required": false,
|
|
256
|
+
"optional": true,
|
|
257
|
+
"docs": {
|
|
258
|
+
"tags": [],
|
|
259
|
+
"text": "Pagination label placed before the bar."
|
|
260
|
+
},
|
|
261
|
+
"attribute": "label",
|
|
262
|
+
"reflect": false
|
|
263
|
+
},
|
|
264
|
+
"navArrows": {
|
|
265
|
+
"type": "boolean",
|
|
266
|
+
"mutable": false,
|
|
267
|
+
"complexType": {
|
|
268
|
+
"original": "boolean",
|
|
269
|
+
"resolved": "boolean",
|
|
270
|
+
"references": {}
|
|
271
|
+
},
|
|
272
|
+
"required": false,
|
|
273
|
+
"optional": false,
|
|
274
|
+
"docs": {
|
|
275
|
+
"tags": [],
|
|
276
|
+
"text": "Enable navigation arrows."
|
|
277
|
+
},
|
|
278
|
+
"attribute": "nav-arrows",
|
|
279
|
+
"reflect": false,
|
|
280
|
+
"defaultValue": "true"
|
|
281
|
+
},
|
|
282
|
+
"totalPages": {
|
|
283
|
+
"type": "number",
|
|
284
|
+
"mutable": false,
|
|
285
|
+
"complexType": {
|
|
286
|
+
"original": "number",
|
|
287
|
+
"resolved": "number",
|
|
288
|
+
"references": {}
|
|
289
|
+
},
|
|
290
|
+
"required": true,
|
|
291
|
+
"optional": false,
|
|
292
|
+
"docs": {
|
|
293
|
+
"tags": [],
|
|
294
|
+
"text": "Total number of pages. Required."
|
|
295
|
+
},
|
|
296
|
+
"attribute": "total-pages",
|
|
297
|
+
"reflect": false
|
|
298
|
+
},
|
|
299
|
+
"skip": {
|
|
300
|
+
"type": "number",
|
|
301
|
+
"mutable": false,
|
|
302
|
+
"complexType": {
|
|
303
|
+
"original": "number",
|
|
304
|
+
"resolved": "number",
|
|
305
|
+
"references": {}
|
|
306
|
+
},
|
|
307
|
+
"required": false,
|
|
308
|
+
"optional": false,
|
|
309
|
+
"docs": {
|
|
310
|
+
"tags": [],
|
|
311
|
+
"text": "Number of pages to skip."
|
|
312
|
+
},
|
|
313
|
+
"attribute": "skip",
|
|
314
|
+
"reflect": false,
|
|
315
|
+
"defaultValue": "0"
|
|
316
|
+
},
|
|
317
|
+
"edges": {
|
|
318
|
+
"type": "boolean",
|
|
319
|
+
"mutable": false,
|
|
320
|
+
"complexType": {
|
|
321
|
+
"original": "boolean",
|
|
322
|
+
"resolved": "boolean",
|
|
323
|
+
"references": {}
|
|
324
|
+
},
|
|
325
|
+
"required": false,
|
|
326
|
+
"optional": false,
|
|
327
|
+
"docs": {
|
|
328
|
+
"tags": [],
|
|
329
|
+
"text": "Enable buttons to go to the first and last pages."
|
|
330
|
+
},
|
|
331
|
+
"attribute": "edges",
|
|
332
|
+
"reflect": false,
|
|
333
|
+
"defaultValue": "false"
|
|
334
|
+
},
|
|
335
|
+
"split": {
|
|
336
|
+
"type": "number",
|
|
337
|
+
"mutable": false,
|
|
338
|
+
"complexType": {
|
|
339
|
+
"original": "number",
|
|
340
|
+
"resolved": "number",
|
|
341
|
+
"references": {}
|
|
342
|
+
},
|
|
343
|
+
"required": false,
|
|
344
|
+
"optional": true,
|
|
345
|
+
"docs": {
|
|
346
|
+
"tags": [],
|
|
347
|
+
"text": "Number of pages to show left/right of the current, before showing \"load more\" symbol (\u2026)."
|
|
348
|
+
},
|
|
349
|
+
"attribute": "split",
|
|
350
|
+
"reflect": false
|
|
351
|
+
},
|
|
352
|
+
"visiblePages": {
|
|
353
|
+
"type": "number",
|
|
354
|
+
"mutable": false,
|
|
355
|
+
"complexType": {
|
|
356
|
+
"original": "number",
|
|
357
|
+
"resolved": "number",
|
|
358
|
+
"references": {}
|
|
359
|
+
},
|
|
360
|
+
"required": false,
|
|
361
|
+
"optional": true,
|
|
362
|
+
"docs": {
|
|
363
|
+
"tags": [],
|
|
364
|
+
"text": "Number of pages to show at a time. If not set, all pages will be shown."
|
|
365
|
+
},
|
|
366
|
+
"attribute": "visible-pages",
|
|
367
|
+
"reflect": false
|
|
368
|
+
},
|
|
369
|
+
"currentPage": {
|
|
370
|
+
"type": "number",
|
|
371
|
+
"mutable": true,
|
|
372
|
+
"complexType": {
|
|
373
|
+
"original": "number",
|
|
374
|
+
"resolved": "number",
|
|
375
|
+
"references": {}
|
|
376
|
+
},
|
|
377
|
+
"required": false,
|
|
378
|
+
"optional": false,
|
|
379
|
+
"docs": {
|
|
380
|
+
"tags": [],
|
|
381
|
+
"text": "Current page."
|
|
382
|
+
},
|
|
383
|
+
"attribute": "current-page",
|
|
384
|
+
"reflect": false,
|
|
385
|
+
"defaultValue": "1"
|
|
386
|
+
},
|
|
387
|
+
"goToPage": {
|
|
388
|
+
"type": "boolean",
|
|
389
|
+
"mutable": false,
|
|
390
|
+
"complexType": {
|
|
391
|
+
"original": "boolean",
|
|
392
|
+
"resolved": "boolean",
|
|
393
|
+
"references": {}
|
|
394
|
+
},
|
|
395
|
+
"required": false,
|
|
396
|
+
"optional": false,
|
|
397
|
+
"docs": {
|
|
398
|
+
"tags": [],
|
|
399
|
+
"text": "Whether to show \"go to page\" feature."
|
|
400
|
+
},
|
|
401
|
+
"attribute": "go-to-page",
|
|
402
|
+
"reflect": false
|
|
403
|
+
}
|
|
404
|
+
}; }
|
|
405
|
+
static get states() { return {
|
|
406
|
+
"_visiblePages": {},
|
|
407
|
+
"isMobile": {},
|
|
408
|
+
"goToPageValue": {}
|
|
409
|
+
}; }
|
|
410
|
+
static get events() { return [{
|
|
411
|
+
"method": "pageChanged",
|
|
412
|
+
"name": "pageChanged",
|
|
413
|
+
"bubbles": true,
|
|
414
|
+
"cancelable": true,
|
|
415
|
+
"composed": true,
|
|
416
|
+
"docs": {
|
|
417
|
+
"tags": [],
|
|
418
|
+
"text": "Event emitted when the current page has changed."
|
|
419
|
+
},
|
|
420
|
+
"complexType": {
|
|
421
|
+
"original": "any",
|
|
422
|
+
"resolved": "any",
|
|
423
|
+
"references": {}
|
|
424
|
+
}
|
|
425
|
+
}]; }
|
|
426
|
+
static get elementRef() { return "host"; }
|
|
427
|
+
static get watchers() { return [{
|
|
428
|
+
"propName": "_visiblePages",
|
|
429
|
+
"methodName": "setPagesContainerWidth"
|
|
430
|
+
}, {
|
|
431
|
+
"propName": "visiblePages",
|
|
432
|
+
"methodName": "setVisiblePages"
|
|
433
|
+
}, {
|
|
434
|
+
"propName": "currentPage",
|
|
435
|
+
"methodName": "onPageChanged"
|
|
436
|
+
}, {
|
|
437
|
+
"propName": "split",
|
|
438
|
+
"methodName": "onSplitChanged"
|
|
439
|
+
}]; }
|
|
440
|
+
static get listeners() { return [{
|
|
441
|
+
"name": "resize",
|
|
442
|
+
"method": "onResize",
|
|
443
|
+
"target": "window",
|
|
444
|
+
"capture": false,
|
|
445
|
+
"passive": true
|
|
446
|
+
}]; }
|
|
447
|
+
}
|