Skip to content

Commit c5c24a8

Browse files
committed
test: remove <Panel /> because deprecated
1 parent 783df83 commit c5c24a8

File tree

3 files changed

+375
-369
lines changed

3 files changed

+375
-369
lines changed

src/Collapse.tsx

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import classNames from 'classnames';
2-
import toArray from 'rc-util/lib/Children/toArray';
32
import useMergedState from 'rc-util/lib/hooks/useMergedState';
4-
import warning from 'rc-util/lib/warning';
53
import React from 'react';
6-
import type { CollapsePanelProps, CollapseProps, CollapsibleType, ItemType } from './interface';
4+
import type { CollapseProps, ItemType } from './interface';
75
import CollapsePanel from './Panel';
86

97
function getActiveKeysArray(activeKey: React.Key | React.Key[]) {
@@ -23,7 +21,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
2321
style,
2422
accordion,
2523
className,
26-
children: rawChildren,
2724
collapsible,
2825
openMotion,
2926
expandIcon,
@@ -58,68 +55,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
5855
});
5956

6057
// ======================== Children ========================
61-
warning(
62-
!rawChildren,
63-
'`children` will be removed in next major version. Please use `items` instead.',
64-
);
65-
66-
const getNewChild = (child: React.ReactElement<CollapsePanelProps>, index: number) => {
67-
if (!child) return null;
68-
69-
const key = child.key || String(index);
70-
71-
const {
72-
header,
73-
headerClass,
74-
destroyInactivePanel: childDestroyInactivePanel,
75-
collapsible: childCollapsible,
76-
onItemClick: childOnItemClick,
77-
} = child.props;
78-
79-
let isActive = false;
80-
if (accordion) {
81-
isActive = activeKey[0] === key;
82-
} else {
83-
isActive = activeKey.indexOf(key) > -1;
84-
}
85-
86-
const mergeCollapsible: CollapsibleType = childCollapsible ?? collapsible;
87-
88-
const handleItemClick = (value: React.Key) => {
89-
if (mergeCollapsible === 'disabled') return;
90-
onClickItem(value);
91-
childOnItemClick?.(value);
92-
};
93-
94-
const childProps = {
95-
key,
96-
panelKey: key,
97-
header,
98-
headerClass,
99-
isActive,
100-
prefixCls,
101-
destroyInactivePanel: childDestroyInactivePanel ?? destroyInactivePanel,
102-
openMotion,
103-
accordion,
104-
children: child.props.children,
105-
onItemClick: handleItemClick,
106-
expandIcon,
107-
collapsible: mergeCollapsible,
108-
};
109-
110-
// https://github.com/ant-design/ant-design/issues/20479
111-
if (typeof child.type === 'string') {
112-
return child;
113-
}
114-
115-
Object.keys(childProps).forEach((propName) => {
116-
if (typeof childProps[propName] === 'undefined') {
117-
delete childProps[propName];
118-
}
119-
});
120-
121-
return React.cloneElement(child, childProps);
122-
};
12358

12459
// eslint-disable-next-line @typescript-eslint/no-shadow
12560
const convertItemsToNodes = (items: ItemType[]) =>
@@ -172,10 +107,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
172107
);
173108
});
174109

175-
const children = Array.isArray(items)
176-
? [convertItemsToNodes(items), rawChildren]
177-
: toArray(rawChildren).map(getNewChild);
178-
179110
// ======================== Render ========================
180111
return (
181112
<div
@@ -184,14 +115,10 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
184115
style={style}
185116
role={accordion ? 'tablist' : undefined}
186117
>
187-
{children}
118+
{convertItemsToNodes(items)}
119+
{props.children}
188120
</div>
189121
);
190122
});
191123

192-
export default Object.assign(Collapse, {
193-
/**
194-
* @deprecated use `items` instead, will be removed in `v4.0.0`
195-
*/
196-
Panel: CollapsePanel,
197-
});
124+
export default Collapse;

src/index.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
import Collapse from './Collapse';
2-
1+
export { default } from './Collapse';
32
export type { CollapsePanelProps, CollapseProps } from './interface';
4-
5-
export default Collapse;
6-
7-
/**
8-
* @deprecated use `items` instead, will be removed in `v4.0.0`
9-
*/
10-
export const { Panel } = Collapse;

0 commit comments

Comments
 (0)