import * as anime from "animejs"; import * as _ from "lodash"; import * as React from "react"; import { CSSTransition } from 'react-transition-group'; export enum LoadingType { /** * A simple grey, rounded background with some text. */ Static = "static", Spinner = "spinner", Aircam = "aircam", } export interface ILoadingProps { type: LoadingType; /** * Large, title text placed below any animating element. */ title?: string; /** * Smaller, explanatory text placed below the title if provided or below the animating element. */ subtitle?: string; /** * Can show & hide the loader */ mount?: boolean; } export class Loading extends React.Component { public componentDidMount() { if (this.props.type === LoadingType.Aircam) { this.startAircamLoadingAnimation(); } } public componentDidUpdate(prevProps: ILoadingProps) { if (!prevProps.mount && this.props.mount && this.props.type === LoadingType.Aircam) { this.startAircamLoadingAnimation(); } } public render() { const { type, title, subtitle, mount } = this.props; return _.isBoolean(mount) && (type === LoadingType.Spinner || type === LoadingType.Aircam) ? ( {state => (
{type === LoadingType.Aircam && ( )}
{title && (
{title}
)} {subtitle && (
{subtitle}
)}
)}
) : (
{title && (
{title}
)} {subtitle && (
{subtitle}
)}
); } private startAircamLoadingAnimation = () => { anime({ targets: '.loading .aircam path', strokeDashoffset: [anime.setDashoffset, 0], easing: 'easeInOutSine', duration: 1500, delay: function(el, i) { return i * 250 }, direction: 'forwards', // loop: true }); } }