@agnos-ui/core 0.0.1-alpha.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/README.md +15 -0
- package/dist/lib/accordion.d.ts +318 -0
- package/dist/lib/accordion.js +263 -0
- package/dist/lib/alert.d.ts +100 -0
- package/dist/lib/alert.js +66 -0
- package/dist/lib/config.d.ts +71 -0
- package/dist/lib/config.js +53 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +11 -0
- package/dist/lib/modal/modal.d.ts +318 -0
- package/dist/lib/modal/modal.js +156 -0
- package/dist/lib/modal/scrollbars.d.ts +2 -0
- package/dist/lib/modal/scrollbars.js +27 -0
- package/dist/lib/pagination.d.ts +464 -0
- package/dist/lib/pagination.js +148 -0
- package/dist/lib/pagination.utils.d.ts +8 -0
- package/dist/lib/pagination.utils.js +110 -0
- package/dist/lib/rating.d.ts +209 -0
- package/dist/lib/rating.js +141 -0
- package/dist/lib/select.d.ts +199 -0
- package/dist/lib/select.js +240 -0
- package/dist/lib/services/checks.d.ts +32 -0
- package/dist/lib/services/checks.js +43 -0
- package/dist/lib/services/directiveUtils.d.ts +95 -0
- package/dist/lib/services/directiveUtils.js +190 -0
- package/dist/lib/services/focustrack.d.ts +19 -0
- package/dist/lib/services/focustrack.js +46 -0
- package/dist/lib/services/index.d.ts +6 -0
- package/dist/lib/services/index.js +6 -0
- package/dist/lib/services/portal.d.ts +6 -0
- package/dist/lib/services/portal.js +33 -0
- package/dist/lib/services/siblingsInert.d.ts +7 -0
- package/dist/lib/services/siblingsInert.js +40 -0
- package/dist/lib/services/stores.d.ts +140 -0
- package/dist/lib/services/stores.js +219 -0
- package/dist/lib/services/writables.d.ts +7 -0
- package/dist/lib/services/writables.js +16 -0
- package/dist/lib/transitions/baseTransitions.d.ts +136 -0
- package/dist/lib/transitions/baseTransitions.js +171 -0
- package/dist/lib/transitions/bootstrap/collapse.d.ts +2 -0
- package/dist/lib/transitions/bootstrap/collapse.js +15 -0
- package/dist/lib/transitions/bootstrap/fade.d.ts +1 -0
- package/dist/lib/transitions/bootstrap/fade.js +7 -0
- package/dist/lib/transitions/bootstrap/index.d.ts +2 -0
- package/dist/lib/transitions/bootstrap/index.js +2 -0
- package/dist/lib/transitions/collapse.d.ts +29 -0
- package/dist/lib/transitions/collapse.js +39 -0
- package/dist/lib/transitions/cssTransitions.d.ts +15 -0
- package/dist/lib/transitions/cssTransitions.js +38 -0
- package/dist/lib/transitions/index.d.ts +5 -0
- package/dist/lib/transitions/index.js +5 -0
- package/dist/lib/transitions/simpleClassTransition.d.ts +29 -0
- package/dist/lib/transitions/simpleClassTransition.js +28 -0
- package/dist/lib/transitions/utils.d.ts +20 -0
- package/dist/lib/transitions/utils.js +83 -0
- package/dist/lib/tsdoc-metadata.json +11 -0
- package/dist/lib/types.d.ts +58 -0
- package/dist/lib/types.js +7 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +2 -0
- package/package.json +52 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { noop } from '../utils';
|
|
2
|
+
const internalRemoveScrollbars = () => {
|
|
3
|
+
const scrollbarWidth = Math.abs(window.innerWidth - document.documentElement.clientWidth);
|
|
4
|
+
const body = document.body;
|
|
5
|
+
const bodyStyle = body.style;
|
|
6
|
+
const { overflow, paddingRight } = bodyStyle;
|
|
7
|
+
if (scrollbarWidth > 0) {
|
|
8
|
+
const actualPadding = parseFloat(window.getComputedStyle(body).paddingRight);
|
|
9
|
+
bodyStyle.paddingRight = `${actualPadding + scrollbarWidth}px`;
|
|
10
|
+
}
|
|
11
|
+
bodyStyle.overflow = 'hidden';
|
|
12
|
+
return () => {
|
|
13
|
+
if (scrollbarWidth > 0) {
|
|
14
|
+
bodyStyle.paddingRight = paddingRight;
|
|
15
|
+
}
|
|
16
|
+
bodyStyle.overflow = overflow;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
let internalRevert = noop;
|
|
20
|
+
export const removeScrollbars = () => {
|
|
21
|
+
internalRevert();
|
|
22
|
+
internalRevert = internalRemoveScrollbars();
|
|
23
|
+
};
|
|
24
|
+
export const revertScrollbars = () => {
|
|
25
|
+
internalRevert();
|
|
26
|
+
internalRevert = noop;
|
|
27
|
+
};
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import type { PropsConfig } from './services';
|
|
2
|
+
import type { Widget, SlotContent, WidgetSlotContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A type for the slot context of the pagination widget
|
|
5
|
+
*/
|
|
6
|
+
export type PaginationContext = WidgetSlotContext<PaginationWidget>;
|
|
7
|
+
/**
|
|
8
|
+
* A type for the slot context of the pagination widget when the slot is the number label
|
|
9
|
+
*/
|
|
10
|
+
export interface PaginationNumberContext extends PaginationContext {
|
|
11
|
+
/**
|
|
12
|
+
* Displayed page
|
|
13
|
+
*/
|
|
14
|
+
displayedPage: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PaginationCommonPropsAndState {
|
|
17
|
+
/**
|
|
18
|
+
* The current page.
|
|
19
|
+
*
|
|
20
|
+
* Page numbers start with `1`.
|
|
21
|
+
* @defaultValue 1
|
|
22
|
+
*/
|
|
23
|
+
page: number;
|
|
24
|
+
/**
|
|
25
|
+
* The pagination display size.
|
|
26
|
+
*
|
|
27
|
+
* Bootstrap currently supports small and large sizes.
|
|
28
|
+
* @defaultValue null
|
|
29
|
+
*/
|
|
30
|
+
size: 'sm' | 'lg' | null;
|
|
31
|
+
/**
|
|
32
|
+
* The label for the nav element.
|
|
33
|
+
*
|
|
34
|
+
* for I18n, we suggest to use the global configuration
|
|
35
|
+
* override any configuration parameters provided for this
|
|
36
|
+
* @defaultValue 'Page navigation'
|
|
37
|
+
*/
|
|
38
|
+
ariaLabel: string;
|
|
39
|
+
/**
|
|
40
|
+
* The label for the "active" page.
|
|
41
|
+
* for I18n, we suggest to use the global configuration
|
|
42
|
+
* override any configuration parameters provided for this
|
|
43
|
+
* @defaultValue '(current)'
|
|
44
|
+
*/
|
|
45
|
+
activeLabel: string;
|
|
46
|
+
/**
|
|
47
|
+
* The label for the "First" page button.
|
|
48
|
+
* for I18n, we suggest to use the global configuration
|
|
49
|
+
* override any configuration parameters provided for this
|
|
50
|
+
* @defaultValue 'Action link for first page'
|
|
51
|
+
*/
|
|
52
|
+
ariaFirstLabel: string;
|
|
53
|
+
/**
|
|
54
|
+
* The label for the "Previous" page button.
|
|
55
|
+
* for I18n, we suggest to use the global configuration
|
|
56
|
+
* override any configuration parameters provided for this
|
|
57
|
+
* @defaultValue 'Action link for previous page'
|
|
58
|
+
*/
|
|
59
|
+
ariaPreviousLabel: string;
|
|
60
|
+
/**
|
|
61
|
+
* The label for the "Next" page button.
|
|
62
|
+
* for I18n, we suggest to use the global configuration
|
|
63
|
+
* override any configuration parameters provided for this
|
|
64
|
+
* @defaultValue 'Action link for next page'
|
|
65
|
+
*/
|
|
66
|
+
ariaNextLabel: string;
|
|
67
|
+
/**
|
|
68
|
+
* The label for the "Last" page button.
|
|
69
|
+
* for I18n, we suggest to use the global configuration
|
|
70
|
+
* override any configuration parameters provided for this
|
|
71
|
+
* @defaultValue 'Action link for last page'
|
|
72
|
+
*/
|
|
73
|
+
ariaLastLabel: string;
|
|
74
|
+
/**
|
|
75
|
+
* If `true`, pagination links will be disabled.
|
|
76
|
+
* @defaultValue false
|
|
77
|
+
*/
|
|
78
|
+
disabled: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* If `true`, the "Next" and "Previous" page links are shown.
|
|
81
|
+
* @defaultValue true
|
|
82
|
+
*/
|
|
83
|
+
directionLinks: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* If `true`, the "First" and "Last" page links are shown.
|
|
86
|
+
* @defaultValue false
|
|
87
|
+
*/
|
|
88
|
+
boundaryLinks: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* An input to add a custom class to the UL
|
|
91
|
+
* @defaultValue ''
|
|
92
|
+
*/
|
|
93
|
+
className: string;
|
|
94
|
+
/**
|
|
95
|
+
* The template to use for the ellipsis slot
|
|
96
|
+
* for I18n, we suggest to use the global configuration
|
|
97
|
+
* override any configuration parameters provided for this
|
|
98
|
+
* @defaultValue '…'
|
|
99
|
+
*/
|
|
100
|
+
slotEllipsis: SlotContent<PaginationContext>;
|
|
101
|
+
/**
|
|
102
|
+
* The template to use for the first slot
|
|
103
|
+
* for I18n, we suggest to use the global configuration
|
|
104
|
+
* override any configuration parameters provided for this
|
|
105
|
+
* @defaultValue '«'
|
|
106
|
+
*/
|
|
107
|
+
slotFirst: SlotContent<PaginationContext>;
|
|
108
|
+
/**
|
|
109
|
+
* The template to use for the previous slot
|
|
110
|
+
* for I18n, we suggest to use the global configuration
|
|
111
|
+
* override any configuration parameters provided for this
|
|
112
|
+
* @defaultValue '‹'
|
|
113
|
+
*/
|
|
114
|
+
slotPrevious: SlotContent<PaginationContext>;
|
|
115
|
+
/**
|
|
116
|
+
* The template to use for the next slot
|
|
117
|
+
* for I18n, we suggest to use the global configuration
|
|
118
|
+
* override any configuration parameters provided for this
|
|
119
|
+
* @defaultValue '›'
|
|
120
|
+
*/
|
|
121
|
+
slotNext: SlotContent<PaginationContext>;
|
|
122
|
+
/**
|
|
123
|
+
* The template to use for the last slot
|
|
124
|
+
* for I18n, we suggest to use the global configuration
|
|
125
|
+
* override any configuration parameters provided for this
|
|
126
|
+
* @defaultValue '»'
|
|
127
|
+
*/
|
|
128
|
+
slotLast: SlotContent<PaginationContext>;
|
|
129
|
+
/**
|
|
130
|
+
* The template to use for the pages slot
|
|
131
|
+
* To use to customize the pages view
|
|
132
|
+
* override any configuration parameters provided for this
|
|
133
|
+
*/
|
|
134
|
+
slotPages: SlotContent<PaginationContext>;
|
|
135
|
+
/**
|
|
136
|
+
* The template to use for the number slot
|
|
137
|
+
* override any configuration parameters provided for this
|
|
138
|
+
* for I18n, we suggest to use the global configuration
|
|
139
|
+
* @defaultValue
|
|
140
|
+
* ```ts
|
|
141
|
+
* ({displayedPage}) => `${displayedPage}`
|
|
142
|
+
* ```
|
|
143
|
+
* @param displayedPage - The current page number
|
|
144
|
+
*/
|
|
145
|
+
slotNumberLabel: SlotContent<PaginationNumberContext>;
|
|
146
|
+
}
|
|
147
|
+
export interface PaginationProps extends PaginationCommonPropsAndState {
|
|
148
|
+
/**
|
|
149
|
+
* The number of items in your paginated collection.
|
|
150
|
+
*
|
|
151
|
+
* Note, that this is not the number of pages. Page numbers are calculated dynamically based on
|
|
152
|
+
* `collectionSize` and `pageSize`.
|
|
153
|
+
*
|
|
154
|
+
* Ex. if you have 100 items in your collection and displaying 20 items per page, you'll end up with 5 pages.
|
|
155
|
+
*
|
|
156
|
+
* Whatever the collectionSize the page number is of minimum 1.
|
|
157
|
+
* @defaultValue 0
|
|
158
|
+
*/
|
|
159
|
+
collectionSize: number;
|
|
160
|
+
/**
|
|
161
|
+
* The number of items per page.
|
|
162
|
+
* @defaultValue 10
|
|
163
|
+
* @remarks min value is 1
|
|
164
|
+
*/
|
|
165
|
+
pageSize: number;
|
|
166
|
+
/**
|
|
167
|
+
* An event fired when the page is changed.
|
|
168
|
+
*
|
|
169
|
+
* Event payload is the number of the newly selected page.
|
|
170
|
+
*
|
|
171
|
+
* Page numbers start with `1`.
|
|
172
|
+
* @defaultValue
|
|
173
|
+
* ```ts
|
|
174
|
+
* () => {}
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
onPageChange: (page: number) => void;
|
|
178
|
+
/**
|
|
179
|
+
* pagesFactory returns a function computing the array of pages to be displayed
|
|
180
|
+
* as number (-1 are treated as ellipsis).
|
|
181
|
+
* Use Page slot to customize the pages view and not this
|
|
182
|
+
* @param page - The current page number
|
|
183
|
+
* @param pageCount - The total number of pages
|
|
184
|
+
* @defaultValue
|
|
185
|
+
* ```ts
|
|
186
|
+
* ({page, pageCount}) => {
|
|
187
|
+
* const pages: number[] = [];
|
|
188
|
+
* for (let i = 1; i <= pageCount; i++) {
|
|
189
|
+
* pages.push(i);
|
|
190
|
+
* }
|
|
191
|
+
* return pages;
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
pagesFactory: (page: number, pageCount: number) => number[];
|
|
196
|
+
/**
|
|
197
|
+
* Provide the label for each "Page" page button.
|
|
198
|
+
* This is used for accessibility purposes.
|
|
199
|
+
* for I18n, we suggest to use the global configuration
|
|
200
|
+
* override any configuration parameters provided for this
|
|
201
|
+
* @param processPage - The current page number
|
|
202
|
+
* @param pageCount - The total number of pages
|
|
203
|
+
* @defaultValue
|
|
204
|
+
* ```ts
|
|
205
|
+
* ({processPage, pageCount}) => `Page ${processPage} of ${pageCount}`
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
ariaPageLabel: (processPage: number, pageCount: number) => string;
|
|
209
|
+
}
|
|
210
|
+
export interface PaginationState extends PaginationCommonPropsAndState {
|
|
211
|
+
/**
|
|
212
|
+
* The number of pages.
|
|
213
|
+
*/
|
|
214
|
+
pageCount: number;
|
|
215
|
+
/**
|
|
216
|
+
* The current pages, the number in the Array is the number of the page.
|
|
217
|
+
*/
|
|
218
|
+
pages: number[];
|
|
219
|
+
/**
|
|
220
|
+
* true if the previous link need to be disabled
|
|
221
|
+
*/
|
|
222
|
+
previousDisabled: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* true if the next link need to be disabled
|
|
225
|
+
*/
|
|
226
|
+
nextDisabled: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* The label for each "Page" page link.
|
|
229
|
+
*/
|
|
230
|
+
pagesLabel: string[];
|
|
231
|
+
}
|
|
232
|
+
export interface PaginationActions {
|
|
233
|
+
/**
|
|
234
|
+
* To "go" to a specific page
|
|
235
|
+
* @param page - The page number to select
|
|
236
|
+
*/
|
|
237
|
+
select(page: number): void;
|
|
238
|
+
/**
|
|
239
|
+
* To "go" to the first page
|
|
240
|
+
*/
|
|
241
|
+
first(): void;
|
|
242
|
+
/**
|
|
243
|
+
* To "go" to the previous page
|
|
244
|
+
*/
|
|
245
|
+
previous(): void;
|
|
246
|
+
/**
|
|
247
|
+
* To "go" to the next page
|
|
248
|
+
*/
|
|
249
|
+
next(): void;
|
|
250
|
+
/**
|
|
251
|
+
* To "go" to the last page
|
|
252
|
+
*/
|
|
253
|
+
last(): void;
|
|
254
|
+
}
|
|
255
|
+
export interface PaginationApi {
|
|
256
|
+
/**
|
|
257
|
+
* If the page number is -1 return true
|
|
258
|
+
* @param page - The page number to check
|
|
259
|
+
*/
|
|
260
|
+
isEllipsis(page: number): boolean;
|
|
261
|
+
}
|
|
262
|
+
export type PaginationWidget = Widget<PaginationProps, PaginationState, PaginationApi, PaginationActions>;
|
|
263
|
+
/**
|
|
264
|
+
* Returns a shallow copy of the default pagination config
|
|
265
|
+
* @returns a copy of the default config
|
|
266
|
+
*/
|
|
267
|
+
export declare function getPaginationDefaultConfig(): {
|
|
268
|
+
/**
|
|
269
|
+
* The number of items in your paginated collection.
|
|
270
|
+
*
|
|
271
|
+
* Note, that this is not the number of pages. Page numbers are calculated dynamically based on
|
|
272
|
+
* `collectionSize` and `pageSize`.
|
|
273
|
+
*
|
|
274
|
+
* Ex. if you have 100 items in your collection and displaying 20 items per page, you'll end up with 5 pages.
|
|
275
|
+
*
|
|
276
|
+
* Whatever the collectionSize the page number is of minimum 1.
|
|
277
|
+
* @defaultValue 0
|
|
278
|
+
*/
|
|
279
|
+
collectionSize: number;
|
|
280
|
+
/**
|
|
281
|
+
* The number of items per page.
|
|
282
|
+
* @defaultValue 10
|
|
283
|
+
* @remarks min value is 1
|
|
284
|
+
*/
|
|
285
|
+
pageSize: number;
|
|
286
|
+
/**
|
|
287
|
+
* An event fired when the page is changed.
|
|
288
|
+
*
|
|
289
|
+
* Event payload is the number of the newly selected page.
|
|
290
|
+
*
|
|
291
|
+
* Page numbers start with `1`.
|
|
292
|
+
* @defaultValue
|
|
293
|
+
* ```ts
|
|
294
|
+
* () => {}
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
onPageChange: (page: number) => void;
|
|
298
|
+
/**
|
|
299
|
+
* pagesFactory returns a function computing the array of pages to be displayed
|
|
300
|
+
* as number (-1 are treated as ellipsis).
|
|
301
|
+
* Use Page slot to customize the pages view and not this
|
|
302
|
+
* @param page - The current page number
|
|
303
|
+
* @param pageCount - The total number of pages
|
|
304
|
+
* @defaultValue
|
|
305
|
+
* ```ts
|
|
306
|
+
* ({page, pageCount}) => {
|
|
307
|
+
* const pages: number[] = [];
|
|
308
|
+
* for (let i = 1; i <= pageCount; i++) {
|
|
309
|
+
* pages.push(i);
|
|
310
|
+
* }
|
|
311
|
+
* return pages;
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
pagesFactory: (page: number, pageCount: number) => number[];
|
|
316
|
+
/**
|
|
317
|
+
* Provide the label for each "Page" page button.
|
|
318
|
+
* This is used for accessibility purposes.
|
|
319
|
+
* for I18n, we suggest to use the global configuration
|
|
320
|
+
* override any configuration parameters provided for this
|
|
321
|
+
* @param processPage - The current page number
|
|
322
|
+
* @param pageCount - The total number of pages
|
|
323
|
+
* @defaultValue
|
|
324
|
+
* ```ts
|
|
325
|
+
* ({processPage, pageCount}) => `Page ${processPage} of ${pageCount}`
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
ariaPageLabel: (processPage: number, pageCount: number) => string;
|
|
329
|
+
/**
|
|
330
|
+
* The current page.
|
|
331
|
+
*
|
|
332
|
+
* Page numbers start with `1`.
|
|
333
|
+
* @defaultValue 1
|
|
334
|
+
*/
|
|
335
|
+
page: number;
|
|
336
|
+
/**
|
|
337
|
+
* The pagination display size.
|
|
338
|
+
*
|
|
339
|
+
* Bootstrap currently supports small and large sizes.
|
|
340
|
+
* @defaultValue null
|
|
341
|
+
*/
|
|
342
|
+
size: "sm" | "lg" | null;
|
|
343
|
+
/**
|
|
344
|
+
* The label for the nav element.
|
|
345
|
+
*
|
|
346
|
+
* for I18n, we suggest to use the global configuration
|
|
347
|
+
* override any configuration parameters provided for this
|
|
348
|
+
* @defaultValue 'Page navigation'
|
|
349
|
+
*/
|
|
350
|
+
ariaLabel: string;
|
|
351
|
+
/**
|
|
352
|
+
* The label for the "active" page.
|
|
353
|
+
* for I18n, we suggest to use the global configuration
|
|
354
|
+
* override any configuration parameters provided for this
|
|
355
|
+
* @defaultValue '(current)'
|
|
356
|
+
*/
|
|
357
|
+
activeLabel: string;
|
|
358
|
+
/**
|
|
359
|
+
* The label for the "First" page button.
|
|
360
|
+
* for I18n, we suggest to use the global configuration
|
|
361
|
+
* override any configuration parameters provided for this
|
|
362
|
+
* @defaultValue 'Action link for first page'
|
|
363
|
+
*/
|
|
364
|
+
ariaFirstLabel: string;
|
|
365
|
+
/**
|
|
366
|
+
* The label for the "Previous" page button.
|
|
367
|
+
* for I18n, we suggest to use the global configuration
|
|
368
|
+
* override any configuration parameters provided for this
|
|
369
|
+
* @defaultValue 'Action link for previous page'
|
|
370
|
+
*/
|
|
371
|
+
ariaPreviousLabel: string;
|
|
372
|
+
/**
|
|
373
|
+
* The label for the "Next" page button.
|
|
374
|
+
* for I18n, we suggest to use the global configuration
|
|
375
|
+
* override any configuration parameters provided for this
|
|
376
|
+
* @defaultValue 'Action link for next page'
|
|
377
|
+
*/
|
|
378
|
+
ariaNextLabel: string;
|
|
379
|
+
/**
|
|
380
|
+
* The label for the "Last" page button.
|
|
381
|
+
* for I18n, we suggest to use the global configuration
|
|
382
|
+
* override any configuration parameters provided for this
|
|
383
|
+
* @defaultValue 'Action link for last page'
|
|
384
|
+
*/
|
|
385
|
+
ariaLastLabel: string;
|
|
386
|
+
/**
|
|
387
|
+
* If `true`, pagination links will be disabled.
|
|
388
|
+
* @defaultValue false
|
|
389
|
+
*/
|
|
390
|
+
disabled: boolean;
|
|
391
|
+
/**
|
|
392
|
+
* If `true`, the "Next" and "Previous" page links are shown.
|
|
393
|
+
* @defaultValue true
|
|
394
|
+
*/
|
|
395
|
+
directionLinks: boolean;
|
|
396
|
+
/**
|
|
397
|
+
* If `true`, the "First" and "Last" page links are shown.
|
|
398
|
+
* @defaultValue false
|
|
399
|
+
*/
|
|
400
|
+
boundaryLinks: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* An input to add a custom class to the UL
|
|
403
|
+
* @defaultValue ''
|
|
404
|
+
*/
|
|
405
|
+
className: string;
|
|
406
|
+
/**
|
|
407
|
+
* The template to use for the ellipsis slot
|
|
408
|
+
* for I18n, we suggest to use the global configuration
|
|
409
|
+
* override any configuration parameters provided for this
|
|
410
|
+
* @defaultValue '…'
|
|
411
|
+
*/
|
|
412
|
+
slotEllipsis: SlotContent<PaginationContext>;
|
|
413
|
+
/**
|
|
414
|
+
* The template to use for the first slot
|
|
415
|
+
* for I18n, we suggest to use the global configuration
|
|
416
|
+
* override any configuration parameters provided for this
|
|
417
|
+
* @defaultValue '«'
|
|
418
|
+
*/
|
|
419
|
+
slotFirst: SlotContent<PaginationContext>;
|
|
420
|
+
/**
|
|
421
|
+
* The template to use for the previous slot
|
|
422
|
+
* for I18n, we suggest to use the global configuration
|
|
423
|
+
* override any configuration parameters provided for this
|
|
424
|
+
* @defaultValue '‹'
|
|
425
|
+
*/
|
|
426
|
+
slotPrevious: SlotContent<PaginationContext>;
|
|
427
|
+
/**
|
|
428
|
+
* The template to use for the next slot
|
|
429
|
+
* for I18n, we suggest to use the global configuration
|
|
430
|
+
* override any configuration parameters provided for this
|
|
431
|
+
* @defaultValue '›'
|
|
432
|
+
*/
|
|
433
|
+
slotNext: SlotContent<PaginationContext>;
|
|
434
|
+
/**
|
|
435
|
+
* The template to use for the last slot
|
|
436
|
+
* for I18n, we suggest to use the global configuration
|
|
437
|
+
* override any configuration parameters provided for this
|
|
438
|
+
* @defaultValue '»'
|
|
439
|
+
*/
|
|
440
|
+
slotLast: SlotContent<PaginationContext>;
|
|
441
|
+
/**
|
|
442
|
+
* The template to use for the pages slot
|
|
443
|
+
* To use to customize the pages view
|
|
444
|
+
* override any configuration parameters provided for this
|
|
445
|
+
*/
|
|
446
|
+
slotPages: SlotContent<PaginationContext>;
|
|
447
|
+
/**
|
|
448
|
+
* The template to use for the number slot
|
|
449
|
+
* override any configuration parameters provided for this
|
|
450
|
+
* for I18n, we suggest to use the global configuration
|
|
451
|
+
* @defaultValue
|
|
452
|
+
* ```ts
|
|
453
|
+
* ({displayedPage}) => `${displayedPage}`
|
|
454
|
+
* ```
|
|
455
|
+
* @param displayedPage - The current page number
|
|
456
|
+
*/
|
|
457
|
+
slotNumberLabel: SlotContent<PaginationNumberContext>;
|
|
458
|
+
};
|
|
459
|
+
/**
|
|
460
|
+
* Create a PaginationWidget with given config props
|
|
461
|
+
* @param config - an optional alert config
|
|
462
|
+
* @returns a PaginationWidget
|
|
463
|
+
*/
|
|
464
|
+
export declare function createPagination(config?: PropsConfig<PaginationProps>): PaginationWidget;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { computed } from '@amadeus-it-group/tansu';
|
|
2
|
+
import { bindableDerived, INVALID_VALUE, stateStores, writablesForProps } from './services';
|
|
3
|
+
import { clamp, isNumber } from './services/checks';
|
|
4
|
+
import { typeBoolean, typeFunction, typeNumber, typeString } from './services/writables';
|
|
5
|
+
import { noop } from './utils';
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
page: 1,
|
|
8
|
+
collectionSize: 0,
|
|
9
|
+
pageSize: 10,
|
|
10
|
+
disabled: false,
|
|
11
|
+
directionLinks: true,
|
|
12
|
+
boundaryLinks: false,
|
|
13
|
+
size: null,
|
|
14
|
+
onPageChange: noop,
|
|
15
|
+
pagesFactory: (page, pageCount) => {
|
|
16
|
+
// TODO extract this for testing
|
|
17
|
+
const pages = [];
|
|
18
|
+
for (let i = 1; i <= pageCount; i++) {
|
|
19
|
+
pages.push(i);
|
|
20
|
+
}
|
|
21
|
+
return pages;
|
|
22
|
+
},
|
|
23
|
+
ariaLabel: 'Page navigation',
|
|
24
|
+
activeLabel: '(current)',
|
|
25
|
+
ariaPageLabel: (processPage, pageCount) => `Page ${processPage} of ${pageCount}`,
|
|
26
|
+
ariaFirstLabel: 'Action link for first page',
|
|
27
|
+
ariaPreviousLabel: 'Action link for previous page',
|
|
28
|
+
ariaNextLabel: 'Action link for next page',
|
|
29
|
+
ariaLastLabel: 'Action link for last page',
|
|
30
|
+
className: '',
|
|
31
|
+
slotEllipsis: '…',
|
|
32
|
+
slotFirst: '«',
|
|
33
|
+
slotPrevious: '‹',
|
|
34
|
+
slotNext: '›',
|
|
35
|
+
slotLast: '»',
|
|
36
|
+
slotPages: undefined,
|
|
37
|
+
slotNumberLabel: ({ displayedPage }) => `${displayedPage}`,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns a shallow copy of the default pagination config
|
|
41
|
+
* @returns a copy of the default config
|
|
42
|
+
*/
|
|
43
|
+
export function getPaginationDefaultConfig() {
|
|
44
|
+
return { ...defaultConfig };
|
|
45
|
+
}
|
|
46
|
+
const configValidator = {
|
|
47
|
+
page: typeNumber,
|
|
48
|
+
collectionSize: typeNumber,
|
|
49
|
+
pageSize: typeNumber,
|
|
50
|
+
disabled: typeBoolean,
|
|
51
|
+
directionLinks: typeBoolean,
|
|
52
|
+
boundaryLinks: typeBoolean,
|
|
53
|
+
size: { normalizeValue: (value) => (value === 'lg' || value === 'sm' || value === null ? value : INVALID_VALUE) },
|
|
54
|
+
onPageChange: typeFunction,
|
|
55
|
+
pagesFactory: typeFunction,
|
|
56
|
+
ariaLabel: typeString,
|
|
57
|
+
activeLabel: typeString,
|
|
58
|
+
ariaPageLabel: typeFunction,
|
|
59
|
+
ariaFirstLabel: typeString,
|
|
60
|
+
ariaPreviousLabel: typeString,
|
|
61
|
+
ariaNextLabel: typeString,
|
|
62
|
+
ariaLastLabel: typeString,
|
|
63
|
+
className: typeString,
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Create a PaginationWidget with given config props
|
|
67
|
+
* @param config - an optional alert config
|
|
68
|
+
* @returns a PaginationWidget
|
|
69
|
+
*/
|
|
70
|
+
export function createPagination(config) {
|
|
71
|
+
const [{
|
|
72
|
+
// dirty inputs that need adjustment:
|
|
73
|
+
page$: _dirtyPage$,
|
|
74
|
+
// clean inputs with value validation:
|
|
75
|
+
collectionSize$, pageSize$, onPageChange$, pagesFactory$, ariaPageLabel$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config, configValidator);
|
|
76
|
+
// computed
|
|
77
|
+
// nb total of Pages.
|
|
78
|
+
const pageCount$ = computed(() => {
|
|
79
|
+
let pageCount = Math.ceil(collectionSize$() / pageSize$());
|
|
80
|
+
// Here we choose to always display a page when collection size is 0
|
|
81
|
+
if (!isNumber(pageCount) || pageCount < 1) {
|
|
82
|
+
pageCount = 1;
|
|
83
|
+
}
|
|
84
|
+
return pageCount;
|
|
85
|
+
});
|
|
86
|
+
// current page
|
|
87
|
+
const page$ = bindableDerived(onPageChange$, [_dirtyPage$, pageCount$], ([dirtyPage, pageCount]) => clamp(dirtyPage, pageCount, 1));
|
|
88
|
+
const pages$ = computed(() => pagesFactory$()(page$(), pageCount$()));
|
|
89
|
+
const nextDisabled$ = computed(() => page$() === pageCount$() || stateProps.disabled$());
|
|
90
|
+
const previousDisabled$ = computed(() => page$() === 1 || stateProps.disabled$());
|
|
91
|
+
const pagesLabel$ = computed(() => {
|
|
92
|
+
const ariaPageLabel = ariaPageLabel$();
|
|
93
|
+
const pageCount = pageCount$();
|
|
94
|
+
return pages$().map((page) => ariaPageLabel(page, pageCount));
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
...stateStores({
|
|
98
|
+
pageCount$,
|
|
99
|
+
page$,
|
|
100
|
+
pages$,
|
|
101
|
+
nextDisabled$,
|
|
102
|
+
previousDisabled$,
|
|
103
|
+
pagesLabel$,
|
|
104
|
+
...stateProps,
|
|
105
|
+
}),
|
|
106
|
+
patch,
|
|
107
|
+
actions: {
|
|
108
|
+
/**
|
|
109
|
+
* Set the current page pageNumber (starting from 1)
|
|
110
|
+
* @param pageNumber - Current page number to set.
|
|
111
|
+
* Value is normalized between 1 and the number of page
|
|
112
|
+
*/
|
|
113
|
+
select(pageNumber) {
|
|
114
|
+
patch({ page: pageNumber });
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* Select the first page
|
|
118
|
+
*/
|
|
119
|
+
first() {
|
|
120
|
+
patch({ page: 1 });
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Select the previous page
|
|
124
|
+
*/
|
|
125
|
+
previous() {
|
|
126
|
+
patch({ page: page$() - 1 });
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Select the next page
|
|
130
|
+
*/
|
|
131
|
+
next() {
|
|
132
|
+
patch({ page: page$() + 1 });
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Select the last page
|
|
136
|
+
*/
|
|
137
|
+
last() {
|
|
138
|
+
patch({ page: pageCount$() });
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
api: {
|
|
142
|
+
isEllipsis(pageNumber) {
|
|
143
|
+
return pageNumber === -1;
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
directives: {},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the pagination algorithm used by ng-bootstrap. While this is not the default implementation of our widget, we export it to ease the migration from ng-bootstrap pagination.
|
|
3
|
+
* @param maxSize - the max size
|
|
4
|
+
* @param rotate - rotate the pages
|
|
5
|
+
* @param ellipses - enable ellipses
|
|
6
|
+
* @returns the pages
|
|
7
|
+
*/
|
|
8
|
+
export declare function ngBootstrapPagination(maxSize: number, rotate: boolean, ellipses: boolean): (page: number, pageCount: number) => number[];
|