@kdcloudjs/kdesign 1.6.16 → 1.6.17

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.
@@ -556,10 +556,12 @@ function usePopper(locatorElement, popperElement, props) {
556
556
  focus: 'mousedown',
557
557
  contextMenu: 'mousedown'
558
558
  };
559
+ popperNode === null || popperNode === void 0 ? void 0 : popperNode.addEventListener('mouseleave', debounceHidePopper);
559
560
  Array.isArray(trigger) ? trigger.forEach(function (action) {
560
561
  return document.addEventListener(mapEvent[action], debounceHidePopper);
561
562
  }) : document.addEventListener(mapEvent[trigger], debounceHidePopper);
562
563
  return function () {
564
+ popperNode === null || popperNode === void 0 ? void 0 : popperNode.removeEventListener('mouseleave', debounceHidePopper);
563
565
  Array.isArray(trigger) ? trigger.forEach(function (action) {
564
566
  return document.removeEventListener(mapEvent[action], debounceHidePopper);
565
567
  }) : document.removeEventListener(mapEvent[trigger], debounceHidePopper);
@@ -1,8 +1,5 @@
1
1
  import React from 'react';
2
- export declare const CheckboxTypes: ["default", "square"];
3
- export declare type CheckboxType = typeof CheckboxTypes[number];
4
- export declare const CheckboxSizes: ["large", "middle", "small"];
5
- export declare type CheckboxSize = typeof CheckboxSizes[number];
2
+ import type { CheckboxType, CheckboxSize } from './group';
6
3
  export interface CheckboxProps {
7
4
  checked?: boolean;
8
5
  defaultChecked?: boolean;
@@ -19,14 +19,12 @@ var __rest = this && this.__rest || function (s, e) {
19
19
 
20
20
  import React, { useCallback, useContext, useEffect, useState, useRef } from 'react';
21
21
  import classNames from 'classnames';
22
+ import { GroupContext, CheckboxTypes, CheckboxSizes } from './group';
22
23
  import ConfigContext from '../config-provider/ConfigContext';
23
24
  import { getCompProps } from '../_utils';
24
- import { tuple } from '../_utils/type';
25
25
  import isBoolean from 'lodash/isBoolean';
26
26
  import Icon from '../icon';
27
27
  import devWarning from '../_utils/devwarning';
28
- export var CheckboxTypes = tuple('default', 'square');
29
- export var CheckboxSizes = tuple('large', 'middle', 'small');
30
28
 
31
29
  var InternalCheckbox = function InternalCheckbox(props, ref) {
32
30
  var _context, _context2, _context3, _classNames, _context4, _context5, _context6, _classNames2, _context7, _context8, _context9, _context10, _context11, _context12, _context13, _context14, _classNames4, _context15, _context16, _context17, _classNames5, _context18;
@@ -53,38 +51,47 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
53
51
  name = CheckboxProps.name,
54
52
  rest = __rest(CheckboxProps, ["checkboxType", "className", "prefixCls", "defaultChecked", "checked", "size", "onChange", "disabled", "children", "style", "value", "indeterminate", "name"]);
55
53
 
56
- var getChecked = function getChecked() {
57
- return isBoolean(checked) ? checked : defaultChecked;
58
- };
54
+ var checkboxGroup = React.useContext(GroupContext);
55
+ var mergedDisabled = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.disabled) || disabled;
56
+ var mergedCheckboxType = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.checkboxType) || checkboxType;
57
+ var mergedName = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.name) || name;
58
+ var initChecked = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue) ? (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue.indexOf(value)) > -1 : isBoolean(checked) ? checked : defaultChecked;
59
59
 
60
- var _useState = useState(getChecked()),
60
+ var _useState = useState(initChecked),
61
61
  _useState2 = _slicedToArray(_useState, 2),
62
62
  selected = _useState2[0],
63
63
  setSelected = _useState2[1];
64
64
 
65
65
  var labelRef = useRef(null);
66
- devWarning(CheckboxTypes.indexOf(checkboxType) === -1, 'checkbox', "cannot found checkbox type '".concat(checkboxType, "'"));
66
+ React.useEffect(function () {
67
+ setSelected((checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue) ? (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue.indexOf(value)) > -1 : isBoolean(checked) ? checked : defaultChecked);
68
+ }, [checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue, checked, defaultChecked]);
69
+ devWarning(CheckboxTypes.indexOf(mergedCheckboxType) === -1, 'checkbox', "cannot found checkbox type '".concat(mergedCheckboxType, "'"));
67
70
  devWarning(CheckboxSizes.indexOf(size) === -1, 'checkbox', "cannot found size type '".concat(size, "'"));
68
71
  var checkboxPrefixCls = getPrefixCls(prefixCls, 'checkbox', customPrefixcls);
69
72
 
70
73
  var isDefaultType = function isDefaultType() {
71
- return checkboxType === 'default';
74
+ return mergedCheckboxType === 'default';
72
75
  };
73
76
 
74
77
  var getIndeterminate = function getIndeterminate() {
75
78
  return selected ? false : indeterminate;
76
79
  };
77
80
 
78
- var getDefaultClassName = classNames(className, (_classNames = {}, _defineProperty(_classNames, "".concat(checkboxPrefixCls), true), _defineProperty(_classNames, "".concat(checkboxPrefixCls, "-no-child"), !children), _defineProperty(_classNames, _concatInstanceProperty(_context = "".concat(checkboxPrefixCls, "-")).call(_context, size), true && !!children), _defineProperty(_classNames, _concatInstanceProperty(_context2 = "".concat(checkboxPrefixCls, "-")).call(_context2, checkboxType), true), _defineProperty(_classNames, _concatInstanceProperty(_context3 = "".concat(checkboxPrefixCls, "-")).call(_context3, checkboxType, "-disabled"), disabled), _defineProperty(_classNames, "checked", selected), _classNames));
79
- var getSquareClassName = classNames(className, (_classNames2 = {}, _defineProperty(_classNames2, "".concat(checkboxPrefixCls), true), _defineProperty(_classNames2, _concatInstanceProperty(_context4 = "".concat(checkboxPrefixCls, "-")).call(_context4, checkboxType), true), _defineProperty(_classNames2, _concatInstanceProperty(_context5 = "".concat(checkboxPrefixCls, "-")).call(_context5, checkboxType, "-disabled"), disabled), _defineProperty(_classNames2, _concatInstanceProperty(_context6 = "".concat(checkboxPrefixCls, "-")).call(_context6, checkboxType, "-checked"), selected && !disabled), _defineProperty(_classNames2, "checked", selected), _classNames2));
81
+ var getDefaultClassName = classNames(className, (_classNames = {}, _defineProperty(_classNames, "".concat(checkboxPrefixCls), true), _defineProperty(_classNames, "".concat(checkboxPrefixCls, "-no-child"), !children), _defineProperty(_classNames, _concatInstanceProperty(_context = "".concat(checkboxPrefixCls, "-")).call(_context, size), true && !!children), _defineProperty(_classNames, _concatInstanceProperty(_context2 = "".concat(checkboxPrefixCls, "-")).call(_context2, mergedCheckboxType), true), _defineProperty(_classNames, _concatInstanceProperty(_context3 = "".concat(checkboxPrefixCls, "-")).call(_context3, mergedCheckboxType, "-disabled"), mergedDisabled), _defineProperty(_classNames, "checked", selected), _classNames));
82
+ var getSquareClassName = classNames(className, (_classNames2 = {}, _defineProperty(_classNames2, "".concat(checkboxPrefixCls), true), _defineProperty(_classNames2, _concatInstanceProperty(_context4 = "".concat(checkboxPrefixCls, "-")).call(_context4, mergedCheckboxType), true), _defineProperty(_classNames2, _concatInstanceProperty(_context5 = "".concat(checkboxPrefixCls, "-")).call(_context5, mergedCheckboxType, "-disabled"), mergedDisabled), _defineProperty(_classNames2, _concatInstanceProperty(_context6 = "".concat(checkboxPrefixCls, "-")).call(_context6, mergedCheckboxType, "-checked"), selected && !mergedDisabled), _defineProperty(_classNames2, "checked", selected), _classNames2));
80
83
  var getRootClassName = isDefaultType() ? getDefaultClassName : getSquareClassName;
81
84
  var inputClassName = classNames(_defineProperty({}, "".concat(checkboxPrefixCls, "-input"), true));
