@etsoo/materialui 1.0.10 → 1.0.13
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/pages/ViewPage.d.ts +3 -2
- package/lib/pages/ViewPage.js +19 -12
- package/package.json +4 -4
- package/src/pages/ViewPage.tsx +30 -17
package/lib/pages/ViewPage.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
3
3
|
import { GridProps } from '@mui/material';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { CommonPageProps } from './CommonPageProps';
|
|
6
|
+
declare type RowType = boolean | 'default' | 'small';
|
|
6
7
|
/**
|
|
7
8
|
* View page display field
|
|
8
9
|
*/
|
|
@@ -22,13 +23,13 @@ export interface ViewPageField<T extends object> extends GridProps {
|
|
|
22
23
|
/**
|
|
23
24
|
* Display as single row
|
|
24
25
|
*/
|
|
25
|
-
singleRow?:
|
|
26
|
+
singleRow?: RowType;
|
|
26
27
|
/**
|
|
27
28
|
* Render props
|
|
28
29
|
*/
|
|
29
30
|
renderProps?: GridColumnRenderProps;
|
|
30
31
|
}
|
|
31
|
-
declare type ViewPageFieldType<T extends object> = (string & keyof T) | [string & keyof T, GridDataType, GridColumnRenderProps?] | ViewPageField<T>;
|
|
32
|
+
declare type ViewPageFieldType<T extends object> = (string & keyof T) | [string & keyof T, GridDataType, GridColumnRenderProps?, RowType?] | ViewPageField<T>;
|
|
32
33
|
/**
|
|
33
34
|
* View page props
|
|
34
35
|
*/
|
package/lib/pages/ViewPage.js
CHANGED
|
@@ -16,25 +16,36 @@ function formatItemData(fieldData) {
|
|
|
16
16
|
return globalApp.formatDate(fieldData, 'd');
|
|
17
17
|
return `${fieldData}`;
|
|
18
18
|
}
|
|
19
|
+
function getResp(singleRow) {
|
|
20
|
+
return singleRow === 'default'
|
|
21
|
+
? { xs: 12, sm: 12, md: 12, lg: 6, xl: 6 }
|
|
22
|
+
: singleRow === true
|
|
23
|
+
? { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }
|
|
24
|
+
: {
|
|
25
|
+
xs: singleRow === false ? 12 : 6,
|
|
26
|
+
sm: 6,
|
|
27
|
+
md: 6,
|
|
28
|
+
lg: 4,
|
|
29
|
+
xl: 3
|
|
30
|
+
};
|
|
31
|
+
}
|
|
19
32
|
function getItemField(field, data) {
|
|
20
33
|
var _a, _b, _c;
|
|
21
34
|
// Item data and label
|
|
22
35
|
let itemData, itemLabel, gridProps = {};
|
|
23
|
-
let xs = 6;
|
|
24
36
|
if (Array.isArray(field)) {
|
|
25
|
-
const [fieldData, fieldType, renderProps] = field;
|
|
37
|
+
const [fieldData, fieldType, renderProps, singleRow = 'small'] = field;
|
|
26
38
|
itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
|
|
27
39
|
itemLabel = (_a = globalApp.get(fieldData)) !== null && _a !== void 0 ? _a : fieldData;
|
|
40
|
+
gridProps = { ...getResp(singleRow) };
|
|
28
41
|
}
|
|
29
42
|
else if (typeof field === 'object') {
|
|
30
43
|
// Destruct
|
|
31
|
-
const { data: fieldData, dataType, label: fieldLabel, renderProps, singleRow, ...rest } = field;
|
|
44
|
+
const { data: fieldData, dataType, label: fieldLabel, renderProps, singleRow = 'default', ...rest } = field;
|
|
32
45
|
gridProps = {
|
|
33
46
|
...rest,
|
|
34
|
-
...(singleRow
|
|
47
|
+
...getResp(singleRow)
|
|
35
48
|
};
|
|
36
|
-
if (singleRow === false)
|
|
37
|
-
xs = 12;
|
|
38
49
|
// Field data
|
|
39
50
|
if (typeof fieldData === 'function')
|
|
40
51
|
itemData = fieldData(data);
|
|
@@ -52,11 +63,7 @@ function getItemField(field, data) {
|
|
|
52
63
|
itemData = formatItemData(data[field]);
|
|
53
64
|
itemLabel = (_c = globalApp.get(field)) !== null && _c !== void 0 ? _c : field;
|
|
54
65
|
}
|
|
55
|
-
return [
|
|
56
|
-
itemData,
|
|
57
|
-
itemLabel,
|
|
58
|
-
{ xs, sm: 6, md: 6, lg: 4, xl: 3, ...gridProps }
|
|
59
|
-
];
|
|
66
|
+
return [itemData, itemLabel, gridProps];
|
|
60
67
|
}
|
|
61
68
|
/**
|
|
62
69
|
* View page
|
|
@@ -94,7 +101,7 @@ export function ViewPage(props) {
|
|
|
94
101
|
React.createElement(Typography, { variant: "caption", component: "div" },
|
|
95
102
|
itemLabel,
|
|
96
103
|
":"),
|
|
97
|
-
React.createElement(Typography, { variant: "subtitle2" }, itemData)));
|
|
104
|
+
typeof itemData === 'object' ? (itemData) : (React.createElement(Typography, { variant: "subtitle2" }, itemData))));
|
|
98
105
|
})),
|
|
99
106
|
actions != null && (React.createElement(Stack, { className: "ET-ViewPage-Actions", direction: "row", width: "100%", flexWrap: "wrap", justifyContent: "flex-end", paddingTop: paddings, paddingBottom: paddings, gap: paddings }, Utils.getResult(actions, data, refresh))),
|
|
100
107
|
Utils.getResult(children, data, refresh),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@etsoo/appscript": "^1.2.90",
|
|
55
55
|
"@etsoo/notificationbase": "^1.1.7",
|
|
56
56
|
"@etsoo/react": "^1.5.89",
|
|
57
|
-
"@etsoo/shared": "^1.1.
|
|
57
|
+
"@etsoo/shared": "^1.1.54",
|
|
58
58
|
"@mui/icons-material": "^5.10.3",
|
|
59
59
|
"@mui/material": "^5.10.4",
|
|
60
60
|
"@types/pica": "^9.0.1",
|
|
@@ -82,10 +82,10 @@
|
|
|
82
82
|
"@babel/runtime-corejs3": "^7.19.0",
|
|
83
83
|
"@testing-library/jest-dom": "^5.16.5",
|
|
84
84
|
"@testing-library/react": "^13.4.0",
|
|
85
|
-
"@types/jest": "^29.0.
|
|
85
|
+
"@types/jest": "^29.0.1",
|
|
86
86
|
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
87
87
|
"@typescript-eslint/parser": "^5.36.2",
|
|
88
|
-
"eslint": "^8.23.
|
|
88
|
+
"eslint": "^8.23.1",
|
|
89
89
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
90
90
|
"eslint-plugin-import": "^2.26.0",
|
|
91
91
|
"eslint-plugin-react": "^7.31.8",
|
package/src/pages/ViewPage.tsx
CHANGED
|
@@ -16,6 +16,8 @@ import { PullToRefreshUI } from '../PullToRefreshUI';
|
|
|
16
16
|
import { CommonPage } from './CommonPage';
|
|
17
17
|
import { CommonPageProps } from './CommonPageProps';
|
|
18
18
|
|
|
19
|
+
type RowType = boolean | 'default' | 'small';
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* View page display field
|
|
21
23
|
*/
|
|
@@ -38,7 +40,7 @@ export interface ViewPageField<T extends object> extends GridProps {
|
|
|
38
40
|
/**
|
|
39
41
|
* Display as single row
|
|
40
42
|
*/
|
|
41
|
-
singleRow?:
|
|
43
|
+
singleRow?: RowType;
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* Render props
|
|
@@ -48,7 +50,7 @@ export interface ViewPageField<T extends object> extends GridProps {
|
|
|
48
50
|
|
|
49
51
|
type ViewPageFieldType<T extends object> =
|
|
50
52
|
| (string & keyof T)
|
|
51
|
-
| [string & keyof T, GridDataType, GridColumnRenderProps?]
|
|
53
|
+
| [string & keyof T, GridDataType, GridColumnRenderProps?, RowType?]
|
|
52
54
|
| ViewPageField<T>;
|
|
53
55
|
|
|
54
56
|
/**
|
|
@@ -98,6 +100,20 @@ function formatItemData(fieldData: unknown): string | undefined {
|
|
|
98
100
|
return `${fieldData}`;
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
function getResp(singleRow: RowType) {
|
|
104
|
+
return singleRow === 'default'
|
|
105
|
+
? { xs: 12, sm: 12, md: 12, lg: 6, xl: 6 }
|
|
106
|
+
: singleRow === true
|
|
107
|
+
? { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }
|
|
108
|
+
: {
|
|
109
|
+
xs: singleRow === false ? 12 : 6,
|
|
110
|
+
sm: 6,
|
|
111
|
+
md: 6,
|
|
112
|
+
lg: 4,
|
|
113
|
+
xl: 3
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
101
117
|
function getItemField<T extends object>(
|
|
102
118
|
field: ViewPageFieldType<T>,
|
|
103
119
|
data: T
|
|
@@ -107,12 +123,11 @@ function getItemField<T extends object>(
|
|
|
107
123
|
itemLabel: React.ReactNode,
|
|
108
124
|
gridProps: GridProps = {};
|
|
109
125
|
|
|
110
|
-
let xs = 6;
|
|
111
|
-
|
|
112
126
|
if (Array.isArray(field)) {
|
|
113
|
-
const [fieldData, fieldType, renderProps] = field;
|
|
127
|
+
const [fieldData, fieldType, renderProps, singleRow = 'small'] = field;
|
|
114
128
|
itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
|
|
115
129
|
itemLabel = globalApp.get<string>(fieldData) ?? fieldData;
|
|
130
|
+
gridProps = { ...getResp(singleRow) };
|
|
116
131
|
} else if (typeof field === 'object') {
|
|
117
132
|
// Destruct
|
|
118
133
|
const {
|
|
@@ -120,17 +135,15 @@ function getItemField<T extends object>(
|
|
|
120
135
|
dataType,
|
|
121
136
|
label: fieldLabel,
|
|
122
137
|
renderProps,
|
|
123
|
-
singleRow,
|
|
138
|
+
singleRow = 'default',
|
|
124
139
|
...rest
|
|
125
140
|
} = field;
|
|
126
141
|
|
|
127
142
|
gridProps = {
|
|
128
143
|
...rest,
|
|
129
|
-
...(singleRow
|
|
144
|
+
...getResp(singleRow)
|
|
130
145
|
};
|
|
131
146
|
|
|
132
|
-
if (singleRow === false) xs = 12;
|
|
133
|
-
|
|
134
147
|
// Field data
|
|
135
148
|
if (typeof fieldData === 'function') itemData = fieldData(data);
|
|
136
149
|
else if (dataType == null) itemData = formatItemData(data[fieldData]);
|
|
@@ -149,11 +162,7 @@ function getItemField<T extends object>(
|
|
|
149
162
|
itemLabel = globalApp.get<string>(field) ?? field;
|
|
150
163
|
}
|
|
151
164
|
|
|
152
|
-
return [
|
|
153
|
-
itemData,
|
|
154
|
-
itemLabel,
|
|
155
|
-
{ xs, sm: 6, md: 6, lg: 4, xl: 3, ...gridProps }
|
|
156
|
-
];
|
|
165
|
+
return [itemData, itemLabel, gridProps];
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
/**
|
|
@@ -236,9 +245,13 @@ export function ViewPage<T extends DataTypes.StringRecord>(
|
|
|
236
245
|
>
|
|
237
246
|
{itemLabel}:
|
|
238
247
|
</Typography>
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
248
|
+
{typeof itemData === 'object' ? (
|
|
249
|
+
itemData
|
|
250
|
+
) : (
|
|
251
|
+
<Typography variant="subtitle2">
|
|
252
|
+
{itemData}
|
|
253
|
+
</Typography>
|
|
254
|
+
)}
|
|
242
255
|
</Grid>
|
|
243
256
|
);
|
|
244
257
|
})}
|