@newskit-render/shared-components 3.12.1-alpha.2 → 3.13.0-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 +13 -0
- package/dist/cjs/ContentListView/index.d.ts +1 -0
- package/dist/cjs/ContentListView/index.js +1 -0
- package/dist/cjs/ContentListView/index.js.map +1 -1
- package/dist/cjs/ContentListView/types.d.ts +5 -0
- package/dist/cjs/ContentListView/types.js.map +1 -1
- package/dist/cjs/ContentListView/utils.d.ts +2 -0
- package/dist/cjs/ContentListView/utils.js +23 -0
- package/dist/cjs/ContentListView/utils.js.map +1 -0
- package/dist/esm/ContentListView/index.d.ts +1 -0
- package/dist/esm/ContentListView/index.js +1 -0
- package/dist/esm/ContentListView/index.js.map +1 -1
- package/dist/esm/ContentListView/types.d.ts +5 -0
- package/dist/esm/ContentListView/types.js.map +1 -1
- package/dist/esm/ContentListView/utils.d.ts +2 -0
- package/dist/esm/ContentListView/utils.js +16 -0
- package/dist/esm/ContentListView/utils.js.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -226,6 +226,19 @@ interface ContentListViewProps {
|
|
|
226
226
|
|
|
227
227
|
`ContentListView` uses some components internally and exports 3 additional components: `ListItem`, `DateItemButtons` and `DateItemStatus`.
|
|
228
228
|
|
|
229
|
+
## filterListItems
|
|
230
|
+
|
|
231
|
+
This function filters a list of items based on specified criteria. It accepts two arguments:
|
|
232
|
+
- ListItems: Array with list items
|
|
233
|
+
- data: The data which will be used for filtering
|
|
234
|
+
|
|
235
|
+
List items contains filter object that contains two attributes:
|
|
236
|
+
- dataPath - The path to the field in the data object used for filtering the items.
|
|
237
|
+
- showOnTrue - Set to true if you want the item to be included in the filtered list when the dataPath returns true.
|
|
238
|
+
Set to false if you want the item to be excluded from the filtered list.
|
|
239
|
+
|
|
240
|
+
The function will return an item if filter is not provided, or the provided data path does not exist in the data object.
|
|
241
|
+
|
|
229
242
|
## ListItem
|
|
230
243
|
|
|
231
244
|
This is the regular list item. It is used in `my-account` main pages and takes the following
|
|
@@ -21,4 +21,5 @@ __exportStar(require("./DateItemStatus"), exports);
|
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
22
|
__exportStar(require("./defaults"), exports);
|
|
23
23
|
__exportStar(require("./style-presets"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentListView/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,6CAA0B;AAC1B,oDAAiC;AACjC,mDAAgC;AAChC,0CAAuB;AACvB,6CAA0B;AAC1B,kDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentListView/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,6CAA0B;AAC1B,oDAAiC;AACjC,mDAAgC;AAChC,0CAAuB;AACvB,6CAA0B;AAC1B,kDAA+B;AAC/B,0CAAuB"}
|
|
@@ -9,6 +9,10 @@ export interface LabelIcon {
|
|
|
9
9
|
stylePreset?: MQ<string>;
|
|
10
10
|
} & LogicalProps;
|
|
11
11
|
}
|
|
12
|
+
export interface ListItemTypeFilter {
|
|
13
|
+
dataPath: string;
|
|
14
|
+
showOnTrue?: boolean;
|
|
15
|
+
}
|
|
12
16
|
export interface ListItemType {
|
|
13
17
|
href?: string;
|
|
14
18
|
label: string;
|
|
@@ -31,6 +35,7 @@ export interface ListItemType {
|
|
|
31
35
|
};
|
|
32
36
|
'data-testid'?: string;
|
|
33
37
|
tooltip?: ListItemTooltip;
|
|
38
|
+
filter?: ListItemTypeFilter;
|
|
34
39
|
}
|
|
35
40
|
export interface ListItemTooltip {
|
|
36
41
|
content: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ContentListView/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ContentListView/types.ts"],"names":[],"mappings":";;;AA4DA,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;AACzB,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.filterListItems = void 0;
|
|
7
|
+
var lodash_get_1 = __importDefault(require("lodash.get"));
|
|
8
|
+
var filterListItems = function (items, data) {
|
|
9
|
+
return items.filter(function (item) {
|
|
10
|
+
if (!item.filter) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
var value = (0, lodash_get_1.default)(data, item.filter.dataPath, 'NOT AVAILABLE');
|
|
14
|
+
if (value === 'NOT AVAILABLE')
|
|
15
|
+
return true;
|
|
16
|
+
if (value === false) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return item.filter.showOnTrue ? value === true : value !== true;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
exports.filterListItems = filterListItems;
|
|
23
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/ContentListView/utils.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAGrB,IAAM,eAAe,GAAG,UAC7B,KAAqB,EACrB,IAAO;IAEP,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,IAAI;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,OAAO,IAAI,CAAA;SACZ;QAED,IAAM,KAAK,GAAG,IAAA,oBAAG,EAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAE9D,IAAI,KAAK,KAAK,eAAe;YAAE,OAAO,IAAI,CAAA;QAE1C,IAAI,KAAK,KAAK,KAAK,EAAE;YACnB,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAA;IACjE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAnBY,QAAA,eAAe,mBAmB3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentListView/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentListView/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA"}
|
|
@@ -9,6 +9,10 @@ export interface LabelIcon {
|
|
|
9
9
|
stylePreset?: MQ<string>;
|
|
10
10
|
} & LogicalProps;
|
|
11
11
|
}
|
|
12
|
+
export interface ListItemTypeFilter {
|
|
13
|
+
dataPath: string;
|
|
14
|
+
showOnTrue?: boolean;
|
|
15
|
+
}
|
|
12
16
|
export interface ListItemType {
|
|
13
17
|
href?: string;
|
|
14
18
|
label: string;
|
|
@@ -31,6 +35,7 @@ export interface ListItemType {
|
|
|
31
35
|
};
|
|
32
36
|
'data-testid'?: string;
|
|
33
37
|
tooltip?: ListItemTooltip;
|
|
38
|
+
filter?: ListItemTypeFilter;
|
|
34
39
|
}
|
|
35
40
|
export interface ListItemTooltip {
|
|
36
41
|
content: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ContentListView/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ContentListView/types.ts"],"names":[],"mappings":"AA4DA,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;AACzB,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import get from 'lodash.get';
|
|
2
|
+
export var filterListItems = function (items, data) {
|
|
3
|
+
return items.filter(function (item) {
|
|
4
|
+
if (!item.filter) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
var value = get(data, item.filter.dataPath, 'NOT AVAILABLE');
|
|
8
|
+
if (value === 'NOT AVAILABLE')
|
|
9
|
+
return true;
|
|
10
|
+
if (value === false) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return item.filter.showOnTrue ? value === true : value !== true;
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/ContentListView/utils.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAA;AAG5B,MAAM,CAAC,IAAM,eAAe,GAAG,UAC7B,KAAqB,EACrB,IAAO;IAEP,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,IAAI;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,OAAO,IAAI,CAAA;SACZ;QAED,IAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAE9D,IAAI,KAAK,KAAK,eAAe;YAAE,OAAO,IAAI,CAAA;QAE1C,IAAI,KAAK,KAAK,KAAK,EAAE;YACnB,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAA;IACjE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newskit-render/shared-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0-alpha.0",
|
|
4
4
|
"description": "Newskit Render Shared Components",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@newskit-themes/tls": "0.0.0",
|
|
38
38
|
"cookie": "0.5.0",
|
|
39
39
|
"cross-fetch": "3.1.5",
|
|
40
|
+
"lodash.get": "4.4.2",
|
|
40
41
|
"react-dates": "21.8.0",
|
|
41
42
|
"striptags": "3.2.0"
|
|
42
43
|
},
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"@babel/polyfill": "7.12.1",
|
|
46
47
|
"@babel/register": "7.18.9",
|
|
47
48
|
"@emotion/jest": "11.10.5",
|
|
48
|
-
"@newskit-render/validation": "^1.8.1
|
|
49
|
+
"@newskit-render/validation": "^1.8.1",
|
|
49
50
|
"@storybook/addon-actions": "6.2.9",
|
|
50
51
|
"@storybook/react": "6.2.9",
|
|
51
52
|
"@testing-library/jest-dom": "5.16.5",
|