import React from 'react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { RiMore2Line } from '@remixicon/react'; import { cn } from '@/lib/utils'; export interface SettingsSidebarItemAction { /** Label shown in dropdown menu */ label: string; /** Icon component to show before label */ icon?: React.ComponentType<{ className?: string }>; /** Callback when action is clicked */ onClick: () => void; /** If true, uses destructive styling (red text) */ destructive?: boolean; } interface SettingsSidebarItemProps { /** Primary title text */ title: React.ReactNode; /** Secondary metadata text (shown below title) */ metadata?: React.ReactNode; /** Whether this item is currently selected */ selected?: boolean; /** Callback when item is clicked */ onSelect: () => void; /** Optional icon to show before title */ icon?: React.ReactNode; /** Actions shown in dropdown menu. If empty/undefined, no dropdown is shown. */ actions?: SettingsSidebarItemAction[]; /** Additional className for the outer container */ className?: string; } /** * Standard list item for settings sidebars. * Provides consistent styling for title, metadata, selection state, and optional actions dropdown. * * @example * setSelectedId(agent.id)} * icon={} * actions={[ * { label: 'Duplicate', icon: RiFileCopyLine, onClick: handleDuplicate }, * { label: 'Delete', icon: RiDeleteBinLine, onClick: handleDelete, destructive: true }, * ]} * /> */ export const SettingsSidebarItem: React.FC = ({ title, metadata, selected = false, onSelect, icon, actions, className, }) => { const hasActions = actions && actions.length > 0; return (
{hasActions && ( {actions.map((action, index) => { const Icon = action.icon; return ( { e.stopPropagation(); action.onClick(); }} className={cn( action.destructive && 'text-destructive focus:text-destructive' )} > {Icon && } {action.label} ); })} )}
); };