MapComplete/UI/Image/SlideShow.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-10-14 12:15:09 +02:00
import {UIEventSource} from "../../Logic/UIEventSource";
2021-06-11 22:51:45 +02:00
import BaseUIElement from "../BaseUIElement";
2020-06-24 00:35:19 +02:00
2021-06-11 22:51:45 +02:00
export class SlideShow extends BaseUIElement {
2020-06-24 00:35:19 +02:00
2021-06-14 19:21:33 +02:00
private readonly embeddedElements: UIEventSource<BaseUIElement[]>;
constructor(embeddedElements: UIEventSource<BaseUIElement[]>) {
2021-06-11 22:51:45 +02:00
super()
2021-06-14 19:21:33 +02:00
this.embeddedElements = embeddedElements;
}
protected InnerConstructElement(): HTMLElement {
2021-06-11 22:51:45 +02:00
const el = document.createElement("div")
2021-06-15 16:18:58 +02:00
el.style.overflowX = "auto"
el.style.width = "min-content"
el.style.minWidth = "min-content"
el.style.display = "flex"
2021-06-14 19:21:33 +02:00
this.embeddedElements.addCallbackAndRun(elements => {
2021-06-15 16:18:58 +02:00
while (el.firstChild) {
el.removeChild(el.lastChild)
}
2021-06-11 22:51:45 +02:00
for (const element of elements ?? []) {
2021-06-16 21:23:03 +02:00
element
.SetClass("block ml-1; bg-gray-200")
.SetStyle("min-width: 150; max-height: var(--image-carousel-height); min-height: var(--image-carousel-height)")
2021-06-15 16:18:58 +02:00
2021-06-14 19:21:33 +02:00
el.appendChild(element.ConstructElement())
2021-06-11 22:51:45 +02:00
}
});
2021-06-11 22:51:45 +02:00
2021-06-15 16:18:58 +02:00
const wrapper = document.createElement("div")
wrapper.style.maxWidth = "100%"
wrapper.style.overflowX = "auto"
wrapper.appendChild(el)
return wrapper;
}
}