Files
SCM-Manager/scm-ui-components/packages/ui-components/src/buttons/Button.js

73 lines
1.3 KiB
JavaScript
Raw Normal View History

//@flow
import React from "react";
import classNames from "classnames";
2018-10-17 14:11:28 +02:00
import { withRouter } from "react-router-dom";
export type ButtonProps = {
label: string,
loading?: boolean,
disabled?: boolean,
action?: (event: Event) => void,
link?: string,
fullWidth?: boolean,
className?: string,
classes: any
};
type Props = ButtonProps & {
type: string,
2018-10-11 17:29:50 +02:00
color: string,
2018-10-17 14:11:28 +02:00
2018-10-11 17:29:50 +02:00
// context prop
2018-10-17 14:11:28 +02:00
history: any
};
class Button extends React.Component<Props> {
static defaultProps = {
type: "button",
color: "default"
};
2018-10-11 17:29:50 +02:00
onClick = (event: Event) => {
const { action, link, history } = this.props;
if (action) {
action(event);
} else if (link) {
history.push(link);
}
};
render() {
const {
label,
loading,
disabled,
type,
color,
fullWidth,
className
} = this.props;
const loadingClass = loading ? "is-loading" : "";
const fullWidthClass = fullWidth ? "is-fullwidth" : "";
return (
<button
type={type}
disabled={disabled}
2018-10-11 17:29:50 +02:00
onClick={this.onClick}
className={classNames(
"button",
"is-" + color,
loadingClass,
fullWidthClass,
className
)}
>
{label}
</button>
);
};
}
2018-10-11 17:29:50 +02:00
export default withRouter(Button);