@salesforcedevs/dx-components 1.11.0 → 1.12.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"volta": {
|
|
47
47
|
"node": "18.18.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "1c9e6eb2ccd22598e23eaa1f8388a61a2f784394"
|
|
50
50
|
}
|
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
+
<div class="search-input" lwc:if={isSearchable}>
|
|
3
|
+
<dx-input
|
|
4
|
+
class="search-box"
|
|
5
|
+
type="search"
|
|
6
|
+
placeholder={getSearchPlaceholder}
|
|
7
|
+
role="search"
|
|
8
|
+
aria-label="Search the below items"
|
|
9
|
+
icon-symbol="search"
|
|
10
|
+
size="small"
|
|
11
|
+
value={searchValue}
|
|
12
|
+
onchange={onInputChange}
|
|
13
|
+
shortcut-key="j"
|
|
14
|
+
clearable
|
|
15
|
+
></dx-input>
|
|
16
|
+
</div>
|
|
2
17
|
<div class={className}><slot onslotchange={onSlotChange}></slot></div>
|
|
3
18
|
</template>
|
|
@@ -4,6 +4,11 @@ import { GridVariant, LightningSlotElement } from "typings/custom";
|
|
|
4
4
|
|
|
5
5
|
const DEFAULT_COLUMNS = "three";
|
|
6
6
|
|
|
7
|
+
interface SlottedItem {
|
|
8
|
+
originalDiplayValue: string;
|
|
9
|
+
htmlElement: HTMLElement;
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
export default class Grid extends LightningElement {
|
|
8
13
|
@api
|
|
9
14
|
get columns() {
|
|
@@ -16,8 +21,69 @@ export default class Grid extends LightningElement {
|
|
|
16
21
|
this._columns = value;
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
@api searchPlaceholder?: string;
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
The data passed in must be an array of elements equal to the number of items
|
|
28
|
+
slotted into this grid. Each item in the array can either be a string, or an object.
|
|
29
|
+
In the second case, we will search on all the string values of these objects.
|
|
30
|
+
*/
|
|
31
|
+
@api
|
|
32
|
+
set searchData(value: string) {
|
|
33
|
+
const data = JSON.parse(value);
|
|
34
|
+
this._searchData = data.map((item: any) =>
|
|
35
|
+
typeof item === "string"
|
|
36
|
+
? item.toLowerCase()
|
|
37
|
+
: Object.values(item)
|
|
38
|
+
.filter((e) => typeof e === "string")
|
|
39
|
+
.join("")
|
|
40
|
+
.toLowerCase()
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
get searchData(): string[] {
|
|
44
|
+
return this._searchData;
|
|
45
|
+
}
|
|
46
|
+
searchValue: string = "";
|
|
47
|
+
|
|
48
|
+
private get isSearchable(): boolean {
|
|
49
|
+
return (
|
|
50
|
+
Boolean(this.searchData) &&
|
|
51
|
+
this._itemCount > 1 &&
|
|
52
|
+
this.searchData.length === this._itemCount
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private get getSearchPlaceholder(): string {
|
|
57
|
+
return this.searchPlaceholder ? this.searchPlaceholder : "Search";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private onInputChange(e: CustomEvent) {
|
|
61
|
+
this.searchValue = e.detail.toLowerCase();
|
|
62
|
+
this.displaySearchResults();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private displaySearchResults() {
|
|
66
|
+
if (this.searchValue) {
|
|
67
|
+
this._slottedItems?.forEach((item, index) => {
|
|
68
|
+
const searchDatum = this._searchData[index];
|
|
69
|
+
if (searchDatum && searchDatum.indexOf(this.searchValue) > -1) {
|
|
70
|
+
item.htmlElement.style.display = item.originalDiplayValue;
|
|
71
|
+
} else {
|
|
72
|
+
item.htmlElement.style.display = "none";
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
// show all items
|
|
77
|
+
this._slottedItems?.forEach((item) => {
|
|
78
|
+
item.htmlElement.style.display = item.originalDiplayValue;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
19
83
|
_columns!: GridVariant;
|
|
20
|
-
_itemCount: number
|
|
84
|
+
_itemCount: number = 0;
|
|
85
|
+
_slottedItems?: SlottedItem[];
|
|
86
|
+
_searchData: string[] = [];
|
|
21
87
|
|
|
22
88
|
private get className(): string {
|
|
23
89
|
return cx("container", `col-${this.columns}`);
|
|
@@ -67,6 +133,16 @@ export default class Grid extends LightningElement {
|
|
|
67
133
|
}
|
|
68
134
|
|
|
69
135
|
onSlotChange(e: Event) {
|
|
70
|
-
|
|
136
|
+
const slottedItems = (
|
|
137
|
+
e.target as LightningSlotElement
|
|
138
|
+
).assignedElements();
|
|
139
|
+
this._itemCount = slottedItems.length;
|
|
140
|
+
this._slottedItems = slottedItems.map((item) => {
|
|
141
|
+
const htmlElement = item as HTMLElement;
|
|
142
|
+
return {
|
|
143
|
+
originalDiplayValue: htmlElement.style.display,
|
|
144
|
+
htmlElement: htmlElement
|
|
145
|
+
};
|
|
146
|
+
});
|
|
71
147
|
}
|
|
72
148
|
}
|