mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
added AnimationPlayer
This commit is contained in:
parent
1b5eb7c05c
commit
a69e09a2ba
41
packages/app/src/components/AnimationPlayer/index.jsx
Normal file
41
packages/app/src/components/AnimationPlayer/index.jsx
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import React from "react"
|
||||||
|
import Lottie from "lottie-react"
|
||||||
|
import classnames from "classnames"
|
||||||
|
|
||||||
|
import "./index.less"
|
||||||
|
|
||||||
|
function animationFetcher(url) {
|
||||||
|
return fetch(url)
|
||||||
|
.then((res) => res.json())
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ({
|
||||||
|
animation,
|
||||||
|
src,
|
||||||
|
loop = false,
|
||||||
|
className = [],
|
||||||
|
}) => {
|
||||||
|
const [animationData, setAnimationData] = React.useState(animation)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!animation) {
|
||||||
|
animationFetcher(src)
|
||||||
|
.then((animationData) => {
|
||||||
|
setAnimationData(animationData)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!animationData) {
|
||||||
|
return React.Fragment
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Lottie
|
||||||
|
className={classnames(
|
||||||
|
"animation-player",
|
||||||
|
...className
|
||||||
|
)}
|
||||||
|
animationData={animationData}
|
||||||
|
loop={loop}
|
||||||
|
/>
|
||||||
|
}
|
10
packages/app/src/components/AnimationPlayer/index.less
Normal file
10
packages/app/src/components/AnimationPlayer/index.less
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.animation-player {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
transition: all 150ms ease-in-out;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user