mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-21 00:48:19 +01:00
Sticker Creator
This commit is contained in:
committed by
Scott Nonnenberg
parent
2df1ba6e61
commit
11d47a8eb9
44
sticker-creator/components/ConfirmModal.tsx
Normal file
44
sticker-creator/components/ConfirmModal.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import * as styles from './ConfirmModal.scss';
|
||||
import { ConfirmDialog, Props } from '../elements/ConfirmDialog';
|
||||
|
||||
export type Mode = 'removable' | 'pick-emoji' | 'add';
|
||||
|
||||
export const ConfirmModal = React.memo(
|
||||
// tslint:disable-next-line max-func-body-length
|
||||
(props: Props) => {
|
||||
const { onCancel } = props;
|
||||
const [popperRoot, setPopperRoot] = React.useState<HTMLDivElement>();
|
||||
|
||||
// Create popper root and handle outside clicks
|
||||
React.useEffect(
|
||||
() => {
|
||||
const root = document.createElement('div');
|
||||
setPopperRoot(root);
|
||||
document.body.appendChild(root);
|
||||
const handleOutsideClick = ({ target }: MouseEvent) => {
|
||||
if (!root.contains(target as Node)) {
|
||||
onCancel();
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', handleOutsideClick);
|
||||
|
||||
return () => {
|
||||
document.body.removeChild(root);
|
||||
document.removeEventListener('click', handleOutsideClick);
|
||||
};
|
||||
},
|
||||
[onCancel]
|
||||
);
|
||||
|
||||
return popperRoot
|
||||
? createPortal(
|
||||
<div className={styles.facade}>
|
||||
<ConfirmDialog {...props} />
|
||||
</div>,
|
||||
popperRoot
|
||||
)
|
||||
: null;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user