| 
									
										
										
										
											2020-07-29 16:46:45 +02:00
										 |  |  | import {UIElement} from "../UIElement"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | import Combine from "./Combine"; | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  | import {FixedUiElement} from "./FixedUiElement"; | 
					
						
							| 
									
										
										
										
											2020-07-29 16:46:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | export class SubtleButton extends Combine { | 
					
						
							| 
									
										
										
										
											2020-07-29 16:46:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |     constructor(imageUrl: string | UIElement, message: string | UIElement, linkTo: { url: string, newTab?: boolean } = undefined) { | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         super(SubtleButton.generateContent(imageUrl, message, linkTo)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.SetClass("block flex p-3 my-2 bg-blue-100 rounded-lg hover:shadow-xl hover:bg-blue-200 link-no-underline") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private static generateContent(imageUrl: string | UIElement, messageT: string | UIElement, linkTo: { url: string, newTab?: boolean } = undefined): (UIElement | string)[] { | 
					
						
							|  |  |  |         const message = Translations.W(messageT); | 
					
						
							|  |  |  |         if (message !== null) { | 
					
						
							|  |  |  |             message.dumbMode = false; | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-01-18 19:36:19 +01:00
										 |  |  |         let img; | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |         if ((imageUrl ?? "") === "") { | 
					
						
							| 
									
										
										
										
											2021-01-18 19:36:19 +01:00
										 |  |  |             img = new FixedUiElement(""); | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |         } else if (typeof (imageUrl) === "string") { | 
					
						
							| 
									
										
										
										
											2021-01-18 19:36:19 +01:00
										 |  |  |             img = new FixedUiElement(`<img style="width: 100%;" src="${imageUrl}" alt="">`); | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-01-18 19:36:19 +01:00
										 |  |  |             img = imageUrl; | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-01-25 03:12:09 +01:00
										 |  |  |         img.SetClass("block flex items-center justify-center h-11 w-11 flex-shrink0") | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         const image = new Combine([img]) | 
					
						
							| 
									
										
										
										
											2021-01-25 03:12:09 +01:00
										 |  |  |             .SetClass("flex-shrink-0"); | 
					
						
							| 
									
										
										
										
											2020-07-29 16:46:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 21:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         if (message !== null && message.IsEmpty()) { | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |             // Message == null: special case to force empty text
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |             return []; | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-29 19:02:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         if (linkTo != undefined) { | 
					
						
							|  |  |  |             return [ | 
					
						
							|  |  |  |                 `<a class='flex group' href="${linkTo.url}" ${linkTo.newTab ? 'target="_blank"' : ""}>`, | 
					
						
							|  |  |  |                 image, | 
					
						
							|  |  |  |                 `<div class='ml-4 overflow-ellipsis'>`, | 
					
						
							|  |  |  |                 message, | 
					
						
							| 
									
										
										
										
											2021-01-17 21:14:48 +01:00
										 |  |  |                 `</div>`, | 
					
						
							|  |  |  |                 `</a>` | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |             ]; | 
					
						
							| 
									
										
										
										
											2020-07-29 19:02:36 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-01-17 21:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             image, | 
					
						
							|  |  |  |             message, | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 16:46:45 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |