@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
tsx 130 lines 4.85 KB
Raw
1 'use client';
2
3 import { useState } from 'react';
4 import type { ComponentProps } from 'react';
5 import Link from 'next/link';
6 import { usePathname, useRouter } from 'next/navigation';
7 import { Check, ChevronsUpDown } from 'lucide-react';
8 import {
9 Popover,
10 PopoverContent,
11 PopoverTrigger,
12 } from 'fumadocs-ui/components/ui/popover';
13 import {
14 DOCS_PRODUCT_ORDER,
15 DOCS_PRODUCTS,
16 docsProductDestination,
17 } from '@/lib/home-navigation';
18 import { ComposioWordmark, ProductBadge, ProductLockup } from './product-lockup';
19 import { ProductSelectionLink } from './product-selection-link';
20 import { useDocsProduct } from './docs-product-context';
21 import { cn } from '@/lib/utils';
22
23 export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' | 'sidebar' }) {
24 const pathname = usePathname();
25 const router = useRouter();
26 const { product } = useDocsProduct();
27 const [open, setOpen] = useState(false);
28 const current = DOCS_PRODUCTS[product];
29
30 return (
31 <Popover open={open} onOpenChange={setOpen}>
32 <PopoverTrigger asChild>
33 <button
34 aria-expanded={open}
35 aria-haspopup="dialog"
36 aria-label={`Switch Composio product. Current product: ${current.product}`}
37 className={cn(
38 'docs-product-switcher group flex items-center gap-2 text-left text-fd-foreground transition-colors hover:bg-fd-accent/50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-fd-ring',
39 placement === 'nav'
40 ? 'h-10 min-w-0 px-1.5 max-sm:gap-1'
41 : 'min-h-14 w-full justify-between border border-fd-border bg-fd-background px-3 py-2 shadow-xs',
42 )}
43 onFocus={() => {
44 for (const productId of DOCS_PRODUCT_ORDER) {
45 if (productId !== product) {
46 router.prefetch(docsProductDestination(pathname, productId));
47 }
48 }
49 }}
50 onMouseEnter={() => {
51 for (const productId of DOCS_PRODUCT_ORDER) {
52 if (productId !== product) {
53 router.prefetch(docsProductDestination(pathname, productId));
54 }
55 }
56 }}
57 type="button"
58 >
59 {placement === 'nav' ? (
60 <ProductBadge product={product} />
61 ) : (
62 <ProductLockup product={product} />
63 )}
64 <span className="inline-flex shrink-0 items-center gap-1 text-xs font-medium text-fd-muted-foreground group-hover:text-fd-foreground">
65 {placement === 'sidebar' && 'Switch'}
66 <ChevronsUpDown aria-hidden="true" className="size-3.5" />
67 </span>
68 </button>
69 </PopoverTrigger>
70 <PopoverContent
71 align="start"
72 aria-label="Choose a Composio product"
73 className="w-[min(20rem,calc(100vw-2rem))] p-1"
74 side="bottom"
75 sideOffset={8}
76 >
77 <div>
78 {DOCS_PRODUCT_ORDER.map((productId, index) => {
79 const option = DOCS_PRODUCTS[productId];
80 const isCurrent = productId === product;
81 const destination = isCurrent
82 ? pathname
83 : docsProductDestination(pathname, productId);
84 return (
85 <div key={productId}>
86 {index > 0 && <div aria-hidden="true" className="mx-2 my-1 h-px bg-fd-border" />}
87 <ProductSelectionLink
88 aria-current={isCurrent ? 'page' : undefined}
89 className="flex w-full items-start gap-3 p-2.5 text-left transition-colors hover:bg-fd-accent/60 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-fd-ring"
90 href={destination}
91 onClick={event => {
92 setOpen(false);
93 if (isCurrent) event.preventDefault();
94 }}
95 product={productId}
96 >
97 <span className="flex min-w-0 flex-1 flex-col gap-2">
98 <ProductLockup product={productId} />
99 <span className="text-sm font-normal text-fd-muted-foreground">
100 {option.switcherDescription}
101 </span>
102 </span>
103 <Check
104 aria-hidden="true"
105 className={`mt-1 size-4 shrink-0 text-fd-primary ${isCurrent ? '' : 'invisible'}`}
106 />
107 </ProductSelectionLink>
108 </div>
109 );
110 })}
111 </div>
112 </PopoverContent>
113 </Popover>
114 );
115 }
116
117 export function ProductNavTitle({ className }: ComponentProps<'a'>) {
118 return (
119 <div className={cn(className, 'flex min-w-0 items-center gap-1')}>
120 <Link
121 aria-label="Composio home"
122 className="shrink-0 rounded-sm px-1.5 max-[420px]:hidden"
123 href="/"
124 >
125 <ComposioWordmark />
126 </Link>
127 <ProductSwitcher placement="nav" />
128 </div>
129 );
130 }