antd-mobile 5.0.0-rc.4 → 5.0.0-rc.5

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 (97) hide show
  1. package/2x/README.md +2 -0
  2. package/2x/cjs/components/collapse/collapse.d.ts +2 -2
  3. package/2x/cjs/components/collapse/collapse.js +1 -1
  4. package/2x/cjs/components/dialog/dialog.js +7 -4
  5. package/2x/cjs/components/list/list.css +5 -4
  6. package/2x/cjs/components/list/list.js +1 -3
  7. package/2x/cjs/components/number-keyboard/number-keyboard.css +2 -2
  8. package/2x/cjs/components/passcode-input/index.d.ts +4 -0
  9. package/2x/cjs/components/passcode-input/index.js +13 -0
  10. package/2x/cjs/components/passcode-input/passcode-input.css +166 -0
  11. package/2x/cjs/components/passcode-input/passcode-input.d.ts +35 -0
  12. package/2x/cjs/components/passcode-input/passcode-input.js +169 -0
  13. package/2x/cjs/components/picker/picker.js +1 -0
  14. package/2x/cjs/components/picker-view/column.js +47 -3
  15. package/2x/cjs/components/picker-view/picker-view.css +45 -5
  16. package/2x/cjs/components/picker-view/picker-view.js +7 -3
  17. package/2x/cjs/components/toast/index.d.ts +2 -1
  18. package/2x/cjs/components/toast/index.js +2 -1
  19. package/2x/cjs/components/toast/methods.d.ts +1 -0
  20. package/2x/cjs/components/toast/methods.js +18 -1
  21. package/2x/cjs/index.d.ts +1 -0
  22. package/2x/cjs/index.js +8 -0
  23. package/2x/cjs/utils/memo-with-event-marks.d.ts +2 -0
  24. package/2x/cjs/utils/memo-with-event-marks.js +23 -0
  25. package/2x/es/components/collapse/collapse.d.ts +2 -2
  26. package/2x/es/components/collapse/collapse.js +1 -1
  27. package/2x/es/components/dialog/dialog.js +6 -4
  28. package/2x/es/components/list/list.css +5 -4
  29. package/2x/es/components/list/list.js +1 -3
  30. package/2x/es/components/number-keyboard/number-keyboard.css +2 -2
  31. package/2x/es/components/passcode-input/index.d.ts +4 -0
  32. package/2x/es/components/passcode-input/index.js +3 -0
  33. package/2x/es/components/passcode-input/passcode-input.css +166 -0
  34. package/2x/es/components/passcode-input/passcode-input.d.ts +35 -0
  35. package/2x/es/components/passcode-input/passcode-input.js +149 -0
  36. package/2x/es/components/picker/picker.js +1 -0
  37. package/2x/es/components/picker-view/column.js +47 -3
  38. package/2x/es/components/picker-view/picker-view.css +45 -5
  39. package/2x/es/components/picker-view/picker-view.js +7 -3
  40. package/2x/es/components/toast/index.d.ts +2 -1
  41. package/2x/es/components/toast/index.js +3 -2
  42. package/2x/es/components/toast/methods.d.ts +1 -0
  43. package/2x/es/components/toast/methods.js +16 -1
  44. package/2x/es/index.d.ts +1 -0
  45. package/2x/es/index.js +2 -1
  46. package/2x/es/utils/memo-with-event-marks.d.ts +2 -0
  47. package/2x/es/utils/memo-with-event-marks.js +15 -0
  48. package/2x/package.json +1 -1
  49. package/README.md +2 -0
  50. package/cjs/components/collapse/collapse.d.ts +2 -2
  51. package/cjs/components/collapse/collapse.js +1 -1
  52. package/cjs/components/dialog/dialog.js +7 -4
  53. package/cjs/components/list/list.css +4 -3
  54. package/cjs/components/list/list.js +1 -3
  55. package/cjs/components/number-keyboard/number-keyboard.css +2 -2
  56. package/cjs/components/passcode-input/index.d.ts +4 -0
  57. package/cjs/components/passcode-input/index.js +13 -0
  58. package/cjs/components/passcode-input/passcode-input.css +136 -0
  59. package/cjs/components/passcode-input/passcode-input.d.ts +35 -0
  60. package/cjs/components/passcode-input/passcode-input.js +169 -0
  61. package/cjs/components/picker/picker.js +1 -0
  62. package/cjs/components/picker-view/column.js +47 -3
  63. package/cjs/components/picker-view/picker-view.css +39 -5
  64. package/cjs/components/picker-view/picker-view.js +7 -3
  65. package/cjs/components/toast/index.d.ts +2 -1
  66. package/cjs/components/toast/index.js +2 -1
  67. package/cjs/components/toast/methods.d.ts +1 -0
  68. package/cjs/components/toast/methods.js +18 -1
  69. package/cjs/index.d.ts +1 -0
  70. package/cjs/index.js +8 -0
  71. package/cjs/utils/memo-with-event-marks.d.ts +2 -0
  72. package/cjs/utils/memo-with-event-marks.js +23 -0
  73. package/es/components/collapse/collapse.d.ts +2 -2
  74. package/es/components/collapse/collapse.js +1 -1
  75. package/es/components/dialog/dialog.js +6 -4
  76. package/es/components/list/list.css +4 -3
  77. package/es/components/list/list.js +1 -3
  78. package/es/components/number-keyboard/number-keyboard.css +2 -2
  79. package/es/components/passcode-input/index.d.ts +4 -0
  80. package/es/components/passcode-input/index.js +3 -0
  81. package/es/components/passcode-input/passcode-input.css +136 -0
  82. package/es/components/passcode-input/passcode-input.d.ts +35 -0
  83. package/es/components/passcode-input/passcode-input.js +149 -0
  84. package/es/components/picker/picker.js +1 -0
  85. package/es/components/picker-view/column.js +47 -3
  86. package/es/components/picker-view/picker-view.css +39 -5
  87. package/es/components/picker-view/picker-view.js +7 -3
  88. package/es/components/toast/index.d.ts +2 -1
  89. package/es/components/toast/index.js +3 -2
  90. package/es/components/toast/methods.d.ts +1 -0
  91. package/es/components/toast/methods.js +16 -1
  92. package/es/index.d.ts +1 -0
  93. package/es/index.js +2 -1
  94. package/es/utils/memo-with-event-marks.d.ts +2 -0
  95. package/es/utils/memo-with-event-marks.js +15 -0
  96. package/package.json +1 -1
  97. package/umd/antd-mobile.js +1 -1
@@ -77,9 +77,13 @@ var PickerView = /*#__PURE__*/(0, _react.memo)(function (p) {
77
77
  }
78
78
  });
79
79
  }), /*#__PURE__*/_react["default"].createElement("div", {
80
- className: classPrefix + "-mask " + classPrefix + "-mask-top"
80
+ className: classPrefix + "-mask"
81
+ }, /*#__PURE__*/_react["default"].createElement("div", {
82
+ className: classPrefix + "-mask-top"
81
83
  }), /*#__PURE__*/_react["default"].createElement("div", {
82
- className: classPrefix + "-mask " + classPrefix + "-mask-bottom"
83
- })));
84
+ className: classPrefix + "-mask-middle"
85
+ }), /*#__PURE__*/_react["default"].createElement("div", {
86
+ className: classPrefix + "-mask-bottom"
87
+ }))));
84
88
  });
85
89
  exports.PickerView = PickerView;
@@ -1,8 +1,9 @@
1
1
  import './toast.less';
2
- import { clear, show } from './methods';
2
+ import { clear, show, config } from './methods';
3
3
  export type { ToastShowProps } from './methods';
4
4
  declare const Toast: {
5
5
  show: typeof show;
6
6
  clear: typeof clear;
7
+ config: typeof config;
7
8
  };
8
9
  export default Toast;
@@ -11,7 +11,8 @@ var _methods = require("./methods");
11
11
 
12
12
  var Toast = {
13
13
  show: _methods.show,
14
- clear: _methods.clear
14
+ clear: _methods.clear,
15
+ config: _methods.config
15
16
  };
16
17
  var _default = Toast;
17
18
  exports["default"] = _default;
@@ -2,3 +2,4 @@ import { ToastProps } from './toast';
2
2
  export declare type ToastShowProps = Omit<ToastProps, 'visible'>;
3
3
  export declare function show(p: ToastShowProps | string): void;
4
4
  export declare function clear(): void;
5
+ export declare function config(val: Pick<ToastProps, 'duration' | 'position' | 'maskClickable'>): void;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.clear = clear;
7
+ exports.config = config;
7
8
  exports.show = show;
8
9
 
9
10
  var _react = _interopRequireWildcard(require("react"));
@@ -33,7 +34,9 @@ function unmount(container) {
33
34
  }
34
35
 
35
36
  var defaultProps = {
36
- duration: 2000
37
+ duration: 2000,
38
+ position: 'center',
39
+ maskClickable: true
37
40
  };
38
41
 
39
42
  function show(p) {
@@ -95,4 +98,18 @@ function clear() {
95
98
  if (!container) break;
96
99
  unmount(container);
97
100
  }
101
+ }
102
+
103
+ function config(val) {
104
+ if (val.duration !== undefined) {
105
+ defaultProps.duration = val.duration;
106
+ }
107
+
108
+ if (val.position !== undefined) {
109
+ defaultProps.position = val.position;
110
+ }
111
+
112
+ if (val.maskClickable !== undefined) {
113
+ defaultProps.maskClickable = val.maskClickable;
114
+ }
98
115
  }
package/2x/cjs/index.d.ts CHANGED
@@ -72,3 +72,4 @@ export { default as Toast } from './components/toast';
72
72
  export { default as TreeSelect } from './components/tree-select';
73
73
  export { default as VirtualInput } from './components/virtual-input';
74
74
  export { default as WaterMark } from './components/water-mark';
75
+ export { default as PasscodeInput } from './components/passcode-input';
package/2x/cjs/index.js CHANGED
@@ -249,6 +249,12 @@ Object.defineProperty(exports, "PageIndicator", {
249
249
  return _pageIndicator["default"];
250
250
  }
251
251
  });
252
+ Object.defineProperty(exports, "PasscodeInput", {
253
+ enumerable: true,
254
+ get: function get() {
255
+ return _passcodeInput["default"];
256
+ }
257
+ });
252
258
  Object.defineProperty(exports, "Picker", {
253
259
  enumerable: true,
254
260
  get: function get() {
@@ -586,6 +592,8 @@ var _virtualInput = _interopRequireDefault(require("./components/virtual-input")
586
592
 
587
593
  var _waterMark = _interopRequireDefault(require("./components/water-mark"));
588
594
 
595
+ var _passcodeInput = _interopRequireDefault(require("./components/passcode-input"));
596
+
589
597
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
590
598
 
591
599
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -0,0 +1,2 @@
1
+ import { FunctionComponent } from 'react';
2
+ export declare function memoWithEventMarks<P extends object>(Component: FunctionComponent<P>, eventProps: (keyof P)[]): import("react").NamedExoticComponent<P>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.memoWithEventMarks = memoWithEventMarks;
7
+
8
+ var _react = require("react");
9
+
10
+ function memoWithEventMarks(Component, eventProps) {
11
+ return /*#__PURE__*/(0, _react.memo)(Component, function (prevProps, nextProps) {
12
+ for (var k in nextProps) {
13
+ var key = k;
14
+ if (eventProps.includes(key)) continue;
15
+
16
+ if (prevProps[key] !== nextProps[key]) {
17
+ return false;
18
+ }
19
+ }
20
+
21
+ return true;
22
+ });
23
+ }
@@ -7,14 +7,14 @@ export declare type CollapsePanelProps = {
7
7
  forceRender?: boolean;
8
8
  destroyOnClose?: boolean;
9
9
  onClick?: (event: React.MouseEvent<Element, MouseEvent>) => void;
10
- arrow?: React.ReactNode;
10
+ arrow?: React.ReactNode | ((active: boolean) => React.ReactNode);
11
11
  } & NativeProps;
12
12
  export declare const CollapsePanel: FC<CollapsePanelProps>;
13
13
  declare type ValueProps<T> = {
14
14
  activeKey?: T;
15
15
  defaultActiveKey?: T;
16
16
  onChange?: (activeKey: T) => void;
17
- arrow?: React.ReactNode;
17
+ arrow?: React.ReactNode | ((active: boolean) => React.ReactNode);
18
18
  };
19
19
  export declare type CollapseProps = (({
20
20
  accordion?: false;
@@ -142,7 +142,7 @@ export var Collapse = function Collapse(props) {
142
142
  arrow = panel.props.arrow;
143
143
  }
144
144
 
145
- return /*#__PURE__*/React.createElement("div", {
145
+ return typeof arrow === 'function' ? arrow(active) : /*#__PURE__*/React.createElement("div", {
146
146
  className: classNames(classPrefix + "-arrow", (_classNames = {}, _classNames[classPrefix + "-arrow-active"] = active, _classNames))
147
147
  }, arrow);
148
148
  };
@@ -38,6 +38,7 @@ import Mask from '../mask';
38
38
  import { DialogActionButton } from './dialog-action-button';
39
39
  import Image from '../image';
40
40
  import Space from '../space';
41
+ import { renderToContainer } from '../../utils/render-to-container';
41
42
  import { withStopPropagation } from '../../utils/with-stop-propagation';
42
43
  import AutoCenter from '../auto-center';
43
44
  import { useSpring, animated } from '@react-spring/web';
@@ -48,7 +49,8 @@ var defaultProps = {
48
49
  actions: [],
49
50
  closeOnAction: false,
50
51
  closeOnMaskClick: false,
51
- stopPropagation: ['click']
52
+ stopPropagation: ['click'],
53
+ getContainer: null
52
54
  };
53
55
  export var Dialog = function Dialog(p) {
54
56
  var props = mergeProps(defaultProps, p);
@@ -81,14 +83,13 @@ export var Dialog = function Dialog(p) {
81
83
  active = _useState[0],
82
84
  setActive = _useState[1];
83
85
 
84
- return withStopPropagation(props.stopPropagation, withNativeProps(props, /*#__PURE__*/React.createElement("div", {
86
+ var node = withNativeProps(props, /*#__PURE__*/React.createElement("div", {
85
87
  className: classPrefix,
86
88
  style: {
87
89
  display: active ? 'unset' : 'none'
88
90
  }
89
91
  }, /*#__PURE__*/React.createElement(Mask, {
90
92
  visible: props.visible,
91
- getContainer: props.getContainer,
92
93
  onMaskClick: props.closeOnMaskClick ? props.onClose : undefined,
93
94
  style: props.maskStyle,
94
95
  className: classNames(classPrefix + "-mask", props.maskClassName)
@@ -158,5 +159,6 @@ export var Dialog = function Dialog(p) {
158
159
  }
159
160
  });
160
161
  }));
161
- })))))));
162
+ }))))));
163
+ return renderToContainer(props.getContainer, withStopPropagation(props.stopPropagation, node));
162
164
  };
@@ -11,10 +11,6 @@
11
11
  font-size: 34px;
12
12
  }
13
13
 
14
- .adm-list-inner {
15
- margin-bottom: -2px;
16
- }
17
-
18
14
  .adm-list-default {
19
15
  border-top: var(--border-top);
20
16
  border-bottom: var(--border-bottom);
@@ -26,10 +22,15 @@
26
22
  }
27
23
 
28
24
  .adm-list-item {
25
+ margin-bottom: -2px;
29
26
  display: block;
30
27
  padding-left: var(--padding-left);
31
28
  }
32
29
 
30
+ .adm-list-item:not(:first-child) {
31
+ padding-top: 2px;
32
+ }
33
+
33
34
  .adm-list-item-title,
34
35
  .adm-list-item-description {
35
36
  color: var(--adm-color-weak);
@@ -10,7 +10,5 @@ export var List = function List(p) {
10
10
  var props = mergeProps(defaultProps, p);
11
11
  return withNativeProps(props, /*#__PURE__*/React.createElement("div", {
12
12
  className: classNames(classPrefix, classPrefix + "-" + props.mode)
13
- }, /*#__PURE__*/React.createElement("div", {
14
- className: classPrefix + "-inner"
15
- }, props.children)));
13
+ }, props.children));
16
14
  };
@@ -4,8 +4,7 @@
4
4
  flex: 1;
5
5
  }
6
6
 
7
- .adm-number-keyboard.confirmed-style {
8
- width: 75%;
7
+ .adm-number-keyboard-main.confirmed-style .sign-key {
9
8
  background-color: var(--adm-color-white);
10
9
  }
11
10
 
@@ -125,6 +124,7 @@
125
124
  color: var(--adm-color-white);
126
125
  height: 288px;
127
126
  font-size: 32px;
127
+ border: none;
128
128
  }
129
129
 
