ente/src/components/MessageDialog.tsx

91 lines
2.8 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-25 15:35:43 +00:00
variant: string;
disabled?: boolean;
};
2021-04-19 17:29:03 +00:00
content?: any;
}
export type SetDialogMessage = React.Dispatch<
React.SetStateAction<MessageAttributes>
>;
2021-04-19 17:29:03 +00:00
type Props = React.PropsWithChildren<{
2021-04-05 11:59:22 +00:00
show: boolean;
onHide: () => void;
2021-04-07 09:21:44 +00:00
attributes: MessageAttributes;
2021-04-26 04:21:14 +00:00
size?: 'sm' | 'lg' | 'xl';
2021-04-19 17:29:03 +00:00
}>;
2021-04-07 09:21:44 +00:00
export default function MessageDialog({
attributes,
children,
...props
}: Props) {
2021-04-20 10:57:25 +00:00
if (!attributes) {
return <Modal />;
}
2021-04-05 11:59:22 +00:00
return (
<Modal
size="lg"
2021-04-26 04:21:14 +00:00
{...props}
centered
2021-04-20 10:57:25 +00:00
backdrop={attributes.staticBackdrop ? 'static' : 'true'}
>
<Modal.Header
style={{ borderBottom: 'none' }}
closeButton={attributes.close != null}
>
2021-04-20 10:57:25 +00:00
{attributes.title && (
2021-04-05 11:59:22 +00:00
<Modal.Title>
<strong>{attributes.title}</strong>
</Modal.Title>
)}
</Modal.Header>
2021-04-19 17:29:03 +00:00
{(children || attributes?.content) && (
2021-04-19 11:21:46 +00:00
<Modal.Body style={{ borderTop: '1px solid #444' }}>
2021-04-20 10:57:25 +00:00
{children ? children : <h5>{attributes.content}</h5>}
2021-04-19 11:21:46 +00:00
</Modal.Body>
)}
2021-04-20 10:57:25 +00:00
<Modal.Footer style={{ borderTop: 'none' }}>
{attributes.close && (
<Button
variant={`outline-${
attributes.close?.variant ?? 'secondary'
}`}
onClick={props.onHide}
style={{
padding: '6px 3em',
marginRight: '20px',
}}
>
{attributes.close?.text ?? constants.OK}
</Button>
)}
{attributes.proceed && (
<Button
variant={`outline-${
attributes.proceed?.variant ?? 'primary'
2021-04-20 10:57:25 +00:00
}`}
onClick={() => {
attributes.proceed.action();
props.onHide();
}}
2021-04-20 10:57:25 +00:00
style={{ padding: '6px 3em', marginRight: '20px' }}
disabled={attributes.proceed.disabled}
2021-04-20 10:57:25 +00:00
>
{attributes.proceed.text}
</Button>
)}
</Modal.Footer>
2021-04-05 11:59:22 +00:00
</Modal>
);
}