@zywave/zui-slider 4.3.2 → 4.3.3-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/custom-elements.json +4 -4
- package/dist/zui-slider.d.ts +0 -4
- package/dist/zui-slider.js +12 -12
- package/dist/zui-slider.js.map +1 -1
- package/package.json +2 -2
- package/src/zui-slider.ts +12 -12
|
@@ -119,12 +119,12 @@
|
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
121
|
"kind": "method",
|
|
122
|
-
"name": "
|
|
122
|
+
"name": "#renderText",
|
|
123
123
|
"privacy": "private"
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"kind": "method",
|
|
127
|
-
"name": "
|
|
127
|
+
"name": "#onInput",
|
|
128
128
|
"privacy": "private",
|
|
129
129
|
"parameters": [
|
|
130
130
|
{
|
|
@@ -137,12 +137,12 @@
|
|
|
137
137
|
},
|
|
138
138
|
{
|
|
139
139
|
"kind": "method",
|
|
140
|
-
"name": "
|
|
140
|
+
"name": "#onChange",
|
|
141
141
|
"privacy": "private"
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
144
|
"kind": "method",
|
|
145
|
-
"name": "
|
|
145
|
+
"name": "#ensureValidValue",
|
|
146
146
|
"privacy": "private",
|
|
147
147
|
"parameters": [
|
|
148
148
|
{
|
package/dist/zui-slider.d.ts
CHANGED
|
@@ -49,10 +49,6 @@ export declare class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
49
49
|
static get styles(): (import("lit").CSSResult | import("lit").CSSResultArray)[];
|
|
50
50
|
connectedCallback(): void;
|
|
51
51
|
render(): import("lit-html").TemplateResult<1>;
|
|
52
|
-
private _renderText;
|
|
53
|
-
private _onInput;
|
|
54
|
-
private _onChange;
|
|
55
|
-
private _ensureValidValue;
|
|
56
52
|
}
|
|
57
53
|
declare global {
|
|
58
54
|
interface HTMLElementTagNameMap {
|
package/dist/zui-slider.js
CHANGED
|
@@ -70,7 +70,7 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
70
70
|
}
|
|
71
71
|
set value(val) {
|
|
72
72
|
const oldVal = this.#value;
|
|
73
|
-
val = this
|
|
73
|
+
val = this.#ensureValidValue(val);
|
|
74
74
|
this.#value = val;
|
|
75
75
|
this._setFormValue(this.#value);
|
|
76
76
|
this.requestUpdate('value', oldVal);
|
|
@@ -90,7 +90,7 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
90
90
|
let value = this.getAttribute('value') ?? this.value;
|
|
91
91
|
const max = this.getAttribute('max') ?? this.max;
|
|
92
92
|
const min = this.getAttribute('min') ?? this.min;
|
|
93
|
-
value = this
|
|
93
|
+
value = this.#ensureValidValue(value, min, max);
|
|
94
94
|
this.#defaultValue = value;
|
|
95
95
|
this._setFormValue(value.toString());
|
|
96
96
|
}
|
|
@@ -103,15 +103,15 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
103
103
|
style=${styleMap(styles)}
|
|
104
104
|
type="range"
|
|
105
105
|
.value="${this.value}"
|
|
106
|
-
.min="${this.min}"
|
|
107
|
-
.max="${this.max}"
|
|
108
|
-
.step="${this.step}"
|
|
106
|
+
.min="${String(this.min)}"
|
|
107
|
+
.max="${String(this.max)}"
|
|
108
|
+
.step="${String(this.step)}"
|
|
109
109
|
?disabled="${this.disabled}"
|
|
110
|
-
@input="${this
|
|
111
|
-
@change="${this
|
|
112
|
-
/>${this
|
|
110
|
+
@input="${this.#onInput}"
|
|
111
|
+
@change="${this.#onChange}"
|
|
112
|
+
/>${this.#renderText()}`;
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
#renderText() {
|
|
115
115
|
if (this.noText) {
|
|
116
116
|
return html ``;
|
|
117
117
|
}
|
|
@@ -121,13 +121,13 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
121
121
|
};
|
|
122
122
|
return html `<span style=${styleMap(styles)}>${this.value}</span>`;
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
#onInput(e) {
|
|
125
125
|
this.value = e.target.value;
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
#onChange() {
|
|
128
128
|
this.dispatchEvent(new CustomEvent('change', { detail: this.value, bubbles: true }));
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
#ensureValidValue(value, min, max) {
|
|
131
131
|
if (value === '') {
|
|
132
132
|
return value;
|
|
133
133
|
}
|
package/dist/zui-slider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zui-slider.js","sourceRoot":"","sources":["../src/zui-slider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,SAAU,SAAQ,wBAAwB;IAAvD;;QAaE,kBAAa,GAAG,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC;QAErC,WAAM,GAAG,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC;QAmB9B;;WAEG;QACyB,QAAG,GAAG,CAAC,CAAC;QAEpC;;WAEG;QAC2C,QAAG,GAAG,GAAG,CAAC;QAExD;;WAEG;QACyB,SAAI,GAAG,CAAC,CAAC;QAErC;;WAEG;QACgD,WAAM,GAAG,KAAK,CAAC;IAsFpE,CAAC;IAzIC,IAAc,qBAAqB;QACjC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAc,UAAU;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAES,iBAAiB;QACzB,IAAI,CAAC,KAAK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AS,EAAE,SAAS,EAAE,CAAC;yCAAgB;AAwFpE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { ZuiFormAssociatedElement } from '@zywave/zui-base';\nimport { html } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { style } from './zui-slider-css.js';\n\nconst DEFAULT_MAX = 100;\n\n/**\n * A range form control for choosing values along a slider.\n * @element zui-slider\n *\n * @attr {string | null} [name=null] - The name of this element that is associated with form submission\n * @attr {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @attr {boolean} [readonly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @attr {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @attr {number} [value=50] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n *\n * @prop {string | null} [name=null] - The name of this element that is associated with form submission\n * @prop {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @prop {boolean} [readOnly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @prop {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @prop {number} [valueAsNumber=50] - Returns the value of the element, interpreted as one of the following, in order: A number, NaN if conversion is impossible\n * @prop {string} [value='50'] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n * @prop {number} [progress=50] - Determines visual placement of the slider thumb along the line\n *\n * @cssprop [--zui-slider-thumb-size=1.875rem (30px)] - Point of contact to grab and slide to change value\n *\n * @event {CustomEvent} change - Fires when value changes, details contain `value`\n */\nexport class ZuiSlider extends ZuiFormAssociatedElement {\n protected get _focusControlSelector() {\n return 'input';\n }\n\n protected get _formValue() {\n return this.value;\n }\n\n protected formResetCallback() {\n this.value = this.#defaultValue;\n }\n\n #defaultValue = `${DEFAULT_MAX / 2}`;\n\n #value = `${DEFAULT_MAX / 2}`;\n\n @property()\n get value() {\n return this.#value;\n }\n\n set value(val) {\n const oldVal = this.#value;\n val = this._ensureValidValue(val);\n this.#value = val;\n this._setFormValue(this.#value);\n this.requestUpdate('value', oldVal);\n }\n\n get valueAsNumber() {\n return parseFloat(this.#value);\n }\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number }) min = 0;\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number, attribute: 'max' }) max = 100;\n\n /**\n * Represents the stepping interval, used both for user interface and validation purposes\n */\n @property({ type: Number }) step = 0;\n\n /**\n * Represents that this control must be filled in for form submission\n */\n @property({ type: Boolean, attribute: 'no-text' }) noText = false;\n\n get progress() {\n return ((this.valueAsNumber - this.min) / (this.max - this.min)) * 100;\n }\n\n static get styles() {\n return [super.styles, style];\n }\n\n connectedCallback() {\n super.connectedCallback();\n\n // we want to go a little faster than LitElement and behave more like native HTML Form Associated Elements\n let value = this.getAttribute('value') ?? this.value;\n const max = this.getAttribute('max') ?? this.max;\n const min = this.getAttribute('min') ?? this.min;\n\n value = this._ensureValidValue(value, min, max);\n\n this.#defaultValue = value;\n this._setFormValue(value.toString());\n }\n\n render() {\n const progressColor = this.disabled ? 'var(--zui-gray)' : 'var(--zui-blue)';\n const styles = {\n background: `linear-gradient(to right, ${progressColor} 0%, ${progressColor} ${this.progress}%, var(--zui-gray-200) ${this.progress}%, var(--zui-gray-200) 100%)`,\n };\n return html`<input\n style=${styleMap(styles)}\n type=\"range\"\n .value=\"${this.value}\"\n .min=\"${this.min}\"\n .max=\"${this.max}\"\n .step=\"${this.step}\"\n ?disabled=\"${this.disabled}\"\n @input=\"${this._onInput}\"\n @change=\"${this._onChange}\"\n />${this._renderText()}`;\n }\n\n private _renderText() {\n if (this.noText) {\n return html``;\n }\n const thumbOffset = `var(--zui-slider-thumb-size) * ${this.progress / 100}`;\n const styles = {\n left: `calc(${this.progress}% - ${thumbOffset} + 0.125rem)`,\n };\n return html`<span style=${styleMap(styles)}>${this.value}</span>`;\n }\n\n private _onInput(e: Event) {\n this.value = (e.target as HTMLInputElement).value;\n }\n\n private _onChange() {\n this.dispatchEvent(new CustomEvent('change', { detail: this.value, bubbles: true }));\n }\n\n private _ensureValidValue(value: string | number, min?: number | string | null, max?: number | string | null) {\n if (value === '') {\n return value;\n }\n min = min ?? this.min;\n max = max ?? this.max;\n\n if (typeof value === 'string') {\n value = parseFloat(value);\n }\n if (typeof min === 'string') {\n min = parseFloat(min);\n }\n if (typeof max === 'string') {\n max = parseFloat(max);\n }\n\n if (value < min) {\n value = min;\n } else if (value > max) {\n value = max;\n }\n\n return value.toString();\n }\n}\n\nwindow.customElements.define('zui-slider', ZuiSlider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'zui-slider': ZuiSlider;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"zui-slider.js","sourceRoot":"","sources":["../src/zui-slider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,SAAU,SAAQ,wBAAwB;IAAvD;;QAaE,kBAAa,GAAG,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC;QAErC,WAAM,GAAG,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC;QAmB9B;;WAEG;QACyB,QAAG,GAAG,CAAC,CAAC;QAEpC;;WAEG;QAC2C,QAAG,GAAG,GAAG,CAAC;QAExD;;WAEG;QACyB,SAAI,GAAG,CAAC,CAAC;QAErC;;WAEG;QACgD,WAAM,GAAG,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;sCAAS;AAKU;IAA7C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;sCAAW;AAK5B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAAU;AAKc;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;yCAAgB;AAwFpE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { ZuiFormAssociatedElement } from '@zywave/zui-base';\nimport { html } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { style } from './zui-slider-css.js';\n\nconst DEFAULT_MAX = 100;\n\n/**\n * A range form control for choosing values along a slider.\n * @element zui-slider\n *\n * @attr {string | null} [name=null] - The name of this element that is associated with form submission\n * @attr {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @attr {boolean} [readonly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @attr {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @attr {number} [value=50] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n *\n * @prop {string | null} [name=null] - The name of this element that is associated with form submission\n * @prop {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @prop {boolean} [readOnly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @prop {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @prop {number} [valueAsNumber=50] - Returns the value of the element, interpreted as one of the following, in order: A number, NaN if conversion is impossible\n * @prop {string} [value='50'] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n * @prop {number} [progress=50] - Determines visual placement of the slider thumb along the line\n *\n * @cssprop [--zui-slider-thumb-size=1.875rem (30px)] - Point of contact to grab and slide to change value\n *\n * @event {CustomEvent} change - Fires when value changes, details contain `value`\n */\nexport class ZuiSlider extends ZuiFormAssociatedElement {\n protected get _focusControlSelector() {\n return 'input';\n }\n\n protected get _formValue() {\n return this.value;\n }\n\n protected formResetCallback() {\n this.value = this.#defaultValue;\n }\n\n #defaultValue = `${DEFAULT_MAX / 2}`;\n\n #value = `${DEFAULT_MAX / 2}`;\n\n @property()\n get value() {\n return this.#value;\n }\n\n set value(val) {\n const oldVal = this.#value;\n val = this.#ensureValidValue(val);\n this.#value = val;\n this._setFormValue(this.#value);\n this.requestUpdate('value', oldVal);\n }\n\n get valueAsNumber() {\n return parseFloat(this.#value);\n }\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number }) min = 0;\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number, attribute: 'max' }) max = 100;\n\n /**\n * Represents the stepping interval, used both for user interface and validation purposes\n */\n @property({ type: Number }) step = 0;\n\n /**\n * Represents that this control must be filled in for form submission\n */\n @property({ type: Boolean, attribute: 'no-text' }) noText = false;\n\n get progress() {\n return ((this.valueAsNumber - this.min) / (this.max - this.min)) * 100;\n }\n\n static get styles() {\n return [super.styles, style];\n }\n\n connectedCallback() {\n super.connectedCallback();\n\n // we want to go a little faster than LitElement and behave more like native HTML Form Associated Elements\n let value = this.getAttribute('value') ?? this.value;\n const max = this.getAttribute('max') ?? this.max;\n const min = this.getAttribute('min') ?? this.min;\n\n value = this.#ensureValidValue(value, min, max);\n\n this.#defaultValue = value;\n this._setFormValue(value.toString());\n }\n\n render() {\n const progressColor = this.disabled ? 'var(--zui-gray)' : 'var(--zui-blue)';\n const styles = {\n background: `linear-gradient(to right, ${progressColor} 0%, ${progressColor} ${this.progress}%, var(--zui-gray-200) ${this.progress}%, var(--zui-gray-200) 100%)`,\n };\n return html`<input\n style=${styleMap(styles)}\n type=\"range\"\n .value=\"${this.value}\"\n .min=\"${String(this.min)}\"\n .max=\"${String(this.max)}\"\n .step=\"${String(this.step)}\"\n ?disabled=\"${this.disabled}\"\n @input=\"${this.#onInput}\"\n @change=\"${this.#onChange}\"\n />${this.#renderText()}`;\n }\n\n #renderText() {\n if (this.noText) {\n return html``;\n }\n const thumbOffset = `var(--zui-slider-thumb-size) * ${this.progress / 100}`;\n const styles = {\n left: `calc(${this.progress}% - ${thumbOffset} + 0.125rem)`,\n };\n return html`<span style=${styleMap(styles)}>${this.value}</span>`;\n }\n\n #onInput(e: Event) {\n this.value = (e.target as HTMLInputElement).value;\n }\n\n #onChange() {\n this.dispatchEvent(new CustomEvent('change', { detail: this.value, bubbles: true }));\n }\n\n #ensureValidValue(value: string | number, min?: number | string | null, max?: number | string | null) {\n if (value === '') {\n return value;\n }\n min = min ?? this.min;\n max = max ?? this.max;\n\n if (typeof value === 'string') {\n value = parseFloat(value);\n }\n if (typeof min === 'string') {\n min = parseFloat(min);\n }\n if (typeof max === 'string') {\n max = parseFloat(max);\n }\n\n if (value < min) {\n value = min;\n } else if (value > max) {\n value = max;\n }\n\n return value.toString();\n }\n}\n\nwindow.customElements.define('zui-slider', ZuiSlider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'zui-slider': ZuiSlider;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zywave/zui-slider",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3-pre.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@zywave/zui-base": "^4.6.1"
|
|
25
25
|
},
|
|
26
26
|
"customElements": "dist/custom-elements.json",
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "8130717d40462a72e3d695ce04263b6b8d874cb2"
|
|
28
28
|
}
|
package/src/zui-slider.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
52
52
|
|
|
53
53
|
set value(val) {
|
|
54
54
|
const oldVal = this.#value;
|
|
55
|
-
val = this
|
|
55
|
+
val = this.#ensureValidValue(val);
|
|
56
56
|
this.#value = val;
|
|
57
57
|
this._setFormValue(this.#value);
|
|
58
58
|
this.requestUpdate('value', oldVal);
|
|
@@ -98,7 +98,7 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
98
98
|
const max = this.getAttribute('max') ?? this.max;
|
|
99
99
|
const min = this.getAttribute('min') ?? this.min;
|
|
100
100
|
|
|
101
|
-
value = this
|
|
101
|
+
value = this.#ensureValidValue(value, min, max);
|
|
102
102
|
|
|
103
103
|
this.#defaultValue = value;
|
|
104
104
|
this._setFormValue(value.toString());
|
|
@@ -113,16 +113,16 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
113
113
|
style=${styleMap(styles)}
|
|
114
114
|
type="range"
|
|
115
115
|
.value="${this.value}"
|
|
116
|
-
.min="${this.min}"
|
|
117
|
-
.max="${this.max}"
|
|
118
|
-
.step="${this.step}"
|
|
116
|
+
.min="${String(this.min)}"
|
|
117
|
+
.max="${String(this.max)}"
|
|
118
|
+
.step="${String(this.step)}"
|
|
119
119
|
?disabled="${this.disabled}"
|
|
120
|
-
@input="${this
|
|
121
|
-
@change="${this
|
|
122
|
-
/>${this
|
|
120
|
+
@input="${this.#onInput}"
|
|
121
|
+
@change="${this.#onChange}"
|
|
122
|
+
/>${this.#renderText()}`;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
#renderText() {
|
|
126
126
|
if (this.noText) {
|
|
127
127
|
return html``;
|
|
128
128
|
}
|
|
@@ -133,15 +133,15 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
133
133
|
return html`<span style=${styleMap(styles)}>${this.value}</span>`;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
#onInput(e: Event) {
|
|
137
137
|
this.value = (e.target as HTMLInputElement).value;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
#onChange() {
|
|
141
141
|
this.dispatchEvent(new CustomEvent('change', { detail: this.value, bubbles: true }));
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
#ensureValidValue(value: string | number, min?: number | string | null, max?: number | string | null) {
|
|
145
145
|
if (value === '') {
|
|
146
146
|
return value;
|
|
147
147
|
}
|