Feat collapse bordered (#3698)

* update ts types

* Add borderless style Collapse, close #3559

* update Collapse mix demo

* update demo description
This commit is contained in:
偏右 2016-11-06 15:06:34 +08:00 committed by GitHub
parent ba9949adcc
commit 7f422c9e18
6 changed files with 77 additions and 13 deletions

View File

@ -0,0 +1,39 @@
---
order: 3
title:
zh-CN: 简洁风格
en-US: Borderless
---
## zh-CN
一套没有边框的简洁样式。
## en-US
A borderless style of Collapse.
````jsx
import { Collapse } from 'antd';
const Panel = Collapse.Panel;
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 bordered={false} defaultActiveKey={['1']}>
<Panel header="This is panel header 1" key="1">
<p>{text}</p>
</Panel>
<Panel header="This is panel header 2" key="2">
<p>{text}</p>
</Panel>
<Panel header="This is panel header 3" key="3">
<p>{text}</p>
</Panel>
</Collapse>
, mountNode);
````

View File

@ -1,17 +1,17 @@
---
order: 2
title:
title:
zh-CN: 面板嵌套
en-US: Nested panel
---
## zh-CN
手风琴嵌套折叠面板。
嵌套折叠面板。
## en-US
`Collapse` is nested inside the `Accordion`.
`Collapse` is nested inside the `Collapse`.
````jsx
import { Collapse } from 'antd';
@ -28,7 +28,7 @@ const text = `
`;
ReactDOM.render(
<Collapse onChange={callback} accordion>
<Collapse onChange={callback}>
<Panel header={'This is panel header 1'} key="1">
<Collapse defaultActiveKey="1">
<Panel header={'This is panel nest panel'} key="1">

View File

@ -2,6 +2,7 @@
category: Components
type: Views
title: Collapse
cols: 1
---
A content area which can be collapsed and expanded.
@ -27,4 +28,3 @@ A content area which can be collapsed and expanded.
|----------|----------------|----------|--------------|
| key | corresponds to the `activeKey` | String | - |
| header | title of the panel | React.Element or String | - |

View File

@ -1,27 +1,27 @@
import RcCollapse from 'rc-collapse';
import React from 'react';
import RcCollapse from 'rc-collapse';
import classNames from 'classnames';
export interface CollapseProps {
activeKey?: Array<string> | string;
/** 初始化选中面板的key */
defaultActiveKey?: Array<string>;
/** accordion 为 true 的时候,一次只可以打开一个面板 */
/** 手风琴效果 */
accordion?: boolean;
/** 切换面板的回调 */
onChange?: (key: string) => void;
style?: React.CSSProperties;
className?: string;
bordered?: boolean;
prefixCls?: string;
}
export interface CollapsePanelProps {
/** 对应 activeKey */
key: string;
/** 面板头内容 */
header: React.ReactNode;
style?: React.CSSProperties;
className?: string;
}
export class CollapsePanel extends React.Component<CollapsePanelProps, {}> {
}
export default class Collapse extends React.Component<CollapseProps, any> {
@ -29,9 +29,15 @@ export default class Collapse extends React.Component<CollapseProps, any> {
static defaultProps = {
prefixCls: 'ant-collapse',
bordered: true,
};
render() {
return <RcCollapse {...this.props} />;
const { prefixCls, className = '', bordered } = this.props;
const collapseClassName = classNames({
[`${prefixCls}-borderless`]: !bordered,
[className]: !!className,
});
return <RcCollapse {...this.props} className={collapseClassName} />;
}
}

View File

@ -3,6 +3,7 @@ category: Components
type: Views
title: Collapse
subtitle: 折叠面板
cols: 1
---
可以折叠/展开的内容区域。

View File

@ -82,4 +82,22 @@
.collapse-open();
}
}
&-borderless {
background-color: #fff;
border: 0;
}
&-borderless > &-item {
border: 0;
}
&-borderless > &-item > &-header {
border-bottom: 1px solid @border-color-base;
transition: all .3s;
border-radius: @border-color-base @border-color-base 0 0;
&:hover {
background-color: #fcfcfc;
}
}
}