@kdcloudjs/kdesign 1.7.9 → 1.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -110,6 +110,7 @@ var CityPanel = function CityPanel(_ref) {
110
110
  if (commons && currentGroup === cityPickerLang.common) {
111
111
  setList([commons[activedIndex] || []]);
112
112
  setGroupKeys(null);
113
+ setActivedGroupIndex(index);
113
114
  return;
114
115
  }
115
116
  var currentGroups = (currentGroup || '').split('');
@@ -296,6 +296,7 @@
296
296
  margin-top: 10px;
297
297
  max-height: calc(100% - 39px - 10px);
298
298
  overflow: scroll;
299
+ height: 100%;
299
300
  }
300
301
  .kd-city-picker-city-table .kd-city-picker-city-table-group {
301
302
  display: -webkit-box;
@@ -177,6 +177,7 @@
177
177
  margin-top: 10px;
178
178
  max-height: ~'calc(100% - 39px - 10px)';
179
179
  overflow: scroll;
180
+ height: 100%;
180
181
 
181
182
  .@{city-picker-prefix-cls}-city-table-group {
182
183
  display: flex;
@@ -2,8 +2,8 @@ import React from 'react';
2
2
  import { PanelProps } from './panel';
3
3
  export declare const IconPositionTypes: ["left", "right"];
4
4
  export declare type IconPositionType = typeof IconPositionTypes[number];
5
- export declare type keyType = string[] | string | number[] | number | NONE_KEY_TYPE;
6
- export declare type NONE_KEY_TYPE = undefined;
5
+ export declare type PanelKeyType = string | number;
6
+ export declare type keyType = string[] | string | number[] | number | undefined;
7
7
  export interface CollapseProps {
8
8
  accordion?: boolean;
9
9
  activeKey?: keyType;
@@ -6,16 +6,13 @@ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/ins
6
6
  import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
7
7
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
8
8
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
9
- import React from 'react';
9
+ import React, { useEffect, useState } from 'react';
10
10
  import ConfigContext from '../config-provider/ConfigContext';
11
11
  import { getCompProps } from '../_utils';
12
12
  import classNames from 'classnames';
13
13
  import { tuple } from '../_utils/type';
14
- import isArray from 'lodash/isArray';
15
- import isBoolean from 'lodash/isBoolean';
16
14
  import devwarning from '../_utils/devwarning';
17
15
  export var IconPositionTypes = tuple('left', 'right');
18
- var NONE_KEY = undefined;
19
16
  var InternalCollapse = /*#__PURE__*/React.forwardRef(function (props, ref) {
20
17
  var _React$useContext = React.useContext(ConfigContext),
21
18
  getPrefixCls = _React$useContext.getPrefixCls,
@@ -34,91 +31,69 @@ var InternalCollapse = /*#__PURE__*/React.forwardRef(function (props, ref) {
34
31
  children = _getCompProps.children,
35
32
  customPrefixcls = _getCompProps.prefixCls;
36
33
  var CollapsePrefixCls = getPrefixCls(prefixCls, 'collapse', customPrefixcls); // 样式前缀
37
- var getDefaultActivePanelKey = function getDefaultActivePanelKey() {
38
- // const _defaultActiveKey =
39
- // defaultActiveKey !== NONE_KEY
40
- // ? defaultActiveKey
41
- // : React.Children.map(children, (item, index) => {
42
- // if (index === 0) return item.props?.panelKey
43
- // })
44
- // return isBoolean(activeKey) ? activeKey : _defaultActiveKey
45
- return isBoolean(activeKey) ? activeKey : defaultActiveKey;
46
- };
47
- var _React$useState = React.useState(getDefaultActivePanelKey()),
48
- _React$useState2 = _slicedToArray(_React$useState, 2),
49
- activePanelKey = _React$useState2[0],
50
- setActivePanelKey = _React$useState2[1];
51
- var getPanelExpand = function getPanelExpand(panelKey, accordion, activeKey) {
52
- var _activeKey = getActiveKey(accordion, activeKey);
53
- return isInclude(_activeKey, panelKey);
54
- };
55
- var getActiveKey = function getActiveKey(accordion, activeKey) {
56
- var _activeKey = activeKey;
57
- if (accordion) {
58
- if (isArray(activeKey)) {
59
- _activeKey = activeKey[0]; // accordion 模式下默认第一个元素
60
- }
34
+ var _useState = useState([]),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ innerKey = _useState2[0],
37
+ setInnerKey = _useState2[1];
38
+ var convertActiveKey = function convertActiveKey(newKey) {
39
+ var ret = [];
40
+ if (Array.isArray(newKey)) {
41
+ ret = newKey;
42
+ } else if (typeof newKey === 'string' || typeof newKey === 'number') {
43
+ ret = [newKey];
61
44
  }
62
-
63
- return _activeKey;
64
- };
65
- var isInclude = function isInclude(activePanelKey, key) {
66
- if (isArray(activePanelKey)) {
67
- return _includesInstanceProperty(activePanelKey).call(activePanelKey, key) || _includesInstanceProperty(activePanelKey).call(activePanelKey, String(key));
68
- } else {
69
- return String(activePanelKey) === String(key);
45
+ if (accordion && ret.length) {
46
+ ret = [ret[0]];
70
47
  }
48
+ return ret;
71
49
  };
72
- var getRemoveKey = function getRemoveKey(key) {
73
- if (isArray(activePanelKey)) {
74
- return _filterInstanceProperty(activePanelKey).call(activePanelKey, function (element) {
75
- return element !== key;
76
- });
50
+ useEffect(function () {
51
+ if (typeof activeKey !== 'undefined') {
52
+ setInnerKey(convertActiveKey(activeKey));
77
53
  }
78
- return NONE_KEY;
79
- };
80
- var getAddKey = function getAddKey(key) {
81
- if (isArray(activePanelKey)) {
82
- var _context;
83
- return _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(activePanelKey), [key]);
54
+ }, [activeKey]);
55
+ useEffect(function () {
56
+ if (typeof activeKey !== 'undefined' || typeof defaultActiveKey !== 'undefined') {
57
+ setInnerKey(convertActiveKey(typeof activeKey !== 'undefined' ? activeKey : defaultActiveKey));
84
58
  }
85
- return activePanelKey ? [activePanelKey, key] : key;
86
- };
87
- var getNewActiveKey = function getNewActiveKey(key) {
88
- if (isInclude(activePanelKey, key)) {
89
- if (accordion) {
90
- return NONE_KEY;
59
+ }, []);
60
+ var onPanelChange = function onPanelChange(key) {
61
+ var newKey = [];
62
+ if (accordion) {
63
+ if (_includesInstanceProperty(innerKey).call(innerKey, key)) {
64
+ newKey = [];
65
+ } else {
66
+ newKey = [key];
91
67
  }
92
- return getRemoveKey(key);
93
68
  } else {
94
- if (accordion) {
95
- return key;
69
+ if (_includesInstanceProperty(innerKey).call(innerKey, key)) {
70
+ newKey = _filterInstanceProperty(innerKey).call(innerKey, function (d) {
71
+ return d !== key;
72
+ });
73
+ } else {
74
+ var _context;
75
+ newKey = _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(innerKey), [key]);
96
76
  }
97
- return getAddKey(key);
98
77
  }
78
+ if (typeof activeKey === 'undefined') {
79
+ setInnerKey(newKey);
80
+ }
81
+ onChange && onChange(newKey);
99
82
  };
100
- var onPanelChange = React.useCallback(function (key) {
101
- key = getNewActiveKey(key);
102
- setActivePanelKey(key);
103
- onChange && onChange();
104
- }, [onChange, activePanelKey, accordion]);
105
83
  var renderPanel = function renderPanel() {
106
84
  var _context2;
107
85
  return _mapInstanceProperty(_context2 = React.Children).call(_context2, children, function (item) {
108
- var _a, _b, _c;
86
+ var _a;
109
87
  if (((_a = item === null || item === void 0 ? void 0 : item.type) === null || _a === void 0 ? void 0 : _a.displayName) !== 'Panel') {
110
88
  devwarning(true, 'Collapse', 'children必须为Collapse.Panel');
111
89
  return item;
112
90
  }
113
- var expand = getPanelExpand((_b = item.props) === null || _b === void 0 ? void 0 : _b.panelKey, accordion, activePanelKey);
114
- var defaultExpand = getPanelExpand((_c = item.props) === null || _c === void 0 ? void 0 : _c.panelKey, accordion, defaultActiveKey);
115
91
  return /*#__PURE__*/React.cloneElement(item, _extends({
116
92
  expandIcon: expandIcon,
117
93
  expandIconPosition: expandIconPosition,
118
94
  onChange: onPanelChange,
119
95
  bordered: bordered,
120
- expand: expand,
121
- defaultExpand: defaultExpand
96
+ innerKey: innerKey
122
97
  }, item.props));
123
98
  });
124
99
  };
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
- import { IconPositionType, keyType } from './collapse';
2
+ import { IconPositionType, PanelKeyType } from './collapse';
3
3
  export interface PanelProps {
4
4
  disabled?: boolean;
5
5
  header?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
6
6
  expandIcon?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
7
7
  bordered?: boolean;
8
8
  expandIconPosition?: IconPositionType;
9
- onChange?: (key: keyType) => void;
9
+ onChange?: (key: PanelKeyType) => void;
10
10
  extra?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
11
11
  assist?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
12
12
  expand?: boolean;
13
13
  defaultExpand?: boolean;
14
14
  children?: React.ReactNode;
15
- panelKey?: any;
15
+ panelKey?: PanelKeyType;
16
16
  style?: React.CSSProperties;
17
17
  className?: string;
18
18
  }
@@ -1,11 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
3
- import React, { useRef, useState } from 'react';
3
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
4
+ import React, { useEffect, useRef, useState } from 'react';
4
5
  import classNames from 'classnames';
5
6
  import ConfigContext from '../config-provider/ConfigContext';
6
7
  import { getCompProps } from '../_utils';
7
8
  import Icon from '../icon';
8
- import isBoolean from 'lodash/isBoolean';
9
9
  var Panel = /*#__PURE__*/React.forwardRef(function (props, ref) {
10
10
  var _classNames6, _classNames7, _classNames8;
11
11
  var _React$useContext = React.useContext(ConfigContext),
@@ -19,8 +19,7 @@ var Panel = /*#__PURE__*/React.forwardRef(function (props, ref) {
19
19
  header = _getCompProps.header,
20
20
  onChange = _getCompProps.onChange,
21
21
  panelKey = _getCompProps.panelKey,
22
- defaultExpand = _getCompProps.defaultExpand,
23
- expand = _getCompProps.expand,
22
+ innerKey = _getCompProps.innerKey,
24
23
  bordered = _getCompProps.bordered,
25
24
  expandIcon = _getCompProps.expandIcon,
26
25
  expandIconPosition = _getCompProps.expandIconPosition,
@@ -36,17 +35,24 @@ var Panel = /*#__PURE__*/React.forwardRef(function (props, ref) {
36
35
  _useState2 = _slicedToArray(_useState, 2),
37
36
  expandAnimation = _useState2[0],
38
37
  setExpandAnimation = _useState2[1];
39
- var getExpand = function getExpand() {
40
- return isBoolean(expand) ? expand : defaultExpand;
41
- };
38
+ var _useState3 = useState(false),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ expand = _useState4[0],
41
+ setExpand = _useState4[1];
42
+ useEffect(function () {
43
+ var newValue = _includesInstanceProperty(innerKey).call(innerKey, panelKey);
44
+ if (newValue !== expand) {
45
+ setExpand(newValue);
46
+ setExpandAnimation(true);
47
+ }
48
+ }, [innerKey]);
42
49
  var handleClick = function handleClick() {
43
50
  if (disabled) return;
44
- setExpandAnimation(true);
45
51
  onChange && onChange(panelKey);
46
52
  };
47
53
  var renderIcon = function renderIcon() {
48
54
  var _classNames;
49
- var iconClassName = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(panelPrefixCls, "-icon"), true), _defineProperty(_classNames, "".concat(panelPrefixCls, "-animation-expand"), !getExpand()), _defineProperty(_classNames, "".concat(panelPrefixCls, "-animation-collapse"), getExpand()), _defineProperty(_classNames, "".concat(panelPrefixCls, "-disabled"), disabled), _classNames));
55
+ var iconClassName = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(panelPrefixCls, "-icon"), true), _defineProperty(_classNames, "".concat(panelPrefixCls, "-animation-expand"), !expand), _defineProperty(_classNames, "".concat(panelPrefixCls, "-animation-collapse"), expand), _defineProperty(_classNames, "".concat(panelPrefixCls, "-disabled"), disabled), _classNames));
50
56
  return /*#__PURE__*/React.createElement("span", {
51
57
  className: iconClassName,
52
58
  onClick: handleClick
@@ -52,6 +52,7 @@ var ClearableInput = function ClearableInput(props) {
52
52
  var needClear = !disabled && value && isMouseEnter;
53
53
  var clearIconclasses = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-textarea-clear-icon"), inputType === ClearableInputType[1]), _defineProperty(_classNames, "".concat(prefixCls, "-clear-icon"), inputType === ClearableInputType[0]), _defineProperty(_classNames, "".concat(prefixCls, "-clear-icon-hidden"), !needClear), _defineProperty(_classNames, "".concat(prefixCls, "-clear-icon-rightSpace"), suffix), _classNames));
54
54
  return /*#__PURE__*/React.createElement("span", {
55
+ onMouseDown: mouseDownHandle,
55
56
  onClick: handleReset,
56
57
  className: clearIconclasses
57
58
  }, typeof allowClear === 'boolean' ? /*#__PURE__*/React.createElement(Icon, {
@@ -286,10 +286,14 @@
286
286
  .kd-pagination .kd-pagination-selector .kd-pagination-selector-size {
287
287
  -webkit-box-sizing: border-box;
288
288
  box-sizing: border-box;
289
- display: inline-block;
289
+ display: -webkit-inline-box;
290
+ display: -ms-inline-flexbox;
291
+ display: inline-flex;
292
+ -webkit-box-align: center;
293
+ -ms-flex-align: center;
294
+ align-items: center;
290
295
  padding: 0;
291
296
  line-height: var(--kd-c-pagination-sizing-square, 24px);
292
- font-size: var(--kd-c-pagination-font-size, var(--kd-g-font-size-small, 12px));
293
297
  color: var(--kd-g-color-text-primary, #212121);
294
298
  border-radius: var(--kd-g-radius-border, 2px);
295
299
  background: var(--kd-g-color-background, #fff);
@@ -790,10 +794,12 @@
790
794
  right: 5px;
791
795
  line-height: calc(var(--kd-c-pagination-sizing-square, 24px) - 2px);
792
796
  font-size: var(--kd-c-pagination-icon-font-size, var(--kd-g-font-size-large, 16px));
793
- color: var(--kd-c-pagination-color-text-hover, var(--kd-g-color-theme, #5582f3));
794
797
  -webkit-transform: translateY(-50%);
795
798
  transform: translateY(-50%);
796
799
  }
800
+ .kd-pagination.nicety .kd-pagination-options .kd-pagination-options-size:hover i {
801
+ color: var(--kd-c-pagination-color-text-hover, var(--kd-g-color-theme, #5582f3));
802
+ }
797
803
  .kd-pagination.nicety .kd-pagination-options .kd-pagination-options-size.kd-pagination-options-dropdown-open i {
798
804
  -webkit-transform: rotate(180deg) translateY(50%);
799
805
  transform: rotate(180deg) translateY(50%);
@@ -144,10 +144,10 @@
144
144
 
145
145
  .@{pagination-selector-prefix-cls}-size {
146
146
  box-sizing: border-box;
147
- display: inline-block;
147
+ display: inline-flex;
148
+ align-items: center;
148
149
  padding: 0;
149
150
  line-height: @pagination-size;
150
- font-size: @pagination-font-size;
151
151
  color: @color-text-primary;
152
152
  border-radius: @radius-border;
153
153
  background: @color-background;
@@ -586,10 +586,15 @@
586
586
  right: 5px;
587
587
  line-height: calc(@pagination-size - 2px);
588
588
  font-size: @pagination-icon-size;
589
- color: @pagination-hover-color;
590
589
  transform: translateY(-50%);
591
590
  }
592
591
 
592
+ &:hover {
593
+ i {
594
+ color: @pagination-hover-color;
595
+ }
596
+ }
597
+
593
598
  &.@{pagination-prefix-cls}-options-dropdown-open {
594
599
  i {
595
600
  transform: rotate(180deg) translateY(50%);
@@ -230,7 +230,6 @@
230
230
  box-sizing: border-box;
231
231
  padding: 4px 0;
232
232
  margin: 0;
233
- overflow: auto;
234
233
  font-size: var(--kd-c-tree-select-dropdown-font-size, 12px);
235
234
  font-variant: initial;
236
235
  background-color: var(--kd-c-tree-select-dropdown-color-background, var(--kd-g-color-background, #fff));
@@ -128,7 +128,6 @@
128
128
  box-sizing: border-box;
129
129
  padding: 4px 0;
130
130
  margin: 0;
131
- overflow: auto;
132
131
  font-size: @tree-select-list-font-size;
133
132
  font-variant: initial;
134
133
  background-color: @tree-select-dropdown-bg;
@@ -122,6 +122,7 @@ var CityPanel = function CityPanel(_ref) {
122
122
  if (commons && currentGroup === cityPickerLang.common) {
123
123
  setList([commons[activedIndex] || []]);
124
124
  setGroupKeys(null);
125
+ setActivedGroupIndex(index);
125
126
  return;
126
127
  }
127
128
  var currentGroups = (currentGroup || '').split('');
@@ -296,6 +296,7 @@
296
296
  margin-top: 10px;
297
297
  max-height: calc(100% - 39px - 10px);
298
298
  overflow: scroll;
299
+ height: 100%;
299
300
  }
300
301
  .kd-city-picker-city-table .kd-city-picker-city-table-group {
301
302
  display: -webkit-box;
@@ -177,6 +177,7 @@
177
177
  margin-top: 10px;
178
178
  max-height: ~'calc(100% - 39px - 10px)';
179
179
  overflow: scroll;
180
+ height: 100%;
180
181
 
181
182
  .@{city-picker-prefix-cls}-city-table-group {
182
183
  display: flex;
@@ -2,8 +2,8 @@ import React from 'react';
2
2
  import { PanelProps } from './panel';
3
3
  export declare const IconPositionTypes: ["left", "right"];
4
4
  export declare type IconPositionType = typeof IconPositionTypes[number];
5
- export declare type keyType = string[] | string | number[] | number | NONE_KEY_TYPE;
6
- export declare type NONE_KEY_TYPE = undefined;
5
+ export declare type PanelKeyType = string | number;
6
+ export declare type keyType = string[] | string | number[] | number | undefined;
7
7
  export interface CollapseProps {
8
8
  accordion?: boolean;
9
9
  activeKey?: keyType;
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
 
3
+ var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
4
+ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
5
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
3
6
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
7
  Object.defineProperty(exports, "__esModule", {
5
8
  value: true
@@ -13,17 +16,16 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/he
13
16
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
14
17
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toConsumableArray"));
15
18
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
16
- var _react = _interopRequireDefault(require("react"));
19
+ var _react = _interopRequireWildcard(require("react"));
17
20
  var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));
18
21
  var _utils = require("../_utils");
19
22
  var _classnames = _interopRequireDefault(require("classnames"));
20
23
  var _type = require("../_utils/type");
21
- var _isArray = _interopRequireDefault(require("lodash/isArray"));
22
- var _isBoolean = _interopRequireDefault(require("lodash/isBoolean"));
23
24
  var _devwarning = _interopRequireDefault(require("../_utils/devwarning"));
25
+ 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); }
26
+ 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; }
24
27
  var IconPositionTypes = (0, _type.tuple)('left', 'right');
25
28
  exports.IconPositionTypes = IconPositionTypes;
26
- var NONE_KEY = undefined;
27
29
  var InternalCollapse = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
28
30
  var _React$useContext = _react.default.useContext(_ConfigContext.default),
29
31
  getPrefixCls = _React$useContext.getPrefixCls,
@@ -42,91 +44,69 @@ var InternalCollapse = /*#__PURE__*/_react.default.forwardRef(function (props, r
42
44
  children = _getCompProps.children,
43
45
  customPrefixcls = _getCompProps.prefixCls;
44
46
  var CollapsePrefixCls = getPrefixCls(prefixCls, 'collapse', customPrefixcls); // 样式前缀
45
- var getDefaultActivePanelKey = function getDefaultActivePanelKey() {
46
- // const _defaultActiveKey =
47
- // defaultActiveKey !== NONE_KEY
48
- // ? defaultActiveKey
49
- // : React.Children.map(children, (item, index) => {
50
- // if (index === 0) return item.props?.panelKey
51
- // })
52
- // return isBoolean(activeKey) ? activeKey : _defaultActiveKey
53
- return (0, _isBoolean.default)(activeKey) ? activeKey : defaultActiveKey;
54
- };
55
- var _React$useState = _react.default.useState(getDefaultActivePanelKey()),
56
- _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
57
- activePanelKey = _React$useState2[0],
58
- setActivePanelKey = _React$useState2[1];
59
- var getPanelExpand = function getPanelExpand(panelKey, accordion, activeKey) {
60
- var _activeKey = getActiveKey(accordion, activeKey);
61
- return isInclude(_activeKey, panelKey);
62
- };
63
- var getActiveKey = function getActiveKey(accordion, activeKey) {
64
- var _activeKey = activeKey;
65
- if (accordion) {
66
- if ((0, _isArray.default)(activeKey)) {
67
- _activeKey = activeKey[0]; // accordion 模式下默认第一个元素
68
- }
47
+ var _useState = (0, _react.useState)([]),
48
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
49
+ innerKey = _useState2[0],
50
+ setInnerKey = _useState2[1];
51
+ var convertActiveKey = function convertActiveKey(newKey) {
52
+ var ret = [];
53
+ if (Array.isArray(newKey)) {
54
+ ret = newKey;
55
+ } else if (typeof newKey === 'string' || typeof newKey === 'number') {
56
+ ret = [newKey];
69
57
  }
70
-
71
- return _activeKey;
72
- };
73
- var isInclude = function isInclude(activePanelKey, key) {
74
- if ((0, _isArray.default)(activePanelKey)) {
75
- return (0, _includes.default)(activePanelKey).call(activePanelKey, key) || (0, _includes.default)(activePanelKey).call(activePanelKey, String(key));
76
- } else {
77
- return String(activePanelKey) === String(key);
58
+ if (accordion && ret.length) {
59
+ ret = [ret[0]];
78
60
  }
61
+ return ret;
79
62
  };
80
- var getRemoveKey = function getRemoveKey(key) {
81
- if ((0, _isArray.default)(activePanelKey)) {
82
- return (0, _filter.default)(activePanelKey).call(activePanelKey, function (element) {
83
- return element !== key;
84
- });
63
+ (0, _react.useEffect)(function () {
64
+ if (typeof activeKey !== 'undefined') {
65
+ setInnerKey(convertActiveKey(activeKey));
85
66
  }
86
- return NONE_KEY;
87
- };
88
- var getAddKey = function getAddKey(key) {
89
- if ((0, _isArray.default)(activePanelKey)) {
90
- var _context;
91
- return (0, _concat.default)(_context = []).call(_context, (0, _toConsumableArray2.default)(activePanelKey), [key]);
67
+ }, [activeKey]);
68
+ (0, _react.useEffect)(function () {
69
+ if (typeof activeKey !== 'undefined' || typeof defaultActiveKey !== 'undefined') {
70
+ setInnerKey(convertActiveKey(typeof activeKey !== 'undefined' ? activeKey : defaultActiveKey));
92
71
  }
93
- return activePanelKey ? [activePanelKey, key] : key;
94
- };
95
- var getNewActiveKey = function getNewActiveKey(key) {
96
- if (isInclude(activePanelKey, key)) {
97
- if (accordion) {
98
- return NONE_KEY;
72
+ }, []);
73
+ var onPanelChange = function onPanelChange(key) {
74
+ var newKey = [];
75
+ if (accordion) {
76
+ if ((0, _includes.default)(innerKey).call(innerKey, key)) {
77
+ newKey = [];
78
+ } else {
79
+ newKey = [key];
99
80
  }
100
- return getRemoveKey(key);
101
81
  } else {
102
- if (accordion) {
103
- return key;
82
+ if ((0, _includes.default)(innerKey).call(innerKey, key)) {
83
+ newKey = (0, _filter.default)(innerKey).call(innerKey, function (d) {
84
+ return d !== key;
85
+ });
86
+ } else {
87
+ var _context;
88
+ newKey = (0, _concat.default)(_context = []).call(_context, (0, _toConsumableArray2.default)(innerKey), [key]);
104
89
  }
105
- return getAddKey(key);
106
90
  }
91
+ if (typeof activeKey === 'undefined') {
92
+ setInnerKey(newKey);
93
+ }
94
+ onChange && onChange(newKey);
107
95
  };
108
- var onPanelChange = _react.default.useCallback(function (key) {
109
- key = getNewActiveKey(key);
110
- setActivePanelKey(key);
111
- onChange && onChange();
112
- }, [onChange, activePanelKey, accordion]);
113
96
  var renderPanel = function renderPanel() {
114
97
  var _context2;
115
98
  return (0, _map.default)(_context2 = _react.default.Children).call(_context2, children, function (item) {
116
- var _a, _b, _c;
99
+ var _a;
117
100
  if (((_a = item === null || item === void 0 ? void 0 : item.type) === null || _a === void 0 ? void 0 : _a.displayName) !== 'Panel') {
118
101
  (0, _devwarning.default)(true, 'Collapse', 'children必须为Collapse.Panel');
119
102
  return item;
120
103
  }
121
- var expand = getPanelExpand((_b = item.props) === null || _b === void 0 ? void 0 : _b.panelKey, accordion, activePanelKey);
122
- var defaultExpand = getPanelExpand((_c = item.props) === null || _c === void 0 ? void 0 : _c.panelKey, accordion, defaultActiveKey);
123
104
  return /*#__PURE__*/_react.default.cloneElement(item, (0, _extends2.default)({
124
105
  expandIcon: expandIcon,
125
106
  expandIconPosition: expandIconPosition,
126
107
  onChange: onPanelChange,
127
108
  bordered: bordered,
128
- expand: expand,
129
- defaultExpand: defaultExpand
109
+ innerKey: innerKey
130
110
  }, item.props));
131
111
  });
132
112
  };
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
- import { IconPositionType, keyType } from './collapse';
2
+ import { IconPositionType, PanelKeyType } from './collapse';
3
3
  export interface PanelProps {
4
4
  disabled?: boolean;
5
5
  header?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
6
6
  expandIcon?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
7
7
  bordered?: boolean;
8
8
  expandIconPosition?: IconPositionType;
9
- onChange?: (key: keyType) => void;
9
+ onChange?: (key: PanelKeyType) => void;
10
10
  extra?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
11
11
  assist?: React.ReactNode | ((props: PanelProps) => React.ReactNode);
12
12
  expand?: boolean;
13
13
  defaultExpand?: boolean;
14
14
  children?: React.ReactNode;
15
- panelKey?: any;
15
+ panelKey?: PanelKeyType;
16
16
  style?: React.CSSProperties;
17
17
  className?: string;
18
18
  }
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
10
  exports.default = void 0;
11
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
11
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
12
13
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
13
14
  var _react = _interopRequireWildcard(require("react"));
@@ -15,7 +16,6 @@ var _classnames = _interopRequireDefault(require("classnames"));
15
16
  var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));
16
17
  var _utils = require("../_utils");
17
18
  var _icon = _interopRequireDefault(require("../icon"));
18
- var _isBoolean = _interopRequireDefault(require("lodash/isBoolean"));
19
19
  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); }
20
20
  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; }
21
21
  var Panel = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
@@ -31,8 +31,7 @@ var Panel = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
31
31
  header = _getCompProps.header,
32
32
  onChange = _getCompProps.onChange,
33
33
  panelKey = _getCompProps.panelKey,
34
- defaultExpand = _getCompProps.defaultExpand,
35
- expand = _getCompProps.expand,
34
+ innerKey = _getCompProps.innerKey,
36
35
  bordered = _getCompProps.bordered,
37
36
  expandIcon = _getCompProps.expandIcon,
38
37
  expandIconPosition = _getCompProps.expandIconPosition,
@@ -48,17 +47,24 @@ var Panel = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
48
47
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
49
48
  expandAnimation = _useState2[0],
50
49
  setExpandAnimation = _useState2[1];
51
- var getExpand = function getExpand() {
52
- return (0, _isBoolean.default)(expand) ? expand : defaultExpand;
53
- };
50
+ var _useState3 = (0, _react.useState)(false),
51
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
52
+ expand = _useState4[0],
53
+ setExpand = _useState4[1];
54
+ (0, _react.useEffect)(function () {
55
+ var newValue = (0, _includes.default)(innerKey).call(innerKey, panelKey);
56
+ if (newValue !== expand) {
57
+ setExpand(newValue);
58
+ setExpandAnimation(true);
59
+ }
60
+ }, [innerKey]);
54
61
  var handleClick = function handleClick() {
55
62
  if (disabled) return;
56
- setExpandAnimation(true);
57
63
  onChange && onChange(panelKey);
58
64
  };
59
65
  var renderIcon = function renderIcon() {
60
66
  var _classNames;
61
- var iconClassName = (0, _classnames.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-icon"), true), (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-animation-expand"), !getExpand()), (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-animation-collapse"), getExpand()), (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-disabled"), disabled), _classNames));
67
+ var iconClassName = (0, _classnames.default)((_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-icon"), true), (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-animation-expand"), !expand), (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-animation-collapse"), expand), (0, _defineProperty2.default)(_classNames, "".concat(panelPrefixCls, "-disabled"), disabled), _classNames));
62
68
  return /*#__PURE__*/_react.default.createElement("span", {
63
69
  className: iconClassName,
64
70
  onClick: handleClick