mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
75 lines
1.4 KiB
JavaScript
75 lines
1.4 KiB
JavaScript
//@flow
|
|
import * as React from "react";
|
|
import classNames from "classnames";
|
|
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,
|
|
children?: React.Node,
|
|
classes: any
|
|
};
|
|
|
|
type Props = ButtonProps & {
|
|
type: string,
|
|
color: string,
|
|
|
|
// context prop
|
|
history: any
|
|
};
|
|
|
|
class Button extends React.Component<Props> {
|
|
static defaultProps = {
|
|
type: "button",
|
|
color: "default"
|
|
};
|
|
|
|
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,
|
|
children,
|
|
className
|
|
} = this.props;
|
|
const loadingClass = loading ? "is-loading" : "";
|
|
const fullWidthClass = fullWidth ? "is-fullwidth" : "";
|
|
return (
|
|
<button
|
|
type={type}
|
|
disabled={disabled}
|
|
onClick={this.onClick}
|
|
className={classNames(
|
|
"button",
|
|
"is-" + color,
|
|
loadingClass,
|
|
fullWidthClass,
|
|
className
|
|
)}
|
|
>
|
|
{label} {children}
|
|
</button>
|
|
);
|
|
};
|
|
|
|
}
|
|
|
|
export default withRouter(Button);
|