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

Kai Reinhard
09.43.2018 1a21e0d3baca3870611a1fe712027a559d9a4b93
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {UncontrolledTooltip} from 'reactstrap';
import {getTranslation} from '../../../utilities/i18n';
 
const FormSelect = (props) => {
    let tooltip = null;
    let targetId = props.id || props.name;
    if (props.hint) {
        tooltip = <UncontrolledTooltip placement={props.hintPlacement} target={targetId}>
            {props.hint}
        </UncontrolledTooltip>;
    }
    const {className, hint, hintPlacement, id, ...other} = props;
    return (
        <React.Fragment>
            <select id={targetId}
                    className={classNames('custom-select form-control form-control-sm mr-1', className)}
                    {...other}
            >
                {props.children}
            </select>
            {tooltip}
        </React.Fragment>
    );
}
 
FormSelect.propTypes = {
    id: PropTypes.string,
    value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
    name: PropTypes.string,
    onChange: PropTypes.func,
    hint: PropTypes.string,
    hintPlacement: PropTypes.oneOf(['right', 'top']),
    children: PropTypes.node,
    className: PropTypes.string
};
 
FormSelect.defaultProps = {
    hint: null,
    hintPlacement: 'top',
};
 
 
const FormOption = (props) => {
    let label;
    if (props.i18nKey) {
        label = getTranslation(props.i18nKey) || props.value;
    } else {
        label = props.label || props.value;
    }
    return (
        <React.Fragment>
            <option value={props.value}
            >
                {label}
            </option>
        </React.Fragment>
    );
}
 
FormSelect.propTypes = {
    value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
    i18nKey: PropTypes.string,
    label: PropTypes.string
};
 
export {
    FormSelect, FormOption
};