Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 62 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from 'react' |
||
2 | import PropTypes from 'prop-types' |
||
3 | import { makeStyles } from '@material-ui/core/styles' |
||
4 | import UIButton from '@material-ui/core/Button' |
||
5 | import Tooltip from '@material-ui/core/Tooltip' |
||
6 | |||
7 | const useStyles = makeStyles({ |
||
8 | buttonLabel: { |
||
9 | fontWeight: 'bold', |
||
10 | }, |
||
11 | |||
12 | tooltip: { |
||
13 | maxWidth: '8.5rem', |
||
14 | fontSize: '0.8rem', |
||
15 | textAlign: 'center', |
||
16 | }, |
||
17 | }) |
||
18 | |||
19 | const Button = ({ text, onClick, color, title, disabled, component }) => { |
||
20 | const classes = useStyles() |
||
21 | const uiButton = ( |
||
22 | <UIButton |
||
23 | classes={{ |
||
24 | label: classes.buttonLabel, |
||
25 | }} |
||
26 | variant="contained" |
||
27 | color={color} |
||
28 | onClick={onClick} |
||
29 | disabled={disabled} |
||
30 | component={component} |
||
31 | > |
||
32 | {text} |
||
33 | </UIButton> |
||
34 | ) |
||
35 | |||
36 | if (title) { |
||
37 | return ( |
||
38 | <Tooltip title={title} classes={{ tooltip: classes.tooltip }}> |
||
39 | {uiButton} |
||
40 | </Tooltip> |
||
41 | ) |
||
42 | } |
||
43 | return uiButton |
||
44 | } |
||
45 | |||
46 | Button.defaultProps = { |
||
47 | color: 'primary', |
||
48 | disabled: false, |
||
49 | component: 'button', |
||
50 | } |
||
51 | |||
52 | Button.propTypes = { |
||
53 | text: PropTypes.string.isRequired, |
||
54 | onClick: PropTypes.func, |
||
55 | color: PropTypes.string, |
||
56 | title: PropTypes.string, |
||
57 | disabled: PropTypes.bool, |
||
58 | component: PropTypes.string, |
||
59 | } |
||
60 | |||
61 | export default Button |
||
62 |