82
- var checkedWrapperClassName = classNames((_classNames4 = {}, _defineProperty(_classNames4, _concatInstanceProperty(_context7 = "".concat(checkboxPrefixCls, "-")).call(_context7, checkboxType, "-no-child"), !children), _defineProperty(_classNames4, _concatInstanceProperty(_context8 = "".concat(checkboxPrefixCls, "-")).call(_context8, checkboxType, "-wrapper"), true), _defineProperty(_classNames4, _concatInstanceProperty(_context9 = "".concat(checkboxPrefixCls, "-")).call(_context9, checkboxType, "-wrapper-size"), !!children), _defineProperty(_classNames4, _concatInstanceProperty(_context10 = "".concat(checkboxPrefixCls, "-")).call(_context10, checkboxType, "-margin"), !!children), _defineProperty(_classNames4, _concatInstanceProperty(_context11 = "".concat(checkboxPrefixCls, "-")).call(_context11, checkboxType, "-checked"), selected), _defineProperty(_classNames4, _concatInstanceProperty(_context12 = "".concat(checkboxPrefixCls, "-")).call(_context12, checkboxType, "-indeterminate"), getIndeterminate()), _defineProperty(_classNames4, _concatInstanceProperty(_context13 = "".concat(checkboxPrefixCls, "-")).call(_context13, checkboxType, "-disabled"), disabled && !selected), _defineProperty(_classNames4, _concatInstanceProperty(_context14 = "".concat(checkboxPrefixCls, "-")).call(_context14, checkboxType, "-checked-disabled"), disabled && selected), _classNames4));
83
- var triangleClassName = classNames((_classNames5 = {}, _defineProperty(_classNames5, _concatInstanceProperty(_context15 = "".concat(checkboxPrefixCls, "-")).call(_context15, checkboxType, "-triangle"), !selected), _defineProperty(_classNames5, _concatInstanceProperty(_context16 = "".concat(checkboxPrefixCls, "-")).call(_context16, checkboxType, "-triangle-checked"), selected), _defineProperty(_classNames5, _concatInstanceProperty(_context17 = "".concat(checkboxPrefixCls, "-")).call(_context17, checkboxType, "-triangle-disabled"), disabled), _classNames5));
84
- var innerIconClassName = classNames(_defineProperty({}, _concatInstanceProperty(_context18 = "".concat(checkboxPrefixCls, "-")).call(_context18, checkboxType, "-inner"), true));
85
+ var checkedWrapperClassName = classNames((_classNames4 = {}, _defineProperty(_classNames4, _concatInstanceProperty(_context7 = "".concat(checkboxPrefixCls, "-")).call(_context7, mergedCheckboxType, "-no-child"), !children), _defineProperty(_classNames4, _concatInstanceProperty(_context8 = "".concat(checkboxPrefixCls, "-")).call(_context8, mergedCheckboxType, "-wrapper"), true), _defineProperty(_classNames4, _concatInstanceProperty(_context9 = "".concat(checkboxPrefixCls, "-")).call(_context9, mergedCheckboxType, "-wrapper-size"), !!children), _defineProperty(_classNames4, _concatInstanceProperty(_context10 = "".concat(checkboxPrefixCls, "-")).call(_context10, mergedCheckboxType, "-margin"), !!children), _defineProperty(_classNames4, _concatInstanceProperty(_context11 = "".concat(checkboxPrefixCls, "-")).call(_context11, mergedCheckboxType, "-checked"), selected), _defineProperty(_classNames4, _concatInstanceProperty(_context12 = "".concat(checkboxPrefixCls, "-")).call(_context12, mergedCheckboxType, "-indeterminate"), getIndeterminate()), _defineProperty(_classNames4, _concatInstanceProperty(_context13 = "".concat(checkboxPrefixCls, "-")).call(_context13, mergedCheckboxType, "-disabled"), mergedDisabled && !selected), _defineProperty(_classNames4, _concatInstanceProperty(_context14 = "".concat(checkboxPrefixCls, "-")).call(_context14, mergedCheckboxType, "-checked-disabled"), mergedDisabled && selected), _classNames4));
86
+ var triangleClassName = classNames((_classNames5 = {}, _defineProperty(_classNames5, _concatInstanceProperty(_context15 = "".concat(checkboxPrefixCls, "-")).call(_context15, mergedCheckboxType, "-triangle"), !selected), _defineProperty(_classNames5, _concatInstanceProperty(_context16 = "".concat(checkboxPrefixCls, "-")).call(_context16, mergedCheckboxType, "-triangle-checked"), selected), _defineProperty(_classNames5, _concatInstanceProperty(_context17 = "".concat(checkboxPrefixCls, "-")).call(_context17, mergedCheckboxType, "-triangle-disabled"), mergedDisabled), _classNames5));
87
+ var innerIconClassName = classNames(_defineProperty({}, _concatInstanceProperty(_context18 = "".concat(checkboxPrefixCls, "-")).call(_context18, mergedCheckboxType, "-inner"), true));
85
88
  var handleChange = useCallback(function (e) {
86
89
  onChange && onChange(e);
87
- setSelected(e.target.checked);
90
+ (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.onCheckboxGroupChange) && (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.onCheckboxGroupChange(value, e.target.checked));
91
+
92
+ if (!(checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.isControlled)) {
93
+ setSelected(e.target.checked);
94
+ }
88
95
  }, [onChange]);
89
96
  useEffect(function () {
90
97
  isBoolean(checked) && checked !== selected && setSelected(checked);
@@ -125,7 +132,7 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
125
132
  className: innerIconClassName
126
133
  }, /*#__PURE__*/React.createElement(Icon, {
127
134
  type: "right-bold",
128
- className: _concatInstanceProperty(_context19 = "".concat(checkboxPrefixCls, "-")).call(_context19, checkboxType, "-inner-icon")
135
+ className: _concatInstanceProperty(_context19 = "".concat(checkboxPrefixCls, "-")).call(_context19, mergedCheckboxType, "-inner-icon")
129
136
  })), /*#__PURE__*/React.createElement("input", {
130
137
  type: "checkbox",
131
138
  className: inputClassName,
@@ -133,8 +140,8 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
133
140
  ref: ref,
134
141
  value: value,
135
142
  checked: selected,
136
- disabled: disabled,
137
- name: name
143
+ disabled: mergedDisabled,
144
+ name: mergedName
138
145
  })), children && /*#__PURE__*/React.createElement("span", {
139
146
  className: "".concat(checkboxPrefixCls, "-children")
140
147
  }, children), !isDefaultType() && /*#__PURE__*/React.createElement("span", {
@@ -143,7 +150,7 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
143
150
  className: innerIconClassName
144
151
  }, /*#__PURE__*/React.createElement(Icon, {
145
152
  type: "right-bold",
146
- className: _concatInstanceProperty(_context20 = "".concat(checkboxPrefixCls, "-")).call(_context20, checkboxType, "-inner-icon")
153
+ className: _concatInstanceProperty(_context20 = "".concat(checkboxPrefixCls, "-")).call(_context20, mergedCheckboxType, "-inner-icon")
147
154
  }))))
148
155
  );
149
156
  };
@@ -3,10 +3,20 @@ export declare const CheckboxTypes: ["default", "square"];
3
3
  export declare type CheckboxType = typeof CheckboxTypes[number];
4
4
  export declare const CheckboxSizes: ["large", "middle", "small"];
5
5
  export declare type CheckboxSize = typeof CheckboxSizes[number];
6
+ export declare type CheckboxValueType = string | number;
7
+ export interface CheckboxGroupContext {
8
+ name?: string;
9
+ isControlled?: boolean;
10
+ groupValue?: Array<CheckboxValueType>;
11
+ checkboxType?: CheckboxType;
12
+ disabled?: boolean;
13
+ onCheckboxGroupChange?: (checkedValue: CheckboxValueType, isChecked: boolean) => void;
14
+ }
15
+ export declare const GroupContext: React.Context<CheckboxGroupContext | null>;
6
16
  export interface CheckboxGroupProps {
7
17
  name?: string;
8
18
  size?: CheckboxSize;
9
- value?: string[];
19
+ value?: Array<CheckboxValueType>;
10
20
  checkboxType?: CheckboxType;
11
21
  disabled?: boolean;
12
22
  defaultValue?: string[] | string;
@@ -1,7 +1,5 @@
1
- import _extends from "@babel/runtime-corejs3/helpers/extends";
2
1
  import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
3
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
4
- import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/splice";
2
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
5
3
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
6
4
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
7
5
  import React, { useContext } from 'react'; // import { Icon } from '../index'
@@ -11,12 +9,11 @@ import ConfigContext from '../config-provider/ConfigContext';
11
9
  import { getCompProps } from '../_utils';
12
10
  import { tuple } from '../_utils/type';
13
11
  import { isArrayValueRepeat } from '../_utils/arrayUtil';
14
- import isArray from 'lodash/isArray';
15
12
  import Checkbox from './checkbox';
16
- import isBoolean from 'lodash/isBoolean';
17
13
  import devWarning from '../_utils/devwarning';
18
14
  export var CheckboxTypes = tuple('default', 'square');
19
15
  export var CheckboxSizes = tuple('large', 'middle', 'small');
16
+ export var GroupContext = /*#__PURE__*/React.createContext(null);
20
17
  var CheckboxGroup = /*#__PURE__*/React.forwardRef(function (props, ref) {
21
18
  // const CheckboxGroup = (props: CheckboxGroupProps): FunctionComponentElement<CheckboxGroupProps> => {
22
19
  var _useContext = useContext(ConfigContext),
@@ -38,111 +35,86 @@ var CheckboxGroup = /*#__PURE__*/React.forwardRef(function (props, ref) {
38
35
  defaultValue = CheckboxProps.defaultValue,
39
36
  value = CheckboxProps.value,
40
37
  name = CheckboxProps.name;
38
+ var initData = value || (Array.isArray(defaultValue) ? defaultValue : typeof defaultValue !== 'undefined' ? [defaultValue] : []);
41
39
 
42
- var _React$useState = React.useState(defaultValue),
40
+ var _React$useState = React.useState([]),
43
41
  _React$useState2 = _slicedToArray(_React$useState, 2),
44
42
  groupValue = _React$useState2[0],
45
43
  setGroupValue = _React$useState2[1];
46
44
 
45
+ var innerValue = React.useRef(initData);
47
46
  React.useEffect(function () {
48
- if (value) {
49
- setGroupValue(value);
50
- }
51
- }, [value]);
47
+ innerValue.current = value || (Array.isArray(defaultValue) ? defaultValue : typeof defaultValue !== 'undefined' ? [defaultValue] : []);
48
+ setGroupValue(innerValue.current);
49
+ }, [value, defaultValue]);
50
+ var isControlled = typeof value !== 'undefined';
52
51
  var checkboxGroupPrefixCls = getPrefixCls(prefixCls, 'checkbox-group', customPrefixcls); // 按钮样式前缀
53
52
 
54
- devWarning(isArrayValueRepeat(value), 'checkboxGroup', "variable value's value should be unique ");
55
-
56
- var getDisabled = function getDisabled(optionDisabled) {
57
- return isBoolean(optionDisabled) ? optionDisabled : disabled;
58
- };
59
-
60
- var getChecked = function getChecked(props, value) {
61
- return isArray(value) ? _includesInstanceProperty(value).call(value, (props === null || props === void 0 ? void 0 : props.value) || props) || _includesInstanceProperty(value).call(value, String((props === null || props === void 0 ? void 0 : props.value) || props)) : String(value) === String((props === null || props === void 0 ? void 0 : props.value) || props);
62
- };
53
+ devWarning(isArrayValueRepeat(groupValue), 'checkboxGroup', "variable value's value should be unique ");
63
54
 
64
55
  var getReduceItem = function getReduceItem(targetValue) {
65
- var index = value.indexOf(targetValue);
66
-
67
- _spliceInstanceProperty(value).call(value, index, 1);
56
+ var _context;
68
57
 
69
- return value;
58
+ return _filterInstanceProperty(_context = innerValue.current).call(_context, function (d) {
59
+ return d !== targetValue;
60
+ });
70
61
  };
71
62
 
72
63
  var getAddItem = function getAddItem(targetValue) {
73
- return _concatInstanceProperty(value).call(value, targetValue);
74
- };
64
+ var _context2;
75
65
 
76
- var onCheckboxChange = function onCheckboxChange(ev, item) {
77
- var _a;
66
+ return innerValue.current.indexOf(targetValue) > -1 ? innerValue.current : _concatInstanceProperty(_context2 = innerValue.current).call(_context2, targetValue);
67
+ };
78
68
 
79
- var val = ev.target.value;
80
- var checked = ev.target.checked;
69
+ var onCheckboxChange = function onCheckboxChange(checkedValue, isChecked) {
81
70
  var newVal = [];
82
71
 
83
- if (checked) {
84
- newVal = getAddItem(val);
72
+ if (isChecked) {
73
+ newVal = getAddItem(checkedValue);
85
74
  } else {
86
- newVal = getReduceItem(val);
75
+ newVal = getReduceItem(checkedValue);
76
+ }
77
+
78
+ if (!isControlled) {
79
+ innerValue.current = newVal;
87
80
  }
88
81
 
89
- setGroupValue(newVal);
90
82
  onChange && onChange(newVal);
91
- ((_a = item.props) === null || _a === void 0 ? void 0 : _a.onChange) && item.props.onChange(ev);
83
+ };
84
+
85
+ var context = {
86
+ groupValue: groupValue,
87
+ disabled: disabled,
88
+ name: name,
89
+ isControlled: isControlled,
90
+ checkboxType: checkboxType,
91
+ onCheckboxGroupChange: function onCheckboxGroupChange(checkedValue, isChecked) {
92
+ onCheckboxChange(checkedValue, isChecked);
93
+ }
92
94
  };
93
95
 
94
96
  var renderByOptions = function renderByOptions() {
95
97
  return _mapInstanceProperty(options).call(options, function (option, index) {
96
98
  return /*#__PURE__*/React.createElement(Checkbox, {
97
99
  size: size,
98
- disabled: getDisabled(option.disabled),
100
+ disabled: option.disabled,
99
101
  key: index,
100
102
  name: name,
101
- defaultChecked: getChecked(option, defaultValue),
102
- checked: getChecked(option, groupValue),
103
+ defaultChecked: option.defaultValue,
104
+ checked: option.checked,
103
105
  checkboxType: checkboxType,
104
106
  value: (option === null || option === void 0 ? void 0 : option.value) || option,
105
- onChange: function onChange(e) {
106
- return onCheckboxChange(e, option);
107
- }
107
+ onChange: option.onChange
108
108
  }, option.label || option);
109
109
  });
110
110
  };
111
111
 
112
- var renderChildren = function renderChildren() {
113
- var _context;
114
-
115
- return _mapInstanceProperty(_context = React.Children).call(_context, children, function (item) {
116
- var _a, _b;
117
-
118
- var groupProps = {};
119
- groupProps = {
120
- name: name,
121
- size: size,
122
- onChange: function onChange(e) {
123
- return onCheckboxChange(e, item);
124
- },
125
- checkboxType: checkboxType || ((_a = item.props) === null || _a === void 0 ? void 0 : _a.checkboxType),
126
- disabled: isBoolean(disabled) ? disabled : (_b = item.props) === null || _b === void 0 ? void 0 : _b.disabled,
127
- checked: getChecked(item.props, groupValue),
128
- defaultChecked: getChecked(item.props, defaultValue)
129
- };
130
- return /*#__PURE__*/React.cloneElement(item, _extends(_extends({}, item.props), groupProps));
131
- });
132
- };
133
-
134
- var renderCheckbox = function renderCheckbox() {
135
- if (isArray(options)) {
136
- return renderByOptions();
137
- } else if (children) {
138
- return renderChildren();
139
- }
140
- };
141
-
142
112
  return /*#__PURE__*/React.createElement("ul", {
143
113
  className: classnames(checkboxGroupPrefixCls, className),
144
114
  style: style,
145
115
  ref: ref
146
- }, renderCheckbox());
116
+ }, /*#__PURE__*/React.createElement(GroupContext.Provider, {
117
+ value: context
118
+ }, options && options.length > 0 ? renderByOptions() : children));
147
119
  });
