English

Animation

A transition animation component.

Base
import React, {Component} from 'react';
import {Animation, Button} from 'hana-ui';

/**
 * @en
 * Base
 *
 * `THE CUBE` can changed its position.
 *
 * @cn
 * 基础
 *
 * 一个可以滑动的小方块。
 */
export default class ExampleBase extends Component {
  state = {
    begin: true
  }

  render() {
    const cubeStyle = {
      width: 40,
      height: 40,
      background: '#6cf',
      borderRadius: 5
    };

    const wrapperStyle = {
      height: 40,
      width: 400,
      padding: 5,
      background: '#ddd',
      borderRadius: 5
    };
    return (
      <div>
        <div style={wrapperStyle}>
          <Animation
            animation={{left: this.state.begin ? 0 : 360}}
            duration={400}
          >
            {style => <div
              style={Object.assign({}, cubeStyle, {
                WebkitTransform: `translate3d(${style.left}px, 0, 0)`,
                transform: `translate3d(${style.left}px, 0, 0)`
              })}
            />}
          </Animation>
        </div>
        <br />
        <Button onClick={() => this.setState({begin: !this.state.begin})}>Move</Button>
      </div>
    );
  }
}

THE CUBE can changed its position.


Properties

Name Type Default Description
children function children
duration number 1000 animation's duration
animation any the animation
onStart function () => {} the callback when the animation start
onEnd function () => {} the callback when the animation end
easing enum:
 'easeCubicInOut'
 'easeLinear'
 'easePolyInOut'
 'easeQuadInOut'
 'easeSinInOut'
 'easeExpInOut'
 'easeCircleInOut'
'easeCubicInOut' ease func, see more

Other properties (no documented) are applied to the root or form element.