import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { IConnectorConfig } from '../../../common/catalogo-protocol'; import TweenOne from 'rc-tween-one'; import { Flex } from '@rebass/grid'; import { Card, Icon } from 'antd'; const { Meta } = Card; interface ConnectorCardProps { index: number; conn: IConnectorConfig; onSelect: (index: number) => void; } interface ConnectorCardState { metaHeight: number; extraHeight: number; cardExpanded: boolean; } export default class ConnectorCard extends React.Component { // container do card private card = null; constructor(props: ConnectorCardProps) { super(props); this.state = { cardExpanded: false, metaHeight: 0, extraHeight: 0 }; } componentDidMount() { this.setState(this.setCardHeight()); } private onSelect = (index: number) => this.props.onSelect(index); private onToggleCard = (state: boolean) => { this.setState({cardExpanded: !state, ...(!state ? this.setCardHeight() : {})}); } /** * Seta o tamanho do card * Esse tamanho é importante para a animação de collapse e expand do card */ private setCardHeight = () => { const cardDom = ReactDOM.findDOMNode(this.card); const metaDom = cardDom.firstChild.firstChild.firstChild.firstChild; const extraHeight = (cardDom as HTMLElement).offsetHeight; const metaHeight = (metaDom as HTMLElement).offsetHeight; return { extraHeight, metaHeight }; } render() { const { index, conn } = this.props; const { metaHeight, extraHeight, cardExpanded } = this.state; const animateMeta = cardExpanded ? { height: 0 , duration: 300 } : { height: metaHeight, duration: 300 } const animateExtra = cardExpanded ? { height: extraHeight , duration: 300 } : { height: 31, duration: 300 } return ( { this.card = c; }} > this.onSelect(index)} > } /> this.onToggleCard(cardExpanded)} className="extra"> { cardExpanded ? : } Version: {Array.isArray(conn.version) ? 'multiple' : conn.version} Type: {conn.type} Keywords: {conn.keywords} ); } }