2024-10-21 13:57:45 -06:00
|
|
|
"use client"
|
2024-04-08 23:40:42 -04:00
|
|
|
|
2024-10-21 13:57:45 -06:00
|
|
|
import { Loader2, X } from "lucide-react"
|
|
|
|
import { MouseEventHandler } from "react"
|
|
|
|
import { Button } from "./button"
|
2024-04-08 23:40:42 -04:00
|
|
|
|
|
|
|
export default function Tab({
|
|
|
|
children,
|
2024-05-09 22:16:56 -07:00
|
|
|
creating = false,
|
2024-04-27 11:08:19 -04:00
|
|
|
saved = true,
|
|
|
|
selected = false,
|
2024-04-08 23:40:42 -04:00
|
|
|
onClick,
|
|
|
|
onClose,
|
2024-05-08 23:52:08 -07:00
|
|
|
closing = false,
|
2024-04-08 23:40:42 -04:00
|
|
|
}: {
|
2024-10-21 13:57:45 -06:00
|
|
|
children: React.ReactNode
|
|
|
|
creating?: boolean
|
|
|
|
saved?: boolean
|
|
|
|
selected?: boolean
|
|
|
|
onClick?: MouseEventHandler<HTMLButtonElement>
|
|
|
|
onClose?: () => void
|
|
|
|
closing?: boolean
|
2024-04-08 23:40:42 -04:00
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
onClick={onClick ?? undefined}
|
|
|
|
size="sm"
|
2024-04-18 15:38:38 -04:00
|
|
|
variant={"secondary"}
|
2024-04-27 11:08:19 -04:00
|
|
|
className={`font-normal select-none ${
|
2024-04-26 00:10:53 -04:00
|
|
|
selected
|
|
|
|
? "bg-neutral-700 hover:bg-neutral-600 text-foreground"
|
|
|
|
: "text-muted-foreground"
|
2024-04-18 15:38:38 -04:00
|
|
|
}`}
|
2024-04-08 23:40:42 -04:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
<div
|
2024-04-26 00:10:53 -04:00
|
|
|
onClick={
|
2024-05-08 23:52:08 -07:00
|
|
|
onClose && !closing
|
2024-04-26 00:10:53 -04:00
|
|
|
? (e) => {
|
2024-10-21 13:57:45 -06:00
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
onClose()
|
2024-04-26 00:10:53 -04:00
|
|
|
}
|
|
|
|
: undefined
|
|
|
|
}
|
2024-04-27 11:08:19 -04:00
|
|
|
className="h-5 w-5 ml-0.5 group flex items-center justify-center translate-x-1 transition-colors bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-sm"
|
2024-04-08 23:40:42 -04:00
|
|
|
>
|
2024-05-09 22:16:56 -07:00
|
|
|
{closing || creating ? (
|
2024-05-08 23:52:08 -07:00
|
|
|
<Loader2 className="animate-spin w-3 h-3" />
|
|
|
|
) : saved ? (
|
2024-04-27 11:08:19 -04:00
|
|
|
<X className="w-3 h-3" />
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<X className="w-3 h-3 group-hover:block hidden" />
|
|
|
|
<div className="w-2 h-2 rounded-full bg-foreground group-hover:hidden" />
|
|
|
|
</>
|
|
|
|
)}
|
2024-04-08 23:40:42 -04:00
|
|
|
</div>
|
|
|
|
</Button>
|
2024-10-21 13:57:45 -06:00
|
|
|
)
|
2024-04-08 23:40:42 -04:00
|
|
|
}
|