ERP-node/frontend/components/screen/StyleEditor.tsx

289 lines
11 KiB
TypeScript

"use client";
import { useState, useEffect } from "react";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { Palette, Type, Square, Box } from "lucide-react";
import { ComponentStyle } from "@/types/screen";
interface StyleEditorProps {
style: ComponentStyle;
onStyleChange: (style: ComponentStyle) => void;
className?: string;
}
export default function StyleEditor({ style, onStyleChange, className }: StyleEditorProps) {
const [localStyle, setLocalStyle] = useState<ComponentStyle>(style || {});
useEffect(() => {
setLocalStyle(style || {});
}, [style]);
const handleStyleChange = (property: keyof ComponentStyle, value: any) => {
const newStyle = { ...localStyle, [property]: value };
setLocalStyle(newStyle);
onStyleChange(newStyle);
};
return (
<div className={`space-y-4 p-3 ${className}`}>
{/* 테두리 섹션 */}
<div className="space-y-2">
<div className="flex items-center gap-2">
<Square className="text-primary h-3.5 w-3.5" />
<h3 className="text-sm font-semibold"></h3>
</div>
<Separator className="my-1.5" />
<div className="space-y-2">
<div className="grid grid-cols-2 gap-2">
<div className="space-y-1">
<Label htmlFor="borderWidth" className="text-xs font-medium">
</Label>
<Input
id="borderWidth"
type="text"
placeholder="1px"
value={localStyle.borderWidth || ""}
onChange={(e) => handleStyleChange("borderWidth", e.target.value)}
className="h-6 w-full px-2 py-0 text-xs"
/>
</div>
<div className="space-y-1">
<Label htmlFor="borderStyle" className="text-xs font-medium">
</Label>
<Select
value={localStyle.borderStyle || "solid"}
onValueChange={(value) => handleStyleChange("borderStyle", value)}
>
<SelectTrigger className=" text-xsh-6 w-full px-2 py-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="solid" className="text-xs">
</SelectItem>
<SelectItem value="dashed" className="text-xs">
</SelectItem>
<SelectItem value="dotted" className="text-xs">
</SelectItem>
<SelectItem value="none" className="text-xs">
</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="grid grid-cols-2 gap-2">
<div className="space-y-1">
<Label htmlFor="borderColor" className="text-xs font-medium">
</Label>
<div className="flex gap-1">
<Input
id="borderColor"
type="color"
value={localStyle.borderColor || "#000000"}
onChange={(e) => handleStyleChange("borderColor", e.target.value)}
className="h-6 w-12 p-1"
className="text-xs"
/>
<Input
type="text"
value={localStyle.borderColor || "#000000"}
onChange={(e) => handleStyleChange("borderColor", e.target.value)}
placeholder="#000000"
className="h-6 flex-1 text-xs"
/>
</div>
</div>
<div className="space-y-1">
<Label htmlFor="borderRadius" className="text-xs font-medium">
</Label>
<Input
id="borderRadius"
type="text"
placeholder="5px"
value={localStyle.borderRadius || ""}
onChange={(e) => handleStyleChange("borderRadius", e.target.value)}
className="h-6 w-full px-2 py-0 text-xs"
/>
</div>
</div>
</div>
</div>
{/* 배경 섹션 */}
<div className="space-y-2">
<div className="flex items-center gap-2">
<Palette className="text-primary h-3.5 w-3.5" />
<h3 className="text-sm font-semibold"></h3>
</div>
<Separator className="my-1.5" />
<div className="space-y-2">
<div className="space-y-1">
<Label htmlFor="backgroundColor" className="text-xs font-medium">
</Label>
<div className="flex gap-1">
<Input
id="backgroundColor"
type="color"
value={localStyle.backgroundColor || "#ffffff"}
onChange={(e) => handleStyleChange("backgroundColor", e.target.value)}
className="h-6 w-12 p-1"
className="text-xs"
/>
<Input
type="text"
value={localStyle.backgroundColor || "#ffffff"}
onChange={(e) => handleStyleChange("backgroundColor", e.target.value)}
placeholder="#ffffff"
className="h-6 flex-1 text-xs"
/>
</div>
</div>
<div className="space-y-1">
<Label htmlFor="backgroundImage" className="text-xs font-medium">
(CSS)
</Label>
<Input
id="backgroundImage"
type="text"
placeholder="url('image.jpg')"
value={localStyle.backgroundImage || ""}
onChange={(e) => handleStyleChange("backgroundImage", e.target.value)}
className="h-6 w-full px-2 py-0 text-xs"
/>
<p className="text-[10px] text-muted-foreground">
( )
</p>
</div>
</div>
</div>
{/* 텍스트 섹션 */}
<div className="space-y-2">
<div className="flex items-center gap-2">
<Type className="text-primary h-3.5 w-3.5" />
<h3 className="text-sm font-semibold"></h3>
</div>
<Separator className="my-1.5" />
<div className="space-y-2">
<div className="grid grid-cols-2 gap-2">
<div className="space-y-1">
<Label htmlFor="color" className="text-xs font-medium">
</Label>
<div className="flex gap-1">
<Input
id="color"
type="color"
value={localStyle.color || "#000000"}
onChange={(e) => handleStyleChange("color", e.target.value)}
className="h-6 w-12 p-1"
className="text-xs"
/>
<Input
type="text"
value={localStyle.color || "#000000"}
onChange={(e) => handleStyleChange("color", e.target.value)}
placeholder="#000000"
className="h-6 flex-1 text-xs"
/>
</div>
</div>
<div className="space-y-1">
<Label htmlFor="fontSize" className="text-xs font-medium">
</Label>
<Input
id="fontSize"
type="text"
placeholder="14px"
value={localStyle.fontSize || ""}
onChange={(e) => handleStyleChange("fontSize", e.target.value)}
className="h-6 w-full px-2 py-0 text-xs"
/>
</div>
</div>
<div className="grid grid-cols-2 gap-2">
<div className="space-y-1">
<Label htmlFor="fontWeight" className="text-xs font-medium">
</Label>
<Select
value={localStyle.fontWeight || "normal"}
onValueChange={(value) => handleStyleChange("fontWeight", value)}
>
<SelectTrigger className=" text-xsh-6 w-full px-2 py-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="normal" className="text-xs">
</SelectItem>
<SelectItem value="bold" className="text-xs">
</SelectItem>
<SelectItem value="100" className="text-xs">
100
</SelectItem>
<SelectItem value="400" className="text-xs">
400
</SelectItem>
<SelectItem value="500" className="text-xs">
500
</SelectItem>
<SelectItem value="600" className="text-xs">
600
</SelectItem>
<SelectItem value="700" className="text-xs">
700
</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-1">
<Label htmlFor="textAlign" className="text-xs font-medium">
</Label>
<Select
value={localStyle.textAlign || "left"}
onValueChange={(value) => handleStyleChange("textAlign", value)}
>
<SelectTrigger className=" text-xsh-6 w-full px-2 py-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="left" className="text-xs">
</SelectItem>
<SelectItem value="center" className="text-xs">
</SelectItem>
<SelectItem value="right" className="text-xs">
</SelectItem>
<SelectItem value="justify" className="text-xs">
</SelectItem>
</SelectContent>
</Select>
</div>
</div>
</div>
</div>
</div>
);
}