90 lines
2.1 KiB
TypeScript
90 lines
2.1 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import { useAtomValue } from 'jotai'
|
|
import { Button } from '@/components/ui/button'
|
|
import {
|
|
Dialog,
|
|
DialogClose,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog'
|
|
import { cn } from '@/lib/utils'
|
|
import { loadingAtom } from '@/store/jotai/loading'
|
|
|
|
export interface KriDialogProps {
|
|
open: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
title: ReactNode
|
|
description?: ReactNode
|
|
children?: ReactNode
|
|
footer?: ReactNode
|
|
showDefaultFooter?: boolean
|
|
closeLabel?: string
|
|
showCloseButton?: boolean
|
|
contentClassName?: string
|
|
bodyClassName?: string
|
|
footerClassName?: string
|
|
}
|
|
|
|
export function KriDialog({
|
|
open,
|
|
onOpenChange,
|
|
title,
|
|
description,
|
|
children,
|
|
footer,
|
|
showDefaultFooter = true,
|
|
closeLabel = '닫기',
|
|
showCloseButton = true,
|
|
contentClassName,
|
|
bodyClassName,
|
|
footerClassName,
|
|
}: KriDialogProps) {
|
|
const isLoading = useAtomValue(loadingAtom)
|
|
|
|
const renderFooter = () => {
|
|
if (footer !== undefined) {
|
|
if (footer === null) return null
|
|
return <DialogFooter className={footerClassName}>{footer}</DialogFooter>
|
|
}
|
|
|
|
if (!showDefaultFooter) return null
|
|
|
|
return (
|
|
<DialogFooter className={footerClassName}>
|
|
<DialogClose asChild>
|
|
<Button type="button" variant="outline">
|
|
{closeLabel}
|
|
</Button>
|
|
</DialogClose>
|
|
</DialogFooter>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent
|
|
className={contentClassName}
|
|
showCloseButton={showCloseButton}
|
|
onInteractOutside={(e) => {
|
|
if (isLoading) e.preventDefault()
|
|
}}
|
|
onEscapeKeyDown={(e) => {
|
|
if (isLoading) e.preventDefault()
|
|
}}
|
|
>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
{description ? <DialogDescription>{description}</DialogDescription> : null}
|
|
</DialogHeader>
|
|
<div className={cn('min-h-0', bodyClassName)}>{children}</div>
|
|
{renderFooter()}
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|