2019-01-12 10:00:17 -08:00
|
|
|
// @flow
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2019-02-17 19:56:50 -08:00
|
|
|
import React, { type Element } from 'react';
|
2019-01-12 10:00:17 -08:00
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
import { TextComponent } from './text';
|
|
|
|
import { Button } from './button';
|
|
|
|
import { Divider } from './divider';
|
2019-01-12 11:28:26 -08:00
|
|
|
import { ModalComponent } from './modal';
|
2019-01-12 10:00:17 -08:00
|
|
|
|
|
|
|
import CloseIcon from '../assets/images/close_icon.svg';
|
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
|
|
|
display: flex;
|
2019-02-07 08:31:59 -08:00
|
|
|
width: ${(props: PropsWithTheme<{ width: number }>) => `${String(props.width)}px`};
|
|
|
|
background-color: ${props => props.theme.colors.background};
|
2019-01-12 10:00:17 -08:00
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
border-radius: 6px;
|
2019-02-17 19:56:50 -08:00
|
|
|
box-shadow: ${props => props.theme.colors.transactionDetailsShadow}
|
2019-01-12 10:00:17 -08:00
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CloseIconWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
align-items: flex-end;
|
|
|
|
justify-content: flex-end;
|
|
|
|
position: absolute;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TitleWrapper = styled.div`
|
|
|
|
margin-top: 20px;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CloseIconImg = styled.img`
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
margin-top: 12px;
|
|
|
|
margin-right: 12px;
|
|
|
|
cursor: pointer;
|
|
|
|
`;
|
|
|
|
|
2019-02-17 19:56:50 -08:00
|
|
|
const ButtonWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex: 1;
|
|
|
|
width: 100%;
|
|
|
|
padding: 20px 40px 10px;
|
|
|
|
|
|
|
|
& > :first-child {
|
|
|
|
margin-right: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
& > :last-child {
|
|
|
|
margin-left: 5px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-01-12 10:00:17 -08:00
|
|
|
const Btn = styled(Button)`
|
|
|
|
width: 95%;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
type Props = {
|
2019-01-12 11:28:26 -08:00
|
|
|
renderTrigger: (() => void) => Element<*>,
|
2019-01-12 10:00:17 -08:00
|
|
|
title: string,
|
|
|
|
onConfirm: () => void,
|
2019-01-24 06:56:49 -08:00
|
|
|
onClose?: () => void,
|
2019-01-12 10:00:17 -08:00
|
|
|
showButtons?: boolean,
|
|
|
|
width?: number,
|
2019-01-12 18:17:28 -08:00
|
|
|
isLoading?: boolean,
|
2019-01-24 06:56:49 -08:00
|
|
|
children: (() => void) => Element<*>,
|
2019-01-12 10:00:17 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const ConfirmDialogComponent = ({
|
|
|
|
children,
|
|
|
|
title,
|
|
|
|
onConfirm,
|
2019-01-24 06:56:49 -08:00
|
|
|
onClose,
|
2019-01-12 11:28:26 -08:00
|
|
|
renderTrigger,
|
2019-01-12 10:00:17 -08:00
|
|
|
showButtons,
|
2019-01-12 18:17:28 -08:00
|
|
|
isLoading,
|
2019-01-12 10:00:17 -08:00
|
|
|
width,
|
2019-01-24 06:56:49 -08:00
|
|
|
}: Props) => {
|
|
|
|
const handleClose = toggle => () => {
|
|
|
|
toggle();
|
|
|
|
if (onClose) onClose();
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ModalComponent
|
2019-01-24 11:26:03 -08:00
|
|
|
id='confirm-dialog-modal-wrapper'
|
2019-01-24 06:56:49 -08:00
|
|
|
renderTrigger={renderTrigger}
|
|
|
|
closeOnBackdropClick={false}
|
|
|
|
closeOnEsc={false}
|
|
|
|
>
|
|
|
|
{toggle => (
|
2019-01-29 07:03:04 -08:00
|
|
|
<Wrapper width={Number(width)}>
|
2019-01-24 06:56:49 -08:00
|
|
|
<CloseIconWrapper>
|
2019-02-06 19:06:48 -08:00
|
|
|
<CloseIconImg src={CloseIcon} onClick={handleClose(toggle)} />
|
2019-01-24 06:56:49 -08:00
|
|
|
</CloseIconWrapper>
|
|
|
|
<TitleWrapper>
|
2019-02-06 19:06:48 -08:00
|
|
|
<TextComponent value={title} align='center' />
|
2019-01-24 06:56:49 -08:00
|
|
|
</TitleWrapper>
|
|
|
|
<Divider opacity={0.3} />
|
|
|
|
{children(handleClose(toggle))}
|
|
|
|
{showButtons && (
|
2019-02-17 19:56:50 -08:00
|
|
|
<ButtonWrapper>
|
2019-01-24 11:26:03 -08:00
|
|
|
<Btn
|
|
|
|
id='confirm-modal-button'
|
|
|
|
label='Confirm'
|
|
|
|
onClick={onConfirm}
|
|
|
|
isLoading={isLoading}
|
|
|
|
/>
|
2019-01-24 06:56:49 -08:00
|
|
|
<Btn
|
|
|
|
label='Cancel'
|
|
|
|
onClick={handleClose(toggle)}
|
|
|
|
variant='secondary'
|
|
|
|
disabled={isLoading}
|
|
|
|
/>
|
2019-02-17 19:56:50 -08:00
|
|
|
</ButtonWrapper>
|
2019-01-24 06:56:49 -08:00
|
|
|
)}
|
|
|
|
</Wrapper>
|
|
|
|
)}
|
|
|
|
</ModalComponent>
|
|
|
|
);
|
|
|
|
};
|
2019-01-12 10:00:17 -08:00
|
|
|
|
|
|
|
ConfirmDialogComponent.defaultProps = {
|
|
|
|
showButtons: true,
|
|
|
|
width: 460,
|
2019-01-12 18:17:28 -08:00
|
|
|
isLoading: false,
|
2019-01-24 06:56:49 -08:00
|
|
|
onClose: () => {},
|
2019-01-12 10:00:17 -08:00
|
|
|
};
|