Getting Started with KendoReact Animation

The KendoReact Animation uses the TransitionGroup component to animate elements which appear, enter, or exit the viewport.

The KendoReact Animation is distributed through NPM under the kendo-react-animation package.

The Animation package is part of KendoReact, a professionally built commercial UI library. To try out this package you need to sign up for a 30-day trial, which gives you access to the full KendoReact library.

Basic Usage

The following example demonstrates the Fade, Expand, Push, Reveal, Slide, and Zoom Animation in action.

<style>
.content {
  width: 100px;
  padding: 10px;
  color: #787878;
  background-color: #fcf7f8;
  font-size: 13px;
  font-family: Helvetica, Arial, sans-serif;
  letter-spacing: 1px;
  text-align: center;
  border: 1px solid rgba(0,0,0,.05);
}
.k-radio-label {
    line-height: 1.2;
    margin-bottom: .5rem;
}
</style>
class App extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            animationType: 'slide',
            show: false
        };
    }

    handleSelect = (event) => {
        this.setState({ animationType: event.target.value });
    }
    render() {
        const { show } = this.state;

        const children = show ? (
            <div
                className="content"
            >Content
            </div >) : null;

        let animation;

        switch (this.state.animationType) {
            case 'slide':
                animation = (<Slide >{children}</Slide>);
                break;
            case 'push':
                animation = (<Push >{children}</Push>);
                break;
            case 'expand':
                animation = (<Expand >{children}</Expand>);
                break;
            case 'fade':
                animation = (<Fade >{children}</Fade>);
                break;
            case 'zoom':
                animation = (<Zoom >{children}</Zoom>);
                break;
            case 'reveal':
                animation = (<Reveal >{children}</Reveal>);
                break;
            default: animation = (<Slide >{children}</Slide>); break;
        }

        return (
            <div className="example-wrapper row">
                <div className="col-xs-12 col-sm-6 example-col">
                    {animation}
                </div>
                <div className="col-xs-12 col-sm-6 example-config">
                    <input
                        onClick={this.handleSelect}
                        id="slide"
                        className="k-radio"
                        name="type"
                        type="radio"
                        value="slide"
                        defaultChecked={true}
                    />
                    <label htmlFor="slide" className="k-radio-label">
                        &nbsp;Slide
                    </label>
                    <br />
                    <input
                        onClick={this.handleSelect}
                        name="type"
                        id="push"
                        className="k-radio"
                        type="radio"
                        value="push"
                    />
                    <label htmlFor="push" className="k-radio-label">
                        &nbsp;Push
                    </label>
                    <br />
                    <input
                        onClick={this.handleSelect}
                        name="type"
                        id="expand"
                        className="k-radio"
                        type="radio"
                        value="expand"
                    />
                    <label htmlFor="expand" className="k-radio-label">
                        &nbsp;Expand
                    </label>
                    <br />
                    <input
                        onClick={this.handleSelect}
                        name="type"
                        id="fade"
                        className="k-radio"
                        type="radio"
                        value="fade"
                    />
                    <label htmlFor="fade" className="k-radio-label">
                        &nbsp;Fade
                    </label>
                    <br />
                    <input
                        onClick={this.handleSelect}
                        name="type"
                        id="zoom"
                        className="k-radio"
                        type="radio"
                        value="zoom"
                    />
                    <label htmlFor="zoom" className="k-radio-label">
                        &nbsp;Zoom
                    </label>
                    <br />
                    <input
                        onClick={this.handleSelect}
                        name="type"
                        id="reveal"
                        className="k-radio"
                        type="radio"
                        value="reveal"
                    />
                    <label htmlFor="reveal" className="k-radio-label">
                        &nbsp;Reveal
                    </label>
                    <br />
                    <button className="k-button" type="submit" onClick={() => this.setState({ show: !this.state.show })}>Animate</button>
                </div>
            </div>
        );
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Functionality and Features

The Push and Zoom Animations further extend the Animation component, which is commonly inherited by all Animation types, and enable you to stack animations.

Installation

  1. Download and install the package. Use Node.js v5.0.0 or later.

    npm install --save @progress/kendo-react-animation
  2. Once installed, import the package module.

    // ES2015 module syntax
    import { Fade } from '@progress/kendo-react-animation';
    // CommonJS format
    const { Fade } = require('@progress/kendo-react-animation');
  3. You are required to install one of the Kendo UI themes to style your components. For more information on how to add the styles, refer to the article on getting started.

Dependencies

The Animation package requires you to install the following peer dependencies in your application:

  • react 16.8.2*
  • react-dom