@autobest-ui/components 2.9.2 → 2.10.0-alpha.0

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 (107) hide show
  1. package/esm/affix/index.d.ts +3 -3
  2. package/esm/affix/index.js +2 -2
  3. package/esm/carousel/index.d.ts +2 -2
  4. package/esm/carousel/index.js +1 -1
  5. package/esm/checkbox/Checkbox.d.ts +60 -0
  6. package/esm/checkbox/Checkbox.js +120 -0
  7. package/esm/checkbox/CheckboxGroup.d.ts +16 -0
  8. package/esm/checkbox/CheckboxGroup.js +57 -0
  9. package/esm/checkbox/index.d.ts +4 -52
  10. package/esm/checkbox/index.js +2 -114
  11. package/esm/checkbox/style/index.css +1 -1
  12. package/esm/ellipsis/index.d.ts +1 -8
  13. package/esm/ellipsis/index.js +9 -9
  14. package/esm/ellipsis/style/index.css +1 -1
  15. package/esm/index.d.ts +6 -3
  16. package/esm/index.js +4 -2
  17. package/esm/input/Input.d.ts +13 -1
  18. package/esm/input/Input.js +64 -4
  19. package/esm/input/TextArea.d.ts +8 -0
  20. package/esm/input/TextArea.js +43 -12
  21. package/esm/input-number/getParserOriginalValue.d.ts +26 -0
  22. package/esm/input-number/getParserOriginalValue.js +73 -0
  23. package/esm/input-number/index.d.ts +20 -7
  24. package/esm/input-number/index.js +60 -48
  25. package/esm/modal/index.d.ts +3 -3
  26. package/esm/modal/index.js +2 -2
  27. package/esm/move/index.d.ts +6 -6
  28. package/esm/move/index.js +5 -5
  29. package/esm/popover/index.d.ts +1 -1
  30. package/esm/popover/index.js +7 -2
  31. package/esm/radio/Radio.d.ts +4 -0
  32. package/esm/radio/Radio.js +80 -0
  33. package/esm/radio/RadioGroup.d.ts +16 -0
  34. package/esm/radio/RadioGroup.js +106 -0
  35. package/esm/radio/context.d.ts +5 -0
  36. package/esm/radio/context.js +4 -0
  37. package/esm/radio/index.d.ts +3 -0
  38. package/esm/radio/index.js +2 -0
  39. package/esm/radio/interface.d.ts +17 -0
  40. package/esm/radio/interface.js +1 -0
  41. package/esm/radio/style/index.css +1 -0
  42. package/esm/select/index.d.ts +2 -2
  43. package/esm/select/index.js +1 -1
  44. package/esm/style.css +1 -1
  45. package/esm/table/body/CheckIcon.js +1 -1
  46. package/esm/table/header/CheckIcon.js +1 -1
  47. package/esm/table/index.d.ts +2 -2
  48. package/esm/table/index.js +2 -1
  49. package/esm/table/style/index.css +1 -1
  50. package/esm/tabs/index.d.ts +2 -2
  51. package/esm/tabs/index.js +1 -1
  52. package/esm/trigger/index.d.ts +5 -5
  53. package/esm/trigger/index.js +5 -5
  54. package/lib/affix/index.d.ts +3 -3
  55. package/lib/affix/index.js +2 -2
  56. package/lib/carousel/index.d.ts +2 -2
  57. package/lib/carousel/index.js +1 -1
  58. package/lib/checkbox/Checkbox.d.ts +60 -0
  59. package/lib/checkbox/Checkbox.js +128 -0
  60. package/lib/checkbox/CheckboxGroup.d.ts +16 -0
  61. package/lib/checkbox/CheckboxGroup.js +65 -0
  62. package/lib/checkbox/index.d.ts +4 -52
  63. package/lib/checkbox/index.js +13 -115
  64. package/lib/checkbox/style/index.css +1 -1
  65. package/lib/ellipsis/index.d.ts +1 -8
  66. package/lib/ellipsis/index.js +9 -9
  67. package/lib/ellipsis/style/index.css +1 -1
  68. package/lib/index.d.ts +6 -3
  69. package/lib/index.js +40 -2
  70. package/lib/input/Input.d.ts +13 -1
  71. package/lib/input/Input.js +64 -4
  72. package/lib/input/TextArea.d.ts +8 -0
  73. package/lib/input/TextArea.js +43 -12
  74. package/lib/input-number/getParserOriginalValue.d.ts +26 -0
  75. package/lib/input-number/getParserOriginalValue.js +79 -0
  76. package/lib/input-number/index.d.ts +20 -7
  77. package/lib/input-number/index.js +59 -47
  78. package/lib/modal/index.d.ts +3 -3
  79. package/lib/modal/index.js +2 -2
  80. package/lib/move/index.d.ts +6 -6
  81. package/lib/move/index.js +5 -5
  82. package/lib/popover/index.d.ts +1 -1
  83. package/lib/popover/index.js +7 -2
  84. package/lib/radio/Radio.d.ts +4 -0
  85. package/lib/radio/Radio.js +91 -0
  86. package/lib/radio/RadioGroup.d.ts +16 -0
  87. package/lib/radio/RadioGroup.js +117 -0
  88. package/lib/radio/context.d.ts +5 -0
  89. package/lib/radio/context.js +15 -0
  90. package/lib/radio/index.d.ts +3 -0
  91. package/lib/radio/index.js +20 -0
  92. package/lib/radio/interface.d.ts +17 -0
  93. package/lib/radio/interface.js +5 -0
  94. package/lib/radio/style/index.css +1 -0
  95. package/lib/select/index.d.ts +2 -2
  96. package/lib/select/index.js +1 -1
  97. package/lib/style.css +1 -1
  98. package/lib/table/body/CheckIcon.js +2 -2
  99. package/lib/table/header/CheckIcon.js +2 -2
  100. package/lib/table/index.d.ts +2 -2
  101. package/lib/table/index.js +2 -1
  102. package/lib/table/style/index.css +1 -1
  103. package/lib/tabs/index.d.ts +2 -2
  104. package/lib/tabs/index.js +1 -1
  105. package/lib/trigger/index.d.ts +5 -5
  106. package/lib/trigger/index.js +5 -5
  107. package/package.json +5 -4
