Toolbar.jsx 2.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import React from 'react';
import BigCalendar from 'react-big-calendar';
import Toolbar from 'react-big-calendar/lib/Toolbar';
import '!style-loader!css-loader!react-big-calendar/lib/css/react-big-calendar.css';
import withSizes from 'react-sizes';

class CustomToolbar extends Toolbar {
    render() {
        const { label, isMobile } = this.props;
        if (isMobile && label === '') {
            this.view('day');
        }
        return (
            <div className="rbc-toolbar d-flex justify-content-between">
                {!isMobile && (
Zac Wood's avatar
Zac Wood committed
16
17
18
19
20
21
22
23
24
25
                    <div>
                        <span className="rbc-btn-group">
                            <button type="button" onClick={() => this.view('day')}>
                                Day
                            </button>
                            <button type="button" onClick={() => this.view('week')}>
                                Week
                            </button>
                        </span>
                    </div>
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
                )}

                <span className="rbc-toolbar-label">{this.props.label}</span>

                {this.props.view === 'day' && (
                    <span className="rbc-btn-group">
                        {this.props.label !== 'Sun' && (
                            <button type="button" onClick={() => this.navigate('PREV')}>
                                Back
                            </button>
                        )}
                        {this.props.label !== 'Sat' && (
                            <button type="button" onClick={() => this.navigate('NEXT')}>
                                Next
                            </button>
                        )}
                    </span>
                )}
            </div>
        );
    }

    navigate = action => {
        this.props.onNavigate(action);
    };

    view = action => {
        this.props.onView(action);
    };
}

const mapSizesToProps = ({ width }) => ({
    isMobile: width < 1000,
});

export default withSizes(mapSizesToProps)(CustomToolbar);