session-desktop/ts/components/session/SessionButton.tsx

72 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-12-05 01:04:48 +01:00
import React from 'react';
import classNames from 'classnames';
export enum SessionButtonType {
Brand = 'brand',
BrandOutline = 'brand-outline',
Default = 'default',
DefaultOutline = 'default-outline',
Square = 'square',
SquareOutline = 'square-outline',
Simple = 'simple',
}
export enum SessionButtonColor {
Green = 'green',
White = 'white',
Primary = 'primary',
Secondary = 'secondary',
Success = 'success',
Danger = 'danger',
Warning = 'warning',
None = '',
2019-12-05 01:04:48 +01:00
}
interface Props {
2020-01-08 09:16:01 +01:00
text?: string;
buttonType: SessionButtonType;
buttonColor: SessionButtonColor;
onClick: any;
2019-12-05 01:04:48 +01:00
}
export class SessionButton extends React.PureComponent<Props> {
public static defaultProps = {
buttonType: SessionButtonType.Default,
buttonColor: SessionButtonColor.Primary,
onClick: () => null,
};
constructor(props: any) {
super(props);
this.clickHandler = this.clickHandler.bind(this);
}
2019-12-05 01:04:48 +01:00
public render() {
const { buttonType, buttonColor, text } = this.props;
2019-12-05 01:04:48 +01:00
2019-12-16 00:03:50 +01:00
const buttonTypes = [];
buttonTypes.push(buttonType);
if (buttonType.includes('-outline')) {
buttonTypes.push(buttonType.replace('-outline', ''));
}
2019-12-05 01:04:48 +01:00
return (
<div
2019-12-16 00:03:50 +01:00
className={classNames('session-button', ...buttonTypes, buttonColor)}
role="button"
onClick={this.clickHandler}
>
2020-01-08 09:16:01 +01:00
{this.props.children || text}
2019-12-05 06:12:33 +01:00
</div>
2019-12-05 01:04:48 +01:00
);
}
private clickHandler(e: any) {
if (this.props.onClick) {
e.stopPropagation();
this.props.onClick();
}
}
2019-12-05 01:04:48 +01:00
}