"use client"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ComponentConfig } from "@/types/report"; import { useReportDesigner } from "@/contexts/ReportDesignerContext"; const FONT_FAMILIES = [ "Malgun Gothic", "NanumGothic", "NanumMyeongjo", "굴림", "돋움", "바탕", "Times New Roman", "Arial", ]; interface Props { componentIds: string[]; components: ComponentConfig[]; } type EditableField = | "fontSize" | "fontFamily" | "fontColor" | "fontWeight" | "textAlign" | "backgroundColor" | "borderWidth" | "borderColor"; function getCommonValue(components: ComponentConfig[], field: EditableField): T | "mixed" { const values = components.map((c) => c[field as keyof ComponentConfig]); const first = values[0]; return values.every((v) => v === first) ? (first as T) : "mixed"; } export function MultiSelectProperties({ componentIds, components }: Props) { const { updateComponent } = useReportDesigner(); const selected = components.filter((c) => componentIds.includes(c.id)); const count = selected.length; const applyToAll = (patch: Partial) => { componentIds.forEach((id) => updateComponent(id, patch)); }; const commonFontSize = getCommonValue(selected, "fontSize"); const commonFontFamily = getCommonValue(selected, "fontFamily"); const commonFontColor = getCommonValue(selected, "fontColor"); const commonFontWeight = getCommonValue(selected, "fontWeight"); const commonTextAlign = getCommonValue(selected, "textAlign"); const commonBgColor = getCommonValue(selected, "backgroundColor"); const commonBorderWidth = getCommonValue(selected, "borderWidth"); const commonBorderColor = getCommonValue(selected, "borderColor"); return ( {count}개 컴포넌트 선택됨

공통 속성을 변경하면 선택된 모든 컴포넌트에 적용됩니다.

{/* 글꼴 크기 */}
{ const val = parseInt(e.target.value); if (val > 0) applyToAll({ fontSize: val }); }} className="h-8" />
{/* 폰트 패밀리 */}
{/* 글꼴 색상 */}
applyToAll({ fontColor: e.target.value })} className="h-8 w-16" /> applyToAll({ fontColor: e.target.value })} className="h-8 flex-1 font-mono text-xs" />
{/* 글꼴 굵기 */}
{/* 텍스트 정렬 */}
{/* 배경 색상 */}
applyToAll({ backgroundColor: e.target.value })} className="h-8 w-16" /> applyToAll({ backgroundColor: e.target.value })} className="h-8 flex-1 font-mono text-xs" />
{/* 테두리 */}
applyToAll({ borderWidth: parseInt(e.target.value) || 0 })} className="h-8" />
applyToAll({ borderColor: e.target.value })} className="h-8" />
); }