summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-theme-default/src/components/Theme.js
blob: 8f5dce69349708538f03f3f41059f7d937ac017f (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
const GitBook = require('gitbook-core');
const { React } = GitBook;

const Sidebar = require('./Sidebar');
const Body = require('./Body');
const LoadingBar = require('./LoadingBar');

const Theme = React.createClass({
    propTypes: {
        // State
        page:     GitBook.PropTypes.Page,
        summary:  GitBook.PropTypes.Summary,
        readme:   GitBook.PropTypes.Readme,
        history:  GitBook.PropTypes.History,
        sidebar:  React.PropTypes.object,
        // Other props
        children: React.PropTypes.node
    },

    render() {
        const { page, summary, children, sidebar, readme, history } = this.props;

        return (
            <GitBook.FlexLayout column className="GitBook book">
                <LoadingBar show={history.loading} />
                <GitBook.Head
                    title={page.title}
                    titleTemplate="%s - GitBook" />
                <GitBook.ImportCSS href="gitbook/theme-default/theme.css" />

                <GitBook.FlexBox>
                    <GitBook.FlexLayout>
                        {sidebar.open ? (
                            <GitBook.FlexBox col={3}>
                                <Sidebar summary={summary} />
                            </GitBook.FlexBox>
                        ) : null}
                        <GitBook.FlexBox col={sidebar.open ? 9 : 12}>
                            <Body page={page} readme={readme} />
                        </GitBook.FlexBox>
                    </GitBook.FlexLayout>
                </GitBook.FlexBox>
                {children}
            </GitBook.FlexLayout>
        );
    }
});

module.exports = GitBook.connect(Theme, ({page, summary, sidebar, readme, history}) => {
    return { page, summary, sidebar, readme, history };
});