@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.
Files changed (29) hide show
  1. package/lib/commonjs/components/Checkbox/CheckboxGroup.js +5 -17
  2. package/lib/commonjs/components/Checkbox/CheckboxGroup.js.map +1 -1
  3. package/lib/commonjs/components/DeprecatedCardWrapper.js +2 -14
  4. package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
  5. package/lib/commonjs/components/NumberInput.js +30 -29
  6. package/lib/commonjs/components/NumberInput.js.map +1 -1
  7. package/lib/commonjs/components/Picker/PickerComponent.ios.js +10 -30
  8. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -1
  9. package/lib/commonjs/components/RadioButton/index.js.map +1 -1
  10. package/lib/commonjs/components/Row.js.map +1 -1
  11. package/lib/commonjs/components/Swiper/Swiper.js.map +1 -1
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/mappings/SafeAreaView.js.map +1 -1
  14. package/lib/commonjs/mappings/Slider.js.map +1 -1
  15. package/lib/commonjs/mappings/TextInput.js +7 -2
  16. package/lib/commonjs/mappings/TextInput.js.map +1 -1
  17. package/lib/module/components/NumberInput.js +26 -25
  18. package/lib/module/components/NumberInput.js.map +1 -1
  19. package/lib/module/components/RadioButton/RadioButtonGroup.js +5 -16
  20. package/lib/module/components/RadioButton/RadioButtonGroup.js.map +1 -1
  21. package/lib/module/mappings/TextInput.js +8 -3
  22. package/lib/module/mappings/TextInput.js.map +1 -1
  23. package/lib/typescript/src/components/NumberInput.d.ts +5 -5
  24. package/lib/typescript/src/mappings/TextInput.d.ts +38 -38
  25. package/package.json +2 -2
  26. package/src/components/NumberInput.js +26 -21
  27. package/src/components/NumberInput.tsx +39 -30
  28. package/src/mappings/TextInput.js +7 -2
  29. 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: (value?: number) => void;
6
+ value?: number | string;
7
+ defaultValue?: number | string;
8
+ onChangeText?: (value?: number) => void;
8
9
  }
9
10
 
10
- const NumberInput: React.FC<Props> = ({
11
+ const NumberInput: FC<Props> = ({
11
12
  onChangeText,
12
13
  value,
13
14
  defaultValue,
14
15
  ...props
15
16
  }) => {
16
- const [isDecimal, setIsDecimal] = React.useState(
17
- value && !Number.isInteger(value)
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
- if (onChangeText) {
27
- const parsedNumber = parseFloat(newValue);
28
- const number = isNaN(parsedNumber) ? 0 : parsedNumber;
29
- setIsDecimal(newValue.includes("."));
30
- onChangeText(number);
31
- }
32
- };
43
+ const newStringNumberValue = formatValueToStringNumber(
44
+ newValue,
45
+ stringNumberValue
46
+ );
47
+ const number = parseFloat(newStringNumberValue);
33
48
 
34
- let strValue;
35
- if (value != undefined) {
36
- strValue = value.toString();
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={strValue}
47
- defaultValue={defaultValue?.toString()}
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
  ];