TeaWeb/shared/js/ui/react-elements/Button.tsx

46 lines
1.3 KiB
TypeScript
Raw Normal View History

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 {
color?: "green" | "blue" | "red" | "purple" | "brown" | "yellow" | "default";
type?: "normal" | "small" | "extra-small";
2020-05-20 20:46:59 +02:00
className?: string;
2020-04-10 20:57:50 +02:00
onClick?: () => void;
2020-05-20 20:46:59 +02:00
hidden?: boolean;
2020-04-10 20:57:50 +02:00
disabled?: boolean;
}
export interface ButtonState {
disabled?: boolean
}
export class Button extends ReactComponentBase<ButtonProperties, ButtonState> {
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"],
this.props.className
2020-04-10 20:57:50 +02:00
)}
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>
)
}
}