"use client"; import React from "react"; import { ComponentRendererProps } from "@/types/component"; import { ImageDisplayConfig } from "./types"; export interface ImageDisplayComponentProps extends ComponentRendererProps { config?: ImageDisplayConfig; } /** * ImageDisplay 컴포넌트 * image-display 컴포넌트입니다 */ export const ImageDisplayComponent: React.FC = ({ component, isDesignMode = false, isSelected = false, onClick, onDragStart, onDragEnd, config, className, style, ...props }) => { const componentConfig = { ...config, ...component.config, } as ImageDisplayConfig; const objectFit = componentConfig.objectFit || "contain"; const altText = componentConfig.altText || "이미지"; const borderRadius = componentConfig.borderRadius ?? 8; const showBorder = componentConfig.showBorder ?? true; const backgroundColor = componentConfig.backgroundColor || "#f9fafb"; const placeholder = componentConfig.placeholder || "이미지 없음"; const imageSrc = component.value || componentConfig.imageUrl || ""; const componentStyle: React.CSSProperties = { width: "100%", height: "100%", ...component.style, ...style, width: "100%", }; if (isDesignMode) { componentStyle.border = "1px dashed #cbd5e1"; componentStyle.borderColor = isSelected ? "#3b82f6" : "#cbd5e1"; } const handleClick = (e: React.MouseEvent) => { e.stopPropagation(); onClick?.(); }; // DOM에 전달하면 안 되는 React-specific props 필터링 const { selectedScreen, onZoneComponentDrop, onZoneClick, componentConfig: _componentConfig, component: _component, isSelected: _isSelected, onClick: _onClick, onDragStart: _onDragStart, onDragEnd: _onDragEnd, size: _size, position: _position, style: _style, screenId: _screenId, tableName: _tableName, onRefresh: _onRefresh, onClose: _onClose, ...domProps } = props; return (
{/* 라벨 렌더링 */} {component.label && (component.style?.labelDisplay ?? true) && ( )}
{ if (!componentConfig.disabled) { if (showBorder) { e.currentTarget.style.borderColor = "#f97316"; } e.currentTarget.style.boxShadow = "0 4px 6px -1px rgba(0, 0, 0, 0.1)"; } }} onMouseLeave={(e) => { if (showBorder) { e.currentTarget.style.borderColor = "#d1d5db"; } e.currentTarget.style.boxShadow = showBorder ? "0 1px 2px 0 rgba(0, 0, 0, 0.05)" : "none"; }} onClick={handleClick} onDragStart={onDragStart} onDragEnd={onDragEnd} > {imageSrc ? ( {altText} { (e.target as HTMLImageElement).style.display = "none"; if (e.target?.parentElement) { e.target.parentElement.innerHTML = `
이미지 로드 실패
`; } }} /> ) : (
{placeholder}
)}
); }; /** * ImageDisplay 래퍼 컴포넌트 */ export const ImageDisplayWrapper: React.FC = (props) => { return ; };