3.0.0 • Published 2 years ago

@asemirsk/youtube v3.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

YouTube Component

The YouTube Component can be used to place a YouTube video on a page via the BodilessJS edit interface. The YouTube Component is responsive and features a 16:9 ratio by default.

Content Editor Details

To add a YouTube Component to your site:

  1. In Edit Mode, select the YouTube Component from the Component Library.
    YouTube Component in Component Library

  2. Click on your newly added YouTube Component, and, within its context menu, under "YouTube," click Settings.
    YouTube Configuration form

  3. Enter the target YouTube URL, and click the checkmark (or press Enter) to confirm.

  4. Resize or reposition the YouTube Component using the Flow Container controls.


Site Builder Details

The YouTube Component can be used to place a YouTube video on a page via the BodilessJS edit interface.

?> Please note that the Embed Component must be activated on your site for the YouTube Component to work.

  import { YouTube } from '@bodiless/youtube';

  <YouTube nodeKey="youtube" />

You can also use the HOC version of this which can then be applied to other components. But the underlining component must accept the same props as an iframe tag. Simply pass the node key to the asBodilessYouTube function and then use the returned HOC

import { CustomYouTube } from 'my-library';
import { asBodilessYouTube } from '@bodiless/youtube';

const YouTube = asBodilessYouTube('customYouTube')(CustomYouTube);

<YouTube />

You can configure YouTube player settings leveraging withYouTubePlayerSettings HOC. For example, to configure AutoPlay for the YouTube component:

import { YouTube } from '@bodiless/youtube';

const AutoPlayYouTube = withYouTubePlayerSettings({
  autoplay: true,
  mute: true,
})(YouTube);

<AutoPlayYouTube nodeKey="youtube" />

Props

namedefaultdescription
nodeKeyundefinedIdentifies where the component data will be stored.
playerSettingsundefinedYouTube embed player settings. Check YouTubePlayerSettings type from 'Youtube.tsx'.

In addition, you can pass HTMLIFrameElement props (id, src, width, etc.). Check HTMLIFrameElement type for more details.

playerSettings Parameters

The YouTube Component utilizes an API that allows you to change the following properties/parameters. You can use defaultPlayerSettings to set parameters that are commonly used together. For more details on each individual parameter see YouTube Player API Reference for iframe Embeds.

ParametersSuggested Default
autoplay0
cc_lang_prefno default
cc_load_policy0
controls1
loop0
enablejsapi1
modestbranding1
origincanonical URL
rel0
mute
version
playlist

e.g.: Responsive YouTube with 16:9 ratio with custom language preferences:

const withCustomLangPref = flowRight(
  withYouTubePlayerSettings({
    ...defaultPlayerSettings,
    cc_lang_pref: 'de',
    cc_load_policy: 1,
  }),
  addProps({
    src: 'https://www.youtube.com/embed/9No-FiEInLA',
  }),
);

const YouTubeWithCustomLangPref = withDesign({
  Item: withCustomLangPref,
})(DefaultReponsive16By9YouTube);

Usage

<YouTubeWithCustomLangPref nodeKey="withLangPref" />

Architectural Details

The YouTube Component renders the following code:

<iframe id="player" type="text/html" 
  src=""
  frameborder="0">
</iframe>

?> There are optional parameters on the src that are configurable.

2.0.3-beta.1

2 years ago

2.0.5-beta.0

2 years ago

2.0.3-beta.0

2 years ago

2.0.6-beta.0

2 years ago

2.0.1-beta.0

2 years ago

2.0.1-beta.1

2 years ago

3.0.0

2 years ago

1.0.0-beta.16

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.2-beta.0

2 years ago

1.0.1

2 years ago

1.0.1-beta.6

2 years ago

1.0.0-beta.6

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-alpha.0

2 years ago

1.0.1-beta.0

2 years ago

1.0.0

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago