Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Merge 5458a0e into 2eb5435
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Quach committed Dec 7, 2018
2 parents 2eb5435 + 5458a0e commit 7487031
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 168 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helpscout/hsds-react",
"version": "2.4.11",
"version": "2.4.12-0",
"private": false,
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
68 changes: 28 additions & 40 deletions src/components/Portal/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Component } from 'react'
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
import { getDocumentFromComponent } from '@helpscout/react-utils'
import { default as Container, ID as portalContainerId } from './Container'
import Container, { ID as portalContainerId } from './Container'
import { isNodeElement } from '../../utilities/node'
import { isObject, isString } from '../../utilities/is'

export const propTypes = {
className: PropTypes.string,
Expand All @@ -18,26 +19,23 @@ export const propTypes = {
timeout: PropTypes.number,
}

const defaultProps = {
timeout: 0,
}

class Portal extends Component {
document: ?Document = null

constructor(props) {
super()
this.node = null
this.portal = null
this.isOpening = false
this.isOpen = false
this.isClosing = false
this.mountPortal = this.mountPortal.bind(this)
this.unmountPortal = this.unmountPortal.bind(this)

this.state = {
mountSelector: null,
}
class Portal extends React.Component {
static propTypes = propTypes
static defaultProps = {
timeout: 0,
}
static Container = Container
static displayName = 'Portal'

document = null
node = null
portal = null
isOpening = false
isOpen = false
isClosing = false

state = {
mountSelector: null,
}

componentDidMount() {
Expand Down Expand Up @@ -76,12 +74,11 @@ class Portal extends Component {
let mountSelector
// 1. Prioritize renderTo selector
if (renderTo) {
mountSelector = isString(renderTo)
? document.querySelector(renderTo)
: false
mountSelector =
typeof renderTo === 'string' ? document.querySelector(renderTo) : false
mountSelector =
typeof renderTo === 'object' && isNodeElement(renderTo)
? renderTo
: mountSelector
isObject(renderTo) && isNodeElement(renderTo) ? renderTo : mountSelector
}
// 2. Fallback to <Portal.Container />
mountSelector =
Expand All @@ -100,7 +97,7 @@ class Portal extends Component {
)
}

mountPortal(props, state) {
mountPortal = (props, state) => {
const { className, id, onOpen } = props

if (!this.state.mountSelector) return
Expand All @@ -111,12 +108,8 @@ class Portal extends Component {
}

this.node = document.createElement('div')
if (className) {
this.node.className = className
}
if (id) {
this.node.id = id
}
this.node.className = className
this.node.id = id
// Render to specified target, instead of document
this.state.mountSelector.appendChild(this.node)
this.renderPortalContent(props)
Expand All @@ -127,7 +120,7 @@ class Portal extends Component {
this.isOpen = true
}

unmountPortal(props) {
unmountPortal = props => {
/* istanbul ignore next */
if (!this.node) return

Expand Down Expand Up @@ -193,9 +186,4 @@ class Portal extends Component {
}
}

Portal.propTypes = propTypes
Portal.defaultProps = defaultProps
Portal.Container = Container
Portal.displayName = 'Portal'

export default Portal
37 changes: 0 additions & 37 deletions src/components/PortalWrapper/Content.js

This file was deleted.

32 changes: 32 additions & 0 deletions src/components/PortalWrapper/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react'
import { setupManager } from '../../utilities/globalManager'

const managerNamespace = 'BluePortalWrapperGlobalManager'

export interface Props {
manager: any
id: number | string
}

class Content extends React.PureComponent<Props> {
static defaultProps = {
manager: setupManager(managerNamespace),
id: 1000,
}

componentDidMount() {
const { id, manager } = this.props
manager.add(id)
}

componentWillUnmount() {
const { id, manager } = this.props
manager.remove(id)
}

render() {
return this.props.children || null
}
}

export default Content

0 comments on commit 7487031

Please sign in to comment.