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 { |
| 4 | useState, |
| 5 | useCallback, |
| 6 | createContext, |
| 7 | useContext, |
| 8 | type ReactNode, |
| 9 | } from 'react'; |
| 10 | import { cn } from '@/lib/utils'; |
| 11 | |
| 12 | const FilterContext = createContext(''); |
| 13 | |
| 14 | function slugify(text: string): string { |
| 15 | return text |
| 16 | .toLowerCase() |
| 17 | .replace(/[^a-z0-9]+/g, '-') |
| 18 | .replace(/^-|-$/g, ''); |
| 19 | } |
| 20 | |
| 21 | export function Glossary({ children }: { children: ReactNode }) { |
| 22 | const [filter, setFilter] = useState(''); |
| 23 | |
| 24 | return ( |
| 25 | <FilterContext.Provider value={filter.toLowerCase()}> |
| 26 | <div className="not-prose"> |
| 27 | <div className="hidden sm:grid grid-cols-[minmax(180px,1fr)_2fr] gap-4 border-b border-fd-border pb-3 mb-0"> |
| 28 | <div className="text-xs font-semibold text-fd-muted-foreground tracking-wider uppercase"> |
| 29 | Glossary Term |
| 30 | </div> |
| 31 | <div className="text-xs font-semibold text-fd-muted-foreground tracking-wider uppercase"> |
| 32 | Definition |
| 33 | </div> |
| 34 | </div> |
| 35 | <div className="border-b border-fd-border py-3"> |
| 36 | <div className="relative max-w-sm"> |
| 37 | <svg |
| 38 | className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-fd-muted-foreground" |
| 39 | fill="none" |
| 40 | stroke="currentColor" |
| 41 | viewBox="0 0 24 24" |
| 42 | aria-hidden="true" |
| 43 | > |
| 44 | <path |
| 45 | strokeLinecap="round" |
| 46 | strokeLinejoin="round" |
| 47 | strokeWidth={2} |
| 48 | d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" |
| 49 | /> |
| 50 | </svg> |
| 51 | <input |
| 52 | type="text" |
| 53 | placeholder="Filter..." |
| 54 | aria-label="Filter glossary terms" |
| 55 | value={filter} |
| 56 | onChange={(e) => setFilter(e.target.value)} |
| 57 | className="w-full pl-9 pr-3 py-1.5 text-sm border border-fd-border rounded-md bg-fd-background text-fd-foreground placeholder:text-fd-muted-foreground focus:outline-none focus:ring-2 focus:ring-fd-ring" |
| 58 | /> |
| 59 | </div> |
| 60 | </div> |
| 61 | {children} |
| 62 | </div> |
| 63 | </FilterContext.Provider> |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | export function GlossaryTerm({ |
| 68 | name, |
| 69 | children, |
| 70 | }: { |
| 71 | name: string; |
| 72 | children: ReactNode; |
| 73 | }) { |
| 74 | const filter = useContext(FilterContext); |
| 75 | const [definitionText, setDefinitionText] = useState(''); |
| 76 | const id = slugify(name); |
| 77 | |
| 78 | const definitionRef = useCallback((node: HTMLDivElement | null) => { |
| 79 | if (node) { |
| 80 | setDefinitionText(node.textContent?.toLowerCase() || ''); |
| 81 | } |
| 82 | }, []); |
| 83 | |
| 84 | const matches = |
| 85 | !filter || |
| 86 | name.toLowerCase().includes(filter) || |
| 87 | definitionText.includes(filter); |
| 88 | |
| 89 | if (!matches) return null; |
| 90 | |
| 91 | return ( |
| 92 | <div |
| 93 | id={id} |
| 94 | data-glossary-term={name} |
| 95 | className={cn( |
| 96 | 'border-b border-fd-border py-4 scroll-mt-20', |
| 97 | 'grid grid-cols-1 sm:grid-cols-[minmax(180px,1fr)_2fr] gap-1 sm:gap-4', |
| 98 | )} |
| 99 | > |
| 100 | <div className="font-medium text-fd-foreground text-sm"> |
| 101 | {name} |
| 102 | </div> |
| 103 | <div |
| 104 | ref={definitionRef} |
| 105 | className="text-sm text-fd-muted-foreground leading-relaxed [&_a]:text-fd-primary [&_a]:underline [&_code]:text-xs [&_code]:bg-fd-muted [&_code]:px-1 [&_code]:py-0.5 [&_code]:rounded" |
| 106 | > |
| 107 | {children} |
| 108 | </div> |
| 109 | </div> |
| 110 | ); |
| 111 | } |