MapComplete/UI/Popup/TagRenderingAnswer.ts

43 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-10-27 01:01:34 +01:00
import {UIEventSource} from "../../Logic/UIEventSource";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import {Utils} from "../../Utils";
2021-02-05 16:32:37 +01:00
import {SubstitutedTranslation} from "../SubstitutedTranslation";
2021-06-11 22:51:45 +02:00
import BaseUIElement from "../BaseUIElement";
2021-06-14 02:39:23 +02:00
import {VariableUiElement} from "../Base/VariableUIElement";
import List from "../Base/List";
import {FixedUiElement} from "../Base/FixedUiElement";
2020-10-27 01:01:34 +01:00
/***
* Displays the correct value for a known tagrendering
*/
2021-06-14 02:39:23 +02:00
export default class TagRenderingAnswer extends VariableUiElement {
2020-10-27 01:01:34 +01:00
2021-06-14 02:39:23 +02:00
constructor(tagsSource: UIEventSource<any>, configuration: TagRenderingConfig, contentClasses: string = "", contentStyle: string = "") {
if (configuration === undefined) {
2020-11-17 02:22:48 +01:00
throw "Trying to generate a tagRenderingAnswer without configuration..."
}
2021-06-14 02:39:23 +02:00
super(tagsSource.map(tags => {
if(tags === undefined){
return undefined;
}
2021-06-14 02:39:23 +02:00
const trs = Utils.NoNull(configuration.GetRenderValues(tags));
if(trs.length === 0){
return undefined;
}
2021-06-14 02:39:23 +02:00
trs.forEach(tr => console.log("Rendering ", tr))
const valuesToRender: BaseUIElement[] = trs.map(tr => new SubstitutedTranslation(tr, tagsSource))
2021-06-14 02:39:23 +02:00
if(valuesToRender.length === 1){
return valuesToRender[0];
}else if(valuesToRender.length > 1){
return new List(valuesToRender)
}
return undefined;
}).map(innerComponent => innerComponent?.SetClass(contentClasses)?.SetStyle(contentStyle))
)
2021-06-14 02:39:23 +02:00
this.SetClass("flex items-center flex-row text-lg link-underline")
this.SetStyle("word-wrap: anywhere;");
2020-10-27 01:01:34 +01:00
}
}