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

const STYLE_TO_ICON = {
    info:    'info',
    tip:     'question',
    danger:  'exclamation-circle',
    warning: 'exclamation-triangle'
};

const HintAlert = React.createClass({
    propTypes: {
        icon:     React.PropTypes.string,
        style:    React.PropTypes.string,
        children: React.PropTypes.node
    },

    render() {
        const { children, style, icon } = this.props;
        const className = classNames('HintAlert', 'alert', `alert-${style}`);

        return (
            <div className={className}>
                <div className="HintAlert/Icon">
                    <GitBook.Icon id={icon || STYLE_TO_ICON[style]} />
                </div>
                <div className="HintAlert/Content">
                    {children}
                </div>
            </div>
        );
    }
});

module.exports = GitBook.createPlugin({
    init: (dispatch, getState, { Components }) => {
        dispatch(Components.registerComponent(HintAlert, { role: 'block:hint' }));
    }
});