50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
|
|
import { type FormEvent, type ReactNode } from 'react'
|
||
|
|
|
||
|
|
interface FormModalProps {
|
||
|
|
title: string
|
||
|
|
onClose: () => void
|
||
|
|
onSubmit: (e: FormEvent) => void
|
||
|
|
children: ReactNode
|
||
|
|
submitLabel?: string
|
||
|
|
isSubmitting?: boolean
|
||
|
|
}
|
||
|
|
|
||
|
|
export function FormModal({
|
||
|
|
title,
|
||
|
|
onClose,
|
||
|
|
onSubmit,
|
||
|
|
children,
|
||
|
|
submitLabel = 'Save',
|
||
|
|
isSubmitting,
|
||
|
|
}: FormModalProps) {
|
||
|
|
return (
|
||
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
||
|
|
<div className="fixed inset-0 bg-black/50" onClick={onClose} />
|
||
|
|
<div className="relative bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-lg w-full mx-4 max-h-[90vh] overflow-y-auto">
|
||
|
|
<div className="px-6 py-4 border-b border-gray-200 dark:border-gray-700">
|
||
|
|
<h2 className="text-lg font-semibold">{title}</h2>
|
||
|
|
</div>
|
||
|
|
<form onSubmit={onSubmit}>
|
||
|
|
<div className="px-6 py-4 space-y-4">{children}</div>
|
||
|
|
<div className="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex justify-end gap-3">
|
||
|
|
<button
|
||
|
|
type="button"
|
||
|
|
onClick={onClose}
|
||
|
|
className="px-4 py-2 text-sm font-medium rounded-md border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-700"
|
||
|
|
>
|
||
|
|
Cancel
|
||
|
|
</button>
|
||
|
|
<button
|
||
|
|
type="submit"
|
||
|
|
disabled={isSubmitting}
|
||
|
|
className="px-4 py-2 text-sm font-medium rounded-md bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50"
|
||
|
|
>
|
||
|
|
{isSubmitting ? 'Saving...' : submitLabel}
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
)
|
||
|
|
}
|