148
120
  export default /*#__PURE__*/React.memo(CheckboxGroup);
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckboxProps } from './checkbox';
3
3
  import Group from './group';
4
- export { CheckboxProps, CheckboxSizes, CheckboxTypes } from './checkbox';
4
+ export { CheckboxSizes, CheckboxTypes, CheckboxSize, CheckboxType, CheckboxValueType } from './group';
5
5
  export { CheckboxGroupProps } from './group';
6
+ export { CheckboxProps } from './checkbox';
6
7
  interface CompoundedComponent extends React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLElement>> {
7
8
  Group: typeof Group;
8
9
  }
@@ -1,6 +1,6 @@
1
1
  import InternalCheckbox from './checkbox';
2
2
  import Group from './group';
3
- export { CheckboxSizes, CheckboxTypes } from './checkbox';
3
+ export { CheckboxSizes, CheckboxTypes } from './group';
4
4
  var Checkbox = InternalCheckbox;
5
5
  Checkbox.Group = Group;
6
6
  export { Group };
@@ -104,6 +104,8 @@
104
104
  .kd-inputNumber {
105
105
  width: 100px;
106
106
  height: var(--kd-c-stepper-input-middle-sizing-height, 28px);
107
+ --kd-c-input-wrapper-padding-left: 9px;
108
+ --kd-c-input-padding-left: 0;
107
109
  }
