forked from MapComplete/MapComplete
		
	Butchering the UI framework
This commit is contained in:
		
							parent
							
								
									8d404b1ba9
								
							
						
					
					
						commit
						6415e195d1
					
				
					 90 changed files with 1012 additions and 3101 deletions
				
			
		|  | @ -1,39 +1,41 @@ | |||
| import {UIElement} from "../UIElement"; | ||||
| import Translations from "../i18n/Translations"; | ||||
| import {UIEventSource} from "../../Logic/UIEventSource"; | ||||
| import Combine from "./Combine"; | ||||
| 
 | ||||
| export class TabbedComponent extends UIElement { | ||||
| 
 | ||||
|     private headers: UIElement[] = []; | ||||
|     private readonly header: UIElement; | ||||
|     private content: UIElement[] = []; | ||||
| 
 | ||||
|     constructor(elements: { header: UIElement | string, content: UIElement | string }[], openedTab: (UIEventSource<number> | number) = 0) { | ||||
|         super(typeof (openedTab) === "number" ? new UIEventSource(openedTab) : (openedTab ?? new UIEventSource<number>(0))); | ||||
|         const self = this; | ||||
|         const tabs: UIElement[] = [] | ||||
| 
 | ||||
|         for (let i = 0; i < elements.length; i++) { | ||||
|             let element = elements[i]; | ||||
|             this.headers.push(Translations.W(element.header).onClick(() => self._source.setData(i))); | ||||
|             const header = Translations.W(element.header).onClick(() => self._source.setData(i)) | ||||
|             const content = Translations.W(element.content) | ||||
|             this.content.push(content); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     InnerRender(): string { | ||||
|         let headerBar = ""; | ||||
|         for (let i = 0; i < this.headers.length; i++) { | ||||
|             let header = this.headers[i]; | ||||
| 
 | ||||
|             if (!this.content[i].IsEmpty()) { | ||||
|                 headerBar += `<div class=\'tab-single-header ${i == this._source.data ? 'tab-active' : 'tab-non-active'}\'>` + | ||||
|                     header.Render() + "</div>" | ||||
|                 const tab = header.SetClass("block tab-single-header") | ||||
|                 tabs.push(tab) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         this.header = new Combine(tabs).SetClass("block tabs-header-bar") | ||||
| 
 | ||||
|         headerBar = "<div class='tabs-header-bar'>" + headerBar + "</div>" | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     InnerRender(): UIElement { | ||||
| 
 | ||||
|         const content = this.content[this._source.data]; | ||||
|         return headerBar + "<div class='tab-content'>" + (content?.Render() ?? "") + "</div>"; | ||||
|         return new Combine([ | ||||
|             this.header, | ||||
|             content.SetClass("tab-content"), | ||||
|         ]) | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue