'use client'; import { memo } from 'react'; import { Checkbox } from '@/components/ui/checkbox'; import { Button } from '@/components/ui/button'; import { ChevronRight, ChevronDown, Plus, SquarePen, Trash2 } from 'lucide-react'; import type { DepartmentTreeItemProps } from './types'; /** * 트리 행 (재귀 렌더링) * - 무제한 깊이 지원 * - depth에 따른 동적 들여쓰기 */ export const DepartmentTreeItem = memo(function DepartmentTreeItem({ department, depth, expandedIds, selectedIds, onToggleExpand, onToggleSelect, onAdd, onEdit, onDelete }: DepartmentTreeItemProps) { const hasChildren = department.children && department.children.length > 0; const isExpanded = expandedIds.has(department.id); const isSelected = selectedIds.has(department.id); // 들여쓰기 계산 (depth * 24px) const paddingLeft = depth * 24; return ( <> {/* 현재 행 */}
{/* 펼침/접힘 버튼 */} {/* 체크박스 */} onToggleSelect(department.id)} aria-label={`${department.name} 선택`} className="shrink-0" /> {/* 부서명 */} {department.name}
{/* 작업 버튼 (선택 시 부서명 아래에 표시, 데스크톱: 호버 시에도 표시) */} {isSelected && (
)}
{/* 하위 부서 (재귀) */} {hasChildren && isExpanded && ( <> {department.children!.map(child => ( ))} )} ); });