| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2018 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { EmbeddedContactType } from '../../types/EmbeddedContact'; | 
					
						
							| 
									
										
										
										
											2018-05-02 19:43:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { LocalizerType } from '../../types/Util'; | 
					
						
							| 
									
										
										
										
											2019-01-14 13:49:58 -08:00
										 |  |  | import { | 
					
						
							|  |  |  |   renderAvatar, | 
					
						
							|  |  |  |   renderContactShorthand, | 
					
						
							|  |  |  |   renderName, | 
					
						
							| 
									
										
										
										
											2021-12-01 17:37:37 -06:00
										 |  |  | } from './contactUtil'; | 
					
						
							| 
									
										
										
										
											2018-05-22 12:31:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | export type Props = { | 
					
						
							| 
									
										
										
										
											2021-08-19 18:56:39 -07:00
										 |  |  |   contact: EmbeddedContactType; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-05-02 19:43:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function EmbeddedContact(props: Props): JSX.Element { | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   const { | 
					
						
							|  |  |  |     contact, | 
					
						
							|  |  |  |     i18n, | 
					
						
							|  |  |  |     isIncoming, | 
					
						
							|  |  |  |     onClick, | 
					
						
							|  |  |  |     tabIndex, | 
					
						
							|  |  |  |     withContentAbove, | 
					
						
							|  |  |  |     withContentBelow, | 
					
						
							|  |  |  |   } = props; | 
					
						
							|  |  |  |   const module = 'embedded-contact'; | 
					
						
							|  |  |  |   const direction = isIncoming ? 'incoming' : 'outgoing'; | 
					
						
							| 
									
										
										
										
											2018-05-07 17:51:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <button | 
					
						
							|  |  |  |       type="button" | 
					
						
							|  |  |  |       className={classNames( | 
					
						
							|  |  |  |         'module-embedded-contact', | 
					
						
							|  |  |  |         `module-embedded-contact--${direction}`, | 
					
						
							|  |  |  |         withContentAbove ? 'module-embedded-contact--with-content-above' : null, | 
					
						
							|  |  |  |         withContentBelow ? 'module-embedded-contact--with-content-below' : null | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |       onKeyDown={(event: React.KeyboardEvent) => { | 
					
						
							|  |  |  |         if (event.key !== 'Enter' && event.key !== 'Space') { | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-11-14 18:12:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |         if (onClick) { | 
					
						
							|  |  |  |           event.stopPropagation(); | 
					
						
							|  |  |  |           event.preventDefault(); | 
					
						
							| 
									
										
										
										
											2019-11-14 18:12:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |           onClick(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |       onClick={(event: React.MouseEvent) => { | 
					
						
							|  |  |  |         if (onClick) { | 
					
						
							|  |  |  |           event.stopPropagation(); | 
					
						
							|  |  |  |           event.preventDefault(); | 
					
						
							| 
									
										
										
										
											2019-11-07 13:36:16 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |           onClick(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |       tabIndex={tabIndex} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       {renderAvatar({ contact, i18n, size: 52, direction })} | 
					
						
							|  |  |  |       <div className="module-embedded-contact__text-container"> | 
					
						
							|  |  |  |         {renderName({ contact, isIncoming, module })} | 
					
						
							|  |  |  |         {renderContactShorthand({ contact, isIncoming, module })} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </button> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } |