2020-04-10 20:57:50 +02:00
|
|
|
import {ReactComponentBase} from "tc-shared/ui/react-elements/ReactComponentBase";
|
|
|
|
import * as React from "react";
|
|
|
|
const cssStyle = require("./Button.scss");
|
|
|
|
|
|
|
|
export interface ButtonProperties {
|
2020-08-11 00:25:20 +02:00
|
|
|
color?: "green" | "blue" | "red" | "purple" | "brown" | "yellow" | "default" | "none";
|
2020-04-10 20:57:50 +02:00
|
|
|
type?: "normal" | "small" | "extra-small";
|
|
|
|
|
2020-05-20 20:46:59 +02:00
|
|
|
className?: string;
|
2020-08-23 11:05:55 +02:00
|
|
|
onClick?: (event: React.MouseEvent) => void;
|
2020-04-10 20:57:50 +02:00
|
|
|
|
2020-05-20 20:46:59 +02:00
|
|
|
hidden?: boolean;
|
2020-04-10 20:57:50 +02:00
|
|
|
disabled?: boolean;
|
2020-08-23 11:05:55 +02:00
|
|
|
|
|
|
|
title?: string;
|
2020-11-28 13:15:27 +01:00
|
|
|
transparency?: boolean;
|
2020-04-10 20:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ButtonState {
|
|
|
|
disabled?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Button extends ReactComponentBase<ButtonProperties, ButtonState> {
|
2020-04-18 19:37:30 +02:00
|
|
|
protected defaultState(): ButtonState {
|
2020-04-10 20:57:50 +02:00
|
|
|
return {
|
|
|
|
disabled: undefined
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-05-20 20:46:59 +02:00
|
|
|
if(this.props.hidden)
|
|
|
|
return null;
|
2020-06-15 16:56:05 +02:00
|
|
|
|
2020-04-10 20:57:50 +02:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
className={this.classList(
|
|
|
|
cssStyle.button,
|
|
|
|
cssStyle["color-" + this.props.color] || cssStyle["color-default"],
|
2020-05-20 20:46:59 +02:00
|
|
|
cssStyle["type-" + this.props.type] || cssStyle["type-normal"],
|
2020-11-28 13:15:27 +01:00
|
|
|
typeof this.props.transparency === "boolean" && !this.props.transparency ? cssStyle.nonTransparent : undefined,
|
2020-05-20 20:46:59 +02:00
|
|
|
this.props.className
|
2020-04-10 20:57:50 +02:00
|
|
|
)}
|
2020-08-23 11:05:55 +02:00
|
|
|
title={this.props.title}
|
2020-06-15 16:56:05 +02:00
|
|
|
disabled={typeof this.state.disabled === "boolean" ? this.state.disabled : this.props.disabled}
|
2020-04-10 20:57:50 +02:00
|
|
|
onClick={this.props.onClick}
|
|
|
|
>
|
|
|
|
{this.props.children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|