mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
21.28.2019 62896e333804c9558d6cadd27c61c3a1e722e70f
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
import React from 'react';
import PropTypes from 'prop-types';
import {UncontrolledTooltip} from 'reactstrap';
import classNames from 'classnames';
import {revisedRandId} from "../../../utilities/global";
import I18n from "../translation/I18n";
 
class FormButton extends React.Component {
 
    _id = this.props.id || this.props.name || revisedRandId();
 
    render() {
        let tooltip = null;
        const {className, hint, hintKey, hintPlacement, id, bsStyle, ...other} = this.props;
        if (hint || hintKey) {
            tooltip = <UncontrolledTooltip placement={hintPlacement} target={this._id}>
                {hintKey ? <I18n name={hintKey}/> : hint}
            </UncontrolledTooltip>;
        }
        return (
            <React.Fragment>
                <button
                    {...other}
                    id={this._id}
                    className={classNames(`btn btn-${bsStyle}`, className)}
                >
                    {this.props.children}
                </button>
                {tooltip}
            </React.Fragment>
        );
    }
};
 
FormButton.propTypes = {
    id: PropTypes.string,
    bsStyle: PropTypes.oneOf(['primary', 'outline-primary', null]),
    type: PropTypes.string,
    onClick: PropTypes.func,
    hint: PropTypes.string,
    hintKey: PropTypes.string,
    hintPlacement: PropTypes.oneOf(['right', 'top']),
    disabled: PropTypes.bool,
    children: PropTypes.node
};
FormButton.defaultProps = {
    bsStyle: 'outline-primary',
    type: 'button',
    hintPlacement: 'top',
    disabled: false
};
 
export {
    FormButton
};