aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/PropertiesSection.tsx
blob: bd586b2f979839d0d0989869386fba099b2e2a8b (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React = require('react');
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { action, computed, observable } from 'mobx';
import { observer } from 'mobx-react';
import './PropertiesSection.scss';
import { Doc } from '../../fields/Doc';
import { StrCast } from '../../fields/Types';
import { SettingsManager } from '../util/SettingsManager';

export interface PropertiesSectionProps {
    title: string;
    children?: JSX.Element | string | null;
    isOpen: boolean;
    setIsOpen: (bool: boolean) => any;
    inSection?: boolean;
    setInSection?: (bool: boolean) => any;
    onDoubleClick?: () => void;
}

@observer
export class PropertiesSection extends React.Component<PropertiesSectionProps> {
    @computed get color() {
        return SettingsManager.userColor;
    }

    @computed get backgroundColor() {
        return SettingsManager.userBackgroundColor;
    }

    @computed get variantColor() {
        return SettingsManager.userVariantColor;
    }

    @observable isDouble: boolean = false;

    render() {
        if (this.props.children === undefined || this.props.children === null) return null;
        else
            return (
                <div className="propertiesView-section" onPointerEnter={action(() => this.props.setInSection && this.props.setInSection(true))} onPointerLeave={action(() => this.props.setInSection && this.props.setInSection(false))}>
                    <div
                        className="propertiesView-sectionTitle"
                        onDoubleClick={action(e => {
                            this.isDouble = true;
                            this.props.onDoubleClick && this.props.onDoubleClick();
                            this.props.setIsOpen(true);
                            setTimeout(() => (this.isDouble = false), 300);
                        })}
                        onClick={action(e => {
                            this.props.setIsOpen(!this.props.isOpen);
                        })}
                        style={{
                            background: this.variantColor,
                            // this.props.isOpen ? this.variantColor : this.backgroundColor,
                            color: this.color,
                        }}>
                        {this.props.title}
                        <div className="propertiesView-sectionTitle-icon">
                            <FontAwesomeIcon icon={this.props.isOpen ? 'caret-down' : 'caret-right'} size="lg" />
                        </div>
                    </div>
                    {!this.props.isOpen ? null : <div className="propertiesView-content">{this.props.children}</div>}
                </div>
            );
    }
}