| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { InputElement } from "./InputElement" | 
					
						
							|  |  |  | import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class SimpleDatePicker extends InputElement<string> { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false) | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     private readonly value: UIEventSource<string> | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private readonly _element: HTMLElement | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     constructor(value?: UIEventSource<string>) { | 
					
						
							|  |  |  |         super() | 
					
						
							|  |  |  |         this.value = value ?? new UIEventSource<string>(undefined) | 
					
						
							|  |  |  |         const self = this | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         const el = document.createElement("input") | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this._element = el | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         el.type = "date" | 
					
						
							|  |  |  |         el.oninput = () => { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             // Already in YYYY-MM-DD value!
 | 
					
						
							|  |  |  |             self.value.setData(el.value) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this.value.addCallbackAndRunD((v) => { | 
					
						
							|  |  |  |             el.value = v | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     GetValue(): UIEventSource<string> { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this.value | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IsValid(t: string): boolean { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return !isNaN(new Date(t).getTime()) | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |     protected InnerConstructElement(): HTMLElement { | 
					
						
							|  |  |  |         return this._element | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |