@draftbit/core 43.4.6-5320f5.0 → 43.4.6
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/commonjs/components/Checkbox/CheckboxGroup.js +5 -17
- package/lib/commonjs/components/Checkbox/CheckboxGroup.js.map +1 -1
- package/lib/commonjs/components/DeprecatedCardWrapper.js +2 -14
- package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
- package/lib/commonjs/components/NumberInput.js +30 -29
- package/lib/commonjs/components/NumberInput.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +10 -30
- package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -1
- package/lib/commonjs/components/RadioButton/index.js.map +1 -1
- package/lib/commonjs/components/Row.js.map +1 -1
- package/lib/commonjs/components/Swiper/Swiper.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mappings/SafeAreaView.js.map +1 -1
- package/lib/commonjs/mappings/Slider.js.map +1 -1
- package/lib/commonjs/mappings/TextInput.js +7 -2
- package/lib/commonjs/mappings/TextInput.js.map +1 -1
- package/lib/module/components/NumberInput.js +26 -25
- package/lib/module/components/NumberInput.js.map +1 -1
- package/lib/module/components/RadioButton/RadioButtonGroup.js +5 -16
- package/lib/module/components/RadioButton/RadioButtonGroup.js.map +1 -1
- package/lib/module/mappings/TextInput.js +8 -3
- package/lib/module/mappings/TextInput.js.map +1 -1
- package/lib/typescript/src/components/NumberInput.d.ts +5 -5
- package/lib/typescript/src/mappings/TextInput.d.ts +38 -38
- package/package.json +2 -2
- package/src/components/NumberInput.js +26 -21
- package/src/components/NumberInput.tsx +39 -30
- package/src/mappings/TextInput.js +7 -2
- package/src/mappings/TextInput.ts +7 -1
|
@@ -1,55 +1,64 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { FC, useCallback, useState } from "react";
|
|
2
2
|
import { TextInput } from "react-native";
|
|
3
|
+
import { isString, isNumber, isNaN } from "lodash";
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
5
|
-
value?: number;
|
|
6
|
-
defaultValue?: number;
|
|
7
|
-
onChangeText
|
|
6
|
+
value?: number | string;
|
|
7
|
+
defaultValue?: number | string;
|
|
8
|
+
onChangeText?: (value?: number) => void;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
const NumberInput:
|
|
11
|
+
const NumberInput: FC<Props> = ({
|
|
11
12
|
onChangeText,
|
|
12
13
|
value,
|
|
13
14
|
defaultValue,
|
|
14
15
|
...props
|
|
15
16
|
}) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
const formatValueToStringNumber = useCallback(
|
|
18
|
+
(valueToFormat?: number | string, currentStringNumberValue?: string) => {
|
|
19
|
+
if (valueToFormat != null) {
|
|
20
|
+
if (isString(valueToFormat)) {
|
|
21
|
+
if (/^0[1-9]$/.test(valueToFormat)) {
|
|
22
|
+
return valueToFormat.slice(1);
|
|
23
|
+
} else if (/^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)$/.test(valueToFormat)) {
|
|
24
|
+
return valueToFormat;
|
|
25
|
+
} else if (currentStringNumberValue) {
|
|
26
|
+
return currentStringNumberValue;
|
|
27
|
+
}
|
|
28
|
+
} else if (isNumber(valueToFormat) && !isNaN(valueToFormat)) {
|
|
29
|
+
return valueToFormat.toString();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return "0";
|
|
34
|
+
},
|
|
35
|
+
[]
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const [stringNumberValue, setStringNumberValue] = useState(
|
|
39
|
+
formatValueToStringNumber(value)
|
|
18
40
|
);
|
|
19
|
-
React.useEffect(() => {
|
|
20
|
-
if (value) {
|
|
21
|
-
setIsDecimal(value.toString().includes("."));
|
|
22
|
-
}
|
|
23
|
-
}, [value]);
|
|
24
41
|
|
|
25
42
|
const handleChangeText = (newValue: string) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
};
|
|
43
|
+
const newStringNumberValue = formatValueToStringNumber(
|
|
44
|
+
newValue,
|
|
45
|
+
stringNumberValue
|
|
46
|
+
);
|
|
47
|
+
const number = parseFloat(newStringNumberValue);
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (isDecimal && !strValue.includes(".")) {
|
|
38
|
-
strValue = `${strValue}.`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
49
|
+
setStringNumberValue(newStringNumberValue);
|
|
50
|
+
onChangeText?.(number);
|
|
51
|
+
};
|
|
41
52
|
|
|
42
53
|
return (
|
|
43
54
|
<TextInput
|
|
44
55
|
keyboardType="numeric"
|
|
45
56
|
{...props}
|
|
46
|
-
value={
|
|
47
|
-
defaultValue={defaultValue
|
|
57
|
+
value={stringNumberValue}
|
|
58
|
+
defaultValue={formatValueToStringNumber(defaultValue)}
|
|
48
59
|
onChangeText={handleChangeText}
|
|
49
60
|
/>
|
|
50
61
|
);
|
|
51
62
|
};
|
|
52
63
|
|
|
53
64
|
export default NumberInput;
|
|
54
|
-
|
|
55
|
-
// comment to try to fix sourcemap issue
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GROUPS, COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, FIELD_NAME, TEXT_INPUT_PROPS, NUMBER_INPUT_PROPS, Triggers, } from "@draftbit/types";
|
|
1
|
+
import { GROUPS, COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, FIELD_NAME, TEXT_INPUT_PROPS, NUMBER_INPUT_PROPS, Triggers, createFieldNameProp, } from "@draftbit/types";
|
|
2
2
|
export const SEED_DATA_PROPS = {
|
|
3
3
|
style: {
|
|
4
4
|
group: GROUPS.basic,
|
|
@@ -196,8 +196,13 @@ export const SEED_DATA = [
|
|
|
196
196
|
},
|
|
197
197
|
triggers: [Triggers.OnChangeText],
|
|
198
198
|
props: {
|
|
199
|
-
...NUMBER_INPUT_PROPS,
|
|
200
199
|
...SEED_DATA_PROPS,
|
|
200
|
+
...NUMBER_INPUT_PROPS,
|
|
201
|
+
fieldName: createFieldNameProp({
|
|
202
|
+
defaultValue: "numberInputValue",
|
|
203
|
+
valuePropName: "value",
|
|
204
|
+
handlerPropName: "onChangeText",
|
|
205
|
+
}),
|
|
201
206
|
},
|
|
202
207
|
},
|
|
203
208
|
];
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
TEXT_INPUT_PROPS,
|
|
8
8
|
NUMBER_INPUT_PROPS,
|
|
9
9
|
Triggers,
|
|
10
|
+
createFieldNameProp,
|
|
10
11
|
} from "@draftbit/types";
|
|
11
12
|
|
|
12
13
|
export const SEED_DATA_PROPS = {
|
|
@@ -219,8 +220,13 @@ export const SEED_DATA = [
|
|
|
219
220
|
},
|
|
220
221
|
triggers: [Triggers.OnChangeText],
|
|
221
222
|
props: {
|
|
222
|
-
...NUMBER_INPUT_PROPS,
|
|
223
223
|
...SEED_DATA_PROPS,
|
|
224
|
+
...NUMBER_INPUT_PROPS,
|
|
225
|
+
fieldName: createFieldNameProp({
|
|
226
|
+
defaultValue: "numberInputValue",
|
|
227
|
+
valuePropName: "value",
|
|
228
|
+
handlerPropName: "onChangeText",
|
|
229
|
+
}),
|
|
224
230
|
},
|
|
225
231
|
},
|
|
226
232
|
];
|