-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
frontend/src/components/ConfirmationModal/ConfirmationModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
import { Dialog, Transition } from '@headlessui/react'; | ||
import { Fragment } from 'react'; | ||
import { IoMdClose } from 'react-icons/io'; | ||
|
||
export interface ConfirmationModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
title?: string; | ||
children: React.ReactNode; | ||
primaryAction: () => void; | ||
primaryActionText?: string; | ||
secondaryActionText?: string; | ||
primaryButtonClassName?: string; | ||
secondaryButtonClassName?: string; | ||
showCloseButton?: boolean; | ||
} | ||
|
||
export const ConfirmationModal: React.FC<ConfirmationModalProps> = ({ | ||
isOpen, | ||
onClose, | ||
title, | ||
children, | ||
primaryAction, | ||
primaryActionText = 'Confirm', | ||
secondaryActionText = 'Cancel', | ||
primaryButtonClassName = '', | ||
secondaryButtonClassName = '', | ||
showCloseButton = true, | ||
}) => { | ||
return ( | ||
<Transition appear show={isOpen} as={Fragment}> | ||
<Dialog as="div" className="relative z-50" onClose={onClose}> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="fixed inset-0 bg-black/25" aria-hidden="true" /> | ||
</Transition.Child> | ||
|
||
<div className="fixed inset-0 overflow-y-auto"> | ||
<div className="flex min-h-full items-center justify-center p-4"> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0 scale-95" | ||
enterTo="opacity-100 scale-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 scale-100" | ||
leaveTo="opacity-0 scale-95" | ||
> | ||
<Dialog.Panel className="relative w-full max-w-md transform overflow-hidden rounded-lg bg-white p-6 text-left shadow-xl transition-all"> | ||
{showCloseButton && ( | ||
<button | ||
onClick={onClose} | ||
className="absolute right-4 top-4 rounded-lg p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-500" | ||
> | ||
<IoMdClose className="h-5 w-5" /> | ||
</button> | ||
)} | ||
|
||
{title && ( | ||
<Dialog.Title className="text-2xl font-bold text-gray-900"> | ||
{title} | ||
</Dialog.Title> | ||
)} | ||
|
||
<div className="mt-4 text-base text-gray-600"> | ||
{children} | ||
</div> | ||
|
||
<div className="mt-8 flex justify-end gap-3"> | ||
<button | ||
type="button" | ||
className={`rounded-lg border border-gray-300 bg-white px-4 py-2 text-gray-900 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 ${secondaryButtonClassName}`} | ||
onClick={onClose} | ||
> | ||
{secondaryActionText} | ||
</button> | ||
|
||
<button | ||
type="button" | ||
className={`rounded-lg bg-gray-500 px-4 py-2 text-white hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 ${primaryButtonClassName}`} | ||
onClick={primaryAction} | ||
> | ||
{primaryActionText} | ||
</button> | ||
</div> | ||
</Dialog.Panel> | ||
</Transition.Child> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { ConfirmationModal } from './ConfirmationModal'; | ||
export type { ConfirmationModalProps } from './ConfirmationModal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters