feat(stitch): redesign settings UI with grid, alignment, border, radius, quality

This commit is contained in:
Siddharth Kumar Sah
2026-04-13 11:46:10 +08:00
parent c4d298ac3e
commit d67dd18a30
+127 -21
View File
@@ -1,21 +1,27 @@
import { ChevronDown, ChevronUp, Download, Loader2 } from "lucide-react"; import { Download, Loader2 } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
import { formatHeaders } from "@/lib/api"; import { formatHeaders } from "@/lib/api";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
type Direction = "horizontal" | "vertical"; type Direction = "horizontal" | "vertical" | "grid";
type ResizeMode = "fit" | "original"; type ResizeMode = "fit" | "original" | "stretch" | "crop";
type Alignment = "start" | "center" | "end";
type OutputFormat = "png" | "jpeg" | "webp"; type OutputFormat = "png" | "jpeg" | "webp";
export function StitchSettings() { export function StitchSettings() {
const { files, processing, error, setProcessing, setError, setProcessedUrl, setSizes, setJobId } = const { files, processing, error, setProcessing, setError, setProcessedUrl, setSizes, setJobId } =
useFileStore(); useFileStore();
const [direction, setDirection] = useState<Direction>("horizontal"); const [direction, setDirection] = useState<Direction>("horizontal");
const [showAdvanced, setShowAdvanced] = useState(false); const [gridColumns, setGridColumns] = useState(3);
const [resizeMode, setResizeMode] = useState<ResizeMode>("fit"); const [resizeMode, setResizeMode] = useState<ResizeMode>("fit");
const [alignment, setAlignment] = useState<Alignment>("center");
const [gap, setGap] = useState(0); const [gap, setGap] = useState(0);
const [border, setBorder] = useState(0);
const [cornerRadius, setCornerRadius] = useState(0);
const [backgroundColor, setBackgroundColor] = useState("#FFFFFF"); const [backgroundColor, setBackgroundColor] = useState("#FFFFFF");
const [format, setFormat] = useState<OutputFormat>("png"); const [format, setFormat] = useState<OutputFormat>("png");
const [quality, setQuality] = useState(90);
const [downloadUrl, setDownloadUrl] = useState<string | null>(null); const [downloadUrl, setDownloadUrl] = useState<string | null>(null);
const handleProcess = async () => { const handleProcess = async () => {
@@ -32,7 +38,18 @@ export function StitchSettings() {
} }
formData.append( formData.append(
"settings", "settings",
JSON.stringify({ direction, resizeMode, gap, backgroundColor, format }), JSON.stringify({
direction,
gridColumns,
resizeMode,
alignment,
gap,
border,
cornerRadius,
backgroundColor,
format,
quality,
}),
); );
const res = await fetch("/api/v1/tools/stitch", { const res = await fetch("/api/v1/tools/stitch", {
@@ -62,10 +79,11 @@ export function StitchSettings() {
return ( return (
<div className="space-y-4"> <div className="space-y-4">
{/* Layout */}
<div> <div>
<p className="text-xs text-muted-foreground">Direction</p> <p className="text-xs text-muted-foreground">Direction</p>
<div className="grid grid-cols-2 gap-1 mt-1"> <div className="grid grid-cols-3 gap-1 mt-1">
{(["horizontal", "vertical"] as const).map((d) => ( {(["horizontal", "vertical", "grid"] as const).map((d) => (
<button <button
type="button" type="button"
key={d} key={d}
@@ -78,21 +96,33 @@ export function StitchSettings() {
</div> </div>
</div> </div>
<button {direction === "grid" && (
type="button" <div>
onClick={() => setShowAdvanced(!showAdvanced)} <div className="flex justify-between items-center">
className="flex items-center gap-1 text-xs text-muted-foreground" <label htmlFor="stitch-grid-columns" className="text-xs text-muted-foreground">
> Grid Columns
Advanced </label>
{showAdvanced ? <ChevronUp className="h-3 w-3" /> : <ChevronDown className="h-3 w-3" />} <span className="text-xs font-mono text-foreground">{gridColumns}</span>
</button> </div>
<input
id="stitch-grid-columns"
type="range"
min={2}
max={10}
value={gridColumns}
onChange={(e) => setGridColumns(Number(e.target.value))}
className="w-full mt-1"
/>
</div>
)}
{showAdvanced && ( <div className="border-t border-border" />
<div className="space-y-4 border border-border rounded-lg p-3">
{/* Size Handling */}
<div> <div>
<p className="text-xs text-muted-foreground">Resize Mode</p> <p className="text-xs text-muted-foreground">Resize Mode</p>
<div className="grid grid-cols-2 gap-1 mt-1"> <div className="grid grid-cols-4 gap-1 mt-1">
{(["fit", "original"] as const).map((m) => ( {(["fit", "original", "stretch", "crop"] as const).map((m) => (
<button <button
type="button" type="button"
key={m} key={m}
@@ -105,6 +135,25 @@ export function StitchSettings() {
</div> </div>
</div> </div>
<div>
<p className="text-xs text-muted-foreground">Alignment</p>
<div className="grid grid-cols-3 gap-1 mt-1">
{(["start", "center", "end"] as const).map((a) => (
<button
type="button"
key={a}
onClick={() => setAlignment(a)}
className={`capitalize text-xs py-1.5 rounded ${alignment === a ? "bg-primary text-primary-foreground" : "bg-muted text-muted-foreground"}`}
>
{a}
</button>
))}
</div>
</div>
<div className="border-t border-border" />
{/* Spacing & Border */}
<div> <div>
<div className="flex justify-between items-center"> <div className="flex justify-between items-center">
<label htmlFor="stitch-gap" className="text-xs text-muted-foreground"> <label htmlFor="stitch-gap" className="text-xs text-muted-foreground">
@@ -116,13 +165,49 @@ export function StitchSettings() {
id="stitch-gap" id="stitch-gap"
type="range" type="range"
min={0} min={0}
max={100} max={200}
value={gap} value={gap}
onChange={(e) => setGap(Number(e.target.value))} onChange={(e) => setGap(Number(e.target.value))}
className="w-full mt-1" className="w-full mt-1"
/> />
</div> </div>
<div>
<div className="flex justify-between items-center">
<label htmlFor="stitch-border" className="text-xs text-muted-foreground">
Border
</label>
<span className="text-xs font-mono text-foreground">{border}px</span>
</div>
<input
id="stitch-border"
type="range"
min={0}
max={50}
value={border}
onChange={(e) => setBorder(Number(e.target.value))}
className="w-full mt-1"
/>
</div>
<div>
<div className="flex justify-between items-center">
<label htmlFor="stitch-corner-radius" className="text-xs text-muted-foreground">
Corner Radius
</label>
<span className="text-xs font-mono text-foreground">{cornerRadius}px</span>
</div>
<input
id="stitch-corner-radius"
type="range"
min={0}
max={50}
value={cornerRadius}
onChange={(e) => setCornerRadius(Number(e.target.value))}
className="w-full mt-1"
/>
</div>
<div> <div>
<label htmlFor="stitch-background-color" className="text-xs text-muted-foreground"> <label htmlFor="stitch-background-color" className="text-xs text-muted-foreground">
Background Color Background Color
@@ -136,8 +221,11 @@ export function StitchSettings() {
/> />
</div> </div>
<div className="border-t border-border" />
{/* Output */}
<div> <div>
<p className="text-xs text-muted-foreground">Output Format</p> <p className="text-xs text-muted-foreground">Format</p>
<div className="grid grid-cols-3 gap-1 mt-1"> <div className="grid grid-cols-3 gap-1 mt-1">
{(["png", "jpeg", "webp"] as const).map((f) => ( {(["png", "jpeg", "webp"] as const).map((f) => (
<button <button
@@ -151,6 +239,24 @@ export function StitchSettings() {
))} ))}
</div> </div>
</div> </div>
{(format === "jpeg" || format === "webp") && (
<div>
<div className="flex justify-between items-center">
<label htmlFor="stitch-quality" className="text-xs text-muted-foreground">
Quality
</label>
<span className="text-xs font-mono text-foreground">{quality}%</span>
</div>
<input
id="stitch-quality"
type="range"
min={1}
max={100}
value={quality}
onChange={(e) => setQuality(Number(e.target.value))}
className="w-full mt-1"
/>
</div> </div>
)} )}