signal-desktop/ts/components/ShortcutGuideModal.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2019 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2019-11-07 21:36:16 +00:00
import * as React from 'react';
import { createPortal } from 'react-dom';
import type { LocalizerType } from '../types/Util';
2019-11-07 21:36:16 +00:00
import { ShortcutGuide } from './ShortcutGuide';
export type PropsType = {
hasInstalledStickers: boolean;
platform: string;
2022-12-22 03:07:45 +00:00
readonly closeShortcutGuideModal: () => unknown;
2019-11-07 21:36:16 +00:00
readonly i18n: LocalizerType;
};
2022-11-18 00:45:19 +00:00
export const ShortcutGuideModal = React.memo(function ShortcutGuideModalInner(
props: PropsType
) {
2023-12-07 23:59:54 +00:00
const { i18n, closeShortcutGuideModal, hasInstalledStickers, platform } =
props;
2020-09-12 00:46:52 +00:00
const [root, setRoot] = React.useState<HTMLElement | null>(null);
2019-11-07 21:36:16 +00:00
2020-09-12 00:46:52 +00:00
React.useEffect(() => {
const div = document.createElement('div');
document.body.appendChild(div);
setRoot(div);
2019-11-07 21:36:16 +00:00
2020-09-12 00:46:52 +00:00
return () => {
document.body.removeChild(div);
};
}, []);
2019-11-07 21:36:16 +00:00
2020-09-12 00:46:52 +00:00
return root
? createPortal(
<div className="module-shortcut-guide-modal">
<div className="module-shortcut-guide-container">
<ShortcutGuide
2022-12-22 03:07:45 +00:00
close={closeShortcutGuideModal}
2020-09-12 00:46:52 +00:00
hasInstalledStickers={hasInstalledStickers}
i18n={i18n}
2022-12-22 03:07:45 +00:00
platform={platform}
2020-09-12 00:46:52 +00:00
/>
</div>
</div>,
root
)
: null;
});