@@ -7,10 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.InputNumberNotRef = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
+ var _components = require("@autobest-ui/components");
10
11
  var _utils = require("@autobest-ui/utils");
11
12
  var _Input = _interopRequireDefault(require("../input/Input"));
12
13
  var _constants = require("./constants");
13
14
  var _ControlArrow = _interopRequireDefault(require("./ControlArrow"));
15
+ var _getParserOriginalValue = _interopRequireDefault(require("./getParserOriginalValue"));
14
16
  var __extends = void 0 && (void 0).__extends || function () {
15
17
  var _extendStatics = function extendStatics(d, b) {
16
18
  _extendStatics = Object.setPrototypeOf || {
@@ -56,25 +58,10 @@ var InputNumberNotRef = /** @class */function (_super) {
56
58
  * @param originalValue
57
59
  */
58
60
  _this.getParserOriginalValue = function (originalValue) {
59
- // 输入为空
60
- if ((0, _utils.isBlank)(originalValue)) {
61
- return undefined;
62
- }
63
- if (!_constants.NumberReg.test(originalValue) || _constants.FirstZeroReg.test(originalValue)) {
64
- return (0, _utils.isBlank)(_this.state.parserValue) ? undefined : _this.state.parserValue.toString();
65
- }
66
- var _a = _this.props,
67
- min = _a.min,
68
- max = _a.max,
69
- precision = _a.precision;
70
- var currentValue = parseFloat(originalValue);
71
- if (!(0, _utils.isBlank)(min) && currentValue < min) {
72
- currentValue = min;
73
- }
74
- if (!(0, _utils.isBlank)(max) && currentValue > max) {
75
- currentValue = max;
76
- }
77
- return (0, _utils.toFixed)(currentValue, precision);
61
+ return (0, _getParserOriginalValue.default)(__assign(__assign({}, _this.props), {
62
+ originalValue: originalValue,
63
+ prevParserValue: _this.state.parserValue
64
+ }));
78
65
  };
79
66
  /**
80
67
  * 键盘和点击上下按钮更新value值
@@ -82,14 +69,20 @@ var InputNumberNotRef = /** @class */function (_super) {
82
69
  */
83
70
  _this.changeValueWithStep = function (isUp) {
84
71
  var step = _this.props.step;
85
- var prevValue = _this.state.parserValue ? _this.state.parserValue : 0;
72
+ var prevParserValue = _this.state.parserValue;
73
+ var prevValue = prevParserValue ? typeof prevParserValue === 'number' ? prevParserValue : parseFloat(prevParserValue) : 0;
86
74
  var keyboardValue = isUp ? prevValue + step : prevValue - step;
87
- var parserValueStr = _this.getParserOriginalValue(keyboardValue.toString());
88
- var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
89
- var _a = _this.props,
90
- name = _a.name,
91
- onChange = _a.onChange,
92
- onContinualChange = _a.onContinualChange;
75
+ var keyboardValueStr = keyboardValue.toString();
76
+ if (typeof prevParserValue === 'string' && _constants.FirstZeroReg.test(prevParserValue)) {
77
+ keyboardValueStr = keyboardValueStr.padStart(prevParserValue.length, '0');
78
+ }
79
+ var _a = _this.getParserOriginalValue(keyboardValueStr),
80
+ parserValueStr = _a.parserValueStr,
81
+ parserValue = _a.parserValue;
82
+ var _b = _this.props,
83
+ name = _b.name,
84
+ onChange = _b.onChange,
85
+ onContinualChange = _b.onContinualChange;
93
86
  if (prevValue !== parserValue) {
94
87
  if (onContinualChange) {
95
88
  onContinualChange(parserValueStr, parserValue, name);
@@ -130,14 +123,13 @@ var InputNumberNotRef = /** @class */function (_super) {
130
123
  }
131
124
  var onFocus = _this.props.onFocus;
132
125
  if (onFocus) {
133
- var parserValueStr = _this.getParserOriginalValue(originalValueStr);
134
- var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
126
+ var parserValue = _this.getParserOriginalValue(originalValueStr).parserValue;
135
127
  onFocus(parserValue, name);
136
128
  }
137
129
  };
138
130
  _this.onBlur = function (originalValueStr, name) {
139
131
  if (_this.keyboardHandler) {
140
- _this.keyboardHandler.remove();
132
+ _this.keyboardHandler();
141
133
  _this.keyboardHandler = null;
142
134
  }
143
135
  if (_this.props.disabled) {
@@ -147,8 +139,9 @@ var InputNumberNotRef = /** @class */function (_super) {
147
139
  onBlur = _a.onBlur,
148
140
  onChange = _a.onChange,
149
141
  onContinualChange = _a.onContinualChange;
150
- var parserValueStr = _this.getParserOriginalValue(originalValueStr);
151
- var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
142
+ var _b = _this.getParserOriginalValue(originalValueStr),
143
+ parserValueStr = _b.parserValueStr,
144
+ parserValue = _b.parserValue;
152
145
  _this.setState({
153
146
  originalValueStr: parserValueStr
154
147
  });
@@ -178,11 +171,12 @@ var InputNumberNotRef = /** @class */function (_super) {
178
171
  if (_this.props.disabled) {
179
172
  return;
180
173
  }
181
- var parserValueStr = _this.getParserOriginalValue(originalValueStr);
182
- var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
183
- var _a = _this.props,
184
- onChange = _a.onChange,
185
- onContinualChange = _a.onContinualChange;
174
+ var _a = _this.getParserOriginalValue(originalValueStr),
175
+ parserValueStr = _a.parserValueStr,
176
+ parserValue = _a.parserValue;
177
+ var _b = _this.props,
178
+ onChange = _b.onChange,
179
+ onContinualChange = _b.onContinualChange;
186
180
  if (onContinualChange) {
187
181
  onContinualChange(originalValueStr, parserValue, name);
188
182
  }
@@ -226,10 +220,16 @@ var InputNumberNotRef = /** @class */function (_super) {
226
220
  onKeyDown(ev, _this.state.parserValue, name);
227
221
  }
228
222
  };
229
- var defaultValueStr = (0, _utils.toFixed)(props.defaultValue, props.precision);
223
+ var _a = (0, _getParserOriginalValue.default)(__assign(__assign({}, props), {
224
+ originalValue: props.defaultValue,
225
+ prevParserValue: undefined,
226
+ skipError: true
227
+ })),
228
+ parserValueStr = _a.parserValueStr,
229
+ parserValue = _a.parserValue;
230
230
  _this.state = {
231
- originalValueStr: defaultValueStr,
232
- parserValue: (0, _utils.getNumberFromString)(defaultValueStr)
231
+ originalValueStr: parserValueStr,
232
+ parserValue: parserValue
233
233
  };
234
234
  return _this;
235
235
  }
@@ -240,9 +240,15 @@ var InputNumberNotRef = /** @class */function (_super) {
240
240
  if (nextProps.value !== prevStates.parserValue && (
241
241
  // 兼容外部传入空string/null的情况, 只有当一个值非空时,才会重新重置State信息
242
242
  !(0, _utils.isBlank)(nextProps.value) || !(0, _utils.isBlank)(prevStates.parserValue))) {
243
- var fixedValueStr = (0, _utils.toFixed)(nextProps.value, nextProps.precision);
244
- nextState.parserValue = (0, _utils.getNumberFromString)(fixedValueStr);
245
- nextState.originalValueStr = fixedValueStr;
243
+ var _a = (0, _getParserOriginalValue.default)(__assign(__assign({}, nextProps), {
244
+ originalValue: nextProps.value,
245
+ prevParserValue: prevStates.parserValue,
246
+ skipError: true
247
+ })),
248
+ parserValueStr = _a.parserValueStr,
249
+ parserValue = _a.parserValue;
250
+ nextState.parserValue = parserValue;
251
+ nextState.originalValueStr = parserValueStr;
246
252
  }
247
253
  }
248
254
  if ((0, _utils.isEmptyObject)(nextState)) {
@@ -252,7 +258,7 @@ var InputNumberNotRef = /** @class */function (_super) {
252
258
  };
253
259
  InputNumberNotRef.prototype.componentWillUnmount = function () {
254
260
  if (this.keyboardHandler) {
255
- this.keyboardHandler.remove();
261
+ this.keyboardHandler();
256
262
  this.keyboardHandler = null;
257
263
  }
258
264
  };
@@ -267,10 +273,12 @@ var InputNumberNotRef = /** @class */function (_super) {
267
273
  disabled = _b.disabled,
268
274
  style = _b.style,
269
275
  prefix = _b.prefix,
270
- controls = _b.controls;
276
+ controls = _b.controls,
277
+ checkValueOnMounted = _b.checkValueOnMounted,
278
+ maxLength = _b.maxLength;
271
279
  var originalValueStr = this.state.originalValueStr;
272
280
  return /*#__PURE__*/_react.default.createElement(_Input.default, {
273
- ref: (0, _utils.composeRef)(this.inputRef, upperRef),
281
+ ref: (0, _components.composeRef)(this.inputRef, upperRef),
274
282
  className: (0, _classnames.default)(cls, className, (_a = {}, _a["".concat(cls, "-has-controls")] = controls, _a)),
275
283
  placeholder: placeholder,
276
284
  disabled: disabled,
@@ -286,14 +294,18 @@ var InputNumberNotRef = /** @class */function (_super) {
286
294
  cls: cls,
287
295
  onUp: this.onUp,
288
296
  onDown: this.onDown
289
- }) : null
297
+ }) : null,
298
+ checkValueOnMounted: checkValueOnMounted,
299
+ maxLength: maxLength
290
300
  });
291
301
  };
292
302
  InputNumberNotRef.defaultProps = {
293
303
  defaultValue: '',
294
304
  controls: true,
295
305
  step: 1,
296
- keyboard: true
306
+ keyboard: true,
307
+ trimStartZero: true,
308
+ isRounding: true
297
309
  };
298
310
  return InputNumberNotRef;
299
311
  }(_react.default.Component);
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { AddListenerEventHandler } from '@autobest-ui/utils';
2
+ import { AddListenerEventRemoveHandler } from '@autobest-ui/utils';
3
3
  declare type PrevPopupSize = {
4
4
  width: number;
5
5
  height: number;
@@ -92,8 +92,8 @@ declare class Modal extends React.Component<ModalProps, ModalStates> {
92
92
  maskClosable: boolean;
93
93
  hiddenScroll: boolean;
94
94
  };
95
- clickOutsideHandler: AddListenerEventHandler | null;
96
- touchOutsideHandler: AddListenerEventHandler | null;
95
+ clickOutsideHandler: AddListenerEventRemoveHandler;
96
+ touchOutsideHandler: AddListenerEventRemoveHandler;
97
97
  popupTimer: any;
98
98
  affixTimer: any;
99
99
  popupRef: React.RefObject<HTMLDivElement>;
@@ -265,11 +265,11 @@ var Modal = /** @class */function (_super) {
265
265
  Modal.prototype.clearOutsideHandler = function () {
266
266
  this.clearPopupTimer();
267
267
  if (this.clickOutsideHandler) {
268
- this.clickOutsideHandler.remove();
268
+ this.clickOutsideHandler();
269
269
  this.clickOutsideHandler = null;
270
270
  }
271
271
  if (this.touchOutsideHandler) {
272
- this.touchOutsideHandler.remove();
272
+ this.touchOutsideHandler();
273
273
  this.touchOutsideHandler = null;
274
274
  }
275
275
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { AddListenerEventHandler } from '@autobest-ui/utils';
2
+ import { AddListenerEventRemoveHandler } from '@autobest-ui/utils';
3
3
  import { Position } from './utils';
4
4
  export interface MoveProps {
5
5
  /**
@@ -82,11 +82,11 @@ declare class Move extends React.Component<MoveProps> {
82
82
  isTouchScale: boolean;
83
83
  isForceUpdatePlacement: boolean;
84
84
  moveRef: React.RefObject<HTMLElement>;
85
- resizeHandler: AddListenerEventHandler | null;
86
- startHandler: AddListenerEventHandler | null;
87
- mousewheelHandler: AddListenerEventHandler | null;
88
- moveHandler: AddListenerEventHandler | null;
89
- endHandler: AddListenerEventHandler | null;
85
+ resizeHandler: AddListenerEventRemoveHandler;
86
+ startHandler: AddListenerEventRemoveHandler;
87
+ mousewheelHandler: AddListenerEventRemoveHandler;
88
+ moveHandler: AddListenerEventRemoveHandler;
89
+ endHandler: AddListenerEventRemoveHandler;
90
90
  updateTimer: any;
91
91
  componentDidMount(): void;
92
92
  componentDidUpdate(prevProps?: MoveProps): void;
package/lib/move/index.js CHANGED
@@ -320,26 +320,26 @@ var Move = /** @class */function (_super) {
320
320
  Move.prototype.componentWillUnmount = function () {
321
321
  clearTimeout(this.updateTimer);
322
322
  if (this.startHandler) {
323
- this.startHandler.remove();
323
+ this.startHandler();
324
324
  this.startHandler = null;
325
325
  }
326
326
  if (this.mousewheelHandler) {
327
- this.mousewheelHandler.remove();
327
+ this.mousewheelHandler();
328
328
  this.mousewheelHandler = null;
329
329
  }
330
330
  if (this.resizeHandler) {
331
- this.resizeHandler.remove();
331
+ this.resizeHandler();
332
332
  this.resizeHandler = null;
333
333
  }
334
334
  this.clearHandler();
335
335
  };
336
336
  Move.prototype.clearHandler = function () {
337
337
  if (this.moveHandler) {
338
- this.moveHandler.remove();
338
+ this.moveHandler();
339
339
  this.moveHandler = null;
340
340
  }
341
341
  if (this.endHandler) {
342
- this.endHandler.remove();
342
+ this.endHandler();
343
343
  this.endHandler = null;
344
344
  }
345
345
  };
@@ -32,7 +32,7 @@ export interface PopoverProps extends Pick<TriggerProps, Exclude<keyof TriggerPr
32
32
  }
33
33
  export declare type PopoverPlacement = TriggerPlacement;
34
34
  export declare type PopoverTriggerType = TriggerType;
35
- declare function Popover({ theme, innerClassName, closeClassName, arrowClassName, hiddenClose, tip, closeIcon, ...extraProps }: PopoverProps): JSX.Element;
35
+ declare function Popover({ theme, innerClassName, closeClassName, arrowClassName, hiddenClose, tip, closeIcon, maxHeight, ...extraProps }: PopoverProps): JSX.Element;
36
36
  declare namespace Popover {
37
37
  var defaultProps: {
38
38
  hiddenClose: boolean;
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
+ var _utils = require("@autobest-ui/utils");
10
11
  var _trigger = _interopRequireDefault(require("../trigger"));
11
12
  var __assign = void 0 && (void 0).__assign || function () {
12
13
  __assign = Object.assign || function (t) {
@@ -40,7 +41,8 @@ function Popover(_a) {
40
41
  hiddenClose = _a.hiddenClose,
41
42
  tip = _a.tip,
42
43
  closeIcon = _a.closeIcon,
43
- extraProps = __rest(_a, ["theme", "innerClassName", "closeClassName", "arrowClassName", "hiddenClose", "tip", "closeIcon"]);
44
+ maxHeight = _a.maxHeight,
45
+ extraProps = __rest(_a, ["theme", "innerClassName", "closeClassName", "arrowClassName", "hiddenClose", "tip", "closeIcon", "maxHeight"]);
44
46
  var triggerEl = _react.default.useRef(null);
45
47
  var _c = _react.default.useState({}),
46
48
  arrowStyle = _c[0],
@@ -78,7 +80,10 @@ function Popover(_a) {
78
80
  className: (0, _classnames.default)("".concat(cls, "-arrow"), arrowClassName),
79
81
  style: arrowStyle
80
82
  }), /*#__PURE__*/_react.default.createElement("div", {
81
- className: innerClass
83
+ className: innerClass,
84
+ style: !(0, _utils.isBlank)(maxHeight) ? {
85
+ maxHeight: "".concat(maxHeight, "px")
86
+ } : undefined
82
87
  }, tip));
83
88
  }
84
89
  return /*#__PURE__*/_react.default.createElement(_trigger.default, __assign({}, extraProps, {
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { RadioProps } from './interface';
3
+ declare const Radio: FC<RadioProps>;
4
+ export default Radio;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _classnames = _interopRequireDefault(require("classnames"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _utils = require("@autobest-ui/utils");
12
+ var _context = _interopRequireDefault(require("./context"));
13
+ 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); }
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ var __assign = void 0 && (void 0).__assign || function () {
16
+ __assign = Object.assign || function (t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) {
20
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
+ }
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var cls = 'ab-radio';
28
+ var Radio = function Radio(props) {
29
+ var _a;
30
+ var _b = props.checked,
31
+ propsChecked = _b === void 0 ? false : _b,
32
+ name = props.name,
33
+ onChange = props.onChange,
34
+ children = props.children,
35
+ disabled = props.disabled,
36
+ value = props.value,
37
+ className = props.className;
38
+ var _c = (0, _react.useState)(propsChecked),
39
+ checked = _c[0],
40
+ setChecked = _c[1];
41
+ var groupContext = (0, _react.useContext)(_context.default);
42
+ var mergedProps = (0, _utils.isEmptyObject)(groupContext) ? {
43
+ name: name,
44
+ disabled: disabled
45
+ } : {
46
+ name: groupContext.name,
47
+ disabled: 'disabled' in props ? disabled : groupContext.disabled
48
+ };
49
+ if ('checked' in props && propsChecked !== checked) {
50
+ setChecked(propsChecked);
51
+ }
52
+ (0, _react.useEffect)(function () {
53
+ // radioGroup
54
+ if ('value' in groupContext) {
55
+ setChecked(groupContext.value === value);
56
+ }
57
+ }, [groupContext, value]);
58
+ var onRadioChange = function onRadioChange(e) {
59
+ if (mergedProps.disabled) {
60
+ return;
61
+ }
62
+ if (onChange) {
63
+ onChange(e, mergedProps.name);
64
+ return;
65
+ }
66
+ // radioGroup
67
+ if (groupContext.onChange) {
68
+ groupContext.onChange(e.target.value, mergedProps.name);
69
+ return;
70
+ }
71
+ setChecked(!checked);
72
+ };
73
+ var onClick = function onClick(e) {
74
+ e.stopPropagation();
75
+ };
76
+ return /*#__PURE__*/_react.default.createElement("label", {
77
+ onClick: onClick,
78
+ className: (0, _classnames.default)(cls, (_a = {}, _a["".concat(cls, "-disabled")] = mergedProps.disabled, _a["".concat(cls, "-checked")] = checked, _a), groupContext.className, className)
79
+ }, /*#__PURE__*/_react.default.createElement("input", __assign({
80
+ type: "radio",
81
+ checked: checked,
82
+ value: value,
83
+ onChange: onRadioChange
84
+ }, mergedProps)), /*#__PURE__*/_react.default.createElement("span", {
85
+ className: "".concat(cls, "-control")
86
+ }), /*#__PURE__*/_react.default.createElement("span", {
87
+ className: "".concat(cls, "-child")
88
+ }, children));
89
+ };
90
+ var _default = Radio;
91
+ exports.default = _default;
@@ -0,0 +1,16 @@
1
+ import { Component } from 'react';
2
+ import { RadioGroupProps, RadioValue } from './interface';
3
+ interface RadioGroupState {
4
+ value: RadioValue;
5
+ }
6
+ declare class RadioGroup extends Component<RadioGroupProps, RadioGroupState> {
7
+ constructor(props: any);
8
+ static getDerivedStateFromProps(nextProps: RadioGroupProps, prevState: RadioGroupState): {
9
+ value: RadioValue;
10
+ };
11
+ onRadioChange: (v: RadioValue, n: string) => void;
12
+ renderRadioGroup: () => JSX.Element;
13
+ renderRadioList: () => JSX.Element;
14
+ render(): JSX.Element;
15
+ }
16
+ export default RadioGroup;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _utils = require("@autobest-ui/utils");
11
+ var _context = require("./context");
12
+ var _Radio = _interopRequireDefault(require("./Radio"));
13
+ 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); }
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ var __extends = void 0 && (void 0).__extends || function () {
16
+ var _extendStatics = function extendStatics(d, b) {
17
+ _extendStatics = Object.setPrototypeOf || {
18
+ __proto__: []
19
+ } instanceof Array && function (d, b) {
20
+ d.__proto__ = b;
21
+ } || function (d, b) {
22
+ for (var p in b) {
23
+ if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
24
+ }
25
+ };
26
+ return _extendStatics(d, b);
27
+ };
28
+ return function (d, b) {
29
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
30
+ _extendStatics(d, b);
31
+ function __() {
32
+ this.constructor = d;
33
+ }
34
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
35
+ };
36
+ }();
37
+ var cls = 'ab-radio';
38
+ function getRadioProp(radioProp, radioGroupProp) {
39
+ return (0, _utils.isUndef)(radioProp) ? radioGroupProp : radioProp;
40
+ }
41
+ var RadioGroup = /** @class */function (_super) {
42
+ __extends(RadioGroup, _super);
43
+ function RadioGroup(props) {
44
+ var _this = _super.call(this, props) || this;
45
+ _this.onRadioChange = function (v, n) {
46
+ var onChange = _this.props.onChange;
47
+ if (onChange) {
48
+ onChange(v, n);
49
+ return;
50
+ }
51
+ _this.setState({
52
+ value: v
53
+ });
54
+ };
55
+ _this.renderRadioGroup = function () {
56
+ var _a = _this.props,
57
+ name = _a.name,
58
+ children = _a.children,
59
+ disabled = _a.disabled;
60
+ var value = _this.state.value;
61
+ return /*#__PURE__*/_react.default.createElement(_context.RadioGroupContextProvider, {
62
+ value: {
63
+ name: name,
64
+ value: value,
65
+ disabled: disabled,
66
+ onChange: _this.onRadioChange,
67
+ className: "".concat(cls, "-item")
68
+ }
69
+ }, children);
70
+ };
71
+ _this.renderRadioList = function () {
72
+ var _a = _this.props,
73
+ name = _a.name,
74
+ options = _a.options,
75
+ disabled = _a.disabled;
76
+ var value = _this.state.value;
77
+ if ((0, _utils.isEmptyArray)(options)) {
78
+ return null;
79
+ }
80
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, options.map(function (item) {
81
+ return /*#__PURE__*/_react.default.createElement(_Radio.default, {
82
+ key: item.value,
83
+ className: "".concat(cls, "-item"),
84
+ name: name,
85
+ value: item.value,
86
+ disabled: getRadioProp(item.disabled, disabled),
87
+ checked: value === item.value,
88
+ onChange: function onChange(e, n) {
89
+ return _this.onRadioChange(e.target.value, n);
90
+ }
91
+ }, item.name);
92
+ }));
93
+ };
94
+ _this.state = {
95
+ value: props.defaultValue
96
+ };
97
+ return _this;
98
+ }
99
+ RadioGroup.getDerivedStateFromProps = function (nextProps, prevState) {
100
+ if ('value' in nextProps && nextProps.value !== prevState.value) {
101
+ return {
102
+ value: nextProps.value
103
+ };
104
+ }
105
+ return null;
106
+ };
107
+ RadioGroup.prototype.render = function () {
108
+ var _a = this.props.direction,
109
+ direction = _a === void 0 ? 'horizontal' : _a;
110
+ return /*#__PURE__*/_react.default.createElement("div", {
111
+ className: "".concat(cls, "-group-").concat(direction)
112
+ }, 'options' in this.props ? this.renderRadioList() : this.renderRadioGroup());
113
+ };
114
+ return RadioGroup;
115
+ }(_react.Component);
116
+ var _default = RadioGroup;
117
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ import { RadioGroupProps } from './interface';
3
+ declare const RadioGroupContext: React.Context<RadioGroupProps>;
4
+ export declare const RadioGroupContextProvider: React.Provider<RadioGroupProps>;
5
+ export default RadioGroupContext;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.RadioGroupContextProvider = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ 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); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ var RadioGroupContext = /*#__PURE__*/React.createContext({});
12
+ var RadioGroupContextProvider = RadioGroupContext.Provider;
13
+ exports.RadioGroupContextProvider = RadioGroupContextProvider;
14
+ var _default = RadioGroupContext;
15
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ export type { RadioProps, RadioGroupProps, RadioValue, RadioOptionItem } from './interface';
2
+ export { default as Radio } from './Radio';
3
+ export { default as RadioGroup } from './RadioGroup';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "Radio", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _Radio.default;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "RadioGroup", {
14
+ enumerable: true,
15
+ get: function get() {
16
+ return _RadioGroup.default;
17
+ }
18
+ });
19
+ var _Radio = _interopRequireDefault(require("./Radio"));
20
+ var _RadioGroup = _interopRequireDefault(require("./RadioGroup"));
@@ -0,0 +1,17 @@
1
+ import { ChangeEvent } from 'react';
2
+ export declare type RadioValue = string | number;
3
+ export interface RadioProps {
4
+ name?: string;
5
+ checked?: boolean;
6
+ disabled?: boolean;
7
+ value?: RadioValue;
8
+ onChange?: (e: ChangeEvent<HTMLInputElement>, name: string) => void;
9
+ className?: string;
10
+ }
11
+ export declare type RadioOptionItem = Pick<RadioProps, 'disabled' | 'name' | 'value'>;
12
+ export interface RadioGroupProps extends Pick<RadioProps, 'value' | 'name' | 'disabled' | 'className'> {
13
+ options?: RadioOptionItem[];
14
+ defaultValue?: RadioValue;
15
+ onChange?: (value: RadioValue, name: string) => void;
16
+ direction?: 'vertical' | 'horizontal';
17
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ .ab-radio{position:relative;overflow:hidden;display:inline-flex;align-items:center;cursor:pointer}.ab-radio input{width:1px;height:1px;margin:-1px;position:absolute}.ab-radio-checked .ab-radio-control{border-color:#0075ff}.ab-radio-checked .ab-radio-control::before{background-color:#0075ff}.ab-radio-checked .ab-radio-control:hover{border-color:#005cc8}.ab-radio-checked .ab-radio-control:hover::before{background-color:#005cc8}.ab-radio-disabled{cursor:not-allowed}.ab-radio-disabled .ab-radio-control{border-color:#d1d1d1;background-color:#f8f8f8}.ab-radio-disabled .ab-radio-control:hover{border-color:#d1d1d1}.ab-radio-disabled.ab-radio-checked .ab-radio-control::before{background-color:#d1d1d1}.ab-radio-control{width:.14rem;height:.14rem;border:1px solid #767676;border-radius:50%;margin-right:.06rem;position:relative;display:flex;align-items:center;justify-content:center}.ab-radio-control::before{content:"";width:.08rem;height:.08rem;border-radius:50%;background-color:transparent}.ab-radio-control:hover{border-color:#4f4f4f}.ab-radio-group-horizontal{display:flex}.ab-radio-group-horizontal .ab-radio-item{margin-right:.2rem}.ab-radio-group-horizontal .ab-radio-item:last-child{margin-right:0}.ab-radio-group-vertical{display:flex;flex-direction:column}.ab-radio-group-vertical .ab-radio-item{margin-bottom:.15rem}.ab-radio-group-vertical .ab-radio-item:last-child{margin-bottom:0}
@@ -1,5 +1,5 @@
1
1
  import React, { ReactElement } from 'react';
2
- import { AddListenerEventHandler } from '@autobest-ui/utils';
2
+ import { AddListenerEventRemoveHandler } from '@autobest-ui/utils';
3
3
  import { TriggerProps } from '../trigger';
4
4
  declare type Value = string | number | null;
5
5
  declare type NameValue = React.ReactChild | null;
@@ -97,7 +97,7 @@ interface SelectStates {
97
97
  }
98
98
  declare class Select extends React.Component<SelectProps, SelectStates> {
99
99
  prefixCls: string;
100
- keydownHandler: AddListenerEventHandler;
100
+ keydownHandler: AddListenerEventRemoveHandler;
101
101
  popupContentRef: React.RefObject<HTMLDivElement>;
102
102
  static defaultProps: {
103
103
  title: any;