ERP-node/frontend/lib/registry/components/text-input/TextInputComponent.tsx

176 lines
5.1 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 { TextInputConfig } from "./types";
import { filterDOMProps } from "@/lib/utils/domPropsFilter";
2025-09-11 18:38:28 +09:00
export interface TextInputComponentProps extends ComponentRendererProps {
config?: TextInputConfig;
}
/**
* TextInput
* text-input
*/
export const TextInputComponent: React.FC<TextInputComponentProps> = ({
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 TextInputConfig;
2025-09-12 14:24:25 +09:00
console.log("🔧 텍스트 입력 컴포넌트 설정:", {
config,
componentConfig,
component: component,
});
2025-09-11 18:38:28 +09:00
// 스타일 계산 (위치는 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;
// DOM 안전한 props만 필터링
const safeDomProps = filterDOMProps(domProps);
2025-09-11 18:38:28 +09:00
return (
<div style={componentStyle} className={className} {...safeDomProps}>
2025-09-11 18:38:28 +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",
}}
>
{component.label}
{component.required && <span style={{ color: "#ef4444" }}>*</span>}
</label>
)}
<input
type="text"
2025-09-12 14:24:25 +09:00
value={
isInteractive && formData && component.columnName
? formData[component.columnName] || ""
: component.value || ""
}
2025-09-11 18:38:28 +09:00
placeholder={componentConfig.placeholder || ""}
disabled={componentConfig.disabled || false}
required={componentConfig.required || false}
readOnly={componentConfig.readonly || false}
style={{
width: "100%",
height: "100%",
border: "1px solid #d1d5db",
borderRadius: "4px",
padding: "8px 12px",
fontSize: "14px",
outline: "none",
2025-09-12 14:24:25 +09:00
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
2025-09-11 18:38:28 +09:00
}}
onClick={handleClick}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
onChange={(e) => {
2025-09-12 14:24:25 +09:00
const newValue = e.target.value;
console.log("🎯 TextInputComponent onChange 호출:", {
2025-09-18 10:05:50 +09:00
componentId: component.id,
columnName: component.columnName,
newValue,
isInteractive,
hasOnFormDataChange: !!onFormDataChange,
hasOnChange: !!props.onChange,
});
2025-09-12 14:24:25 +09:00
// isInteractive 모드에서는 formData 업데이트
if (isInteractive && onFormDataChange && component.columnName) {
2025-09-18 10:05:50 +09:00
console.log(`📤 TextInputComponent -> onFormDataChange 호출: ${component.columnName} = "${newValue}"`);
console.log("🔍 onFormDataChange 함수 정보:", {
2025-09-18 10:05:50 +09:00
functionName: onFormDataChange.name,
functionString: onFormDataChange.toString().substring(0, 200),
});
2025-09-12 14:24:25 +09:00
onFormDataChange(component.columnName, newValue);
2025-09-18 10:05:50 +09:00
} else {
console.log("❌ TextInputComponent onFormDataChange 조건 미충족:", {
2025-09-18 10:05:50 +09:00
isInteractive,
hasOnFormDataChange: !!onFormDataChange,
hasColumnName: !!component.columnName,
});
2025-09-12 14:24:25 +09:00
}
// 기존 onChange 핸들러도 호출
2025-09-11 18:38:28 +09:00
if (props.onChange) {
2025-09-18 10:05:50 +09:00
console.log(`📤 TextInputComponent -> props.onChange 호출: "${newValue}"`);
2025-09-12 14:24:25 +09:00
props.onChange(newValue);
2025-09-11 18:38:28 +09:00
}
}}
/>
</div>
);
};
/**
* TextInput
*
*/
export const TextInputWrapper: React.FC<TextInputComponentProps> = (props) => {
return <TextInputComponent {...props} />;
};