|
1 |
| -import toArray from 'rc-util/lib/Children/toArray'; |
2 | 1 | import React from 'react';
|
3 | 2 | import type { CollapsePanelProps, CollapseProps, ItemType } from '../interface';
|
4 | 3 | import CollapsePanel from '../Panel';
|
@@ -31,8 +30,6 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
|
31 | 30 | ...restProps
|
32 | 31 | } = item;
|
33 | 32 |
|
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 |
36 | 33 | const key = String(rawKey ?? index);
|
37 | 34 | const mergeCollapsible = rawCollapsible ?? collapsible;
|
38 | 35 | const mergeDestroyInactivePanel = rawDestroyInactivePanel ?? destroyInactivePanel;
|
@@ -71,92 +68,12 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
|
71 | 68 | });
|
72 | 69 | };
|
73 | 70 |
|
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) { |
155 | 72 | if (Array.isArray(items)) {
|
156 | 73 | return convertItemsToNodes(items, props);
|
157 | 74 | }
|
158 | 75 |
|
159 |
| - return toArray(rawChildren).map((child, index) => getNewChild(child, index, props)); |
| 76 | + return null; |
160 | 77 | }
|
161 | 78 |
|
162 | 79 | export default useItems;
|
0 commit comments