@etsoo/materialui 1.3.20 → 1.3.21
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/NumberInputField.d.ts +13 -0
- package/lib/NumberInputField.js +10 -1
- package/package.json +1 -1
- package/src/NumberInputField.tsx +42 -1
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { InputFieldProps } from "./InputField";
|
|
3
|
+
import { Currency } from "@etsoo/appscript";
|
|
3
4
|
/**
|
|
4
5
|
* Number input field properties
|
|
5
6
|
*/
|
|
6
7
|
export type NumberInputFieldProps = Omit<InputFieldProps, "type" | "inputProps"> & {
|
|
8
|
+
/**
|
|
9
|
+
* Currency
|
|
10
|
+
*/
|
|
11
|
+
currency?: string | Currency;
|
|
12
|
+
/**
|
|
13
|
+
* End symbol
|
|
14
|
+
*/
|
|
15
|
+
endSymbol?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Start (Currency) symbol
|
|
18
|
+
*/
|
|
19
|
+
symbol?: string;
|
|
7
20
|
/**
|
|
8
21
|
* Input field style
|
|
9
22
|
*/
|
package/lib/NumberInputField.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { InputField } from "./InputField";
|
|
3
|
+
import { InputAdornment } from "@mui/material";
|
|
4
|
+
import { NumberUtils } from "@etsoo/shared";
|
|
3
5
|
/**
|
|
4
6
|
* Number input field, for controlled only components, please see IntInputField and MoneyInputField
|
|
5
7
|
* @param props Props
|
|
6
8
|
* @returns Component
|
|
7
9
|
*/
|
|
8
10
|
export function NumberInputField(props) {
|
|
9
|
-
const { inputStyle, min = 0, step = 1,
|
|
11
|
+
const { currency, inputStyle, min = 0, step = 1, symbol = currency
|
|
12
|
+
? `${currency} ${NumberUtils.getCurrencySymbol(currency)}`
|
|
13
|
+
: undefined, endSymbol, max = 9999999, InputProps, ...rest } = props;
|
|
10
14
|
return (React.createElement(InputField, { type: "number", inputProps: {
|
|
11
15
|
min,
|
|
12
16
|
step,
|
|
13
17
|
max,
|
|
14
18
|
style: inputStyle,
|
|
15
19
|
inputMode: "numeric"
|
|
20
|
+
}, InputProps: {
|
|
21
|
+
startAdornment: symbol ? (React.createElement(React.Fragment, null,
|
|
22
|
+
React.createElement(InputAdornment, { position: "start" }, symbol))) : undefined,
|
|
23
|
+
endAdornment: endSymbol ? (React.createElement(InputAdornment, { position: "end" }, endSymbol)) : undefined,
|
|
24
|
+
...InputProps
|
|
16
25
|
}, ...rest }));
|
|
17
26
|
}
|
package/package.json
CHANGED
package/src/NumberInputField.tsx
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { InputField, InputFieldProps } from "./InputField";
|
|
3
|
+
import { Currency } from "@etsoo/appscript";
|
|
4
|
+
import { InputAdornment } from "@mui/material";
|
|
5
|
+
import { NumberUtils } from "@etsoo/shared";
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Number input field properties
|
|
@@ -8,6 +11,21 @@ export type NumberInputFieldProps = Omit<
|
|
|
8
11
|
InputFieldProps,
|
|
9
12
|
"type" | "inputProps"
|
|
10
13
|
> & {
|
|
14
|
+
/**
|
|
15
|
+
* Currency
|
|
16
|
+
*/
|
|
17
|
+
currency?: string | Currency;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* End symbol
|
|
21
|
+
*/
|
|
22
|
+
endSymbol?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Start (Currency) symbol
|
|
26
|
+
*/
|
|
27
|
+
symbol?: string;
|
|
28
|
+
|
|
11
29
|
/**
|
|
12
30
|
* Input field style
|
|
13
31
|
*/
|
|
@@ -35,7 +53,19 @@ export type NumberInputFieldProps = Omit<
|
|
|
35
53
|
* @returns Component
|
|
36
54
|
*/
|
|
37
55
|
export function NumberInputField(props: NumberInputFieldProps) {
|
|
38
|
-
const {
|
|
56
|
+
const {
|
|
57
|
+
currency,
|
|
58
|
+
inputStyle,
|
|
59
|
+
min = 0,
|
|
60
|
+
step = 1,
|
|
61
|
+
symbol = currency
|
|
62
|
+
? `${currency} ${NumberUtils.getCurrencySymbol(currency)}`
|
|
63
|
+
: undefined,
|
|
64
|
+
endSymbol,
|
|
65
|
+
max = 9999999,
|
|
66
|
+
InputProps,
|
|
67
|
+
...rest
|
|
68
|
+
} = props;
|
|
39
69
|
|
|
40
70
|
return (
|
|
41
71
|
<InputField
|
|
@@ -47,6 +77,17 @@ export function NumberInputField(props: NumberInputFieldProps) {
|
|
|
47
77
|
style: inputStyle,
|
|
48
78
|
inputMode: "numeric"
|
|
49
79
|
}}
|
|
80
|
+
InputProps={{
|
|
81
|
+
startAdornment: symbol ? (
|
|
82
|
+
<React.Fragment>
|
|
83
|
+
<InputAdornment position="start">{symbol}</InputAdornment>
|
|
84
|
+
</React.Fragment>
|
|
85
|
+
) : undefined,
|
|
86
|
+
endAdornment: endSymbol ? (
|
|
87
|
+
<InputAdornment position="end">{endSymbol}</InputAdornment>
|
|
88
|
+
) : undefined,
|
|
89
|
+
...InputProps
|
|
90
|
+
}}
|
|
50
91
|
{...rest}
|
|
51
92
|
/>
|
|
52
93
|
);
|