🎥 Make videos programmatically with React
Add Alert on image file sizes larger than 10MB
ASchwadd9f248cdab67
diff --git a/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/RenderControls/Error.tsx b/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/RenderControls/Error.tsxindex 7b0b79a405..7f5932d905 100644--- a/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/RenderControls/Error.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/RenderControls/Error.tsx@@ -1,4 +1,6 @@import React from "react";+import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";+import { AlertCircle } from "lucide-react";const isLambdaNotConfiguredError = (message: string): boolean => {return (@@ -14,11 +16,10 @@ export const ErrorComp: React.FC<{if (isLambdaError) {return (- <div className="py-2">- <div className="text-destructive text-sm font-semibold font-sans">- Lambda not configured- </div>- <div className="text-destructive-foreground text-sm font-sans mt-1">+ <Alert variant="destructive" className="my-2">+ <AlertCircle className="h-4 w-4" />+ <AlertTitle>Lambda not configured</AlertTitle>+ <AlertDescription>To render videos, set up Remotion Lambda and add your AWS credentialsto the <code className="font-mono text-xs">.env</code> file.{" "}<a@@ -29,19 +30,18 @@ export const ErrorComp: React.FC<{>Setup guide</a>- </div>- </div>+ </AlertDescription>+ </Alert>);}return (- <div className="py-2">- <div className="text-destructive text-sm font-semibold font-sans">- Error- </div>- <div className="text-destructive-foreground text-sm font-mono mt-1 whitespace-pre-wrap break-words">+ <Alert variant="destructive" className="my-2">+ <AlertCircle className="h-4 w-4" />+ <AlertTitle>Error</AlertTitle>+ <AlertDescription className="font-mono whitespace-pre-wrap break-words">{message}- </div>- </div>+ </AlertDescription>+ </Alert>);};diff --git a/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsxindex 1551f54a75..d98a5ac440 100644--- a/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx@@ -1,8 +1,9 @@"use client";-import { useState, type ComponentType } from "react";+import { useState, useEffect, type ComponentType } from "react";import { ArrowUp, Camera, X, Paperclip } from "lucide-react";import { Button } from "@/components/ui/button";+import { Alert, AlertDescription } from "@/components/ui/alert";import {Select,SelectContent,@@ -54,8 +55,18 @@ export function ChatInput({handleDragLeave,handleDrop,canAddMore,+ error,+ clearError,} = useImageAttachments();+ // Auto-clear error after 5 seconds+ useEffect(() => {+ if (error) {+ const timer = setTimeout(clearError, 5000);+ return () => clearTimeout(timer);+ }+ }, [error, clearError]);+const handleSubmit = (e: React.FormEvent) => {e.preventDefault();if (!prompt.trim()) return;@@ -103,6 +114,22 @@ export function ChatInput({onDragLeave={handleDragLeave}onDrop={handleDrop}>+ {/* Error message */}+ {error && (+ <Alert variant="destructive" className="mb-2 py-2 flex items-center justify-between text-xs">+ <AlertDescription className="text-xs">{error}</AlertDescription>+ <Button+ type="button"+ variant="ghost"+ size="icon-sm"+ onClick={clearError}+ className="h-5 w-5 text-destructive hover:text-destructive hover:bg-destructive/20"+ >+ <X className="w-3 h-3" />+ </Button>+ </Alert>+ )}+{/* Image previews */}{attachedImages.length > 0 && (<div className="mb-2 flex gap-2 overflow-x-auto pb-1 pt-2">diff --git a/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsx b/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsxindex dfc9a093df..523b13b7ab 100644--- a/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsx@@ -1,6 +1,8 @@"use client";import React from "react";+import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";+import { AlertCircle } from "lucide-react";export type ErrorType = "compilation" | "api" | "validation";@@ -21,14 +23,15 @@ export const ErrorDisplay: React.FC<ErrorDisplayProps> = ({}) => {return (<div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-error rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)] border border-destructive">- <div className="text-center max-w-[80%]">- <div className="text-destructive text-base font-semibold mb-2 font-sans">+ <Alert variant="destructive" className="max-w-[80%] bg-transparent border-none text-center">+ <AlertCircle className="h-5 w-5 mx-auto" />+ <AlertTitle className="text-base font-semibold">{errorTitles[errorType]}- </div>- <div className="text-destructive-foreground text-sm font-mono whitespace-pre-wrap break-words">+ </AlertTitle>+ <AlertDescription className="text-destructive-foreground font-mono whitespace-pre-wrap break-words">{error}- </div>- </div>+ </AlertDescription>+ </Alert></div>);};diff --git a/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsxindex 7a7c691076..70b846dae2 100644--- a/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx@@ -1,6 +1,6 @@"use client";-import { useState } from "react";+import { useState, useEffect } from "react";import Link from "next/link";import {ArrowUp,@@ -22,6 +22,7 @@ import {SelectValue,} from "@/components/ui/select";import { Button } from "@/components/ui/button";+import { Alert, AlertDescription } from "@/components/ui/alert";import { examplePrompts } from "@/examples/prompts";import { type ModelId, MODELS } from "@/types/generation";import { useImageAttachments } from "@/hooks/useImageAttachments";@@ -58,8 +59,18 @@ export function LandingPageInput({handleDragLeave,handleDrop,canAddMore,+ error,+ clearError,} = useImageAttachments();+ // Auto-clear error after 5 seconds+ useEffect(() => {+ if (error) {+ const timer = setTimeout(clearError, 5000);+ return () => clearTimeout(timer);+ }+ }, [error, clearError]);+const handleSubmit = (e: React.FormEvent) => {e.preventDefault();if (!prompt.trim() || isNavigating) return;@@ -89,6 +100,22 @@ export function LandingPageInput({onDragLeave={handleDragLeave}onDrop={handleDrop}>+ {/* Error message */}+ {error && (+ <Alert variant="destructive" className="mb-3 flex items-center justify-between">+ <AlertDescription>{error}</AlertDescription>+ <Button+ type="button"+ variant="ghost"+ size="icon-sm"+ onClick={clearError}+ className="h-6 w-6 text-destructive hover:text-destructive hover:bg-destructive/20"+ >+ <X className="w-4 h-4" />+ </Button>+ </Alert>+ )}+{/* Image previews */}{attachedImages.length > 0 && (<div className="mb-3 flex gap-2 overflow-x-auto pb-1 pt-2">diff --git a/packages/template-prompt-to-motion-graphics/src/components/ui/alert.tsx b/packages/template-prompt-to-motion-graphics/src/components/ui/alert.tsxnew file mode 100644index 0000000000..14213546e5--- /dev/null+++ b/packages/template-prompt-to-motion-graphics/src/components/ui/alert.tsx@@ -0,0 +1,66 @@+import * as React from "react"+import { cva, type VariantProps } from "class-variance-authority"++import { cn } from "@/lib/utils"++const alertVariants = cva(+ "relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",+ {+ variants: {+ variant: {+ default: "bg-card text-card-foreground",+ destructive:+ "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",+ },+ },+ defaultVariants: {+ variant: "default",+ },+ }+)++function Alert({+ className,+ variant,+ ...props+}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {+ return (+ <div+ data-slot="alert"+ role="alert"+ className={cn(alertVariants({ variant }), className)}+ {...props}+ />+ )+}++function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="alert-title"+ className={cn(+ "col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",+ className+ )}+ {...props}+ />+ )+}++function AlertDescription({+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="alert-description"+ className={cn(+ "text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",+ className+ )}+ {...props}+ />+ )+}++export { Alert, AlertTitle, AlertDescription }diff --git a/packages/template-prompt-to-motion-graphics/src/hooks/useImageAttachments.ts b/packages/template-prompt-to-motion-graphics/src/hooks/useImageAttachments.tsindex 2a3f9a0d9b..a8e8130f8d 100644--- a/packages/template-prompt-to-motion-graphics/src/hooks/useImageAttachments.ts+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useImageAttachments.ts@@ -2,6 +2,8 @@ import { useState, useRef, useCallback, type ChangeEvent, type DragEvent, type Cimport { fileToBase64 } from "@/helpers/capture-frame";const MAX_ATTACHED_IMAGES = 4;+const MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024; // 10MB per image+const MAX_FILE_SIZE_MB = MAX_FILE_SIZE_BYTES / (1024 * 1024);interface UseImageAttachmentsReturn {attachedImages: string[];@@ -16,13 +18,42 @@ interface UseImageAttachmentsReturn {handleDragLeave: (e: DragEvent) => void;handleDrop: (e: DragEvent) => Promise<void>;canAddMore: boolean;+ error: string | null;+ clearError: () => void;}export function useImageAttachments(): UseImageAttachmentsReturn {const [attachedImages, setAttachedImages] = useState<string[]>([]);const [isDragging, setIsDragging] = useState(false);+ const [error, setError] = useState<string | null>(null);const fileInputRef = useRef<HTMLInputElement>(null);+ const clearError = useCallback(() => {+ setError(null);+ }, []);++ const filterValidFiles = useCallback((files: File[]): File[] => {+ const validFiles: File[] = [];+ const oversizedFiles: File[] = [];++ for (const file of files) {+ if (file.size > MAX_FILE_SIZE_BYTES) {+ oversizedFiles.push(file);+ } else {+ validFiles.push(file);+ }+ }++ if (oversizedFiles.length > 0) {+ const fileNames = oversizedFiles.map((f) => f.name).join(", ");+ setError(+ `${oversizedFiles.length === 1 ? "File" : "Files"} too large (max ${MAX_FILE_SIZE_MB}MB): ${fileNames}`+ );+ }++ return validFiles;+ }, []);+const addImages = useCallback((newImages: string[]) => {setAttachedImages((prev) => {const combined = [...prev, ...newImages];@@ -41,11 +72,14 @@ export function useImageAttachments(): UseImageAttachmentsReturn {const handleFileSelect = useCallback(async (e: ChangeEvent<HTMLInputElement>) => {const files = Array.from(e.target.files || []);const imageFiles = files.filter((f) => f.type.startsWith("image/"));- const base64Images = await Promise.all(imageFiles.map(fileToBase64));- addImages(base64Images);+ const validFiles = filterValidFiles(imageFiles);+ if (validFiles.length > 0) {+ const base64Images = await Promise.all(validFiles.map(fileToBase64));+ addImages(base64Images);+ }// Reset input so same file can be selected againe.target.value = "";- }, [addImages]);+ }, [addImages, filterValidFiles]);const handlePaste = useCallback(async (e: ClipboardEvent) => {const items = Array.from(e.clipboardData.items);@@ -55,10 +89,13 @@ export function useImageAttachments(): UseImageAttachmentsReturn {const files = imageItems.map((item) => item.getAsFile()).filter((f): f is File => f !== null);- const base64Images = await Promise.all(files.map(fileToBase64));- addImages(base64Images);+ const validFiles = filterValidFiles(files);+ if (validFiles.length > 0) {+ const base64Images = await Promise.all(validFiles.map(fileToBase64));+ addImages(base64Images);+ }}- }, [addImages]);+ }, [addImages, filterValidFiles]);const handleDragOver = useCallback((e: DragEvent) => {e.preventDefault();@@ -76,9 +113,12 @@ export function useImageAttachments(): UseImageAttachmentsReturn {const files = Array.from(e.dataTransfer.files);const imageFiles = files.filter((f) => f.type.startsWith("image/"));- const base64Images = await Promise.all(imageFiles.map(fileToBase64));- addImages(base64Images);- }, [addImages]);+ const validFiles = filterValidFiles(imageFiles);+ if (validFiles.length > 0) {+ const base64Images = await Promise.all(validFiles.map(fileToBase64));+ addImages(base64Images);+ }+ }, [addImages, filterValidFiles]);return {attachedImages,@@ -93,5 +133,7 @@ export function useImageAttachments(): UseImageAttachmentsReturn {handleDragLeave,handleDrop,canAddMore: attachedImages.length < MAX_ATTACHED_IMAGES,+ error,+ clearError,};}