import { UncontrolledDropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { toPairs } from 'ramda'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSortAmountUp as sortAscIcon, faSortAmountDown as sortDescIcon } from '@fortawesome/free-solid-svg-icons'; import classNames from 'classnames'; import { determineOrderDir, OrderDir } from './utils'; import './SortingDropdown.scss'; export interface SortingDropdownProps { items: Record; orderField?: T; orderDir?: OrderDir; onChange: (orderField?: T, orderDir?: OrderDir) => void; isButton?: boolean; right?: boolean; } export default function SortingDropdown( { items, orderField, orderDir, onChange, isButton = true, right = false }: SortingDropdownProps, ) { const handleItemClick = (fieldKey: T) => () => { const newOrderDir = determineOrderDir(fieldKey, orderField, orderDir); onChange(newOrderDir ? fieldKey : undefined, newOrderDir); }; return ( {!isButton && <>Order by} {isButton && !orderField && <>Order by...} {isButton && orderField && `Order by: "${items[orderField]}" - "${orderDir ?? 'DESC'}"`} {toPairs(items).map(([ fieldKey, fieldValue ]) => ( {fieldValue} {orderField === fieldKey && ( )} ))} onChange()}> Clear selection ); }