import React, { ReactNode, useState } from 'react'; import * as DropdownMenu from '@radix-ui/react-dropdown-menu'; import { clsx } from 'clsx/lite'; import { FiMoreHorizontal } from 'react-icons/fi'; import Link from 'next/link'; export default function MoreMenu({ items, className, buttonClassName, }: { items: { label: ReactNode icon?: ReactNode href?: string prefetch?: boolean action?: () => Promise | void }[] className?: string buttonClassName?: string }){ const [isLoading, setIsLoading] = useState(false); const renderItemContent = ( label: ReactNode, icon?: ReactNode, ) =>
{icon} {label}
; return ( {items.map(({ label, icon, href, prefetch = false, action }) => { const result = action?.(); if (result instanceof Promise) { e.preventDefault(); setIsLoading(true); result.finally(() => setIsLoading(false)); } }} > <> {href && {renderItemContent(label, icon)} } {action && renderItemContent(label, icon)} )} ); };