Examples
App elements
Assets and media
Fundamentals
Intents
Design interaction
Drag and drop
Design elements
Localization
Content replacement
Drag and drop video
Drag-and-drop functionality for video elements.
Running this example
To run this example locally:
-
If you haven't already, create a new app in the Developer Portal(opens in a new tab or window). For more information, refer to our Quickstart guide.
-
In your app's configuration on the Developer Portal(opens in a new tab or window), ensure the "Development URL" is set to
http://localhost:8080
. -
Clone the starter kit:
git clone https://github.com/canva-sdks/canva-apps-sdk-starter-kit.gitcd canva-apps-sdk-starter-kitSHELL -
Install dependencies:
npm installSHELL -
Run the example:
npm run start drag_and_drop_videoSHELL -
Click the Preview URL link shown in the terminal to open the example in the Canva editor.
Example app source code
// For usage information, see the README.md file.import React from "react";import { Rows, Text, Title, VideoCard } from "@canva/app-ui-kit";import { upload } from "@canva/asset";import type { VideoDragConfig } from "@canva/design";import { ui } from "@canva/design";import * as styles from "styles/components.css";import { useFeatureSupport } from "utils/use_feature_support";import { useAddElement } from "utils/use_add_element";const uploadVideo = () => {return upload({mimeType: "video/mp4",thumbnailImageUrl:"https://www.canva.dev/example-assets/video-import/beach-thumbnail-image.jpg",thumbnailVideoUrl:"https://www.canva.dev/example-assets/video-import/beach-thumbnail-video.mp4",type: "video",url: "https://www.canva.dev/example-assets/video-import/beach-video.mp4",width: 320,height: 180,aiDisclosure: "none",});};const altText = {text: "beach video",decorative: true,};export const App = () => {const isSupported = useFeatureSupport();const addElement = useAddElement();const dragData: VideoDragConfig = {type: "video",resolveVideoRef: uploadVideo,previewSize: {width: 320,height: 180,},previewUrl:"https://www.canva.dev/example-assets/video-import/beach-thumbnail-image.jpg",};const onDragStart = (event: React.DragEvent<HTMLElement>) => {if (isSupported(ui.startDragToPoint)) {ui.startDragToPoint(event, dragData);} else if (isSupported(ui.startDragToCursor)) {ui.startDragToCursor(event, dragData);}};const insertVideo = async () => {const { ref } = await uploadVideo();addElement({ type: "video", ref, altText });};return (<div className={styles.scrollContainer}><Rows spacing="3u"><Text>This example demonstrates how apps can support drag-and-drop ofvideos.</Text><Rows spacing="1u"><Title size="small">External Video</Title><Text size="small" tone="tertiary">This video is an external https video made draggable via drag anddrop and asset upload.</Text><VideoCardariaLabel="Add video to design"thumbnailUrl="https://www.canva.dev/example-assets/video-import/beach-thumbnail-image.jpg"videoPreviewUrl="https://www.canva.dev/example-assets/video-import/beach-thumbnail-video.mp4"durationInSeconds={7}mimeType="video/mp4"onDragStart={onDragStart}onClick={insertVideo}/></Rows></Rows></div>);};
TYPESCRIPT
import { AppUiProvider } from "@canva/app-ui-kit";import { createRoot } from "react-dom/client";import { App } from "./app";import "@canva/app-ui-kit/styles.css";const root = createRoot(document.getElementById("root") as Element);function render() {root.render(<AppUiProvider><App /></AppUiProvider>,);}render();if (module.hot) {module.hot.accept("./app", render);}
TYPESCRIPT
# Drag and drop videoDemonstrates how to implement drag-and-drop functionality for video files using VideoCard and startDragToPoint. Shows video upload, thumbnail previews, and design integration with feature detection.For API reference docs and instructions on running this example, see: https://www.canva.dev/docs/apps/examples/drag-and-drop-video/.Related examples: See drag_and_drop/drag_and_drop_image for image drag-and-drop, or asset_upload for direct video import.NOTE: This example differs from what is expected for public apps to pass a Canva review:- Static assets are used for demonstration purposes only. Production apps should host assets on a CDN/hosting service and use the `upload` function from the `@canva/asset` package- Error handling is simplified for demonstration. Production apps must implement comprehensive error handling with clear user feedback and graceful failure modes- Video format validation and thumbnail generation is not implemented. Production apps should validate video formats and provide proper thumbnail generation- Internationalization is not implemented. Production apps must support multiple languages using the `@canva/app-i18n-kit` package to pass Canva review requirements
MARKDOWN
API Reference
Need Help?
- Join our Community Forum(opens in a new tab or window)
- Report issues with this example on GitHub(opens in a new tab or window)