aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/MainViewModal.tsx
blob: d7640dc7294393873a63d13de109fe5425b19049 (plain)
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
import { isDark } from '@dash/components';
import { observer } from 'mobx-react';
import * as React from 'react';
import { SnappingManager } from '../util/SnappingManager';
import './MainViewModal.scss';

export interface MainViewOverlayProps {
    isDisplayed: boolean;
    interactive: boolean;
    contents: string | JSX.Element | null;
    dialogueBoxStyle?: React.CSSProperties;
    overlayStyle?: React.CSSProperties;
    dialogueBoxDisplayedOpacity?: number;
    closeOnExternalClick?: () => void; // the close method of a MainViewModal, triggered if there is a click on the overlay (closing the modal)
}

@observer
export class MainViewModal extends React.Component<MainViewOverlayProps> {
    render() {
        const p = this.props;
        const dialogueOpacity = p.dialogueBoxDisplayedOpacity || 1;
        return !p.isDisplayed ? null : (
            <div
                className="mainViewModal-cont"
                style={{
                    pointerEvents: p.isDisplayed && p.interactive ? 'all' : 'none',
                }}>
                <div
                    className="dialogue-box"
                    style={{
                        borderColor: 'black',
                        height: 'max-content',
                        overflow: 'auto',
                        maxHeight: '80%',
                        ...(p.dialogueBoxStyle || {}),
                        opacity: p.isDisplayed ? dialogueOpacity : 0,
                    }}>
                    {p.contents}
                </div>
                <div
                    className="overlay"
                    onClick={this.props?.closeOnExternalClick}
                    style={{
                        backgroundColor: isDark(SnappingManager.userColor ?? '') ? '#DFDFDF30' : '#32323230',
                        ...(p.overlayStyle || {}),
                    }}
                />
            </div>
        );
    }
}