2025-09-11 18:38:28 +09:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { ComponentRendererProps } from "@/types/component";
|
|
|
|
|
import { CheckboxBasicConfig } from "./types";
|
|
|
|
|
|
|
|
|
|
export interface CheckboxBasicComponentProps extends ComponentRendererProps {
|
|
|
|
|
config?: CheckboxBasicConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CheckboxBasic 컴포넌트
|
|
|
|
|
* checkbox-basic 컴포넌트입니다
|
|
|
|
|
*/
|
|
|
|
|
export const CheckboxBasicComponent: React.FC<CheckboxBasicComponentProps> = ({
|
|
|
|
|
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 CheckboxBasicConfig;
|
|
|
|
|
|
|
|
|
|
// 스타일 계산 (위치는 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-30 18:42:33 +09:00
|
|
|
{component.label && (component.style?.labelDisplay ?? true) && (
|
2025-09-11 18:38:28 +09:00
|
|
|
<label
|
|
|
|
|
style={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "-25px",
|
|
|
|
|
left: "0px",
|
|
|
|
|
fontSize: component.style?.labelFontSize || "14px",
|
2025-10-02 14:34:15 +09:00
|
|
|
color: component.style?.labelColor || "#64748b",
|
2025-09-11 18:38:28 +09:00
|
|
|
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-12 14:24:25 +09:00
|
|
|
{component.required && (
|
2025-09-22 14:13:05 +09:00
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
color: "#ef4444",
|
|
|
|
|
// isInteractive 모드에서는 사용자 스타일 우선 적용
|
|
|
|
|
...(isInteractive && component.style ? component.style : {}),
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-09-12 14:24:25 +09:00
|
|
|
*
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2025-09-11 18:38:28 +09:00
|
|
|
</label>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<label
|
2025-09-22 14:13:05 +09:00
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
2025-09-11 18:38:28 +09:00
|
|
|
alignItems: "center",
|
2025-10-01 16:15:53 +09:00
|
|
|
gap: "12px",
|
2025-09-11 18:38:28 +09:00
|
|
|
cursor: "pointer",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
fontSize: "14px",
|
2025-10-01 16:15:53 +09:00
|
|
|
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)",
|
2025-09-12 14:24:25 +09:00
|
|
|
// isInteractive 모드에서는 사용자 스타일 우선 적용
|
2025-09-22 14:13:05 +09:00
|
|
|
...(isInteractive && component.style ? component.style : {}),
|
|
|
|
|
}}
|
2025-10-01 16:15:53 +09:00
|
|
|
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)";
|
|
|
|
|
}}
|
2025-09-11 18:38:28 +09:00
|
|
|
onClick={handleClick}
|
|
|
|
|
onDragStart={onDragStart}
|
|
|
|
|
onDragEnd={onDragEnd}
|
|
|
|
|
>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={component.value === true || component.value === "true"}
|
|
|
|
|
disabled={componentConfig.disabled || false}
|
|
|
|
|
required={componentConfig.required || false}
|
2025-09-22 14:13:05 +09:00
|
|
|
style={{
|
|
|
|
|
width: "16px",
|
2025-09-11 18:38:28 +09:00
|
|
|
height: "16px",
|
|
|
|
|
accentColor: "#3b82f6",
|
2025-09-22 14:13:05 +09:00
|
|
|
// isInteractive 모드에서는 사용자 스타일 우선 적용
|
|
|
|
|
...(isInteractive && component.style ? component.style : {}),
|
|
|
|
|
}}
|
2025-09-11 18:38:28 +09:00
|
|
|
onChange={(e) => {
|
|
|
|
|
if (component.onChange) {
|
|
|
|
|
component.onChange(e.target.checked);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-09-22 14:13:05 +09:00
|
|
|
<span
|
|
|
|
|
style={{
|
2025-10-02 14:34:15 +09:00
|
|
|
color: "#212121",
|
2025-09-22 14:13:05 +09:00
|
|
|
// isInteractive 모드에서는 사용자 스타일 우선 적용
|
|
|
|
|
...(isInteractive && component.style ? component.style : {}),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{componentConfig.checkboxLabel || component.text || "체크박스"}
|
|
|
|
|
</span>
|
2025-09-11 18:38:28 +09:00
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CheckboxBasic 래퍼 컴포넌트
|
|
|
|
|
* 추가적인 로직이나 상태 관리가 필요한 경우 사용
|
|
|
|
|
*/
|
|
|
|
|
export const CheckboxBasicWrapper: React.FC<CheckboxBasicComponentProps> = (props) => {
|
|
|
|
|
return <CheckboxBasicComponent {...props} />;
|
|
|
|
|
};
|