Files
supabase__supabase/apps/design-system/components/code-block-wrapper.tsx
Danny White a6a030cb10 add FloatingPlate and tokenise button shadows
Introduce a shared opaque plate for floating default buttons, migrate call sites off hand-rolled wrappers, and assemble button shadows from component CSS variables.
2026-09-22 11:58:53 +10:00

49 lines
1.5 KiB
TypeScript

'use client'
import * as React from 'react'
import { Button, cn, Collapsible, CollapsibleContent, CollapsibleTrigger, FloatingPlate } from 'ui'
interface CodeBlockProps extends React.HTMLAttributes<HTMLDivElement> {
expandButtonTitle?: string
}
export function CodeBlockWrapper({
expandButtonTitle = 'View Code',
className,
children,
...props
}: CodeBlockProps) {
const [isOpened, setIsOpened] = React.useState(false)
return (
<Collapsible open={isOpened} onOpenChange={setIsOpened}>
<div className={cn('relative overflow-hidden', className)} {...props}>
<CollapsibleContent forceMount className={cn('overflow-hidden', !isOpened && 'max-h-32')}>
<div
className={cn(
'[&_pre]:my-0 [&_pre]:max-h-[650px] [&_pre]:pb-[100px]',
!isOpened ? '[&_pre]:overflow-hidden' : '[&_pre]:overflow-auto]'
)}
>
{children}
</div>
</CollapsibleContent>
<div
className={cn(
'absolute flex items-center justify-center bg-linear-to-b from-zinc-700/30 to-zinc-950/90 p-2',
isOpened ? 'inset-x-0 bottom-0 h-12' : 'inset-0'
)}
>
<FloatingPlate>
<CollapsibleTrigger asChild>
<Button variant="secondary" className="h-8 text-xs">
{isOpened ? 'Collapse' : expandButtonTitle}
</Button>
</CollapsibleTrigger>
</FloatingPlate>
</div>
</div>
</Collapsible>
)
}