275 lines
10 KiB
TypeScript
275 lines
10 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-6 p-6 ${className}`}>
|
|
{/* 테두리 섹션 */}
|
|
<div className="space-y-3">
|
|
<div className="flex items-center gap-2">
|
|
<Square className="text-primary h-4 w-4" />
|
|
<h3 className="text-sm font-semibold">테두리</h3>
|
|
</div>
|
|
<Separator className="my-2" />
|
|
<div className="space-y-3">
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div className="space-y-1.5">
|
|
<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-8 text-xs"
|
|
/>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="borderStyle" className="text-xs font-medium">
|
|
스타일
|
|
</Label>
|
|
<Select
|
|
value={localStyle.borderStyle || "solid"}
|
|
onValueChange={(value) => handleStyleChange("borderStyle", value)}
|
|
>
|
|
<SelectTrigger className="h-8 text-xs">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="solid">실선</SelectItem>
|
|
<SelectItem value="dashed">파선</SelectItem>
|
|
<SelectItem value="dotted">점선</SelectItem>
|
|
<SelectItem value="none">없음</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="borderColor" className="text-xs font-medium">
|
|
색상
|
|
</Label>
|
|
<div className="flex gap-2">
|
|
<Input
|
|
id="borderColor"
|
|
type="color"
|
|
value={localStyle.borderColor || "#000000"}
|
|
onChange={(e) => handleStyleChange("borderColor", e.target.value)}
|
|
className="h-8 w-14 p-1 text-xs"
|
|
/>
|
|
<Input
|
|
type="text"
|
|
value={localStyle.borderColor || "#000000"}
|
|
onChange={(e) => handleStyleChange("borderColor", e.target.value)}
|
|
placeholder="#000000"
|
|
className="h-8 flex-1 text-xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<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-8 text-xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 배경 섹션 */}
|
|
<div className="space-y-3">
|
|
<div className="flex items-center gap-2">
|
|
<Palette className="text-primary h-4 w-4" />
|
|
<h3 className="text-sm font-semibold">배경</h3>
|
|
</div>
|
|
<Separator className="my-2" />
|
|
<div className="space-y-3">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="backgroundColor" className="text-xs font-medium">
|
|
배경 색상
|
|
</Label>
|
|
<div className="flex gap-2">
|
|
<Input
|
|
id="backgroundColor"
|
|
type="color"
|
|
value={localStyle.backgroundColor || "#ffffff"}
|
|
onChange={(e) => handleStyleChange("backgroundColor", e.target.value)}
|
|
className="h-8 w-14 p-1 text-xs"
|
|
/>
|
|
<Input
|
|
type="text"
|
|
value={localStyle.backgroundColor || "#ffffff"}
|
|
onChange={(e) => handleStyleChange("backgroundColor", e.target.value)}
|
|
placeholder="#ffffff"
|
|
className="h-8 flex-1 text-xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="backgroundImage" className="text-xs font-medium">
|
|
배경 이미지
|
|
</Label>
|
|
<Input
|
|
id="backgroundImage"
|
|
type="text"
|
|
placeholder="url('image.jpg')"
|
|
value={localStyle.backgroundImage || ""}
|
|
onChange={(e) => handleStyleChange("backgroundImage", e.target.value)}
|
|
className="h-8 text-xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 텍스트 섹션 */}
|
|
<div className="space-y-3">
|
|
<div className="flex items-center gap-2">
|
|
<Type className="text-primary h-4 w-4" />
|
|
<h3 className="text-sm font-semibold">텍스트</h3>
|
|
</div>
|
|
<Separator className="my-2" />
|
|
<div className="space-y-3">
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="color" className="text-xs font-medium">
|
|
색상
|
|
</Label>
|
|
<div className="flex gap-2">
|
|
<Input
|
|
id="color"
|
|
type="color"
|
|
value={localStyle.color || "#000000"}
|
|
onChange={(e) => handleStyleChange("color", e.target.value)}
|
|
className="h-8 w-14 p-1 text-xs"
|
|
/>
|
|
<Input
|
|
type="text"
|
|
value={localStyle.color || "#000000"}
|
|
onChange={(e) => handleStyleChange("color", e.target.value)}
|
|
placeholder="#000000"
|
|
className="h-8 flex-1 text-xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<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-8 text-xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
<div className="max-w-[140px] space-y-0.5">
|
|
<Label htmlFor="fontWeight" className="text-[10px] font-medium">
|
|
굵기
|
|
</Label>
|
|
<Select
|
|
value={localStyle.fontWeight || "normal"}
|
|
onValueChange={(value) => handleStyleChange("fontWeight", value)}
|
|
>
|
|
<SelectTrigger className="h-6 w-full px-2 text-[10px]">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="normal" className="text-[10px]">
|
|
보통
|
|
</SelectItem>
|
|
<SelectItem value="bold" className="text-[10px]">
|
|
굵게
|
|
</SelectItem>
|
|
<SelectItem value="100" className="text-[10px]">
|
|
100
|
|
</SelectItem>
|
|
<SelectItem value="400" className="text-[10px]">
|
|
400
|
|
</SelectItem>
|
|
<SelectItem value="500" className="text-[10px]">
|
|
500
|
|
</SelectItem>
|
|
<SelectItem value="600" className="text-[10px]">
|
|
600
|
|
</SelectItem>
|
|
<SelectItem value="700" className="text-[10px]">
|
|
700
|
|
</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<div className="max-w-[140px] space-y-0.5">
|
|
<Label htmlFor="textAlign" className="text-[10px] font-medium">
|
|
정렬
|
|
</Label>
|
|
<Select
|
|
value={localStyle.textAlign || "left"}
|
|
onValueChange={(value) => handleStyleChange("textAlign", value)}
|
|
>
|
|
<SelectTrigger className="h-6 w-full px-2 text-[10px]">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="left" className="text-[10px]">
|
|
왼쪽
|
|
</SelectItem>
|
|
<SelectItem value="center" className="text-[10px]">
|
|
가운데
|
|
</SelectItem>
|
|
<SelectItem value="right" className="text-[10px]">
|
|
오른쪽
|
|
</SelectItem>
|
|
<SelectItem value="justify" className="text-[10px]">
|
|
양쪽
|
|
</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|