diff options
Diffstat (limited to '_www/functions.ts')
| -rw-r--r-- | _www/functions.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/_www/functions.ts b/_www/functions.ts new file mode 100644 index 0000000..3590864 --- /dev/null +++ b/_www/functions.ts @@ -0,0 +1,46 @@ +import { WuiInputNumber, WuiInputNumberOpts } from "./wui/input/number.js" +import { WuiInputString, WuiInputStringOpts } from "./wui/input/string.js" + +import { CLASS_INPUT, CLASS_INPUT_LABEL, FormInput, FormInputKindNumber, FormInputKindString } from "./interface.js" + +export function GenerateFormInput(parent: HTMLElement, fi: FormInput) { + switch (fi.kind) { + case FormInputKindNumber: + let wui_input_number_opts: WuiInputNumberOpts = { + label: fi.label, + hint: fi.hint, + value: +fi.value, + class_input: CLASS_INPUT, + class_label: CLASS_INPUT_LABEL, + is_hint_toggled: true, + onChangeHandler: (new_value: number) => { + fi.value = "" + new_value + }, + } + if (fi.max) { + wui_input_number_opts.max = fi.max + } + if (fi.min) { + wui_input_number_opts.min = fi.min + } + let wui_input_number = new WuiInputNumber(wui_input_number_opts) + parent.appendChild(wui_input_number.el) + break + + case FormInputKindString: + let wui_input_string_opts: WuiInputStringOpts = { + label: fi.label, + hint: fi.hint, + value: fi.value, + class_input: CLASS_INPUT, + class_label: CLASS_INPUT_LABEL, + is_hint_toggled: true, + onChangeHandler: (new_value: string) => { + fi.value = new_value + }, + } + let wui_input_string = new WuiInputString(wui_input_string_opts) + parent.appendChild(wui_input_string.el) + break + } +} |
