import * as React from 'react'; import { Props, State } from './type'; import * as Styled from './index.style' export class FoldContainer extends React.Component { public static defaultProps = new Props(); public state = new State(); componentDidMount() { if (this.props.foldImg) { this.preloadImg(this.props.foldImg.url) } } handleFold = () => { const { fold } = this.state this.setState({ fold: !fold }) } preloadImg = (url: string) => { const img = new Image(); img.src = url } public render() { const { children, isEdit, foldHeight, expandImg, foldImg } = this.props const { fold } = this.state return (
{ children && ( Array.isArray(children) && children.length) ? ( <> {children} { !!foldHeight && ( <> { fold && expandImg || !fold && foldImg ? ( ) : ( { fold ? '展开' : '收起' } ) } ) } ) : ( { isEdit && (
请添加需要折叠的元素到该容器下
) }
) }
) } }