컬럼 세부 타입 설정

This commit is contained in:
kjs
2025-10-14 11:48:04 +09:00
parent dadd49b98f
commit 55f52ed1b5
17 changed files with 2226 additions and 585 deletions

View File

@@ -1,8 +1,10 @@
"use client";
import React from "react";
import React, { useState } from "react";
import { ComponentRendererProps } from "@/types/component";
import { RadioBasicConfig } from "./types";
import { cn } from "@/lib/registry/components/common/inputStyles";
import { filterDOMProps } from "@/lib/utils/domPropsFilter";
export interface RadioBasicComponentProps extends ComponentRendererProps {
config?: RadioBasicConfig;
@@ -33,6 +35,12 @@ export const RadioBasicComponent: React.FC<RadioBasicComponentProps> = ({
...component.config,
} as RadioBasicConfig;
// webType에 따른 세부 타입 결정 (TextInputComponent와 동일한 방식)
const webType = component.componentConfig?.webType || "radio";
// 상태 관리
const [selectedValue, setSelectedValue] = useState<string>(component.value || "");
// 스타일 계산 (위치는 RealtimePreviewDynamic에서 처리하므로 제외)
const componentStyle: React.CSSProperties = {
width: "100%",
@@ -53,185 +61,123 @@ export const RadioBasicComponent: React.FC<RadioBasicComponentProps> = ({
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;
const handleRadioChange = (value: string) => {
setSelectedValue(value);
if (component.onChange) {
component.onChange(value);
}
if (isInteractive && onFormDataChange && component.columnName) {
onFormDataChange(component.columnName, value);
}
};
return (
<div style={componentStyle} className={className} {...domProps}>
{/* 라벨 렌더링 */}
{component.label && component.style?.labelDisplay !== false && (
<label
style={{
position: "absolute",
top: "-25px",
left: "0px",
fontSize: component.style?.labelFontSize || "14px",
color: component.style?.labelColor || "#64748b",
fontWeight: "500",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
{component.label}
{component.required && (
<span
style={{
color: "#ef4444",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
*
</span>
// DOM 안전한 props만 필터링
const safeDomProps = filterDOMProps(props);
// 세부 타입별 렌더링
const renderRadioByWebType = () => {
const options = componentConfig.options || [
{ value: "option1", label: "옵션 1" },
{ value: "option2", label: "옵션 2" },
];
// radio-horizontal: 가로 배치
if (webType === "radio-horizontal") {
return (
<div
className={cn(
"flex flex-row gap-4 rounded-lg border border-gray-200 bg-gray-50 p-3",
"transition-all hover:border-orange-400 hover:shadow-md",
isSelected && "ring-2 ring-orange-500",
)}
</label>
)}
>
{options.map((option: any, index: number) => (
<label key={index} className="flex cursor-pointer items-center gap-2">
<input
type="radio"
name={component.id || "radio-group"}
value={option.value}
checked={selectedValue === option.value}
onChange={() => handleRadioChange(option.value)}
disabled={componentConfig.disabled || isDesignMode}
className="h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<span className="text-sm text-gray-900">{option.label}</span>
</label>
))}
</div>
);
}
// radio-vertical: 세로 배치
if (webType === "radio-vertical") {
return (
<div
className={cn(
"flex flex-col gap-2 rounded-lg border border-gray-200 bg-gray-50 p-3",
"transition-all hover:border-orange-400 hover:shadow-md",
isSelected && "ring-2 ring-orange-500",
)}
>
{options.map((option: any, index: number) => (
<label key={index} className="flex cursor-pointer items-center gap-2">
<input
type="radio"
name={component.id || "radio-group"}
value={option.value}
checked={selectedValue === option.value}
onChange={() => handleRadioChange(option.value)}
disabled={componentConfig.disabled || isDesignMode}
className="h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<span className="text-sm text-gray-900">{option.label}</span>
</label>
))}
</div>
);
}
// radio (기본 라디오 - direction 설정 따름)
return (
<div
style={{
width: "100%",
height: "100%",
display: "flex",
flexDirection: componentConfig.direction === "horizontal" ? "row" : "column",
gap: "12px",
padding: "12px",
borderRadius: "8px",
border: "1px solid #e5e7eb",
backgroundColor: "#f9fafb",
transition: "all 0.2s ease-in-out",
boxShadow: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
onMouseEnter={(e) => {
e.currentTarget.style.borderColor = "#f97316";
e.currentTarget.style.boxShadow = "0 4px 6px -1px rgba(0, 0, 0, 0.1)";
}}
onMouseLeave={(e) => {
e.currentTarget.style.borderColor = "#e5e7eb";
e.currentTarget.style.boxShadow = "0 1px 2px 0 rgba(0, 0, 0, 0.05)";
}}
onClick={handleClick}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
className={cn(
"flex gap-3 rounded-lg border border-gray-200 bg-gray-50 p-3",
"transition-all hover:border-orange-400 hover:shadow-md",
componentConfig.direction === "horizontal" ? "flex-row" : "flex-col",
isSelected && "ring-2 ring-orange-500",
)}
>
{(componentConfig.options || []).map((option, index) => (
<label
key={index}
style={{
display: "flex",
alignItems: "center",
gap: "6px",
cursor: "pointer",
fontSize: "14px",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
{options.map((option: any, index: number) => (
<label key={index} className="flex cursor-pointer items-center gap-2">
<input
type="radio"
name={component.id || "radio-group"}
value={option.value}
checked={component.value === option.value}
disabled={componentConfig.disabled || false}
checked={selectedValue === option.value}
onChange={() => handleRadioChange(option.value)}
disabled={componentConfig.disabled || isDesignMode}
required={componentConfig.required || false}
style={{
width: "16px",
height: "16px",
accentColor: "#3b82f6",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
onChange={(e) => {
if (component.onChange) {
component.onChange(e.target.value);
}
}}
className="h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<span
style={{
color: "#212121",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
{option.label}
</span>
<span className="text-sm text-gray-900">{option.label}</span>
</label>
))}
{(!componentConfig.options || componentConfig.options.length === 0) && (
<>
<label
style={{
display: "flex",
alignItems: "center",
gap: "6px",
cursor: "pointer",
fontSize: "14px",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
<input
type="radio"
name={component.id || "radio-group"}
value="option1"
style={{
width: "16px",
height: "16px",
accentColor: "#3b82f6",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
/>
<span> 1</span>
</label>
<label
style={{
display: "flex",
alignItems: "center",
gap: "6px",
cursor: "pointer",
fontSize: "14px",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
>
<input
type="radio"
name={component.id || "radio-group"}
value="option2"
style={{
width: "16px",
height: "16px",
accentColor: "#3b82f6",
// isInteractive 모드에서는 사용자 스타일 우선 적용
...(isInteractive && component.style ? component.style : {}),
}}
/>
<span> 2</span>
</label>
</>
)}
</div>
);
};
return (
<div style={componentStyle} className={className} {...safeDomProps}>
{/* 라벨 렌더링 */}
{component.label && component.style?.labelDisplay !== false && (
<label className="absolute -top-6 left-0 text-sm font-medium text-slate-600">
{component.label}
{component.required && <span className="text-red-500">*</span>}
</label>
)}
{/* 세부 타입별 UI 렌더링 */}
{renderRadioByWebType()}
</div>
);
};