Files
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

99 lines
3.1 KiB
TypeScript

import React from 'react';
interface Item {
id: string;
name: string;
}
interface StructureColumnProps {
title: string;
items: Item[];
selectedId: string | null;
onSelect: (id: string) => void;
onAdd: () => void;
onEdit: (item: Item) => void;
onDelete: (id: string) => void;
disabled?: boolean;
}
const StructureColumn: React.FC<StructureColumnProps> = ({
title,
items,
selectedId,
onSelect,
onAdd,
onEdit,
onDelete,
disabled = false,
}) => {
return (
<div
className={`bg-white rounded-xl shadow-sm border flex flex-col ${disabled ? 'opacity-50' : ''}`}
>
<div className="p-4 border-b flex justify-between items-center">
<h2 className="text-xl font-bold text-gray-800">{title}</h2>
<button
onClick={onAdd}
disabled={disabled}
className="text-red-600 hover:text-red-800 disabled:text-gray-400 disabled:cursor-not-allowed"
title={`Tambah ${title}`}
>
<i className="fa-solid fa-plus-circle text-2xl"></i>
</button>
</div>
<div className="flex-grow overflow-y-auto p-2">
{items.length > 0 ? (
<ul className="space-y-1">
{items.map((item) => (
<li key={item.id}>
<div
className={`group flex items-center justify-between p-3 rounded-lg cursor-pointer transition-colors ${selectedId === item.id ? 'bg-red-100 text-red-700' : 'hover:bg-gray-100 text-gray-700'}`}
onClick={() => onSelect(item.id)}
>
<span className="font-semibold truncate">{item.name}</span>
<div className="flex items-center space-x-2 opacity-0 group-hover:opacity-100 transition-opacity">
<button
onClick={(e) => {
e.stopPropagation();
onEdit(item);
}}
className="hover:text-blue-600"
title={`Edit ${item.name}`}
>
<i className="fa-solid fa-pencil"></i>
</button>
<button
onClick={(e) => {
e.stopPropagation();
onDelete(item.id);
}}
className="hover:text-red-600"
title={`Hapus ${item.name}`}
>
<i className="fa-solid fa-trash"></i>
</button>
</div>
</div>
</li>
))}
</ul>
) : (
<div className="text-center text-gray-500 p-10">
<p>Tidak ada {title.toLowerCase()} ditemukan.</p>
{!disabled && (
<button
onClick={onAdd}
className="mt-4 text-sm bg-red-50 hover:bg-red-100 text-red-600 font-semibold px-3 py-1.5 rounded-md"
>
Tambah {title}
</button>
)}
</div>
)}
</div>
</div>
);
};
export default StructureColumn;