Path: blob/main/components/dashboard/src/workspaces/VideoCarousel.tsx
2500 views
/**1* Copyright (c) 2024 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import React, { useState } from "react";7import { trackVideoClick } from "../Analytics";89import "lite-youtube-embed/src/lite-yt-embed.css";10import "lite-youtube-embed/src/lite-yt-embed";1112interface Video {13id: string;14title: string;15analyticsLabel: string;16}1718const videos: Video[] = [19{ id: "1ZBN-b2cIB8", title: "Gitpod in 120 seconds", analyticsLabel: "gitpod-demo" },20{ id: "zhZNnzFlZnY", title: "Getting started with Gitpod", analyticsLabel: "getting-started-with-gitpod" },21{ id: "kuoHM2bpBqY", title: "Fully automate your dev setup", analyticsLabel: "automate-gitpod-setup" },22{ id: "_CwFzCbAsoU", title: "Personalise your workspace", analyticsLabel: "personalise-gitpod-workspace" },23];2425declare global {26namespace JSX {27interface IntrinsicElements {28"lite-youtube": any;29}30}31}3233export const VideoCarousel: React.FC = () => {34const [currentVideo, setCurrentVideo] = useState(0);3536const handleDotClick = (index: number) => {37setCurrentVideo(index);38};3940const onPlayerStateChange = (index: number) => {41trackVideoClick(videos[index].analyticsLabel);42};4344return (45<div className="video-carousel">46<div className="video-container">47{videos.map((video, index) => (48<div key={video.id} style={{ display: index === currentVideo ? "block" : "none" }}>49{index === currentVideo && (50<lite-youtube51videoid={video.id}52style={{53width: "320px",54height: "180px",55}}56class="rounded-lg"57playlabel={video.title}58onClick={() => onPlayerStateChange(index)}59></lite-youtube>60)}61</div>62))}63</div>64<div className="flex justify-center space-x-2 mt-2">65{videos.map((_, index) => (66<button67key={index}68className={`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 ${69index === currentVideo70? "bg-kumquat-dark"71: "bg-gray-300 dark:bg-gray-600 hover:bg-kumquat-light dark:hover:bg-kumquat-light"72}`}73onClick={() => handleDotClick(index)}74aria-label={`Go to video ${index + 1}`}75></button>76))}77</div>78</div>79);80};818283