import type { JSX } from 'react' import { cloneElement, useCallback } from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '../base/portal-to-follow-elem' import Divider from '@/app/components/base/divider' import { RiMoreFill } from '@remixicon/react' import cn from '@/utils/classnames' export type Operation = { id: string title: string icon: JSX.Element onClick: () => void type?: 'action' | 'divider' className?: string } const AppOperations = ({ primaryOperations, secondaryOperations, gap }: { primaryOperations: Operation[] secondaryOperations: Operation[] gap: number }) => { const { t } = useTranslation() const [showMore, setShowMore] = useState(false) const handleTriggerMore = useCallback(() => { setShowMore(prev => !prev) }, []) const renderSecondaryOperation = (operation: Operation, index: number) => { if (operation.type === 'divider') { return ( ) } return (
{ setShowMore(false) operation.onClick() }} > {cloneElement(operation.icon, { className: 'h-4 w-4 text-text-tertiary', })} {operation.title}
) } return (
{/* Fixed primary operations */} {primaryOperations.map(operation => , )} {/* More button - always show if there are secondary operations */} {secondaryOperations.length > 0 && (
{secondaryOperations.map((operation, index) => renderSecondaryOperation(operation, index))}
)}
) } export default AppOperations