-
-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathButton.jsx
More file actions
38 lines (32 loc) · 830 Bytes
/
Button.jsx
File metadata and controls
38 lines (32 loc) · 830 Bytes
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
import cls from "classnames";
import PureComponent from "../lib/PureComponent.jsx";
import * as styles from "./Button.css";
export default class Button extends PureComponent {
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 { props } = this;
return props.disabled || (props.active && !props.toggle);
}
handleClick = (event) => {
this.elem.blur();
this.props.onClick(event);
};
saveRef = (elem) => (this.elem = elem);
}