|
| 1 | +import { type FC } from 'react' |
| 2 | +import ReactMarkdown from 'react-markdown' |
| 3 | +import { Button } from '@oasisprotocol/ui-library/src/components/ui/button' |
| 4 | +import { ChevronRight, HelpCircle } from 'lucide-react' |
| 5 | +import { cn } from '@oasisprotocol/ui-library/src/lib/utils' |
| 6 | +import xAgentDocs from '../../../templates/x-agent/README.md?raw' |
| 7 | +import tbotDocs from '../../../templates/tgbot/README.md?raw' |
| 8 | +import hlCopyTraderDocs from '../../../templates/hl-copy-trader/README.md?raw' |
| 9 | + |
| 10 | +type HelpWidgetProps = { |
| 11 | + selectedTemplateId?: string |
| 12 | + isExpanded: boolean |
| 13 | + setIsExpanded: (expanded: boolean) => void |
| 14 | +} |
| 15 | + |
| 16 | +export const HelpWidget: FC<HelpWidgetProps> = ({ selectedTemplateId, isExpanded, setIsExpanded }) => { |
| 17 | + const getMarkdownForTemplate = (templateId: string) => { |
| 18 | + switch (templateId) { |
| 19 | + case 'tgbot': |
| 20 | + return tbotDocs |
| 21 | + case 'x-agent': |
| 22 | + return xAgentDocs |
| 23 | + case 'hl-copy-trader': |
| 24 | + return hlCopyTraderDocs |
| 25 | + default: |
| 26 | + return '' |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + if (!selectedTemplateId) { |
| 31 | + return null |
| 32 | + } |
| 33 | + |
| 34 | + const markdown = getMarkdownForTemplate(selectedTemplateId) |
| 35 | + |
| 36 | + if (!markdown) { |
| 37 | + return null |
| 38 | + } |
| 39 | + |
| 40 | + return ( |
| 41 | + <> |
| 42 | + <div |
| 43 | + className={cn('right-0 top-26 md:top-16 h-[calc(100vh-8rem)] flex', !isExpanded ? 'hidden' : 'fixed')} |
| 44 | + > |
| 45 | + <div className="bg-background border-l border-border transition-transform duration-300 ease-in-out flex flex-col w-[min(380px,100vw)]"> |
| 46 | + <div className="flex items-center justify-between p-4 border-b bg-card"> |
| 47 | + <div className="flex items-center gap-2"> |
| 48 | + <HelpCircle className="h-4 w-4" /> |
| 49 | + <span className="text-sm font-medium">Template Guide</span> |
| 50 | + </div> |
| 51 | + <Button |
| 52 | + variant="ghost" |
| 53 | + size="sm" |
| 54 | + onClick={() => setIsExpanded(false)} |
| 55 | + className="h-8 w-8 p-0 hover:bg-muted" |
| 56 | + title="Close panel" |
| 57 | + > |
| 58 | + <ChevronRight className="h-4 w-4" /> |
| 59 | + </Button> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div className="flex-1 overflow-y-auto p-4"> |
| 63 | + {/* prose classes https://github.com/tailwindlabs/tailwindcss-typography */} |
| 64 | + <div className="prose prose-sm dark:prose-invert max-w-none"> |
| 65 | + <ReactMarkdown>{markdown}</ReactMarkdown> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + <Button |
| 71 | + variant="secondary" |
| 72 | + onClick={() => setIsExpanded(!isExpanded)} |
| 73 | + className={cn('absolute top-0 right-0 transition-all duration-300', { |
| 74 | + 'opacity-0 pointer-events-none': isExpanded, |
| 75 | + 'opacity-100': !isExpanded, |
| 76 | + })} |
| 77 | + > |
| 78 | + Need help? |
| 79 | + </Button> |
| 80 | + </> |
| 81 | + ) |
| 82 | +} |
0 commit comments