You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
4 years ago
|
import React, { ReactNode } from 'react';
|
||
5 years ago
|
import classNames from 'classnames';
|
||
|
|
||
5 years ago
|
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',
|
||
5 years ago
|
Success = 'success',
|
||
5 years ago
|
Danger = 'danger',
|
||
|
Warning = 'warning',
|
||
5 years ago
|
None = '',
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
type Props = {
|
||
5 years ago
|
text?: string;
|
||
5 years ago
|
disabled?: boolean;
|
||
5 years ago
|
buttonType: SessionButtonType;
|
||
|
buttonColor: SessionButtonColor;
|
||
|
onClick: any;
|
||
4 years ago
|
children?: ReactNode;
|
||
3 years ago
|
dataTestId?: string;
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
export const SessionButton = (props: Props) => {
|
||
3 years ago
|
const { buttonType, dataTestId, buttonColor, text, disabled, onClick } = props;
|
||
5 years ago
|
|
||
4 years ago
|
const clickHandler = (e: any) => {
|
||
3 years ago
|
if (onClick) {
|
||
4 years ago
|
e.stopPropagation();
|
||
3 years ago
|
onClick();
|
||
5 years ago
|
}
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
const buttonTypes = [];
|
||
|
const onClickFn = disabled ? () => null : clickHandler;
|
||
5 years ago
|
|
||
4 years ago
|
buttonTypes.push(buttonType);
|
||
|
if (buttonType.includes('-outline')) {
|
||
|
buttonTypes.push(buttonType.replace('-outline', ''));
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
|
return (
|
||
|
<div
|
||
4 years ago
|
className={classNames('session-button', ...buttonTypes, buttonColor, disabled && 'disabled')}
|
||
4 years ago
|
role="button"
|
||
|
onClick={onClickFn}
|
||
3 years ago
|
data-testid={dataTestId}
|
||
4 years ago
|
>
|
||
|
{props.children || text}
|
||
|
</div>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
SessionButton.defaultProps = {
|
||
|
disabled: false,
|
||
|
buttonType: SessionButtonType.Default,
|
||
|
buttonColor: SessionButtonColor.Primary,
|
||
|
onClick: null,
|
||
|
} as Partial<Props>;
|