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

51 lines
1.6 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" | "none";
2020-04-10 20:57:50 +02:00
type?: "normal" | "small" | "extra-small";
2020-05-20 20:46:59 +02:00
className?: string;
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;
title?: string;
transparency?: boolean;
2020-04-10 20:57:50 +02:00
}
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"],
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
)}
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>
)
}
}