aboutsummaryrefslogtreecommitdiffstats
path: root/src/wwwroot/scripts/components.js
blob: 28d25f07ed9f9d080ee86c93146fb063e25ff220 (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
47
48
import {configuration} from "./configuration";
import {doc} from "./base";

export function getCounterControl(options = configuration.defaultParameters.counterControlOptions) {
	const wrapper = doc.createElement("div");
	wrapper.className = "number-input";

	const count = doc.createElement("input");
	count.inputMode = "numeric";
	count.type = "number";
	if (options.min !== undefined) {
		count.min = options.min;
	}
	if (options.max !== undefined) {
		count.max = options.max;
	}
	if (options.initialCount !== undefined) {
		count.value = options.initialCount;
	}
	if (options.onChange !== undefined && typeof options.onChange === "function") {
		count.addEventListener("change", (e) => {
			options.onChange(e);
		});
	}

	const minus = doc.createElement("button");
	minus.innerHTML = "-";
	minus.onclick = (e) => {
		count.stepDown();
		count.dispatchEvent(new Event("change"));
	};

	const plus = doc.createElement("button");
	plus.innerHTML = "+";
	plus.onclick = (e) => {
		count.stepUp();
		count.dispatchEvent(new Event("change"));
	};

	wrapper.appendChild(minus);
	wrapper.appendChild(count);
	wrapper.appendChild(plus);
	return wrapper;
}

export function getSpinner() {
	return `<div class="spinner-border text-primary" role="status"><span class="visually-hidden">Laster...</span></div>`;
}