Skip to content
Merged
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module.exports = {
'jsx-a11y/label-has-for': 0,
'jsx-a11y/no-noninteractive-tabindex': 0,
'import/no-extraneous-dependencies': 0,
'@typescript-eslint/consistent-type-exports': 2,
},
};
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
2 changes: 1 addition & 1 deletion docs/examples/_util/motionUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion';
import type { CSSMotionProps, MotionEndEventHandler, MotionEventHandler } from 'rc-motion';

const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
const getRealHeight: MotionEventHandler = (node) => ({ height: node.scrollHeight, opacity: 1 });
Expand Down
68 changes: 30 additions & 38 deletions docs/examples/custom-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Collapse, { Panel } from 'rc-collapse';
import motion from './_util/motionUtil';
import * as React from 'react';
import '../../assets/index.less';
import motion from './_util/motionUtil';

const initLength = 3;

Expand Down Expand Up @@ -48,40 +48,32 @@ 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>
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 tools = (
<>
Expand All @@ -90,7 +82,7 @@ const App: React.FC = () => {
</button>
<br />
<br />
<button type="button" onClick={() => setAccordion(prev => !prev)}>
<button type="button" onClick={() => setAccordion((prev) => !prev)}>
{accordion ? 'Mode: accordion' : 'Mode: collapse'}
</button>
<br />
Expand All @@ -101,7 +93,7 @@ const App: React.FC = () => {
<br />
<br />
</>
)
);

return (
<>
Expand All @@ -116,7 +108,7 @@ const App: React.FC = () => {
{panelItems}
</Collapse>
</>
)
}
);
};

export default App;
2 changes: 1 addition & 1 deletion docs/examples/fragment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Collapse, { Panel } from 'rc-collapse';
import * as React from 'react';
import { Fragment } from 'react';
import Collapse, { Panel } from 'rc-collapse';
import '../../assets/index.less';

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

const initLength = 3;

Expand Down Expand Up @@ -50,65 +50,44 @@ 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>
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 handleCollapsibleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const values = [undefined, 'header', 'icon', 'disabled'];
setCollapsible(values[e.target.value])
}
setCollapsible(values[e.target.value]);
};

const tools = (
<>
Expand All @@ -117,7 +96,7 @@ const App: React.FC = () => {
</button>
<br />
<br />
<button type="button" onClick={() => setAccordion(prev => !prev)}>
<button type="button" onClick={() => setAccordion((prev) => !prev)}>
{accordion ? 'Mode: accordion' : 'Mode: collapse'}
</button>
<br />
Expand All @@ -138,7 +117,7 @@ const App: React.FC = () => {
<br />
<br />
</>
)
);

return (
<>
Expand All @@ -154,7 +133,7 @@ const App: React.FC = () => {
{panelItems}
</Collapse>
</>
)
}
);
};

export default App;
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
"compile": "father build && lessc assets/index.less assets/index.css",
"coverage": "npm test -- --coverage",
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
"prepare": "husky install",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
"start": "dumi dev",
"test": "rc-test"
},
"lint-staged": {
"**/*.{ts,tsx,js,jsx,json,md}": "npm run prettier"
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"classnames": "2.x",
Expand All @@ -55,8 +59,10 @@
"dumi": "^2.1.1",
"eslint": "^7.11.0",
"father": "^4.1.3",
"husky": "^8.0.3",
"jest": "^29.1.2",
"less": "^3.12.2",
"lint-staged": "^13.1.0",
"np": "^6.0.0",
"prettier": "^2.1.2",
"rc-test": "^7.0.14",
Expand Down
4 changes: 2 additions & 2 deletions src/Collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import CollapsePanel from './Panel';
import React from 'react';
import type { CollapseProps, CollapsibleType } from './interface';
import CollapsePanel from './Panel';

function getActiveKeysArray(activeKey: React.Key | React.Key[]) {
let currentActiveKey = activeKey;
Expand Down
6 changes: 3 additions & 3 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import classNames from 'classnames';
import type { CollapsePanelProps } from './interface';
import KeyCode from 'rc-util/lib/KeyCode';
import CSSMotion from 'rc-motion';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
import type { CollapsePanelProps } from './interface';
import PanelContent from './PanelContent';

const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((props, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion src/PanelContent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import classnames from 'classnames';
import React from 'react';
import type { CollapsePanelProps } from './interface';

const PanelContent = React.forwardRef<
Expand Down
5 changes: 1 addition & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Collapse from './Collapse';

export type {
CollapseProps,
CollapsePanelProps
} from './interface';
export type { CollapsePanelProps, CollapseProps } from './interface';

export default Collapse;
export const { Panel } = Collapse;
6 changes: 3 additions & 3 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent, render } from '@testing-library/react';
import type { RenderResult } from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';
import KeyCode from 'rc-util/lib/KeyCode';
import React, { Fragment } from 'react';
import Collapse, { Panel } from '../src/index';
Expand Down Expand Up @@ -623,11 +623,11 @@ describe('collapse', () => {
const { container } = render(
<Collapse>
{null}
<Panel header="collapse 1" key="1" >
<Panel header="collapse 1" key="1">
<p>Panel 1 content</p>
</Panel>
{0}
<Panel header="collapse 2" key="2" >
<Panel header="collapse 2" key="2">
<p>Panel 2 content</p>
</Panel>
{undefined}
Expand Down