index.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import { Animation } from '@douyinfe/semi-animation-react';
  3. import { GradientPinkRed as Gradient } from '@vx/gradient';
  4. import * as easings from 'd3-ease';
  5. export default class App extends React.Component {
  6. state = { offset: 0 };
  7. path = React.createRef();
  8. componentDidMount() {
  9. this.setState({ offset: this.path.current.getTotalLength() });
  10. }
  11. render() {
  12. const { offset } = this.state;
  13. return (
  14. <div
  15. style={{
  16. background: '#272727',
  17. width: '100%',
  18. height: '100%',
  19. display: 'flex',
  20. justifyContent: 'center',
  21. alignItems: 'center',
  22. }}
  23. onClick={() => this.forceUpdate()}
  24. >
  25. <svg width="180" viewBox="0 0 23 23">
  26. <Gradient id="gradient-dashoffset" />
  27. <g fill="#373737" stroke="url(#gradient-dashoffset)" strokeWidth="0.5">
  28. <Animation
  29. reset
  30. from={{ dash: offset }}
  31. to={{ dash: 0 }}
  32. config={{
  33. duration: 3000,
  34. easing: easings.easeCubic,
  35. }}
  36. >
  37. {props => (
  38. <path
  39. ref={this.path}
  40. strokeDasharray={offset}
  41. strokeDashoffset={props.dash}
  42. d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"
  43. />
  44. )}
  45. </Animation>
  46. </g>
  47. </svg>
  48. </div>
  49. );
  50. }
  51. }