| 
									
										
										
										
											2018-05-02 19:43:23 -07:00
										 |  |  | import React from 'react'; | 
					
						
							| 
									
										
										
										
											2018-07-06 17:48:14 -07:00
										 |  |  | import classNames from 'classnames'; | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 15:18:00 -07:00
										 |  |  | import { ContactType } from '../../types/Contact'; | 
					
						
							| 
									
										
										
										
											2018-05-02 19:43:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-14 13:49:58 -08:00
										 |  |  | import { LocalizerType } from '../../types/Util'; | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   renderAvatar, | 
					
						
							|  |  |  |   renderContactShorthand, | 
					
						
							|  |  |  |   renderName, | 
					
						
							|  |  |  | } from './_contactUtil'; | 
					
						
							| 
									
										
										
										
											2018-05-22 12:31:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-02 19:43:23 -07:00
										 |  |  | interface Props { | 
					
						
							| 
									
										
										
										
											2019-03-15 15:18:00 -07:00
										 |  |  |   contact: ContactType; | 
					
						
							| 
									
										
										
										
											2019-01-14 13:49:58 -08:00
										 |  |  |   i18n: LocalizerType; | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |   isIncoming: boolean; | 
					
						
							|  |  |  |   withContentAbove: boolean; | 
					
						
							|  |  |  |   withContentBelow: boolean; | 
					
						
							| 
									
										
										
										
											2019-11-14 18:12:31 -08:00
										 |  |  |   tabIndex: number; | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  |   onClick?: () => void; | 
					
						
							| 
									
										
										
										
											2018-05-02 19:43:23 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 12:31:43 -07:00
										 |  |  | export class EmbeddedContact extends React.Component<Props> { | 
					
						
							| 
									
										
										
										
											2018-05-07 17:51:29 -07:00
										 |  |  |   public render() { | 
					
						
							|  |  |  |     const { | 
					
						
							|  |  |  |       contact, | 
					
						
							|  |  |  |       i18n, | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |       isIncoming, | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  |       onClick, | 
					
						
							| 
									
										
										
										
											2019-11-14 18:12:31 -08:00
										 |  |  |       tabIndex, | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |       withContentAbove, | 
					
						
							|  |  |  |       withContentBelow, | 
					
						
							| 
									
										
										
										
											2018-05-07 17:51:29 -07:00
										 |  |  |     } = this.props; | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |     const module = 'embedded-contact'; | 
					
						
							| 
									
										
										
										
											2019-01-30 12:15:07 -08:00
										 |  |  |     const direction = isIncoming ? 'incoming' : 'outgoing'; | 
					
						
							| 
									
										
										
										
											2018-05-07 17:51:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2019-11-07 13:36:16 -08:00
										 |  |  |       <button | 
					
						
							| 
									
										
										
										
											2018-07-06 17:48:14 -07:00
										 |  |  |         className={classNames( | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |           'module-embedded-contact', | 
					
						
							|  |  |  |           withContentAbove | 
					
						
							|  |  |  |             ? 'module-embedded-contact--with-content-above' | 
					
						
							|  |  |  |             : null, | 
					
						
							|  |  |  |           withContentBelow | 
					
						
							|  |  |  |             ? 'module-embedded-contact--with-content-below' | 
					
						
							|  |  |  |             : null | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2019-11-14 18:12:31 -08:00
										 |  |  |         onKeyDown={(event: React.KeyboardEvent) => { | 
					
						
							|  |  |  |           if (event.key !== 'Enter' && event.key !== 'Space') { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if (onClick) { | 
					
						
							|  |  |  |             event.stopPropagation(); | 
					
						
							|  |  |  |             event.preventDefault(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             onClick(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }} | 
					
						
							| 
									
										
										
										
											2019-11-07 13:36:16 -08:00
										 |  |  |         onClick={(event: React.MouseEvent) => { | 
					
						
							|  |  |  |           if (onClick) { | 
					
						
							|  |  |  |             event.stopPropagation(); | 
					
						
							|  |  |  |             event.preventDefault(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             onClick(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }} | 
					
						
							| 
									
										
										
										
											2019-11-14 18:12:31 -08:00
										 |  |  |         tabIndex={tabIndex} | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |       > | 
					
						
							| 
									
										
										
										
											2019-10-04 11:06:17 -07:00
										 |  |  |         {renderAvatar({ contact, i18n, size: 52, direction })} | 
					
						
							| 
									
										
										
										
											2018-06-27 13:53:49 -07:00
										 |  |  |         <div className="module-embedded-contact__text-container"> | 
					
						
							|  |  |  |           {renderName({ contact, isIncoming, module })} | 
					
						
							|  |  |  |           {renderContactShorthand({ contact, isIncoming, module })} | 
					
						
							| 
									
										
										
										
											2018-05-07 17:51:29 -07:00
										 |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2019-11-07 13:36:16 -08:00
										 |  |  |       </button> | 
					
						
							| 
									
										
										
										
											2018-05-07 17:51:29 -07:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |