aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/Button.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ui/Button.js')
-rw-r--r--src/components/ui/Button.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/components/ui/Button.js b/src/components/ui/Button.js
new file mode 100644
index 000000000..67c801d98
--- /dev/null
+++ b/src/components/ui/Button.js
@@ -0,0 +1,95 @@
1import { Component } from 'react';
2import PropTypes from 'prop-types';
3import { observer, inject } from 'mobx-react';
4import Loader from 'react-loader';
5import classnames from 'classnames';
6
7@inject('stores')
8@observer
9class Button extends Component {
10 static propTypes = {
11 className: PropTypes.string,
12 label: PropTypes.string.isRequired,
13 disabled: PropTypes.bool,
14 onClick: PropTypes.func,
15 type: PropTypes.string,
16 buttonType: PropTypes.string,
17 loaded: PropTypes.bool,
18 htmlForm: PropTypes.string,
19 stores: PropTypes.shape({
20 settings: PropTypes.shape({
21 app: PropTypes.shape({
22 accentColor: PropTypes.string.isRequired,
23 }).isRequired,
24 }).isRequired,
25 }).isRequired,
26 };
27
28 static defaultProps = {
29 className: null,
30 disabled: false,
31 onClick: () => {},
32 type: 'button',
33 buttonType: '',
34 loaded: true,
35 htmlForm: '',
36 };
37
38 element = null;
39
40 render() {
41 const {
42 label,
43 className,
44 disabled,
45 onClick,
46 type,
47 buttonType,
48 loaded,
49 htmlForm,
50 } = this.props;
51
52 const buttonProps = {
53 className: classnames({
54 'franz-form__button': true,
55 [`franz-form__button--${buttonType}`]: buttonType,
56 [`${className}`]: className,
57 }),
58 type,
59 };
60
61 if (disabled) {
62 buttonProps.disabled = true;
63 }
64
65 if (onClick) {
66 buttonProps.onClick = onClick;
67 }
68
69 if (htmlForm) {
70 buttonProps.form = htmlForm;
71 }
72
73 return (
74 // disabling rule as button has type defined in `buttonProps`
75 /* eslint-disable react/button-has-type */
76 <button {...buttonProps}>
77 <Loader
78 loaded={loaded}
79 lines={10}
80 scale={0.4}
81 color={
82 buttonType !== 'secondary'
83 ? '#FFF'
84 : this.props.stores.settings.app.accentColor
85 }
86 component="span"
87 />
88 {label}
89 </button>
90 /* eslint-enable react/button-has-type */
91 );
92 }
93}
94
95export default Button;