bg-media
cult-ui/bg-mediaUnverifiedComponent
Background media component with video/image support and overlay effects
Install it
npx shadcn@latest add https://raw.githubusercontent.com/nolly-studio/cult-ui/HEAD/apps/www/bg-media.jsonSource
1"use client"23import React, { useRef, useState } from "react"4import { cva } from "class-variance-authority"56import { cn } from "@/lib/utils"78// Make sure this utility exists in your project for combining class names910// Define the type for the variant and type props11type OverlayVariant = "none" | "light" | "dark"12type MediaType = "image" | "video"1314// Update the cva call with these types15const backgroundVariants = cva(16 "relative h-screen max-h-[1000px] w-full min-h-[500px] lg:min-h-[600px]",17 {18 variants: {19 overlay: {20 none: "",21 light:22 "before:absolute before:inset-0 before:bg-white before:opacity-30",23 dark: "before:absolute before:inset-0 before:bg-black before:opacity-30",24 },25 type: {26 image: "",27 video: "z-10",28 },29 },30 defaultVariants: {31 overlay: "none",32 type: "image",33 },34 }35)3637interface BackgroundMediaProps {38 variant?: OverlayVariant39 type?: MediaType40 src: string41 alt?: string42}4344export const BackgroundMedia: React.FC<BackgroundMediaProps> = ({45 variant = "light",46 type = "image",47 src,48 alt = "",49}) => {50 const [isPlaying, setIsPlaying] = useState(true)51 const mediaRef = useRef<HTMLVideoElement | null>(null)5253 const toggleMediaPlay = () => {54 if (type === "video" && mediaRef.current) {55 if (isPlaying) {56 mediaRef.current.pause()57 } else {58 mediaRef.current.play()59 }60 setIsPlaying(!isPlaying)61 }62 }6364 const mediaClasses = cn(65 backgroundVariants({ overlay: variant, type }),66 "overflow-hidden"67 )6869 const renderMedia = () => {70 if (type === "video") {71 return (72 <video73 ref={mediaRef}74 aria-hidden="true"75 muted76 className="absolute inset-0 h-full w-full object-cover transition-opacity duration-300 pointer-events-none"77 autoPlay78 playsInline79 >80 <source src={src} type="video/mp4" />81 Your browser does not support the video tag.82 </video>83 )84 } else {85 return (86 <img87 src={src}88 alt={alt}89 className="absolute inset-0 h-full w-full object-cover rounded-br-[88px]"90 loading="eager"91 />92 )93 }94 }9596 return (97 <div className={mediaClasses}>98 {renderMedia()}99 {type === "video" && (100 <button101 aria-label={isPlaying ? "Pause video" : "Play video"}102// … truncated
Files it writes
More from cult/ui
All 157 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-instructionsai-instructions | cult/ui | Components | Unverified | 2 deps | |
| ai-instructions-demoai-instructions-demo | cult/ui | Components | Unverified | no deps | |
| animated-numberanimated-number | cult/ui | Components | Unverified | 1 dep | |
| animated-number-demoanimated-number-demo | cult/ui | Components | Unverified | no deps | |
| bg-animate-buttonbg-animate-button | cult/ui | Components | Unverified | no deps | |
| bg-animate-button-demobg-animate-button-demo | cult/ui | Components | Unverified | no deps | |
| bg-animated-fractal-dot-gridbg-animated-fractal-dot-grid | cult/ui | Components | Unverified | 1 dep | |
| bg-animated-fractal-dot-grid-demobg-animated-fractal-dot-grid-demo | cult/ui | Components | Unverified | no deps |
