;
isDesignMode?: boolean;
className?: string;
}
export function DisplayRenderer({
id,
config,
formData,
isDesignMode = false,
className,
}: DisplayRendererProps) {
const { displayType } = config;
// 데이터 바인딩 처리
const getBoundValue = (defaultValue: any) => {
if (config.dataBinding && formData) {
return formData[config.dataBinding] ?? defaultValue;
}
return defaultValue;
};
// text: + 크기/굵기/정렬
if (displayType === "text" && config.text) {
const { content, size = "md", weight = "normal", align = "left" } = config.text;
const boundContent = getBoundValue(content);
const sizeClass = {
xs: "text-xs",
sm: "text-sm",
md: "text-base",
lg: "text-lg",
xl: "text-xl",
}[size];
const weightClass = {
normal: "font-normal",
medium: "font-medium",
semibold: "font-semibold",
bold: "font-bold",
}[weight];
const alignClass = {
left: "text-left",
center: "text-center",
right: "text-right",
}[align];
return (
{isDesignMode && !boundContent ? "(텍스트)" : boundContent}
);
}
// heading: ~
if (displayType === "heading" && config.heading) {
const { content, level } = config.heading;
const boundContent = getBoundValue(content);
const Tag = `h${level}` as keyof JSX.IntrinsicElements;
const sizeClass = {
1: "text-3xl",
2: "text-2xl",
3: "text-xl",
4: "text-lg",
5: "text-base",
6: "text-sm",
}[level];
return (
{isDesignMode && !boundContent ? "(제목)" : boundContent}
);
}
// divider: shadcn Separator
if (displayType === "divider") {
return ;
}
// badge: shadcn Badge
if (displayType === "badge" && config.badge) {
const { text, variant = "default" } = config.badge;
const boundText = getBoundValue(text);
return (
{isDesignMode && !boundText ? "(뱃지)" : boundText}
);
}
// alert: shadcn Alert
if (displayType === "alert" && config.alert) {
const { title, message, variant = "default" } = config.alert;
const boundMessage = getBoundValue(message);
return (
{title && {title}}
{isDesignMode && !boundMessage ? "(알림 메시지)" : boundMessage}
);
}
// stat: 통계 카드
if (displayType === "stat" && config.stat) {
const { label, value, change, changeType = "neutral" } = config.stat;
const boundValue = getBoundValue(value);
const icon =
changeType === "increase" ? (
) : changeType === "decrease" ? (
) : null;
return (
{label}
{change && (
{icon}
{change}
)}
{isDesignMode && !boundValue ? "0" : boundValue}
);
}
return (
Unknown display type: {displayType}
);
}