108
110
  .kd-inputNumber input {
109
111
  text-align: center;
@@ -2,10 +2,13 @@
2
2
  @import './mixin.less';
3
3
 
4
4
  @inputNumber-prefix-cls: ~'@{kd-prefix}-inputNumber';
5
+ @inputWrapper-prefix-cls: ~'@{kd-prefix}-wrapper';
5
6
  .@{inputNumber-prefix-cls} {
6
7
  width: 100px;
7
8
  height: @stepper-input-middle-sizing-height;
8
9
 
10
+ --kd-c-input-wrapper-padding-left: 9px;
11
+ --kd-c-input-padding-left: 0;
9
12
  input {
10
13
  text-align: center;
11
14
  color: @stepper-input-color;
@@ -590,10 +590,12 @@ function usePopper(locatorElement, popperElement, props) {
590
590
  focus: 'mousedown',
591
591
  contextMenu: 'mousedown'
592
592
  };
593
+ popperNode === null || popperNode === void 0 ? void 0 : popperNode.addEventListener('mouseleave', debounceHidePopper);
593
594
  Array.isArray(trigger) ? trigger.forEach(function (action) {
594
595
  return document.addEventListener(mapEvent[action], debounceHidePopper);
595
596
  }) : document.addEventListener(mapEvent[trigger], debounceHidePopper);
596
597
  return function () {
598
+ popperNode === null || popperNode === void 0 ? void 0 : popperNode.removeEventListener('mouseleave', debounceHidePopper);
597
599
  Array.isArray(trigger) ? trigger.forEach(function (action) {
598
600
  return document.removeEventListener(mapEvent[action], debounceHidePopper);
599
601
  }) : document.removeEventListener(mapEvent[trigger], debounceHidePopper);
@@ -1,8 +1,5 @@
1
1
  import React from 'react';
2
- export declare const CheckboxTypes: ["default", "square"];
3
- export declare type CheckboxType = typeof CheckboxTypes[number];
4
- export declare const CheckboxSizes: ["large", "middle", "small"];
5
- export declare type CheckboxSize = typeof CheckboxSizes[number];
2
+ import type { CheckboxType, CheckboxSize } from './group';
6
3
  export interface CheckboxProps {
7
4
  checked?: boolean;
8
5
  defaultChecked?: boolean;
@@ -11,7 +11,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
11
11
  Object.defineProperty(exports, "__esModule", {
12
12
  value: true
13
13
  });
14
- exports.default = exports.CheckboxTypes = exports.CheckboxSizes = void 0;
14
+ exports.default = void 0;
15
15
 
16
16
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
17
17
 
@@ -27,12 +27,12 @@ var _react = _interopRequireWildcard(require("react"));
27
27
 
28
28
  var _classnames = _interopRequireDefault(require("classnames"));
29
29
 
30
+ var _group = require("./group");
31
+
30
32
  var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));
31
33
 
32
34
  var _utils = require("../_utils");
33
35
 
34
- var _type = require("../_utils/type");
35
-
36
36
  var _isBoolean = _interopRequireDefault(require("lodash/isBoolean"));
37
37
 
38
38
  var _icon = _interopRequireDefault(require("../icon"));
@@ -56,11 +56,6 @@ var __rest = void 0 && (void 0).__rest || function (s, e) {
56
56
  return t;
57
57
  };
58
58
 
59
- var CheckboxTypes = (0, _type.tuple)('default', 'square');
60
- exports.CheckboxTypes = CheckboxTypes;
61
- var CheckboxSizes = (0, _type.tuple)('large', 'middle', 'small');
62
- exports.CheckboxSizes = CheckboxSizes;
63
-
64
59
  var InternalCheckbox = function InternalCheckbox(props, ref) {
65
60
  var _context, _context2, _context3, _classNames, _context4, _context5, _context6, _classNames2, _context7, _context8, _context9, _context10, _context11, _context12, _context13, _context14, _classNames4, _context15, _context16, _context17, _classNames5, _context18;
66
61
 
@@ -86,38 +81,50 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
86
81
  name = CheckboxProps.name,
87
82
  rest = __rest(CheckboxProps, ["checkboxType", "className", "prefixCls", "defaultChecked", "checked", "size", "onChange", "disabled", "children", "style", "value", "indeterminate", "name"]);
88
83
 
89
- var getChecked = function getChecked() {
90
- return (0, _isBoolean.default)(checked) ? checked : defaultChecked;
91
- };
84
+ var checkboxGroup = _react.default.useContext(_group.GroupContext);
92
85
 
93
- var _useState = (0, _react.useState)(getChecked()),
86
+ var mergedDisabled = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.disabled) || disabled;
87
+ var mergedCheckboxType = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.checkboxType) || checkboxType;
88
+ var mergedName = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.name) || name;
89
+ var initChecked = (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue) ? (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue.indexOf(value)) > -1 : (0, _isBoolean.default)(checked) ? checked : defaultChecked;
90
+
91
+ var _useState = (0, _react.useState)(initChecked),
94
92
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
95
93
  selected = _useState2[0],
96
94
  setSelected = _useState2[1];
97
95
 
98
96
  var labelRef = (0, _react.useRef)(null);
99
- (0, _devwarning.default)(CheckboxTypes.indexOf(checkboxType) === -1, 'checkbox', "cannot found checkbox type '".concat(checkboxType, "'"));
100
- (0, _devwarning.default)(CheckboxSizes.indexOf(size) === -1, 'checkbox', "cannot found size type '".concat(size, "'"));
97
+
98
+ _react.default.useEffect(function () {
99
+ setSelected((checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue) ? (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue.indexOf(value)) > -1 : (0, _isBoolean.default)(checked) ? checked : defaultChecked);
100
+ }, [checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.groupValue, checked, defaultChecked]);
101
+
102
+ (0, _devwarning.default)(_group.CheckboxTypes.indexOf(mergedCheckboxType) === -1, 'checkbox', "cannot found checkbox type '".concat(mergedCheckboxType, "'"));
103
+ (0, _devwarning.default)(_group.CheckboxSizes.indexOf(size) === -1, 'checkbox', "cannot found size type '".concat(size, "'"));
101
104
  var checkboxPrefixCls = getPrefixCls(prefixCls, 'checkbox', customPrefixcls);
102
105
 
103
106
  var isDefaultType = function isDefaultType() {
104
- return checkboxType === 'default';
107
+ return mergedCheckboxType === 'default';
105
108
  };
106
109
 
107
110
  var getIndeterminate = function getIndeterminate() {
108
111
  return selected ? false : indeterminate;
109
112
  };
110
113
 
111
- var getDefaultClassName = (0, _classnames.default)(className, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(checkboxPrefixCls), true), (0, _defineProperty2.default)(_classNames, "".concat(checkboxPrefixCls, "-no-child"), !children), (0, _defineProperty2.default)(_classNames, (0, _concat.default)(_context = "".concat(checkboxPrefixCls, "-")).call(_context, size), true && !!children), (0, _defineProperty2.default)(_classNames, (0, _concat.default)(_context2 = "".concat(checkboxPrefixCls, "-")).call(_context2, checkboxType), true), (0, _defineProperty2.default)(_classNames, (0, _concat.default)(_context3 = "".concat(checkboxPrefixCls, "-")).call(_context3, checkboxType, "-disabled"), disabled), (0, _defineProperty2.default)(_classNames, "checked", selected), _classNames));
112
- var getSquareClassName = (0, _classnames.default)(className, (_classNames2 = {}, (0, _defineProperty2.default)(_classNames2, "".concat(checkboxPrefixCls), true), (0, _defineProperty2.default)(_classNames2, (0, _concat.default)(_context4 = "".concat(checkboxPrefixCls, "-")).call(_context4, checkboxType), true), (0, _defineProperty2.default)(_classNames2, (0, _concat.default)(_context5 = "".concat(checkboxPrefixCls, "-")).call(_context5, checkboxType, "-disabled"), disabled), (0, _defineProperty2.default)(_classNames2, (0, _concat.default)(_context6 = "".concat(checkboxPrefixCls, "-")).call(_context6, checkboxType, "-checked"), selected && !disabled), (0, _defineProperty2.default)(_classNames2, "checked", selected), _classNames2));
114
+ var getDefaultClassName = (0, _classnames.default)(className, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(checkboxPrefixCls), true), (0, _defineProperty2.default)(_classNames, "".concat(checkboxPrefixCls, "-no-child"), !children), (0, _defineProperty2.default)(_classNames, (0, _concat.default)(_context = "".concat(checkboxPrefixCls, "-")).call(_context, size), true && !!children), (0, _defineProperty2.default)(_classNames, (0, _concat.default)(_context2 = "".concat(checkboxPrefixCls, "-")).call(_context2, mergedCheckboxType), true), (0, _defineProperty2.default)(_classNames, (0, _concat.default)(_context3 = "".concat(checkboxPrefixCls, "-")).call(_context3, mergedCheckboxType, "-disabled"), mergedDisabled), (0, _defineProperty2.default)(_classNames, "checked", selected), _classNames));
115
+ var getSquareClassName = (0, _classnames.default)(className, (_classNames2 = {}, (0, _defineProperty2.default)(_classNames2, "".concat(checkboxPrefixCls), true), (0, _defineProperty2.default)(_classNames2, (0, _concat.default)(_context4 = "".concat(checkboxPrefixCls, "-")).call(_context4, mergedCheckboxType), true), (0, _defineProperty2.default)(_classNames2, (0, _concat.default)(_context5 = "".concat(checkboxPrefixCls, "-")).call(_context5, mergedCheckboxType, "-disabled"), mergedDisabled), (0, _defineProperty2.default)(_classNames2, (0, _concat.default)(_context6 = "".concat(checkboxPrefixCls, "-")).call(_context6, mergedCheckboxType, "-checked"), selected && !mergedDisabled), (0, _defineProperty2.default)(_classNames2, "checked", selected), _classNames2));
113
116
  var getRootClassName = isDefaultType() ? getDefaultClassName : getSquareClassName;
