Skip to content

Instantly share code, notes, and snippets.

@damon-kreft
Created April 19, 2017 16:15
Show Gist options
  • Save damon-kreft/b4eb0f992f503a70ca3cd752c3bcc438 to your computer and use it in GitHub Desktop.
Save damon-kreft/b4eb0f992f503a70ca3cd752c3bcc438 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react'
import {connect} from 'react-redux'
import classNames from 'classnames'
class InjectPoint extends Component {
render () {
const {popUpStack} = this.props
const children = popUpStack.map((item, i) => {
const clonedChild = React.cloneElement(item.Component, {
...item.Component.props,
ref: item.Component.key,
className: classNames('c-popup', item.Component.props.className)
})
return (
<div
key={item.Component.key + 'backdrop'}
className='c-popup-modal'
style={{zIndex: (i + 1) * 100 - 1}}>
{clonedChild}
</div>
)
})
return (
<div className='c-popup-inject-point'>
{children}
</div>
)
}
}
export default connect((state) => {
return state.popUps
})(InjectPoint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment