Skip to content

Commit

Permalink
feature: migrate to react 16, closes #135
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Kuhrt committed Oct 3, 2017
1 parent 9f46755 commit a02daf8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 96 deletions.
54 changes: 24 additions & 30 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from "react"
import { PropTypes as T } from "prop-types"
import createReactClass from "create-react-class"
import { findDOMNode } from "react-dom"
import ReactDOM from "react-dom"
import Debug from "debug"
import throttle from "lodash.throttle"
import * as cssVendor from "css-vendor"
import resizeEvent from "./on-resize"
import Layout from "./layout"
import ReactLayerMixin from "./react-layer-mixin"
import { isServer, window, document } from "./platform"
import { arrayify, clientOnly } from "./utils"
import Tip from "./tip"
Expand Down Expand Up @@ -59,7 +58,6 @@ const flowToPopoverTranslations = {


const Popover = createReactClass({
displayName: "popover",
propTypes: {
body: T.node.isRequired,
children: T.element.isRequired,
Expand All @@ -75,7 +73,6 @@ const Popover = createReactClass({
tipSize: T.number,
onOuterAction: T.func,
},
mixins: [ReactLayerMixin()],
getDefaultProps () {
return {
tipSize: 7,
Expand All @@ -98,7 +95,6 @@ const Popover = createReactClass({
}
},
componentDidMount () {
this.targetEl = findDOMNode(this)
if (this.props.isOpen) this.enter()
},
componentWillReceiveProps (propsNext) {
Expand Down Expand Up @@ -353,7 +349,6 @@ const Popover = createReactClass({

/* Get references to DOM elements. */

this.containerEl = findDOMNode(this.layerReactComponent)
this.bodyEl = this.containerEl.querySelector(".Popover-body")
this.tipEl = this.containerEl.querySelector(".Popover-tip")

Expand Down Expand Up @@ -438,38 +433,37 @@ const Popover = createReactClass({
measureFrameBounds () {
this.frameBounds = Layout.El.calcBounds(this.frameEl)
},
renderLayer () {
if (this.state.exited) return null

const { className = "", style = {}} = this.props
const { standing } = this.state;
getTargetNodeRef (targetWrapperEl) {
Object.assign(this, {
targetEl: targetWrapperEl ? targetWrapperEl.firstElementChild : null
})
},
getContainerNodeRef (containerEl) {
Object.assign(this, { containerEl })
},
render () {
const { className = "", style = {}, tipSize } = this.props
const { standing } = this.state

const popoverProps = {
className: `Popover Popover-${standing} ${className}`,
style: { ...coreStyle, ...style }
}

const tipProps = {
direction: faces[standing],
size: this.props.tipSize,
}

/* If we pass array of nodes to component children React will complain that each
item should have a key prop. This is not a valid requirement in our case. Users
should be able to give an array of elements applied as if they were just normal
children of the body component (note solution is to spread array items as args). */

const popoverBody = arrayify(this.props.body)

return (
<div {...popoverProps}>
<div className="Popover-body" children={popoverBody} />
<Tip {...tipProps} />
const popover = this.state.exited ? null : (
<div ref={this.getContainerNodeRef} {...popoverProps}>
<div className="Popover-body" children={this.props.body} />
<Tip
direction={faces[standing]}
size={tipSize}
/>
</div>
)
},
render () {
return this.props.children
return [
<div key="1" ref={this.getTargetNodeRef}>{this.props.children}</div>,
// TODO do not hardcode document.body
ReactDOM.createPortal(popover, document.body)
]
},
})

Expand Down
63 changes: 0 additions & 63 deletions lib/react-layer-mixin.js

This file was deleted.

6 changes: 3 additions & 3 deletions stories/playground/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class Main extends React.Component {
isOpen: this.state.popoverIsOpen,
preferPlace: this.state.preferPlace,
place: this.state.place,
onOuterAction: this.togglePopover.bind(null, false),
onOuterAction: this.togglePopover.bind(this, false),
body: [
<h1>Popover Title</h1>,
<div>Popover contents</div>
<h1 key="a">Popover Title</h1>,
<div key="b">Popover contents</div>
]
}

Expand Down

0 comments on commit a02daf8

Please sign in to comment.