| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  | import { | 
					
						
							|  |  |  |   customElement, | 
					
						
							|  |  |  |   DeesElement, | 
					
						
							|  |  |  |   type TemplateResult, | 
					
						
							|  |  |  |   state, | 
					
						
							|  |  |  |   html, | 
					
						
							|  |  |  |   domtools, | 
					
						
							|  |  |  |   property, | 
					
						
							|  |  |  |   css, | 
					
						
							|  |  |  |   cssManager, | 
					
						
							|  |  |  | } from '@design.estate/dees-element'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { demoFunc } = await import('./dees-input-multitoggle.demo.js'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @customElement('dees-input-multitoggle') | 
					
						
							|  |  |  | export class DeesInputMultitoggle extends DeesElement { | 
					
						
							|  |  |  |   public static demo = demoFunc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |   @property({ | 
					
						
							|  |  |  |     type: String, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   public label: string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-21 01:45:35 +01:00
										 |  |  |   @property({ | 
					
						
							|  |  |  |     type: String, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   public description: string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |   @property() | 
					
						
							|  |  |  |   type: 'boolean' | 'multi' | 'single' = 'multi'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property() | 
					
						
							|  |  |  |   booleanTrueName: string = 'true'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property() | 
					
						
							|  |  |  |   booleanFalseName: string = 'false'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property({ | 
					
						
							|  |  |  |     type: Array, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   options: string[] = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property() | 
					
						
							|  |  |  |   selectedOption: string = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property() | 
					
						
							|  |  |  |   boolValue: boolean = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public static styles = [ | 
					
						
							|  |  |  |     cssManager.defaultStyles, | 
					
						
							|  |  |  |     css`
 | 
					
						
							|  |  |  |       :host { | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         display: block; | 
					
						
							|  |  |  |         color: ${cssManager.bdTheme('#333', '#ccc')}; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         user-select: none; | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         margin: 8px 0px 24px 0px; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       .label { | 
					
						
							|  |  |  |         font-size: 14px; | 
					
						
							|  |  |  |         margin-bottom: 8px; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |       .selections { | 
					
						
							|  |  |  |         position: relative; | 
					
						
							|  |  |  |         display: flex; | 
					
						
							|  |  |  |         flex-direction: row; | 
					
						
							|  |  |  |         flex-wrap: nowrap; | 
					
						
							| 
									
										
										
										
											2024-01-21 01:12:57 +01:00
										 |  |  |         background: ${cssManager.bdTheme('#fff', '#222')}; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         width: min-content; | 
					
						
							|  |  |  |         border-radius: 20px; | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         height: 32px; | 
					
						
							|  |  |  |         border-top: 1px solid #ffffff10; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       .option { | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         color: #ccc; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         position: relative; | 
					
						
							|  |  |  |         padding: 0px 16px; | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         line-height: 32px; | 
					
						
							| 
									
										
										
										
											2024-01-11 21:14:30 +01:00
										 |  |  |         cursor: default; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         width: min-content; /* Make the width as per the content */ | 
					
						
							|  |  |  |         white-space: nowrap; /* Prevent text wrapping */ | 
					
						
							| 
									
										
										
										
											2024-01-11 21:14:30 +01:00
										 |  |  |         transition: all 0.1s; | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         font-size: 14px; | 
					
						
							|  |  |  |         transform: translateY(-1px); | 
					
						
							| 
									
										
										
										
											2024-01-11 21:14:30 +01:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       .option:hover { | 
					
						
							|  |  |  |         color: #fff; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |       .option.selected { | 
					
						
							|  |  |  |         color: #fff; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |       .indicator { | 
					
						
							|  |  |  |         opacity: 0; | 
					
						
							|  |  |  |         position: absolute; | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         height: 24px; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         left: 4px; | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |         top: 3px; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         border-radius: 16px; | 
					
						
							|  |  |  |         background: #0050b9; | 
					
						
							|  |  |  |         min-width: 36px; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public render(): TemplateResult { | 
					
						
							|  |  |  |     return html`
 | 
					
						
							| 
									
										
										
										
											2024-01-21 01:45:35 +01:00
										 |  |  |       <dees-label .label=${this.label} .description=${this.description}></dees-label> | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |       <div class="mainbox"> | 
					
						
							|  |  |  |         <div class="selections"> | 
					
						
							|  |  |  |           <div class="indicator"></div> | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |           ${this.options.map( | 
					
						
							|  |  |  |             (option) => | 
					
						
							|  |  |  |               html`<div class="option ${option === this.selectedOption ? 'selected': ''}" @click=${() => this.handleSelection(option)}>
 | 
					
						
							|  |  |  |                 ${option} | 
					
						
							|  |  |  |               </div> `
 | 
					
						
							|  |  |  |           )} | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     `;
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public async firstUpdated() { | 
					
						
							|  |  |  |     if (this.type === 'boolean') { | 
					
						
							| 
									
										
										
										
											2024-01-15 12:57:49 +01:00
										 |  |  |       this.options = [this.booleanTrueName || 'true', this.booleanFalseName || 'false']; | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     this.setIndicator(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public async handleSelection(optionArg: string) { | 
					
						
							|  |  |  |     this.selectedOption = optionArg; | 
					
						
							|  |  |  |     this.setIndicator(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public async setIndicator() { | 
					
						
							|  |  |  |     const indicator: HTMLDivElement = this.shadowRoot.querySelector('.indicator'); | 
					
						
							| 
									
										
										
										
											2024-01-18 02:08:19 +01:00
										 |  |  |     const option: HTMLDivElement = this.shadowRoot.querySelector( | 
					
						
							|  |  |  |       `.option:nth-child(${this.options.indexOf(this.selectedOption) + 2})` | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2024-01-10 05:11:55 +01:00
										 |  |  |     if (indicator && option) { | 
					
						
							|  |  |  |       indicator.style.width = `${option.clientWidth - 8}px`; | 
					
						
							|  |  |  |       indicator.style.left = `${option.offsetLeft + 4}px`; | 
					
						
							|  |  |  |       indicator.style.opacity = '1'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     setTimeout(() => { | 
					
						
							|  |  |  |       indicator.style.transition = 'all 0.1s'; | 
					
						
							|  |  |  |     }, 100); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |