/// import * as React from 'react'; import classNames from 'classnames'; import Hammer from 'react-hammerjs'; import Carousel from '../carousel'; const prefix = 'tsp-component-Tab'; class Tab extends React.Component { constructor(props: tspComponentTabProps, state: tspComponentTabState) { super(props, state); } public static defaultProps: tspComponentTabProps = { selectedIndex: 0, tabs: [] }; private carouselElem: HTMLElement; private bodyElem: HTMLElement; public state: tspComponentTabState = { selectedIndex: this.props.selectedIndex }; public componentDidMount(): void { this.carouselElem = this.refs.carousel['refs'].container as HTMLElement; this.bodyElem = this.refs.body as HTMLElement; this.setHeight(); } public componentDidUpdate(nextProps): void { if (nextProps.selectIndex !== this.props.selectedIndex) { this.setHeight(); } } public setHeight(): void { this.bodyElem.style.height = this.carouselElem.clientHeight + 'px'; } /** * 点击头部tab */ public clickTab(selectedIndex: number): void { if (this.props.onChange) { this.props.onChange(selectedIndex); } this.setState({ selectedIndex }, () => this.setHeight()); } public render(): JSX.Element { return (
{this.props.tabs.map((tab, i) => ( this.clickTab(i)} key={i}>
{tab}
))}
{this.props.children}
); } } export default Tab;