import type { FC } from 'react' import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiArrowDownSLine, RiCheckLine, RiSortAsc, RiSortDesc } from '@remixicon/react' import cn from '@/utils/classnames' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' export type Item = { value: number | string name: string } & Record type Props = { order?: string value: number | string items: Item[] onSelect: (item: any) => void } const Sort: FC = ({ order, value, items, onSelect, }) => { const { t } = useTranslation() const [open, setOpen] = useState(false) const triggerContent = useMemo(() => { return items.find(item => item.value === value)?.name || '' }, [items, value]) return (
setOpen(v => !v)} className='block' >
{t('appLog.filter.sortBy')}
{triggerContent}
{items.map(item => (
{ onSelect(`${order}${item.value}`) setOpen(false) }} >
{item.name}
{value === item.value && }
))}
onSelect(`${order ? '' : '-'}${value}`)}> {!order && } {order && }
) } export default Sort