Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | 'use client'; |
| 2 | |
| 3 | import Image from 'next/image'; |
| 4 | import Link from 'next/link'; |
| 5 | import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'; |
| 6 | import { ReactNode, useEffect, useState } from 'react'; |
| 7 | import { createPortal } from 'react-dom'; |
| 8 | |
| 9 | interface TabConfig { |
| 10 | value: string; |
| 11 | label: string; |
| 12 | icon?: string; |
| 13 | iconDark?: string; |
| 14 | } |
| 15 | |
| 16 | const defaultTabs: TabConfig[] = [ |
| 17 | { value: 'native', label: 'Native Tools', icon: '/images/providers/native-tools-logo.svg', iconDark: '/images/providers/native-tools-logo-dark.svg' }, |
| 18 | { value: 'mcp', label: 'MCP', icon: '/images/mcp-logo.svg', iconDark: '/images/mcp-logo-dark.svg' }, |
| 19 | ]; |
| 20 | |
| 21 | interface IntegrationTabsProps { |
| 22 | children: ReactNode; |
| 23 | defaultValue?: string; |
| 24 | tabs?: TabConfig[]; |
| 25 | } |
| 26 | |
| 27 | function TabsHeader({ tabs }: { tabs: TabConfig[] }) { |
| 28 | return ( |
| 29 | <div className="flex items-center gap-3"> |
| 30 | <TabsList> |
| 31 | {tabs.map((tab) => ( |
| 32 | <TabsTrigger key={tab.value} value={tab.value} className="gap-2"> |
| 33 | {tab.icon && tab.iconDark && ( |
| 34 | <div className="flex h-4 w-4 shrink-0 items-center justify-center"> |
| 35 | <Image |
| 36 | src={tab.icon} |
| 37 | alt={tab.label} |
| 38 | width={16} |
| 39 | height={16} |
| 40 | className="h-4 w-4 dark:hidden" |
| 41 | /> |
| 42 | <Image |
| 43 | src={tab.iconDark} |
| 44 | alt={tab.label} |
| 45 | width={16} |
| 46 | height={16} |
| 47 | className="hidden h-4 w-4 dark:block" |
| 48 | /> |
| 49 | </div> |
| 50 | )} |
| 51 | {tab.label} |
| 52 | </TabsTrigger> |
| 53 | ))} |
| 54 | </TabsList> |
| 55 | </div> |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | function PortaledTabsHeader({ tabs }: { tabs: TabConfig[] }) { |
| 60 | const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null); |
| 61 | |
| 62 | useEffect(() => { |
| 63 | const target = document.getElementById('integration-tabs-portal'); |
| 64 | if (target) { |
| 65 | setPortalTarget(target); |
| 66 | return; |
| 67 | } |
| 68 | // Portal target may not exist yet (frameworks register asynchronously via useEffect) |
| 69 | const observer = new MutationObserver(() => { |
| 70 | const el = document.getElementById('integration-tabs-portal'); |
| 71 | if (el) { |
| 72 | setPortalTarget(el); |
| 73 | observer.disconnect(); |
| 74 | } |
| 75 | }); |
| 76 | observer.observe(document.body, { childList: true, subtree: true }); |
| 77 | return () => observer.disconnect(); |
| 78 | }, []); |
| 79 | |
| 80 | const header = ( |
| 81 | <div className="mt-4 border-t border-fd-border pt-4"> |
| 82 | <p className="mb-3 max-w-2xl text-sm text-fd-muted-foreground"> |
| 83 | If your framework has good native tool-calling support, we recommend native tools. The remote MCP URL is always available too.{' '} |
| 84 | <Link href="/docs/sessions-via-mcp" className="text-fd-muted-foreground hover:text-fd-foreground transition-colors underline underline-offset-2"> |
| 85 | Using sessions via MCP |
| 86 | </Link> |
| 87 | . |
| 88 | </p> |
| 89 | <TabsHeader tabs={tabs} /> |
| 90 | </div> |
| 91 | ); |
| 92 | |
| 93 | if (portalTarget) { |
| 94 | return createPortal(header, portalTarget); |
| 95 | } |
| 96 | |
| 97 | // Fallback: render inline if portal target not found |
| 98 | return <div className="mb-5">{header}</div>; |
| 99 | } |
| 100 | |
| 101 | export function IntegrationTabs({ children, defaultValue, tabs = defaultTabs }: IntegrationTabsProps) { |
| 102 | const isQuickstart = tabs === defaultTabs; |
| 103 | |
| 104 | return ( |
| 105 | <Tabs defaultValue={defaultValue ?? tabs[0]?.value ?? 'native'} className="not-prose"> |
| 106 | {isQuickstart ? ( |
| 107 | <PortaledTabsHeader tabs={tabs} /> |
| 108 | ) : ( |
| 109 | <div className="mb-5"> |
| 110 | <TabsHeader tabs={tabs} /> |
| 111 | </div> |
| 112 | )} |
| 113 | {children} |
| 114 | </Tabs> |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | export function IntegrationContent({ |
| 119 | value, |
| 120 | children |
| 121 | }: { |
| 122 | value: string; |
| 123 | children: ReactNode; |
| 124 | }) { |
| 125 | return <TabsContent value={value}>{children}</TabsContent>; |
| 126 | } |