Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | 'use client'; |
| 2 | |
| 3 | import Link from 'next/link'; |
| 4 | import type { AnchorHTMLAttributes, MouseEvent, ReactNode } from 'react'; |
| 5 | import type { DocsProduct } from '@/lib/home-navigation'; |
| 6 | import { useDocsProduct } from './docs-product-context'; |
| 7 | |
| 8 | type ProductSelectionLinkProps = |
| 9 | Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & { |
| 10 | children: ReactNode; |
| 11 | href: string; |
| 12 | product: DocsProduct; |
| 13 | }; |
| 14 | |
| 15 | export function ProductSelectionLink({ |
| 16 | product, |
| 17 | href, |
| 18 | children, |
| 19 | onClick, |
| 20 | ...props |
| 21 | }: ProductSelectionLinkProps) { |
| 22 | const { navigateToProduct, persistProduct } = useDocsProduct(); |
| 23 | |
| 24 | const handleClick = (event: MouseEvent<HTMLAnchorElement>) => { |
| 25 | onClick?.(event); |
| 26 | if (event.defaultPrevented) return; |
| 27 | |
| 28 | const modified = |
| 29 | event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey; |
| 30 | if (modified || props.target === '_blank') { |
| 31 | persistProduct(product); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | event.preventDefault(); |
| 36 | navigateToProduct(product, href, event.currentTarget); |
| 37 | }; |
| 38 | |
| 39 | return ( |
| 40 | <Link href={href} onClick={handleClick} {...props}> |
| 41 | {children} |
| 42 | </Link> |
| 43 | ); |
| 44 | } |