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
		
	
| 
											5 years ago
										 | import React, { ReactNode } from 'react'; | ||
| 
											6 years ago
										 | import classNames from 'classnames'; | ||
|  | 
 | ||
| 
											6 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', | ||
| 
											6 years ago
										 |   Success = 'success', | ||
| 
											6 years ago
										 |   Danger = 'danger', | ||
|  |   Warning = 'warning', | ||
| 
											6 years ago
										 |   None = '', | ||
| 
											6 years ago
										 | } | ||
|  | 
 | ||
| 
											5 years ago
										 | type Props = { | ||
| 
											6 years ago
										 |   text?: string; | ||
| 
											6 years ago
										 |   disabled?: boolean; | ||
| 
											6 years ago
										 |   buttonType: SessionButtonType; | ||
|  |   buttonColor: SessionButtonColor; | ||
|  |   onClick: any; | ||
| 
											5 years ago
										 |   children?: ReactNode; | ||
| 
											4 years ago
										 |   dataTestId?: string; | ||
| 
											5 years ago
										 | }; | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 | export const SessionButton = (props: Props) => { | ||
| 
											4 years ago
										 |   const { buttonType, dataTestId, buttonColor, text, disabled, onClick } = props; | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 |   const clickHandler = (e: any) => { | ||
| 
											4 years ago
										 |     if (onClick) { | ||
| 
											5 years ago
										 |       e.stopPropagation(); | ||
| 
											4 years ago
										 |       onClick(); | ||
| 
											6 years ago
										 |     } | ||
| 
											5 years ago
										 |   }; | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 |   const buttonTypes = []; | ||
|  |   const onClickFn = disabled ? () => null : clickHandler; | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 |   buttonTypes.push(buttonType); | ||
|  |   if (buttonType.includes('-outline')) { | ||
|  |     buttonTypes.push(buttonType.replace('-outline', '')); | ||
| 
											6 years ago
										 |   } | ||
| 
											5 years ago
										 | 
 | ||
|  |   return ( | ||
|  |     <div | ||
| 
											5 years ago
										 |       className={classNames('session-button', ...buttonTypes, buttonColor, disabled && 'disabled')} | ||
| 
											5 years ago
										 |       role="button" | ||
|  |       onClick={onClickFn} | ||
| 
											4 years ago
										 |       data-testid={dataTestId} | ||
| 
											5 years ago
										 |     > | ||
|  |       {props.children || text} | ||
|  |     </div> | ||
|  |   ); | ||
|  | }; | ||
|  | 
 | ||
|  | SessionButton.defaultProps = { | ||
|  |   disabled: false, | ||
|  |   buttonType: SessionButtonType.Default, | ||
|  |   buttonColor: SessionButtonColor.Primary, | ||
|  |   onClick: null, | ||
|  | } as Partial<Props>; |