This repository has been archived by the owner on Nov 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GBA bios style intro animation component
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { forwardRef, useState } from "react"; | ||
import BiosAnimation from "../../assets/bios_animation.mp4"; | ||
|
||
interface IntroAnimationPlayerProps { | ||
onVideoEnded?: () => void; | ||
} | ||
const IntroAnimationPlayerPlayer = forwardRef(function _introAnimationPlayer( | ||
{ onVideoEnded = () => {} }: IntroAnimationPlayerProps, | ||
ref: React.Ref<HTMLVideoElement> | ||
) { | ||
const [isVideoEnded, setIsVideoEnded] = useState(false); | ||
const handleVideoEnded = () => { | ||
setIsVideoEnded(true); | ||
onVideoEnded(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<video | ||
className={ | ||
isVideoEnded | ||
? "transition-opacity ease-out duration-700 opacity-0" | ||
: "transition-opacity ease-in duration-100 opacity-100" | ||
} | ||
preload="auto" | ||
ref={ref} | ||
onEnded={handleVideoEnded} | ||
onPlay={() => setIsVideoEnded(false)} | ||
> | ||
<source src={BiosAnimation} type="video/mp4" /> | ||
Your browser does not support HTML5 video. | ||
</video> | ||
</> | ||
); | ||
}); | ||
|
||
export default IntroAnimationPlayerPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import IntroAnimationPlayer from "@/components/wasmgba/IntroAnimationPlayer"; | ||
import { useRef, useState } from "react"; | ||
import { Button } from "@/components/ui/button"; | ||
|
||
const meta: Meta<typeof IntroAnimationPlayer> = { | ||
component: IntroAnimationPlayer, | ||
argTypes: { | ||
onVideoEnded: { | ||
action: "videoEnded", | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
}, | ||
args: { | ||
onVideoEnded: () => {}, | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<div className="flex flex-col justify-center items-center space-y-2"> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof IntroAnimationPlayer>; | ||
export const Default: Story = { | ||
render: ({ ...args }) => { | ||
const playerRef = useRef<HTMLVideoElement | null>(null); | ||
|
||
return ( | ||
<> | ||
<span onClick={() => playerRef.current?.play()} | ||
className="border-2"> | ||
<IntroAnimationPlayer | ||
ref={playerRef} | ||
onVideoEnded={args.onVideoEnded} | ||
/> | ||
</span> | ||
{/* <Button onClick={() => playerRef.current?.play()}>Play</Button> */} | ||
</> | ||
); | ||
}, | ||
}; |