@draftbit/core 47.3.2-c6ac02.2 → 47.3.2-ec0f78.2
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/src/components/NumberInput.d.ts +3 -2
- package/lib/src/components/NumberInput.js +3 -3
- package/lib/src/components/NumberInput.js.map +1 -1
- package/lib/src/interfaces/Icon.d.ts +1 -1
- package/lib/src/interfaces/Icon.js +1 -1
- package/lib/src/interfaces/Icon.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/NumberInput.js +3 -3
- package/src/components/NumberInput.js.map +1 -1
- package/src/components/NumberInput.tsx +52 -53
- package/src/interfaces/Icon.js +1 -1
- package/src/interfaces/Icon.js.map +1 -1
- package/src/interfaces/Icon.ts +7 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "47.3.2-
|
|
3
|
+
"version": "47.3.2-ec0f78.2+ec0f78a",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@date-io/date-fns": "^1.3.13",
|
|
41
41
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
42
|
-
"@draftbit/types": "^47.3.2-
|
|
42
|
+
"@draftbit/types": "^47.3.2-ec0f78.2+ec0f78a",
|
|
43
43
|
"@expo/vector-icons": "^13.0.0",
|
|
44
44
|
"@material-ui/core": "^4.11.0",
|
|
45
45
|
"@material-ui/pickers": "^3.2.10",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"node_modules/",
|
|
80
80
|
"lib/"
|
|
81
81
|
],
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "ec0f78aa43d41e487c1056cf1ee3a2030e5052b2"
|
|
83
83
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { TextInput } from "react-native";
|
|
3
3
|
import { isString, isNumber, isNaN } from "lodash";
|
|
4
|
-
const NumberInput = ({ onChangeText, value, defaultValue, ...props }) => {
|
|
4
|
+
const NumberInput = React.forwardRef(({ onChangeText, value, defaultValue, ...props }, ref) => {
|
|
5
5
|
const [currentStringNumberValue, setCurrentStringNumberValue] = useState("");
|
|
6
6
|
const formatValueToStringNumber = (valueToFormat) => {
|
|
7
7
|
if (valueToFormat != null) {
|
|
@@ -44,7 +44,7 @@ const NumberInput = ({ onChangeText, value, defaultValue, ...props }) => {
|
|
|
44
44
|
}
|
|
45
45
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
46
|
}, []);
|
|
47
|
-
return (React.createElement(TextInput, { keyboardType: "numeric", value: currentStringNumberValue, onChangeText: handleChangeText, ...props }));
|
|
48
|
-
};
|
|
47
|
+
return (React.createElement(TextInput, { ref: ref, keyboardType: "numeric", value: currentStringNumberValue, onChangeText: handleChangeText, ...props }));
|
|
48
|
+
});
|
|
49
49
|
export default NumberInput;
|
|
50
50
|
//# sourceMappingURL=NumberInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAQnD,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAClC,CAAC,EAAE,YAAY,EAA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uDAAuD;IACzD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,iGAAiG;IACjG,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,wBAAwB,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAEzE,IAAI,wBAAwB,KAAK,wBAAwB,EAAE;YACzD,2BAA2B,CAAC,wBAAwB,CAAC,CAAC;SACvD;QACD,uDAAuD;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,EACR,YAAY,EAAC,SAAS,EACtB,KAAK,EAAE,wBAAwB,EAC/B,YAAY,EAAE,gBAAgB,KAC1B,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { TextInput } from "react-native";
|
|
3
3
|
import { isString, isNumber, isNaN } from "lodash";
|
|
4
4
|
|
|
@@ -8,68 +8,67 @@ interface Props {
|
|
|
8
8
|
onChangeText?: (value?: number) => void;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const NumberInput
|
|
12
|
-
onChangeText,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...props
|
|
16
|
-
}) => {
|
|
17
|
-
const [currentStringNumberValue, setCurrentStringNumberValue] = useState("");
|
|
11
|
+
const NumberInput = React.forwardRef<TextInput, Props>(
|
|
12
|
+
({ onChangeText, value, defaultValue, ...props }, ref) => {
|
|
13
|
+
const [currentStringNumberValue, setCurrentStringNumberValue] =
|
|
14
|
+
useState("");
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
const formatValueToStringNumber = (valueToFormat?: number | string) => {
|
|
17
|
+
if (valueToFormat != null) {
|
|
18
|
+
if (isString(valueToFormat) && valueToFormat !== "") {
|
|
19
|
+
if (/^0[1-9]$/.test(valueToFormat)) {
|
|
20
|
+
return valueToFormat.slice(1);
|
|
21
|
+
} else if (/^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)$/.test(valueToFormat)) {
|
|
22
|
+
return valueToFormat;
|
|
23
|
+
} else {
|
|
24
|
+
return currentStringNumberValue;
|
|
25
|
+
}
|
|
26
|
+
} else if (isNumber(valueToFormat) && !isNaN(valueToFormat)) {
|
|
27
|
+
return valueToFormat.toString();
|
|
28
28
|
}
|
|
29
|
-
} else if (isNumber(valueToFormat) && !isNaN(valueToFormat)) {
|
|
30
|
-
return valueToFormat.toString();
|
|
31
29
|
}
|
|
32
|
-
}
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
return "";
|
|
32
|
+
};
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const handleChangeText = (newValue: string) => {
|
|
35
|
+
const newStringNumberValue = formatValueToStringNumber(newValue);
|
|
36
|
+
const number = parseFloat(newStringNumberValue);
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
setCurrentStringNumberValue(newStringNumberValue);
|
|
39
|
+
onChangeText?.(number);
|
|
40
|
+
};
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
// run handleChangeText with value prop only when value prop changes (and first render to reset currentStringNumberValue)
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const nextStringNumberValue = formatValueToStringNumber(value);
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
if (currentStringNumberValue !== nextStringNumberValue) {
|
|
47
|
+
handleChangeText(nextStringNumberValue);
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
+
}, [value]);
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
// set currentStringNumberValue as defaultValue prop if there is a differnce on first render only
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const defaultStringNumberValue = formatValueToStringNumber(defaultValue);
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
if (currentStringNumberValue !== defaultStringNumberValue) {
|
|
57
|
+
setCurrentStringNumberValue(defaultStringNumberValue);
|
|
58
|
+
}
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
+
}, []);
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
return (
|
|
63
|
+
<TextInput
|
|
64
|
+
ref={ref}
|
|
65
|
+
keyboardType="numeric"
|
|
66
|
+
value={currentStringNumberValue}
|
|
67
|
+
onChangeText={handleChangeText}
|
|
68
|
+
{...props}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
74
73
|
|
|
75
74
|
export default NumberInput;
|
package/src/interfaces/Icon.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* `@draftbit/ui`.
|
|
6
6
|
*/
|
|
7
7
|
import React from "react";
|
|
8
|
-
export const injectIcon = (Component, Icon) => (props) => React.createElement(Component, { ...props, Icon });
|
|
8
|
+
export const injectIcon = (Component, Icon) => React.forwardRef((props, ref) => React.createElement(Component, { ...props, Icon, ref }));
|
|
9
9
|
//# sourceMappingURL=Icon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","sourceRoot":"","sources":["Icon.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B,MAAM,CAAC,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"Icon.js","sourceRoot":"","sources":["Icon.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,SAAiC,EACjC,IAAW,EACX,EAAE,CACF,KAAK,CAAC,UAAU,CAA2B,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxD,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,GAAI,KAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAC/D,CAAC"}
|
package/src/interfaces/Icon.ts
CHANGED
|
@@ -22,10 +22,10 @@ export interface IconSlot {
|
|
|
22
22
|
|
|
23
23
|
type $Without<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
24
24
|
|
|
25
|
-
export const injectIcon =
|
|
26
|
-
<P
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
export const injectIcon = <P extends IconSlot>(
|
|
26
|
+
Component: React.ComponentType<P>,
|
|
27
|
+
Icon: IconI
|
|
28
|
+
) =>
|
|
29
|
+
React.forwardRef<any, $Without<P, "Icon">>((props, ref) =>
|
|
30
|
+
React.createElement(Component, { ...(props as P), Icon, ref })
|
|
31
|
+
);
|