114
117
  var inputClassName = (0, _classnames.default)((0, _defineProperty2.default)({}, "".concat(checkboxPrefixCls, "-input"), true));
115
- var checkedWrapperClassName = (0, _classnames.default)((_classNames4 = {}, (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context7 = "".concat(checkboxPrefixCls, "-")).call(_context7, checkboxType, "-no-child"), !children), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context8 = "".concat(checkboxPrefixCls, "-")).call(_context8, checkboxType, "-wrapper"), true), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context9 = "".concat(checkboxPrefixCls, "-")).call(_context9, checkboxType, "-wrapper-size"), !!children), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context10 = "".concat(checkboxPrefixCls, "-")).call(_context10, checkboxType, "-margin"), !!children), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context11 = "".concat(checkboxPrefixCls, "-")).call(_context11, checkboxType, "-checked"), selected), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context12 = "".concat(checkboxPrefixCls, "-")).call(_context12, checkboxType, "-indeterminate"), getIndeterminate()), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context13 = "".concat(checkboxPrefixCls, "-")).call(_context13, checkboxType, "-disabled"), disabled && !selected), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context14 = "".concat(checkboxPrefixCls, "-")).call(_context14, checkboxType, "-checked-disabled"), disabled && selected), _classNames4));
116
- var triangleClassName = (0, _classnames.default)((_classNames5 = {}, (0, _defineProperty2.default)(_classNames5, (0, _concat.default)(_context15 = "".concat(checkboxPrefixCls, "-")).call(_context15, checkboxType, "-triangle"), !selected), (0, _defineProperty2.default)(_classNames5, (0, _concat.default)(_context16 = "".concat(checkboxPrefixCls, "-")).call(_context16, checkboxType, "-triangle-checked"), selected), (0, _defineProperty2.default)(_classNames5, (0, _concat.default)(_context17 = "".concat(checkboxPrefixCls, "-")).call(_context17, checkboxType, "-triangle-disabled"), disabled), _classNames5));
117
- var innerIconClassName = (0, _classnames.default)((0, _defineProperty2.default)({}, (0, _concat.default)(_context18 = "".concat(checkboxPrefixCls, "-")).call(_context18, checkboxType, "-inner"), true));
118
+ var checkedWrapperClassName = (0, _classnames.default)((_classNames4 = {}, (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context7 = "".concat(checkboxPrefixCls, "-")).call(_context7, mergedCheckboxType, "-no-child"), !children), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context8 = "".concat(checkboxPrefixCls, "-")).call(_context8, mergedCheckboxType, "-wrapper"), true), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context9 = "".concat(checkboxPrefixCls, "-")).call(_context9, mergedCheckboxType, "-wrapper-size"), !!children), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context10 = "".concat(checkboxPrefixCls, "-")).call(_context10, mergedCheckboxType, "-margin"), !!children), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context11 = "".concat(checkboxPrefixCls, "-")).call(_context11, mergedCheckboxType, "-checked"), selected), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context12 = "".concat(checkboxPrefixCls, "-")).call(_context12, mergedCheckboxType, "-indeterminate"), getIndeterminate()), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context13 = "".concat(checkboxPrefixCls, "-")).call(_context13, mergedCheckboxType, "-disabled"), mergedDisabled && !selected), (0, _defineProperty2.default)(_classNames4, (0, _concat.default)(_context14 = "".concat(checkboxPrefixCls, "-")).call(_context14, mergedCheckboxType, "-checked-disabled"), mergedDisabled && selected), _classNames4));
119
+ var triangleClassName = (0, _classnames.default)((_classNames5 = {}, (0, _defineProperty2.default)(_classNames5, (0, _concat.default)(_context15 = "".concat(checkboxPrefixCls, "-")).call(_context15, mergedCheckboxType, "-triangle"), !selected), (0, _defineProperty2.default)(_classNames5, (0, _concat.default)(_context16 = "".concat(checkboxPrefixCls, "-")).call(_context16, mergedCheckboxType, "-triangle-checked"), selected), (0, _defineProperty2.default)(_classNames5, (0, _concat.default)(_context17 = "".concat(checkboxPrefixCls, "-")).call(_context17, mergedCheckboxType, "-triangle-disabled"), mergedDisabled), _classNames5));
120
+ var innerIconClassName = (0, _classnames.default)((0, _defineProperty2.default)({}, (0, _concat.default)(_context18 = "".concat(checkboxPrefixCls, "-")).call(_context18, mergedCheckboxType, "-inner"), true));
118
121
  var handleChange = (0, _react.useCallback)(function (e) {
119
122
  onChange && onChange(e);
120
- setSelected(e.target.checked);
123
+ (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.onCheckboxGroupChange) && (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.onCheckboxGroupChange(value, e.target.checked));
124
+
125
+ if (!(checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.isControlled)) {
126
+ setSelected(e.target.checked);
127
+ }
121
128
  }, [onChange]);
