| 7 | import { Icon } from "../icon"; |
| 8 | |
| 9 | export function CodeBlock({ title, description, children, code, options, className, ...props }: CodeBlockProps) { |
| 10 | const [isOpen, setIsOpen] = useState(false); |
| 11 | |
| 12 | return ( |
| 13 | <Card className={cn("w-full", className)} {...props}> |
| 14 | <CardHeader> |
| 15 | <CardTitle>{title}</CardTitle> |
| 16 | <CardDescription>{description}</CardDescription> |
| 17 | </CardHeader> |
| 18 | <CardContent>{children}</CardContent> |
| 19 | <CardFooter className="flex items-center justify-between"> |
| 20 | <Collapsible open={isOpen} onOpenChange={setIsOpen} className="flex flex-col gap-2 w-full"> |
| 21 | <CollapsibleTrigger asChild> |
| 22 | <Button variant="ghost" size="icon" className="size-8 w-full"> |
| 23 | <Icon icon="lucide:code-xml" size={20} /> |
| 24 | </Button> |
| 25 | </CollapsibleTrigger> |
| 26 | <CollapsibleContent className="flex flex-col gap-2 w-full"> |
| 27 | <HighlightCode code={code} options={options} /> |
| 28 | </CollapsibleContent> |
| 29 | </Collapsible> |
| 30 | </CardFooter> |
| 31 | </Card> |
| 32 | ); |
| 33 | } |