import React, { Component, HTMLAttributes, ReactNode } from 'react'; import { classNames } from '../../lib/classNames'; import { HasPlatform, HasRootRef } from '../../types'; import { withAdaptivity, ViewWidth, AdaptivityProps } from '../../hoc/withAdaptivity'; import { AppRootPortal } from '../AppRoot/AppRootPortal'; import { DOMProps, withDOM } from '../../lib/dom'; export interface PopoutRootProps extends HTMLAttributes, HasPlatform, AdaptivityProps, HasRootRef { popout?: ReactNode; modal?: ReactNode; } class PopoutRoot extends Component { static defaultProps: Partial = { popout: null, }; get document() { return this.props.document; } get window() { return this.props.window; } componentDidUpdate(prevProps: PopoutRootProps) { if (this.props.popout && !prevProps.popout) { this.blurActiveElement(); } } blurActiveElement() { if (typeof this.window !== 'undefined' && this.document.activeElement) { (this.document.activeElement as HTMLElement).blur(); } } render() { const { popout, modal, viewWidth, children, className, getRootRef, window, document, ...restProps } = this.props; const isDesktop = viewWidth >= ViewWidth.TABLET; return (
{children} {!!popout &&
{popout}
} {!!modal &&
{modal}
}
); } } export default withAdaptivity(withDOM(PopoutRoot), { viewWidth: true, });