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

70 lines
1.3 KiB
JavaScript
Raw Normal View History

//@flow
import React from "react";
import classNames from "classnames";
2018-07-19 12:05:50 +02:00
import { Link } from "react-router-dom";
export type ButtonProps = {
label: string,
loading?: boolean,
disabled?: boolean,
2018-08-03 10:37:56 +02:00
action?: (event: Event) => void,
2018-07-19 12:05:50 +02:00
link?: string,
fullWidth?: boolean,
2018-08-02 16:09:58 +02:00
className?: string,
classes: any
};
type Props = ButtonProps & {
2018-08-06 16:57:46 +02:00
type: string,
color: string
};
class Button extends React.Component<Props> {
static defaultProps = {
2018-08-06 16:57:46 +02:00
type: "button",
color: "default"
};
2018-07-19 12:05:50 +02:00
renderButton = () => {
const {
label,
loading,
disabled,
type,
2018-08-06 16:57:46 +02:00
color,
action,
fullWidth,
className
} = this.props;
const loadingClass = loading ? "is-loading" : "";
2018-07-19 12:05:50 +02:00
const fullWidthClass = fullWidth ? "is-fullwidth" : "";
return (
<button
2018-08-06 16:57:46 +02:00
type={type}
disabled={disabled}
2018-08-03 10:37:56 +02:00
onClick={action ? action : (event: Event) => {}}
2018-07-19 12:05:50 +02:00
className={classNames(
"button",
2018-08-06 16:57:46 +02:00
"is-" + color,
2018-07-19 12:05:50 +02:00
loadingClass,
fullWidthClass,
className
2018-07-19 12:05:50 +02:00
)}
>
{label}
</button>
);
2018-07-19 12:05:50 +02:00
};
render() {
const { link } = this.props;
if (link) {
return <Link to={link}>{this.renderButton()}</Link>;
} else {
return this.renderButton();
}
}
}
export default Button;