import * as anime from "animejs"; import * as _ from "lodash"; import * as React from "react"; import { CSSTransition } from 'react-transition-group'; import { Button, IButtonProps } from "../../components/Button"; import { Map, MapExtra } from "../../components/Map"; export enum StaticMapAnimation { EnteringTitleText = "entering-title-text", BouncingMapExtra = "bouncing-map-extra", } export interface IStaticMapProps { mount: boolean; mapExtra: MapExtra; /** * The `title` property is an array of strings. Each string * is a line. */ title: string[]; subtitle?: string; actions?: IButtonProps[]; animations?: StaticMapAnimation[]; renderContent?: () => any; renderBottomContent?: () => any; imagePrefix?: string; } interface IStaticMapState { mount: boolean; mapMounted?: boolean; } const defaultStaticMapState: IStaticMapState = { mount: false, mapMounted: false, }; const MOUNT_DELAY = 200; const TIME_TO_MAP_ANIMATIONS_COMPLETE = 600; const TIME_TO_MAP_TEXT_ANIMATIONS_COMPLETE = TIME_TO_MAP_ANIMATIONS_COMPLETE + 750; export class StaticMap extends React.Component { public state: IStaticMapState = defaultStaticMapState; public componentDidMount() { if (this.props.mount) { setTimeout(() => { this.setState({ mount: true, }); }, MOUNT_DELAY); } } public componentDidUpdate(prevProps: IStaticMapState, prevState: IStaticMapState) { // We want a "springy" animation for the button which isn't easily doable in CSS. So we use animejs. if (this.state.mount && !prevState.mount && document) { anime({ targets: document.querySelectorAll(".static-map .static-map__btn-group .btn"), scale: [1.1, 1], delay: TIME_TO_MAP_TEXT_ANIMATIONS_COMPLETE, }); } if (this.props.mount !== prevProps.mount) { setTimeout(() => { this.setState({ mount: this.props.mount, }); }, this.props.mount ? MOUNT_DELAY : 0); } } public render() { return ( {state => (
!!animation).map(animation => `static-map-animation--${animation}`).join(" ")}`}>
{ this.setState({ mapMounted: true, }); }}/>
{this.props.title.map((line, index) => (

{line}

))} {!_.isEmpty(this.props.subtitle) && (

{this.props.subtitle}

)} {_.isFunction(this.props.renderContent) && (
{this.props.renderContent()}
)} {!_.isEmpty(this.props.actions) && (
{this.props.actions.filter(button => !!button).map((button, index) =>
)} {_.isFunction(this.props.renderBottomContent) && (
{this.props.renderBottomContent()}
)}
)}
) } }