From 9383a2fb09ffb60cfe63683106945bd688affa59 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 1 Jun 2022 21:13:43 +0200 Subject: feat: Initial commit after clean slate --- src/wwwroot/scripts/components.js | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/wwwroot/scripts/components.js (limited to 'src/wwwroot/scripts/components.js') diff --git a/src/wwwroot/scripts/components.js b/src/wwwroot/scripts/components.js new file mode 100644 index 0000000..28d25f0 --- /dev/null +++ b/src/wwwroot/scripts/components.js @@ -0,0 +1,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 `
Laster...
`; +} -- cgit v1.3