index.jsx 1.8 KB

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