-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: APP-313 add video controls (#2461)
Co-authored-by: Ralph <“[email protected]>
- Loading branch information
Showing
14 changed files
with
149 additions
and
66 deletions.
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
15 changes: 0 additions & 15 deletions
15
web-components/src/components/atoms/PlayButton/PlayButton.stories.tsx
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
web-components/src/components/atoms/PlayButton/PlayButton.tsx
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
web-components/src/components/atoms/PlayPauseButton/PlayPauseButton.stories.tsx
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,26 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { PlayPauseButton } from './PlayPauseButton'; | ||
|
||
export default { | ||
title: 'atoms/PlayPauseButton', | ||
component: PlayPauseButton, | ||
} as Meta<typeof PlayPauseButton>; | ||
|
||
type Story = StoryObj<typeof PlayPauseButton>; | ||
|
||
export const Play: Story = { | ||
render: args => <PlayPauseButton {...args} />, | ||
}; | ||
|
||
Play.args = { | ||
playing: false, | ||
}; | ||
|
||
export const Pause: Story = { | ||
render: args => <PlayPauseButton {...args} />, | ||
}; | ||
|
||
Pause.args = { | ||
playing: true, | ||
}; |
4 changes: 2 additions & 2 deletions
4
...nts/atoms/PlayButton/PlayButton.styles.ts → ...PlayPauseButton/PlayPauseButton.styles.ts
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
32 changes: 32 additions & 0 deletions
32
web-components/src/components/atoms/PlayPauseButton/PlayPauseButton.tsx
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,32 @@ | ||
import { cn } from '../../../utils/styles/cn'; | ||
import { PauseIcon } from '../../icons/PauseIcon'; | ||
import PlayIcon from '../../icons/PlayIcon'; | ||
import { usePlayPauseButtonStyles } from './PlayPauseButton.styles'; | ||
|
||
type Props = { | ||
className?: string; | ||
playing?: boolean; | ||
handlePlayPause?: () => void; | ||
}; | ||
|
||
export const PlayPauseButton = ({ | ||
className, | ||
playing = false, | ||
handlePlayPause, | ||
}: Props) => { | ||
const { classes: styles } = usePlayPauseButtonStyles(); | ||
return ( | ||
<button | ||
onClick={handlePlayPause ? handlePlayPause : undefined} | ||
className="outline-none cursor-pointer bg-transparent border-none" | ||
> | ||
<div className={cn(styles.button, className)}> | ||
{playing ? ( | ||
<PauseIcon width="100%" height="100%" /> | ||
) : ( | ||
<PlayIcon width="50%" height="50%" /> | ||
)} | ||
</div> | ||
</button> | ||
); | ||
}; |
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
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,21 @@ | ||
export const PauseIcon = (props: React.SVGProps<SVGSVGElement>) => ( | ||
<svg viewBox="0 0 70 70" {...props}> | ||
<g id="Pause icon"> | ||
<circle | ||
id="Ellipse 3" | ||
cx="35" | ||
cy="35" | ||
r="35" | ||
fill="white" | ||
fill-opacity="0.9" | ||
/> | ||
<path | ||
id="Union" | ||
fill-rule="evenodd" | ||
clip-rule="evenodd" | ||
d="M32 20H25V50H32V20ZM45 20H38V50H45V20Z" | ||
fill="#4FB573" | ||
/> | ||
</g> | ||
</svg> | ||
); |
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
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
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
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
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
50 changes: 50 additions & 0 deletions
50
web-components/src/components/organisms/PostFiles/components/VideoPreview.tsx
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,50 @@ | ||
import { useState } from 'react'; | ||
import ReactPlayer from 'react-player/es6'; | ||
import { PlayPauseButton } from 'web-components/src/components/atoms/PlayPauseButton/PlayPauseButton'; | ||
|
||
export const VideoPreview = ({ | ||
url, | ||
buttonClassName = '', | ||
}: { | ||
url: string; | ||
buttonClassName?: string; | ||
}) => { | ||
const [playing, setPlaying] = useState(false); | ||
const [hovered, setHovered] = useState(false); | ||
|
||
const handlePlayPause = () => { | ||
setPlaying(!playing); | ||
}; | ||
const handleMouseEnter = () => { | ||
setHovered(true); | ||
}; | ||
const handleMouseLeave = () => { | ||
setHovered(false); | ||
}; | ||
|
||
return ( | ||
<div className="relative h-full"> | ||
<ReactPlayer | ||
url={url} | ||
width="100%" | ||
height="100%" | ||
playing={playing} | ||
controls={false} | ||
onEnded={() => setPlaying(false)} | ||
/> | ||
<div | ||
className={`z-50 absolute top-0 left-0 w-full h-full flex justify-center items-center ${ | ||
playing ? 'transition-opacity duration-500 opacity-0' : '' | ||
} ${playing && hovered ? 'hover:opacity-100' : ''}`} | ||
onMouseEnter={playing ? handleMouseEnter : undefined} | ||
onMouseLeave={playing ? handleMouseLeave : undefined} | ||
> | ||
<PlayPauseButton | ||
playing={playing} | ||
handlePlayPause={handlePlayPause} | ||
className={buttonClassName} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |