iglooform 2.5.8 → 2.5.11

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 (61) hide show
  1. package/es/form/element/index.js +22 -21
  2. package/es/form/elements.js +2 -1
  3. package/es/form/hstep/index.js +14 -5
  4. package/es/form/hstep/style/index.less +2 -7
  5. package/es/form/hsteps/index.d.ts +9 -3
  6. package/es/form/hsteps/index.js +48 -14
  7. package/es/form/hsteps/style/index.less +31 -3
  8. package/es/form/pages/index.js +2 -2
  9. package/es/form/section/style/index.less +4 -0
  10. package/es/form/step/index.js +14 -5
  11. package/es/form/steps/index.js +2 -2
  12. package/es/index.d.ts +1 -1
  13. package/es/index.js +1 -1
  14. package/es/input/index.d.ts +1 -0
  15. package/es/input/index.js +1 -0
  16. package/es/input/input-id.d.ts +6 -0
  17. package/es/input/input-id.js +112 -0
  18. package/es/input/input-number.js +71 -1
  19. package/es/input/phone-number.js +80 -20
  20. package/es/locale/en-US/messages.json +5 -0
  21. package/es/locale/format-message.js +2 -2
  22. package/es/locale/id-ID/messages.json +14 -9
  23. package/es/locale/locale-provider.js +2 -2
  24. package/es/locale/th-TH/messages.json +14 -9
  25. package/es/locale/vi-VN/messages.json +14 -9
  26. package/es/locale/zh-CN/messages.json +14 -9
  27. package/es/locale/zh-TW/messages.json +5 -0
  28. package/es/types.d.ts +4 -0
  29. package/es/upload/style/index.less +2 -0
  30. package/es/upload-photo/index.js +10 -4
  31. package/lib/form/element/index.js +22 -21
  32. package/lib/form/elements.js +1 -0
  33. package/lib/form/hstep/index.js +14 -5
  34. package/lib/form/hstep/style/index.less +2 -7
  35. package/lib/form/hsteps/index.d.ts +9 -3
  36. package/lib/form/hsteps/index.js +48 -14
  37. package/lib/form/hsteps/style/index.less +31 -3
  38. package/lib/form/pages/index.js +2 -2
  39. package/lib/form/section/style/index.less +4 -0
  40. package/lib/form/step/index.js +14 -5
  41. package/lib/form/steps/index.js +2 -2
  42. package/lib/index.d.ts +1 -1
  43. package/lib/index.js +7 -0
  44. package/lib/input/index.d.ts +1 -0
  45. package/lib/input/index.js +8 -0
  46. package/lib/input/input-id.d.ts +6 -0
  47. package/lib/input/input-id.js +127 -0
  48. package/lib/input/input-number.js +72 -1
  49. package/lib/input/phone-number.js +78 -18
  50. package/lib/locale/en-US/messages.json +5 -0
  51. package/lib/locale/format-message.js +2 -2
  52. package/lib/locale/id-ID/messages.json +14 -9
  53. package/lib/locale/locale-provider.js +2 -2
  54. package/lib/locale/th-TH/messages.json +14 -9
  55. package/lib/locale/vi-VN/messages.json +14 -9
  56. package/lib/locale/zh-CN/messages.json +14 -9
  57. package/lib/locale/zh-TW/messages.json +5 -0
  58. package/lib/types.d.ts +4 -0
  59. package/lib/upload/style/index.less +2 -0
  60. package/lib/upload-photo/index.js +10 -4
  61. package/package.json +1 -1
@@ -151,26 +151,6 @@ var Element = function Element(_ref) {
151
151
  var _useBreakpoint = useBreakpoint(),
152
152
  md = _useBreakpoint.md;
153
153
 
154
- if (type === 'Section') {
155
- return _jsx(Section, {
156
- parentName: parentName,
157
- config: config,
158
- preview: preview,
159
- disabled: disabled,
160
- setShowStepButton: setShowStepButton
161
- });
162
- }
163
-
164
- if (type === 'AddableSection') {
165
- return _jsx(AddableSection, {
166
- parentName: parentName,
167
- config: config,
168
- preview: preview,
169
- disabled: disabled,
170
- setShowStepButton: setShowStepButton
171
- });
172
- }
173
-
174
154
  var _calcFormItemProps = calcFormItemProps(config, _objectSpread(_objectSpread({}, extraConfig), {}, {
175
155
  requiredMark: requiredMark
176
156
  }), form, parentName),
@@ -235,7 +215,28 @@ var Element = function Element(_ref) {
235
215
  name: formItemProps.name,
236
216
  value: formItemProps.initialValue
237
217
  }]);
238
- }, [formItemProps.initialValue]); //这里要想一下有没有更优雅的实现方式
218
+ }, [formItemProps.initialValue]);
219
+
220
+ if (type === 'Section') {
221
+ return _jsx(Section, {
222
+ parentName: parentName,
223
+ config: config,
224
+ preview: preview,
225
+ disabled: disabled,
226
+ setShowStepButton: setShowStepButton
227
+ });
228
+ }
229
+
230
+ if (type === 'AddableSection') {
231
+ return _jsx(AddableSection, {
232
+ parentName: parentName,
233
+ config: config,
234
+ preview: preview,
235
+ disabled: disabled,
236
+ setShowStepButton: setShowStepButton
237
+ });
238
+ } //这里要想一下有没有更优雅的实现方式
239
+
239
240
 
240
241
  if (withoutForm) {
241
242
  var hideWhenPreview = elementProps.hideWhenPreview,
@@ -1,7 +1,7 @@
1
1
  import { useMemo } from 'react';
2
2
  import Button from '../button';
3
3
  import Radio, { RadioGroup, RadioGroupWithOther } from '../radio';
4
- import Input, { PhoneNumber, Amount, Email, Password, InputNumber, TextArea, InputDate, CreditCard, Otp, ExpiryDate } from '../input';
4
+ import Input, { PhoneNumber, Amount, Email, Password, InputNumber, TextArea, InputDate, CreditCard, Otp, ExpiryDate, InputId } from '../input';
5
5
  import DatePicker, { IglooBuddhistDatePicker as BuddhistDatePicker, IglooRangePicker as RangePicker, IglooWeekPicker as WeekPicker, IglooMonthPicker as MonthPicker } from '../date-picker';
6
6
  import Confirmation from '../confirmation';
7
7
  import { AttachedSelect as Select, TimeSelect } from '../select';
@@ -18,6 +18,7 @@ var elementMap = {
18
18
  PhoneNumber: PhoneNumber,
19
19
  Amount: Amount,
20
20
  InputNumber: InputNumber,
21
+ InputId: InputId,
21
22
  TextArea: TextArea,
22
23
  DatePicker: DatePicker,
23
24
  CreditCard: CreditCard,
@@ -74,14 +74,23 @@ var Step = function Step(_ref) {
74
74
  md = _useBreakpoint.md;
75
75
 
76
76
  useEffect(function () {
77
- var _containerRef$current, _containerRef$current2, _containerRef$current3;
77
+ var _containerRef$current, _containerRef$current4;
78
78
 
79
79
  if (md || !(shouldScroll && edit)) return;
80
80
  var scrollContainer = getScrollContainer() || window;
81
- (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.offsetTop) ? scrollContainer.scrollTo({
82
- top: (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.offsetTop) - 50,
83
- behavior: 'smooth'
84
- }) : containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.scrollIntoView();
81
+ if (typeof scrollContainer.scrollTo !== 'function') return;
82
+
83
+ if (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.offsetTop) {
84
+ var _containerRef$current2, _containerRef$current3;
85
+
86
+ scrollContainer.scrollTo.length === 2 ? scrollContainer.scrollTo(0, (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.offsetTop) - 50) : scrollContainer.scrollTo({
87
+ top: (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.offsetTop) - 50,
88
+ behavior: 'smooth'
89
+ });
90
+ return;
91
+ }
92
+
93
+ containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.scrollIntoView();
85
94
  }, [shouldScroll, edit]);
86
95
  return _jsxs(_Fragment, {
87
96
  children: [_jsxs("div", {
@@ -2,7 +2,7 @@
2
2
  width: 100%;
3
3
  background: #ffffff;
4
4
  padding: 32px;
5
- margin-top: 16px;
5
+ margin-top: 32px;
6
6
 
7
7
  .igloo-hstep-label {
8
8
  display: flex;
@@ -47,6 +47,7 @@
47
47
  .igloo-hstep-container {
48
48
  width: 100%;
49
49
  padding: 24px 16px;
50
+ margin-top: 0;
50
51
 
51
52
  .igloo-hstep-content {
52
53
  margin-top: 24px;
@@ -59,12 +60,6 @@
59
60
  margin-left: 16px;
60
61
  margin-right: 16px;
61
62
  }
62
-
63
- .igloo-hstep-label {
64
- margin-bottom: 8px;
65
- font-size: 16px;
66
- line-height: 24px;
67
- }
68
63
  }
69
64
 
70
65
  .igloo-hstep-button-container {
@@ -3,11 +3,17 @@ import { FormItemConfig, FormItemName } from '../../types';
3
3
  import './style/index.less';
4
4
  import { ConfirmationProps } from '../../confirmation';
5
5
  export interface HStepsProps {
6
- config: FormItemConfig;
6
+ config: FormItemConfig & {
7
+ confirmations?: {
8
+ [key: string]: {
9
+ required: boolean;
10
+ confirmation?: ConfirmationProps;
11
+ };
12
+ };
13
+ withReview?: boolean;
14
+ };
7
15
  parentName?: FormItemName;
8
16
  name?: FormItemName;
9
- withReview?: boolean;
10
- confirmation?: ConfirmationProps;
11
17
  }
12
18
  declare const HSteps: FC<HStepsProps>;
13
19
  export default HSteps;
@@ -49,8 +49,7 @@ var useBreakpoint = _Grid.useBreakpoint;
49
49
  var HSteps = function HSteps(_ref) {
50
50
  var _renderElements$curre2, _renderElements$curre3;
51
51
 
52
- var name = _ref.name,
53
- parentName = _ref.parentName,
52
+ var parentName = _ref.parentName,
54
53
  _ref$config = _ref.config,
55
54
  _ref$config$elements = _ref$config.elements,
56
55
  elements = _ref$config$elements === void 0 ? [] : _ref$config$elements,
@@ -58,10 +57,10 @@ var HSteps = function HSteps(_ref) {
58
57
  currentStep = _ref$config$currentSt === void 0 ? 0 : _ref$config$currentSt,
59
58
  subscribedFields = _ref$config.subscribedFields,
60
59
  onEdit = _ref$config.onEdit,
61
- _ref$withReview = _ref.withReview,
62
- withReview = _ref$withReview === void 0 ? true : _ref$withReview,
63
- _ref$confirmation = _ref.confirmation,
64
- confirmation = _ref$confirmation === void 0 ? {} : _ref$confirmation;
60
+ confirmations = _ref$config.confirmations,
61
+ _ref$config$withRevie = _ref$config.withReview,
62
+ withReview = _ref$config$withRevie === void 0 ? true : _ref$config$withRevie,
63
+ name = _ref$config.name;
65
64
 
66
65
  var _useState = useState(0),
67
66
  _useState2 = _slicedToArray(_useState, 2),
@@ -235,6 +234,13 @@ var HSteps = function HSteps(_ref) {
235
234
  'igloo-hsteps-bar-item': true,
236
235
  'igloo-hsteps-bar-item-current': index === current
237
236
  }),
237
+ style: {
238
+ cursor: index < current ? 'pointer' : 'default'
239
+ },
240
+ onClick: function onClick() {
241
+ if (index >= current) return;
242
+ setCurrent(index);
243
+ },
238
244
  children: [index < current && _jsx(SuccessFilled, {
239
245
  className: 'igloo-hsteps-bar-item-icon'
240
246
  }), _jsx(Typography, {
@@ -259,9 +265,7 @@ var HSteps = function HSteps(_ref) {
259
265
  })]
260
266
  })]
261
267
  }), _jsxs("div", {
262
- className: classNames({
263
- 'igloo-hsteps-content': !md
264
- }),
268
+ className: "igloo-hsteps-content",
265
269
  children: [current < renderElements.length && _jsx(StepContext.Provider, {
266
270
  value: {
267
271
  registerSection: registerSection
@@ -278,10 +282,14 @@ var HSteps = function HSteps(_ref) {
278
282
  shouldScroll: shouldScroll
279
283
  }, ((_renderElements$curre2 = renderElements[current]) === null || _renderElements$curre2 === void 0 ? void 0 : _renderElements$curre2.key) || ((_renderElements$curre3 = renderElements[current]) === null || _renderElements$curre3 === void 0 ? void 0 : _renderElements$curre3.name))
280
284
  }), current === renderElements.length && _jsxs("div", {
281
- className: "igloo-hstep-container",
285
+ className: "igloo-hsteps-confirmation-container",
282
286
  children: [withReview && !md && _jsxs(Typography, {
283
287
  className: "igloo-hstep-label",
284
288
  level: "h3a",
289
+ style: {
290
+ display: 'flex',
291
+ justifyContent: 'space-between'
292
+ },
285
293
  children: [_jsx("span", {
286
294
  className: "igloo-hstep-label-text",
287
295
  children: formatMessage({
@@ -305,8 +313,8 @@ var HSteps = function HSteps(_ref) {
305
313
  }, (step === null || step === void 0 ? void 0 : step.key) || (step === null || step === void 0 ? void 0 : step.name));
306
314
  }), _jsxs("div", {
307
315
  className: "igloo-hsteps-confirmation",
308
- children: [md && _jsx(Typography, {
309
- level: "h3a",
316
+ children: [_jsx(Typography, {
317
+ level: md ? 'h3a' : 'h4',
310
318
  wrapElement: "div",
311
319
  children: formatMessage({
312
320
  id: 'Review and Submit'
@@ -329,7 +337,7 @@ var HSteps = function HSteps(_ref) {
329
337
  children: formatMessage({
330
338
  id: 'Once you’re happy with the above, and you’ve checked the box below, please go ahead and submit your activation.'
331
339
  })
332
- }), _jsx(_Divider, {}), _jsx(_Form.Item, {
340
+ }), _jsx(_Divider, {}), !confirmations && _jsx(_Form.Item, {
333
341
  name: calcNamePath(parentName, 'confirmation'),
334
342
  rules: [{
335
343
  validator: function validator(_, value) {
@@ -345,7 +353,33 @@ var HSteps = function HSteps(_ref) {
345
353
  style: {
346
354
  margin: 0
347
355
  },
348
- children: _jsx(Confirmation, _objectSpread({}, confirmation))
356
+ children: _jsx(Confirmation, {})
357
+ }), confirmations && Object.entries(confirmations).map(function (_ref6) {
358
+ var _ref7 = _slicedToArray(_ref6, 2),
359
+ key = _ref7[0],
360
+ _ref7$ = _ref7[1],
361
+ required = _ref7$.required,
362
+ _ref7$$confirmation = _ref7$.confirmation,
363
+ confirmation = _ref7$$confirmation === void 0 ? {} : _ref7$$confirmation;
364
+
365
+ return _jsx(_Form.Item, {
366
+ name: calcNamePath(parentName, key),
367
+ rules: [{
368
+ validator: function validator(_, value) {
369
+ if (required && !value) {
370
+ return Promise.reject(formatMessage({
371
+ id: 'Please read and agree to Igloo Terms of Use and Privacy Policy'
372
+ }));
373
+ }
374
+
375
+ return Promise.resolve();
376
+ }
377
+ }],
378
+ style: {
379
+ margin: 0
380
+ },
381
+ children: _jsx(Confirmation, _objectSpread({}, confirmation))
382
+ });
349
383
  }), showSubmitButton && md && _jsx(_Form.Item, {
350
384
  style: {
351
385
  marginBottom: 0
@@ -29,6 +29,12 @@
29
29
  width: 100%;
30
30
  }
31
31
 
32
+ .igloo-hsteps-confirmation-container {
33
+ background: #f9f9f9;
34
+ padding: 0;
35
+ margin: 0;
36
+ }
37
+
32
38
  .igloo-hsteps-button {
33
39
  margin-top: 24px;
34
40
  min-width: 221px;
@@ -38,7 +44,7 @@
38
44
  width: 100%;
39
45
  padding: 32px;
40
46
  background: #ffffff;
41
- margin-top: 16px;
47
+ margin-top: 32px;
42
48
  border-radius: 3px;
43
49
  }
44
50
  }
@@ -49,8 +55,30 @@
49
55
  .igloo-hsteps-content {
50
56
  width: 100%;
51
57
 
52
- .igloo-hsteps-confirmation {
53
- padding: 16px;
58
+ .igloo-hsteps-confirmation-container {
59
+ background: #ffffff;
60
+ padding: 24px 16px;
61
+
62
+ .igloo-hsteps-confirmation {
63
+ padding: 16px;
64
+ margin-top: 8px;
65
+ }
66
+
67
+ .igloo-hstep-container {
68
+ width: 100%;
69
+ padding: 16px;
70
+ border-radius: 10px;
71
+
72
+ &:not(:first-child) {
73
+ margin-top: 24px;
74
+ }
75
+
76
+ .igloo-hstep-label {
77
+ margin-bottom: 8px;
78
+ font-size: 16px;
79
+ line-height: 24px;
80
+ }
81
+ }
54
82
  }
55
83
  }
56
84
 
@@ -32,9 +32,9 @@ import Typography from '../../typography';
32
32
  var useBreakpoint = _Grid.useBreakpoint;
33
33
 
34
34
  var Pages = function Pages(_ref) {
35
- var name = _ref.name,
36
- parentName = _ref.parentName,
35
+ var parentName = _ref.parentName,
37
36
  _ref$config = _ref.config,
37
+ name = _ref$config.name,
38
38
  _ref$config$elements = _ref$config.elements,
39
39
  elements = _ref$config$elements === void 0 ? [] : _ref$config$elements,
40
40
  subscribedFields = _ref$config.subscribedFields;
@@ -11,6 +11,10 @@
11
11
  margin-top: 16px;
12
12
  }
13
13
 
14
+ .igloo-section-collapse-divider {
15
+ margin-bottom: 0;
16
+ }
17
+
14
18
  &:last-child {
15
19
  .igloo-section-collapse-divider {
16
20
  display: none;
@@ -77,14 +77,23 @@ var Step = function Step(_ref) {
77
77
  md = _useBreakpoint.md;
78
78
 
79
79
  useEffect(function () {
80
- var _containerRef$current, _containerRef$current2, _containerRef$current3;
80
+ var _containerRef$current, _containerRef$current4;
81
81
 
82
82
  if (md || !(shouldScroll && edit)) return;
83
83
  var scrollContainer = getScrollContainer() || window;
84
- (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.offsetTop) ? scrollContainer.scrollTo({
85
- top: (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.offsetTop) - 50,
86
- behavior: 'smooth'
87
- }) : containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.scrollIntoView();
84
+ if (typeof scrollContainer.scrollTo !== 'function') return;
85
+
86
+ if (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.offsetTop) {
87
+ var _containerRef$current2, _containerRef$current3;
88
+
89
+ scrollContainer.scrollTo.length === 2 ? scrollContainer.scrollTo(0, (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.offsetTop) - 50) : scrollContainer.scrollTo({
90
+ top: (containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.offsetTop) - 50,
91
+ behavior: 'smooth'
92
+ });
93
+ return;
94
+ }
95
+
96
+ containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.scrollIntoView();
88
97
  }, [shouldScroll, edit]);
89
98
  var displayTotal = showLastIndex ? total : total - 1;
90
99
  return _jsxs("div", {
@@ -24,9 +24,9 @@ import './style/index.less';
24
24
  import invariant from 'invariant';
25
25
 
26
26
  var Steps = function Steps(_ref) {
27
- var name = _ref.name,
28
- parentName = _ref.parentName,
27
+ var parentName = _ref.parentName,
29
28
  _ref$config = _ref.config,
29
+ name = _ref$config.name,
30
30
  _ref$config$elements = _ref$config.elements,
31
31
  elements = _ref$config$elements === void 0 ? [] : _ref$config$elements,
32
32
  _ref$config$showLastI = _ref$config.showLastIndex,
package/es/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { default as Form } from './form';
2
2
  export { default as Button, GreenButton, YellowButton, RedButton, } from './button';
3
3
  export { default as DatePicker, IglooBuddhistDatePicker as BuddhistDatePicker, IglooRangePicker as RangePicker, IglooWeekPicker as WeekPicker, IglooMonthPicker as MonthPicker, } from './date-picker';
4
- export { default as Input, PhoneNumber, Amount, Password, Email, InputNumber, TextArea, InputDate, CreditCard, ExpiryDate, } from './input';
4
+ export { default as Input, PhoneNumber, Amount, Password, Email, InputNumber, TextArea, InputDate, CreditCard, ExpiryDate, InputId, } from './input';
5
5
  export { default as Select, TimeSelect, AttachedSelect } from './select';
6
6
  export { default as Radio, RadioGroup, RadioGroupWithOther } from './radio';
7
7
  export { default as Example } from './example';
package/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { default as Form } from './form';
2
2
  export { default as Button, GreenButton, YellowButton, RedButton } from './button';
3
3
  export { default as DatePicker, IglooBuddhistDatePicker as BuddhistDatePicker, IglooRangePicker as RangePicker, IglooWeekPicker as WeekPicker, IglooMonthPicker as MonthPicker } from './date-picker';
4
- export { default as Input, PhoneNumber, Amount, Password, Email, InputNumber, TextArea, InputDate, CreditCard, ExpiryDate } from './input';
4
+ export { default as Input, PhoneNumber, Amount, Password, Email, InputNumber, TextArea, InputDate, CreditCard, ExpiryDate, InputId } from './input';
5
5
  export { default as Select, TimeSelect, AttachedSelect } from './select';
6
6
  export { default as Radio, RadioGroup, RadioGroupWithOther } from './radio';
7
7
  export { default as Example } from './example';
@@ -8,5 +8,6 @@ export { default as InputDate } from './input-date';
8
8
  export { default as CreditCard } from './credit-card';
9
9
  export { default as Otp } from './otp';
10
10
  export { default as ExpiryDate } from './expiry-date';
11
+ export { default as InputId } from './input-id';
11
12
  import IglooInput from './input';
12
13
  export default IglooInput;
package/es/input/index.js CHANGED
@@ -8,5 +8,6 @@ export { default as InputDate } from './input-date';
8
8
  export { default as CreditCard } from './credit-card';
9
9
  export { default as Otp } from './otp';
10
10
  export { default as ExpiryDate } from './expiry-date';
11
+ export { default as InputId } from './input-id';
11
12
  import IglooInput from './input';
12
13
  export default IglooInput;
@@ -0,0 +1,6 @@
1
+ import { InputProps } from 'antd/es/input';
2
+ import { FC, IglooComponentProps } from '../types';
3
+ import './style/index.less';
4
+ declare type Props = InputProps & IglooComponentProps;
5
+ declare const InputId: FC<Props>;
6
+ export default InputId;
@@ -0,0 +1,112 @@
1
+ import "antd/es/input/style";
2
+ import _Input from "antd/es/input";
3
+
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import omit from 'omit.js';
12
+ import formMethods from '../utils/form-methods';
13
+ import { staticFormatMessage as formatMessage } from '../locale';
14
+ import './style/index.less';
15
+
16
+ var InputId = function InputId(props) {
17
+ return _jsx(_Input, _objectSpread(_objectSpread({
18
+ className: "igloo-input"
19
+ }, omit(props, formMethods)), {}, {
20
+ type: "number"
21
+ }));
22
+ };
23
+
24
+ InputId.formItemPropsHandler = function (config) {
25
+ var length = config.length,
26
+ maxLength = config.maxLength,
27
+ minLength = config.minLength,
28
+ label = config.label,
29
+ idType = config.idType;
30
+ var rules = [];
31
+
32
+ if (length !== undefined) {
33
+ rules.push({
34
+ validator: function validator(_, value) {
35
+ if (value === undefined || value === null || String(value).length === length) return Promise.resolve();
36
+ return Promise.reject(formatMessage({
37
+ id: '{label} must be {length} digits.',
38
+ values: {
39
+ length: length,
40
+ label: label
41
+ }
42
+ }));
43
+ }
44
+ });
45
+ }
46
+
47
+ if (maxLength !== undefined && minLength !== undefined) {
48
+ rules.push({
49
+ validator: function validator(_, value) {
50
+ if (value === undefined || value === null || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
51
+ return Promise.reject(formatMessage({
52
+ id: '{label} must be {minLength} - {maxLength} digits.',
53
+ values: {
54
+ maxLength: maxLength,
55
+ minLength: minLength,
56
+ label: label
57
+ }
58
+ }));
59
+ }
60
+ });
61
+ }
62
+
63
+ if (maxLength !== undefined && minLength === undefined) {
64
+ rules.push({
65
+ validator: function validator(_, value) {
66
+ if (value === undefined || value === null || String(value).length <= maxLength) return Promise.resolve();
67
+ return Promise.reject(formatMessage({
68
+ id: '{label} must be less than {maxLength} digits.',
69
+ values: {
70
+ maxLength: maxLength,
71
+ label: label
72
+ }
73
+ }));
74
+ }
75
+ });
76
+ }
77
+
78
+ if (maxLength === undefined && minLength !== undefined) {
79
+ rules.push({
80
+ validator: function validator(_, value) {
81
+ if (value === undefined || value === null || String(value).length >= minLength) return Promise.resolve();
82
+ return Promise.reject(formatMessage({
83
+ id: '{label} must be at least {minLength} digits.',
84
+ values: {
85
+ minLength: minLength,
86
+ label: label
87
+ }
88
+ }));
89
+ }
90
+ });
91
+ }
92
+
93
+ if (idType === 'KTP') {
94
+ rules.push({
95
+ validator: function validator(rule, value) {
96
+ if (!/^((1[1-9])|(21)|([37][1-6])|(5[1-4])|(6[1-5])|([8-9][1-2]))[0-9]{4}(([0-6][0-9])|(7[0-1]))((0[1-9])|(1[0-2]))[0-9]{6}$/.test(value)) {
97
+ return Promise.reject(formatMessage({
98
+ id: 'Invalid KTP Number.'
99
+ }));
100
+ }
101
+
102
+ return Promise.resolve();
103
+ }
104
+ });
105
+ }
106
+
107
+ return {
108
+ rules: rules
109
+ };
110
+ };
111
+
112
+ export default InputId;
@@ -10,6 +10,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import omit from 'omit.js';
12
12
  import formMethods from '../utils/form-methods';
13
+ import { staticFormatMessage } from '../locale';
13
14
  import './style/index.less';
14
15
 
15
16
  var IglooInputNumber = function IglooInputNumber(props) {
@@ -39,6 +40,74 @@ var IglooInputNumber = function IglooInputNumber(props) {
39
40
  };
40
41
 
41
42
  IglooInputNumber.formItemPropsHandler = function (config) {
43
+ var length = config.length,
44
+ maxLength = config.maxLength,
45
+ minLength = config.minLength,
46
+ label = config.label,
47
+ idType = config.idType;
48
+ var rules = [];
49
+
50
+ if (length !== undefined) {
51
+ rules.push({
52
+ validator: function validator(_, value) {
53
+ if (value === undefined || value === null || String(value).length === length) return Promise.resolve();
54
+ return Promise.reject(staticFormatMessage({
55
+ id: '{label} must be {length} digits.',
56
+ values: {
57
+ length: length,
58
+ label: label
59
+ }
60
+ }));
61
+ }
62
+ });
63
+ }
64
+
65
+ if (maxLength !== undefined && minLength !== undefined) {
66
+ rules.push({
67
+ validator: function validator(_, value) {
68
+ if (value === undefined || value === null || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
69
+ return Promise.reject(staticFormatMessage({
70
+ id: '{label} must be {minLength} - {maxLength} digits.',
71
+ values: {
72
+ maxLength: maxLength,
73
+ minLength: minLength,
74
+ label: label
75
+ }
76
+ }));
77
+ }
78
+ });
79
+ }
80
+
81
+ if (maxLength !== undefined && minLength === undefined) {
82
+ rules.push({
83
+ validator: function validator(_, value) {
84
+ if (value === undefined || value === null || String(value).length <= maxLength) return Promise.resolve();
85
+ return Promise.reject(staticFormatMessage({
86
+ id: '{label} must be less than {maxLength} digits.',
87
+ values: {
88
+ maxLength: maxLength,
89
+ label: label
90
+ }
91
+ }));
92
+ }
93
+ });
94
+ }
95
+
96
+ if (maxLength === undefined && minLength !== undefined) {
97
+ rules.push({
98
+ validator: function validator(_, value) {
99
+ if (value === undefined || value === null || String(value).length >= minLength) return Promise.resolve();
100
+ return Promise.reject(staticFormatMessage({
101
+ id: '{label} must be at least {minLength} digits.',
102
+ values: {
103
+ minLength: minLength,
104
+ label: label
105
+ }
106
+ }));
107
+ }
108
+ });
109
+ }
110
+
42
111
  return {
43
112
  getValueFromEvent: function getValueFromEvent(e) {
44
113
  var value = e.target.value;
@@ -49,7 +118,8 @@ IglooInputNumber.formItemPropsHandler = function (config) {
49
118
  }
50
119
 
51
120
  return str ? parseFloat(str) : undefined;
52
- }
121
+ },
122
+ rules: rules
53
123
  };
54
124
  };
55
125