Files
supabase/apps/studio/components/ui/ProductMenu/ProductMenuItem.tsx
Danny WhiteandJoshen Lim 031b227165 studio(chore): badge component defrag (#40118)
* component clean up

* optically center

* docs and type size

* code badge variant

* sensible defaults

* fix product menu flex

* badge sweep

* new project badges

* logs

* compute badge

* studio badge sweep

* www sweep

* docs sweep

* clean up

* fixes

* cleanup

* fixes

* better docs

* fixes

* misc fixes

* consistency

* Minor fixes for issues i found

* simplify mt-0

* mt simplification

* remaining optical alignment

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-12-02 11:15:50 +11:00

76 lines
1.7 KiB
TypeScript

import Link from 'next/link'
import { ReactNode } from 'react'
import { Badge, Button, Menu } from 'ui'
interface ProductMenuItemProps {
name: string | ReactNode
isActive: boolean
isExternal?: boolean
icon?: ReactNode
rightIcon?: ReactNode
url?: string
target?: '_blank' | '_self'
onClick?: () => void
textClassName?: string
hoverText?: string
label?: string
}
const ProductMenuItem = ({
name = '',
isActive,
isExternal,
icon,
rightIcon,
url = '',
target = '_self',
onClick,
textClassName = '',
hoverText = '',
label,
}: ProductMenuItemProps) => {
const menuItem = (
<Menu.Item icon={icon} rounded active={isActive} onClick={onClick}>
<div className="flex w-full items-center justify-between gap-1">
<div
className="flex items-center gap-1 min-w-0 flex-1"
title={hoverText ? hoverText : typeof name === 'string' ? name : ''}
>
<span className="truncate flex-1 min-w-0">{name}</span>
{label !== undefined && (
<Badge
variant={label.toLowerCase() === 'new' ? 'success' : 'warning'}
className="flex-shrink-0"
>
{label}
</Badge>
)}
</div>
{rightIcon && <div>{rightIcon}</div>}
</div>
</Menu.Item>
)
if (url) {
if (isExternal) {
return (
<Button asChild block className="!justify-start" type="text" size="small" icon={icon}>
<Link href={url} target="_blank" rel="noreferrer">
{name}
</Link>
</Button>
)
}
return (
<Link href={url} className="block" target={target}>
{menuItem}
</Link>
)
}
return menuItem
}
export default ProductMenuItem