diff --git a/packages/pebble-web/src/components/DropDown.tsx b/packages/pebble-web/src/components/DropDown.tsx index deafaefd..721033ed 100644 --- a/packages/pebble-web/src/components/DropDown.tsx +++ b/packages/pebble-web/src/components/DropDown.tsx @@ -90,7 +90,6 @@ class DropDown extends React.PureComponent { )} - {/* TODO: Add native flag. */} {transitionStyles => ( { ...style, ...transitionStyles, backgroundColor: colors.white.base, - transform: `${style.transform || ""} ${ - transitionStyles.transform || "" - }`, + transform: + transitionStyles.transform?.interpolate( + t => `${style.transform || ""} ${t}` + ) || style.transform, transformOrigin: `${arrowProps.style.left || 0}px ${ arrowProps.style.top || 0 }px`, @@ -113,7 +113,7 @@ class DropDown extends React.PureComponent { }; return ( -
{ toggle: this.toggleDropdown, isOpen: _isDropDownOpen })} -
+
); }} diff --git a/packages/pebble-web/src/components/Modal.tsx b/packages/pebble-web/src/components/Modal.tsx index 6f4d7fff..b9818fbe 100644 --- a/packages/pebble-web/src/components/Modal.tsx +++ b/packages/pebble-web/src/components/Modal.tsx @@ -1,10 +1,11 @@ import * as React from "react"; import { ModalProps } from "./typings/Modal"; import { modalContainer } from "./styles/Modal.styles"; -import { cx, css } from "emotion"; +import { cx } from "emotion"; import isBrowser from "is-in-browser"; import * as ReactDOM from "react-dom"; import MountTransition from "./shared/MountTransition"; +import { animated } from "react-spring/renderprops.cjs"; class Modal extends React.PureComponent { private node = isBrowser ? document.createElement("div") : null; @@ -41,23 +42,21 @@ class Modal extends React.PureComponent { // tslint:disable-next-line:jsx-wrap-multiline {transitionStyles => ( -
-
{children} -
-
+ + )}
, node as NonNullable diff --git a/packages/pebble-web/src/components/Popper.tsx b/packages/pebble-web/src/components/Popper.tsx index f3411f06..18a6ed43 100644 --- a/packages/pebble-web/src/components/Popper.tsx +++ b/packages/pebble-web/src/components/Popper.tsx @@ -6,6 +6,7 @@ import { colors } from "pebble-shared"; import { cx } from "emotion"; import OutsideClick from "./OutsideClick"; import MountTransition from "./shared/MountTransition"; +import { animated } from "react-spring/renderprops.cjs"; export default class PebblePopper extends React.PureComponent< PopperProps, @@ -71,16 +72,17 @@ export default class PebblePopper extends React.PureComponent< ...style, ...transitionStyles, backgroundColor: popperBackgroundColor, - transform: `${style.transform || ""} ${ - transitionStyles.transform || "" - }`, + transform: + transitionStyles.transform?.interpolate( + t => `${style.transform || ""} ${t}` + ) || style.transform, transformOrigin: `${arrowProps.style.left || 0}px ${ arrowProps.style.top || 0 }px` }; return ( -
- + ); }} diff --git a/packages/pebble-web/src/components/Sidebar.tsx b/packages/pebble-web/src/components/Sidebar.tsx index 0e383567..c0077675 100644 --- a/packages/pebble-web/src/components/Sidebar.tsx +++ b/packages/pebble-web/src/components/Sidebar.tsx @@ -61,10 +61,10 @@ class SideBar extends React.PureComponent { return ( - {styles => ( + {transitionStyles => ( <> { data-testid="shadowArea" /> - +
diff --git a/packages/pebble-web/src/components/shared/MountTransition.tsx b/packages/pebble-web/src/components/shared/MountTransition.tsx index 44d21e39..8596ae8c 100644 --- a/packages/pebble-web/src/components/shared/MountTransition.tsx +++ b/packages/pebble-web/src/components/shared/MountTransition.tsx @@ -6,12 +6,15 @@ import { } from "react-spring/renderprops.cjs"; import { animationConfig } from "../../utils/animation"; import { Omit } from "utility-types"; +import { AnimatedValue } from "react-spring"; + +type TransitionStyles = AnimatedValue; interface MountTransitionProps extends Omit, "items">, "children"> { visible: boolean; children: ( - params: React.CSSProperties, + styles: TransitionStyles, state: State, index: number ) => React.ReactNode; @@ -19,10 +22,10 @@ interface MountTransitionProps const MountTransition: React.FunctionComponent = props => { return ( - + {(show, state, index) => show && - (styles => props.children(styles as React.CSSProperties, state, index)) + (styles => props.children(styles as TransitionStyles, state, index)) } ); diff --git a/packages/pebble-web/src/utils/animation.ts b/packages/pebble-web/src/utils/animation.ts index 72dc8937..4e8dad42 100644 --- a/packages/pebble-web/src/utils/animation.ts +++ b/packages/pebble-web/src/utils/animation.ts @@ -1,9 +1,14 @@ -import { State } from "react-spring"; +import { State, SpringConfig } from "react-spring"; + +const isProd = process.env.NODE_ENV === "production"; + +const [duration, durationLeave] = isProd ? [200, 80] : [1000, 500]; export const animationConfig = { from: { opacity: 0, transform: "scale(0.95)" }, enter: { opacity: 1, transform: "scale(1)" }, leave: { opacity: 0, transform: "scale(0.95)", pointerEvents: "none" }, - config: (_a: boolean, motion: State) => - motion === "leave" ? { duration: 80 } : { duration: 200 } + config: (_a: boolean, motion: State): SpringConfig => ({ + duration: motion === "leave" ? durationLeave : duration + }) };