// apps/web/src/components/editor/common/new-document-dialog.tsx import { useState } from "react"; import { cn } from "@/lib/utils"; import { useEditorStore } from "@/stores/editor-store"; const PRESETS = [ { label: "Custom", width: 1920, height: 1080 }, { label: "1920x1080 (HD)", width: 1920, height: 1080 }, { label: "3840x2160 (4K)", width: 3840, height: 2160 }, { label: "1080x1080 (Instagram)", width: 1080, height: 1080 }, { label: "1200x628 (Facebook)", width: 1200, height: 628 }, { label: "800x600", width: 800, height: 600 }, { label: "1280x720", width: 1280, height: 720 }, ]; const BACKGROUNDS = ["White", "Black", "Transparent"] as const; interface NewDocumentDialogProps { open: boolean; onClose: () => void; } export function NewDocumentDialog({ open, onClose }: NewDocumentDialogProps) { const [width, setWidth] = useState(1920); const [height, setHeight] = useState(1080); const [preset, setPreset] = useState("1920x1080 (HD)"); const [background, setBackground] = useState<(typeof BACKGROUNDS)[number]>("White"); const loadImage = useEditorStore((s) => s.loadImage); if (!open) return null; const handlePresetChange = (e: React.ChangeEvent) => { const selected = PRESETS.find((p) => p.label === e.target.value); if (selected) { setPreset(selected.label); if (selected.label !== "Custom") { setWidth(selected.width); setHeight(selected.height); } } }; const handleCreate = () => { const canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; const ctx = canvas.getContext("2d"); if (ctx) { if (background === "White") { ctx.fillStyle = "#ffffff"; ctx.fillRect(0, 0, width, height); } else if (background === "Black") { ctx.fillStyle = "#000000"; ctx.fillRect(0, 0, width, height); } } const url = canvas.toDataURL("image/png"); loadImage(url, width, height); onClose(); }; return (

New Document

{ setWidth(Number(e.target.value)); setPreset("Custom"); }} className="w-full mt-1 px-2 py-1.5 bg-muted border border-border rounded text-sm text-foreground" min={1} max={10000} />
{ setHeight(Number(e.target.value)); setPreset("Custom"); }} className="w-full mt-1 px-2 py-1.5 bg-muted border border-border rounded text-sm text-foreground" min={1} max={10000} />
Background
{BACKGROUNDS.map((bg) => ( ))}
); }