gd-bs 6.6.9 → 6.6.11
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/build/components/dropdown/index.js +81 -23
- package/dist/gd-bs-icons.js +1 -1
- package/dist/gd-bs-icons.min.js +1 -1
- package/dist/gd-bs.js +1 -1
- package/dist/gd-bs.min.js +1 -1
- package/package.json +1 -1
- package/src/components/dropdown/index.ts +81 -23
package/package.json
CHANGED
|
@@ -371,6 +371,77 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
// Generates the checkbox items
|
|
375
|
+
private generateCheckboxItems(): ICheckboxGroupItem[] {
|
|
376
|
+
let cbItems: ICheckboxGroupItem[] = [];
|
|
377
|
+
|
|
378
|
+
// Parse the items
|
|
379
|
+
let items = this.props.items || [];
|
|
380
|
+
for (let i = 0; i < items.length; i++) {
|
|
381
|
+
let item = items[i];
|
|
382
|
+
|
|
383
|
+
// Create the checkbox item
|
|
384
|
+
cbItems.push({
|
|
385
|
+
data: item,
|
|
386
|
+
isDisabled: item.isDisabled,
|
|
387
|
+
isSelected: item.isSelected,
|
|
388
|
+
label: item.text,
|
|
389
|
+
onChange: item.onClick,
|
|
390
|
+
type: CheckboxGroupTypes.Checkbox
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Return the items
|
|
395
|
+
return cbItems;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Generates the checkbox value
|
|
399
|
+
private generateCheckboxValue(currentValues: string | string[] | IDropdownItem[]): string[] {
|
|
400
|
+
let values: string[] = [];
|
|
401
|
+
|
|
402
|
+
// Ensure a value exists
|
|
403
|
+
if (currentValues == null) { return values; }
|
|
404
|
+
|
|
405
|
+
// Ensure it's an array
|
|
406
|
+
if (typeof (currentValues) === "string") {
|
|
407
|
+
// Make it an array
|
|
408
|
+
currentValues = [currentValues];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Parse the current values
|
|
412
|
+
for (let i = 0; i < currentValues.length; i++) {
|
|
413
|
+
let currentValue = currentValues[i];
|
|
414
|
+
let currentItem:IDropdownItem = { };
|
|
415
|
+
|
|
416
|
+
// See if this is a string
|
|
417
|
+
if (typeof (currentValue) == "string") {
|
|
418
|
+
// Set the text property
|
|
419
|
+
currentItem.text = currentValue;
|
|
420
|
+
} else {
|
|
421
|
+
// Set the item
|
|
422
|
+
currentItem = currentValue;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Find the item
|
|
426
|
+
let item = this.props.items?.find((item) => {
|
|
427
|
+
// Match by the text property if the value doesn't exist
|
|
428
|
+
if (typeof (item.value) === undefined) { return item.text == currentItem.text; }
|
|
429
|
+
|
|
430
|
+
// See if the value property matches
|
|
431
|
+
return item.value == currentItem.value;
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// See if an item was found
|
|
435
|
+
if (item) {
|
|
436
|
+
// Add the text property
|
|
437
|
+
values.push(item.text);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Return the values
|
|
442
|
+
return values;
|
|
443
|
+
}
|
|
444
|
+
|
|
374
445
|
// Handles the click event outside of the menu to close it
|
|
375
446
|
private handleClick = (ev: Event) => {
|
|
376
447
|
// See if we clicked within the menu
|
|
@@ -395,31 +466,13 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
395
466
|
if (menu) {
|
|
396
467
|
// See if we are creating checkboxes
|
|
397
468
|
if (this.props.isCheckbox) {
|
|
398
|
-
let cbItems: ICheckboxGroupItem[] = [];
|
|
399
|
-
|
|
400
|
-
// Parse the items
|
|
401
|
-
let items = this.props.items || [];
|
|
402
|
-
for (let i = 0; i < items.length; i++) {
|
|
403
|
-
let item = items[i];
|
|
404
|
-
|
|
405
|
-
// Create the checkbox item
|
|
406
|
-
cbItems.push({
|
|
407
|
-
data: item,
|
|
408
|
-
isDisabled: item.isDisabled,
|
|
409
|
-
isSelected: item.isSelected,
|
|
410
|
-
label: item.text,
|
|
411
|
-
onChange: item.onClick,
|
|
412
|
-
type: CheckboxGroupTypes.Checkbox
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
|
|
416
469
|
// Render the checkbox
|
|
417
470
|
this._cb = CheckboxGroup({
|
|
418
471
|
className: "m-2",
|
|
419
472
|
el: menu,
|
|
420
|
-
items:
|
|
473
|
+
items: this.generateCheckboxItems(),
|
|
421
474
|
multi: this.props.multi,
|
|
422
|
-
value: this.props.value,
|
|
475
|
+
value: this.generateCheckboxValue(this.props.value),
|
|
423
476
|
onChange: this.props.onChange ? (values, ev) => {
|
|
424
477
|
// Pass the current values
|
|
425
478
|
this.props.onChange(this.getValue(), ev);
|
|
@@ -497,8 +550,6 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
497
550
|
// Add the value
|
|
498
551
|
values.push(items[i].data);
|
|
499
552
|
}
|
|
500
|
-
|
|
501
|
-
// Return the value
|
|
502
553
|
} else {
|
|
503
554
|
// Parse the items
|
|
504
555
|
for (let i = 0; i < this._items.length; i++) {
|
|
@@ -536,7 +587,7 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
536
587
|
// See if we are rendering checkboxes
|
|
537
588
|
if (this._cb) {
|
|
538
589
|
// Set the items
|
|
539
|
-
this._cb.setItems(
|
|
590
|
+
this._cb.setItems(this.generateCheckboxItems());
|
|
540
591
|
return;
|
|
541
592
|
}
|
|
542
593
|
|
|
@@ -614,6 +665,13 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
614
665
|
// Ensure it's an array
|
|
615
666
|
let values = value == null ? [] : (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]);
|
|
616
667
|
|
|
668
|
+
// See if this is a checkbox
|
|
669
|
+
if (this._cb) {
|
|
670
|
+
// Set the value
|
|
671
|
+
this._cb.setValue(this.generateCheckboxValue(value));
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
|
|
617
675
|
// Parse the items
|
|
618
676
|
for (let i = 0; i < this._items.length; i++) {
|
|
619
677
|
let item = this._items[i];
|