1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-10-16 23:17:26 +00:00
festa/components/postcard/renderer.tsx

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-06-11 03:08:49 +00:00
import { default as classNames } from "classnames"
import style from "./renderer.module.css"
import { useDefinedContext } from "../../utils/definedContext"
2022-07-20 22:30:09 +00:00
import { PostcardContext, PostcardSource, PostcardVisibility } from "./base"
import { LegacyRef, useEffect, useRef } from "react"
2022-06-11 03:08:49 +00:00
export function PostcardRenderer() {
const { previousSrc, currentSrc, visibility } = useDefinedContext(PostcardContext)
const currentRef: LegacyRef<HTMLImageElement> = useRef(null)
2022-06-11 03:08:49 +00:00
useEffect(
() => {
if (currentRef.current) {
currentRef.current.animate(
[
{ opacity: 0 },
{ opacity: 1 },
],
{
duration: 1000
}
)
}
},
[currentRef, currentSrc]
)
2022-07-20 19:34:27 +00:00
return <>
<img
src={previousSrc}
2022-07-16 14:07:16 +00:00
alt=""
2022-06-11 03:08:49 +00:00
className={classNames(
style.postcard,
style.postcardPrevious,
2022-06-11 03:08:49 +00:00
visibility === PostcardVisibility.BACKGROUND ? style.postcardBackground : null,
visibility === PostcardVisibility.FOREGROUND ? style.postcardForeground : null,
)}
/>
<img
src={currentSrc}
alt=""
ref={currentRef}
className={classNames(
style.postcard,
style.postcardCurrent,
visibility === PostcardVisibility.BACKGROUND ? style.postcardBackground : null,
visibility === PostcardVisibility.FOREGROUND ? style.postcardForeground : null,
)}
/>
</>
2022-06-11 03:08:49 +00:00
}