diff options
| author | Shulhan <ms@kilabit.info> | 2021-09-11 00:31:23 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-09-11 00:31:23 +0700 |
| commit | 42ebec89d615989a95019f7d1234a79e415bc207 (patch) | |
| tree | 006f18e8a4d1e6ffd7d6b6e690f27fa15f97e7df /input/number.ts | |
| parent | af17111480d41f4770c7129733817e0dfd2d4f7c (diff) | |
| download | pakakeh.ts-42ebec89d615989a95019f7d1234a79e415bc207.tar.xz | |
input: add options to add custom CSS class to label and input
The input options for string, number, and select now have two additional
options: "class_label" and "class_input".
The "class_label" option will add custom CSS class to the input label.
The "class_input" option will add custom CSS class to the input group.
Diffstat (limited to 'input/number.ts')
| -rw-r--r-- | input/number.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/input/number.ts b/input/number.ts index e2d1bc5..990d94a 100644 --- a/input/number.ts +++ b/input/number.ts @@ -5,6 +5,8 @@ export interface WuiInputNumberOpts { hint?: string max?: number min?: number + class_label?: string // Additional CSS class for label. + class_input?: string // Additional CSS class for input. is_disabled?: boolean onChangeHandler: (new_value: number) => void } @@ -24,11 +26,11 @@ const WUI_INPUT_NUMBER_CLASS_LABEL = "wui_input_number_label" // // <div [id=${id}] class="${WUI_INPUT_NUMBER_CLASS}"> // <div> -// <label class="${WUI_INPUT_NUMBER_CLASS_LABEL}"> +// <label class="${WUI_INPUT_NUMBER_CLASS_LABEL} [${class_label}]"> // ${label} | HTMLElement // </label> // <input -// class="${WUI_INPUT_NUMBER_CLASS_INPUT}" +// class="${WUI_INPUT_NUMBER_CLASS_INPUT} [${class_input}]" // [max=${max}] // [min=${min}] // [disabled=${is_disabled}] @@ -77,6 +79,10 @@ export class WuiInputNumber { private generateLabel(wrapper: HTMLElement) { this.el_label = document.createElement("label") this.el_label.classList.add(WUI_INPUT_NUMBER_CLASS_LABEL) + if (this.opts.class_label) { + this.el_label.classList.add(this.opts.class_label) + } + if (typeof this.opts.label === "string") { this.el_label.innerHTML = `${this.opts.label} ` } else { @@ -90,6 +96,10 @@ export class WuiInputNumber { "input", ) as HTMLInputElement this.el_input.classList.add(WUI_INPUT_NUMBER_CLASS_INPUT) + if (this.opts.class_input) { + this.el_input.classList.add(this.opts.class_input) + } + this.el_input.type = "number" this.el_input.value = "" + this.opts.value |
