ant-design/components/collapse/Collapse.tsx

57 lines
1.5 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import RcCollapse from 'rc-collapse';
import classNames from 'classnames';
import CollapsePanel from './CollapsePanel';
2018-08-21 20:03:48 +08:00
import Icon from '../icon';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import animation from '../_util/openAnimation';
export interface CollapseProps {
activeKey?: Array<string> | string;
defaultActiveKey?: Array<string>;
/** 手风琴效果 */
accordion?: boolean;
destroyInactivePanel?: boolean;
onChange?: (key: string | string[]) => void;
style?: React.CSSProperties;
className?: string;
bordered?: boolean;
prefixCls?: string;
}
export default class Collapse extends React.Component<CollapseProps, any> {
static Panel = CollapsePanel;
static defaultProps = {
bordered: true,
2018-12-07 20:02:01 +08:00
openAnimation: { ...animation, appear() {} },
};
2018-08-21 20:03:48 +08:00
renderExpandIcon = () => {
2018-12-07 20:02:01 +08:00
return <Icon type="right" className={`arrow`} />;
};
2018-08-21 20:03:48 +08:00
renderCollapse = ({ getPrefixCls }: ConfigConsumerProps) => {
const { prefixCls: customizePrefixCls, className = '', bordered } = this.props;
const prefixCls = getPrefixCls('collapse', customizePrefixCls);
2018-12-07 20:02:01 +08:00
const collapseClassName = classNames(
{
[`${prefixCls}-borderless`]: !bordered,
},
className,
);
2018-08-21 20:03:48 +08:00
return (
<RcCollapse
{...this.props}
prefixCls={prefixCls}
2018-08-21 20:03:48 +08:00
className={collapseClassName}
expandIcon={this.renderExpandIcon}
/>
);
2018-12-07 20:02:01 +08:00
};
render() {
2018-12-07 20:02:01 +08:00
return <ConfigConsumer>{this.renderCollapse}</ConfigConsumer>;
}
}