Skip to content

Commit

Permalink
feat(Popup): add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Nov 14, 2016
1 parent ece3893 commit e95e98e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/modules/Popup/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getElementType,
getUnhandledProps,
isBrowser,
makeDebugger,
META,
SUI,
useKeyOnly,
Expand All @@ -14,6 +15,8 @@ import Portal from '../../addons/Portal'
import PopupContent from './PopupContent'
import PopupHeader from './PopupHeader'

const debug = makeDebugger('popup')

const _meta = {
name: 'Popup',
type: META.TYPES.MODULE,
Expand Down Expand Up @@ -234,13 +237,16 @@ export default class Popup extends Component {
portalProps.closeOnTriggerBlur = true
break

default: // default to hover
case 'hover':
portalProps.openOnTriggerMouseOver = true
portalProps.closeOnTriggerMouseLeave = true
// Taken from SUI: https://git.io/vPmCm
portalProps.mouseLeaveDelay = 70
portalProps.mouseOverDelay = 50
break

default:
break
}

if (hoverable) {
Expand All @@ -258,18 +264,21 @@ export default class Popup extends Component {
}

handleClose = (e) => {
debug('handleClose()')
const { onClose } = this.props
if (onClose) onClose(e, this.props)
}

handleOpen = (e) => {
debug('handleOpen()')
this.coords = e.currentTarget.getBoundingClientRect()

const { onOpen } = this.props
if (onOpen) onOpen(e, this.props)
}

handlePortalMount = (e) => {
debug('handlePortalMount()')
if (this.props.hideOnScroll) {
window.addEventListener('scroll', this.hideOnScroll)
}
Expand All @@ -279,11 +288,13 @@ export default class Popup extends Component {
}

handlePortalUnmount = (e) => {
debug('handlePortalUnmount()')
const { onUnmount } = this.props
if (onUnmount) onUnmount(e, this.props)
}

popupMounted = (ref) => {
debug('popupMounted()')
this.popupCoords = ref ? ref.getBoundingClientRect() : null
this.setPopupStyle()
}
Expand Down Expand Up @@ -333,10 +344,12 @@ export default class Popup extends Component {
</ElementType>
)

const mergedPortalProps = { ...this.getPortalProps(), ...portalProps }
debug('portal props:', mergedPortalProps)

return (
<Portal
{...this.getPortalProps()}
{...portalProps}
{...mergedPortalProps}
trigger={trigger}
onClose={this.handleClose}
onMount={this.handlePortalMount}
Expand Down

0 comments on commit e95e98e

Please sign in to comment.