import * as React from 'react' ; import * as PropTypes from 'prop-types' ; import Component from '@reactions/component' ; import { LocalPopoverProps , PopoverProps , popoverPropTypes , popoverDefaultProps } from '../Popover/Popover' ; import MenuContext , { MenuProvider } from './MenuContext' ; import { MenuPopover as _MenuPopover } from './styled' ; export type LocalMenuPopoverProps = LocalPopoverProps & { children : React . ReactNode ; } ; export type MenuPopoverProps = PopoverProps & LocalMenuPopoverProps ; export const menuPopoverPropTypes = { ... popoverPropTypes , children : PropTypes . node . isRequired } ; export const menuPopoverDefaultProps = { ... popoverDefaultProps , gutter : 6 , placement : 'bottom-start' } ; export class MenuPopover extends React . Component < LocalMenuPopoverProps > { static propTypes = menuPopoverPropTypes ; static defaultProps = menuPopoverDefaultProps ; render = ( ) => { const { children , ... props } = this . props ; return ( < MenuProvider > < _MenuPopover { ... props } > { ( popover ) => ( < MenuContext . Consumer > { ( { setPopoverProps } ) => ( < Component initialState = { { isVisible : popover . isVisible } } didMount = { ( { setState } ) => { setState ( { isVisible : popover . isVisible } ) ; setPopoverProps && setPopoverProps ( popover ) ; } } didUpdate = { ( { state : { isVisible } , setState } ) => { if ( popover . isVisible !== isVisible ) { setState ( { isVisible : popover . isVisible } ) ; setPopoverProps && setPopoverProps ( popover ) ; } } } > { ( ) => children } < /Component>)} < /MenuContext.Consumer>)} < /_MenuPopover> < /MenuProvider>); } ; } const C = MenuPopover ; export default C ;