Skip to content

Commit aecd0c9

Browse files
committed
test: remove <Panel /> because deprecated
(cherry picked from commit 3ed3175) # Conflicts: # src/Collapse.tsx # tests/index.spec.tsx
1 parent 827ffc2 commit aecd0c9

File tree

3 files changed

+411
-302
lines changed

3 files changed

+411
-302
lines changed

src/Collapse.tsx

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import classNames from 'classnames';
22
import useMergedState from 'rc-util/lib/hooks/useMergedState';
3-
import warning from 'rc-util/lib/warning';
43
import React from 'react';
54
import useItems from './hooks/useItems';
65
import type { CollapseProps } from './interface';
@@ -23,7 +22,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
2322
style,
2423
accordion,
2524
className,
26-
children,
2725
collapsible,
2826
openMotion,
2927
expandIcon,
@@ -74,6 +72,57 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
7472
activeKey,
7573
});
7674

75+
// eslint-disable-next-line @typescript-eslint/no-shadow
76+
const convertItemsToNodes = (items: ItemType[]) =>
77+
items.map((item, index) => {
78+
const {
79+
children,
80+
key: rawKey,
81+
collapsible: rawCollapsible,
82+
onItemClick: rawOnItemClick,
83+
destroyInactivePanel: rawDestroyInactivePanel,
84+
expandIcon: rawExpandIcon = expandIcon,
85+
...restProps
86+
} = item;
87+
88+
// You may be puzzled why you want to convert them all into strings, me too.
89+
// Maybe: https://github.com/react-component/collapse/blob/aac303a8b6ff30e35060b4f8fecde6f4556fcbe2/src/Collapse.tsx#L15
90+
const key = String(rawKey ?? index);
91+
const mergeCollapsible = rawCollapsible ?? collapsible;
92+
const mergeDestroyInactivePanel = rawDestroyInactivePanel ?? destroyInactivePanel;
93+
94+
const handleItemClick = (value: React.Key) => {
95+
if (mergeCollapsible === 'disabled') return;
96+
onClickItem(value);
97+
rawOnItemClick?.(value);
98+
};
99+
100+
let isActive = false;
101+
if (accordion) {
102+
isActive = activeKey[0] === key;
103+
} else {
104+
isActive = activeKey.indexOf(key) > -1;
105+
}
106+
107+
return (
108+
<CollapsePanel
109+
prefixCls={prefixCls}
110+
key={key}
111+
panelKey={key}
112+
isActive={isActive}
113+
accordion={accordion}
114+
openMotion={openMotion}
115+
collapsible={mergeCollapsible}
116+
onItemClick={handleItemClick}
117+
destroyInactivePanel={mergeDestroyInactivePanel}
118+
expandIcon={rawExpandIcon}
119+
{...restProps}
120+
>
121+
{children}
122+
</CollapsePanel>
123+
);
124+
});
125+
77126
// ======================== Render ========================
78127
return (
79128
<div
@@ -87,9 +136,4 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
87136
);
88137
});
89138

90-
export default Object.assign(Collapse, {
91-
/**
92-
* @deprecated use `items` instead, will be removed in `v4.0.0`
93-
*/
94-
Panel: CollapsePanel,
95-
});
139+
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)