@refinitiv-ui/elements 5.9.0 → 5.10.1
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/CHANGELOG.md +48 -4
- package/lib/button/themes/solar/charcoal/index.js +1 -1
- package/lib/button/themes/solar/pearl/index.js +1 -1
- package/lib/checkbox/index.js +0 -1
- package/lib/combo-box/themes/halo/dark/index.js +1 -1
- package/lib/combo-box/themes/halo/light/index.js +1 -1
- package/lib/combo-box/themes/solar/charcoal/index.js +1 -1
- package/lib/combo-box/themes/solar/pearl/index.js +1 -1
- package/lib/counter/themes/halo/dark/index.js +1 -1
- package/lib/counter/themes/halo/light/index.js +1 -1
- package/lib/label/index.js +2 -1
- package/lib/number-field/themes/solar/charcoal/index.js +1 -1
- package/lib/pagination/custom-elements.json +16 -33
- package/lib/pagination/custom-elements.md +8 -9
- package/lib/pagination/index.d.ts +142 -74
- package/lib/pagination/index.js +356 -202
- package/lib/pagination/themes/halo/dark/index.js +1 -1
- package/lib/pagination/themes/halo/light/index.js +1 -1
- package/lib/pagination/themes/solar/charcoal/index.js +1 -1
- package/lib/pagination/themes/solar/pearl/index.js +1 -1
- package/lib/radio-button/index.js +4 -1
- package/lib/toggle/themes/halo/dark/index.js +1 -1
- package/lib/toggle/themes/halo/light/index.js +1 -1
- package/lib/toggle/themes/solar/charcoal/index.js +1 -1
- package/lib/toggle/themes/solar/pearl/index.js +1 -1
- package/lib/tree/themes/halo/dark/index.js +1 -1
- package/lib/tree/themes/halo/light/index.js +1 -1
- package/lib/tree/themes/solar/charcoal/index.js +1 -1
- package/lib/tree/themes/solar/pearl/index.js +1 -1
- package/lib/tree-select/themes/halo/dark/index.js +1 -1
- package/lib/tree-select/themes/halo/light/index.js +1 -1
- package/lib/tree-select/themes/solar/charcoal/index.js +1 -1
- package/lib/tree-select/themes/solar/pearl/index.js +1 -1
- package/lib/version.js +1 -1
- package/package.json +10 -10
- package/lib/pagination/helpers/types.d.ts +0 -9
- package/lib/pagination/helpers/types.js +0 -1
package/lib/pagination/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { BasicElement, html, css } from '@refinitiv-ui/core';
|
|
2
|
+
import { BasicElement, html, css, WarningNotice, DeprecationNotice } from '@refinitiv-ui/core';
|
|
3
3
|
import { customElement } from '@refinitiv-ui/core/lib/decorators/custom-element.js';
|
|
4
4
|
import { property } from '@refinitiv-ui/core/lib/decorators/property.js';
|
|
5
|
+
import { state } from '@refinitiv-ui/core/lib/decorators/state.js';
|
|
5
6
|
import { query } from '@refinitiv-ui/core/lib/decorators/query.js';
|
|
6
7
|
import { VERSION } from '../version.js';
|
|
7
8
|
import '../button/index.js';
|
|
@@ -10,29 +11,42 @@ import '../layout/index.js';
|
|
|
10
11
|
import '../text-field/index.js';
|
|
11
12
|
import '@refinitiv-ui/phrasebook/lib/locale/en/pagination.js';
|
|
12
13
|
import { translate } from '@refinitiv-ui/translate';
|
|
14
|
+
const pageDeprecation = new DeprecationNotice('Property `page` is deprecated, use `value` instead.');
|
|
15
|
+
const pageSizeDeprecation = new DeprecationNotice('Property `pageSize ` is deprecated, use `max` instead.');
|
|
16
|
+
const totalItemsDeprecation = new DeprecationNotice('Property `totalItems ` is deprecated, use `max` instead.');
|
|
13
17
|
/**
|
|
14
18
|
* Used to control and navigate through multiple pages
|
|
15
|
-
* @fires
|
|
19
|
+
* @fires value-changed - Fired when the `value` property is changed
|
|
16
20
|
*/
|
|
17
21
|
let Pagination = class Pagination extends BasicElement {
|
|
18
22
|
constructor() {
|
|
19
23
|
super(...arguments);
|
|
20
24
|
/**
|
|
21
|
-
*
|
|
25
|
+
* Current page internal current page value
|
|
22
26
|
*/
|
|
23
|
-
this.
|
|
27
|
+
this._value = '';
|
|
24
28
|
/**
|
|
25
|
-
*
|
|
29
|
+
* Max page
|
|
26
30
|
*/
|
|
27
|
-
this.
|
|
31
|
+
this._max = '';
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
33
|
+
* Number of item per page internal value
|
|
34
|
+
* @deprecated
|
|
30
35
|
*/
|
|
31
|
-
this.
|
|
36
|
+
this._pageSize = '';
|
|
37
|
+
/**
|
|
38
|
+
* Total items internal value
|
|
39
|
+
* @deprecated
|
|
40
|
+
*/
|
|
41
|
+
this._totalItems = '';
|
|
32
42
|
/**
|
|
33
43
|
* Set state to disable
|
|
34
44
|
*/
|
|
35
45
|
this.disabled = false;
|
|
46
|
+
/**
|
|
47
|
+
* State for check the input focus
|
|
48
|
+
*/
|
|
49
|
+
this.inputFocused = false;
|
|
36
50
|
}
|
|
37
51
|
/**
|
|
38
52
|
* Element version number
|
|
@@ -42,208 +56,332 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
42
56
|
return VERSION;
|
|
43
57
|
}
|
|
44
58
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* and the internal template of the element.
|
|
48
|
-
* @return CSS template
|
|
59
|
+
* Internal current page
|
|
60
|
+
* @returns current page
|
|
49
61
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`;
|
|
62
|
+
get internalValue() {
|
|
63
|
+
let value = parseInt(this._value, 10) || 0;
|
|
64
|
+
if (value <= 0) {
|
|
65
|
+
value = 1;
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
57
68
|
}
|
|
58
69
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param changedProperties Map of changed properties with old values
|
|
61
|
-
* @returns {void}
|
|
70
|
+
* Current page
|
|
62
71
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
get value() {
|
|
73
|
+
return this._value;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set current page
|
|
77
|
+
* @param value current page
|
|
78
|
+
*/
|
|
79
|
+
set value(value) {
|
|
80
|
+
let newValue = value;
|
|
81
|
+
if (!newValue || !this.validatePage(newValue, true, 'value')) {
|
|
82
|
+
newValue = '';
|
|
67
83
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
this.updateButtons();
|
|
84
|
+
const oldValue = this._value;
|
|
85
|
+
if (oldValue !== newValue) {
|
|
86
|
+
this._value = newValue.toString();
|
|
72
87
|
}
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
this.requestUpdate('value', oldValue);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Internal max page
|
|
92
|
+
* @returns max page
|
|
93
|
+
*/
|
|
94
|
+
get internalMax() {
|
|
95
|
+
const max = parseInt(this._max, 10) || 0;
|
|
96
|
+
const pageSize = this.internalPageSize;
|
|
97
|
+
const totalItems = this.internalTotalitems;
|
|
98
|
+
if (!max && !totalItems) {
|
|
99
|
+
return Infinity;
|
|
75
100
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
101
|
+
else if (max >= 1) {
|
|
102
|
+
return max;
|
|
78
103
|
}
|
|
104
|
+
if (pageSize > 0) {
|
|
105
|
+
const totalPage = Math.ceil(totalItems / pageSize);
|
|
106
|
+
return totalPage >= 1 ? totalPage : 1;
|
|
107
|
+
}
|
|
108
|
+
return 1;
|
|
79
109
|
}
|
|
80
110
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @returns
|
|
111
|
+
* Max page
|
|
112
|
+
* @returns max page
|
|
113
|
+
*/
|
|
114
|
+
get max() {
|
|
115
|
+
return this._max;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set max page
|
|
119
|
+
* @param value max page
|
|
83
120
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (pageSize < 1) {
|
|
89
|
-
this.pageSize = '1';
|
|
121
|
+
set max(value) {
|
|
122
|
+
let newValue = value;
|
|
123
|
+
if (!newValue || !this.validatePage(value, true, 'max')) {
|
|
124
|
+
newValue = '';
|
|
90
125
|
}
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
const oldValue = this._max;
|
|
127
|
+
if (oldValue !== newValue) {
|
|
128
|
+
this._max = newValue.toString();
|
|
93
129
|
}
|
|
94
|
-
this.
|
|
130
|
+
this.requestUpdate('max', oldValue);
|
|
95
131
|
}
|
|
96
132
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @returns
|
|
133
|
+
* Current page
|
|
134
|
+
* @returns current page
|
|
135
|
+
* @deprecated
|
|
136
|
+
* @ignore
|
|
137
|
+
*/
|
|
138
|
+
get page() {
|
|
139
|
+
pageDeprecation.once();
|
|
140
|
+
return this._value;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Set current page
|
|
144
|
+
* @param value - Set current page
|
|
145
|
+
* @deprecated
|
|
146
|
+
* @ignore
|
|
99
147
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.totalItems = '0';
|
|
106
|
-
this.page = '1';
|
|
148
|
+
set page(value) {
|
|
149
|
+
pageDeprecation.show();
|
|
150
|
+
let newValue = value;
|
|
151
|
+
if (!newValue || !this.validatePage(value, true, 'page')) {
|
|
152
|
+
newValue = '';
|
|
107
153
|
}
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
const oldValue = this._value;
|
|
155
|
+
if (oldValue !== newValue) {
|
|
156
|
+
this._value = newValue.toString();
|
|
110
157
|
}
|
|
111
|
-
this.
|
|
158
|
+
this.requestUpdate('page', oldValue);
|
|
112
159
|
}
|
|
113
160
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @returns
|
|
161
|
+
* Number of item per page
|
|
162
|
+
* @returns number of items per page
|
|
163
|
+
* @deprecated
|
|
164
|
+
* @ignore
|
|
165
|
+
*/
|
|
166
|
+
get pageSize() {
|
|
167
|
+
pageSizeDeprecation.once();
|
|
168
|
+
return this._pageSize;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set number of item per page
|
|
172
|
+
* @param value - number of item per page
|
|
173
|
+
* @deprecated
|
|
174
|
+
* @ignore
|
|
116
175
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
176
|
+
set pageSize(value) {
|
|
177
|
+
pageSizeDeprecation.show();
|
|
178
|
+
let newValue = value;
|
|
179
|
+
if (!newValue || !this.validatePage(value, true, 'page-size')) {
|
|
180
|
+
newValue = '';
|
|
120
181
|
}
|
|
121
|
-
|
|
122
|
-
|
|
182
|
+
// Validate to show warning only, need to keep developer value.
|
|
183
|
+
// Check page still is in supported range if page-size changed
|
|
184
|
+
const newTotalPage = Math.ceil(this.internalTotalitems / (parseInt(newValue, 10) || 1)) || 1;
|
|
185
|
+
if (this.internalValue > newTotalPage) {
|
|
186
|
+
new WarningNotice(`${this.localName} : The specified value "${newValue}" of page-size caused the value of page property is out of supported range.`).show();
|
|
187
|
+
}
|
|
188
|
+
const oldValue = this._pageSize;
|
|
189
|
+
if (oldValue !== newValue) {
|
|
190
|
+
this._pageSize = newValue;
|
|
123
191
|
}
|
|
124
|
-
this.
|
|
125
|
-
// recalculate button state
|
|
126
|
-
this.updateButtons();
|
|
192
|
+
this.requestUpdate('pageSize', oldValue);
|
|
127
193
|
}
|
|
128
194
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @returns {void}
|
|
195
|
+
* Internal page size
|
|
196
|
+
* @deprecated
|
|
197
|
+
* @returns page size
|
|
133
198
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const firstPage = this.disabled || page <= 1;
|
|
137
|
-
const lastPage = this.disabled || page >= this.totalPage;
|
|
138
|
-
this.previousPageButton.disabled = firstPage;
|
|
139
|
-
this.firstPageButton.disabled = firstPage;
|
|
140
|
-
this.nextPageButton.disabled = lastPage;
|
|
141
|
-
this.lastPageButton.disabled = lastPage;
|
|
199
|
+
get internalPageSize() {
|
|
200
|
+
return parseInt(this._pageSize, 10);
|
|
142
201
|
}
|
|
143
202
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @
|
|
203
|
+
* Internal total items
|
|
204
|
+
* @returns total items
|
|
205
|
+
* @deprecated
|
|
147
206
|
*/
|
|
148
|
-
get
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (pageSize > 0) {
|
|
152
|
-
const totalPage = Math.ceil(totalItems / pageSize);
|
|
153
|
-
return totalPage > 0 ? totalPage : 1;
|
|
154
|
-
}
|
|
155
|
-
return 1;
|
|
207
|
+
get internalTotalitems() {
|
|
208
|
+
const totalItems = parseInt(this._totalItems, 10) || 0;
|
|
209
|
+
return totalItems >= 1 ? totalItems : 0;
|
|
156
210
|
}
|
|
157
211
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* @
|
|
162
|
-
* @param newPage a new page value
|
|
163
|
-
* @return return a new page value
|
|
212
|
+
* Total items
|
|
213
|
+
* @returns total items
|
|
214
|
+
* @deprecated
|
|
215
|
+
* @ignore
|
|
164
216
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
217
|
+
get totalItems() {
|
|
218
|
+
totalItemsDeprecation.once();
|
|
219
|
+
return this._totalItems;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Set total items
|
|
223
|
+
* @param value total items
|
|
224
|
+
* @deprecated
|
|
225
|
+
* @ignore
|
|
226
|
+
*/
|
|
227
|
+
set totalItems(value) {
|
|
228
|
+
totalItemsDeprecation.show();
|
|
229
|
+
let newValue = value;
|
|
230
|
+
if (!newValue || !this.validatePage(value, true, 'total-items')) {
|
|
231
|
+
newValue = '';
|
|
169
232
|
}
|
|
170
|
-
|
|
171
|
-
|
|
233
|
+
// Validate to show warning only, need to keep developer value.
|
|
234
|
+
// Check page still is in supported range if total-item changed
|
|
235
|
+
const newTotalPage = Math.ceil((parseInt(newValue, 10) || 1) / this.internalPageSize) || 1;
|
|
236
|
+
if (this.internalValue > newTotalPage) {
|
|
237
|
+
new WarningNotice(`${this.localName} : The specified value "${newValue}" of total-items caused the value of page property is out of supported range.`).show();
|
|
172
238
|
}
|
|
173
|
-
|
|
174
|
-
|
|
239
|
+
const oldValue = this._totalItems;
|
|
240
|
+
if (oldValue !== newValue) {
|
|
241
|
+
this._totalItems = newValue;
|
|
175
242
|
}
|
|
176
|
-
|
|
243
|
+
this.requestUpdate('totalItems', oldValue);
|
|
177
244
|
}
|
|
178
245
|
/**
|
|
179
|
-
* Get
|
|
180
|
-
* @returns
|
|
246
|
+
* Get infinite pagination state
|
|
247
|
+
* @returns infinite pagination state
|
|
181
248
|
*/
|
|
182
|
-
get
|
|
183
|
-
|
|
184
|
-
const pageSize = Number.parseInt(this.pageSize, 10);
|
|
185
|
-
const totalCount = Number.parseInt(this.totalItems, 10);
|
|
186
|
-
const from = ((page - 1) * pageSize) + 1;
|
|
187
|
-
const to = page * pageSize > totalCount ? totalCount : page * pageSize;
|
|
188
|
-
return {
|
|
189
|
-
from,
|
|
190
|
-
to,
|
|
191
|
-
totalCount,
|
|
192
|
-
pageSize
|
|
193
|
-
};
|
|
249
|
+
get infinitePaginate() {
|
|
250
|
+
return this.internalMax === Infinity; // internalMax always returns 1-Infinity
|
|
194
251
|
}
|
|
195
252
|
/**
|
|
196
|
-
*
|
|
197
|
-
* @returns
|
|
253
|
+
* Getter for display text in the input
|
|
254
|
+
* @returns input text
|
|
198
255
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
256
|
+
get inputText() {
|
|
257
|
+
if (this.inputFocused) {
|
|
258
|
+
return this.internalValue.toString();
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
return (this.infinitePaginate ? this.t('PAGE', { page: this.internalValue }) : this.t('PAGE_OF', { page: this.internalValue, pageTotal: this.internalMax }));
|
|
262
|
+
}
|
|
202
263
|
}
|
|
203
264
|
/**
|
|
204
|
-
*
|
|
205
|
-
* @returns {void}
|
|
265
|
+
* State for checking the first page button is available
|
|
206
266
|
*/
|
|
207
|
-
|
|
208
|
-
this.
|
|
209
|
-
setTimeout(() => {
|
|
210
|
-
this.input.select();
|
|
211
|
-
});
|
|
267
|
+
get useFirstButton() {
|
|
268
|
+
return !this.disabled && this.internalValue >= 2;
|
|
212
269
|
}
|
|
213
270
|
/**
|
|
214
|
-
*
|
|
215
|
-
|
|
216
|
-
|
|
271
|
+
* State for checking the previous page button is available
|
|
272
|
+
*/
|
|
273
|
+
get usePreviousButton() {
|
|
274
|
+
return this.useFirstButton;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* State for checking the next page button is available
|
|
278
|
+
*/
|
|
279
|
+
get useNextButton() {
|
|
280
|
+
return !this.disabled && this.internalValue < this.internalMax;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* State for checking the last page button is available
|
|
217
284
|
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
285
|
+
get useLastButton() {
|
|
286
|
+
return this.useNextButton && !this.infinitePaginate;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* @override
|
|
290
|
+
*/
|
|
291
|
+
updated(changedProperties) {
|
|
292
|
+
super.updated(changedProperties);
|
|
293
|
+
if (this.inputFocused && changedProperties.has('inputFocused')) {
|
|
294
|
+
void this.selectInput();
|
|
225
295
|
}
|
|
226
296
|
}
|
|
227
297
|
/**
|
|
228
|
-
*
|
|
298
|
+
* Validate page value which returns true when value is valid
|
|
299
|
+
* @param value value
|
|
300
|
+
* @param warning show warning message when value is invalid
|
|
301
|
+
* @param propName property name to show in warning message
|
|
302
|
+
* @returns result of validation
|
|
303
|
+
*/
|
|
304
|
+
validatePage(value, warning = false, propName = '') {
|
|
305
|
+
if ((/^[1-9]([0-9]+)?$/).test(value)) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (value !== null && warning && propName) {
|
|
310
|
+
new WarningNotice(`${this.localName} : The specified value "${value}" of ${propName} property is not valid, The value must be integer and greater than 0.`).show();
|
|
311
|
+
}
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Handles action when Enter and Tab key is press onto the input
|
|
229
317
|
* @param event Keyboard event
|
|
230
318
|
* @returns {void}
|
|
231
319
|
*/
|
|
232
320
|
onInputKeyDown(event) {
|
|
233
321
|
var _a, _b;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
322
|
+
const isEnter = event.key === 'Enter' || event.keyCode === 13;
|
|
323
|
+
const isTab = event.key === 'Tab' || event.keyCode === 9;
|
|
324
|
+
if (isEnter || isTab) {
|
|
325
|
+
this.updatePageInput();
|
|
326
|
+
if (isEnter) {
|
|
327
|
+
this.input.blur();
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
/**
|
|
330
|
+
* Issue only in firefox
|
|
331
|
+
* cannot blur() or focus() to this.input so create a temp to this.input loses focus
|
|
332
|
+
*/
|
|
333
|
+
const temp = document.createElement('input');
|
|
334
|
+
(_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.appendChild(temp);
|
|
335
|
+
temp.focus();
|
|
336
|
+
this.input.blur();
|
|
337
|
+
(_b = this.shadowRoot) === null || _b === void 0 ? void 0 : _b.removeChild(temp);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Handles action when input focused change
|
|
343
|
+
* @param event focus change event
|
|
344
|
+
* @returns {void}
|
|
345
|
+
*/
|
|
346
|
+
onInputFocusedChanged(event) {
|
|
347
|
+
this.inputFocused = event.detail.value;
|
|
348
|
+
if (!this.inputFocused) {
|
|
349
|
+
this.updatePageInput();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Update page by using value from the input
|
|
354
|
+
* @returns {void}
|
|
355
|
+
*/
|
|
356
|
+
updatePageInput() {
|
|
357
|
+
// Prevent update page to the same value
|
|
358
|
+
if (this.value === this.input.value) {
|
|
359
|
+
return;
|
|
246
360
|
}
|
|
361
|
+
const oldValue = this.value;
|
|
362
|
+
let newValue = parseInt(this.input.value, 10);
|
|
363
|
+
// Reset input and boundary value into supported range.
|
|
364
|
+
if (this.validatePage(this.input.value)) {
|
|
365
|
+
if (newValue > this.internalMax) {
|
|
366
|
+
newValue = this.internalMax;
|
|
367
|
+
}
|
|
368
|
+
this.value = newValue.toString();
|
|
369
|
+
}
|
|
370
|
+
// When input value is invalid in case less than support range (value<1), then reset value = '1'.
|
|
371
|
+
else if (!isNaN(newValue) && newValue < 1) {
|
|
372
|
+
this.value = '1';
|
|
373
|
+
}
|
|
374
|
+
if (this.value !== oldValue) {
|
|
375
|
+
this.notifyValueChange();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Select text in input when update element complete
|
|
380
|
+
* @returns returns a promise void
|
|
381
|
+
*/
|
|
382
|
+
async selectInput() {
|
|
383
|
+
await this.updateComplete;
|
|
384
|
+
this.input.select();
|
|
247
385
|
}
|
|
248
386
|
/**
|
|
249
387
|
* Updates page value depending on direction
|
|
@@ -252,21 +390,35 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
252
390
|
* @returns {void}
|
|
253
391
|
*/
|
|
254
392
|
updatePage(direction, event = false) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Handle in case the value of max property is greater than value of value/page property,
|
|
395
|
+
* which it might happen by using developer API.
|
|
396
|
+
*/
|
|
397
|
+
let page = this.internalValue;
|
|
398
|
+
if (page > this.internalMax) {
|
|
399
|
+
page = this.internalMax + 1;
|
|
400
|
+
}
|
|
401
|
+
const limit = direction === 'increment' ? page >= this.internalMax : page <= 1;
|
|
402
|
+
if (!limit) {
|
|
403
|
+
this.value = direction === 'increment' ? (page + 1).toString() : (page - 1).toString();
|
|
259
404
|
if (event) {
|
|
260
|
-
this.
|
|
405
|
+
this.notifyValueChange();
|
|
261
406
|
}
|
|
262
407
|
}
|
|
263
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Fires event when value change
|
|
411
|
+
* @returns {void}
|
|
412
|
+
*/
|
|
413
|
+
notifyValueChange() {
|
|
414
|
+
this.notifyPropertyChange('value', this.value);
|
|
415
|
+
this.notifyPropertyChange('page', this.value); // deprecated. support backwards compatibility.
|
|
416
|
+
}
|
|
264
417
|
/**
|
|
265
418
|
* Go to the next page
|
|
266
419
|
* @returns {void}
|
|
267
420
|
*/
|
|
268
421
|
next() {
|
|
269
|
-
this.input.blur();
|
|
270
422
|
this.updatePage('increment');
|
|
271
423
|
}
|
|
272
424
|
/**
|
|
@@ -274,7 +426,6 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
274
426
|
* @returns {void}
|
|
275
427
|
*/
|
|
276
428
|
onNextTap() {
|
|
277
|
-
this.input.blur();
|
|
278
429
|
this.updatePage('increment', true);
|
|
279
430
|
}
|
|
280
431
|
/**
|
|
@@ -282,15 +433,13 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
282
433
|
* @returns {void}
|
|
283
434
|
*/
|
|
284
435
|
previous() {
|
|
285
|
-
this.input.blur();
|
|
286
436
|
this.updatePage('decrement');
|
|
287
437
|
}
|
|
288
438
|
/**
|
|
289
|
-
* Go to the previous page and fires
|
|
439
|
+
* Go to the previous page and fires event
|
|
290
440
|
* @returns {void}
|
|
291
441
|
*/
|
|
292
442
|
onPreviousTap() {
|
|
293
|
-
this.input.blur();
|
|
294
443
|
this.updatePage('decrement', true);
|
|
295
444
|
}
|
|
296
445
|
/**
|
|
@@ -298,8 +447,7 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
298
447
|
* @returns {void}
|
|
299
448
|
*/
|
|
300
449
|
first() {
|
|
301
|
-
this.
|
|
302
|
-
this.page = '1';
|
|
450
|
+
this.value = '1';
|
|
303
451
|
}
|
|
304
452
|
/**
|
|
305
453
|
* Go to the first page and fires event
|
|
@@ -307,15 +455,18 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
307
455
|
*/
|
|
308
456
|
onFirstTap() {
|
|
309
457
|
this.first();
|
|
310
|
-
this.
|
|
458
|
+
this.notifyValueChange();
|
|
311
459
|
}
|
|
312
460
|
/**
|
|
313
461
|
* Go to the last page
|
|
314
462
|
* @returns {void}
|
|
315
463
|
*/
|
|
316
464
|
last() {
|
|
317
|
-
this.
|
|
318
|
-
|
|
465
|
+
if (this.infinitePaginate) {
|
|
466
|
+
new WarningNotice(`${this.localName}: Cannot call "last()" when "max" attribute/property is unset.`).show();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
this.value = this.internalMax.toString();
|
|
319
470
|
}
|
|
320
471
|
/**
|
|
321
472
|
* Go to the last page and fires event
|
|
@@ -323,35 +474,44 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
323
474
|
*/
|
|
324
475
|
onLastTap() {
|
|
325
476
|
this.last();
|
|
326
|
-
this.
|
|
477
|
+
this.notifyValueChange();
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* A `CSSResultGroup` that will be used
|
|
481
|
+
* to style the host, slotted children
|
|
482
|
+
* and the internal template of the element.
|
|
483
|
+
* @return CSS template
|
|
484
|
+
*/
|
|
485
|
+
static get styles() {
|
|
486
|
+
return css `
|
|
487
|
+
:host {
|
|
488
|
+
display: inline-block;
|
|
489
|
+
}
|
|
490
|
+
`;
|
|
327
491
|
}
|
|
328
492
|
/**
|
|
329
493
|
* A `TemplateResult` that will be used
|
|
330
494
|
* to render the updated internal template.
|
|
331
|
-
* @return
|
|
495
|
+
* @return Render template
|
|
332
496
|
*/
|
|
333
497
|
render() {
|
|
334
498
|
return html `
|
|
335
|
-
<ef-layout part="container" flex nowrap
|
|
336
|
-
<div id="info" part="info">${this.t('ITEM_INFO', this.pageInfo)}</div>
|
|
499
|
+
<ef-layout part="container" flex nowrap>
|
|
337
500
|
<ef-button-bar part="buttons">
|
|
338
|
-
<ef-button id="first" icon="skip-to-start" @tap="${this.onFirstTap}"></ef-button>
|
|
339
|
-
<ef-button id="previous" icon="left" @tap="${this.onPreviousTap}"></ef-button>
|
|
501
|
+
<ef-button id="first" icon="skip-to-start" @tap="${this.onFirstTap}" .disabled=${!this.useFirstButton}></ef-button>
|
|
502
|
+
<ef-button id="previous" icon="left" @tap="${this.onPreviousTap}" .disabled=${!this.usePreviousButton}></ef-button>
|
|
340
503
|
</ef-button-bar>
|
|
341
504
|
<ef-text-field
|
|
342
505
|
id="input"
|
|
343
506
|
part="input"
|
|
344
|
-
@
|
|
345
|
-
@
|
|
346
|
-
|
|
347
|
-
.
|
|
348
|
-
page: this.page,
|
|
349
|
-
pageTotal: this.totalPage
|
|
350
|
-
})}"
|
|
507
|
+
@focused-changed=${this.onInputFocusedChanged}
|
|
508
|
+
@keydown=${this.onInputKeyDown}
|
|
509
|
+
.value=${this.inputText}
|
|
510
|
+
.disabled=${this.disabled}
|
|
351
511
|
no-spinner></ef-text-field>
|
|
352
512
|
<ef-button-bar part="buttons">
|
|
353
|
-
<ef-button id="next" icon="right" @tap="${this.onNextTap}"></ef-button>
|
|
354
|
-
<ef-button id="last" icon="skip-to-end" @tap="${this.onLastTap}"></ef-button>
|
|
513
|
+
<ef-button id="next" icon="right" @tap="${this.onNextTap}" .disabled=${!this.useNextButton}></ef-button>
|
|
514
|
+
<ef-button id="last" icon="skip-to-end" @tap="${this.onLastTap}" .disabled=${!this.useLastButton}></ef-button>
|
|
355
515
|
</ef-button-bar>
|
|
356
516
|
</ef-layout>
|
|
357
517
|
`;
|
|
@@ -359,37 +519,31 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
359
519
|
};
|
|
360
520
|
__decorate([
|
|
361
521
|
property({ type: String })
|
|
362
|
-
], Pagination.prototype, "
|
|
522
|
+
], Pagination.prototype, "value", null);
|
|
523
|
+
__decorate([
|
|
524
|
+
property({ type: String })
|
|
525
|
+
], Pagination.prototype, "max", null);
|
|
526
|
+
__decorate([
|
|
527
|
+
property({ type: String })
|
|
528
|
+
], Pagination.prototype, "page", null);
|
|
363
529
|
__decorate([
|
|
364
530
|
property({ type: String, attribute: 'page-size' })
|
|
365
|
-
], Pagination.prototype, "pageSize",
|
|
531
|
+
], Pagination.prototype, "pageSize", null);
|
|
366
532
|
__decorate([
|
|
367
533
|
property({ type: String, attribute: 'total-items' })
|
|
368
|
-
], Pagination.prototype, "totalItems",
|
|
534
|
+
], Pagination.prototype, "totalItems", null);
|
|
369
535
|
__decorate([
|
|
370
536
|
property({ type: Boolean, reflect: true })
|
|
371
537
|
], Pagination.prototype, "disabled", void 0);
|
|
372
|
-
__decorate([
|
|
373
|
-
query('#info')
|
|
374
|
-
], Pagination.prototype, "infoElement", void 0);
|
|
375
538
|
__decorate([
|
|
376
539
|
query('#input')
|
|
377
540
|
], Pagination.prototype, "input", void 0);
|
|
378
|
-
__decorate([
|
|
379
|
-
query('#first')
|
|
380
|
-
], Pagination.prototype, "firstPageButton", void 0);
|
|
381
|
-
__decorate([
|
|
382
|
-
query('#previous')
|
|
383
|
-
], Pagination.prototype, "previousPageButton", void 0);
|
|
384
|
-
__decorate([
|
|
385
|
-
query('#next')
|
|
386
|
-
], Pagination.prototype, "nextPageButton", void 0);
|
|
387
|
-
__decorate([
|
|
388
|
-
query('#last')
|
|
389
|
-
], Pagination.prototype, "lastPageButton", void 0);
|
|
390
541
|
__decorate([
|
|
391
542
|
translate()
|
|
392
543
|
], Pagination.prototype, "t", void 0);
|
|
544
|
+
__decorate([
|
|
545
|
+
state()
|
|
546
|
+
], Pagination.prototype, "inputFocused", void 0);
|
|
393
547
|
Pagination = __decorate([
|
|
394
548
|
customElement('ef-pagination', {
|
|
395
549
|
alias: 'emerald-pagination'
|