"use client"; import React from "react"; import { cn } from "@/lib/utils"; import { LayoutRow } from "@/types/grid-system"; import { ComponentData } from "@/types/screen"; import { GAP_PRESETS, buildGridClasses } from "@/lib/constants/columnSpans"; import { RealtimePreviewDynamic } from "./RealtimePreviewDynamic"; interface LayoutRowRendererProps { row: LayoutRow; components: Map; isSelected: boolean; selectedComponentId?: string; onSelectRow: () => void; onSelectComponent: (componentId: string) => void; onUpdateRow?: (row: LayoutRow) => void; } export const LayoutRowRenderer: React.FC = ({ row, components, isSelected, selectedComponentId, onSelectRow, onSelectComponent, onUpdateRow, }) => { // 행 클래스 생성 const rowClasses = cn( // 그리드 기본 "grid grid-cols-12 w-full relative", // Gap (컴포넌트 간격) GAP_PRESETS[row.gap].class, // Padding GAP_PRESETS[row.padding].class.replace("gap-", "p-"), // 높이 row.height === "auto" && "h-auto", row.height === "fixed" && row.fixedHeight && `h-[${row.fixedHeight}px]`, row.height === "min" && row.minHeight && `min-h-[${row.minHeight}px]`, row.height === "max" && row.maxHeight && `max-h-[${row.maxHeight}px]`, // 수평 정렬 row.alignment === "start" && "justify-items-start", row.alignment === "center" && "justify-items-center", row.alignment === "end" && "justify-items-end", row.alignment === "stretch" && "justify-items-stretch", row.alignment === "baseline" && "justify-items-baseline", // 수직 정렬 row.verticalAlignment === "top" && "items-start", row.verticalAlignment === "middle" && "items-center", row.verticalAlignment === "bottom" && "items-end", row.verticalAlignment === "stretch" && "items-stretch", // 선택 상태 isSelected && "ring-2 ring-blue-500 ring-inset", // 호버 효과 "hover:bg-gray-50 transition-colors cursor-pointer border-2 border-dashed border-transparent hover:border-gray-300", ); // 배경색 스타일 const rowStyle: React.CSSProperties = { ...(row.backgroundColor && { backgroundColor: row.backgroundColor }), }; return (
{/* 행 인덱스 표시 */}
{row.rowIndex + 1}
{row.components.length === 0 ? ( // 빈 행

컴포넌트를 여기에 드래그하세요

) : ( // 컴포넌트 렌더링 row.components.map((rowComponent) => { const component = components.get(rowComponent.componentId); if (!component) return null; // 그리드 클래스 생성 const componentClasses = cn( // 컬럼 스팬 buildGridClasses(rowComponent.columnSpan, rowComponent.columnStart), // 정렬 순서 rowComponent.order && `order-${rowComponent.order}`, // 선택 상태 selectedComponentId === component.id && "ring-2 ring-green-500 ring-inset", ); // 오프셋 스타일 (여백) const componentStyle: React.CSSProperties = { ...(rowComponent.offset && { marginLeft: `${(GAP_PRESETS[rowComponent.offset as any]?.value || 0) * 4}px`, }), }; return (
{ e.stopPropagation(); onSelectComponent(component.id); }} > { e?.stopPropagation(); onSelectComponent(component.id); }} />
); }) )} {/* 선택 시 행 설정 버튼 */} {isSelected && (
)}
); };