import { BookOpenIcon } from 'lucide-react' import type { MouseEvent } from 'react' import { Button } from 'ui' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { getDocsPath } from '@/lib/telemetry/docs-path' import { useTrack } from '@/lib/telemetry/track' interface DocsButtonProps { href: string abbrev?: boolean className?: string topic?: string /** Custom button text, e.g. to distinguish multiple docs buttons side by side. */ label?: string /** Shows only the book icon, with the label in a tooltip */ iconOnly?: boolean } export const DocsButton = ({ href, abbrev = true, className, topic, label, iconOnly = false, }: DocsButtonProps) => { const track = useTrack() const trackDocsClick = () => { const docsPath = getDocsPath(href) if (docsPath) track('studio_docs_link_clicked', { docsPath }) } const handleClick = (e: MouseEvent) => { e.stopPropagation() trackDocsClick() } const handleAuxClick = (e: MouseEvent) => { const isMiddleClick = e.button === 1 if (isMiddleClick) trackDocsClick() } const text = label ?? (abbrev ? 'Docs' : 'Documentation') const topicLabel = topic ? `${topic} documentation (opens in new tab)` : undefined if (iconOnly) { return ( } onClick={handleClick} tooltip={{ content: { side: 'bottom', text } }} > ) } return ( ) }