import { useState } from 'react'; import { BookmarkFilledIcon, BookmarkIcon } from '@radix-ui/react-icons'; import type { FC } from 'react'; import { Spinner } from '~/components/svg'; import { cn } from '~/utils'; type MenuItemProps = { tag: string | React.ReactNode; selected: boolean; ctx: 'header' | 'nav'; count?: number; handleSubmit: (tag: string) => Promise; icon?: React.ReactNode; highlightSelected?: boolean; }; const BookmarkItem: FC = ({ tag, ctx, selected, count, handleSubmit, icon, highlightSelected, ...rest }) => { const [isLoading, setIsLoading] = useState(false); const clickHandler = async () => { setIsLoading(true); await handleSubmit(tag as string); setIsLoading(false); }; const breakWordStyle: React.CSSProperties = { wordBreak: 'break-word', overflowWrap: 'anywhere', }; const renderIcon = () => { if (icon) { return icon; } if (isLoading) { return ; } if (selected) { return ; } return ; }; const ariaLabel = ctx === 'header' ? `${selected ? 'Remove' : 'Add'} bookmark for ${tag}` : (tag as string); return ( ); }; export default BookmarkItem;