import { Component } from 'react'; import cx from 'classnames'; import { AnimateHeight } from '../utils/component/AnimateHeight'; import LazyMount from '../utils/component/LazyMount'; import { EASE_IN_CUBIC, EASE_IN_OUT, EASE_OUT_CUBIC, } from '../utils/timingFunctions'; import { DisabledContext, IDisabledContext } from '../disabled'; import isNil from '../utils/isNil'; import Icon from '../icon/Icon'; const NO_BOTTOM_BORDER = { borderBottomWidth: 0, borderBottomColor: 'rgba(255, 255, 255, 0)', transition: `border-bottom-width 200ms ${EASE_IN_OUT}, border-bottom-color 200ms ${EASE_IN_OUT}`, }; const NO_STYLE = {}; export interface ICollapsePanelProps { title: React.ReactNode; disabled?: boolean; showArrow: boolean; style?: React.CSSProperties; className?: string; active?: boolean; onChange?(key: string, active: boolean): void; panelKey?: string; panelTitleBackground?: string; showContentBackground?: boolean; isLast?: boolean; bordered?: boolean; extra?: React.ReactNode; } export class CollapsePanel extends Component { static defaultProps = { showArrow: true, }; static contextType = DisabledContext; context!: IDisabledContext; state = { animateAppear: !this.props.active, }; render() { const { children, title, style, active, disabled = this.context.value, showArrow, className, isLast, bordered, extra, panelTitleBackground, showContentBackground, } = this.props; const { animateAppear } = this.state; const isBorderedLast = bordered && isLast; // border transitions are done in JS to keep height animtion in sync const titleStyle = isBorderedLast && !active ? NO_BOTTOM_BORDER : NO_STYLE; const contentBoxStyle = isBorderedLast || !active ? NO_BOTTOM_BORDER : NO_STYLE; return (
{showArrow && ( )} {title}
{extra}
{children}
); } toggle = () => { const { onChange, panelKey, active, disabled = this.context.value, } = this.props; if (!disabled && !isNil(panelKey)) { onChange?.(panelKey, !active); } }; } export default CollapsePanel;