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

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

const reduceState = require('./reducers');

let ThemeBody = React.createClass({
    propTypes: {
        // State
        page:     GitBook.Shapes.Page,
        summary:  GitBook.Shapes.Summary,
        sidebar:  React.PropTypes.object,
        // Other props
        children: React.PropTypes.node
    },

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

        return (
            <GitBook.FlexLayout column className="GitBook book">
                <GitBook.Head
                    title={page.title}
                    titleTemplate="%s - GitBook" />
                <GitBook.ImportCSS href="gitbook/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} />
                        </GitBook.FlexBox>
                    </GitBook.FlexLayout>
                </GitBook.FlexBox>
                {children}
            </GitBook.FlexLayout>
        );
    }
});

ThemeBody = GitBook.connect(ThemeBody, ({page, summary, sidebar}) => {
    return { page, summary, sidebar };
});

module.exports = GitBook.createPlugin({
    init: (dispatch, state, { Components }) => {
        dispatch(Components.registerComponent(ThemeBody, { role: 'Body' }));
    },
    reduce: reduceState
});