-
Notifications
You must be signed in to change notification settings - Fork 256
/
OverlayTechnology.tsx
78 lines (61 loc) · 1.57 KB
/
OverlayTechnology.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Libraries
import React, {Component} from 'react'
import classnames from 'classnames'
import {ErrorHandling} from 'src/shared/decorators/errors'
interface Props {
children: JSX.Element
visible: boolean
}
interface State {
showChildren: boolean
}
@ErrorHandling
class OverlayTechnology extends Component<Props, State> {
public static getDerivedStateFromProps(props) {
if (props.visible) {
return {showChildren: true}
}
return {}
}
private animationTimer: number
constructor(props: Props) {
super(props)
this.state = {
showChildren: false,
}
}
public componentDidUpdate(prevProps) {
if (prevProps.visible && !this.props.visible) {
clearTimeout(this.animationTimer)
this.animationTimer = window.setTimeout(this.hideChildren, 300)
}
}
public render() {
return (
<div className={this.overlayClass}>
{this.childContainer}
<div className="overlay--mask" />
</div>
)
}
private get childContainer(): JSX.Element {
const {children} = this.props
const {showChildren} = this.state
if (showChildren) {
return (
<div className="overlay--dialog" data-test="overlay-children">
{children}
</div>
)
}
return <div className="overlay--dialog" data-test="overlay-children" />
}
private get overlayClass(): string {
const {visible} = this.props
return classnames('overlay-tech', {show: visible})
}
private hideChildren = (): void => {
this.setState({showChildren: false})
}
}
export default OverlayTechnology