gd-bs 6.9.0 → 6.9.2

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/indexv2.html CHANGED
@@ -380,7 +380,7 @@
380
380
 
381
381
  <h5>Paging</h5>
382
382
 
383
- <bs-paging number-of-pages="5" on-click="MyLib.pagingOnClick"></bs-paging>
383
+ <bs-paging number-of-pages="85" on-click="MyLib.pagingOnClick"></bs-paging>
384
384
 
385
385
  <h5>Popover</h5>
386
386
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gd-bs",
3
- "version": "6.9.0",
3
+ "version": "6.9.2",
4
4
  "description": "Bootstrap JavaScript, TypeScript and Web Components library.",
5
5
  "main": "build/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -82,6 +82,12 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
82
82
  // Render the items
83
83
  this.renderItems();
84
84
 
85
+ // See if values were defined
86
+ if (this.props.value) {
87
+ // Set the values
88
+ this.setValue(this.props.value);
89
+ }
90
+
85
91
  // Set the menu element
86
92
  this._elMenu = this.el.querySelector(".dropdown-menu");
87
93
  if (this._elMenu) {
@@ -1,5 +1,9 @@
1
1
  import { IPagination, IPaginationProps } from "./types";
2
2
  import { Base } from "../base";
3
+ import { skipBackward } from "../../icons/svgs/skipBackward";
4
+ import { skipForward } from "../../icons/svgs/skipForward";
5
+ import { skipEnd } from "../../icons/svgs/skipEnd";
6
+ import { skipStart } from "../../icons/svgs/skipStart";
3
7
  import { HTML, HTMLItem } from "./templates";
4
8
 
5
9
  /**
@@ -15,13 +19,24 @@ export enum PaginationAlignment {
15
19
  * Pagination
16
20
  */
17
21
  class _Pagination extends Base<IPaginationProps> implements IPagination {
22
+ private _activePage: number = null;
18
23
  private _elList: HTMLUListElement = null;
19
24
  private _items: Array<HTMLLIElement> = null;
25
+ private _showDefault: boolean = true;
26
+
27
+ // Buttons
28
+ private _buttons: {
29
+ First: HTMLLIElement, Last: HTMLLIElement, Next: HTMLLIElement, Previous: HTMLLIElement,
30
+ SkipBack10: HTMLLIElement, SkipBack5: HTMLLIElement, SkipForward5: HTMLLIElement, SkipForward10: HTMLLIElement
31
+ } = null;
20
32
 
21
33
  // Constructor
22
34
  constructor(props: IPaginationProps, template: string = HTML, itemTemplate: string = HTMLItem) {
23
35
  super(template, props);
24
36
 
37
+ // Create the default buttons
38
+ this.createButtons(itemTemplate);
39
+
25
40
  // Configure the collapse
26
41
  this.configure(itemTemplate);
27
42
 
@@ -53,37 +68,45 @@ class _Pagination extends Base<IPaginationProps> implements IPagination {
53
68
  }
54
69
 
55
70
  // Render the page numbers
56
- this.renderPageNumbers(1, itemTemplate);
71
+ this.renderPageNumbers(itemTemplate);
57
72
  }
58
73
  }
59
74
 
60
- // Configures the next/previous buttons, based on the active index
61
- private configureNextPrevButtons(activePage: number) {
75
+ // Configures the default buttons, based on the active index
76
+ private configureDefaultButtons() {
62
77
  // Update the previous button
63
- let prevItem = this._items[0];
64
- if (activePage == 1) {
65
- // Ensure the previous item is disabled
66
- prevItem.classList.add("disabled");
78
+ if (this._activePage == 1) {
79
+ // Ensure the first/previous item is disabled
80
+ this._buttons.First.classList.add("disabled");
81
+ this._buttons.Previous.classList.add("disabled");
67
82
  } else {
68
- // Ensure the previous item is enabled
69
- prevItem.classList.remove("disabled");
83
+ // Ensure the first/previous item is enabled
84
+ this._buttons.First.classList.remove("disabled");
85
+ this._buttons.Previous.classList.remove("disabled");
70
86
  }
71
87
 
72
- // Update the next button
73
- let nextItem = this._items[this._items.length - 1];
74
- if (activePage == this._items.length - 2) {
75
- // Ensure the previous item is disabled
76
- nextItem.classList.add("disabled");
88
+ // Update the next/last button
89
+ if (this._activePage == this._items.length) {
90
+ // Ensure the next/last item is disabled
91
+ this._buttons.Next.classList.add("disabled");
92
+ this._buttons.Last.classList.add("disabled");
77
93
  } else {
78
- // Ensure the previous item is enabled
79
- nextItem.classList.remove("disabled");
94
+ // Ensure the next/last item is enabled
95
+ this._buttons.Next.classList.remove("disabled");
96
+ this._buttons.Last.classList.remove("disabled");
80
97
  }
81
98
  }
82
99
 
83
100
  // Configure the events
84
- private configureEvents(item: HTMLLIElement) {
85
- // See if this is the next or previous item and skip it
101
+ private configureEvents(item: HTMLLIElement, itemTemplate: string) {
102
+ // See if this is a spacer
86
103
  let link = item.querySelector("a").getAttribute("aria-label");
104
+ if (link == "...") {
105
+ // Do nothing
106
+ return;
107
+ }
108
+
109
+ // See if this is the next or previous item and skip it
87
110
  if (link == "Previous" || link == "Next") {
88
111
  let isPrevious = link == "Previous";
89
112
 
@@ -95,26 +118,88 @@ class _Pagination extends Base<IPaginationProps> implements IPagination {
95
118
  // Do nothing if it's disabled
96
119
  if (item.classList.contains("disabled")) { return; }
97
120
 
98
- // Parse the items, excluding the next/previous items
99
- for (let i = 1; i < this._items.length - 1; i++) {
100
- let item = this._items[i];
101
-
102
- // See if this item is active
103
- if (item.classList.contains("active")) {
104
- // See if the previous button was clicked
105
- if (isPrevious) {
106
- // Click the previous item if it's available
107
- i - 1 > 0 ? this._items[i - 1].click() : null;
108
- } else {
109
- // Click the next item if it's available
110
- i < this._items.length - 2 ? this._items[i + 1].click() : null;
111
- }
112
-
113
- // Break from the loop
114
- break;
121
+ // Update the active page
122
+ isPrevious ? this._activePage-- : this._activePage++;
123
+
124
+ // See if we are rendering the default
125
+ if (this._showDefault) {
126
+ // Click the item
127
+ this._items[this._activePage]?.click();
128
+ } else {
129
+ // Render the active buttons
130
+ this.renderActivePageNumbers(itemTemplate);
131
+
132
+ // Call the click event
133
+ this.props.onClick ? this.props.onClick(this._activePage) : null;
134
+ }
135
+ });
136
+ } else if (link == "First" || link == "Last") {
137
+ let isLast = link == "Last";
138
+
139
+ // Add a click event
140
+ item.addEventListener("click", ev => {
141
+ // Prevent the page from moving to the top
142
+ ev.preventDefault();
143
+
144
+ // Do nothing if it's disabled
145
+ if (item.classList.contains("disabled")) { return; }
146
+
147
+ // See if we are rendering the default
148
+ if (this._showDefault) {
149
+ // See if this is the last item
150
+ if (isLast) {
151
+ // Click on the last item
152
+ this._items[this._items.length - 1]?.click();
153
+ } else {
154
+ // Click on the first item
155
+ this._items[0]?.click();
115
156
  }
157
+ } else {
158
+ // Update the active page
159
+ this._activePage = isLast ? this.props.numberOfPages : 1;
160
+
161
+ // Render the active buttons
162
+ this.renderActivePageNumbers(itemTemplate);
163
+
164
+ // Call the click event
165
+ this.props.onClick ? this.props.onClick(this._activePage) : null;
116
166
  }
117
167
  });
168
+ } else if (link == "&lt;&lt;" || link == "&lt;" || link == "&gt;" || link == "&gt;&gt;") {
169
+ // Add a click event
170
+ item.addEventListener("click", ev => {
171
+ // Prevent the page from moving to the top
172
+ ev.preventDefault();
173
+
174
+ // Update the active page
175
+ switch (link) {
176
+ case "&lt;&lt;":
177
+ this._activePage -= 10;
178
+ break;
179
+ case "&lt;":
180
+ this._activePage -= 5;
181
+ break;
182
+ case "&gt;":
183
+ this._activePage += 5;
184
+ break;
185
+ case "&gt;&gt;":
186
+ this._activePage += 10;
187
+ break;
188
+ }
189
+
190
+ // Validate the page number
191
+ if (this._activePage <= 0) {
192
+ this._activePage = 1;
193
+ } else if (this._activePage > this.props.numberOfPages) {
194
+ this._activePage = this.props.numberOfPages;
195
+ }
196
+
197
+ // Render the active buttons
198
+ this.renderActivePageNumbers(itemTemplate);
199
+
200
+ // Call the click event
201
+ this.props.onClick ? this.props.onClick(this._activePage) : null;
202
+ });
118
203
  } else {
119
204
  let pageNumber = parseInt(link);
120
205
 
@@ -123,44 +208,81 @@ class _Pagination extends Base<IPaginationProps> implements IPagination {
123
208
  // Prevent the page from moving to the top
124
209
  ev.preventDefault();
125
210
 
126
- // Parse the active items
127
- let activeItems = this.el.querySelectorAll(".page-item.active");
128
- for (let i = 0; i < activeItems.length; i++) {
129
- let item = activeItems[i];
211
+ // Set the active index
212
+ this._activePage = pageNumber;
130
213
 
131
- // Clear the active class
132
- item.classList.remove("active");
214
+ // See if we are showing the default
215
+ if (this._showDefault) {
216
+ // Clear the active item
217
+ let activeItem = this._items[this._activePage - 1];
218
+ if (activeItem) {
219
+ // Clear the active class
220
+ activeItem.classList.remove("active");
133
221
 
134
- // Remove the active span
135
- let span = item.querySelector("span") as HTMLSpanElement;
136
- span ? span.parentNode.removeChild(span) : null;
137
- }
222
+ // Remove the active span
223
+ let span = activeItem.querySelector("span") as HTMLSpanElement;
224
+ span ? span.parentNode.removeChild(span) : null;
225
+ }
138
226
 
139
- // Make this item active
140
- item.classList.add("active");
227
+ // Show the active item
228
+ this._items[this._activePage - 1].classList.add("active");
141
229
 
142
- // Add the span
143
- let span = document.createElement("span");
144
- span.classList.add("visually-hidden");
145
- span.innerHTML = "(current)";
146
- item.appendChild(span);
230
+ // Add the span
231
+ let span = document.createElement("span");
232
+ span.classList.add("visually-hidden");
233
+ span.innerHTML = "(current)";
234
+ this._items[this._activePage - 1].appendChild(span);
147
235
 
148
- // Configure the next/previous buttons
149
- this.configureNextPrevButtons(pageNumber);
236
+ // Configure the default buttons
237
+ this.configureDefaultButtons();
238
+ } else {
239
+ // Render the active buttons
240
+ this.renderActivePageNumbers(itemTemplate);
241
+ }
150
242
 
151
- // Class the click event
152
- this.props.onClick ? this.props.onClick(pageNumber, ev) : null;
243
+ // Call the click event
244
+ this.props.onClick ? this.props.onClick(pageNumber) : null;
153
245
  });
154
246
  }
155
247
  }
156
248
 
249
+ // Creates the default buttons
250
+ private createButtons(itemTemplate: string) {
251
+ this._buttons = {
252
+ First: this.createItem("First", itemTemplate, true),
253
+ Last: this.createItem("Last", itemTemplate, true),
254
+ Next: this.createItem("Next", itemTemplate, true),
255
+ Previous: this.createItem("Previous", itemTemplate, true),
256
+ SkipBack10: this.createItem("<<", itemTemplate, true),
257
+ SkipBack5: this.createItem("<", itemTemplate, true),
258
+ SkipForward5: this.createItem(">", itemTemplate, true),
259
+ SkipForward10: this.createItem(">>", itemTemplate, true)
260
+ };
261
+
262
+ // Set the default classes
263
+ this._buttons.First.classList.add("first");
264
+ this._buttons.Last.classList.add("last");
265
+ this._buttons.Next.classList.add("next");
266
+ this._buttons.Previous.classList.add("previous");
267
+
268
+ // Disable the first and previous buttons by default
269
+ this._buttons.First.classList.add("disabled");
270
+ this._buttons.Previous.classList.add("disabled");
271
+
272
+ // Set the icons
273
+ this._buttons.SkipBack10.querySelector("a").innerHTML = skipBackward(15, 15).outerHTML;
274
+ this._buttons.SkipBack5.querySelector("a").innerHTML = skipStart(15, 15).outerHTML;
275
+ this._buttons.SkipForward5.querySelector("a").innerHTML = skipEnd(15, 15).outerHTML;
276
+ this._buttons.SkipForward10.querySelector("a").innerHTML = skipForward(15, 15).outerHTML;
277
+ }
278
+
157
279
  // Creates an page number item
158
- private createItem(text: string, itemTemplate: string): HTMLLIElement {
280
+ private createItem(text: string, itemTemplate: string, isDefault: boolean = false): HTMLLIElement {
159
281
  // Create the item
160
282
  let el = document.createElement("div");
161
283
  el.innerHTML = itemTemplate;
162
284
  let item = el.firstChild as HTMLLIElement;
163
- this._items.push(item);
285
+ isDefault ? null : this._items.push(item);
164
286
 
165
287
  // Update the link
166
288
  let link = item.querySelector("a");
@@ -170,49 +292,143 @@ class _Pagination extends Base<IPaginationProps> implements IPagination {
170
292
  }
171
293
 
172
294
  // Configure the events
173
- this.configureEvents(item);
295
+ this.configureEvents(item, itemTemplate);
174
296
 
175
297
  // Return the item
176
298
  return item;
177
299
  }
178
300
 
179
301
  // Renders the page numbers
180
- private renderPageNumbers(activeItem: number, itemTemplate: string) {
302
+ private renderPageNumbers(itemTemplate: string) {
181
303
  // Clear the items
304
+ this._activePage = 1;
182
305
  this._items = [];
183
306
 
184
307
  // Determine if there are > 10 pages
185
308
  let pages = this.props.numberOfPages || 1;
186
- let showFirstLast = pages > 10;
187
-
188
- // Create the previous link
189
- let item = this.createItem("Previous", itemTemplate);
190
- item.classList.add("disabled");
191
- item.classList.add("previous");
192
- this._elList.appendChild(item);
193
-
194
- // See if we are showing the first/last links
195
- if (showFirstLast) {
196
- item = this.createItem("1", itemTemplate);
197
- activeItem == 1 ? item.classList.add("active") : null;
198
- item.classList.add("next");
309
+ let maxPages = typeof (this.props.maxPages) === "number" ? this.props.maxPages : 10;
310
+ this._showDefault = pages < maxPages;
311
+
312
+ // See if we are rendering the default
313
+ if (this._showDefault) {
314
+ // Append the first/previous link
315
+ this._elList.appendChild(this._buttons.First);
316
+ this._elList.appendChild(this._buttons.Previous);
317
+
318
+ // Loop for the number of pages to create
319
+ for (let i = 1; i <= pages; i++) {
320
+ // Create a link
321
+ let item = this.createItem(i.toString(), itemTemplate);
322
+ i == this._activePage ? item.classList.add("active") : null;
323
+ this._elList.appendChild(item);
324
+ }
325
+
326
+ // Append the next/last link
327
+ this._elList.appendChild(this._buttons.Next);
328
+ this._elList.appendChild(this._buttons.Last);
329
+ if (pages == 1) {
330
+ this._buttons.Next.classList.add("disabled");
331
+ this._buttons.Last.classList.add("disabled");
332
+ }
333
+ } else {
334
+ // Render the active page numbers
335
+ this.renderActivePageNumbers(itemTemplate);
336
+ }
337
+ }
338
+
339
+ // Renders the active page numbers
340
+ private renderActivePageNumbers(itemTemplate: string) {
341
+ // Clear the items and list element
342
+ this._items = [];
343
+ while (this._elList.firstChild) { this._elList.removeChild(this._elList.firstChild); }
344
+
345
+ // Append the first/previous link
346
+ this._elList.appendChild(this._buttons.First);
347
+ this._elList.appendChild(this._buttons.Previous);
348
+ if (this._activePage == 1) {
349
+ this._buttons.First.classList.add("disabled");
350
+ this._buttons.Previous.classList.add("disabled");
351
+ } else {
352
+ this._buttons.First.classList.remove("disabled");
353
+ this._buttons.Previous.classList.remove("disabled");
354
+ }
355
+
356
+ // See if we are at the beginning
357
+ if (this._activePage < 5) {
358
+ // Render the first five
359
+ for (let i = 1; i <= 5; i++) {
360
+ // Create a link
361
+ let item = this.createItem(i.toString(), itemTemplate);
362
+ i == this._activePage ? item.classList.add("active") : null;
363
+ this._elList.appendChild(item);
364
+ }
365
+
366
+ // Render a spacer
367
+ let item = this.createItem("...", itemTemplate, true);
199
368
  this._elList.appendChild(item);
369
+
370
+ // Render the last 3
371
+ let diff = Math.round((this.props.numberOfPages - 5) / 3);
372
+ for (let i = 2; i >= 0; i--) {
373
+ // Create a link
374
+ let idx = this.props.numberOfPages - i * diff;
375
+ let item = this.createItem((idx).toString(), itemTemplate);
376
+ this._elList.appendChild(item);
377
+ }
200
378
  }
379
+ // Else, see if we are at the end
380
+ else if (this._activePage > this.props.numberOfPages - 5) {
381
+
382
+ // Render the first 3
383
+ let diff = Math.round((this.props.numberOfPages - 5) / 3);
384
+ for (let i = 0; i <= 2; i++) {
385
+ // Create a link
386
+ let idx = i == 0 ? 1 : i * diff;
387
+ let item = this.createItem((idx).toString(), itemTemplate);
388
+ this._elList.appendChild(item);
389
+ }
201
390
 
202
- // Loop for the number of pages to create
203
- // Parse the number of pages
204
- for (let i = 2; i <= pages; i++) {
205
- // Create a link
206
- item = this.createItem(i.toString(), itemTemplate);
207
- i == activeItem ? item.classList.add("active") : null;
391
+ // Render a spacer
392
+ let item = this.createItem("...", itemTemplate, true);
208
393
  this._elList.appendChild(item);
394
+
395
+ // Render the last five
396
+ for (let i = this.props.numberOfPages - 5; i <= this.props.numberOfPages; i++) {
397
+ // Create a link
398
+ let item = this.createItem(i.toString(), itemTemplate);
399
+ i == this._activePage ? item.classList.add("active") : null;
400
+ this._elList.appendChild(item);
401
+ }
402
+ }
403
+ // Else, render the skip buttons
404
+ else {
405
+ // Render the skip buttons
406
+ this._elList.appendChild(this._buttons.SkipBack10);
407
+ this._elList.appendChild(this._buttons.SkipBack5);
408
+
409
+ // Render +/- 2 from the active index
410
+ for (let i = this._activePage - 2; i <= this._activePage + 2; i++) {
411
+ // Create a link
412
+ let item = this.createItem(i.toString(), itemTemplate);
413
+ i == this._activePage ? item.classList.add("active") : null;
414
+ this._elList.appendChild(item);
415
+ }
416
+
417
+ // Render the skip buttons
418
+ this._elList.appendChild(this._buttons.SkipForward5);
419
+ this._elList.appendChild(this._buttons.SkipForward10);
209
420
  }
210
421
 
211
- // Create the next link
212
- item = this.createItem("Next", itemTemplate);
213
- pages > 1 ? null : item.classList.add("disabled");
214
- item.classList.add("next");
215
- this._elList.appendChild(item);
422
+ // Append the next/last link
423
+ this._elList.appendChild(this._buttons.Next);
424
+ this._elList.appendChild(this._buttons.Last);
425
+ if (this._activePage == this.props.numberOfPages) {
426
+ this._buttons.Next.classList.add("disabled");
427
+ this._buttons.Last.classList.add("disabled");
428
+ } else {
429
+ this._buttons.Next.classList.remove("disabled");
430
+ this._buttons.Last.classList.remove("disabled");
431
+ }
216
432
  }
217
433
  }
218
434
  export const Pagination = (props: IPaginationProps, template?: string, itemTemplate?: string): IPagination => { return new _Pagination(props, template, itemTemplate); }
@@ -62,8 +62,9 @@ export interface IPaginationProps extends IBaseProps<IPagination> {
62
62
  isLarge?: boolean;
63
63
  isSmall?: boolean;
64
64
  label?: string;
65
+ maxPages?: number;
65
66
  numberOfPages?: number;
66
- onClick?: (pageNumber?: number, ev?: Event) => void;
67
+ onClick?: (pageNumber?: number) => void;
67
68
  }
68
69
 
69
70
  /**
@@ -43,6 +43,10 @@
43
43
  -webkit-mask-repeat: no-repeat;
44
44
  }
45
45
 
46
+ .badge {
47
+ cursor: pointer;
48
+ }
49
+
46
50
  .bg-danger {
47
51
  background-color: var(--sp-error-icon, #a80000) !important;
48
52
  }
@@ -751,6 +755,14 @@
751
755
  height: 100vh;
752
756
  }
753
757
 
758
+ .page-item {
759
+ cursor: pointer;
760
+
761
+ .page-link {
762
+ cursor: pointer;
763
+ }
764
+ }
765
+
754
766
  /* Color match the pagination link color to 'SharePoint Blue' */
755
767
  .page-link {
756
768
  border-color: var(--sp-info-icon, #605e5c);