@autobest-ui/components 2.11.3 → 2.13.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 (45) hide show
  1. package/esm/checkbox/Checkbox.d.ts +8 -31
  2. package/esm/checkbox/Checkbox.js +51 -113
  3. package/esm/checkbox/CheckboxGroup.d.ts +1 -1
  4. package/esm/checkbox/CheckboxGroup.js +3 -3
  5. package/esm/checkbox/style/index.css +1 -1
  6. package/esm/input-phone/index.d.ts +0 -1
  7. package/esm/input-phone/index.js +14 -6
  8. package/esm/radio/Radio.d.ts +1 -1
  9. package/esm/radio/Radio.js +37 -9
  10. package/esm/radio/RadioGroup.d.ts +2 -2
  11. package/esm/radio/RadioGroup.js +7 -7
  12. package/esm/radio/context.d.ts +2 -2
  13. package/esm/radio/context.js +1 -1
  14. package/esm/radio/index.d.ts +1 -1
  15. package/esm/radio/style/index.css +1 -1
  16. package/esm/radio/{interface.d.ts → type.d.ts} +4 -3
  17. package/esm/style.css +1 -1
  18. package/esm/table/body/CheckIcon.js +1 -0
  19. package/esm/table/header/CheckIcon.js +1 -0
  20. package/esm/table/index.d.ts +0 -4
  21. package/esm/table/style/index.css +1 -1
  22. package/lib/checkbox/Checkbox.d.ts +8 -31
  23. package/lib/checkbox/Checkbox.js +54 -113
  24. package/lib/checkbox/CheckboxGroup.d.ts +1 -1
  25. package/lib/checkbox/CheckboxGroup.js +3 -3
  26. package/lib/checkbox/style/index.css +1 -1
  27. package/lib/input-phone/index.d.ts +0 -1
  28. package/lib/input-phone/index.js +14 -6
  29. package/lib/radio/Radio.d.ts +1 -1
  30. package/lib/radio/Radio.js +37 -9
  31. package/lib/radio/RadioGroup.d.ts +2 -2
  32. package/lib/radio/RadioGroup.js +7 -7
  33. package/lib/radio/context.d.ts +2 -2
  34. package/lib/radio/context.js +3 -5
  35. package/lib/radio/index.d.ts +1 -1
  36. package/lib/radio/style/index.css +1 -1
  37. package/lib/radio/{interface.d.ts → type.d.ts} +4 -3
  38. package/lib/style.css +1 -1
  39. package/lib/table/body/CheckIcon.js +1 -0
  40. package/lib/table/header/CheckIcon.js +1 -0
  41. package/lib/table/index.d.ts +0 -4
  42. package/lib/table/style/index.css +1 -1
  43. package/package.json +3 -3
  44. /package/esm/radio/{interface.js → type.js} +0 -0
  45. /package/lib/radio/{interface.js → type.js} +0 -0
@@ -1,10 +1,14 @@
1
- import React, { MouseEvent } from 'react';
1
+ import React, { ReactChild } from 'react';
2
2
  export interface CheckboxProps {
3
- children?: React.ReactChild | React.ReactChild[];
3
+ children?: ReactChild | ReactChild[];
4
+ /**
5
+ * 勾选框尺寸,单位px
6
+ */
7
+ size?: number;
4
8
  /**
5
9
  * checked变化的回调函数, 参数 checked: boolean
6
10
  */
7
- onChange: (checked: boolean, name?: string | number) => void;
11
+ onChange?: (checked: boolean, name?: string | number) => void;
8
12
  /**
9
13
  * 是否选中
10
14
  */
@@ -18,18 +22,10 @@ export interface CheckboxProps {
18
22
  */
19
23
  className?: string;
20
24
  name?: string | number;
21
- /**
22
- * 勾选框尺寸,单位px
23
- */
24
- size?: number;
25
25
  /**
26
26
  * 是否禁用
27
27
  */
28
28
  disabled?: boolean;
29
- /**
30
- * 掉转文字和勾选框位置
31
- */
32
- reverse?: boolean;
33
29
  /**
34
30
  * 主题样式
35
31
  * white为选中时白底红箭头
@@ -37,24 +33,5 @@ export interface CheckboxProps {
37
33
  */
38
34
  theme?: 'white' | 'blue';
39
35
  }
40
- interface CheckboxState {
41
- visible: boolean;
42
- }
43
- declare class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
44
- static defaultProps: {
45
- size: number;
46
- disabled: boolean;
47
- defaultChecked: boolean;
48
- reverse: boolean;
49
- theme: string;
50
- };
51
- constructor(props: any);
52
- static getDerivedStateFromProps(nextProps: CheckboxProps, prevState: CheckboxState): {
53
- visible: boolean;
54
- };
55
- onVisibleChange: () => void;
56
- renderBox: () => JSX.Element;
57
- onClick: (e: MouseEvent<HTMLLabelElement>) => void;
58
- render(): JSX.Element;
59
- }
36
+ declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
60
37
  export default Checkbox;
