Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

feat: YouTube Component (#4732)

Ivan Starkova09d12abe051
diff --git a/packages/sdk-components-react/src/__generated__/vimeo.props.ts b/packages/sdk-components-react/src/__generated__/vimeo.props.ts
index 2bfc388713..15daa8f7c6 100644
--- a/packages/sdk-components-react/src/__generated__/vimeo.props.ts
+++ b/packages/sdk-components-react/src/__generated__/vimeo.props.ts
@@ -414,7 +414,7 @@ export const props: Record<string, PropMeta> = {
},
autoplay: {
description:
- "Whether to start playback of the video automatically. This feature might not work on all devices.",
+ "Whether to start playback of the video automatically. This feature might not work on all devices.\nSome browsers require the `muted` parameter to be set to `true` for autoplay to work.",
required: false,
control: "boolean",
type: "boolean",
@@ -708,11 +708,11 @@ export const props: Record<string, PropMeta> = {
type: "string",
},
title: {
+ description:
+ 'The `title` attribute for the iframe.\nImproves accessibility by providing a brief description of the video content for screen readers.\nExample: "Video about web development tips".',
required: false,
control: "text",
type: "string",
- description:
- "Text to be displayed in a tooltip when hovering over the element.",
},
translate: {
required: false,
diff --git a/packages/sdk-components-react/src/__generated__/youtube.props.ts b/packages/sdk-components-react/src/__generated__/youtube.props.ts
new file mode 100644
index 0000000000..084f0bc0e6
--- /dev/null
+++ b/packages/sdk-components-react/src/__generated__/youtube.props.ts
@@ -0,0 +1,730 @@
+import type { PropMeta } from "@webstudio-is/sdk";
+
+export const props: Record<string, PropMeta> = {
+ about: { required: false, control: "text", type: "string" },
+ accessKey: {
+ required: false,
+ control: "text",
+ type: "string",
+ description: "Keyboard shortcut to activate or add focus to the element.",
+ },
+ allowFullscreen: {
+ description: "Whether to allow fullscreen mode.\nOriginal parameter: `fs`",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: true,
+ },
+ "aria-activedescendant": {
+ description:
+ "Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-atomic": {
+ description:
+ "Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-autocomplete": {
+ description:
+ "Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be\npresented if they are made.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: ["list", "inline", "none", "both"],
+ },
+ "aria-braillelabel": {
+ description:
+ "Defines a string value that labels the current element, which is intended to be converted into Braille.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-brailleroledescription": {
+ description:
+ "Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-busy": { required: false, control: "boolean", type: "boolean" },
+ "aria-checked": {
+ description:
+ 'Indicates the current "checked" state of checkboxes, radio buttons, and other widgets.',
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-colcount": {
+ description:
+ "Defines the total number of columns in a table, grid, or treegrid.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-colindex": {
+ description:
+ "Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-colindextext": {
+ description: "Defines a human readable text alternative of aria-colindex.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-colspan": {
+ description:
+ "Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-controls": {
+ description:
+ "Identifies the element (or elements) whose contents or presence are controlled by the current element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-current": {
+ description:
+ "Indicates the element that represents the current item within a container or set of related elements.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-describedby": {
+ description:
+ "Identifies the element (or elements) that describes the object.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-description": {
+ description:
+ "Defines a string value that describes or annotates the current element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-details": {
+ description:
+ "Identifies the element that provides a detailed, extended description for the object.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-disabled": {
+ description:
+ "Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-dropeffect": {
+ description:
+ "Indicates what functions can be performed when a dragged object is released on the drop target.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: ["link", "none", "copy", "execute", "move", "popup"],
+ },
+ "aria-errormessage": {
+ description:
+ "Identifies the element that provides an error message for the object.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-expanded": {
+ description:
+ "Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-flowto": {
+ description:
+ "Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion,\nallows assistive technology to override the general default of reading in document source order.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-grabbed": {
+ description:
+ 'Indicates an element\'s "grabbed" state in a drag-and-drop operation.',
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-haspopup": {
+ description:
+ "Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-hidden": {
+ description:
+ "Indicates whether the element is exposed to an accessibility API.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-invalid": {
+ description:
+ "Indicates the entered value does not conform to the format expected by the application.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-keyshortcuts": {
+ description:
+ "Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-label": {
+ description:
+ "Provides the accessible name that describes an interactive element if no other accessible name exists, for example in a button that contains an image with no text.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-labelledby": {
+ description:
+ "Identifies the element (or elements) that labels the current element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-level": {
+ description:
+ "Defines the hierarchical level of an element within a structure.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-live": {
+ description:
+ "Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.",
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["off", "assertive", "polite"],
+ },
+ "aria-modal": {
+ description: "Indicates whether an element is modal when displayed.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-multiline": {
+ description:
+ "Indicates whether a text box accepts multiple lines of input or only a single line.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-multiselectable": {
+ description:
+ "Indicates that the user may select more than one item from the current selectable descendants.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-orientation": {
+ description:
+ "Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.",
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["horizontal", "vertical"],
+ },
+ "aria-owns": {
+ description:
+ "Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship\nbetween DOM elements where the DOM hierarchy cannot be used to represent the relationship.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-placeholder": {
+ description:
+ "Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value.\nA hint could be a sample value or a brief description of the expected format.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-posinset": {
+ description:
+ "Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-pressed": {
+ description: 'Indicates the current "pressed" state of toggle buttons.',
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-readonly": {
+ description:
+ "Indicates that the element is not editable, but is otherwise operable.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-relevant": {
+ description:
+ "Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: [
+ "text",
+ "additions",
+ "additions removals",
+ "additions text",
+ "all",
+ "removals",
+ "removals additions",
+ "removals text",
+ "text additions",
+ "text removals",
+ ],
+ },
+ "aria-required": {
+ description:
+ "Indicates that user input is required on the element before a form may be submitted.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-roledescription": {
+ description:
+ "Defines a human-readable, author-localized description for the role of an element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-rowcount": {
+ description:
+ "Defines the total number of rows in a table, grid, or treegrid.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-rowindex": {
+ description:
+ "Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-rowindextext": {
+ description: "Defines a human readable text alternative of aria-rowindex.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-rowspan": {
+ description:
+ "Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-selected": {
+ description: 'Indicates the current "selected" state of various widgets.',
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-setsize": {
+ description:
+ "Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-sort": {
+ description:
+ "Indicates if items in a table or grid are sorted in ascending or descending order.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: ["none", "ascending", "descending", "other"],
+ },
+ "aria-valuemax": {
+ description: "Defines the maximum allowed value for a range widget.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-valuemin": {
+ description: "Defines the minimum allowed value for a range widget.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-valuenow": {
+ description: "Defines the current value for a range widget.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-valuetext": {
+ description:
+ "Defines the human readable text alternative of aria-valuenow for a range widget.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ autoCapitalize: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "Sets whether input is automatically capitalized when entered by user.",
+ },
+ autoCorrect: { required: false, control: "text", type: "string" },
+ autoFocus: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ description:
+ "Indicates that an element should be focused on page load, or when its parent dialog is displayed.",
+ },
+ autoplay: {
+ description:
+ "Whether the video should autoplay.\nSome browsers require the `muted` parameter to be set to `true` for autoplay to work.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: false,
+ },
+ autoSave: { required: false, control: "text", type: "string" },
+ captionLanguage: {
+ description:
+ "Specifies the default language that the player will use to display captions.\nThe value is an ISO 639-1 two-letter language code.\nOriginal parameter: `cc_lang_pref`",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ className: { required: false, control: "text", type: "string" },
+ color: {
+ description:
+ "Specifies the color that will be used in the player's video progress bar to highlight the amount of the video that the viewer has already seen.\nValid values are 'red' and 'white'.",
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["red", "white"],
+ },
+ content: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "A value associated with http-equiv orname depending on the context.",
+ },
+ contextMenu: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "Defines the ID of a menu element which willserve as the element's context menu.",
+ },
+ datatype: { required: false, control: "text", type: "string" },
+ defaultChecked: { required: false, control: "boolean", type: "boolean" },
+ defaultValue: { required: false, control: "text", type: "string" },
+ dir: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left)",
+ },
+ disableKeyboard: {
+ description:
+ "Whether to disable keyboard controls.\nOriginal parameter: `disablekb`",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: false,
+ },
+ draggable: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ description: "Defines whether the element can be dragged.",
+ },
+ endTime: {
+ description: "End time of the video in seconds.\nOriginal parameter: `end`",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ hidden: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ description:
+ "Prevents rendering of given element, while keeping child elements, e.g. script elements, active.",
+ },
+ id: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "Often used with CSS to style a specific element. The value of this attribute must be unique.",
+ },
+ inline: {
+ description: "Whether to play inline on mobile (not fullscreen).",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: false,
+ },
+ inputMode: {
+ description:
+ "Hints at the type of data that might be entered by the user while editing the element or its contents",
+ required: false,
+ control: "select",
+ type: "string",
+ options: [
+ "search",
+ "text",
+ "url",
+ "none",
+ "tel",
+ "email",
+ "numeric",
+ "decimal",
+ ],
+ },
+ is: {
+ description:
+ "Specify that a standard HTML element should behave like a defined custom built-in element",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ itemID: { required: false, control: "text", type: "string" },
+ itemProp: { required: false, control: "text", type: "string" },
+ itemRef: { required: false, control: "text", type: "string" },
+ itemScope: { required: false, control: "boolean", type: "boolean" },
+ itemType: { required: false, control: "text", type: "string" },
+ keyboard: {
+ description: "Whether to enable keyboard controls.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: true,
+ },
+ lang: {
+ required: false,
+ control: "text",
+ type: "string",
+ description: "Defines the language used in the element.",
+ },
+ language: {
+ description:
+ "Sets the player's interface language. The value is an ISO 639-1 two-letter language code or a fully specified locale.\nOriginal parameter: `hl`",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ listId: {
+ description: "ID of the playlist to load.\nOriginal parameter: `list`",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ listType: {
+ description: "Type of playlist to load.",
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["playlist", "user_uploads"],
+ },
+ loading: {
+ description: "Loading strategy for iframe",
+ required: false,
+ control: "radio",
+ type: "string",
+ defaultValue: "lazy",
+ options: ["eager", "lazy"],
+ },
+ loop: {
+ description: "Whether the video should loop continuously.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: false,
+ },
+ muted: {
+ description:
+ "Whether the video should start muted.\nUseful for enabling autoplay in browsers that require videos to be muted.\nOriginal parameter: `mute`",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: false,
+ },
+ nonce: { required: false, control: "text", type: "string" },
+ origin: {
+ description:
+ "Your domain for API compliance (e.g., `https://yourdomain.com`).",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ playlist: {
+ description:
+ "This parameter specifies a comma-separated list of video IDs to play",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ prefix: { required: false, control: "text", type: "string" },
+ privacyEnhancedMode: {
+ description:
+ "The Privacy Enhanced Mode of the YouTube embedded player prevents the use of views of embedded YouTube content from influencing the viewer’s browsing experience on YouTube.\nhttps://support.google.com/youtube/answer/171780?hl=en#zippy=%2Cturn-on-privacy-enhanced-mode",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: true,
+ },
+ property: { required: false, control: "text", type: "string" },
+ radioGroup: { required: false, control: "text", type: "string" },
+ referrer: {
+ description:
+ "Referrer URL for tracking purposes.\nOriginal parameter: `widget_referrer`",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ rel: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "Specifies the relationship of the target object to the link object.",
+ },
+ resource: { required: false, control: "text", type: "string" },
+ results: { required: false, control: "number", type: "number" },
+ rev: { required: false, control: "text", type: "string" },
+ role: {
+ required: false,
+ control: "text",
+ type: "string",
+ description:
+ "Defines an explicit role for an element for use by assistive technologies.",
+ },
+ security: { required: false, control: "text", type: "string" },
+ showAnnotations: {
+ description:
+ "Whether to show annotations on the video.\nOriginal parameter: `iv_load_policy`",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: true,
+ },
+ showCaptions: {
+ description:
+ "Whether captions should be shown by default.\nOriginal parameter: `cc_load_policy`",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: false,
+ },
+ showControls: {
+ description: "Whether to show player controls.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: true,
+ },
+ showPreview: { required: false, control: "boolean", type: "boolean" },
+ showRelatedVideos: {
+ description:
+ "Whether to show related videos at the end.\nOriginal parameter: `rel`",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ defaultValue: true,
+ },
+ slot: {
+ required: false,
+ control: "text",
+ type: "string",
+ description: "Assigns a slot in a shadow DOM shadow tree to an element.",
+ },
+ spellCheck: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ description: "Indicates whether spell checking is allowed for the element.",
+ },
+ startTime: {
+ description:
+ "Start time of the video in seconds.\nOriginal parameter: `start`",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ suppressContentEditableWarning: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ suppressHydrationWarning: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ tabIndex: {
+ required: false,
+ control: "number",
+ type: "number",
+ description:
+ "Overrides the browser's default tab order and follows the one specified instead.",
+ },
+ title: {
+ description:
+ 'The `title` attribute for the iframe.\nImproves accessibility by providing a brief description of the video content for screen readers.\nExample: "Video about web development tips".',
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ translate: {
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["yes", "no"],
+ description:
+ "Specify whether an element's attribute values and the values of its text node children are to be translated when the page is localized, or whether to leave them unchanged.",
+ },
+ typeof: { required: false, control: "text", type: "string" },
+ unselectable: {
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["on", "off"],
+ },
+ url: {
+ description: "The YouTube video URL or ID",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ vocab: { required: false, control: "text", type: "string" },
+};
diff --git a/packages/sdk-components-react/src/components.ts b/packages/sdk-components-react/src/components.ts
index f57476ce01..44a45a0d78 100644
--- a/packages/sdk-components-react/src/components.ts
+++ b/packages/sdk-components-react/src/components.ts
@@ -29,6 +29,7 @@ export { Textarea } from "./textarea";
export { RadioButton } from "./radio-button";
export { Checkbox } from "./checkbox";
export { Vimeo } from "./vimeo";
+export { YouTube } from "./youtube";
export { VimeoPreviewImage } from "./vimeo-preview-image";
export { VimeoPlayButton } from "./vimeo-play-button";
export { VimeoSpinner } from "./vimeo-spinner";
diff --git a/packages/sdk-components-react/src/metas.ts b/packages/sdk-components-react/src/metas.ts
index f099857b0a..2156ed2f00 100644
--- a/packages/sdk-components-react/src/metas.ts
+++ b/packages/sdk-components-react/src/metas.ts
@@ -29,6 +29,7 @@ export { meta as Textarea } from "./textarea.ws";
export { meta as RadioButton } from "./radio-button.ws";
export { meta as Checkbox } from "./checkbox.ws";
export { meta as Vimeo } from "./vimeo.ws";
+export { meta as YouTube } from "./youtube.ws";
export { meta as VimeoPreviewImage } from "./vimeo-preview-image.ws";
export { meta as VimeoPlayButton } from "./vimeo-play-button.ws";
export { meta as VimeoSpinner } from "./vimeo-spinner.ws";
diff --git a/packages/sdk-components-react/src/props.ts b/packages/sdk-components-react/src/props.ts
index 333bb1346a..27c2238375 100644
--- a/packages/sdk-components-react/src/props.ts
+++ b/packages/sdk-components-react/src/props.ts
@@ -29,6 +29,7 @@ export { propsMeta as Textarea } from "./textarea.ws";
export { propsMeta as RadioButton } from "./radio-button.ws";
export { propsMeta as Checkbox } from "./checkbox.ws";
export { propsMeta as Vimeo } from "./vimeo.ws";
+export { propsMeta as YouTube } from "./youtube.ws";
export { propsMeta as VimeoPreviewImage } from "./vimeo-preview-image.ws";
export { propsMeta as VimeoPlayButton } from "./vimeo-play-button.ws";
export { propsMeta as VimeoSpinner } from "./vimeo-spinner.ws";
diff --git a/packages/sdk-components-react/src/templates.ts b/packages/sdk-components-react/src/templates.ts
index 3435ca768c..05584079e9 100644
--- a/packages/sdk-components-react/src/templates.ts
+++ b/packages/sdk-components-react/src/templates.ts
@@ -13,4 +13,5 @@ export { meta as Label } from "./label.template";
export { meta as RadioButton } from "./radio-button.template";
export { meta as Checkbox } from "./checkbox.template";
export { meta as Vimeo } from "./vimeo.template";
+export { meta as YouTube } from "./youtube.template";
export { meta as Select } from "./select.template";
diff --git a/packages/sdk-components-react/src/vimeo-play-button.ws.ts b/packages/sdk-components-react/src/vimeo-play-button.ws.ts
index ceae06855d..a0baee1cdd 100644
--- a/packages/sdk-components-react/src/vimeo-play-button.ws.ts
+++ b/packages/sdk-components-react/src/vimeo-play-button.ws.ts
@@ -19,7 +19,7 @@ export const meta: WsComponentMeta = {
constraints: [
{
relation: "ancestor",
- component: { $eq: "Vimeo" },
+ component: { $in: ["Vimeo", "YouTube"] },
},
{
relation: "ancestor",
diff --git a/packages/sdk-components-react/src/vimeo-preview-image.ws.ts b/packages/sdk-components-react/src/vimeo-preview-image.ws.ts
index f79c2dc8dc..da80c6f107 100644
--- a/packages/sdk-components-react/src/vimeo-preview-image.ws.ts
+++ b/packages/sdk-components-react/src/vimeo-preview-image.ws.ts
@@ -8,7 +8,7 @@ export const meta: WsComponentMeta = {
label: "Preview Image",
constraints: {
relation: "ancestor",
- component: { $eq: "Vimeo" },
+ component: { $in: ["Vimeo", "YouTube"] },
},
};
diff --git a/packages/sdk-components-react/src/vimeo-spinner.ws.ts b/packages/sdk-components-react/src/vimeo-spinner.ws.ts
index b6f02e02e1..e9df12507c 100644
--- a/packages/sdk-components-react/src/vimeo-spinner.ws.ts
+++ b/packages/sdk-components-react/src/vimeo-spinner.ws.ts
@@ -16,7 +16,7 @@ export const meta: WsComponentMeta = {
type: "container",
constraints: {
relation: "ancestor",
- component: { $eq: "Vimeo" },
+ component: { $in: ["Vimeo", "YouTube"] },
},
icon: BoxIcon,
states: defaultStates,
diff --git a/packages/sdk-components-react/src/vimeo.template.tsx b/packages/sdk-components-react/src/vimeo.template.tsx
index ce0d2a7a80..b52428eb0c 100644
--- a/packages/sdk-components-react/src/vimeo.template.tsx
+++ b/packages/sdk-components-react/src/vimeo.template.tsx
@@ -25,6 +25,7 @@ export const meta: TemplateMeta = {
`}
alt="Vimeo video preview image"
sizes="100vw"
+ optimize={true}
/>
<$.VimeoSpinner
ws:label="Spinner"
diff --git a/packages/sdk-components-react/src/vimeo.tsx b/packages/sdk-components-react/src/vimeo.tsx
index 271dbf06f2..694ae0b55a 100644
--- a/packages/sdk-components-react/src/vimeo.tsx
+++ b/packages/sdk-components-react/src/vimeo.tsx
@@ -33,7 +33,10 @@ type VimeoPlayerOptions = {
autopause?: boolean;
/** Whether to enable the browser to enter picture-in-picture mode automatically when switching tabs or windows, where supported. */
autopip?: boolean;
- /** Whether to start playback of the video automatically. This feature might not work on all devices. */
+ /**
+ * Whether to start playback of the video automatically. This feature might not work on all devices.
+ * Some browsers require the `muted` parameter to be set to `true` for autoplay to work.
+ * */
autoplay?: boolean;
/** Whether to display the video owner's name. */
byline?: boolean;
@@ -250,6 +253,7 @@ type PlayerProps = Pick<
"loading" | "autoplay" | "showPreview"
> & {
videoUrl: string;
+ title: string | undefined;
status: PlayerStatus;
renderer: ContextType<typeof ReactSdkContext>["renderer"];
previewImageUrl?: URL;
@@ -258,6 +262,7 @@ type PlayerProps = Pick<
};
const Player = ({
+ title,
status,
loading,
videoUrl,
@@ -307,6 +312,7 @@ const Player = ({
return (
<iframe
+ title={title}
src={videoUrl}
loading={loading}
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture;"
@@ -339,7 +345,14 @@ export const VimeoContext = createContext<{
const defaultTag = "div";
type Props = Omit<ComponentProps<typeof defaultTag>, keyof VimeoOptions> &
- VimeoOptions;
+ VimeoOptions & {
+ /**
+ * The `title` attribute for the iframe.
+ * Improves accessibility by providing a brief description of the video content for screen readers.
+ * Example: "Video about web development tips".
+ */
+ title?: string | undefined;
+ };
type Ref = ElementRef<typeof defaultTag>;
export const Vimeo = forwardRef<Ref, Props>(
@@ -425,6 +438,7 @@ export const Vimeo = forwardRef<Ref, Props>(
<>
{children}
<Player
+ title={rest.title}
autoplay={autoplay}
videoUrl={videoUrl}
previewImageUrl={previewImageUrl}
diff --git a/packages/sdk-components-react/src/vimeo.ws.ts b/packages/sdk-components-react/src/vimeo.ws.ts
index e9e148f123..72cec187b7 100644
--- a/packages/sdk-components-react/src/vimeo.ws.ts
+++ b/packages/sdk-components-react/src/vimeo.ws.ts
@@ -29,6 +29,7 @@ const initialProps: Array<keyof ComponentProps<typeof Vimeo>> = [
"id",
"className",
"url",
+ "title",
"quality",
"loading",
"showPreview",
diff --git a/packages/sdk-components-react/src/youtube.stories.tsx b/packages/sdk-components-react/src/youtube.stories.tsx
new file mode 100644
index 0000000000..8a817fa374
--- /dev/null
+++ b/packages/sdk-components-react/src/youtube.stories.tsx
@@ -0,0 +1,440 @@
+import { VimeoPreviewImage } from "./vimeo-preview-image";
+import { Box } from "./box";
+import { HtmlEmbed } from "./html-embed";
+import { VimeoPlayButton } from "./vimeo-play-button";
+import { YouTube } from "./youtube";
+
+const Component = () => (
+ <YouTube
+ data-ws-id="ZkDuD4HlHP3pDdp0SXJuh"
+ data-ws-component="Vimeo"
+ url={"https://www.youtube.com/embed/dQw4w9WgXcQ"}
+ showPreview={true}
+ className="ca1m5u0 ciuvvr7 cuk1bdz"
+ >
+ <VimeoPreviewImage
+ data-ws-id="wxd8Wul8dl2yPRFFedNn6"
+ data-ws-component="VimeoPreviewImage"
+ alt={"Vimeo video preview image"}
+ sizes={"100vw"}
+ src={"/home_wsKvRSqvkajPPBeycZ-C8.svg"}
+ className="c1eccbi0 cc32szi cuk1bdz c1ge5ofh c1fwh0y5 ch160p4 c1jxoq3x cewch87 c1la265j"
+ />
+ <Box
+ data-ws-id="CnbJrVYAMQ7aDqemVdWI5"
+ data-ws-component="Box"
+ className="c1eccbi0 ce5jzw0 cq3eebu c1319rdz c1x7j4n5 c176tfq4 c1qg633k"
+ >
+ <HtmlEmbed
+ data-ws-id="JeL4m1QcrRyK7gPyN3p5j"
+ data-ws-component="HtmlEmbed"
+ code={
+ '<svg xmlns="http://www.w3.org/2000/svg" id="e2CRglijn891" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 128 128" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes e2CRglijn892_tr__tr{0%{transform:translate(64px,64px) rotate(90deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}50%{transform:translate(64px,64px) rotate(810deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}to{transform:translate(64px,64px) rotate(1530deg)}}@keyframes e2CRglijn892_s_p{0%,to{stroke:#39fbbb}25%{stroke:#4a4efa}50%{stroke:#e63cfe}75%{stroke:#ffae3c}}@keyframes e2CRglijn892_s_do{0%{stroke-dashoffset:251.89}2.5%,52.5%{stroke-dashoffset:263.88;animation-timing-function:cubic-bezier(.42,0,.58,1)}25%,75%{stroke-dashoffset:131.945}to{stroke-dashoffset:251.885909}}#e2CRglijn892_tr{animation:e2CRglijn892_tr__tr 3000ms linear infinite normal forwards}#e2CRglijn892{animation-name:e2CRglijn892_s_p,e2CRglijn892_s_do;animation-duration:3000ms;animation-fill-mode:forwards;animation-timing-function:linear;animation-direction:normal;animation-iteration-count:infinite}</style><g id="e2CRglijn892_tr" transform="translate(64,64) rotate(90)"><circle id="e2CRglijn892" r="42" fill="none" stroke="#39fbbb" stroke-dasharray="263.89" stroke-dashoffset="251.89" stroke-linecap="round" stroke-width="16" transform="scale(-1,1) translate(0,0)"/></g></svg>'
+ }
+ />
+ </Box>
+ <VimeoPlayButton
+ data-ws-id="9hBBPGSf7hB30ZkSHKjNd"
+ data-ws-component="VimeoPlayButton"
+ aria-label={"Play button"}
+ className="c1eccbi0 c1yx3ait c1scl4ay ce5jzw0 cq3eebu cxar3by c1fiqkhd c1b095zn cyw79s9 c2f7s8e c9bs64c c6lou2r c16c73ai c1fisnnh c82rye8 c1xaktbd c1xplc5b c5admkk ccn3fhu cyn2bny c1xs2zvh c1be0m8p"
+ >
+ <Box
+ data-ws-id="D__QElBIIQtamhJN3a4FI"
+ data-ws-component="Box"
+ aria-hidden={"true"}
+ className="c14af118 c1xa5m0w"
+ >
+ <HtmlEmbed
+ data-ws-id="iEc6hab-WardXZc5P9wJu"
+ data-ws-component="HtmlEmbed"
+ code={
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="currentColor" width="100%" height="100%" style="display: block;"><path d="M4.766 5.765c0-.725 0-1.088.178-1.288a.93.93 0 0 1 .648-.294c.294-.015.65.186 1.359.588l9.234 5.235c.586.332.88.498.982.708.09.183.09.389 0 .572-.102.21-.396.376-.982.708l-9.234 5.235c-.71.402-1.065.603-1.359.588a.93.93 0 0 1-.648-.294c-.178-.2-.178-.563-.178-1.288V5.765Z"/></svg>'
+ }
+ />
+ </Box>
+ </VimeoPlayButton>
+ </YouTube>
+);
+
+const Story = {
+ render() {
+ return (
+ <>
+ <style>
+ {`
+html {
+ margin: 0;
+ display: grid;
+ min-height: 100%;
+}
+@media all {
+ body:where([data-ws-component="Body"]) {
+ margin-top: 0;
+ margin-right: 0;
+ margin-bottom: 0;
+ margin-left: 0;
+ font-family: Arial, Roboto, sans-serif;
+ font-size: 16px;
+ line-height: 1.2;
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ }
+ h1:where([data-ws-component="Heading"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ h2:where([data-ws-component="Heading"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ h3:where([data-ws-component="Heading"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ h4:where([data-ws-component="Heading"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ h5:where([data-ws-component="Heading"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ h6:where([data-ws-component="Heading"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ a:where([data-ws-component="Link"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ min-height: 1em;
+ display: inline-block;
+ }
+ div:where([data-ws-component="Vimeo"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ img:where([data-ws-component="VimeoPreviewImage"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ max-width: 100%;
+ display: block;
+ }
+ div:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ address:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ article:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ aside:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ figure:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ footer:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ header:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ main:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ nav:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ section:where([data-ws-component="Box"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ button:where([data-ws-component="VimeoPlayButton"]) {
+ font-family: inherit;
+ font-size: 100%;
+ line-height: 1.15;
+ margin-top: 0;
+ margin-right: 0;
+ margin-bottom: 0;
+ margin-left: 0;
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ border-top-style: solid;
+ border-right-style: solid;
+ border-bottom-style: solid;
+ border-left-style: solid;
+ text-transform: none;
+ }
+}
+@media all {
+ .c11x2bo2 {
+ font-size: 4em;
+ }
+ .cykwawo {
+ font-family: "Cormorant Garamond", sans-serif;
+ }
+ .c1qmshyz {
+ background-attachment: scroll, scroll, scroll;
+ }
+ .c12wnxll {
+ -webkit-background-clip: border-box, border-box, border-box;
+ }
+ .c1hzshzo {
+ background-blend-mode: normal, normal, normal;
+ }
+ .c136ve95 {
+ background-image: linear-gradient(
+ rgba(255, 0, 0, 0.2),
+ rgba(0, 255, 255, 0.2)
+ ),
+ url("/home_wsKvRSqvkajPPBeycZ-C8.svg"),
+ linear-gradient(to right, rgba(255, 0, 255, 0.2), rgba(0, 255, 0, 0.2));
+ }
+ .cyttr60 {
+ background-origin: padding-box, padding-box, padding-box;
+ }
+ .c1cywb85 {
+ background-position: 0%, 0%, 0%;
+ }
+ .c187ui6a {
+ background-repeat: repeat, repeat, repeat;
+ }
+ .c1azrtl7 {
+ background-size: auto, auto, auto;
+ }
+ .c1vynykc {
+ margin-top: 15px;
+ }
+ .c122cnm9 {
+ margin-bottom: 15px;
+ }
+ .c15qd3jj {
+ margin-right: 15px;
+ }
+ .c1jp5sfs {
+ margin-left: 15px;
+ }
+ .ca1m5u0 {
+ position: relative;
+ }
+ .ciuvvr7 {
+ aspect-ratio: 640/360;
+ }
+ .cuk1bdz {
+ width: 100%;
+ }
+ .c1eccbi0 {
+ position: absolute;
+ }
+ .cc32szi {
+ object-fit: cover;
+ }
+ .c1ge5ofh {
+ height: 100%;
+ }
+ .c1fwh0y5 {
+ border-top-left-radius: 20px;
+ }
+ .ch160p4 {
+ border-top-right-radius: 20px;
+ }
+ .c1jxoq3x {
+ border-bottom-left-radius: 20px;
+ }
+ .cewch87 {
+ border-bottom-right-radius: 20px;
+ }
+ .c1la265j {
+ object-position: cover;
+ }
+ .ce5jzw0 {
+ top: 50%;
+ }
+ .cq3eebu {
+ left: 50%;
+ }
+ .c1319rdz {
+ width: 70px;
+ }
+ .c1x7j4n5 {
+ height: 70px;
+ }
+ .c176tfq4 {
+ margin-top: -35px;
+ }
+ .c1qg633k {
+ margin-left: -35px;
+ }
+ .c1yx3ait {
+ width: 140px;
+ }
+ .c1scl4ay {
+ height: 80px;
+ }
+ .cxar3by {
+ margin-top: -40px;
+ }
+ .c1fiqkhd {
+ margin-left: -70px;
+ }
+ .c1b095zn {
+ display: flex;
+ }
+ .cyw79s9 {
+ align-items: center;
+ }
+ .c2f7s8e {
+ justify-content: center;
+ }
+ .c9bs64c {
+ border-top-style: none;
+ }
+ .c6lou2r {
+ border-right-style: none;
+ }
+ .c16c73ai {
+ border-bottom-style: none;
+ }
+ .c1fisnnh {
+ border-left-style: none;
+ }
+ .c82rye8 {
+ border-top-left-radius: 5px;
+ }
+ .c1xaktbd {
+ border-top-right-radius: 5px;
+ }
+ .c1xplc5b {
+ border-bottom-left-radius: 5px;
+ }
+ .c5admkk {
+ border-bottom-right-radius: 5px;
+ }
+ .ccn3fhu {
+ cursor: pointer;
+ }
+ .cyn2bny {
+ background-color: rgba(18, 18, 18, 1);
+ }
+ .c1xs2zvh {
+ color: rgba(255, 255, 255, 1);
+ }
+ .c1be0m8p:hover {
+ background-color: rgba(0, 173, 239, 1);
+ }
+ .c14af118 {
+ width: 60px;
+ }
+ .c1xa5m0w {
+ height: 60px;
+ }
+}
+
+ `}
+ </style>
+ <Component />
+ </>
+ );
+ },
+};
+
+export { Story as Youtube };
+
+export default {
+ title: "Components/Youtube",
+};
diff --git a/packages/sdk-components-react/src/youtube.template.tsx b/packages/sdk-components-react/src/youtube.template.tsx
new file mode 100644
index 0000000000..751ab5d497
--- /dev/null
+++ b/packages/sdk-components-react/src/youtube.template.tsx
@@ -0,0 +1,83 @@
+import { PlayIcon, SpinnerIcon } from "@webstudio-is/icons/svg";
+import { type TemplateMeta, $, css } from "@webstudio-is/template";
+
+export const meta: TemplateMeta = {
+ category: "media",
+ order: 1,
+ description:
+ "Add a video to your page that is hosted on Vimeo. Paste a Vimeo URL and configure the video in the Settings tab.",
+ template: (
+ <$.YouTube
+ ws:label="YouTube"
+ ws:style={css`
+ position: relative;
+ aspect-ratio: 640/360;
+ width: 100%;
+ `}
+ >
+ <$.VimeoPreviewImage
+ ws:label="Preview Image"
+ ws:style={css`
+ position: absolute;
+ object-fit: cover;
+ object-position: cover;
+ width: 100%;
+ height: 100%;
+ border-radius: 20px;
+ `}
+ alt="Vimeo video preview image"
+ sizes="100vw"
+ optimize={true}
+ />
+ <$.VimeoSpinner
+ ws:label="Spinner"
+ ws:style={css`
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ width: 70px;
+ height: 70px;
+ margin-top: -35px;
+ margin-left: -35px;
+ `}
+ >
+ <$.HtmlEmbed ws:label="Spinner SVG" code={SpinnerIcon} />
+ </$.VimeoSpinner>
+ <$.VimeoPlayButton
+ ws:label="Play Button"
+ ws:style={css`
+ position: absolute;
+ width: 140px;
+ height: 80px;
+ top: 50%;
+ left: 50%;
+ margin-top: -40px;
+ margin-left: -70px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-style: none;
+ border-radius: 5px;
+ cursor: pointer;
+ background-color: rgb(18, 18, 18);
+ color: rgb(255, 255, 255);
+ &:hover {
+ background-color: rgb(0, 173, 239);
+ }
+ `}
+ aria-label="Play button"
+ >
+ <$.Box
+ ws:label="Play Icon"
+ ws:style={css`
+ width: 60px;
+ height: 60px;
+ `}
+ aria-hidden={true}
+ >
+ <$.HtmlEmbed ws:label="Play SVG" code={PlayIcon} />
+ </$.Box>
+ </$.VimeoPlayButton>
+ </$.YouTube>
+ ),
+};
diff --git a/packages/sdk-components-react/src/youtube.tsx b/packages/sdk-components-react/src/youtube.tsx
new file mode 100644
index 0000000000..145303b4ef
--- /dev/null
+++ b/packages/sdk-components-react/src/youtube.tsx
@@ -0,0 +1,509 @@
+import {
+ forwardRef,
+ useState,
+ useEffect,
+ type ElementRef,
+ type ComponentProps,
+ useContext,
+ type ContextType,
+} from "react";
+import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
+import { VimeoContext } from "./vimeo";
+
+/**
+ * Options for configuring the YouTube player parameters.
+ * https://developers.google.com/youtube/player_parameters
+ */
+type YouTubePlayerParameters = {
+ /**
+ * Whether the video should autoplay.
+ * Some browsers require the `muted` parameter to be set to `true` for autoplay to work.
+ * @default false
+ */
+ autoplay?: boolean;
+ /**
+ * Whether the video should start muted.
+ * Useful for enabling autoplay in browsers that require videos to be muted.
+ * Original parameter: `mute`
+ *@default false
+ */
+ muted?: boolean;
+
+ /**
+ * Whether to show player controls.
+ * @default true
+ */
+ showControls?: boolean;
+
+ /**
+ * Whether to show related videos at the end.
+ * Original parameter: `rel`
+ * @default true
+ */
+ showRelatedVideos?: boolean;
+
+ /**
+ * Whether to enable keyboard controls.
+ * @default true
+ */
+ keyboard?: boolean;
+
+ /**
+ * Whether the video should loop continuously.
+ * @default false
+ */
+ loop?: boolean;
+
+ /**
+ * Whether to play inline on mobile (not fullscreen).
+ * @default false
+ */
+ inline?: boolean;
+
+ /**
+ * Whether to allow fullscreen mode.
+ * Original parameter: `fs`
+ * @default true
+ */
+ allowFullscreen?: boolean;
+
+ /**
+ * Whether captions should be shown by default.
+ * Original parameter: `cc_load_policy`
+ * @default false
+ */
+ showCaptions?: boolean;
+
+ /**
+ * Whether to show annotations on the video.
+ * Original parameter: `iv_load_policy`
+ * @default true
+ */
+ showAnnotations?: boolean;
+
+ /**
+ * Start time of the video in seconds.
+ * Original parameter: `start`
+ */
+ startTime?: number;
+
+ /**
+ * End time of the video in seconds.
+ * Original parameter: `end`
+ */
+ endTime?: number;
+
+ /**
+ * Whether to disable keyboard controls.
+ * Original parameter: `disablekb`
+ * @default false
+ */
+ disableKeyboard?: boolean;
+
+ /**
+ * Referrer URL for tracking purposes.
+ * Original parameter: `widget_referrer`
+ */
+ referrer?: string;
+
+ /**
+ * Type of playlist to load.
+ */
+ listType?: "playlist" | "user_uploads";
+
+ /**
+ * ID of the playlist to load.
+ * Original parameter: `list`
+ */
+ listId?: string;
+
+ /**
+ * Your domain for API compliance (e.g., `https://yourdomain.com`).
+ */
+ origin?: string;
+
+ /**
+ * Specifies the default language that the player will use to display captions.
+ * The value is an ISO 639-1 two-letter language code.
+ * Original parameter: `cc_lang_pref`
+ */
+ captionLanguage?: string;
+
+ /**
+ * Sets the player's interface language. The value is an ISO 639-1 two-letter language code or a fully specified locale.
+ * Original parameter: `hl`
+ */
+ language?: string;
+
+ /**
+ * Specifies the color that will be used in the player's video progress bar to highlight the amount of the video that the viewer has already seen.
+ * Valid values are 'red' and 'white'.
+ */
+ color?: "red" | "white";
+
+ /**
+ * This parameter specifies a comma-separated list of video IDs to play
+ */
+ playlist?: string;
+};
+
+type YouTubePlayerOptions = {
+ /** The YouTube video URL or ID */
+ url?: string;
+ showPreview?: boolean;
+ /**
+ * The Privacy Enhanced Mode of the YouTube embedded player prevents the use of views of embedded YouTube content from influencing the viewer’s browsing experience on YouTube.
+ * https://support.google.com/youtube/answer/171780?hl=en#zippy=%2Cturn-on-privacy-enhanced-mode
+ * @default true
+ */
+ privacyEnhancedMode?: boolean;
+} & YouTubePlayerParameters & {
+ /** Loading strategy for iframe */
+ loading?: "eager" | "lazy";
+ };
+
+const PLAYER_PRIVACY_ENHANVED_MODE_CDN = "https://www.youtube-nocookie.com";
+const PLAYER_ORIGINAL_CDN = "https://www.youtube.com";
+
+const IMAGE_CDN = "https://img.youtube.com";
+
+const getVideoId = (url?: string) => {
+ if (!url) {
+ return;
+ }
+ try {
+ const urlObj = new URL(url);
+ if (urlObj.hostname === "youtu.be") {
+ return urlObj.pathname.slice(1);
+ }
+ return urlObj.searchParams.get("v") || urlObj.pathname.split("/").pop();
+ } catch {
+ // If not URL, assume it's a video ID
+ return url;
+ }
+};
+
+const getVideoUrl = (options: YouTubePlayerOptions, videoUrlOrigin: string) => {
+ const videoId = getVideoId(options.url);
+ if (!videoId) {
+ return;
+ }
+
+ const url = new URL(`${videoUrlOrigin}/embed/${videoId}`);
+
+ const optionsKeys = Object.keys(options) as (keyof YouTubePlayerParameters)[];
+
+ const parameters: Record<string, string | undefined> = {};
+
+ for (const optionsKey of optionsKeys) {
+ switch (optionsKey) {
+ case "autoplay":
+ parameters.autoplay = options.autoplay ? "1" : "0";
+ // Mute video if autoplay is enabled and muted is not touched
+ if (options.autoplay && options.muted === undefined) {
+ parameters.mute = "1";
+ }
+ break;
+
+ case "muted":
+ parameters.mute = options.muted ? "1" : "0";
+ break;
+
+ case "showControls":
+ parameters.controls = options.showControls ? "1" : "0";
+ break;
+
+ case "showRelatedVideos":
+ parameters.rel = options.showRelatedVideos ? "1" : "0";
+ break;
+
+ case "keyboard":
+ parameters.keyboard = options.keyboard ? "1" : "0";
+ break;
+
+ case "loop":
+ parameters.loop = options.loop ? "1" : "0";
+ if (options.loop && (options.playlist ?? "").trim() === "") {
+ parameters.playlist = videoId;
+ }
+
+ break;
+
+ case "inline":
+ parameters.playsinline = options.inline ? "1" : "0";
+ break;
+
+ case "allowFullscreen":
+ parameters.fs = options.allowFullscreen ? "1" : "0";
+ break;
+
+ case "captionLanguage":
+ parameters.cc_lang_pref = options.captionLanguage;
+ break;
+
+ case "showCaptions":
+ parameters.cc_load_policy = options.showCaptions ? "1" : "0";
+ break;
+
+ case "showAnnotations":
+ parameters.iv_load_policy = options.showAnnotations ? "1" : "3";
+ break;
+
+ case "startTime":
+ parameters.start = options.startTime?.toString();
+ break;
+
+ case "endTime":
+ parameters.end = options.endTime?.toString();
+ break;
+
+ case "disableKeyboard":
+ parameters.disablekb = options.disableKeyboard ? "1" : "0";
+ break;
+
+ case "language":
+ parameters.hl = options.language;
+ break;
+
+ case "listId":
+ parameters.list = options.listId;
+ break;
+
+ case "listType":
+ parameters.listType = options.listType;
+ break;
+
+ case "color":
+ parameters.color = options.color;
+ break;
+
+ case "origin":
+ parameters.origin = options.origin;
+ break;
+ case "referrer":
+ parameters.widget_referrer = options.referrer;
+ break;
+ case "playlist":
+ parameters.playlist = options.playlist;
+ break;
+
+ default:
+ optionsKey satisfies never;
+ }
+ }
+
+ Object.entries(parameters).forEach(([key, value]) => {
+ if (value === undefined) {
+ return;
+ }
+ url.searchParams.append(key, value.toString());
+ });
+
+ return url.toString();
+};
+
+const preconnect = (url: string) => {
+ const link = document.createElement("link");
+ link.rel = "preconnect";
+ link.href = url;
+ link.crossOrigin = "true";
+ document.head.appendChild(link);
+};
+
+let warmed = false;
+
+const warmConnections = (videoUrl: string) => {
+ if (warmed || window.matchMedia("(hover: none)").matches) {
+ return;
+ }
+
+ try {
+ const videoUrlObject = new URL(videoUrl);
+
+ preconnect(videoUrlObject.origin);
+ } catch {
+ // Ignore invalid URL
+ }
+
+ preconnect(IMAGE_CDN);
+ warmed = true;
+};
+
+const getPreviewImageUrl = (videoId: string) => {
+ return new URL(`${IMAGE_CDN}/vi/${videoId}/maxresdefault.jpg`);
+};
+
+type PlayerStatus = "initial" | "loading" | "ready";
+
+const EmptyState = () => {
+ return (
+ <div className="flex w-full h-full items-center justify-center text-lg">
+ Open the "Settings" panel and paste a video URL, e.g.
+ https://youtube.com/watch?v=dQw4w9WgXcQ
+ </div>
+ );
+};
+
+type PlayerProps = Pick<
+ YouTubePlayerOptions,
+ "loading" | "autoplay" | "showPreview"
+> & {
+ videoUrl: string;
+ title: string | undefined;
+ status: PlayerStatus;
+ renderer: ContextType<typeof ReactSdkContext>["renderer"];
+ previewImageUrl?: URL;
+ onStatusChange: (status: PlayerStatus) => void;
+ onPreviewImageUrlChange: (url?: URL) => void;
+};
+
+const Player = ({
+ title,
+ status,
+ loading,
+ videoUrl,
+ previewImageUrl,
+ autoplay,
+ renderer,
+ showPreview,
+ onStatusChange,
+ onPreviewImageUrlChange,
+}: PlayerProps) => {
+ const [opacity, setOpacity] = useState(0);
+
+ useEffect(() => {
+ if (autoplay && renderer !== "canvas" && status === "initial") {
+ onStatusChange("loading");
+ }
+ }, [autoplay, status, renderer, onStatusChange]);
+
+ useEffect(() => {
+ if (renderer !== "canvas") {
+ warmConnections(videoUrl);
+ }
+ }, [renderer, videoUrl]);
+
+ useEffect(() => {
+ const videoId = getVideoId(videoUrl);
+ if (!videoId || !showPreview) {
+ onPreviewImageUrlChange(undefined);
+ return;
+ }
+
+ if (!previewImageUrl) {
+ onPreviewImageUrlChange(getPreviewImageUrl(videoId));
+ }
+ }, [onPreviewImageUrlChange, showPreview, videoUrl, previewImageUrl]);
+
+ if (renderer === "canvas" || status === "initial") {
+ return null;
+ }
+
+ return (
+ <iframe
+ title={title}
+ src={videoUrl}
+ loading={loading}
+ allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
+ allowFullScreen
+ style={{
+ position: "absolute",
+ width: "100%",
+ height: "100%",
+ opacity,
+ transition: "opacity 1s",
+ border: "none",
+ }}
+ onLoad={() => {
+ onStatusChange("ready");
+ setOpacity(1);
+ }}
+ />
+ );
+};
+
+const defaultTag = "div";
+
+type Props = Omit<
+ ComponentProps<typeof defaultTag>,
+ keyof YouTubePlayerOptions
+> &
+ YouTubePlayerOptions & {
+ /**
+ * The `title` attribute for the iframe.
+ * Improves accessibility by providing a brief description of the video content for screen readers.
+ * Example: "Video about web development tips".
+ */
+ title?: string | undefined;
+ };
+type Ref = ElementRef<typeof defaultTag>;
+
+export const YouTube = forwardRef<Ref, Props>(
+ (
+ {
+ url,
+ loading = "lazy",
+ autoplay,
+ showPreview,
+ children,
+ privacyEnhancedMode,
+ ...rest
+ },
+ ref
+ ) => {
+ const [status, setStatus] = useState<PlayerStatus>("initial");
+ const [previewImageUrl, setPreviewImageUrl] = useState<URL>();
+ const { renderer } = useContext(ReactSdkContext);
+
+ const videoUrlOrigin =
+ (privacyEnhancedMode ?? true)
+ ? PLAYER_PRIVACY_ENHANVED_MODE_CDN
+ : PLAYER_ORIGINAL_CDN;
+ const videoUrl = getVideoUrl(
+ {
+ ...rest,
+ url,
+ autoplay: true,
+ },
+ videoUrlOrigin
+ );
+
+ return (
+ <VimeoContext.Provider
+ value={{
+ status,
+ previewImageUrl,
+ onInitPlayer() {
+ if (renderer !== "canvas") {
+ setStatus("loading");
+ }
+ },
+ }}
+ >
+ <div {...rest} ref={ref}>
+ {!videoUrl ? (
+ <EmptyState />
+ ) : (
+ <>
+ {children}
+ <Player
+ title={rest.title}
+ autoplay={autoplay}
+ videoUrl={videoUrl}
+ previewImageUrl={previewImageUrl}
+ loading={loading}
+ showPreview={showPreview}
+ renderer={renderer}
+ status={status}
+ onStatusChange={setStatus}
+ onPreviewImageUrlChange={setPreviewImageUrl}
+ />
+ </>
+ )}
+ </div>
+ </VimeoContext.Provider>
+ );
+ }
+);
+
+YouTube.displayName = "YouTube";
diff --git a/packages/sdk-components-react/src/youtube.ws.ts b/packages/sdk-components-react/src/youtube.ws.ts
new file mode 100644
index 0000000000..c0aa80a58b
--- /dev/null
+++ b/packages/sdk-components-react/src/youtube.ws.ts
@@ -0,0 +1,61 @@
+import type { ComponentProps } from "react";
+import { Youtube1cIcon } from "@webstudio-is/icons/svg";
+import {
+ defaultStates,
+ type PresetStyle,
+ type WsComponentMeta,
+ type WsComponentPropsMeta,
+} from "@webstudio-is/sdk";
+import { div } from "@webstudio-is/sdk/normalize.css";
+import { props } from "./__generated__/youtube.props";
+import type { YouTube } from "./youtube";
+
+const presetStyle = {
+ div,
+} satisfies PresetStyle<"div">;
+
+export const meta: WsComponentMeta = {
+ type: "container",
+ icon: Youtube1cIcon,
+ states: defaultStates,
+ presetStyle,
+ constraints: {
+ relation: "ancestor",
+ component: { $nin: ["Button", "Link", "Heading"] },
+ },
+};
+
+const initialProps: Array<keyof ComponentProps<typeof YouTube>> = [
+ "id",
+ "className",
+ "url",
+ "privacyEnhancedMode",
+ "title",
+ "loading",
+ "showPreview",
+ "autoplay",
+ "showControls",
+ "showRelatedVideos",
+ "keyboard",
+ "loop",
+ "inline",
+ "allowFullscreen",
+ "showCaptions",
+ "showAnnotations",
+ "startTime",
+ "endTime",
+ "disableKeyboard",
+ "referrer",
+ "listType",
+ "listId",
+ "origin",
+ "captionLanguage",
+ "language",
+ "color",
+ "playlist",
+];
+
+export const propsMeta: WsComponentPropsMeta = {
+ props,
+ initialProps,
+};