@etsoo/react 1.2.6 → 1.2.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/lib/app/ReactApp.d.ts +8 -0
- package/lib/app/ReactApp.js +10 -0
- package/lib/components/GridColumn.d.ts +29 -0
- package/lib/mu/DataGridEx.js +3 -2
- package/lib/mu/DataGridRenderers.d.ts +1 -1
- package/lib/mu/DataGridRenderers.js +3 -3
- package/package.json +2 -2
- package/src/app/ReactApp.ts +11 -0
- package/src/components/GridColumn.ts +35 -0
- package/src/mu/DataGridEx.tsx +4 -2
- package/src/mu/DataGridRenderers.tsx +12 -5
package/lib/app/ReactApp.d.ts
CHANGED
|
@@ -50,6 +50,14 @@ export declare abstract class ReactApp<S extends IAppSettings, D extends IUser,
|
|
|
50
50
|
* @param culture New culture definition
|
|
51
51
|
*/
|
|
52
52
|
changeCultureEx(dispatch: React.Dispatch<CultureAction>, culture: DataTypes.CultureDefinition): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get money format props
|
|
55
|
+
* @returns Props
|
|
56
|
+
*/
|
|
57
|
+
getMoneyFormatProps(): {
|
|
58
|
+
culture: string;
|
|
59
|
+
currency: string;
|
|
60
|
+
};
|
|
53
61
|
/**
|
|
54
62
|
* Try login
|
|
55
63
|
* Will update user state with UserActionType.Unauthorized
|
package/lib/app/ReactApp.js
CHANGED
|
@@ -50,11 +50,21 @@ export class ReactApp extends CoreApp {
|
|
|
50
50
|
* @param culture New culture definition
|
|
51
51
|
*/
|
|
52
52
|
changeCultureEx(dispatch, culture) {
|
|
53
|
+
// Same?
|
|
54
|
+
if (culture.name === this.culture)
|
|
55
|
+
return;
|
|
53
56
|
// Dispatch action
|
|
54
57
|
dispatch(culture);
|
|
55
58
|
// Super call
|
|
56
59
|
super.changeCulture(culture);
|
|
57
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Get money format props
|
|
63
|
+
* @returns Props
|
|
64
|
+
*/
|
|
65
|
+
getMoneyFormatProps() {
|
|
66
|
+
return { culture: this.culture, currency: this.currency };
|
|
67
|
+
}
|
|
58
68
|
/**
|
|
59
69
|
* Try login
|
|
60
70
|
* Will update user state with UserActionType.Unauthorized
|
|
@@ -61,6 +61,10 @@ export interface GridCellRendererProps<T, P = any> extends GridCellFormatterProp
|
|
|
61
61
|
* Data type
|
|
62
62
|
*/
|
|
63
63
|
type?: GridDataType;
|
|
64
|
+
/**
|
|
65
|
+
* Render props
|
|
66
|
+
*/
|
|
67
|
+
renderProps?: GridColumnRenderProps;
|
|
64
68
|
}
|
|
65
69
|
/**
|
|
66
70
|
* Grid header cell renderer props
|
|
@@ -83,6 +87,27 @@ export interface GridHeaderCellRendererProps<T, P = any> {
|
|
|
83
87
|
*/
|
|
84
88
|
states: GridLoaderStates<T>;
|
|
85
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Grid column render props
|
|
92
|
+
*/
|
|
93
|
+
export interface GridColumnRenderProps {
|
|
94
|
+
/**
|
|
95
|
+
* Culture, like zh-CN
|
|
96
|
+
*/
|
|
97
|
+
readonly culture?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Currency, like USD for US dollar
|
|
100
|
+
*/
|
|
101
|
+
readonly currency?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Number format options
|
|
104
|
+
*/
|
|
105
|
+
readonly numberFormatOptions?: Intl.NumberFormatOptions;
|
|
106
|
+
/**
|
|
107
|
+
* Additional data
|
|
108
|
+
*/
|
|
109
|
+
readonly data?: Readonly<Record<string, any>>;
|
|
110
|
+
}
|
|
86
111
|
/**
|
|
87
112
|
* Grid column
|
|
88
113
|
*/
|
|
@@ -128,6 +153,10 @@ export interface GridColumn<T> {
|
|
|
128
153
|
* Cell renderer
|
|
129
154
|
*/
|
|
130
155
|
cellRenderer?: (props: GridCellRendererProps<T>) => React.ReactNode;
|
|
156
|
+
/**
|
|
157
|
+
* Render props
|
|
158
|
+
*/
|
|
159
|
+
renderProps?: GridColumnRenderProps;
|
|
131
160
|
/**
|
|
132
161
|
* Header cell renderer
|
|
133
162
|
*/
|
package/lib/mu/DataGridEx.js
CHANGED
|
@@ -224,7 +224,7 @@ export function DataGridEx(props) {
|
|
|
224
224
|
*/
|
|
225
225
|
const itemRenderer = ({ columnIndex, rowIndex, style, data, selectedItems }) => {
|
|
226
226
|
// Column
|
|
227
|
-
const { align, cellRenderer = DataGridRenderers.defaultCellRenderer, field, type, valueFormatter } = columns[columnIndex];
|
|
227
|
+
const { align, cellRenderer = DataGridRenderers.defaultCellRenderer, field, type, valueFormatter, renderProps } = columns[columnIndex];
|
|
228
228
|
// Props
|
|
229
229
|
const formatProps = {
|
|
230
230
|
data,
|
|
@@ -260,7 +260,8 @@ export function DataGridEx(props) {
|
|
|
260
260
|
type,
|
|
261
261
|
rowIndex,
|
|
262
262
|
columnIndex,
|
|
263
|
-
cellProps
|
|
263
|
+
cellProps,
|
|
264
|
+
renderProps
|
|
264
265
|
});
|
|
265
266
|
return (React.createElement("div", { className: rowClass, style: style, "data-row": rowIndex, "data-column": columnIndex, onClick: selectable && !checkable ? handleClick : undefined, onMouseOver: selectable ? handleMouseOver : undefined, onMouseOut: selectable ? handleMouseOut : undefined },
|
|
266
267
|
React.createElement(Box, { ...cellProps, onMouseEnter: handleMouseEnter }, child)));
|
|
@@ -10,7 +10,7 @@ export declare namespace DataGridRenderers {
|
|
|
10
10
|
* @param param Props
|
|
11
11
|
* @returns Component
|
|
12
12
|
*/
|
|
13
|
-
function defaultCellRenderer<T extends Record<string, any>>({ cellProps, data, field, formattedValue, columnIndex, type }: GridCellRendererProps<T>): React.ReactNode;
|
|
13
|
+
function defaultCellRenderer<T extends Record<string, any>>({ cellProps, data, field, formattedValue, columnIndex, type, renderProps }: GridCellRendererProps<T>): React.ReactNode;
|
|
14
14
|
/**
|
|
15
15
|
* Default footer item renderer
|
|
16
16
|
* @param param Props
|
|
@@ -14,7 +14,7 @@ export var DataGridRenderers;
|
|
|
14
14
|
* @param param Props
|
|
15
15
|
* @returns Component
|
|
16
16
|
*/
|
|
17
|
-
function defaultCellRenderer({ cellProps, data, field, formattedValue, columnIndex, type }) {
|
|
17
|
+
function defaultCellRenderer({ cellProps, data, field, formattedValue, columnIndex, type, renderProps }) {
|
|
18
18
|
// Is loading
|
|
19
19
|
if (data == null) {
|
|
20
20
|
// First column, show loading indicator
|
|
@@ -37,9 +37,9 @@ export var DataGridRenderers;
|
|
|
37
37
|
// For numbers
|
|
38
38
|
if (typeof value === 'number') {
|
|
39
39
|
if (type === GridDataType.Money || type === GridDataType.IntMoney)
|
|
40
|
-
return NumberUtils.formatMoney(value,
|
|
40
|
+
return NumberUtils.formatMoney(value, renderProps === null || renderProps === void 0 ? void 0 : renderProps.currency, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, type === GridDataType.IntMoney, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
|
|
41
41
|
else
|
|
42
|
-
return NumberUtils.format(value);
|
|
42
|
+
return NumberUtils.format(value, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
|
|
43
43
|
}
|
|
44
44
|
// For boolean
|
|
45
45
|
if (typeof value === 'boolean') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@emotion/react": "^11.4.1",
|
|
45
45
|
"@emotion/style": "^0.8.0",
|
|
46
46
|
"@emotion/styled": "^11.3.0",
|
|
47
|
-
"@etsoo/appscript": "^1.0.
|
|
47
|
+
"@etsoo/appscript": "^1.0.99",
|
|
48
48
|
"@etsoo/notificationbase": "^1.0.78",
|
|
49
49
|
"@etsoo/shared": "^1.0.44",
|
|
50
50
|
"@mui/icons-material": "^5.0.1",
|
package/src/app/ReactApp.ts
CHANGED
|
@@ -106,6 +106,9 @@ export abstract class ReactApp<
|
|
|
106
106
|
dispatch: React.Dispatch<CultureAction>,
|
|
107
107
|
culture: DataTypes.CultureDefinition
|
|
108
108
|
): void {
|
|
109
|
+
// Same?
|
|
110
|
+
if (culture.name === this.culture) return;
|
|
111
|
+
|
|
109
112
|
// Dispatch action
|
|
110
113
|
dispatch(culture);
|
|
111
114
|
|
|
@@ -113,6 +116,14 @@ export abstract class ReactApp<
|
|
|
113
116
|
super.changeCulture(culture);
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Get money format props
|
|
121
|
+
* @returns Props
|
|
122
|
+
*/
|
|
123
|
+
getMoneyFormatProps() {
|
|
124
|
+
return { culture: this.culture, currency: this.currency };
|
|
125
|
+
}
|
|
126
|
+
|
|
116
127
|
/**
|
|
117
128
|
* Try login
|
|
118
129
|
* Will update user state with UserActionType.Unauthorized
|
|
@@ -86,6 +86,11 @@ export interface GridCellRendererProps<T, P = any>
|
|
|
86
86
|
* Data type
|
|
87
87
|
*/
|
|
88
88
|
type?: GridDataType;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Render props
|
|
92
|
+
*/
|
|
93
|
+
renderProps?: GridColumnRenderProps;
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
/**
|
|
@@ -113,6 +118,31 @@ export interface GridHeaderCellRendererProps<T, P = any> {
|
|
|
113
118
|
states: GridLoaderStates<T>;
|
|
114
119
|
}
|
|
115
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Grid column render props
|
|
123
|
+
*/
|
|
124
|
+
export interface GridColumnRenderProps {
|
|
125
|
+
/**
|
|
126
|
+
* Culture, like zh-CN
|
|
127
|
+
*/
|
|
128
|
+
readonly culture?: string;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Currency, like USD for US dollar
|
|
132
|
+
*/
|
|
133
|
+
readonly currency?: string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Number format options
|
|
137
|
+
*/
|
|
138
|
+
readonly numberFormatOptions?: Intl.NumberFormatOptions;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Additional data
|
|
142
|
+
*/
|
|
143
|
+
readonly data?: Readonly<Record<string, any>>;
|
|
144
|
+
}
|
|
145
|
+
|
|
116
146
|
/**
|
|
117
147
|
* Grid column
|
|
118
148
|
*/
|
|
@@ -168,6 +198,11 @@ export interface GridColumn<T> {
|
|
|
168
198
|
*/
|
|
169
199
|
cellRenderer?: (props: GridCellRendererProps<T>) => React.ReactNode;
|
|
170
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Render props
|
|
203
|
+
*/
|
|
204
|
+
renderProps?: GridColumnRenderProps;
|
|
205
|
+
|
|
171
206
|
/**
|
|
172
207
|
* Header cell renderer
|
|
173
208
|
*/
|
package/src/mu/DataGridEx.tsx
CHANGED
|
@@ -505,7 +505,8 @@ export function DataGridEx<T extends Record<string, any>>(
|
|
|
505
505
|
cellRenderer = DataGridRenderers.defaultCellRenderer,
|
|
506
506
|
field,
|
|
507
507
|
type,
|
|
508
|
-
valueFormatter
|
|
508
|
+
valueFormatter,
|
|
509
|
+
renderProps
|
|
509
510
|
} = columns[columnIndex];
|
|
510
511
|
|
|
511
512
|
// Props
|
|
@@ -554,7 +555,8 @@ export function DataGridEx<T extends Record<string, any>>(
|
|
|
554
555
|
type,
|
|
555
556
|
rowIndex,
|
|
556
557
|
columnIndex,
|
|
557
|
-
cellProps
|
|
558
|
+
cellProps,
|
|
559
|
+
renderProps
|
|
558
560
|
});
|
|
559
561
|
|
|
560
562
|
return (
|
|
@@ -21,7 +21,8 @@ export namespace DataGridRenderers {
|
|
|
21
21
|
field,
|
|
22
22
|
formattedValue,
|
|
23
23
|
columnIndex,
|
|
24
|
-
type
|
|
24
|
+
type,
|
|
25
|
+
renderProps
|
|
25
26
|
}: GridCellRendererProps<T>): React.ReactNode {
|
|
26
27
|
// Is loading
|
|
27
28
|
if (data == null) {
|
|
@@ -53,11 +54,17 @@ export namespace DataGridRenderers {
|
|
|
53
54
|
if (type === GridDataType.Money || type === GridDataType.IntMoney)
|
|
54
55
|
return NumberUtils.formatMoney(
|
|
55
56
|
value,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
type === GridDataType.IntMoney
|
|
57
|
+
renderProps?.currency,
|
|
58
|
+
renderProps?.culture,
|
|
59
|
+
type === GridDataType.IntMoney,
|
|
60
|
+
renderProps?.numberFormatOptions
|
|
61
|
+
);
|
|
62
|
+
else
|
|
63
|
+
return NumberUtils.format(
|
|
64
|
+
value,
|
|
65
|
+
renderProps?.culture,
|
|
66
|
+
renderProps?.numberFormatOptions
|
|
59
67
|
);
|
|
60
|
-
else return NumberUtils.format(value);
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
// For boolean
|