mapcomplete/UI/Base/ScrollableFullScreen.ts

70 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-01-08 02:13:44 +01:00
import {UIElement} from "../UIElement";
import Svg from "../../Svg";
import State from "../../State";
import Combine from "./Combine";
2021-01-08 16:49:42 +01:00
import Ornament from "./Ornament";
2021-01-08 02:13:44 +01:00
/**
* Wraps some contents into a panel that scrolls the content _under_ the title
*/
2021-01-09 00:03:21 +01:00
export default class ScrollableFullScreen extends UIElement {
2021-01-21 23:39:31 +01:00
private _component: UIElement;
2021-01-24 18:33:16 +01:00
private elementsToRestore: Set<HTMLElement> = new Set<HTMLElement>();
2021-01-08 02:13:44 +01:00
2021-01-22 00:40:15 +01:00
constructor(title: UIElement, content: UIElement, onClose: (() => void)) {
2021-01-08 02:13:44 +01:00
super();
2021-01-24 18:33:16 +01:00
this.dumbMode = false;
2021-01-08 02:13:44 +01:00
const returnToTheMap = Svg.back_svg().onClick(() => {
2021-01-24 18:33:16 +01:00
console.log("Clicked back!");
this.RestoreLeaflet();
if (onClose() !== undefined) {
console.error("WARNING: onClose is not defined")
onClose();
}
}).SetClass("block sm:hidden mb-2 bg-blue-50 rounded-full w-12 h-12 p-1.5")
title.SetClass("block w-full")
2021-01-22 00:40:15 +01:00
const ornament = new Combine([new Ornament().SetStyle("height:5em;")])
.SetClass("block sm:hidden h-5")
2021-01-09 00:03:21 +01:00
2021-01-24 18:33:16 +01:00
this._component =
new Combine([
new Combine([
2021-01-22 00:40:15 +01:00
new Combine([returnToTheMap, title])
2021-01-24 18:33:16 +01:00
.AddClass("border-b-2 border-black shadow sm:shadow-none bg-white p-2 pb-0 sm:p-0 flex overflow-x-hidden flex-shrink-0 max-h-20vh"),
new Combine(["<span>", content, "</span>", ornament])
2021-01-24 18:33:16 +01:00
.SetClass("block p-2 sm:pt-4 w-full h-screen landscape:h-screen sm:h-full sm:w-full overflow-y-auto overflow-x-hidden"),
2021-01-08 16:49:42 +01:00
// We add an ornament which takes around 5em. This is in order to make sure the Web UI doesn't hide
2021-01-24 18:33:16 +01:00
]).SetClass("block flex flex-col relative bg-white")
]).SetClass("fixed top-0 left-0 right-0 h-screen w-screen sm:max-h-65vh sm:w-auto");
2021-01-09 00:03:21 +01:00
2021-01-08 02:13:44 +01:00
}
2021-01-09 00:03:21 +01:00
2021-01-08 02:13:44 +01:00
InnerRender(): string {
return this._component.Render();
}
2021-01-24 18:33:16 +01:00
protected InnerUpdate(htmlElement: HTMLElement) {
do {
// A leaflet workaround: in order for fullscreen to work, we need to get the parent element which does a transform3d and remove/read the transform
if (htmlElement.style.transform !== "") {
this.elementsToRestore.add(htmlElement);
htmlElement.classList.add("no-transform")
}
htmlElement = htmlElement.parentElement;
} while (htmlElement != null)
super.InnerUpdate(htmlElement);
}
private RestoreLeaflet() {
this.elementsToRestore.forEach(
el => el.classList.remove("no-transform")
);
}
2021-01-08 02:13:44 +01:00
}