Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: enhance ExportDropdown with TabButton component and streamline bitrate options

CristianOlivera1a9e7c50f1ee2
diff --git a/app/components/ui/ExportDropdown.tsx b/app/components/ui/ExportDropdown.tsx
index 559d002..7eed30e 100644
--- a/app/components/ui/ExportDropdown.tsx
+++ b/app/components/ui/ExportDropdown.tsx
@@ -1,6 +1,7 @@
"use client";
import { Button } from "@/components/ui/button";
+import { TabButton } from "@/components/ui/TabButton";
import { Icon } from "@iconify/react";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import type { ExportQuality } from "@/types";
@@ -20,7 +21,7 @@ interface ExportDropdownProps {
}
type VideoFormat = "mp4" | "webm" | "gif";
-type BitratePreset = "whatsapp" | "balanced" | "youtube" | "custom";
+type BitratePreset = "balanced" | "youtube" | "custom";
interface QualityOption {
id: ExportQuality;
@@ -62,8 +63,6 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
// Calculate effective bitrate in bits/sec based on preset or resolution
const effectiveBitrateBps = useMemo(() => {
switch (bitrateMode) {
- case "whatsapp":
- return 3_000_000; // 3 Mbps (~22MB/min, easily fits WhatsApp/Discord limits)
case "balanced":
return selectedQuality === "4k" ? 25_000_000 : selectedQuality === "2k" ? 16_000_000 : 10_000_000;
case "youtube":
@@ -106,140 +105,98 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
</PopoverTrigger>
<PopoverContent
align="end"
- className="w-[390px] p-0 bg-background/95 backdrop-blur-xl border border-border/80 text-foreground shadow-2xl rounded-xl overflow-hidden z-999999 max-h-[85vh] flex flex-col"
+ className="w-[390px] p-0 bg-background/95 backdrop-blur-xl border border-border/80 text-foreground shadow-2xl rounded-xl overflow-hidden z-999999 max-h-[90vh] flex flex-col"
>
- {/* Header */}
<div className="px-4 py-3 border-b border-border/60 bg-muted/40 flex items-center justify-between shrink-0">
<div className="flex items-center gap-2">
- <div className="w-6 h-6 rounded-md bg-blue-500/10 text-blue-500 flex items-center justify-center border border-blue-500/20">
- <Icon icon="lucide:video" width="14" />
- </div>
<span className="text-xs font-semibold uppercase tracking-wider text-foreground">
Export Video
</span>
</div>
- <div className="flex items-center gap-1.5">
- <span className="text-[10px] font-mono font-medium px-2 py-0.5 rounded-full bg-blue-500/10 text-blue-400 border border-blue-500/20">
- ~{estimatedMbPerMin} MB/min
- </span>
- {isTransparent && (
- <span className="text-[10px] font-medium px-2 py-0.5 rounded-full bg-cyan-500/10 text-cyan-400 border border-cyan-500/20">
- Alpha
- </span>
- )}
- </div>
</div>
<div className="p-4 space-y-4 overflow-y-auto custom-scrollbar flex-1">
- {/* Format Switcher */}
<div>
<div className="flex items-center justify-between mb-1.5">
<span className="text-xs font-medium text-muted-foreground">Format</span>
- <span className="text-[10px] text-muted-foreground/70 font-mono">
- {selectedFormat === "mp4" ? "H.264 · WebCodecs" : selectedFormat === "webm" ? "VP9 · Alpha" : "Animated Loop"}
- </span>
</div>
<div className="grid grid-cols-3 gap-1.5 p-1 bg-muted/50 rounded-lg border border-border/50">
- <button
- type="button"
+ <TabButton
+ label="MP4"
+ isActive={selectedFormat === "mp4"}
onClick={() => setSelectedFormat("mp4")}
- className={`py-1.5 px-2 text-xs font-medium rounded-md transition-all flex items-center justify-center gap-1.5 ${selectedFormat === "mp4"
- ? "bg-background text-foreground shadow-sm font-semibold border border-border/40"
- : "text-muted-foreground hover:text-foreground"
- }`}
+ className="flex-1 py-1.5 px-2 text-xs font-medium rounded-md transition-all flex items-center justify-center gap-1.5"
+ activeClassName="bg-background text-foreground shadow-sm font-semibold border border-border/40"
>
<Icon icon="mdi:video" width="14" className={selectedFormat === "mp4" ? "text-blue-500" : ""} />
MP4
- </button>
- <button
- type="button"
+ </TabButton>
+ <TabButton
+ label="WebM"
+ isActive={selectedFormat === "webm"}
onClick={() => setSelectedFormat("webm")}
- className={`py-1.5 px-2 text-xs font-medium rounded-md transition-all flex items-center justify-center gap-1.5 ${selectedFormat === "webm"
- ? "bg-background text-foreground shadow-sm font-semibold border border-border/40"
- : "text-muted-foreground hover:text-foreground"
- }`}
+ className="flex-1 py-1.5 px-2 text-xs font-medium rounded-md transition-all flex items-center justify-center gap-1.5"
+ activeClassName="bg-background text-foreground shadow-sm font-semibold border border-border/40"
>
<Icon icon="mdi:web" width="14" className={selectedFormat === "webm" ? "text-cyan-500" : ""} />
WebM
- </button>
- <button
- type="button"
+ </TabButton>
+ <TabButton
+ label="GIF"
+ isActive={selectedFormat === "gif"}
onClick={() => setSelectedFormat("gif")}
- className={`py-1.5 px-2 text-xs font-medium rounded-md transition-all flex items-center justify-center gap-1.5 ${selectedFormat === "gif"
- ? "bg-background text-foreground shadow-sm font-semibold border border-border/40"
- : "text-muted-foreground hover:text-foreground"
- }`}
+ className="flex-1 py-1.5 px-2 text-xs font-medium rounded-md transition-all flex items-center justify-center gap-1.5"
+ activeClassName="bg-background text-foreground shadow-sm font-semibold border border-border/40"
>
<Icon icon="mdi:file-gif-box" width="14" className={selectedFormat === "gif" ? "text-orange-500" : ""} />
GIF
- </button>
+ </TabButton>
</div>
</div>
- {/* Target Preset / Bitrate Mode */}
{selectedFormat !== "gif" && (
<div>
- <div className="flex items-center justify-between mb-1.5">
- <span className="text-xs font-medium text-muted-foreground">Target Bitrate & Size</span>
- <span className="text-[10px] font-mono text-muted-foreground">
- {Math.round(effectiveBitrateBps / 1_000_000)} Mbps
- </span>
+ <div className="flex items-center mb-1.5">
+ <span className="text-xs font-medium text-muted-foreground">Target Bitrate</span>
</div>
- <div className="grid grid-cols-4 gap-1 p-1 bg-muted/40 rounded-lg border border-border/50">
- <button
- type="button"
- onClick={() => setBitrateMode("whatsapp")}
- className={`py-1.5 px-1 text-[11px] font-medium rounded transition-all flex flex-col items-center gap-0.5 ${bitrateMode === "whatsapp"
- ? "bg-emerald-500/15 text-emerald-400 border border-emerald-500/30 font-semibold"
- : "text-muted-foreground hover:text-foreground"
- }`}
- >
- <Icon icon="ic:baseline-whatsapp" width="14" className="text-emerald-500" />
- <span>WhatsApp</span>
- <span className="text-[9px] opacity-75 font-mono">3 Mbps</span>
- </button>
-
- <button
- type="button"
+ <div className="grid grid-cols-3 gap-1 p-1 bg-muted/40 rounded-lg border border-border/50">
+ <TabButton
+ label="Social"
+ isActive={bitrateMode === "balanced"}
onClick={() => setBitrateMode("balanced")}
- className={`py-1.5 px-1 text-[11px] font-medium rounded transition-all flex flex-col items-center gap-0.5 ${bitrateMode === "balanced"
- ? "bg-blue-500/15 text-blue-400 border border-blue-500/30 font-semibold"
- : "text-muted-foreground hover:text-foreground"
- }`}
+ className="flex-1 py-1.5 px-1 text-[11px] font-medium rounded-lg transition-all flex flex-col items-center gap-0.5"
+ activeClassName="bg-blue-500/15 text-blue-400 border border-blue-500/30 font-semibold"
>
<Icon icon="lucide:share-2" width="14" className="text-blue-500" />
<span>Social</span>
<span className="text-[9px] opacity-75 font-mono">Balanced</span>
- </button>
+ </TabButton>
- <button
- type="button"
+ <TabButton
+ label="YouTube"
+ isActive={bitrateMode === "youtube"}
onClick={() => setBitrateMode("youtube")}
- className={`py-1.5 px-1 text-[11px] font-medium rounded transition-all flex flex-col items-center gap-0.5 ${bitrateMode === "youtube"
- ? "bg-red-500/15 text-red-400 border border-red-500/30 font-semibold"
- : "text-muted-foreground hover:text-foreground"
- }`}
+ className="flex-1 py-1.5 px-1 text-[11px] font-medium rounded transition-all flex flex-col items-center gap-0.5"
+ activeClassName="bg-red-500/15 text-red-400 border border-red-500/30 font-semibold"
>
<Icon icon="mdi:youtube" width="14" className="text-red-500" />
<span>YouTube</span>
<span className="text-[9px] opacity-75 font-mono">Max HQ</span>
- </button>
+ </TabButton>
- <button
- type="button"
+ <TabButton
+ label="Custom"
+ isActive={bitrateMode === "custom"}
onClick={() => setBitrateMode("custom")}
- className={`py-1.5 px-1 text-[11px] font-medium rounded transition-all flex flex-col items-center gap-0.5 ${bitrateMode === "custom"
- ? "bg-purple-500/15 text-purple-400 border border-purple-500/30 font-semibold"
- : "text-muted-foreground hover:text-foreground"
- }`}
+ className="flex-1 py-1.5 px-1 text-[11px] font-medium rounded transition-all flex flex-col items-center gap-0.5"
+ activeClassName="bg-purple-500/15 text-purple-400 border border-purple-500/30 font-semibold"
>
<Icon icon="lucide:sliders" width="14" className="text-purple-500" />
<span>Custom</span>
<span className="text-[9px] opacity-75 font-mono">Slider</span>
- </button>
+ </TabButton>
</div>
- {/* Custom Bitrate Slider */}
{bitrateMode === "custom" && (
<div className="mt-2.5 p-2.5 rounded-lg border border-purple-500/30 bg-purple-500/5 space-y-1.5">
<div className="flex items-center justify-between text-xs">
@@ -265,17 +222,10 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
</div>
)}
- {/* Framerate Selection (FPS) */}
{selectedFormat !== "gif" && (
<div>
- <div className="flex items-center justify-between mb-1.5">
- <div className="flex items-center gap-1.5">
- <span className="text-xs font-medium text-muted-foreground">Framerate</span>
- <span className="text-[10px] text-blue-500/90 font-medium"> Smooth Scroll</span>
- </div>
- <span className="text-[10px] text-muted-foreground/70">
- {selectedFps === 120 ? "120/144Hz Native" : selectedFps === 60 ? "Fluid 60 FPS" : "Standard 30 FPS"}
- </span>
+ <div className="flex items-center mb-1.5">
+ <span className="text-xs font-medium text-muted-foreground">Framerate</span>
</div>
<div className="grid grid-cols-3 gap-1.5">
{FPS_PRESETS.map((preset) => {
@@ -286,17 +236,14 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
type="button"
onClick={() => setSelectedFps(preset.value)}
className={`p-2 rounded-lg border text-left transition-all relative ${isSelected
- ? "border-blue-500/60 bg-blue-500/10 text-foreground shadow-sm ring-1 ring-blue-500/30"
- : "border-border/60 bg-card/40 hover:bg-muted/60 text-muted-foreground hover:text-foreground"
+ ? "border-blue-500/60 bg-blue-500/10 text-foreground shadow-sm ring-1 ring-blue-500/30"
+ : "border-border/60 bg-card/40 hover:bg-muted/60 text-muted-foreground hover:text-foreground"
}`}
>
<div className="flex items-center justify-between">
<span className={`text-xs font-bold ${isSelected ? "text-blue-500 dark:text-blue-400" : ""}`}>
{preset.label}
</span>
- {preset.recommended && (
- <span className="w-1.5 h-1.5 rounded-full bg-blue-500 animate-pulse" />
- )}
</div>
<span className="text-[10px] text-muted-foreground block mt-0.5 leading-tight">
{preset.desc}
@@ -308,14 +255,12 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
</div>
)}
- {/* Resolution Selector */}
{selectedFormat !== "gif" ? (
<div>
- <div className="flex items-center justify-between mb-1.5">
+ <div className="flex items-center mb-1.5">
<span className="text-xs font-medium text-muted-foreground">Resolution</span>
- <span className="text-[10px] text-muted-foreground/70">Aspect 16:9</span>
</div>
- <div className="space-y-1.5 max-h-40 overflow-y-auto custom-scrollbar pr-1">
+ <div className="space-y-1.5 max-h-75 overflow-y-auto custom-scrollbar pr-1">
{QUALITY_OPTIONS.map((opt) => {
const isSelected = selectedQuality === opt.id;
return (
@@ -326,12 +271,11 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
setSelectedQuality(opt.id);
}}
className={`w-full flex items-center justify-between p-2.5 rounded-lg border text-left transition-all ${isSelected
- ? "border-primary/60 bg-primary/10 text-foreground ring-1 ring-primary/20"
- : "border-border/40 hover:border-border/80 hover:bg-muted/40 text-muted-foreground hover:text-foreground"
+ ? "border-primary/60 bg-primary/10 text-foreground ring-1 ring-primary/20"
+ : "border-border/40 hover:border-border/80 hover:bg-muted/40 text-muted-foreground hover:text-foreground"
}`}
>
<div className="flex items-center gap-2.5">
- <div className={`w-2 h-2 rounded-full ${isSelected ? "bg-primary" : "bg-muted-foreground/40"}`} />
<div>
<div className="flex items-center gap-1.5">
<span className={`text-xs font-semibold ${isSelected ? "text-foreground" : ""}`}>
@@ -369,15 +313,13 @@ export function ExportDropdown({ onExport, exportProgress, hasTransparentBackgro
)}
</div>
- {/* Footer Action */}
<div className="p-3 border-t border-border/60 bg-muted/30 flex items-center gap-2 shrink-0">
<Button
onClick={handleStartExport}
variant="primary"
className="w-full py-2.5 text-xs font-semibold gap-2 shadow-md hover:brightness-105 active:scale-[0.98] transition-all"
>
- <Icon icon="lucide:arrow-down-circle" width="16" />
- Export {selectedFormat.toUpperCase()} ({selectedFormat === "gif" ? "720p · 24fps" : `${selectedQuality.toUpperCase()} · ${selectedFps}fps · ${Math.round(effectiveBitrateBps / 1_000_000)}Mbps`})
+ Export {selectedFormat.toUpperCase()}
</Button>
</div>
</PopoverContent>
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index b347a0b..5e29154 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -1733,7 +1733,7 @@ function VideoCanvasInner({
fgCtx.save();
fgCtx.translate(fgOffsetX, fgOffsetY);
if (!imagePhoneActive) {
- drawMockupAndMedia(fgCtx, containerX, containerY, containerWidth, containerHeight, mediaSource as any, false, true, mockupDrawCtx);
+ drawMockupAndMedia(fgCtx, containerX, containerY, containerWidth, containerHeight, mediaSource, false, true, mockupDrawCtx);
}
fgCtx.restore();
@@ -1772,7 +1772,7 @@ function VideoCanvasInner({
vlCtx.imageSmoothingEnabled = true;
vlCtx.imageSmoothingQuality = 'high';
if (!imagePhoneActive) {
- drawMockupAndMedia(vlCtx, containerX, containerY, containerWidth, containerHeight, mediaSource as any, false, false, mockupDrawCtx);
+ drawMockupAndMedia(vlCtx, containerX, containerY, containerWidth, containerHeight, mediaSource, false, false, mockupDrawCtx);
}
const vm = videoMaskConfig!;
@@ -1866,7 +1866,7 @@ function VideoCanvasInner({
ctx.save();
applyVideoZoom(ctx);
if (!imagePhoneActive) {
- drawMockupAndMedia(ctx, containerX, containerY, containerWidth, containerHeight, mediaSource as any, false, false, mockupDrawCtx);
+ drawMockupAndMedia(ctx, containerX, containerY, containerWidth, containerHeight, mediaSource, false, false, mockupDrawCtx);
}
ctx.restore();
diff --git a/components/ui/TabButton.tsx b/components/ui/TabButton.tsx
index ea2706a..fb412a9 100644
--- a/components/ui/TabButton.tsx
+++ b/components/ui/TabButton.tsx
@@ -1,22 +1,35 @@
"use client";
+import type { ReactNode } from "react";
+
interface TabButtonProps {
label: string;
isActive?: boolean;
onClick?: () => void;
+ children?: ReactNode;
+ className?: string;
+ activeClassName?: string;
+ inactiveClassName?: string;
}
-export function TabButton({ label, isActive, onClick }: TabButtonProps) {
+export function TabButton({
+ label,
+ isActive = false,
+ onClick,
+ children,
+ className = "flex-1 py-1.5 rounded-md transition",
+ activeClassName = "bg-background text-foreground shadow-xs",
+ inactiveClassName = "hover:text-foreground text-muted-foreground",
+}: TabButtonProps) {
return (
<button
+ type="button"
onClick={onClick}
- className={`flex-1 py-1.5 rounded-md transition ${
- isActive
- ? "bg-background text-foreground shadow-xs"
- : "hover:text-foreground text-muted-foreground"
- }`}
+ aria-label={label}
+ aria-pressed={isActive}
+ className={`${className} ${isActive ? activeClassName : inactiveClassName}`}
>
- {label}
+ {children ?? label}
</button>
);
}