| 
									
										
										
										
											2025-06-19 13:47:52 +00:00
										 |  |  | import { demoFunc } from './dees-form-submit.demo.js'; | 
					
						
							| 
									
										
										
										
											2021-08-25 17:34:15 +02:00
										 |  |  | import { | 
					
						
							|  |  |  |   customElement, | 
					
						
							|  |  |  |   html, | 
					
						
							|  |  |  |   DeesElement, | 
					
						
							|  |  |  |   css, | 
					
						
							|  |  |  |   cssManager, | 
					
						
							|  |  |  |   property, | 
					
						
							| 
									
										
										
										
											2023-08-07 19:13:29 +02:00
										 |  |  | } from '@design.estate/dees-element'; | 
					
						
							| 
									
										
										
										
											2025-06-19 14:01:07 +00:00
										 |  |  | import type { DeesForm } from './dees-form.js'; | 
					
						
							| 
									
										
										
										
											2020-09-13 16:24:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  | declare global { | 
					
						
							|  |  |  |   interface HTMLElementTagNameMap { | 
					
						
							|  |  |  |     'dees-form-submit': DeesFormSubmit; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:24:48 +00:00
										 |  |  | @customElement('dees-form-submit') | 
					
						
							| 
									
										
										
										
											2021-05-05 20:55:49 +00:00
										 |  |  | export class DeesFormSubmit extends DeesElement { | 
					
						
							| 
									
										
										
										
											2025-06-19 13:47:52 +00:00
										 |  |  |   public static demo = demoFunc; | 
					
						
							| 
									
										
										
										
											2021-08-25 13:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @property({ | 
					
						
							| 
									
										
										
										
											2021-08-25 17:34:15 +02:00
										 |  |  |     type: Boolean, | 
					
						
							| 
									
										
										
										
											2023-08-19 18:56:32 +02:00
										 |  |  |     reflect: true, | 
					
						
							| 
									
										
										
										
											2021-08-25 13:51:55 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  |   public disabled = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 16:09:52 +02:00
										 |  |  |   @property({ | 
					
						
							| 
									
										
										
										
											2021-08-25 17:34:15 +02:00
										 |  |  |     type: String, | 
					
						
							| 
									
										
										
										
											2021-08-25 16:09:52 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  |   public text: string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-27 13:38:08 +02:00
										 |  |  |   @property({ | 
					
						
							| 
									
										
										
										
											2023-04-12 02:47:45 +02:00
										 |  |  |     type: String, | 
					
						
							| 
									
										
										
										
											2021-08-27 13:38:08 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  |   public status: 'normal' | 'pending' | 'success' | 'error' = 'normal'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 20:55:49 +00:00
										 |  |  |   constructor() { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-19 12:42:50 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2021-05-05 20:55:49 +00:00
										 |  |  |   public static styles = [cssManager.defaultStyles, css``]; | 
					
						
							| 
									
										
										
										
											2020-09-13 16:24:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public render() { | 
					
						
							| 
									
										
										
										
											2021-08-25 17:34:15 +02:00
										 |  |  |     return html`
 | 
					
						
							| 
									
										
										
										
											2023-04-12 02:47:45 +02:00
										 |  |  |       <dees-button | 
					
						
							| 
									
										
										
										
											2025-06-19 12:42:50 +00:00
										 |  |  |         status="${this.status}" | 
					
						
							|  |  |  |         @click="${this.submit}" | 
					
						
							|  |  |  |         ?disabled="${this.disabled}" | 
					
						
							| 
									
										
										
										
											2023-04-12 02:47:45 +02:00
										 |  |  |       > | 
					
						
							| 
									
										
										
										
											2025-06-19 12:42:50 +00:00
										 |  |  |         ${this.text || html`<slot></slot>`} | 
					
						
							| 
									
										
										
										
											2021-08-25 17:34:15 +02:00
										 |  |  |       </dees-button> | 
					
						
							|  |  |  |     `;
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:24:48 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public async submit() { | 
					
						
							| 
									
										
										
										
											2021-08-25 17:34:15 +02:00
										 |  |  |     if (this.disabled) { | 
					
						
							| 
									
										
										
										
											2021-08-25 13:51:55 +02:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-09-07 09:02:25 +00:00
										 |  |  |     // Walk up the DOM tree to find the nearest dees-form element
 | 
					
						
							|  |  |  |     const parentFormElement = this.closest('dees-form') as DeesForm; | 
					
						
							|  |  |  |     if (parentFormElement && parentFormElement.gatherAndDispatch) { | 
					
						
							|  |  |  |       parentFormElement.gatherAndDispatch(); | 
					
						
							| 
									
										
										
										
											2025-06-19 13:47:52 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-13 16:24:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-04-12 02:47:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public async focus() { | 
					
						
							|  |  |  |     const domtools = await this.domtoolsPromise; | 
					
						
							|  |  |  |     if (!this.disabled) { | 
					
						
							| 
									
										
										
										
											2025-06-19 13:47:52 +00:00
										 |  |  |       await domtools.convenience.smartdelay.delayFor(0); | 
					
						
							| 
									
										
										
										
											2023-04-12 02:47:45 +02:00
										 |  |  |       this.submit(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-13 16:24:48 +00:00
										 |  |  | } |