@etsoo/materialui 1.0.61 → 1.0.63
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/TwoFieldInput.js +14 -4
- package/lib/app/ReactApp.d.ts +1 -1
- package/lib/app/ReactApp.js +2 -2
- package/package.json +1 -1
- package/src/TwoFieldInput.tsx +11 -3
- package/src/app/ReactApp.ts +4 -3
package/lib/TwoFieldInput.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Input, InputAdornment } from '@mui/material';
|
|
|
2
2
|
import ArrowRightAltIcon from '@mui/icons-material/ArrowRightAlt';
|
|
3
3
|
import { useDimensions } from '@etsoo/react';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { DomUtils } from '@etsoo/shared';
|
|
5
|
+
import { DateUtils, DomUtils } from '@etsoo/shared';
|
|
6
6
|
import { InputField } from './InputField';
|
|
7
7
|
/**
|
|
8
8
|
* TwoField Input
|
|
@@ -10,7 +10,6 @@ import { InputField } from './InputField';
|
|
|
10
10
|
* @returns Component
|
|
11
11
|
*/
|
|
12
12
|
export function TwoFieldInput(props) {
|
|
13
|
-
var _a, _b;
|
|
14
13
|
// Destruct
|
|
15
14
|
const { name, inputProps, type = inputProps === null || inputProps === void 0 ? void 0 : inputProps.inputMode, values, onValuesChange, onChange, onInput, ...rest } = props;
|
|
16
15
|
// Local values
|
|
@@ -40,14 +39,25 @@ export function TwoFieldInput(props) {
|
|
|
40
39
|
if (onChange)
|
|
41
40
|
onChange(event);
|
|
42
41
|
};
|
|
42
|
+
const formatValue = (v, type) => {
|
|
43
|
+
if (v == null)
|
|
44
|
+
return '';
|
|
45
|
+
if (typeof v === 'number')
|
|
46
|
+
return v;
|
|
47
|
+
if (type === 'date')
|
|
48
|
+
return DateUtils.formatForInput(v);
|
|
49
|
+
if (type === 'datetime-local')
|
|
50
|
+
return DateUtils.formatForInput(v, true);
|
|
51
|
+
return v;
|
|
52
|
+
};
|
|
43
53
|
// Layout
|
|
44
|
-
return (React.createElement(InputField, { name: `${name}-start`, type: type, defaultValue: (
|
|
54
|
+
return (React.createElement(InputField, { name: `${name}-start`, type: type, defaultValue: formatValue(localValues[0], type), ref: dimensions[0][0], inputProps: inputProps, InputProps: {
|
|
45
55
|
endAdornment: (React.createElement(InputAdornment, { position: "end", sx: {
|
|
46
56
|
display: 'flex',
|
|
47
57
|
alignItems: 'center',
|
|
48
58
|
gap: 1
|
|
49
59
|
} },
|
|
50
60
|
React.createElement(ArrowRightAltIcon, null),
|
|
51
|
-
React.createElement(Input, { type: type, name: `${name}-end`, defaultValue: (
|
|
61
|
+
React.createElement(Input, { type: type, name: `${name}-end`, defaultValue: formatValue(localValues[1], type), disableUnderline: true, onInput: onInput, onChange: handleChange, inputProps: inputProps })))
|
|
52
62
|
}, onInput: onInput, onChange: handleChange, ...rest }));
|
|
53
63
|
}
|
package/lib/app/ReactApp.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
|
|
|
143
143
|
* @param result Action result
|
|
144
144
|
* @param callback Callback
|
|
145
145
|
*/
|
|
146
|
-
alertResult(result: IActionResult, callback?: NotificationReturn<void>): void;
|
|
146
|
+
alertResult(result: IActionResult | string, callback?: NotificationReturn<void>): void;
|
|
147
147
|
/**
|
|
148
148
|
* Change culture
|
|
149
149
|
* @param culture New culture definition
|
package/lib/app/ReactApp.js
CHANGED
|
@@ -88,7 +88,7 @@ export class ReactApp extends CoreApp {
|
|
|
88
88
|
* @param callback Callback
|
|
89
89
|
*/
|
|
90
90
|
alertResult(result, callback) {
|
|
91
|
-
const message = this.formatResult(result);
|
|
91
|
+
const message = typeof result === 'string' ? result : this.formatResult(result);
|
|
92
92
|
if (message.endsWith(')')) {
|
|
93
93
|
const startPos = message.lastIndexOf('(');
|
|
94
94
|
if (startPos > 0) {
|
|
@@ -99,7 +99,7 @@ export class ReactApp extends CoreApp {
|
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
super.alertResult(message, callback);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Change culture
|
package/package.json
CHANGED
package/src/TwoFieldInput.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { Input, InputAdornment } from '@mui/material';
|
|
|
2
2
|
import ArrowRightAltIcon from '@mui/icons-material/ArrowRightAlt';
|
|
3
3
|
import { useDimensions } from '@etsoo/react';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { DomUtils } from '@etsoo/shared';
|
|
5
|
+
import { DateUtils, DomUtils } from '@etsoo/shared';
|
|
6
6
|
import { InputField, InputFieldProps } from './InputField';
|
|
7
7
|
|
|
8
8
|
type ValueType = string | number | Date | null | undefined;
|
|
@@ -80,12 +80,20 @@ export function TwoFieldInput(props: TwoFieldInputProps) {
|
|
|
80
80
|
if (onChange) onChange(event);
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
const formatValue = (v: ValueType, type?: string) => {
|
|
84
|
+
if (v == null) return '';
|
|
85
|
+
if (typeof v === 'number') return v;
|
|
86
|
+
if (type === 'date') return DateUtils.formatForInput(v);
|
|
87
|
+
if (type === 'datetime-local') return DateUtils.formatForInput(v, true);
|
|
88
|
+
return v;
|
|
89
|
+
};
|
|
90
|
+
|
|
83
91
|
// Layout
|
|
84
92
|
return (
|
|
85
93
|
<InputField
|
|
86
94
|
name={`${name}-start`}
|
|
87
95
|
type={type}
|
|
88
|
-
defaultValue={localValues[0]
|
|
96
|
+
defaultValue={formatValue(localValues[0], type)}
|
|
89
97
|
ref={dimensions[0][0]}
|
|
90
98
|
inputProps={inputProps}
|
|
91
99
|
InputProps={{
|
|
@@ -102,7 +110,7 @@ export function TwoFieldInput(props: TwoFieldInputProps) {
|
|
|
102
110
|
<Input
|
|
103
111
|
type={type}
|
|
104
112
|
name={`${name}-end`}
|
|
105
|
-
defaultValue={localValues[1]
|
|
113
|
+
defaultValue={formatValue(localValues[1], type)}
|
|
106
114
|
disableUnderline
|
|
107
115
|
onInput={onInput}
|
|
108
116
|
onChange={handleChange}
|
package/src/app/ReactApp.ts
CHANGED
|
@@ -280,10 +280,11 @@ export class ReactApp<
|
|
|
280
280
|
* @param callback Callback
|
|
281
281
|
*/
|
|
282
282
|
override alertResult(
|
|
283
|
-
result: IActionResult,
|
|
283
|
+
result: IActionResult | string,
|
|
284
284
|
callback?: NotificationReturn<void>
|
|
285
285
|
) {
|
|
286
|
-
const message =
|
|
286
|
+
const message =
|
|
287
|
+
typeof result === 'string' ? result : this.formatResult(result);
|
|
287
288
|
if (message.endsWith(')')) {
|
|
288
289
|
const startPos = message.lastIndexOf('(');
|
|
289
290
|
if (startPos > 0) {
|
|
@@ -305,7 +306,7 @@ export class ReactApp<
|
|
|
305
306
|
return;
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
|
-
|
|
309
|
+
super.alertResult(message, callback);
|
|
309
310
|
}
|
|
310
311
|
|
|
311
312
|
/**
|