mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-08 01:53:34 +08:00
Add option for disabling arrow icon in collapse panel (#8536)
This commit is contained in:
parent
5a94236c30
commit
28e9d1ee88
@ -2,37 +2,27 @@ import * as React from 'react';
|
|||||||
import RcCollapse from 'rc-collapse';
|
import RcCollapse from 'rc-collapse';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import animation from '../_util/openAnimation';
|
import animation from '../_util/openAnimation';
|
||||||
|
import CollapsePanel from './CollapsePanel';
|
||||||
|
|
||||||
export interface CollapseProps {
|
export interface CollapseProps {
|
||||||
activeKey?: Array<string> | string;
|
activeKey?: Array<string> | string;
|
||||||
defaultActiveKey?: Array<string>;
|
defaultActiveKey?: Array<string>;
|
||||||
/** 手风琴效果 */
|
/** 手风琴效果 */
|
||||||
accordion?: boolean;
|
accordion?: boolean;
|
||||||
onChange?: (key: string | string[]) => void;
|
onChange?: (key: string | string[]) => void;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
bordered?: boolean;
|
bordered?: boolean;
|
||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollapsePanelProps {
|
|
||||||
key: string;
|
|
||||||
header: React.ReactNode;
|
|
||||||
disabled?: boolean;
|
|
||||||
className?: string;
|
|
||||||
style?: React.CSSProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CollapsePanel extends React.Component<CollapsePanelProps, {}> {
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Collapse extends React.Component<CollapseProps, any> {
|
export default class Collapse extends React.Component<CollapseProps, any> {
|
||||||
static Panel: typeof CollapsePanel = RcCollapse.Panel;
|
static Panel = CollapsePanel;
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
prefixCls: 'ant-collapse',
|
prefixCls: 'ant-collapse',
|
||||||
bordered: true,
|
bordered: true,
|
||||||
openAnimation: { ...animation, appear() {} },
|
openAnimation: { ...animation, appear() { } },
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
23
components/collapse/CollapsePanel.tsx
Normal file
23
components/collapse/CollapsePanel.tsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import RcCollapse from 'rc-collapse';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
export interface CollapsePanelProps {
|
||||||
|
key: string;
|
||||||
|
header: React.ReactNode;
|
||||||
|
disabled?: boolean;
|
||||||
|
className?: string;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
showArrow?: boolean;
|
||||||
|
prefixCls?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class CollapsePanel extends React.Component<CollapsePanelProps, {}> {
|
||||||
|
render() {
|
||||||
|
const { prefixCls, className = '', showArrow = true } = this.props;
|
||||||
|
const collapsePanelClassName = classNames({
|
||||||
|
[`${prefixCls}-no-arrow`]: !showArrow,
|
||||||
|
}, className);
|
||||||
|
return <RcCollapse.Panel {...this.props} className={collapsePanelClassName} />;
|
||||||
|
}
|
||||||
|
}
|
@ -293,3 +293,51 @@ exports[`renders ./components/collapse/demo/mix.md correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`renders ./components/collapse/demo/noarrow.md correctly 1`] = `
|
||||||
|
<div
|
||||||
|
class="ant-collapse"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-collapse-item ant-collapse-item-active"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-expanded="true"
|
||||||
|
class="ant-collapse-header"
|
||||||
|
role="tab"
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
class="arrow"
|
||||||
|
/>
|
||||||
|
This is panel header with arrow icon
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="ant-collapse-content ant-collapse-content-active"
|
||||||
|
role="tabpanel"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-collapse-content-box"
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
A dog is a type of domesticated animal.
|
||||||
|
Known for its loyalty and faithfulness,
|
||||||
|
it can be found as a welcome guest in many households across the world.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="ant-collapse-item ant-collapse-no-arrow"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-expanded="false"
|
||||||
|
class="ant-collapse-header"
|
||||||
|
role="tab"
|
||||||
|
>
|
||||||
|
This is panel header with no arrow icon
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
40
components/collapse/demo/noarrow.md
Normal file
40
components/collapse/demo/noarrow.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
order: 4
|
||||||
|
title:
|
||||||
|
zh-CN: TODO
|
||||||
|
en-US: No arrow
|
||||||
|
---
|
||||||
|
|
||||||
|
## zh-CN
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## en-US
|
||||||
|
|
||||||
|
You can disable showing arrow icon by passing `showArrow={false}` to `CollapsePanel` component.
|
||||||
|
|
||||||
|
````jsx
|
||||||
|
import { Collapse } from 'antd';
|
||||||
|
const Panel = Collapse.Panel;
|
||||||
|
|
||||||
|
function callback(key) {
|
||||||
|
console.log(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = `
|
||||||
|
A dog is a type of domesticated animal.
|
||||||
|
Known for its loyalty and faithfulness,
|
||||||
|
it can be found as a welcome guest in many households across the world.
|
||||||
|
`;
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<Collapse defaultActiveKey={['1']} onChange={callback}>
|
||||||
|
<Panel header="This is panel header with arrow icon" key="1">
|
||||||
|
<p>{text}</p>
|
||||||
|
</Panel>
|
||||||
|
<Panel showArrow={false} header="This is panel header with no arrow icon" key="2">
|
||||||
|
<p>{text}</p>
|
||||||
|
</Panel>
|
||||||
|
</Collapse>
|
||||||
|
, mountNode);
|
||||||
|
````
|
@ -29,3 +29,4 @@ A content area which can be collapsed and expanded.
|
|||||||
| disabled | If `true`, panel cannot be opened or closed | boolean | `false` |
|
| disabled | If `true`, panel cannot be opened or closed | boolean | `false` |
|
||||||
| header | Title of the panel | string\|ReactNode | - |
|
| header | Title of the panel | string\|ReactNode | - |
|
||||||
| key | Unique key identifying the panel from among its siblings | string | - |
|
| key | Unique key identifying the panel from among its siblings | string | - |
|
||||||
|
| showArrow | If `false`, panel will not show arrow icon | boolean | `true` |
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import Collapse from './Collapse';
|
import Collapse from './Collapse';
|
||||||
|
|
||||||
export { CollapsePanelProps, CollapseProps } from './Collapse';
|
export { CollapseProps } from './Collapse';
|
||||||
|
export { CollapsePanelProps } from './CollapsePanel';
|
||||||
|
|
||||||
export default Collapse;
|
export default Collapse;
|
||||||
|
@ -54,6 +54,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.@{collapse-prefix-cls}-no-arrow {
|
||||||
|
> .@{collapse-prefix-cls}-header {
|
||||||
|
padding-left: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&-anim-active {
|
&-anim-active {
|
||||||
|
Loading…
Reference in New Issue
Block a user