Browse Source

fix: priceOptions allowZero

Roxas 4 years ago
parent
commit
ae2a0529c2

+ 2
- 1
eslib/PriceOptions/index.d.ts View File

7
     size: "small" | "normal" | "large";
7
     size: "small" | "normal" | "large";
8
     focusScroll: boolean;
8
     focusScroll: boolean;
9
     withTitle: boolean;
9
     withTitle: boolean;
10
+    allowZero: boolean;
10
     titleText?: string | JSX.Element[] | JSX.Element;
11
     titleText?: string | JSX.Element[] | JSX.Element;
11
     inputPlaceholderText?: string;
12
     inputPlaceholderText?: string;
12
     priceOptions?: Array<any>;
13
     priceOptions?: Array<any>;
19
     };
20
     };
20
     inputRef: React.RefObject<any>;
21
     inputRef: React.RefObject<any>;
21
 }
22
 }
22
-declare const PriceOptions: ({ price, onPriceChange, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23
+declare const PriceOptions: ({ price, onPriceChange, allowZero, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23
 export { PriceOptions as default };
24
 export { PriceOptions as default };

+ 5
- 0
eslib/PriceOptions/index.js View File

56
 var PriceOptions = function PriceOptions(_ref) {
56
 var PriceOptions = function PriceOptions(_ref) {
57
   var price = _ref.price,
57
   var price = _ref.price,
58
       onPriceChange = _ref.onPriceChange,
58
       onPriceChange = _ref.onPriceChange,
59
+      allowZero = _ref.allowZero,
59
       _ref$rowMode = _ref.rowMode,
60
       _ref$rowMode = _ref.rowMode,
60
       rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
61
       rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
61
       _ref$size = _ref.size,
62
       _ref$size = _ref.size,
139
         return;
140
         return;
140
       }
141
       }
141
 
142
 
143
+      if (!allowZero && n === 0) {
144
+        return;
145
+      }
146
+
142
       setInputPrice("".concat(n * 100));
147
       setInputPrice("".concat(n * 100));
143
       onPriceChange(n * 100);
148
       onPriceChange(n * 100);
144
     },
149
     },

+ 1
- 1
eslib/PriceOptions/index.js.map
File diff suppressed because it is too large
View File


+ 2
- 1
lib/PriceOptions/index.d.ts View File

7
     size: "small" | "normal" | "large";
7
     size: "small" | "normal" | "large";
8
     focusScroll: boolean;
8
     focusScroll: boolean;
9
     withTitle: boolean;
9
     withTitle: boolean;
10
+    allowZero: boolean;
10
     titleText?: string | JSX.Element[] | JSX.Element;
11
     titleText?: string | JSX.Element[] | JSX.Element;
11
     inputPlaceholderText?: string;
12
     inputPlaceholderText?: string;
12
     priceOptions?: Array<any>;
13
     priceOptions?: Array<any>;
19
     };
20
     };
20
     inputRef: React.RefObject<any>;
21
     inputRef: React.RefObject<any>;
21
 }
22
 }
22
-declare const PriceOptions: ({ price, onPriceChange, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23
+declare const PriceOptions: ({ price, onPriceChange, allowZero, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23
 export { PriceOptions as default };
24
 export { PriceOptions as default };

+ 5
- 0
lib/PriceOptions/index.js View File

63
 var PriceOptions = function PriceOptions(_ref) {
63
 var PriceOptions = function PriceOptions(_ref) {
64
   var price = _ref.price,
64
   var price = _ref.price,
65
       onPriceChange = _ref.onPriceChange,
65
       onPriceChange = _ref.onPriceChange,
66
+      allowZero = _ref.allowZero,
66
       _ref$rowMode = _ref.rowMode,
67
       _ref$rowMode = _ref.rowMode,
67
       rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
68
       rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
68
       _ref$size = _ref.size,
69
       _ref$size = _ref.size,
146
         return;
147
         return;
147
       }
148
       }
148
 
149
 
150
+      if (!allowZero && n === 0) {
151
+        return;
152
+      }
153
+
149
       setInputPrice("".concat(n * 100));
154
       setInputPrice("".concat(n * 100));
150
       onPriceChange(n * 100);
155
       onPriceChange(n * 100);
151
     },
156
     },

+ 1
- 1
lib/PriceOptions/index.js.map
File diff suppressed because it is too large
View File


+ 5
- 0
src/components/Payment/PriceOptions/index.tsx View File

28
   size: "small" | "normal" | "large";
28
   size: "small" | "normal" | "large";
29
   focusScroll: boolean;
29
   focusScroll: boolean;
30
   withTitle: boolean;
30
   withTitle: boolean;
31
+  allowZero: boolean;
31
   titleText?: string | JSX.Element[] | JSX.Element;
32
   titleText?: string | JSX.Element[] | JSX.Element;
32
   inputPlaceholderText?: string;
33
   inputPlaceholderText?: string;
33
   priceOptions?: Array<any>;
34
   priceOptions?: Array<any>;
44
 const PriceOptions = ({
45
 const PriceOptions = ({
45
   price,
46
   price,
46
   onPriceChange,
47
   onPriceChange,
48
+  allowZero,
47
   rowMode = "single",
49
   rowMode = "single",
48
   size = "normal",
50
   size = "normal",
49
   focusScroll = true,
51
   focusScroll = true,
110
             if (Number.isNaN(n)) {
112
             if (Number.isNaN(n)) {
111
               return;
113
               return;
112
             }
114
             }
115
+            if (!allowZero && n === 0) {
116
+              return;
117
+            }
113
             // 测试暂时改成1分
118
             // 测试暂时改成1分
114
             setInputPrice(`${n * 100}`);
119
             setInputPrice(`${n * 100}`);
115
             onPriceChange(n * 100);
120
             onPriceChange(n * 100);

+ 1
- 1
stats.html
File diff suppressed because it is too large
View File