@etsoo/materialui 1.3.10 → 1.3.12
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/lib/CultureDataTable.d.ts +18 -0
- package/lib/CultureDataTable.js +30 -0
- package/lib/MUUtils.d.ts +8 -0
- package/lib/MUUtils.js +23 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +6 -6
- package/src/CultureDataTable.tsx +60 -0
- package/src/MUUtils.ts +29 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DataTableProps } from "./DataTable";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ListType1 } from "@etsoo/shared";
|
|
4
|
+
/**
|
|
5
|
+
* Culture table props
|
|
6
|
+
*/
|
|
7
|
+
export type CultureDataTableProps = Omit<DataTableProps, "columns"> & {
|
|
8
|
+
cultures: ListType1[];
|
|
9
|
+
cultureLabel?: string;
|
|
10
|
+
editable?: boolean;
|
|
11
|
+
titleLabel?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Culture DataTable
|
|
15
|
+
* @param props Props
|
|
16
|
+
* @returns Component
|
|
17
|
+
*/
|
|
18
|
+
export declare function CultureDataTable(props: CultureDataTableProps): React.JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DataTable } from "./DataTable";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { globalApp } from "./app/ReactApp";
|
|
4
|
+
/**
|
|
5
|
+
* Culture DataTable
|
|
6
|
+
* @param props Props
|
|
7
|
+
* @returns Component
|
|
8
|
+
*/
|
|
9
|
+
export function CultureDataTable(props) {
|
|
10
|
+
// Destruct
|
|
11
|
+
const { cultures, cultureLabel = globalApp === null || globalApp === void 0 ? void 0 : globalApp.get("culture"), editable = true, titleLabel, ...rest } = props;
|
|
12
|
+
const getCultureLabel = React.useCallback((value) => { var _a, _b; return (_b = (_a = cultures.find((c) => c.id == value.id)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : `${value.value}`; }, [cultures]);
|
|
13
|
+
return (React.createElement(DataTable, { columns: [
|
|
14
|
+
{
|
|
15
|
+
field: "id",
|
|
16
|
+
headerName: cultureLabel,
|
|
17
|
+
valueFormatter: getCultureLabel,
|
|
18
|
+
width: 150,
|
|
19
|
+
editable: false,
|
|
20
|
+
sortable: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
field: "title",
|
|
24
|
+
headerName: titleLabel,
|
|
25
|
+
flex: 1,
|
|
26
|
+
editable,
|
|
27
|
+
sortable: false
|
|
28
|
+
}
|
|
29
|
+
], ...rest }));
|
|
30
|
+
}
|
package/lib/MUUtils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ListType2 } from "@etsoo/shared";
|
|
2
|
+
import { GridApiCommunity } from "@mui/x-data-grid/models/api/gridApiCommunity";
|
|
2
3
|
/**
|
|
3
4
|
* MU utilities
|
|
4
5
|
*/
|
|
@@ -9,4 +10,11 @@ export declare namespace MUUtils {
|
|
|
9
10
|
* @returns Result
|
|
10
11
|
*/
|
|
11
12
|
function getListItemLabel(item: ListType2): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get grid data
|
|
15
|
+
* @param grid Grid
|
|
16
|
+
* @param checkField Check field or callback
|
|
17
|
+
* @returns Results
|
|
18
|
+
*/
|
|
19
|
+
function getGridData<T>(grid: GridApiCommunity, checkField: keyof T | ((item: T) => boolean)): T[];
|
|
12
20
|
}
|
package/lib/MUUtils.js
CHANGED
|
@@ -16,4 +16,27 @@ export var MUUtils;
|
|
|
16
16
|
: item.title;
|
|
17
17
|
}
|
|
18
18
|
MUUtils.getListItemLabel = getListItemLabel;
|
|
19
|
+
/**
|
|
20
|
+
* Get grid data
|
|
21
|
+
* @param grid Grid
|
|
22
|
+
* @param checkField Check field or callback
|
|
23
|
+
* @returns Results
|
|
24
|
+
*/
|
|
25
|
+
function getGridData(grid, checkField) {
|
|
26
|
+
const check = typeof checkField === "function"
|
|
27
|
+
? checkField
|
|
28
|
+
: (item) => {
|
|
29
|
+
const value = item[checkField];
|
|
30
|
+
return value == null || value === "" ? false : true;
|
|
31
|
+
};
|
|
32
|
+
const items = [];
|
|
33
|
+
for (const [_, value] of grid.getRowModels()) {
|
|
34
|
+
const item = value;
|
|
35
|
+
if (check(item)) {
|
|
36
|
+
items.push(item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return items;
|
|
40
|
+
}
|
|
41
|
+
MUUtils.getGridData = getGridData;
|
|
19
42
|
})(MUUtils || (MUUtils = {}));
|
package/lib/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export * from "./ComboBoxMultiple";
|
|
|
44
44
|
export * from "./ComboBoxPro";
|
|
45
45
|
export * from "./CountdownButton";
|
|
46
46
|
export * from "./CountryList";
|
|
47
|
+
export * from "./CultureDataTable";
|
|
47
48
|
export * from "./CustomFabProps";
|
|
48
49
|
export * from "./DataGridEx";
|
|
49
50
|
export * from "./DataGridRenderers";
|
package/lib/index.js
CHANGED
|
@@ -44,6 +44,7 @@ export * from "./ComboBoxMultiple";
|
|
|
44
44
|
export * from "./ComboBoxPro";
|
|
45
45
|
export * from "./CountdownButton";
|
|
46
46
|
export * from "./CountryList";
|
|
47
|
+
export * from "./CultureDataTable";
|
|
47
48
|
export * from "./CustomFabProps";
|
|
48
49
|
export * from "./DataGridEx";
|
|
49
50
|
export * from "./DataGridRenderers";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.12",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@emotion/css": "^11.11.2",
|
|
51
51
|
"@emotion/react": "^11.11.1",
|
|
52
52
|
"@emotion/styled": "^11.11.0",
|
|
53
|
-
"@etsoo/appscript": "^1.4.
|
|
53
|
+
"@etsoo/appscript": "^1.4.48",
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.28",
|
|
55
55
|
"@etsoo/react": "^1.7.8",
|
|
56
56
|
"@etsoo/shared": "^1.2.12",
|
|
@@ -85,10 +85,10 @@
|
|
|
85
85
|
"@testing-library/jest-dom": "^6.1.3",
|
|
86
86
|
"@testing-library/react": "^14.0.0",
|
|
87
87
|
"@types/jest": "^29.5.4",
|
|
88
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
89
|
-
"@typescript-eslint/parser": "^6.
|
|
90
|
-
"jest": "^29.
|
|
91
|
-
"jest-environment-jsdom": "^29.
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
89
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
90
|
+
"jest": "^29.7.0",
|
|
91
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
92
92
|
"typescript": "^5.2.2"
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DataTable, DataTableProps } from "./DataTable";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { globalApp } from "./app/ReactApp";
|
|
4
|
+
import { ListType1 } from "@etsoo/shared";
|
|
5
|
+
import { GridValueFormatterParams } from "@mui/x-data-grid";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Culture table props
|
|
9
|
+
*/
|
|
10
|
+
export type CultureDataTableProps = Omit<DataTableProps, "columns"> & {
|
|
11
|
+
cultures: ListType1[];
|
|
12
|
+
cultureLabel?: string;
|
|
13
|
+
editable?: boolean;
|
|
14
|
+
titleLabel?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Culture DataTable
|
|
19
|
+
* @param props Props
|
|
20
|
+
* @returns Component
|
|
21
|
+
*/
|
|
22
|
+
export function CultureDataTable(props: CultureDataTableProps) {
|
|
23
|
+
// Destruct
|
|
24
|
+
const {
|
|
25
|
+
cultures,
|
|
26
|
+
cultureLabel = globalApp?.get("culture"),
|
|
27
|
+
editable = true,
|
|
28
|
+
titleLabel,
|
|
29
|
+
...rest
|
|
30
|
+
} = props;
|
|
31
|
+
|
|
32
|
+
const getCultureLabel = React.useCallback(
|
|
33
|
+
(value: GridValueFormatterParams) =>
|
|
34
|
+
cultures.find((c) => c.id == value.id)?.label ?? `${value.value}`,
|
|
35
|
+
[cultures]
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<DataTable
|
|
40
|
+
columns={[
|
|
41
|
+
{
|
|
42
|
+
field: "id",
|
|
43
|
+
headerName: cultureLabel,
|
|
44
|
+
valueFormatter: getCultureLabel,
|
|
45
|
+
width: 150,
|
|
46
|
+
editable: false,
|
|
47
|
+
sortable: false
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
field: "title",
|
|
51
|
+
headerName: titleLabel,
|
|
52
|
+
flex: 1,
|
|
53
|
+
editable,
|
|
54
|
+
sortable: false
|
|
55
|
+
}
|
|
56
|
+
]}
|
|
57
|
+
{...rest}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
package/src/MUUtils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ListType2 } from "@etsoo/shared";
|
|
2
|
+
import { GridApiCommunity } from "@mui/x-data-grid/models/api/gridApiCommunity";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* MU utilities
|
|
@@ -16,4 +17,32 @@ export namespace MUUtils {
|
|
|
16
17
|
? item.name
|
|
17
18
|
: item.title;
|
|
18
19
|
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get grid data
|
|
23
|
+
* @param grid Grid
|
|
24
|
+
* @param checkField Check field or callback
|
|
25
|
+
* @returns Results
|
|
26
|
+
*/
|
|
27
|
+
export function getGridData<T>(
|
|
28
|
+
grid: GridApiCommunity,
|
|
29
|
+
checkField: keyof T | ((item: T) => boolean)
|
|
30
|
+
) {
|
|
31
|
+
const check =
|
|
32
|
+
typeof checkField === "function"
|
|
33
|
+
? checkField
|
|
34
|
+
: (item: T) => {
|
|
35
|
+
const value = item[checkField];
|
|
36
|
+
return value == null || value === "" ? false : true;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const items: T[] = [];
|
|
40
|
+
for (const [_, value] of grid.getRowModels()) {
|
|
41
|
+
const item = value as T;
|
|
42
|
+
if (check(item)) {
|
|
43
|
+
items.push(item);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return items;
|
|
47
|
+
}
|
|
19
48
|
}
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,7 @@ export * from "./ComboBoxMultiple";
|
|
|
48
48
|
export * from "./ComboBoxPro";
|
|
49
49
|
export * from "./CountdownButton";
|
|
50
50
|
export * from "./CountryList";
|
|
51
|
+
export * from "./CultureDataTable";
|
|
51
52
|
export * from "./CustomFabProps";
|
|
52
53
|
export * from "./DataGridEx";
|
|
53
54
|
export * from "./DataGridRenderers";
|