gd-bs 6.6.8 → 6.6.10
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/checkboxGroup/index.js +11 -8
- package/build/components/dropdown/index.js +71 -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/checkboxGroup/index.ts +13 -9
- package/src/components/dropdown/index.ts +71 -23
package/package.json
CHANGED
|
@@ -71,6 +71,9 @@ class _CheckboxGroup extends Base<ICheckboxGroupProps> implements ICheckboxGroup
|
|
|
71
71
|
|
|
72
72
|
// Render the checkboxes
|
|
73
73
|
this.renderItems();
|
|
74
|
+
|
|
75
|
+
// Set the value
|
|
76
|
+
this.setValue(this.props.value);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
// Configure the events
|
|
@@ -122,15 +125,6 @@ class _CheckboxGroup extends Base<ICheckboxGroupProps> implements ICheckboxGroup
|
|
|
122
125
|
});
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
// See if this is a single checkbox
|
|
126
|
-
if (this.props.multi != true && items.length > 0) {
|
|
127
|
-
// See if this checkbox should be checked
|
|
128
|
-
if (typeof (this.props.value) === "boolean" && this.props.value) {
|
|
129
|
-
// Select the item
|
|
130
|
-
items[0].isSelected = true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
128
|
// Parse the items
|
|
135
129
|
for (let i = 0; i < items.length; i++) {
|
|
136
130
|
let item = items[i];
|
|
@@ -189,6 +183,16 @@ class _CheckboxGroup extends Base<ICheckboxGroupProps> implements ICheckboxGroup
|
|
|
189
183
|
// Method to set the value
|
|
190
184
|
// Sets the dropdown value
|
|
191
185
|
setValue(value) {
|
|
186
|
+
// See if this is a single checkbox
|
|
187
|
+
if (this.props.multi != true && this._checkboxes.length == 1) {
|
|
188
|
+
// See if this checkbox should be checked
|
|
189
|
+
if (typeof (value) === "boolean" && value) {
|
|
190
|
+
// Select the item
|
|
191
|
+
this._checkboxes[0].isChecked ? null : this._checkboxes[0].toggle();
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
192
196
|
// Ensure it's an array
|
|
193
197
|
let values = value ? (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]) : [];
|
|
194
198
|
|
|
@@ -371,6 +371,67 @@ 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[]): 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 value = currentValues[i];
|
|
414
|
+
|
|
415
|
+
// Find the item
|
|
416
|
+
let item = this.props.items?.find((item) => {
|
|
417
|
+
// Match by the text property if the value doesn't exist
|
|
418
|
+
if (typeof (item.value) === undefined) { return item.text == value; }
|
|
419
|
+
|
|
420
|
+
// See if the value property matches
|
|
421
|
+
return item.value == value;
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// See if an item was found
|
|
425
|
+
if (item) {
|
|
426
|
+
// Add the text property
|
|
427
|
+
values.push(item.text);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Return the values
|
|
432
|
+
return values;
|
|
433
|
+
}
|
|
434
|
+
|
|
374
435
|
// Handles the click event outside of the menu to close it
|
|
375
436
|
private handleClick = (ev: Event) => {
|
|
376
437
|
// See if we clicked within the menu
|
|
@@ -395,31 +456,13 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
395
456
|
if (menu) {
|
|
396
457
|
// See if we are creating checkboxes
|
|
397
458
|
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
459
|
// Render the checkbox
|
|
417
460
|
this._cb = CheckboxGroup({
|
|
418
461
|
className: "m-2",
|
|
419
462
|
el: menu,
|
|
420
|
-
items:
|
|
463
|
+
items: this.generateCheckboxItems(),
|
|
421
464
|
multi: this.props.multi,
|
|
422
|
-
value: this.props.value,
|
|
465
|
+
value: this.generateCheckboxValue(this.props.value),
|
|
423
466
|
onChange: this.props.onChange ? (values, ev) => {
|
|
424
467
|
// Pass the current values
|
|
425
468
|
this.props.onChange(this.getValue(), ev);
|
|
@@ -497,8 +540,6 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
497
540
|
// Add the value
|
|
498
541
|
values.push(items[i].data);
|
|
499
542
|
}
|
|
500
|
-
|
|
501
|
-
// Return the value
|
|
502
543
|
} else {
|
|
503
544
|
// Parse the items
|
|
504
545
|
for (let i = 0; i < this._items.length; i++) {
|
|
@@ -536,7 +577,7 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
536
577
|
// See if we are rendering checkboxes
|
|
537
578
|
if (this._cb) {
|
|
538
579
|
// Set the items
|
|
539
|
-
this._cb.setItems(
|
|
580
|
+
this._cb.setItems(this.generateCheckboxItems());
|
|
540
581
|
return;
|
|
541
582
|
}
|
|
542
583
|
|
|
@@ -614,6 +655,13 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
|
|
|
614
655
|
// Ensure it's an array
|
|
615
656
|
let values = value == null ? [] : (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]);
|
|
616
657
|
|
|
658
|
+
// See if this is a checkbox
|
|
659
|
+
if (this._cb) {
|
|
660
|
+
// Set the value
|
|
661
|
+
this._cb.setValue(this.generateCheckboxValue(value));
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
|
|
617
665
|
// Parse the items
|
|
618
666
|
for (let i = 0; i < this._items.length; i++) {
|
|
619
667
|
let item = this._items[i];
|