BloksMoleculeYoutube Embed

Youtube Embed

Description

The Youtube Embed component allows you to easily embed YouTube videos into your Storyblok-powered website. It provides a customizable interface with options for autoplay, controls, and width settings. The component displays a thumbnail preview with a play button, which transforms into the actual video embed when clicked.

Installation

bash
sabaccui add youtubeEmbed

Usage

Here's an example of how to use the Youtube Embed component in a Storyblok block:

Preview

Schema

FieldTypeDescriptionDefault
urltextThe YouTube video URL. Must be a valid YouTube URL.Required
autoplaybooleanDetermines if the video should autoplay when embedded.false
controlsbooleanDetermines if video controls should be displayed.true
widthoptionSets the width of the video. Options: fullWidthnull

None specified.

Notes

  1. The component uses a regex pattern to validate the YouTube URL format.
  2. It fetches the video thumbnail and title using the YouTube oEmbed API.
  3. The component implements a lazy-loading strategy for the iframe, only loading it when the play button is clicked. Thus reducing initial page load times and complying with cookie consent policies.

Best practices:

  • Ensure the YouTube URL is correct and accessible.
  • Use the fullWidth option for responsive layouts.
  • Be mindful of content restrictions and copyright when embedding videos.