Skip to content

Commit fb3888a

Browse files
committed
refactor: remove deprecated
1 parent e3025c4 commit fb3888a

File tree

3 files changed

+4
-102
lines changed

3 files changed

+4
-102
lines changed

src/Collapse.tsx

Lines changed: 1 addition & 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,
@@ -58,12 +56,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
5856
});
5957

6058
// ======================== Children ========================
61-
warning(
62-
!children,
63-
'`children` will be removed in next major version. Please use `items` instead.',
64-
);
65-
66-
const mergedChildren = useItems(items, children, {
59+
const mergedChildren = useItems(items, {
6760
prefixCls,
6861
accordion,
6962
openMotion,

src/hooks/useItems.tsx

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import toArray from 'rc-util/lib/Children/toArray';
21
import React from 'react';
32
import type { CollapsePanelProps, CollapseProps, ItemType } from '../interface';
43
import CollapsePanel from '../Panel';
@@ -31,8 +30,6 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
3130
...restProps
3231
} = item;
3332

34-
// You may be puzzled why you want to convert them all into strings, me too.
35-
// Maybe: https://github.com/react-component/collapse/blob/aac303a8b6ff30e35060b4f8fecde6f4556fcbe2/src/Collapse.tsx#L15
3633
const key = String(rawKey ?? index);
3734
const mergeCollapsible = rawCollapsible ?? collapsible;
3835
const mergeDestroyInactivePanel = rawDestroyInactivePanel ?? destroyInactivePanel;
@@ -71,92 +68,12 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
7168
});
7269
};
7370

74-
/**
75-
* @deprecated The next major version will be removed
76-
*/
77-
const getNewChild = (
78-
child: React.ReactElement<CollapsePanelProps>,
79-
index: number,
80-
props: Props,
81-
) => {
82-
if (!child) return null;
83-
84-
const {
85-
prefixCls,
86-
accordion,
87-
collapsible,
88-
destroyInactivePanel,
89-
onItemClick,
90-
activeKey,
91-
openMotion,
92-
expandIcon,
93-
} = props;
94-
95-
const key = child.key || String(index);
96-
97-
const {
98-
header,
99-
headerClass,
100-
destroyInactivePanel: childDestroyInactivePanel,
101-
collapsible: childCollapsible,
102-
onItemClick: childOnItemClick,
103-
} = child.props;
104-
105-
let isActive = false;
106-
if (accordion) {
107-
isActive = activeKey[0] === key;
108-
} else {
109-
isActive = activeKey.indexOf(key) > -1;
110-
}
111-
112-
const mergeCollapsible = childCollapsible ?? collapsible;
113-
114-
const handleItemClick = (value: React.Key) => {
115-
if (mergeCollapsible === 'disabled') return;
116-
onItemClick(value);
117-
childOnItemClick?.(value);
118-
};
119-
120-
const childProps = {
121-
key,
122-
panelKey: key,
123-
header,
124-
headerClass,
125-
isActive,
126-
prefixCls,
127-
destroyInactivePanel: childDestroyInactivePanel ?? destroyInactivePanel,
128-
openMotion,
129-
accordion,
130-
children: child.props.children,
131-
onItemClick: handleItemClick,
132-
expandIcon,
133-
collapsible: mergeCollapsible,
134-
};
135-
136-
// https://github.com/ant-design/ant-design/issues/20479
137-
if (typeof child.type === 'string') {
138-
return child;
139-
}
140-
141-
Object.keys(childProps).forEach((propName) => {
142-
if (typeof childProps[propName] === 'undefined') {
143-
delete childProps[propName];
144-
}
145-
});
146-
147-
return React.cloneElement(child, childProps);
148-
};
149-
150-
function useItems(
151-
items?: ItemType[],
152-
rawChildren?: React.ReactNode,
153-
props?: Props,
154-
): React.ReactElement<CollapsePanelProps>[] {
71+
function useItems(items?: ItemType[], props?: Props) {
15572
if (Array.isArray(items)) {
15673
return convertItemsToNodes(items, props);
15774
}
15875

159-
return toArray(rawChildren).map((child, index) => getNewChild(child, index, props));
76+
return null;
16077
}
16178

16279
export default useItems;

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)