# YouTubeVideo — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/youtube_video

Category: Media

Embeds a YouTube video based on the provided video ID, handling loading states and error messages. Supports theme customization and responsive resizing.

Public component import: `YouTubeVideo`

Public manager import: `create_youtube_video_manager`

## Component notes

- aliases:
  - YoutubeVideo

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { YouTubeVideo, create_youtube_video_manager } from "sveltekit-ui"

  const manager = create_youtube_video_manager({
    video_id: "aqz-KE-bpKQ",
    is_dark_theme: false,
  })
</script>

<div style="max-width: 72rem;">
  <YouTubeVideo {manager} />
</div>
```

## Configuration

### `id`

- type: string or null
- default: generated unique ID
- description: A unique identifier for the YouTubeVideo component. If not provided, a unique ID is generated automatically.

### `video_id`

- type: string
- default: null
- description: The unique identifier of the YouTube video to embed. This is required for rendering the video.

### `is_dark_theme`

- type: boolean
- default: false
- description: Determines the theme of the embedded video. If true, applies a dark theme; otherwise, a light theme is used.

## Methods

### `render_video()`

- description: Attempts to load and render the YouTube video by checking the availability of the video thumbnail. Sets error messages if the video fails to load.

### `resize_video()`

- description: Adjusts the size of the video container to maintain a 16:9 aspect ratio, ensuring responsiveness based on the container's width.

## Returned state

### `id`

- type: string
- description: The unique identifier of the YouTubeVideo component.

### `video_id`

- type: string
- description: The YouTube video ID being embedded.

### `theme`

- type: string
- description: The current theme of the embedded video ('dark' or 'light').
