index.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react';
  2. import { Animation } from '@douyinfe/semi-animation-react';
  3. import './style.scss';
  4. const LOREM = 'Hello world';
  5. export default class App extends React.Component {
  6. state = { toggle: true, text: [LOREM] };
  7. onToggle = () => this.setState(state => ({ toggle: !state.toggle }));
  8. onAddText = () => this.setState(state => ({ toggle: true, text: [...state.text, LOREM] }));
  9. onRemoveText = () => this.setState(state => ({ toggle: true, text: state.text.slice(1) }));
  10. render() {
  11. const { toggle, text } = this.state;
  12. return (
  13. <div className="semi-animation-react-demo-auto">
  14. <div className="auto-main">
  15. <button onClick={this.onToggle}>Toggle</button>
  16. <button onClick={this.onAddText}>Add text</button>
  17. <button onClick={this.onRemoveText}>Remove text</button>
  18. <div className="content">
  19. <Animation
  20. force
  21. config={{ duration: 200, easing: toggle ? 'easeInCubic' : 'easeOutCubic' }}
  22. from={{ height: toggle ? 0 : 38 * text.length }}
  23. to={{ height: toggle ? 38 * text.length : 0 }}
  24. >
  25. {props => (
  26. <div className="item" style={props}>
  27. {text.map((t, i) => (
  28. <p key={i}>{t}</p>
  29. ))}
  30. </div>
  31. )}
  32. </Animation>
  33. </div>
  34. </div>
  35. </div>
  36. );
  37. }
  38. }