130
130
  .adm-number-keyboard-bs-key {
@@ -0,0 +1,4 @@
1
+ import './passcode-input.less';
2
+ import { PasscodeInput } from './passcode-input';
3
+ export type { PasscodeInputProps } from './passcode-input';
4
+ export default PasscodeInput;
@@ -0,0 +1,3 @@
1
+ import "./passcode-input.css";
2
+ import { PasscodeInput } from './passcode-input';
3
+ export default PasscodeInput;
@@ -0,0 +1,166 @@
1
+ .adm-passcode-input {
2
+ position: relative;
3
+ display: inline-block;
4
+ --cell-size: 80px;
5
+ --cell-gap: 12px;
6
+ --dot-size: 20px;
7
+ --border-color: #e5e5e5;
8
+ --border-radius: 16px;
9
+ }
10
+
11
+ .adm-passcode-input-cell-container {
12
+ display: inline-flex;
13
+ vertical-align: top;
14
+ }
15
+
16
+ .adm-passcode-input-cell {
17
+ flex: none;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ box-sizing: border-box;
22
+ font-size: 36px;
23
+ width: var(--cell-size);
24
+ height: var(--cell-size);
25
+ background: var(--adm-color-white);
26
+ }
27
+
28
+ .adm-passcode-input:not(.seperated) {
29
+ border-radius: var(--border-radius);
30
+ overflow: hidden;
31
+ border: 2px solid var(--border-color);
32
+ }
33
+
34
+ .adm-passcode-input:not(.seperated) .adm-passcode-input-cell:not(:last-child) {
35
+ border-right: 2px solid var(--border-color);
36
+ }
37
+
38
+ .adm-passcode-input:not(.seperated).focused {
39
+ border-color: var(--adm-color-primary);
40
+ box-shadow: 0 0 4px 0 var(--adm-color-primary);
41
+ outline: none;
42
+ }
43
+
44
+ .adm-passcode-input:not(.seperated).error {
45
+ border-color: var(--adm-color-danger);
46
+ box-shadow: 0 0 4px 0 var(--adm-color-danger);
47
+ animation: 100ms ease-in-out 0s 3 normal none running adm-shake-horizontal;
48
+ }
49
+
50
+ .adm-passcode-input.seperated .adm-passcode-input-cell {
51
+ border-radius: var(--border-radius);
52
+ border: 2px solid var(--border-color);
53
+ }
54
+
55
+ .adm-passcode-input.seperated .adm-passcode-input-cell:not(:last-child) {
56
+ margin-right: var(--cell-gap);
57
+ }
58
+
59
+ .adm-passcode-input.seperated .adm-passcode-input-cell.focused {
60
+ border-color: var(--adm-color-primary);
61
+ box-shadow: 0 0 4px 0 var(--adm-color-primary);
62
+ }
63
+
64
+ .adm-passcode-input.seperated.focused {
65
+ outline: none;
66
+ }
67
+
68
+ .adm-passcode-input.seperated.error {
69
+ animation: 100ms ease-in-out 0s 3 normal none running adm-shake-horizontal;
70
+ }
71
+
72
+ .adm-passcode-input.seperated.error .adm-passcode-input-cell {
73
+ border-color: var(--adm-color-danger);
74
+ box-shadow: 0 0 4px 0 var(--adm-color-danger);
75
+ }
76
+
77
+ .adm-passcode-input-cell.dot::before {
78
+ content: '';
79
+ width: var(--dot-size);
80
+ height: var(--dot-size);
81
+ border-radius: 50%;
82
+ background: var(--adm-color-text);
83
+ }
84
+
85
+ .adm-passcode-input-cell.caret::after {
86
+ content: '';
87
+ width: 4px;
88
+ height: 1.1em;
89
+ margin-left: 2px;
90
+ background: var(--adm-color-primary);
91
+ animation: 1s linear infinite adm-caret-blink;
92
+ }
93
+
94
+ .adm-passcode-input > .adm-passcode-input-native-input {
95
+ position: absolute;
96
+ left: -200vw;
97
+ top: 0;
98
+ display: block;
99
+ width: 100px;
100
+ height: 40px;
101
+ opacity: 0.5;
102
+ }
103
+
104
+ @keyframes adm-shake-horizontal {
105
+ 0% {
106
+ transform: translateX(0);
107
+ }
108
+
109
+ 10% {
110
+ transform: translateX(-8px);
111
+ }
112
+
113
+ 20% {
114
+ transform: translateX(10px);
115
+ }
116
+
117
+ 30% {
118
+ transform: translateX(-2px);
119
+ }
120
+
121
+ 40% {
122
+ transform: translateX(16px);
123
+ }
124
+
125
+ 50% {
126
+ transform: translateX(0);
127
+ }
128
+
129
+ 60% {
130
+ transform: translateX(-16px);
131
+ }
132
+
133
+ 70% {
134
+ transform: translateX(2px);
135
+ }
136
+
137
+ 80% {
138
+ transform: translateX(-10px);
139
+ }
140
+
141
+ 90% {
142
+ transform: translateX(8px);
143
+ }
144
+
145
+ 100% {
146
+ transform: translateX(0);
147
+ }
148
+ }
149
+
150
+ @keyframes adm-caret-blink {
151
+ from {
152
+ opacity: 1;
153
+ }
154
+
155
+ 60% {
156
+ opacity: 1;
157
+ }
158
+
159
+ 80% {
160
+ opacity: 0;
161
+ }
162
+
163
+ to {
164
+ opacity: 0;
165
+ }
166
+ }
@@ -0,0 +1,35 @@
1
+ import React, { ReactElement } from 'react';
2
+ import { NativeProps } from '../../utils/native-props';
3
+ import type { NumberKeyboardProps } from '../number-keyboard';
4
+ export declare type PasscodeInputProps = {
5
+ value?: string;
6
+ defaultValue?: string;
7
+ onChange?: (val: string) => void;
8
+ length?: number;
9
+ plain?: boolean;
10
+ error?: boolean;
11
+ caret?: boolean;
12
+ seperated?: boolean;
13
+ onBlur?: () => void;
14
+ onFocus?: () => void;
15
+ keyboard?: ReactElement<NumberKeyboardProps>;
16
+ onFill?: (val: string) => void;
17
+ } & NativeProps<'--cell-gap' | '--cell-size'>;
18
+ export declare type PasscodeInputRef = {
19
+ focus: () => void;
20
+ blur: () => void;
21
+ };
22
+ export declare const PasscodeInput: React.ForwardRefExoticComponent<{
23
+ value?: string | undefined;
24
+ defaultValue?: string | undefined;
25
+ onChange?: ((val: string) => void) | undefined;
26
+ length?: number | undefined;
27
+ plain?: boolean | undefined;
28
+ error?: boolean | undefined;
29
+ caret?: boolean | undefined;
30
+ seperated?: boolean | undefined;
31
+ onBlur?: (() => void) | undefined;
32
+ onFocus?: (() => void) | undefined;
33
+ keyboard?: React.ReactElement<NumberKeyboardProps, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)> | undefined;
34
+ onFill?: ((val: string) => void) | undefined;
35
+ } & NativeProps<"--cell-size" | "--cell-gap"> & React.RefAttributes<PasscodeInputRef>>;
@@ -0,0 +1,149 @@
1
+ import React, { useState, useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
2
+ import { mergeProps } from '../../utils/with-default-props';
3
+ import { withNativeProps } from '../../utils/native-props';
4
+ import classNames from 'classnames';
5
+ import { bound } from '../../utils/bound';
6
+ import { usePropsValue } from '../../utils/use-props-value';
7
+ var classPrefix = 'adm-passcode-input';
8
+ var defaultProps = {
9
+ defaultValue: '',
10
+ length: 6,
11
+ plain: false,
12
+ error: false,
13
+ seperated: false,
14
+ caret: true
15
+ };
16
+ export var PasscodeInput = /*#__PURE__*/forwardRef(function (p, ref) {
17
+ var props = mergeProps(defaultProps, p); // 防止 length 值不合法
18
+
19
+ var cellLength = props.length > 0 && props.length < Infinity ? Math.floor(props.length) : defaultProps.length;
20
+
21
+ var _useState = useState(false),
22
+ focused = _useState[0],
23
+ setFocused = _useState[1];
24
+
25
+ var _usePropsValue = usePropsValue(props),
26
+ value = _usePropsValue[0],
27
+ setValue = _usePropsValue[1];
28
+
29
+ var rootRef = useRef(null);
30
+ var nativeInputRef = useRef(null);
31
+ useEffect(function () {
32
+ var _a;
33
+
34
+ if (value.length >= cellLength) {
35
+ (_a = props.onFill) === null || _a === void 0 ? void 0 : _a.call(props, value);
36
+ }
37
+ }, [props.onFill, value, cellLength]);
38
+
39
+ var onFocus = function onFocus() {
40
+ var _a, _b;
41
+
42
+ if (!props.keyboard) {
43
+ (_a = nativeInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
44
+ }
45
+
46
+ setFocused(true);
47
+ (_b = props.onFocus) === null || _b === void 0 ? void 0 : _b.call(props);
48
+ };
49
+
50
+ useEffect(function () {
51
+ if (!focused) return;
52
+ var timeout = window.setTimeout(function () {
53
+ var _a;
54
+
55
+ (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
56
+ block: 'center',
57
+ inline: 'center',
58
+ behavior: 'smooth'
59
+ });
60
+ }, 100);
61
+ return function () {
62
+ window.clearTimeout(timeout);
63
+ };
64
+ }, [focused]);
65
+
66
+ var onBlur = function onBlur() {
67
+ var _a;
68
+
69
+ setFocused(false);
70
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props);
71
+ };
72
+
73
+ useImperativeHandle(ref, function () {
74
+ return {
75
+ focus: function focus() {
76
+ var _a;
77
+
78
+ return (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.focus();
79
+ },
80
+ blur: function blur() {
81
+ var _a, _b;
82
+
83
+ (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.blur();
84
+ (_b = nativeInputRef.current) === null || _b === void 0 ? void 0 : _b.blur();
85
+ }
86
+ };
87
+ });
88
+
89
+ var renderCells = function renderCells() {
90
+ var cells = [];
91
+ var chars = value.split('');
92
+ var caretIndex = chars.length; // 光标位置index等于当前文字长度
93
+
94
+ var focusedIndex = bound(chars.length, 0, cellLength - 1);
95
+
96
+ for (var i = 0; i < cellLength; i++) {
97
+ cells.push( /*#__PURE__*/React.createElement("div", {
98
+ className: classNames(classPrefix + "-cell", {
99
+ caret: props.caret && caretIndex === i && focused,
100
+ focused: focusedIndex === i && focused,
101
+ dot: !props.plain && chars[i]
102
+ }),
103
+ key: i
104
+ }, chars[i] && props.plain ? chars[i] : ''));
105
+ }
106
+
107
+ return cells;
108
+ };
109
+
110
+ var cls = classNames(classPrefix, {
111
+ focused: focused,
112
+ error: props.error,
113
+ seperated: props.seperated
114
+ });
115
+ return /*#__PURE__*/React.createElement(React.Fragment, null, withNativeProps(props, /*#__PURE__*/React.createElement("div", {
116
+ ref: rootRef,
117
+ tabIndex: 0,
118
+ className: cls,
119
+ onFocus: onFocus,
120
+ onBlur: onBlur
121
+ }, /*#__PURE__*/React.createElement("div", {
122
+ className: classPrefix + "-cell-container"
123
+ }, renderCells()), /*#__PURE__*/React.createElement("input", {
124
+ ref: nativeInputRef,
125
+ className: classPrefix + "-native-input",
126
+ value: value,
127
+ type: 'text',
128
+ pattern: '[0-9]*',
129
+ inputMode: 'numeric',
130
+ onChange: function onChange(e) {
131
+ setValue(e.target.value.slice(0, props.length));
132
+ }
133
+ }))), props.keyboard && /*#__PURE__*/React.cloneElement(props.keyboard, {
134
+ visible: focused,
135
+ onInput: function onInput(v) {
136
+ if (value.length < cellLength) {
137
+ setValue((value + v).slice(0, props.length));
138
+ }
139
+ },
140
+ onDelete: function onDelete() {
141
+ setValue(value.slice(0, -1));
142
+ },
143
+ onClose: function onClose() {
144
+ var _a;
145
+
146
+ (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.blur();
147
+ }
148
+ }));
149
+ });
@@ -103,6 +103,7 @@ export var Picker = /*#__PURE__*/memo(function (p) {
103
103
  afterShow: props.afterShow,
104
104
  afterClose: props.afterClose,
105
105
  onClick: props.onClick,
106
+ forceRender: true,
106
107
  stopPropagation: props.stopPropagation
107
108
  }, pickerElement);
108
109
  return /*#__PURE__*/React.createElement(React.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props, generateValueExtend(value).items));