@@ -1,120 +1,58 @@
1
- var __extends = this && this.__extends || function () {
2
- var _extendStatics = function extendStatics(d, b) {
3
- _extendStatics = Object.setPrototypeOf || {
4
- __proto__: []
5
- } instanceof Array && function (d, b) {
6
- d.__proto__ = b;
7
- } || function (d, b) {
8
- for (var p in b) {
9
- if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
10
- }
11
- };
12
- return _extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
- _extendStatics(d, b);
17
- function __() {
18
- this.constructor = d;
19
- }
20
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
21
- };
22
- }();
23
- import React from 'react';
1
+ import React, { forwardRef, useEffect, useState } from 'react';
24
2
  import classNames from 'classnames';
3
+ import { isUndef } from '@autobest-ui/utils';
25
4
  var cls = 'ab-checkbox';
26
- var Checkbox = /** @class */function (_super) {
27
- __extends(Checkbox, _super);
28
- function Checkbox(props) {
29
- var _this = _super.call(this, props) || this;
30
- _this.onVisibleChange = function () {
31
- var _a = _this.props,
32
- disabled = _a.disabled,
33
- onChange = _a.onChange,
34
- name = _a.name;
35
- if (disabled) {
36
- return;
37
- }
38
- var visible = !_this.state.visible;
39
- if (!('checked' in _this.props)) {
40
- _this.setState({
41
- visible: visible
42
- });
43
- }
44
- onChange(visible, name);
45
- };
46
- _this.renderBox = function () {
47
- var _a;
48
- var _b = _this.props,
49
- className = _b.className,
50
- disabled = _b.disabled,
51
- size = _b.size,
52
- theme = _b.theme;
53
- var visible = _this.state.visible;
54
- var innerStyle = {
55
- width: "".concat(size, "px"),
56
- height: "".concat(size, "px")
57
- };
58
- var iconStyle = {
59
- width: "".concat(size * 6 / 16, "px"),
60
- height: "".concat(size * 10 / 16, "px")
61
- };
62
- return /*#__PURE__*/React.createElement("span", {
63
- className: classNames(cls, className, "".concat(cls, "-").concat(theme), (_a = {}, _a["".concat(cls, "-checked")] = visible, _a["".concat(cls, "-disabled")] = disabled, _a))
64
- }, /*#__PURE__*/React.createElement("input", {
65
- className: "".concat(cls, "-input"),
66
- type: "checkbox",
67
- onChange: _this.onVisibleChange
68
- }), /*#__PURE__*/React.createElement("span", {
69
- className: "".concat(cls, "-inner"),
70
- style: innerStyle
71
- }, /*#__PURE__*/React.createElement("span", {
72
- className: "".concat(cls, "-icon"),
73
- style: iconStyle
74
- })));
75
- };
76
- _this.onClick = function (e) {
77
- e.stopPropagation();
78
- };
79
- _this.state = {
80
- visible: props.checked || props.defaultChecked
81
- };
82
- return _this;
83
- }
84
- Checkbox.getDerivedStateFromProps = function (nextProps, prevState) {
85
- // 如果父级传了 checked 则更新 state
86
- if ('checked' in nextProps && nextProps.checked !== prevState.visible) {
87
- return {
88
- visible: nextProps.checked
89
- };
5
+ var Checkbox = /*#__PURE__*/forwardRef(function (_a, ref) {
6
+ var _b;
7
+ var className = _a.className,
8
+ name = _a.name,
9
+ onChange = _a.onChange,
10
+ propsChecked = _a.checked,
11
+ defaultChecked = _a.defaultChecked,
12
+ disabled = _a.disabled,
13
+ children = _a.children,
14
+ theme = _a.theme,
15
+ size = _a.size;
16
+ var _c = useState(defaultChecked),
17
+ checked = _c[0],
18
+ setChecked = _c[1];
19
+ useEffect(function () {
20
+ if (!isUndef(propsChecked) && propsChecked !== checked) {
21
+ setChecked(propsChecked);
90
22
  }
91
- return null;
92
- };
93
- Checkbox.prototype.render = function () {
94
- var _a;
95
- var _b = this.props,
96
- className = _b.className,
97
- disabled = _b.disabled,
98
- children = _b.children,
99
- reverse = _b.reverse;
100
- // 只渲染复选框
101
- if (!children) {
102
- return this.renderBox();
23
+ }, [propsChecked, checked]);
24
+ var onCheckboxChange = function onCheckboxChange(e) {
25
+ setChecked(e.target.checked);
26
+ if (onChange) {
27
+ onChange(e.target.checked, name);
103
28
  }
104
- return /*#__PURE__*/React.createElement("label", {
105
- onClick: this.onClick,
106
- className: classNames("".concat(cls, "-wrap"), className, (_a = {}, _a["".concat(cls, "-reverse")] = reverse, _a["".concat(cls, "-disabled")] = disabled, _a))
107
- }, this.renderBox(), children ? /*#__PURE__*/React.createElement("span", {
108
- className: "".concat(cls, "-content")
109
- }, children) : null);
110
29
  };
111
- Checkbox.defaultProps = {
112
- size: 16,
113
- disabled: false,
114
- defaultChecked: false,
115
- reverse: false,
116
- theme: 'white'
30
+ var onWrapClick = function onWrapClick(e) {
31
+ e.stopPropagation();
117
32
  };
118
- return Checkbox;
119
- }(React.Component);
33
+ return /*#__PURE__*/React.createElement("label", {
34
+ className: classNames(cls, "".concat(cls, "-").concat(theme), (_b = {}, _b["".concat(cls, "-checked")] = checked, _b["".concat(cls, "-disabled")] = disabled, _b), className),
35
+ onClick: onWrapClick
36
+ }, /*#__PURE__*/React.createElement("input", {
37
+ ref: ref,
38
+ className: "".concat(cls, "-input"),
39
+ type: "checkbox",
40
+ checked: checked,
41
+ disabled: disabled,
42
+ onChange: onCheckboxChange
43
+ }), /*#__PURE__*/React.createElement("span", {
44
+ className: "".concat(cls, "-inner"),
45
+ style: {
46
+ width: size,
47
+ height: size
48
+ }
49
+ }), children);
50
+ });
51
+ Checkbox.defaultProps = {
52
+ disabled: false,
53
+ defaultChecked: false,
54
+ theme: 'blue',
55
+ size: 16
56
+ };
57
+ Checkbox.displayName = 'Checkbox';
120
58
  export default Checkbox;
@@ -1,6 +1,6 @@
1
1
  import { FC } from 'react';
2
2
  import { CheckboxProps } from './Checkbox';
3
- declare type CommonCheckboxProps = Partial<Pick<CheckboxProps, 'theme' | 'reverse' | 'disabled'>>;
3
+ declare type CommonCheckboxProps = Partial<Pick<CheckboxProps, 'theme' | 'disabled' | 'size'>>;
4
4
  export interface CheckboxGroupOptionItem extends CommonCheckboxProps {
5
5
  name: string;
6
6
  value?: string | number;
@@ -24,8 +24,8 @@ var CheckboxGroup = function CheckboxGroup(_a) {
24
24
  options = _a.options,
25
25
  className = _a.className,
26
26
  disabled = _a.disabled,
27
- reverse = _a.reverse,
28
- theme = _a.theme;
27
+ theme = _a.theme,
28
+ size = _a.size;
29
29
  if (isEmptyArray(options)) {
30
30
  return null;
31
31
  }
@@ -46,8 +46,8 @@ var CheckboxGroup = function CheckboxGroup(_a) {
46
46
  return /*#__PURE__*/React.createElement(Checkbox, {
47
47
  key: item.name,
48
48
  name: item.name,
49
- reverse: getCheckboxProp(item.reverse, reverse),
50
49
  theme: getCheckboxProp(item.theme, theme),
50
+ size: getCheckboxProp(item.size, size),
51
51
  disabled: getCheckboxProp(item.disabled, disabled),
52
52
  checked: item.checked,
53
53
  onChange: onCheckboxChange
@@ -1 +1 @@
1
- .ab-checkbox{display:inline-block;position:relative;font-size:0;cursor:pointer}.ab-checkbox-input{position:absolute;opacity:0;margin:0;padding:0;width:100%;height:100%;cursor:pointer;z-index:2}.ab-checkbox-white .ab-checkbox-icon{border-color:#e84040}.ab-checkbox-blue .ab-checkbox-icon{border-color:#fff}.ab-checkbox-blue .ab-checkbox-inner{transition:none}.ab-checkbox-blue.ab-checkbox-checked .ab-checkbox-inner{border:.01rem solid #0075ff;background-color:#0075ff}.ab-checkbox-inner{display:inline-block;position:relative;width:.16rem;height:.16rem;transition:.3s;border:.02rem solid #b0b0b0;border-radius:.02rem;background-color:#fff}.ab-checkbox-icon{visibility:hidden;position:absolute;width:.06rem;height:.1rem;left:20%;top:40%;transform:rotate(45deg) scale(0) translate(-50%,-50%);transition:.2s;border:.02rem solid #e84040;border-top:none;border-left:none}.ab-checkbox.ab-checkbox-checked .ab-checkbox-icon{visibility:visible;transform:rotate(45deg) scale(1) translate(-50%,-50%)}.ab-checkbox.ab-checkbox-disabled{cursor:not-allowed;color:rgba(0,0,0,.25)}.ab-checkbox.ab-checkbox-disabled .ab-checkbox-inner{border-color:#f0f0f0;background-color:#f5f5f5}.ab-checkbox.ab-checkbox-disabled .ab-checkbox-icon{border-color:#cecece}.ab-checkbox.ab-checkbox-disabled .ab-checkbox-content{text-decoration:none}.ab-checkbox-wrap{display:inline-block;position:relative;cursor:pointer}.ab-checkbox-wrap .ab-checkbox{position:absolute;transform:translateY(-50%);top:50%;left:0}.ab-checkbox-wrap:hover .ab-checkbox-content{text-decoration:underline}.ab-checkbox-wrap:hover .ab-checkbox-blue+.ab-checkbox-content{text-decoration:none}.ab-checkbox-content{padding-left:.24rem;display:inline-block}.ab-checkbox-wrap.ab-checkbox-reverse .ab-checkbox{left:auto;right:0}.ab-checkbox-wrap.ab-checkbox-reverse .ab-checkbox-content{padding-left:0;padding-right:.24rem}.ab-checkbox-wrap.ab-checkbox-disabled{cursor:not-allowed;color:rgba(0,0,0,.25)}.ab-checkbox-wrap.ab-checkbox-disabled .ab-checkbox-content{text-decoration:none}.ab-checkbox-group{display:flex;flex-wrap:wrap}.ab-checkbox-group .ab-checkbox-wrap{margin-right:.15rem}
1
+ .ab-checkbox{cursor:pointer;display:inline-flex;align-items:center;user-select:none}.ab-checkbox-input{cursor:pointer;position:absolute;opacity:0;margin:0;padding:0;z-index:2}.ab-checkbox-inner{display:inline-block;margin-right:.06rem;position:relative;border:1px solid #b0b0b0;border-radius:.02rem;background-color:#fff;transition:.3s;flex-shrink:0}.ab-checkbox-inner::after{box-sizing:border-box;position:absolute;top:45%;left:22%;display:table;width:37.5%;height:62.5%;border-style:solid;border-width:2px;border-top:0;border-inline-start:0;transform:rotate(45deg) scale(0) translate(-50%,-50%);opacity:0;content:"";transition:.2s cubic-bezier(.71,-.46,.88,.6),opacity .1s}.ab-checkbox-checked .ab-checkbox-inner::after{opacity:1;transform:rotate(45deg) scale(1) translate(-50%,-50%);transition:.2s cubic-bezier(.12,.4,.29,1.46) .1s}.ab-checkbox-disabled{cursor:not-allowed;color:rgba(0,0,0,.25)}.ab-checkbox-disabled .ab-checkbox-inner{border-color:#f0f0f0;background-color:#f5f5f5}.ab-checkbox-disabled .ab-checkbox-input{cursor:not-allowed}.ab-checkbox-white .ab-checkbox-inner::after{border-color:#e84040}.ab-checkbox-white.ab-checkbox-disabled .ab-checkbox-inner::after{border-color:#cecece}.ab-checkbox-blue .ab-checkbox-inner::after{border-color:#fff}.ab-checkbox-blue.ab-checkbox-checked .ab-checkbox-inner{transition:none;background-color:#0075ff;border-color:#0075ff}.ab-checkbox-blue.ab-checkbox-disabled .ab-checkbox-inner{border-color:#f0f0f0;background-color:#f5f5f5}.ab-checkbox-blue.ab-checkbox-disabled .ab-checkbox-inner::after{border-color:#cecece}.ab-checkbox-group{display:flex;flex-wrap:wrap}.ab-checkbox-group .ab-checkbox{margin-right:.08rem}
@@ -45,7 +45,6 @@ interface InputPhonePropsWithRef extends InputPhoneProps {
45
45
  export declare class InputPhoneNotRef extends React.Component<InputPhonePropsWithRef, InputPhoneState> {
46
46
  prefixCls: string;
47
47
  inputRef: React.RefObject<HTMLInputElement>;
48
- prevFormatValue: string;
49
48
  onFocusTimer: ReturnType<typeof setTimeout>;
50
49
  static defaultProps: {
51
50
  defaultValue: string;
@@ -76,6 +76,7 @@ var InputPhoneNotRef = /** @class */function (_super) {
76
76
  _this.onFocus = function (inputValue, name) {
77
77
  var _a = _this.props,
78
78
  onFocus = _a.onFocus,
79
+ onChange = _a.onChange,
79
80
  format = _a.format,
80
81
  placeholderChar = _a.placeholderChar;
81
82
  var formatValue = inputValue;
@@ -89,6 +90,9 @@ var InputPhoneNotRef = /** @class */function (_super) {
89
90
  }, function () {
90
91
  _this.resetCursorPositionOnFocus('', 50);
91
92
  });
93
+ if (onChange) {
94
+ onChange(formatValue, getNumberValue(formatValue), name);
95
+ }
92
96
  return;
93
97
  }
94
98
  _this.resetCursorPositionOnFocus(inputValue, 50);
@@ -102,11 +106,15 @@ var InputPhoneNotRef = /** @class */function (_super) {
102
106
  var _a = _this.props,
103
107
  format = _a.format,
104
108
  placeholderChar = _a.placeholderChar,
105
- onBlur = _a.onBlur;
109
+ onBlur = _a.onBlur,
110
+ onChange = _a.onChange;
106
111
  if (formatValue === getPhoneFormat('', format, placeholderChar)) {
107
112
  _this.setState({
108
113
  formatValue: ''
109
114
  });
115
+ if (onChange) {
116
+ onChange('', '', name);
117
+ }
110
118
  if (onBlur) {
111
119
  onBlur('', '', name);
112
120
  }
@@ -124,16 +132,16 @@ var InputPhoneNotRef = /** @class */function (_super) {
124
132
  format = _a.format,
125
133
  onChange = _a.onChange,
126
134
  placeholderChar = _a.placeholderChar;
135
+ var prevFormatValue = _this.state.formatValue;
127
136
  var _b = getUpdatedValue({
128
137
  value: inputValue,
129
- prevValue: _this.prevFormatValue,
138
+ prevValue: prevFormatValue,
130
139
  format: format,
131
140
  selectionEnd: _this.inputRef.current.selectionEnd,
132
141
  placeholder: placeholderChar
133
142
  }),
134
143
  formatValue = _b.value,
135
144
  cursorPosition = _b.cursorPosition;
136
- _this.prevFormatValue = formatValue;
137
145
  _this.setState({
138
146
  formatValue: formatValue
139
147
  }, function () {
@@ -146,9 +154,8 @@ var InputPhoneNotRef = /** @class */function (_super) {
146
154
  var defaultValue = props.defaultValue,
147
155
  format = props.format,
148
156
  placeholderChar = props.placeholderChar;
149
- _this.prevFormatValue = getPhoneFormat(defaultValue, format, placeholderChar);
150
157
  _this.state = {
151
- formatValue: isBlank(defaultValue) ? '' : _this.prevFormatValue
158
+ formatValue: isBlank(defaultValue) ? '' : getPhoneFormat(defaultValue, format, placeholderChar)
152
159
  };
153
160
  return _this;
154
161
  }
@@ -157,8 +164,9 @@ var InputPhoneNotRef = /** @class */function (_super) {
157
164
  if (nextProps.value !== prevState.formatValue && (
158
165
  // 兼容外部传入空string/null的情况, 只有当一个值非空时,才会重新重置State信息
159
166
  !isBlank(nextProps.value) || !isBlank(prevState.formatValue))) {
167
+ var formatValue = isBlank(nextProps.value) ? '' : getPhoneFormat(nextProps.value, nextProps.format, nextProps.placeholderChar);
160
168
  return {
161
- formatValue: getPhoneFormat(nextProps.value, nextProps.format, nextProps.placeholderChar)
169
+ formatValue: formatValue
162
170
  };
163
171
  }
164
172
  }
@@ -1,4 +1,4 @@
1
1
  import { FC } from 'react';
2
- import { RadioProps } from './interface';
2
+ import { RadioProps } from './type';
3
3
  declare const Radio: FC<RadioProps>;
4
4
  export default Radio;
@@ -19,6 +19,7 @@ var Radio = function Radio(props) {
19
19
  var _a;
20
20
  var _b = props.checked,
21
21
  propsChecked = _b === void 0 ? false : _b,
22
+ size = props.size,
22
23
  name = props.name,
23
24
  onChange = props.onChange,
24
25
  children = props.children,
@@ -45,36 +46,63 @@ var Radio = function Radio(props) {
45
46
  setChecked(groupContext.value === value);
46
47
  }
47
48
  }, [groupContext, value]);
48
- var onRadioChange = function onRadioChange(e) {
49
+ var onRadioChange = function onRadioChange(ev) {
49
50
  if (mergedProps.disabled) {
50
51
  return;
51
52
  }
53
+ var checkedValue = ev.target.value;
52
54
  if (onChange) {
53
- onChange(e, mergedProps.name);
55
+ onChange(checkedValue, mergedProps.name, ev.target.checked);
54
56
  return;
55
57
  }
56
58
  // radioGroup
57
59
  if (groupContext.onChange) {
58
- groupContext.onChange(e.target.value, mergedProps.name);
60
+ groupContext.onChange(checkedValue, mergedProps.name);
59
61
  return;
60
62
  }
61
63
  setChecked(!checked);
62
64
  };
63
- var onClick = function onClick(e) {
64
- e.stopPropagation();
65
+ var onClick = function onClick(ev) {
66
+ ev.stopPropagation();
65
67
  };
66
68
  return /*#__PURE__*/React.createElement("label", {
67
69
  onClick: onClick,
68
70
  className: classNames(cls, (_a = {}, _a["".concat(cls, "-disabled")] = mergedProps.disabled, _a["".concat(cls, "-checked")] = checked, _a), groupContext.className, className)
69
71
  }, /*#__PURE__*/React.createElement("input", __assign({
72
+ style: {
73
+ width: size,
74
+ height: size
75
+ },
70
76
  type: "radio",
71
77
  checked: checked,
72
78
  value: value,
73
79
  onChange: onRadioChange
74
80
  }, mergedProps)), /*#__PURE__*/React.createElement("span", {
75
- className: "".concat(cls, "-control")
76
- }), /*#__PURE__*/React.createElement("span", {
77
- className: "".concat(cls, "-child")
78
- }, children));
81
+ className: "".concat(cls, "-control"),
82
+ style: {
83
+ width: size,
84
+ height: size,
85
+ fontSize: size
86
+ }
87
+ }, /*#__PURE__*/React.createElement("svg", {
88
+ className: "".concat(cls, "-outer"),
89
+ focusable: "false",
90
+ "aria-hidden": "true",
91
+ viewBox: "0 0 512 512"
92
+ }, /*#__PURE__*/React.createElement("path", {
93
+ d: "M448,256c0-106-86-192-192-192S64,150,64,256s86,192,192,192S448,362,448,256Z",
94
+ strokeWidth: "1.5em",
95
+ fill: "#fff"
96
+ })), /*#__PURE__*/React.createElement("svg", {
97
+ className: "".concat(cls, "-dot"),
98
+ focusable: "false",
99
+ "aria-hidden": "true",
100
+ viewBox: "0 0 24 24"
101
+ }, /*#__PURE__*/React.createElement("path", {
102
+ d: "M8.465 8.465C9.37 7.56 10.62 7 12 7C14.76 7 17 9.24 17 12C17 13.38 16.44 14.63 15.535 15.535C14.63 16.44 13.38 17 12 17C9.24 17 7 14.76 7 12C7 10.62 7.56 9.37 8.465 8.465Z"
103
+ }))), children);
104
+ };
105
+ Radio.defaultProps = {
106
+ size: 16
79
107
  };
80
108
  export default Radio;
@@ -1,5 +1,5 @@
1
1
  import { Component } from 'react';
2
- import { RadioGroupProps, RadioValue } from './interface';
2
+ import { RadioGroupProps, RadioValue } from './type';
3
3
  interface RadioGroupState {
4
4
  value: RadioValue;
5
5
  }
@@ -8,7 +8,7 @@ declare class RadioGroup extends Component<RadioGroupProps, RadioGroupState> {
8
8
  static getDerivedStateFromProps(nextProps: RadioGroupProps, prevState: RadioGroupState): {
9
9
  value: RadioValue;
10
10
  };
11
- onRadioChange: (v: RadioValue, n: string) => void;
11
+ onRadioChange: (value: RadioValue, name?: string) => void;
12
12
  renderRadioGroup: () => JSX.Element;
13
13
  renderRadioList: () => JSX.Element;
14
14
  render(): JSX.Element;
@@ -32,14 +32,14 @@ var RadioGroup = /** @class */function (_super) {
32
32
  __extends(RadioGroup, _super);
33
33
  function RadioGroup(props) {
34
34
  var _this = _super.call(this, props) || this;
35
- _this.onRadioChange = function (v, n) {
35
+ _this.onRadioChange = function (value, name) {
36
36
  var onChange = _this.props.onChange;
37
37
  if (onChange) {
38
- onChange(v, n);
38
+ onChange(value, name);
39
39
  return;
40
40
  }
41
41
  _this.setState({
42
- value: v
42
+ value: value
43
43
  });
44
44
  };
45
45
  _this.renderRadioGroup = function () {
@@ -62,7 +62,8 @@ var RadioGroup = /** @class */function (_super) {
62
62
  var _a = _this.props,
63
63
  name = _a.name,
64
64
  options = _a.options,
65
- disabled = _a.disabled;
65
+ disabled = _a.disabled,
66
+ size = _a.size;
66
67
  var value = _this.state.value;
67
68
  if (isEmptyArray(options)) {
68
69
  return null;
@@ -72,12 +73,11 @@ var RadioGroup = /** @class */function (_super) {
72
73
  key: item.value,
73
74
  className: "".concat(cls, "-item"),
74
75
  name: name,
76
+ size: size,
75
77
  value: item.value,
76
78
  disabled: getRadioProp(item.disabled, disabled),
77
79
  checked: value === item.value,
78
- onChange: function onChange(e, n) {
79
- return _this.onRadioChange(e.target.value, n);
80
- }
80
+ onChange: _this.onRadioChange
81
81
  }, item.name);
82
82
  }));
83
83
  };
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
- import { RadioGroupProps } from './interface';
1
+ import React from 'react';
2
+ import { RadioGroupProps } from './type';
3
3
  declare const RadioGroupContext: React.Context<RadioGroupProps>;
4
4
  export declare const RadioGroupContextProvider: React.Provider<RadioGroupProps>;
5
5
  export default RadioGroupContext;
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  var RadioGroupContext = /*#__PURE__*/React.createContext({});
3
3
  export var RadioGroupContextProvider = RadioGroupContext.Provider;
4
4
  export default RadioGroupContext;
@@ -1,3 +1,3 @@
1
- export type { RadioProps, RadioGroupProps, RadioValue, RadioOptionItem } from './interface';
1
+ export type { RadioProps, RadioGroupProps, RadioValue, RadioOptionItem } from './type';
2
2
  export { default as Radio } from './Radio';
3
3
  export { default as RadioGroup } from './RadioGroup';
@@ -1 +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
+ .ab-radio{position:relative;overflow:hidden;display:inline-flex;align-items:center;cursor:pointer;font-size:.14rem}.ab-radio:hover .ab-radio-control{color:#4f4f4f}.ab-radio input{cursor:inherit;position:absolute;margin:0;padding:0;opacity:0;top:0;left:0;z-index:1}.ab-radio-checked:hover .ab-radio-control{color:#005cc8}.ab-radio-checked .ab-radio-control{color:#0075ff}.ab-radio-checked .ab-radio-control svg{display:inline-block}.ab-radio-disabled{cursor:not-allowed}.ab-radio-disabled .ab-radio-control,.ab-radio-disabled:hover .ab-radio-control{color:#d1d1d1}.ab-radio-control{margin-right:.06rem;position:relative;color:#767676}.ab-radio-control svg{width:1em;height:1em;user-select:none;flex-shrink:0;fill:currentcolor;stroke:currentcolor}.ab-radio-dot,.ab-radio-outer{position:absolute;left:0;top:0}.ab-radio-dot{display:none}.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,15 +1,16 @@
1
- import { ChangeEvent } from 'react';
2
1
  export declare type RadioValue = string | number;
3
2
  export interface RadioProps {
4
3
  name?: string;
5
4
  checked?: boolean;
6
5
  disabled?: boolean;
7
6
  value?: RadioValue;
8
- onChange?: (e: ChangeEvent<HTMLInputElement>, name: string) => void;
7
+ /**单位为px */
8
+ size?: number;
9
+ onChange?: (value: RadioValue, name?: string, checked?: boolean) => void;
9
10
  className?: string;
10
11
  }
11
12
  export declare type RadioOptionItem = Pick<RadioProps, 'disabled' | 'name' | 'value'>;
12
- export interface RadioGroupProps extends Pick<RadioProps, 'value' | 'name' | 'disabled' | 'className'> {
13
+ export interface RadioGroupProps extends Pick<RadioProps, 'value' | 'name' | 'disabled' | 'className' | 'size'> {
13
14
  options?: RadioOptionItem[];
14
15
  defaultValue?: RadioValue;
15
16
  onChange?: (value: RadioValue, name: string) => void;