Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retire deprecated api #357

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ package-lock.json
.env.local
src/.umi

bun.lockb
bun.lockb
.vscode/
8 changes: 0 additions & 8 deletions docs/demo/fragment.md

This file was deleted.

83 changes: 53 additions & 30 deletions docs/examples/custom-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Collapse, { Panel } from 'rc-collapse';
import Collapse from 'rc-collapse';
import * as React from 'react';
import '../../assets/index.less';
import motion from './_util/motionUtil';
Expand Down Expand Up @@ -48,32 +48,56 @@ const App: React.FC = () => {

const time = random();

const panelItems = Array.from<object, React.ReactNode>({ length: initLength }, (_, i) => {
const key = i + 1;
return (
<Panel header={`This is panel header ${key}`} key={key}>
<p>{text.repeat(time)}</p>
</Panel>
);
}).concat(
<Panel header={`This is panel header ${initLength + 1}`} key={initLength + 1}>
<Collapse defaultActiveKey="1" expandIcon={expandIcon}>
<Panel header="This is panel nest panel" key="1" id="header-test">
<p>{text}</p>
</Panel>
</Collapse>
</Panel>,
<Panel header={`This is panel header ${initLength + 2}`} key={initLength + 2}>
<Collapse defaultActiveKey="1">
<Panel header="This is panel nest panel" key="1" id="another-test">
<form>
<label htmlFor="test">Name:&nbsp;</label>
<input type="text" id="test" />
</form>
</Panel>
</Collapse>
</Panel>,
);
const items = [
...Array.from({ length: initLength }, (_, i) => {
const key = i + 1;
return {
key,
label: `This is panel header ${key}`,
children: <p>{text.repeat(time)}</p>,
};
}),
{
key: initLength + 1,
label: `This is panel header ${initLength + 1}`,
children: (
<Collapse
defaultActiveKey="1"
expandIcon={expandIcon}
items={[
{
key: '1',
label: 'This is panel nest panel',
id: 'header-test',
children: <p>{text}</p>,
},
]}
/>
),
},
{
key: initLength + 2,
label: `This is panel header ${initLength + 2}`,
children: (
<Collapse
defaultActiveKey="1"
items={[
{
key: '1',
label: 'This is panel nest panel',
id: 'another-test',
children: (
<form>
<label htmlFor="test">Name:&nbsp;</label>
<input type="text" id="test" />
</form>
),
},
]}
/>
),
},
];

const tools = (
<>
Expand Down Expand Up @@ -104,9 +128,8 @@ const App: React.FC = () => {
activeKey={activeKey}
expandIcon={expandIcon}
openMotion={motion}
>
{panelItems}
</Collapse>
items={items}
/>
</>
);
};
Expand Down
23 changes: 0 additions & 23 deletions docs/examples/fragment.tsx

This file was deleted.

96 changes: 59 additions & 37 deletions docs/examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CollapseProps } from 'rc-collapse';
import Collapse, { Panel } from 'rc-collapse';
import Collapse from 'rc-collapse';
import * as React from 'react';
import '../../assets/index.less';
import motion from './_util/motionUtil';
Expand Down Expand Up @@ -50,39 +50,62 @@ const App: React.FC = () => {

const time = random();

const panelItems = Array.from<object, React.ReactNode>({ length: initLength }, (_, i) => {
const key = i + 1;
return (
<Panel header={`This is panel header ${key}`} key={key}>
<p>{text.repeat(time)}</p>
</Panel>
);
}).concat(
<Panel header={`This is panel header ${initLength + 1}`} key={initLength + 1}>
<Collapse defaultActiveKey="1" expandIcon={expandIcon}>
<Panel header="This is panel nest panel" key="1" id="header-test">
<p>{text}</p>
</Panel>
</Collapse>
</Panel>,
<Panel header={`This is panel header ${initLength + 2}`} key={initLength + 2}>
<Collapse defaultActiveKey="1">
<Panel header="This is panel nest panel" key="1" id="another-test">
<form>
<label htmlFor="test">Name:&nbsp;</label>
<input type="text" id="test" />
</form>
</Panel>
</Collapse>
</Panel>,
<Panel
header={`This is panel header ${initLength + 3}`}
key={initLength + 3}
extra={<span>Extra Node</span>}
>
<p>Panel with extra</p>
</Panel>,
);
const items: CollapseProps['items'] = [
...Array.from({ length: initLength }, (_, i) => {
const key = i + 1;
return {
key,
label: `This is panel header ${key}`,
children: <p>{text.repeat(time)}</p>,
};
}),
{
key: initLength + 1,
label: `This is panel header ${initLength + 1}`,
children: (
<Collapse
defaultActiveKey="1"
expandIcon={expandIcon}
items={[
{
key: '1',
label: 'This is panel nest panel',
id: 'header-test',
children: <p>{text}</p>,
},
]}
/>
),
},
{
key: initLength + 2,
label: `This is panel header ${initLength + 2}`,
children: (
<Collapse
defaultActiveKey="1"
items={[
{
key: '1',
label: 'This is panel nest panel',
id: 'another-test',
children: (
<form>
<label htmlFor="test">Name:&nbsp;</label>
<input type="text" id="test" />
</form>
),
},
]}
/>
),
},
{
key: initLength + 3,
label: `This is panel header ${initLength + 3}`,
extra: <span>Extra Node</span>,
children: <p>Panel with extra</p>,
},
];

const handleCollapsibleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const values = [undefined, 'header', 'icon', 'disabled'];
Expand Down Expand Up @@ -129,9 +152,8 @@ const App: React.FC = () => {
expandIcon={expandIcon}
openMotion={motion}
collapsible={collapsible}
>
{panelItems}
</Collapse>
items={items}
/>
</>
);
};
Expand Down
17 changes: 2 additions & 15 deletions src/Collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import warning from 'rc-util/lib/warning';
import React from 'react';
import useItems from './hooks/useItems';
import type { CollapseProps } from './interface';
import CollapsePanel from './Panel';
import pickAttrs from 'rc-util/lib/pickAttrs';

function getActiveKeysArray(activeKey: React.Key | React.Key[]) {
Expand All @@ -24,7 +22,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
style,
accordion,
className,
children,
collapsible,
openMotion,
expandIcon,
Expand Down Expand Up @@ -59,12 +56,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
});

// ======================== Children ========================
warning(
!children,
'[rc-collapse] `children` will be removed in next major version. Please use `items` instead.',
);

const mergedChildren = useItems(items, children, {
const mergedChildren = useItems(items, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

antd v4 还是 jsx 的,v5 是在 5.6.0 进行的 depreacted,v6 还得兼容一版。但是文档里不透出老的写法

prefixCls,
accordion,
openMotion,
Expand All @@ -89,9 +81,4 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
);
});

export default Object.assign(Collapse, {
/**
* @deprecated use `items` instead, will be removed in `v4.0.0`
*/
Panel: CollapsePanel,
});
export default Collapse;
Loading
Loading