forked from BeOnAuto/auto-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-collapsible-wrapper.tsx
More file actions
39 lines (35 loc) · 1.56 KB
/
code-collapsible-wrapper.tsx
File metadata and controls
39 lines (35 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use client';
import * as React from 'react';
import { cn } from '@/lib/utils';
import { Button } from '@/registry/new-york-v4/ui/button';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/registry/new-york-v4/ui/collapsible';
import { Separator } from '@/registry/new-york-v4/ui/separator';
export function CodeCollapsibleWrapper({ className, children, ...props }: React.ComponentProps<typeof Collapsible>) {
const [isOpened, setIsOpened] = React.useState(false);
return (
<Collapsible
open={isOpened}
onOpenChange={setIsOpened}
className={cn('group/collapsible relative md:-mx-1', className)}
{...props}
>
<CollapsibleTrigger asChild>
<div className="absolute top-1.5 right-9 z-10 flex items-center">
<Button variant="ghost" size="sm" className="text-muted-foreground h-7 rounded-md px-2">
{isOpened ? 'Collapse' : 'Expand'}
</Button>
<Separator orientation="vertical" className="mx-1.5 !h-4" />
</div>
</CollapsibleTrigger>
<CollapsibleContent
forceMount
className="relative mt-6 overflow-hidden data-[state=closed]:max-h-64 [&>figure]:mt-0 [&>figure]:md:!mx-0"
>
{children}
</CollapsibleContent>
<CollapsibleTrigger className="from-code/70 to-code text-muted-foreground absolute inset-x-0 -bottom-2 flex h-20 items-center justify-center rounded-b-lg bg-gradient-to-b text-sm group-data-[state=open]/collapsible:hidden">
{isOpened ? 'Collapse' : 'Expand'}
</CollapsibleTrigger>
</Collapsible>
);
}