-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ModalContainer into its own file
- Loading branch information
Showing
2 changed files
with
59 additions
and
58 deletions.
There are no files selected for viewing
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,55 @@ | ||
import { useCallback } from 'react' | ||
import { Box } from 'grommet/es6/components/Box' | ||
import { Button } from 'grommet/es6/components/Button' | ||
import { Layer } from 'grommet/es6/components/Layer' | ||
import { Paragraph } from 'grommet/es6/components/Paragraph' | ||
import { useTranslation } from 'react-i18next' | ||
import { Alert } from 'grommet-icons/es6/icons/Alert' | ||
import { Checkmark } from 'grommet-icons/es6/icons/Checkmark' | ||
import { Close } from 'grommet-icons/es6/icons/Close' | ||
import { ModalHeader } from 'app/components/Header' | ||
|
||
export interface Modal { | ||
title: string | ||
description: string | ||
handleConfirm: () => void | ||
isDangerous: boolean | ||
} | ||
|
||
interface ModalContainerProps { | ||
modal: Modal | ||
closeModal: () => void | ||
} | ||
|
||
export const ModalContainer = ({ modal, closeModal }: ModalContainerProps) => { | ||
const { t } = useTranslation() | ||
const confirm = useCallback(() => { | ||
modal.handleConfirm() | ||
closeModal() | ||
}, [closeModal, modal]) | ||
|
||
return ( | ||
<Layer modal onEsc={closeModal} onClickOutside={closeModal} background="background-front"> | ||
<Box margin="medium"> | ||
<ModalHeader>{modal.title}</ModalHeader> | ||
<Paragraph fill>{modal.description}</Paragraph> | ||
<Box direction="row" gap="small" justify="between" pad={{ top: 'large' }}> | ||
<Button | ||
label={t('common.cancel', 'Cancel')} | ||
onClick={closeModal} | ||
secondary | ||
icon={<Close size="18px" />} | ||
/> | ||
<Button | ||
label={t('common.confirm', 'Confirm')} | ||
onClick={confirm} | ||
disabled={modal.isDangerous} | ||
primary={modal.isDangerous} | ||
color={modal.isDangerous ? 'status-error' : ''} | ||
icon={modal.isDangerous ? <Alert size="18px" /> : <Checkmark size="18px" />} | ||
/> | ||
</Box> | ||
</Box> | ||
</Layer> | ||
) | ||
} |
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