mapcomplete/UI/Image/SlideShow.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-03-29 17:21:20 +02:00
import { Store } from "../../Logic/UIEventSource"
2021-06-11 22:51:45 +02:00
import BaseUIElement from "../BaseUIElement"
2021-06-17 13:17:16 +02:00
import { Utils } from "../../Utils"
import Combine from "../Base/Combine"
2020-06-24 00:35:19 +02:00
2021-06-11 22:51:45 +02:00
export class SlideShow extends BaseUIElement {
private readonly embeddedElements: Store<BaseUIElement[]>
2021-06-14 19:21:33 +02:00
constructor(embeddedElements: Store<BaseUIElement[]>) {
2021-06-11 22:51:45 +02:00
super()
this.embeddedElements = embeddedElements
this.SetStyle("scroll-snap-type: x mandatory; overflow-x: auto")
}
2021-06-14 19:21:33 +02:00
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.minWidth = "min-content"
el.style.display = "flex"
el.style.justifyContent = "center"
2021-06-14 19:21:33 +02:00
this.embeddedElements.addCallbackAndRun((elements) => {
if (elements.length > 1) {
el.style.justifyContent = "unset"
}
2021-06-15 16:18:58 +02:00
while (el.firstChild) {
el.removeChild(el.lastChild)
}
elements = Utils.NoNull(elements).map((el) =>
new Combine([el])
2021-06-17 13:17:16 +02:00
.SetClass("block relative ml-1 bg-gray-200 m-1 rounded slideshow-item")
.SetStyle(
"min-width: 150px; width: max-content; height: var(--image-carousel-height);max-height: var(--image-carousel-height);scroll-snap-align: start;"
)
2021-06-17 13:17:16 +02:00
)
2021-06-11 22:51:45 +02:00
for (const element of elements ?? []) {
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
}
}