import { ArrowUp, ArrowDown, Loader2 } from 'lucide-react'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; interface SortControlsProps { /** Current sort field */ sortField: T; /** Current sort direction */ sortDirection: 'asc' | 'desc'; /** Available sort fields with labels */ sortFields: Record; /** Handler for field change */ onFieldChange: (field: T) => void; /** Handler for direction toggle */ onDirectionToggle: () => void; /** Whether component is in mobile mode */ isMobile?: boolean; /** Whether data is loading */ isLoading?: boolean; /** Optional label for the sort selector */ label?: string; } /** * Generic reusable sort controls component * * Provides consistent sorting UI across the application: * - Field selector with custom labels * - Direction toggle (asc/desc) * - Mobile-responsive layout * - Loading states * * @example * ```tsx * setSortConfig({ ...sortConfig, field })} * onDirectionToggle={() => setSortConfig({ * ...sortConfig, * direction: sortConfig.direction === 'asc' ? 'desc' : 'asc' * })} * isMobile={isMobile} * /> * ``` */ export function SortControls({ sortField, sortDirection, sortFields, onFieldChange, onDirectionToggle, isMobile = false, isLoading = false, label = 'Sort By', }: SortControlsProps) { const DirectionIcon = sortDirection === 'asc' ? ArrowUp : ArrowDown; return (
); }