52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect } from 'react'
|
|
import { X } from 'lucide-react'
|
|
import { Button } from './button'
|
|
|
|
export function Drawer({
|
|
open,
|
|
onClose,
|
|
title,
|
|
actions,
|
|
children,
|
|
}: {
|
|
open: boolean
|
|
onClose: () => void
|
|
title: string
|
|
actions?: React.ReactNode
|
|
children: React.ReactNode
|
|
}) {
|
|
useEffect(() => {
|
|
if (!open) return
|
|
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() }
|
|
document.addEventListener('keydown', onKey)
|
|
return () => document.removeEventListener('keydown', onKey)
|
|
}, [open, onClose])
|
|
|
|
if (!open) return null
|
|
|
|
return (
|
|
<div className="fixed inset-0 z-50">
|
|
<div className="absolute inset-0 bg-black/30" onClick={onClose} aria-hidden />
|
|
<aside
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label={title}
|
|
className="absolute top-2 right-2 bottom-2 w-[420px] max-w-[calc(100vw-16px)] flex flex-col overflow-hidden rounded-2xl bg-surface shadow-drawer"
|
|
>
|
|
<div className="flex items-center justify-between px-4 pt-3.5 pb-2.5">
|
|
<h2 className="text-base font-[650]">{title}</h2>
|
|
<div className="flex items-center gap-1">
|
|
{actions}
|
|
<Button variant="icon" aria-label="Close" onClick={onClose}>
|
|
<X size={16} strokeWidth={2} aria-hidden />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div className="flex-1 overflow-y-auto">{children}</div>
|
|
</aside>
|
|
</div>
|
|
)
|
|
}
|