🎥 Make videos programmatically with React
Minor cleanup
ASchwad2cab10a8a041
diff --git a/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer.tsx b/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer.tsxindex d39f99d186..db136cef48 100644--- a/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer.tsx@@ -45,83 +45,52 @@ export const AnimationPlayer: React.FC<AnimationPlayerProps> = ({errorType = "compilation",code,}) => {- if (isStreaming) {- return (- <div className="flex flex-col bg-background min-w-0 h-full">- <div className="w-full h-full flex flex-col gap-3">- <h2 className="text-sm font-medium text-muted-foreground shrink-0">- Video Preview- </h2>- <div className="w-full aspect-video max-h-[calc(100%-80px)] flex flex-col justify-center items-center gap-4 bg-background-elevated rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)]">- <div className="w-12 h-12 border-4 border-border border-t-primary rounded-full animate-spin" />- <p className="text-muted-foreground text-sm">- Waiting for code generation to finish...- </p>- </div>+ const renderContent = () => {+ if (isStreaming) {+ return (+ <div className="w-full aspect-video max-h-[calc(100%-80px)] flex flex-col justify-center items-center gap-4 bg-background-elevated rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)]">+ <div className="w-12 h-12 border-4 border-border border-t-primary rounded-full animate-spin" />+ <p className="text-muted-foreground text-sm">+ Waiting for code generation to finish...+ </p></div>- </div>- );- }+ );+ }- if (isCompiling) {- return (- <div className="flex flex-col bg-background min-w-0 h-full">- <div className="w-full h-full flex flex-col gap-3">- <h2 className="text-sm font-medium text-muted-foreground shrink-0">- Video Preview- </h2>- <div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-elevated rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)]">- <div className="w-12 h-12 border-4 border-border border-t-primary rounded-full animate-spin" />- </div>+ if (isCompiling) {+ return (+ <div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-elevated rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)]">+ <div className="w-12 h-12 border-4 border-border border-t-primary rounded-full animate-spin" /></div>- </div>- );- }+ );+ }- if (error) {- const errorTitle = errorType === "api" ? "API Error" : "Compilation Error";- return (- <div className="flex flex-col bg-background min-w-0 h-full">- <div className="w-full h-full flex flex-col gap-3">- <h2 className="text-sm font-medium text-muted-foreground shrink-0">- Video Preview- </h2>- <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">- {errorTitle}- </div>- <div className="text-destructive-foreground text-sm font-mono whitespace-pre-wrap break-words">- {error}- </div>+ if (error) {+ const errorTitle = errorType === "api" ? "API Error" : "Compilation Error";+ 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">+ {errorTitle}+ </div>+ <div className="text-destructive-foreground text-sm font-mono whitespace-pre-wrap break-words">+ {error}</div></div></div>- </div>- );- }+ );+ }- if (!Component) {- return (- <div className="flex flex-col bg-background min-w-0 h-full">- <div className="w-full h-full flex flex-col gap-3">- <h2 className="text-sm font-medium text-muted-foreground shrink-0">- Video Preview- </h2>- <div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-elevated rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)] text-muted-foreground-dim text-lg font-sans">- Select an example to get started- </div>+ if (!Component) {+ return (+ <div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-elevated rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)] text-muted-foreground-dim text-lg font-sans">+ Select an example to get started</div>- </div>- );- }+ );+ }- return (- <div className="flex flex-col bg-background min-w-0 h-full">- <div className="w-full flex flex-col gap-3 h-full">- <h2 className="text-sm font-medium text-muted-foreground shrink-0">- Video Preview- </h2>+ return (+ <><div className="w-full aspect-video max-h-[calc(100%-80px)] rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)]"><Playerkey={Component.toString()}@@ -152,6 +121,17 @@ export const AnimationPlayer: React.FC<AnimationPlayerProps> = ({onFpsChange={onFpsChange}/></div>+ </>+ );+ };++ return (+ <div className="flex flex-col bg-background min-w-0 h-full">+ <div className="w-full h-full flex flex-col gap-3">+ <h2 className="text-sm font-medium text-muted-foreground shrink-0">+ Video Preview+ </h2>+ {renderContent()}</div></div>);diff --git a/packages/template-prompt-to-motion-graphics/src/components/CodeEditor/styles.ts b/packages/template-prompt-to-motion-graphics/src/components/CodeEditor/styles.tsindex 976a7dcb3c..731cb42bb6 100644--- a/packages/template-prompt-to-motion-graphics/src/components/CodeEditor/styles.ts+++ b/packages/template-prompt-to-motion-graphics/src/components/CodeEditor/styles.ts@@ -7,29 +7,10 @@ export const EDITOR_STYLES = `.monaco-editor .margin {background-color: #1e1e1e !important;}- .readonly-line {- background-color: rgba(80, 80, 80, 0.2) !important;- }- .readonly-glyph {- background-color: rgba(255, 255, 255, 0.15);- border-radius: 2px;- margin-left: 5px;- }/* JSX syntax highlighting classes */.jsx-tag-angle-bracket { color: #808080; }.jsx-tag-name { color: #4ec9b0; }.jsx-tag-attribute-key { color: #9cdcfe; }.jsx-expression-braces { color: #ffd700; }.jsx-text { color: #ce9178; }- .jsx-tag-order-1 { }- .jsx-tag-order-2 { }- .jsx-tag-order-3 { }- /* Toast animation */- @keyframes fade-in {- from { opacity: 0; transform: translateY(-10px); }- to { opacity: 1; transform: translateY(0); }- }- .animate-fade-in {- animation: fade-in 0.2s ease-out;- }`;diff --git a/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsxindex 23857ab7c6..c522230399 100644--- a/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx@@ -3,7 +3,6 @@import { useState, forwardRef, useImperativeHandle } from "react";import {ArrowUp,- Loader2,Type,MessageCircle,Hash,@@ -18,6 +17,7 @@ import {SelectTrigger,SelectValue,} from "@/components/ui/select";+import { Button } from "@/components/ui/button";import { examplePrompts } from "@/data/examplePrompts";const iconMap: Record<string, LucideIcon> = {@@ -148,7 +148,9 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(} catch (error) {console.error("Error generating code:", error);const errorMessage =- error instanceof Error ? error.message : "An unexpected error occurred";+ error instanceof Error+ ? error.message+ : "An unexpected error occurred";onError?.(errorMessage);} finally {setIsLoading(false);@@ -232,17 +234,15 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(</SelectContent></Select>- <button+ <Buttontype="submit"- disabled={isLoading || !prompt.trim()}- className="p-2 rounded-lg bg-foreground text-background hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed transition-all"+ size="icon-sm"+ disabled={!prompt.trim()}+ loading={isLoading}+ className="bg-foreground text-background hover:bg-gray-200">- {isLoading ? (- <Loader2 className="w-5 h-5 animate-spin" />- ) : (- <ArrowUp className="w-5 h-5" />- )}- </button>+ <ArrowUp className="w-5 h-5" />+ </Button></div></div>@@ -251,7 +251,9 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(isLanding ? "justify-center mt-6 gap-2" : ""}`}>- <span className="text-muted-foreground-dim text-xs mr-1">Prompt Examples</span>+ <span className="text-muted-foreground-dim text-xs mr-1">+ Prompt Examples+ </span>{examplePrompts.map((example) => {const Icon = iconMap[example.icon];return (@@ -265,9 +267,7 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(}}className={`rounded-full bg-background-elevated border hover:brightness-125 transition-all flex items-center gap-1 px-1.5 py-0.5 text-[11px]`}>- {Icon && (- <Icon className={isLanding ? "w-3 h-3" : "w-3 h-3"} />- )}+ <Icon className="w-3 h-3" />{example.headline}</button>);diff --git a/packages/template-prompt-to-motion-graphics/src/components/ui/button.tsx b/packages/template-prompt-to-motion-graphics/src/components/ui/button.tsxindex 459b4af923..25c404885d 100644--- a/packages/template-prompt-to-motion-graphics/src/components/ui/button.tsx+++ b/packages/template-prompt-to-motion-graphics/src/components/ui/button.tsx@@ -56,8 +56,7 @@ function Button({disabled={loading || props.disabled}{...props}>- {loading && <Spinner className="size-4" />}- {children}+ {loading ? <Spinner className="size-4" /> : children}</Comp>)}