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

module.exports = GitBook.createPlugin({
    activate: (dispatch, getState, { Components }) => {
        // Dispatch initialization actions
        dispatch(Components.registerComponent(SharingButton, { role: 'toolbar:buttons:right' }))
    },
    deactivate: (dispatch, getState) => {
        // Dispatch cleanup actions
    },
    reduce: (state, action) => state
});

let SharingButton = React.createClass({
    propTypes: {
        page: GitBook.Shapes.Page
    },

    onClick() {
        alert(this.props.page.title)
    },

    render() {
        return (
            <GitBook.Button onClick={this.onClick}>
                <GitBook.Icon id="facebook"/>
            </GitBook.Button>
        )
    }
})
SharingButton = GitBook.connect(SharingButton, function mapStateToProps(state) {
    return { page: state.page }
})