import React from 'react' import classnames from 'classnames' import Card from '../Card/Card' import Icon from '../Icon/Icon' import AnimateHeight from 'react-animate-height' import { Button } from "react-bootstrap" export type CollapsibleCardProps = { children: React.ChildrenArray>, className: string, } const CollapsibleCardMain = () => null; const CollapsibleCardContent = () => null; class CollapsibleCard extends React.Component { static CollapsibleCardMain: Function static CollapsibleCardContent: Function static defaultProps = { children: null, } props: Props state = { height: 0, } constructor() { super() } toggleExpand() { const { height } = this.state; this.setState({ height: height === 0 ? 'auto' : 0, }) } renderTop() { const { children } = this.props; const content = React.Children.map(children, child => { if (child.type.displayName === 'CollapsibleCardMain' || child.type.name === 'CollapsibleCardMain') { return React.cloneElement(child) } }); return (
{content.length > 0 ? content[0].props.children : '' }
); } renderContent() { const { children } = this.props; const height = this.state.height; const content = React.Children.map(children, child => { if (child.type.displayName === 'CollapsibleCardContent' || child.type.name === 'CollapsibleCardContent') { return React.cloneElement(child) } }); return (
{content.length > 0 ? content[0].props.children : '' }
); } render() { const { children, className, main, } = this.props const { height } = this.state const css = classnames([ "collapsible-card", className ]) return ( {this.renderTop()} {this.renderContent()} ) } } CollapsibleCard.Main = CollapsibleCardMain CollapsibleCard.Content = CollapsibleCardContent export default CollapsibleCard