-
-
Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathButton.jsx
More file actions
54 lines (43 loc) · 1.1 KB
/
Button.jsx
File metadata and controls
54 lines (43 loc) · 1.1 KB
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
import cls from "classnames";
import PropTypes from "prop-types";
import PureComponent from "../lib/PureComponent.jsx";
import * as styles from "./Button.css";
export default class Button extends PureComponent {
static propTypes = {
className: PropTypes.string,
active: PropTypes.bool,
toggle: PropTypes.bool,
disabled: PropTypes.bool,
onClick: PropTypes.func.isRequired,
children: PropTypes.node,
};
render({ active, className, children, ...props }) {
const classes = cls(className, {
[styles.button]: true,
[styles.active]: active,
});
return (
<button
{...props}
ref={this.saveRef}
type="button"
className={classes}
disabled={this.disabled}
onClick={this.handleClick}
>
{children}
</button>
);
}
get disabled() {
const { disabled, active, toggle } = this.props;
return disabled || (active && !toggle);
}
handleClick = (event) => {
if (this.elem) {
this.elem.blur();
}
this.props.onClick(event);
};
saveRef = (elem) => (this.elem = elem);
}