Packages

Introduction

The video components are built on top of the hooks and provide a complete video player solution with built-in controls, auto-hide functionality, and keyboard shortcuts.

Install

npm install @zuude-ui/video

VideoProvider (Required)

The main context provider that wraps your video player and provides global state management.

PropTypeDescriptionDefault
childrenReactNodeVideo player components-
onError(error: string) => voidError callback function-
classNamestringCSS classes for the wrapper-
...propsReact.ComponentProps<"div">Div element props-

Example:

import { VideoProvider } from "@zuude-ui/video";

const VideoPlayer = () => {
  return (
    <VideoProvider onError={(error) => console.log(error)}>
      {/* Your video player components */}
    </VideoProvider>
  );
};

Video

The main video component that renders the HTML video element.

PropTypeDescriptionDefault
srcstringVideo source URL-
refRefObject<HTMLVideoElement>Video element reference-
classNamestringCSS classes for the video element-
autoPlayboolean | "force"Auto-play the video-
controlsbooleanShow/hide controlstrue
muteFallback(onMute: () => void) => React.ReactNodeCustom UI for autoplay blocked-
autoPlayOnVisibleboolean | numberAuto-play the video when visible-
rangesnumber[]Ranges for the video-
playsInlinebooleanPlays inline the videotrue
...propsReact.ComponentProps<"video">Video element props-

Example:

import { Video } from "@zuude-ui/video";

const VideoPlayer = () => {
  const videoRef = useRef<HTMLVideoElement>(null);

  return (
    <VideoProvider>
      <Video
        ref={videoRef}
        src="https://example.com/video.mp4"
        className="w-full aspect-video object-cover rounded-lg"
        autoPlay
        muted
        loop
        onClick={() => console.log("Video clicked")}
        onLoadedMetadata={() => console.log("Metadata loaded")}
      />
    </VideoProvider>
  );
};

Good to Know

If you don't specify a ref prop, the video component will use its own internal ref. If you provide your own ref prop, the component will use that instead. This allows you to either let the component handle the ref internally or have direct access to the video element when needed.