aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/html/util/modal.js
blob: a28b013d15a007ccfad9a81a64ad9face2cf50b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Epic Games, Inc. All Rights Reserved.

"use strict";

import { Component } from "./component.js"

////////////////////////////////////////////////////////////////////////////////
export class Modal
{
	constructor()
	{
		const body = new Component(document.body);
		this._root = body.tag().classify("zen_modal");

		const bg = this._root.tag().classify("zen_modal_bg");
		bg.on("click", () => this._root.destroy());

		const rect = this._root.tag();
		this._title = rect.tag().classify("zen_modal_title");
		this._content = rect.tag().classify("zen_modal_message");
		this._buttons = rect.tag().classify("zen_modal_buttons");
	}

	title(value)
	{
		this._title.text(value);
		return this;
	}

	message(value)
	{
		this._content.text(value);
		return this;
	}

	option(name, func, ...args)
	{
		const thunk = () => {
			this._root.destroy();
			if (func)
				func(...args);
		};
		this._buttons.tag().text(name).on("click", thunk);
		return this;
	}
}