122
129
  (0, _react.useEffect)(function () {
123
130
  (0, _isBoolean.default)(checked) && checked !== selected && setSelected(checked);
@@ -158,7 +165,7 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
158
165
  className: innerIconClassName
159
166
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
160
167
  type: "right-bold",
161
- className: (0, _concat.default)(_context19 = "".concat(checkboxPrefixCls, "-")).call(_context19, checkboxType, "-inner-icon")
168
+ className: (0, _concat.default)(_context19 = "".concat(checkboxPrefixCls, "-")).call(_context19, mergedCheckboxType, "-inner-icon")
162
169
  })), /*#__PURE__*/_react.default.createElement("input", {
163
170
  type: "checkbox",
164
171
  className: inputClassName,
@@ -166,8 +173,8 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
166
173
  ref: ref,
167
174
  value: value,
168
175
  checked: selected,
169
- disabled: disabled,
170
- name: name
176
+ disabled: mergedDisabled,
177
+ name: mergedName
171
178
  })), children && /*#__PURE__*/_react.default.createElement("span", {
172
179
  className: "".concat(checkboxPrefixCls, "-children")
173
180
  }, children), !isDefaultType() && /*#__PURE__*/_react.default.createElement("span", {
@@ -176,7 +183,7 @@ var InternalCheckbox = function InternalCheckbox(props, ref) {
176
183
  className: innerIconClassName
177
184
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
178
185
  type: "right-bold",
179
- className: (0, _concat.default)(_context20 = "".concat(checkboxPrefixCls, "-")).call(_context20, checkboxType, "-inner-icon")
186
+ className: (0, _concat.default)(_context20 = "".concat(checkboxPrefixCls, "-")).call(_context20, mergedCheckboxType, "-inner-icon")
180
187
  }))))
181
188
  );
182
189
  };
@@ -3,10 +3,20 @@ export declare const CheckboxTypes: ["default", "square"];
3
3
  export declare type CheckboxType = typeof CheckboxTypes[number];
4
4
  export declare const CheckboxSizes: ["large", "middle", "small"];
5
5
  export declare type CheckboxSize = typeof CheckboxSizes[number];
6
+ export declare type CheckboxValueType = string | number;
7
+ export interface CheckboxGroupContext {
8
+ name?: string;
9
+ isControlled?: boolean;
10
+ groupValue?: Array<CheckboxValueType>;
11
+ checkboxType?: CheckboxType;
12
+ disabled?: boolean;
13
+ onCheckboxGroupChange?: (checkedValue: CheckboxValueType, isChecked: boolean) => void;
14
+ }
15
+ export declare const GroupContext: React.Context<CheckboxGroupContext | null>;
6
16
  export interface CheckboxGroupProps {
7
17
  name?: string;
8
18
  size?: CheckboxSize;
9
- value?: string[];
19
+ value?: Array<CheckboxValueType>;
10
20
  checkboxType?: CheckboxType;
11
21
  disabled?: boolean;
12
22
  defaultValue?: string[] | string;