Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/workspaces/VideoCarousel.tsx
2500 views
1
/**
2
* Copyright (c) 2024 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import React, { useState } from "react";
8
import { trackVideoClick } from "../Analytics";
9
10
import "lite-youtube-embed/src/lite-yt-embed.css";
11
import "lite-youtube-embed/src/lite-yt-embed";
12
13
interface Video {
14
id: string;
15
title: string;
16
analyticsLabel: string;
17
}
18
19
const videos: Video[] = [
20
{ id: "1ZBN-b2cIB8", title: "Gitpod in 120 seconds", analyticsLabel: "gitpod-demo" },
21
{ id: "zhZNnzFlZnY", title: "Getting started with Gitpod", analyticsLabel: "getting-started-with-gitpod" },
22
{ id: "kuoHM2bpBqY", title: "Fully automate your dev setup", analyticsLabel: "automate-gitpod-setup" },
23
{ id: "_CwFzCbAsoU", title: "Personalise your workspace", analyticsLabel: "personalise-gitpod-workspace" },
24
];
25
26
declare global {
27
namespace JSX {
28
interface IntrinsicElements {
29
"lite-youtube": any;
30
}
31
}
32
}
33
34
export const VideoCarousel: React.FC = () => {
35
const [currentVideo, setCurrentVideo] = useState(0);
36
37
const handleDotClick = (index: number) => {
38
setCurrentVideo(index);
39
};
40
41
const onPlayerStateChange = (index: number) => {
42
trackVideoClick(videos[index].analyticsLabel);
43
};
44
45
return (
46
<div className="video-carousel">
47
<div className="video-container">
48
{videos.map((video, index) => (
49
<div key={video.id} style={{ display: index === currentVideo ? "block" : "none" }}>
50
{index === currentVideo && (
51
<lite-youtube
52
videoid={video.id}
53
style={{
54
width: "320px",
55
height: "180px",
56
}}
57
class="rounded-lg"
58
playlabel={video.title}
59
onClick={() => onPlayerStateChange(index)}
60
></lite-youtube>
61
)}
62
</div>
63
))}
64
</div>
65
<div className="flex justify-center space-x-2 mt-2">
66
{videos.map((_, index) => (
67
<button
68
key={index}
69
className={`w-3 h-3 rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-kumquat-dark transition-colors duration-200 ease-in-out ${
70
index === currentVideo
71
? "bg-kumquat-dark"
72
: "bg-gray-300 dark:bg-gray-600 hover:bg-kumquat-light dark:hover:bg-kumquat-light"
73
}`}
74
onClick={() => handleDotClick(index)}
75
aria-label={`Go to video ${index + 1}`}
76
></button>
77
))}
78
</div>
79
</div>
80
);
81
};
82
83