import React from 'react'
import classnames from 'classnames'
import PropTypes from 'prop-types'
class PopinFixedContent extends React.Component {
constructor (props) {
super(props)
this.state = {
rightPartOpen: false
}
}
componentDidMount () {
if (this.props.showRightPartOnLoad) this.setState({rightPartOpen: true})
}
handleToggleRightPart = () => {
this.setState(prev => ({rightPartOpen: !prev.rightPartOpen}))
}
render () {
return this.props.children.length === 2
? (
{this.props.children[0]}
{React.cloneElement(this.props.children[1], {
toggleRightPart: this.handleToggleRightPart,
rightPartOpen: this.state.rightPartOpen
})}
)
: (
{this.props.children}
)
}
}
export default PopinFixedContent
PopinFixedContent.propTypes = {
customClass: PropTypes.string,
children: (props, propName, componentName) => {
if (Array.isArray(props) && props.length !== 2) {
return new Error(`PropType Error: ${componentName} must have 1 or 2 children.`)
} else if (typeof props !== 'object') {
return new Error(`PropType Error: childrens of ${componentName} must have 1 or 2 children.`)
}
}
}