Sean Rhee 5 лет назад
Родитель
Сommit
68f11e293f
1 измененных файлов с 26 добавлено и 0 удалено
  1. 26 0
      dashboard/src/main/home/modals/Modal.tsx

+ 26 - 0
dashboard/src/main/home/modals/Modal.tsx

@@ -11,11 +11,28 @@ type StateType = {
 }
 }
 
 
 export default class Modal extends Component<PropsType, StateType> {
 export default class Modal extends Component<PropsType, StateType> {
+  wrapperRef: any = React.createRef();
+
+  componentDidMount() {
+    document.addEventListener('mousedown', this.handleClickOutside.bind(this));
+  }
+
+  componentWillUnmount() {
+    document.removeEventListener('mousedown', this.handleClickOutside.bind(this));
+  }
+
+  handleClickOutside = (event: any) => {
+    if (this.wrapperRef && !this.wrapperRef.current.contains(event.target)) {
+      this.props.onRequestClose();
+    }
+  }
+
   render() {
   render() {
     let { width, height } = this.props;
     let { width, height } = this.props;
     return (
     return (
       <Overlay>
       <Overlay>
         <StyledModal
         <StyledModal
+          ref={this.wrapperRef}
           width={width}
           width={width}
           height={height}
           height={height}
         >
         >
@@ -52,4 +69,13 @@ const StyledModal = styled.div`
   background-color: #202227;
   background-color: #202227;
   overflow: visible;
   overflow: visible;
   padding: 25px 32px;
   padding: 25px 32px;
+  animation: floatInModal 0.5s 0s;
+  @keyframes floatInModal {
+    from {
+      opacity: 0; transform: translateY(30px);
+    }
+    to {
+      opacity: 1; transform: translateY(0px);
+    }
+  }
 `;
 `;