session-desktop/ts/components/session/SessionConfirm.tsx

90 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-12-30 07:38:28 +01:00
import React from 'react';
import { SessionModal } from './SessionModal';
2020-01-08 07:21:39 +01:00
import { SessionButton, SessionButtonColor } from './SessionButton';
2020-07-30 07:01:11 +02:00
import { SessionHtmlRenderer } from './SessionHTMLRenderer';
import { SessionIcon, SessionIconSize, SessionIconType } from './icon';
2021-06-07 00:36:48 +02:00
import { DefaultTheme, useTheme, withTheme } from 'styled-components';
import { SessionWrapperModal } from './SessionWrapperModal';
2019-12-30 07:38:28 +01:00
type Props = {
2019-12-30 07:38:28 +01:00
message: string;
2021-06-07 00:36:48 +02:00
messageSub?: string;
2019-12-30 07:38:28 +01:00
title: string;
onOk?: any;
onClose?: any;
2020-01-03 01:48:55 +01:00
onClickOk: any;
2021-06-07 00:36:48 +02:00
onClickClose?: any;
2019-12-30 07:38:28 +01:00
okText?: string;
cancelText?: string;
2021-06-07 00:36:48 +02:00
hideCancel?: boolean;
2020-01-08 07:21:39 +01:00
okTheme: SessionButtonColor;
2021-06-07 00:36:48 +02:00
closeTheme?: SessionButtonColor;
sessionIcon?: SessionIconType;
iconSize?: SessionIconSize;
2021-06-07 00:36:48 +02:00
theme?: DefaultTheme;
};
2019-12-30 07:38:28 +01:00
const SessionConfirmInner = (props: Props) => {
const {
title = '',
message,
messageSub = '',
okTheme = SessionButtonColor.Primary,
closeTheme = SessionButtonColor.Primary,
onClickOk,
onClickClose,
hideCancel = false,
sessionIcon,
iconSize,
} = props;
2019-12-30 07:38:28 +01:00
const okText = props.okText || window.i18n('ok');
const cancelText = props.cancelText || window.i18n('cancel');
const showHeader = !!props.title;
2019-12-30 07:38:28 +01:00
2021-06-07 00:36:48 +02:00
const theme = useTheme();
const messageSubText = messageSub ? 'session-confirm-main-message' : 'subtle';
2019-12-30 07:38:28 +01:00
return (
2021-06-07 00:36:48 +02:00
2021-06-07 09:12:21 +02:00
<SessionWrapperModal
2021-06-07 00:36:48 +02:00
title={title}
onClose={onClickClose}
showExitIcon={false}
showHeader={showHeader}
theme={theme}
2021-06-07 09:12:21 +02:00
>
2021-06-07 00:36:48 +02:00
{!showHeader && <div className="spacer-lg" />}
2019-12-30 07:38:28 +01:00
<div className="session-modal__centered">
{sessionIcon && iconSize && (
<>
2021-06-07 00:36:48 +02:00
<SessionIcon iconType={sessionIcon} iconSize={iconSize} theme={theme} />
<div className="spacer-lg" />
</>
)}
2020-01-03 01:48:55 +01:00
2021-04-22 10:03:58 +02:00
<SessionHtmlRenderer tag="span" className={messageSubText} html={message} />
<SessionHtmlRenderer
tag="span"
className="session-confirm-sub-message subtle"
html={messageSub}
/>
</div>
<div className="session-modal__button-group">
2021-04-22 10:03:58 +02:00
<SessionButton text={okText} buttonColor={okTheme} onClick={onClickOk} />
2020-01-03 01:48:55 +01:00
{!hideCancel && (
2021-04-22 10:03:58 +02:00
<SessionButton text={cancelText} buttonColor={closeTheme} onClick={onClickClose} />
)}
</div>
2021-06-07 09:15:06 +02:00
2021-06-07 09:12:21 +02:00
</SessionWrapperModal>
);
};
export const SessionConfirm = withTheme(SessionConfirmInner);