File size: 964 Bytes
6e38ce1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import React, { ReactNode } from "react";
export interface SubMenuItemProps<T> {
id: T;
label: string;
icon?: ReactNode;
}
interface SubMenuProps<T> {
items: SubMenuItemProps<T>[];
activeItem: T;
onClick: (id: T) => void;
}
function SubMenu<T extends string>({
activeItem,
onClick,
items,
}: SubMenuProps<T>) {
return (
<div className="w-full border-b border-secondary">
{items.map((item) => (
<button
key={item.id}
className={`w-full text-left py-2 pl-0 pr-4 text-sm transition-colors flex items-center
${
activeItem === item.id
? "font-semibold text-magenta-800"
: "font-normal text-secondary hover:text-primary"
}`}
onClick={() => onClick(item.id)}
>
{item.icon && <span className="mr-2">{item.icon}</span>}
{item.label}
</button>
))}
</div>
);
}
export default SubMenu;
|