ente/src/components/MessageDialog.tsx

62 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-04-05 11:59:22 +00:00
import React from 'react';
import { Button, Modal } from 'react-bootstrap';
2021-04-05 12:17:33 +00:00
import constants from 'utils/strings/constants';
2021-04-05 11:59:22 +00:00
export interface MessageAttributes {
title?: string;
staticBackdrop?: boolean;
close?: { text?: string; variant?: string };
proceed?: { text: string; action: any };
}
2021-04-05 11:59:22 +00:00
interface Props {
show: boolean;
2021-04-05 12:10:32 +00:00
children?: any;
2021-04-05 11:59:22 +00:00
onHide: () => void;
attributes?: MessageAttributes;
2021-04-05 11:59:22 +00:00
}
export function MessageDialog({ attributes, children, ...props }: Props) {
return (
<Modal
{...props}
size="lg"
centered
backdrop={attributes?.staticBackdrop ? 'static' : 'true'}
>
2021-04-05 11:59:22 +00:00
<Modal.Body>
2021-04-05 13:17:18 +00:00
{attributes?.title && (
2021-04-05 11:59:22 +00:00
<Modal.Title>
<strong>{attributes.title}</strong>
</Modal.Title>
)}
{children && (
<>
<hr /> {children}
</>
)}
2021-04-05 11:59:22 +00:00
</Modal.Body>
2021-04-05 13:17:18 +00:00
{attributes && (
<Modal.Footer style={{ borderTop: 'none' }}>
{attributes.close && (
2021-04-05 15:23:53 +00:00
<Button
variant={`outline-${
attributes.close?.variant ?? 'secondary'
}`}
onClick={props.onHide}
2021-04-05 15:23:53 +00:00
>
{attributes.close?.text ?? constants.OK}
2021-04-05 13:17:18 +00:00
</Button>
)}
{attributes.proceed && (
<Button
2021-04-05 13:53:12 +00:00
variant="outline-success"
2021-04-05 13:17:18 +00:00
onClick={attributes.proceed.action}
>
{attributes.proceed.text}
</Button>
)}
</Modal.Footer>
)}
2021-04-05 11:59:22 +00:00
</Modal>
);
}