From 402491743ba9df2e2d6a9285bd1777f0686c975c Mon Sep 17 00:00:00 2001 From: Tanel Vari Date: Fri, 17 Jan 2020 14:59:04 -0800 Subject: [PATCH 1/2] Testing popup --- packages/react/src/components/Popup/Popup.tsx | 44 ++++++++++++++----- .../react/src/themes/teams/animations/fade.ts | 12 +++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/packages/react/src/components/Popup/Popup.tsx b/packages/react/src/components/Popup/Popup.tsx index 7245a05c52..f3ca86f5b5 100644 --- a/packages/react/src/components/Popup/Popup.tsx +++ b/packages/react/src/components/Popup/Popup.tsx @@ -37,6 +37,7 @@ import { createShorthandFactory, ShorthandFactory } from '../../utils/factories' import createReferenceFromContextClick from './createReferenceFromContextClick' import isRightClick from '../../utils/isRightClick' import PortalInner from '../Portal/PortalInner' +import Animation from '../Animation/Animation' export type PopupEvents = 'click' | 'hover' | 'focus' | 'context' export type RestrictedClickEvents = 'click' | 'focus' @@ -176,7 +177,7 @@ export default class Popup extends AutoControlledComponent): React.ReactNode { const { inline, mountNode } = this.props const { open } = this.state - const popupContent = open && this.renderPopupContent(classes.popup, rtl, accessibility) + const popupContent = open && this.renderPopupContent(classes.popup, rtl, accessibility, open) return ( <> @@ -468,6 +471,7 @@ export default class Popup extends AutoControlledComponent ) } @@ -491,6 +501,7 @@ export default class Popup extends AutoControlledComponent { const { @@ -523,18 +534,29 @@ export default class Popup extends AutoControlledComponent {(getRefs, nestingRef) => ( <> - { - this.popupDomElement = domElement - handleRef(contentRef, domElement) - nestingRef.current = domElement - }} + - {popupContent} - + { + this.popupDomElement = domElement + handleRef(contentRef, domElement) + nestingRef.current = domElement + }} + > + {popupContent} + + Date: Mon, 20 Jan 2020 14:55:33 +0100 Subject: [PATCH 2/2] -changed Animation component to accept children as fn -fixed Popup component --- .../src/components/Animation/Animation.tsx | 22 +++++--- packages/react/src/components/Popup/Popup.tsx | 56 ++++++++++++------- 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/packages/react/src/components/Animation/Animation.tsx b/packages/react/src/components/Animation/Animation.tsx index 0ab236522b..fd6cf2020b 100644 --- a/packages/react/src/components/Animation/Animation.tsx +++ b/packages/react/src/components/Animation/Animation.tsx @@ -8,17 +8,18 @@ import { childrenExist, StyledComponentProps, commonPropTypes, - ChildrenComponentProps, ShorthandFactory, } from '../../utils' import { WithAsProp, withSafeTypeForAs } from '../../types' -export interface AnimationProps - extends StyledComponentProps, - ChildrenComponentProps { +export type AnimationChildrenProp = (props: { classes: Record }) => React.ReactNode + +export interface AnimationProps extends StyledComponentProps { /** Additional CSS class name(s) to apply. */ className?: string + children: AnimationChildrenProp | React.ReactChild + /** The name for the animation that should be applied, defined in the theme. */ name?: string @@ -168,9 +169,13 @@ class Animation extends UIComponent, any> { onExiting, } = this.props - const child = - childrenExist(children) && (React.Children.only(children) as React.ReactElement) + // const child = + // childrenExist(children) && (React.Children.only(children) as React.ReactElement) + const child = + typeof children === 'function' + ? (children as AnimationChildrenProp)({ classes }) + : childrenExist(children) && (React.Children.only(children) as React.ReactElement) return ( , any> { onExiting={onExiting} onExited={onExited} {...unhandledProps} - className={cx(classes.root, child.props.className)} + className={cx( + classes.root, + typeof child === 'object' && (child as any).props && (child as any).props.className, + )} > {child} diff --git a/packages/react/src/components/Popup/Popup.tsx b/packages/react/src/components/Popup/Popup.tsx index f3ca86f5b5..b1872b11d6 100644 --- a/packages/react/src/components/Popup/Popup.tsx +++ b/packages/react/src/components/Popup/Popup.tsx @@ -8,6 +8,7 @@ import * as React from 'react' import * as PropTypes from 'prop-types' import * as keyboardKey from 'keyboard-key' import * as _ from 'lodash' +import cx from 'classnames' import { applyAccessibilityKeyHandlers, @@ -177,7 +178,7 @@ export default class Popup extends AutoControlledComponent): React.ReactNode { const { inline, mountNode } = this.props const { open } = this.state - const popupContent = open && this.renderPopupContent(classes.popup, rtl, accessibility, open) return ( <> {this.renderTrigger(accessibility)} - {open && - (inline ? popupContent : {popupContent})} + + {({ classes: animationClasses }) => { + return inline ? ( + this.renderPopupContent(cx(classes.popup, animationClasses.root), rtl, accessibility) + ) : ( + + {this.renderPopupContent( + cx(classes.popup, animationClasses.root), + rtl, + accessibility, + )} + + ) + }} + ) } @@ -471,7 +490,6 @@ export default class Popup extends AutoControlledComponent {(getRefs, nestingRef) => ( <> - { + this.popupDomElement = domElement + handleRef(contentRef, domElement) + nestingRef.current = domElement + }} > - { - this.popupDomElement = domElement - handleRef(contentRef, domElement) - nestingRef.current = domElement - }} - > - {popupContent} - - + {popupContent} +