ERP-node/frontend/lib/registry/components/file-upload/FileUploadComponent.tsx

201 lines
5.7 KiB
TypeScript
Raw Normal View History

2025-09-11 18:38:28 +09:00
"use client";
import React from "react";
import { ComponentRendererProps } from "@/types/component";
import { FileUploadConfig } from "./types";
export interface FileUploadComponentProps extends ComponentRendererProps {
config?: FileUploadConfig;
}
/**
* FileUpload
* file-upload
*/
export const FileUploadComponent: React.FC<FileUploadComponentProps> = ({
component,
isDesignMode = false,
isSelected = false,
2025-09-12 14:24:25 +09:00
isInteractive = false,
2025-09-11 18:38:28 +09:00
onClick,
onDragStart,
onDragEnd,
config,
className,
style,
2025-09-12 14:24:25 +09:00
formData,
onFormDataChange,
2025-09-11 18:38:28 +09:00
...props
}) => {
// 컴포넌트 설정
const componentConfig = {
...config,
...component.config,
} as FileUploadConfig;
// 스타일 계산 (위치는 RealtimePreviewDynamic에서 처리하므로 제외)
const componentStyle: React.CSSProperties = {
width: "100%",
height: "100%",
...component.style,
...style,
};
// 디자인 모드 스타일
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,
2025-09-12 14:24:25 +09:00
screenId: _screenId,
tableName: _tableName,
onRefresh: _onRefresh,
onClose: _onClose,
2025-09-11 18:38:28 +09:00
...domProps
} = props;
return (
<div style={componentStyle} className={className} {...domProps}>
{/* 라벨 렌더링 */}
2025-09-22 14:13:05 +09:00
{component.label && component.style?.labelDisplay !== false && (
2025-09-11 18:38:28 +09:00
<label
style={{
position: "absolute",
top: "-25px",
left: "0px",
fontSize: component.style?.labelFontSize || "14px",
color: component.style?.labelColor || "#374151",
fontWeight: "500",
2025-09-12 14:24:25 +09:00
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
2025-09-11 18:38:28 +09:00
}}
>
{component.label}
2025-09-22 14:13:05 +09:00
{component.required && (
<span
style={{
color: "#ef4444",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
*
</span>
)}
2025-09-11 18:38:28 +09:00
</label>
)}
<div
2025-09-22 14:13:05 +09:00
style={{
width: "100%",
2025-09-11 18:38:28 +09:00
height: "100%",
border: "2px dashed #d1d5db",
borderRadius: "8px",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
cursor: "pointer",
backgroundColor: "#f9fafb",
position: "relative",
2025-09-22 14:13:05 +09:00
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
2025-09-11 18:38:28 +09:00
onClick={handleClick}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
>
<input
type="file"
multiple={componentConfig.multiple || false}
accept={componentConfig.accept || "*/*"}
disabled={componentConfig.disabled || false}
required={componentConfig.required || false}
style={{
position: "absolute",
width: "100%",
height: "100%",
opacity: 0,
cursor: "pointer",
2025-09-12 14:24:25 +09:00
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
2025-09-11 18:38:28 +09:00
}}
onChange={(e) => {
if (component.onChange) {
const files = Array.from(e.target.files || []);
component.onChange(componentConfig.multiple ? files : files[0]);
}
}}
/>
2025-09-22 14:13:05 +09:00
<div
style={{
textAlign: "center",
color: "#6b7280",
fontSize: "14px",
2025-09-12 14:24:25 +09:00
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
2025-09-22 14:13:05 +09:00
}}
>
<div
style={{
fontSize: "24px",
marginBottom: "8px",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
📁
</div>
<div
style={{
fontWeight: "500",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
</div>
<div
style={{
fontSize: "12px",
marginTop: "4px",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
2025-09-11 18:38:28 +09:00
{componentConfig.accept && `지원 형식: ${componentConfig.accept}`}
</div>
</div>
</div>
</div>
);
};
/**
* FileUpload
*
*/
export const FileUploadWrapper: React.FC<FileUploadComponentProps> = (props) => {
return <FileUploadComponent {...props} />;
};