Skip to content

Commit 13eeaec

Browse files
committed
[FEAT]: Add new component VideoPreview to prform video preview on full screen
1 parent 1c8aa9b commit 13eeaec

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.video-container {
2+
position: fixed;
3+
display: flex;
4+
align-items: center;
5+
justify-content: center;
6+
width: 100%;
7+
height: 100%;
8+
top: 0;
9+
left: 0;
10+
background: rgba(0, 0, 0, 0.734);
11+
transform: translate(100%);
12+
transition: transform 0.2s ease-in-out;
13+
&.show {
14+
transform: translate(0);
15+
}
16+
z-index: 4;
17+
}
18+
.vid-rel-container {
19+
position: relative;
20+
height: 80%;
21+
//width: 60%;
22+
max-width: 95%;
23+
@media (max-width: 600px) {
24+
width: 80%;
25+
height: auto;
26+
}
27+
@media (max-width: 960px) {
28+
width: 90%;
29+
height: auto;
30+
}
31+
}
32+
.video-full-screen {
33+
//width: 100%;
34+
// height: 100%;
35+
//max-height: 80%;
36+
//max-width: 80%;
37+
position: relative;
38+
transform: scale(0);
39+
border-radius: 10px;
40+
transition: transform 0.3s 0.2s;
41+
&.show-video {
42+
transform: scale(1);
43+
}
44+
}
45+
.button-full-screen {
46+
//top: 0;
47+
//right: 0;
48+
position: absolute;
49+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React, { FC, Fragment } from "react";
2+
import { useEffect } from "react";
3+
import { useState } from "react";
4+
import { useRef } from "react";
5+
import { Cancel } from "../icons";
6+
import { VideoPreviewProps } from "./VideoPreviewProps";
7+
import "./VideoPreview.scss";
8+
const VideoPreview: FC<VideoPreviewProps> = (props: VideoPreviewProps) => {
9+
const { videoSrc, openVideo, onClose, autoplay, controls , style} = props;
10+
const videoRef = useRef<HTMLVideoElement>(null);
11+
const [source, setSource] = useState<string | undefined>(undefined);
12+
13+
useEffect(() => {
14+
if (!videoSrc) {
15+
return;
16+
}
17+
if (typeof videoSrc === "string") {
18+
setSource(videoSrc);
19+
} else {
20+
const newVideoSrc = URL.createObjectURL(videoSrc);
21+
setSource(newVideoSrc);
22+
}
23+
}, [videoSrc]);
24+
useEffect(() => {
25+
if (source && videoRef.current) {
26+
videoRef.current.load();
27+
}
28+
}, [source]);
29+
30+
31+
32+
function handleClose<T extends HTMLDivElement>(
33+
e: React.MouseEvent<T, MouseEvent>
34+
): void {
35+
e.stopPropagation();
36+
onClose?.();
37+
}
38+
if (videoSrc) {
39+
return (
40+
<div
41+
className={openVideo ? "video-container show" : "video-container"}
42+
onClick={handleClose}
43+
>
44+
{videoSrc && openVideo && (
45+
<div
46+
className="vid-rel-container"
47+
onClick={(evt) => {
48+
evt.preventDefault();
49+
}}
50+
>
51+
<video
52+
onClick={(evt) => {
53+
evt.preventDefault();
54+
}}
55+
//onLoadedMetadata={handleLoaded}
56+
id="dropzone-ui-video"
57+
controls={controls}
58+
ref={videoRef}
59+
className={"video-full-screen show-video"}
60+
autoPlay={autoplay}
61+
src={source}
62+
width={"100%"}
63+
height={"100%"}
64+
style={style}
65+
>
66+
<source type="video/webm" />
67+
<source type="video/ogg" />
68+
<source type="video/mp4" />
69+
</video>
70+
<Cancel
71+
color="rgba(255,255,255,0.8)"
72+
onClick={handleClose}
73+
colorFill="black"
74+
className="button-full-screen"
75+
/>
76+
</div>
77+
)}
78+
</div>
79+
);
80+
} else {
81+
return <Fragment></Fragment>;
82+
}
83+
};
84+
export default VideoPreview;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { OverridableProps } from "@unlimited-react-components/kernel";
2+
3+
export interface VideoPreviewProps extends OverridableProps {
4+
/**
5+
* video source in string format or File object
6+
* FileItemComponent returns this value in onWatch handler
7+
*/
8+
videoSrc: File | string;
9+
/**
10+
* boolean value. Whether to open the preview or not
11+
*/
12+
openVideo?: boolean;
13+
/**
14+
* handler for on Close operation
15+
*/
16+
onClose?: Function;
17+
/**
18+
* boolean value. Whether to play automatically the video or not.
19+
*/
20+
autoplay?: boolean;
21+
/**
22+
* boolean value. Whether to display the controls in the video player or not.
23+
*/
24+
controls?: boolean;
25+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export * from "./components/file-item/components/FileItemContainer/FileItemConta
3131
export { default as FullScreenPreview } from "./components/image-preview/FullScreenPreview";
3232
export * from "./components/image-preview/FullScreenPreview";
3333

34+
export { default as VideoPreview } from "./components/video-preview/VideoPreview";
35+
export * from "./components/video-preview/VideoPreview";
36+
3437
export { default as InputButton } from "./components/input-button/InputButton";
3538
export * from "./components/input-button/InputButton";
3639

0 commit comments

Comments
 (0)