-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ front: introduce confirm modal (#50)
- Loading branch information
1 parent
7bc6e36
commit ce1180d
Showing
7 changed files
with
150 additions
and
67 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
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,60 @@ | ||
import React, { useState } from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import { RecoilRoot } from 'recoil'; | ||
import { ComponentStory } from '@storybook/react'; | ||
import { CheckCircleIcon, ExclamationCircleIcon } from '@heroicons/react/outline'; | ||
import { Title } from '../text'; | ||
|
||
import { ConfirmModal, ConfirmModalProps } from './confirm'; | ||
const icons = { | ||
check: CheckCircleIcon, | ||
exclamation: ExclamationCircleIcon, | ||
none: null, | ||
} | ||
export default { | ||
title: '@atoms/modal/confirm', | ||
component: ConfirmModal, | ||
argTypes: { | ||
theme: { | ||
options: "success danger warning gray".split(' '), | ||
}, | ||
buttonTheme: { | ||
options: "primary secondary danger default outline dark white green", | ||
}, | ||
open: { table: { disable: true } }, | ||
icon: { | ||
options: [...Object.keys(icons)], | ||
mapping: icons, | ||
} | ||
}, | ||
args: { | ||
title: "Very brief description", | ||
text: "Long description no one will probably really read", | ||
buttonOkLabel: 'general.continue', | ||
skipCancelOnClose: false, | ||
} | ||
}; | ||
|
||
const Template: ComponentStory<any> = (props: ConfirmModalProps) => { | ||
const [open, setOpen] = useState(true); | ||
|
||
return ( | ||
<RecoilRoot> | ||
<button className='dark:text-white' onClick={() => setOpen(true)}>Open</button> | ||
<ConfirmModal | ||
{...props} | ||
open={open} | ||
onClose={(...a) => { | ||
setOpen(false); | ||
action("onClose")(...a); | ||
}} | ||
onOk={action("onOk")} | ||
onCancel={action("onCancel")} | ||
/> | ||
</RecoilRoot> | ||
); | ||
} | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = {}; |
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,59 @@ | ||
import React from 'react'; | ||
|
||
import { Modal, ModalContent, ModalContentTheme } from '.'; | ||
import { Button, ButtonTheme } from 'app/atoms/button/button'; | ||
|
||
import Languages from 'features/global/services/languages-service'; | ||
|
||
export type ConfirmModalProps = { | ||
open: boolean; | ||
title: string; | ||
text: string; | ||
theme?: ModalContentTheme; | ||
icon: React.ComponentType; | ||
skipCancelOnClose?: boolean; | ||
buttonOkTheme?: ButtonTheme; | ||
buttonOkLabel: string; | ||
buttonCancelLabel?: string; | ||
onClose: () => void; | ||
onCancel?: () => void; | ||
onOk: () => void; | ||
}; | ||
export const ConfirmModal = (props: ConfirmModalProps) => { | ||
function dialogCloseHandler(confirm?: boolean) { | ||
return () => { | ||
if (confirm === true) | ||
props.onOk(); | ||
else if (confirm === false || !props.skipCancelOnClose) | ||
props.onCancel && props.onCancel(); | ||
props.onClose(); | ||
}; | ||
} | ||
return <> | ||
<Modal open={props.open} onClose={dialogCloseHandler()}> | ||
<ModalContent | ||
title={props.title} | ||
text={props.text} | ||
theme={props.theme} | ||
icon={props.icon} | ||
buttons={ | ||
<> | ||
<Button | ||
className="ml-2" | ||
theme='default' | ||
onClick={dialogCloseHandler(false)} | ||
> | ||
{Languages.t(props.buttonCancelLabel || "general.cancel")} | ||
</Button> | ||
<Button | ||
theme={props.buttonOkTheme || "danger"} | ||
onClick={dialogCloseHandler(true)} | ||
> | ||
{Languages.t(props.buttonOkLabel)} | ||
</Button> | ||
</> | ||
} | ||
/> | ||
</Modal> | ||
</>; | ||
}; |
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
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
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
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