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

254 lines
9.3 KiB
TypeScript
Raw Normal View History

2025-09-01 11:48:12 +09:00
"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";
2025-12-09 17:08:10 +09:00
import { Palette, Type, Square } from "lucide-react";
2025-09-01 11:48:12 +09:00
import { ComponentStyle } from "@/types/screen";
2025-12-09 17:08:10 +09:00
import { ColorPickerWithTransparent } from "./common/ColorPickerWithTransparent";
2025-09-01 11:48:12 +09:00
export default function StyleEditor({ style, onStyleChange, className }: StyleEditorProps) {
2025-10-15 10:24:33 +09:00
const [localStyle, setLocalStyle] = useState<ComponentStyle>(style || {});
2025-09-01 11:48:12 +09:00
useEffect(() => {
2025-10-15 10:24:33 +09:00
setLocalStyle(style || {});
2025-09-01 11:48:12 +09:00
}, [style]);
const handleStyleChange = (property: keyof ComponentStyle, value: any) => {
const newStyle = { ...localStyle, [property]: value };
setLocalStyle(newStyle);
onStyleChange(newStyle);
};
return (
2025-10-28 17:33:03 +09:00
<div className={`space-y-4 p-3 ${className}`}>
{/* 테두리 섹션 */}
2025-10-28 17:33:03 +09:00
<div className="space-y-2">
<div className="flex items-center gap-2">
2025-10-28 17:33:03 +09:00
<Square className="text-primary h-3.5 w-3.5" />
2025-10-17 16:21:08 +09:00
<h3 className="text-sm font-semibold"></h3>
</div>
2025-10-28 17:33:03 +09:00
<Separator className="my-1.5" />
<div className="space-y-2">
<div className="grid grid-cols-2 gap-2">
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="borderWidth" className="text-xs font-medium">
</Label>
<Input
id="borderWidth"
type="text"
2025-10-17 16:21:08 +09:00
placeholder="1px"
value={localStyle.borderWidth || ""}
onChange={(e) => handleStyleChange("borderWidth", e.target.value)}
2025-10-28 17:33:03 +09:00
className="h-6 w-full px-2 py-0 text-xs"
/>
</div>
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<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">
2025-10-28 17:33:03 +09:00
</SelectItem>
<SelectItem value="dashed" className="text-xs">
2025-10-28 17:33:03 +09:00
</SelectItem>
<SelectItem value="dotted" className="text-xs">
2025-10-28 17:33:03 +09:00
</SelectItem>
<SelectItem value="none" className="text-xs">
2025-10-28 17:33:03 +09:00
</SelectItem>
</SelectContent>
</Select>
</div>
</div>
2025-09-01 11:48:12 +09:00
2025-12-09 17:08:10 +09:00
<div className="space-y-2">
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="borderColor" className="text-xs font-medium">
</Label>
2025-12-09 17:08:10 +09:00
<ColorPickerWithTransparent
id="borderColor"
value={localStyle.borderColor}
onChange={(value) => handleStyleChange("borderColor", value)}
defaultColor="#e5e7eb"
placeholder="#e5e7eb"
/>
</div>
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="borderRadius" className="text-xs font-medium">
</Label>
<Input
id="borderRadius"
type="text"
2025-10-17 16:21:08 +09:00
placeholder="5px"
value={localStyle.borderRadius || ""}
onChange={(e) => handleStyleChange("borderRadius", e.target.value)}
2025-10-28 17:33:03 +09:00
className="h-6 w-full px-2 py-0 text-xs"
/>
</div>
</div>
</div>
</div>
{/* 배경 섹션 */}
2025-10-28 17:33:03 +09:00
<div className="space-y-2">
<div className="flex items-center gap-2">
2025-10-28 17:33:03 +09:00
<Palette className="text-primary h-3.5 w-3.5" />
2025-10-17 16:21:08 +09:00
<h3 className="text-sm font-semibold"></h3>
</div>
2025-10-28 17:33:03 +09:00
<Separator className="my-1.5" />
<div className="space-y-2">
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="backgroundColor" className="text-xs font-medium">
2025-10-28 17:33:03 +09:00
2025-10-17 16:21:08 +09:00
</Label>
2025-12-09 17:08:10 +09:00
<ColorPickerWithTransparent
id="backgroundColor"
value={localStyle.backgroundColor}
onChange={(value) => handleStyleChange("backgroundColor", value)}
defaultColor="#ffffff"
placeholder="#ffffff"
/>
</div>
2025-09-01 11:48:12 +09:00
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="backgroundImage" className="text-xs font-medium">
(CSS)
2025-10-17 16:21:08 +09:00
</Label>
<Input
id="backgroundImage"
type="text"
placeholder="url('image.jpg')"
value={localStyle.backgroundImage || ""}
onChange={(e) => handleStyleChange("backgroundImage", e.target.value)}
2025-10-28 17:33:03 +09:00
className="h-6 w-full px-2 py-0 text-xs"
/>
<p className="text-[10px] text-muted-foreground">
( )
</p>
</div>
</div>
</div>
{/* 텍스트 섹션 */}
2025-10-28 17:33:03 +09:00
<div className="space-y-2">
<div className="flex items-center gap-2">
2025-10-28 17:33:03 +09:00
<Type className="text-primary h-3.5 w-3.5" />
2025-10-17 16:21:08 +09:00
<h3 className="text-sm font-semibold"></h3>
</div>
2025-10-28 17:33:03 +09:00
<Separator className="my-1.5" />
<div className="space-y-2">
2025-12-09 17:08:10 +09:00
<div className="space-y-2">
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="color" className="text-xs font-medium">
</Label>
2025-12-09 17:08:10 +09:00
<ColorPickerWithTransparent
id="color"
value={localStyle.color}
onChange={(value) => handleStyleChange("color", value)}
defaultColor="#000000"
placeholder="#000000"
/>
</div>
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
2025-10-17 16:21:08 +09:00
<Label htmlFor="fontSize" className="text-xs font-medium">
</Label>
<Input
id="fontSize"
type="text"
2025-10-17 16:21:08 +09:00
placeholder="14px"
value={localStyle.fontSize || ""}
onChange={(e) => handleStyleChange("fontSize", e.target.value)}
2025-10-28 17:33:03 +09:00
className="h-6 w-full px-2 py-0 text-xs"
/>
</div>
</div>
2025-09-01 11:48:12 +09:00
2025-10-22 17:19:47 +09:00
<div className="grid grid-cols-2 gap-2">
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
<Label htmlFor="fontWeight" className="text-xs font-medium">
2025-10-17 16:21:08 +09:00
</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">
2025-10-28 16:16:00 +09:00
</SelectItem>
<SelectItem value="bold" className="text-xs">
2025-10-28 16:16:00 +09:00
</SelectItem>
<SelectItem value="100" className="text-xs">
2025-10-28 16:16:00 +09:00
100
</SelectItem>
<SelectItem value="400" className="text-xs">
2025-10-28 16:16:00 +09:00
400
</SelectItem>
<SelectItem value="500" className="text-xs">
2025-10-28 16:16:00 +09:00
500
</SelectItem>
<SelectItem value="600" className="text-xs">
2025-10-28 16:16:00 +09:00
600
</SelectItem>
<SelectItem value="700" className="text-xs">
2025-10-28 16:16:00 +09:00
700
</SelectItem>
</SelectContent>
</Select>
</div>
2025-10-28 17:33:03 +09:00
<div className="space-y-1">
<Label htmlFor="textAlign" className="text-xs font-medium">
2025-10-17 16:21:08 +09:00
</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">
2025-10-28 16:16:00 +09:00
</SelectItem>
<SelectItem value="center" className="text-xs">
2025-10-28 16:16:00 +09:00
</SelectItem>
<SelectItem value="right" className="text-xs">
2025-10-28 16:16:00 +09:00
</SelectItem>
<SelectItem value="justify" className="text-xs">
2025-10-28 16:16:00 +09:00
</SelectItem>
</SelectContent>
</Select>
</div>
</div>
</div>
</div>
2025-09-01 11:48:12 +09:00
</div>
);
}