@particle-network/ui-native 0.4.2-beta.16 → 0.4.2-beta.18

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.
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3
3
  import { TextInput } from "react-native";
4
- import { useColors, useKeyboard } from "../../hooks/index.js";
4
+ import { useColors, useI18n, useKeyboard } from "../../hooks/index.js";
5
5
  import { Icon } from "../../icons/index.js";
6
6
  import { HStack } from "../layout/HStack.js";
7
7
  import { VStack } from "../layout/VStack.js";
@@ -16,6 +16,7 @@ const UXInput = /*#__PURE__*/ forwardRef((props, ref)=>{
16
16
  const [isFocused, setIsFocused] = useState(false);
17
17
  const [isInvalid, setIsInvalid] = useState(isInvalidProp);
18
18
  const { isKeyboardVisible } = useKeyboard();
19
+ const i18n = useI18n();
19
20
  useEffect(()=>{
20
21
  if (!isKeyboardVisible && blurOnKeyboardHide) inputRef.current?.blur();
21
22
  }, [
@@ -78,7 +79,7 @@ const UXInput = /*#__PURE__*/ forwardRef((props, ref)=>{
78
79
  setIsInvalid(true);
79
80
  return {
80
81
  isValid: false,
81
- errorMessage: 'This field is required'
82
+ errorMessage: i18n.validation.required
82
83
  };
83
84
  }
84
85
  setIsInvalid(false);
@@ -87,7 +88,8 @@ const UXInput = /*#__PURE__*/ forwardRef((props, ref)=>{
87
88
  };
88
89
  }, [
89
90
  internalValue,
90
- isRequired
91
+ isRequired,
92
+ i18n
91
93
  ]);
92
94
  const renderError = useMemo(()=>{
93
95
  if (isInvalidProp && errorMessage) {
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3
3
  import { Platform, TextInput } from "react-native";
4
- import { useColors, useKeyboard } from "../../hooks/index.js";
4
+ import { useColors, useI18n, useKeyboard } from "../../hooks/index.js";
5
5
  import { Icon } from "../../icons/index.js";
6
6
  import { HStack } from "../layout/HStack.js";
7
7
  import { VStack } from "../layout/VStack.js";
@@ -16,6 +16,7 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
16
16
  const [displayText, setDisplayText] = useState(defaultValue?.toString() ?? '');
17
17
  const [isFocused, setIsFocused] = useState(false);
18
18
  const [isInvalid, setIsInvalid] = useState(isInvalidProp);
19
+ const i18n = useI18n();
19
20
  const { isKeyboardVisible } = useKeyboard();
20
21
  const formatOptions = useMemo(()=>{
21
22
  const restFormatOptions = {
@@ -74,15 +75,15 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
74
75
  const validationResult = useMemo(()=>{
75
76
  if (isNaN(internalValue) && isRequired) return {
76
77
  isValid: false,
77
- errorMessage: 'This field is required'
78
+ errorMessage: i18n.validation.required
78
79
  };
79
80
  if (void 0 !== minValue && internalValue < minValue) return {
80
81
  isValid: false,
81
- errorMessage: `Value must be at least ${minValue}`
82
+ errorMessage: i18n.validation.min.replace('{min}', minValue.toString())
82
83
  };
83
84
  if (void 0 !== maxValue && internalValue > maxValue) return {
84
85
  isValid: false,
85
- errorMessage: `Value must be at most ${maxValue}`
86
+ errorMessage: i18n.validation.max.replace('{max}', maxValue.toString())
86
87
  };
87
88
  setIsInvalid(false);
88
89
  return {
@@ -92,7 +93,8 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
92
93
  internalValue,
93
94
  isRequired,
94
95
  minValue,
95
- maxValue
96
+ maxValue,
97
+ i18n
96
98
  ]);
97
99
  const adjustValueToRange = useCallback((num)=>{
98
100
  if (isNaN(num)) return NaN;
@@ -114,6 +116,7 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
114
116
  if (cleanedText.includes('-') && !cleanedText.startsWith('-')) return;
115
117
  setDisplayText(cleanedText);
116
118
  onChangeText?.(cleanedText);
119
+ if ('' === cleanedText || '-' === cleanedText) return void setInternalValue(NaN);
117
120
  const numValue = Number(cleanedText);
118
121
  isNaN(numValue) ? setInternalValue(NaN) : setInternalValue(numValue);
119
122
  }, [
@@ -127,6 +130,13 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
127
130
  ]);
128
131
  const handleBlur = useCallback((e)=>{
129
132
  setIsFocused(false);
133
+ if ('' === displayText || '-' === displayText) {
134
+ setInternalValue(NaN);
135
+ onChangeText?.('');
136
+ onValueChange?.(NaN);
137
+ onBlur?.(e);
138
+ return;
139
+ }
130
140
  if (!isNaN(internalValue)) {
131
141
  const adjustedValue = adjustValueToFractionDigits(adjustValueToRange(internalValue));
132
142
  if (adjustedValue !== internalValue) {
@@ -139,6 +149,7 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
139
149
  }
140
150
  onBlur?.(e);
141
151
  }, [
152
+ displayText,
142
153
  internalValue,
143
154
  onChangeText,
144
155
  onValueChange,
@@ -163,10 +174,11 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
163
174
  if (isNaN(internalValue)) return '';
164
175
  if (numberFormatter) {
165
176
  const formattedValue = numberFormatter.format(internalValue);
166
- if (formatOptions?.signDisplay === 'exceptZero' || formatOptions?.signDisplay === 'always') {
177
+ const signDisplay = restProps.formatOptions?.signDisplay;
178
+ if ('exceptZero' === signDisplay || 'always' === signDisplay) {
167
179
  if (internalValue > 0) return `+${formattedValue}`;
168
180
  else if (internalValue < 0) ;
169
- else if ('always' === formatOptions.signDisplay) return `+${formattedValue}`;
181
+ else if ('always' === signDisplay) return `+${formattedValue}`;
170
182
  }
171
183
  return formattedValue;
172
184
  }
@@ -176,7 +188,7 @@ const UXNumberInput = /*#__PURE__*/ forwardRef((props, ref)=>{
176
188
  displayText,
177
189
  numberFormatter,
178
190
  isFocused,
179
- formatOptions
191
+ restProps.formatOptions
180
192
  ]);
181
193
  const renderError = useMemo(()=>{
182
194
  if (isInvalidProp && errorMessage) {
@@ -41,5 +41,10 @@ export declare const en: {
41
41
  on: string;
42
42
  off: string;
43
43
  };
44
+ validation: {
45
+ required: string;
46
+ min: string;
47
+ max: string;
48
+ };
44
49
  };
45
50
  export type LocaleText = typeof en;
@@ -40,6 +40,11 @@ const en = {
40
40
  switch: {
41
41
  on: 'On',
42
42
  off: 'Off'
43
+ },
44
+ validation: {
45
+ required: 'This field is required',
46
+ min: 'Value must be greater than {min}',
47
+ max: 'Value must be less than {max}'
43
48
  }
44
49
  };
45
50
  export { en };
@@ -45,6 +45,11 @@ export declare const locales: {
45
45
  on: string;
46
46
  off: string;
47
47
  };
48
+ validation: {
49
+ required: string;
50
+ min: string;
51
+ max: string;
52
+ };
48
53
  };
49
54
  zh: {
50
55
  datePicker: {
@@ -89,6 +94,11 @@ export declare const locales: {
89
94
  on: string;
90
95
  off: string;
91
96
  };
97
+ validation: {
98
+ required: string;
99
+ min: string;
100
+ max: string;
101
+ };
92
102
  };
93
103
  };
94
104
  export declare function getLocaleText(locale: Locale): {
@@ -134,4 +144,9 @@ export declare function getLocaleText(locale: Locale): {
134
144
  on: string;
135
145
  off: string;
136
146
  };
147
+ validation: {
148
+ required: string;
149
+ min: string;
150
+ max: string;
151
+ };
137
152
  };
@@ -40,6 +40,11 @@ const zh = {
40
40
  switch: {
41
41
  on: '开',
42
42
  off: '关'
43
+ },
44
+ validation: {
45
+ required: '请输入',
46
+ min: '值不能小于{min}',
47
+ max: '值不能大于{max}'
43
48
  }
44
49
  };
45
50
  export { zh };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-native",
3
- "version": "0.4.2-beta.16",
3
+ "version": "0.4.2-beta.18",
4
4
  "main": "./entry.js",
5
5
  "react-native": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -89,9 +89,9 @@
89
89
  "unfetch": "^4.2.0",
90
90
  "vite": "^6.3.5",
91
91
  "zustand": "^5.0.8",
92
- "@particle-network/eslint-config": "0.3.0",
93
92
  "@particle-network/icons": "0.4.2-beta.7",
94
- "@particle-network/lintstaged-config": "0.1.0"
93
+ "@particle-network/lintstaged-config": "0.1.0",
94
+ "@particle-network/eslint-config": "0.3.0"
95
95
  },
96
96
  "overrides": {
97
97
  "react-docgen-typescript": "2.2.2",