@six-group/ui-library 0.0.0-insider.9277796 → 0.0.0-insider.a358260
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/cjs/six-checkbox.cjs.entry.js +57 -46
- package/dist/cjs/six-checkbox.cjs.entry.js.map +1 -1
- package/dist/cjs/six-input.cjs.entry.js +107 -81
- package/dist/cjs/six-input.cjs.entry.js.map +1 -1
- package/dist/cjs/six-radio.cjs.entry.js +56 -51
- package/dist/cjs/six-radio.cjs.entry.js.map +1 -1
- package/dist/cjs/six-range.cjs.entry.js +114 -75
- package/dist/cjs/six-range.cjs.entry.js.map +1 -1
- package/dist/cjs/six-select.cjs.entry.js +298 -239
- package/dist/cjs/six-select.cjs.entry.js.map +1 -1
- package/dist/cjs/six-textarea.cjs.entry.js +97 -74
- package/dist/cjs/six-textarea.cjs.entry.js.map +1 -1
- package/dist/cjs/slot-ad537f24.js.map +1 -1
- package/dist/collection/components/six-checkbox/six-checkbox.js +62 -49
- package/dist/collection/components/six-checkbox/six-checkbox.js.map +1 -1
- package/dist/collection/components/six-input/six-input.js +130 -117
- package/dist/collection/components/six-input/six-input.js.map +1 -1
- package/dist/collection/components/six-radio/six-radio.js +60 -53
- package/dist/collection/components/six-radio/six-radio.js.map +1 -1
- package/dist/collection/components/six-range/six-range.js +121 -76
- package/dist/collection/components/six-range/six-range.js.map +1 -1
- package/dist/collection/components/six-select/six-select.js +248 -240
- package/dist/collection/components/six-select/six-select.js.map +1 -1
- package/dist/collection/components/six-select/util.js +52 -0
- package/dist/collection/components/six-select/util.js.map +1 -0
- package/dist/collection/components/six-textarea/six-textarea.js +115 -105
- package/dist/collection/components/six-textarea/six-textarea.js.map +1 -1
- package/dist/collection/utils/slot.js.map +1 -1
- package/dist/components/six-checkbox.js +57 -46
- package/dist/components/six-checkbox.js.map +1 -1
- package/dist/components/six-input2.js +107 -81
- package/dist/components/six-input2.js.map +1 -1
- package/dist/components/six-radio.js +56 -51
- package/dist/components/six-radio.js.map +1 -1
- package/dist/components/six-range.js +114 -75
- package/dist/components/six-range.js.map +1 -1
- package/dist/components/six-select.js +299 -240
- package/dist/components/six-select.js.map +1 -1
- package/dist/components/six-textarea.js +97 -74
- package/dist/components/six-textarea.js.map +1 -1
- package/dist/components/slot.js.map +1 -1
- package/dist/components.json +51 -41
- package/dist/esm/six-checkbox.entry.js +57 -46
- package/dist/esm/six-checkbox.entry.js.map +1 -1
- package/dist/esm/six-input.entry.js +107 -81
- package/dist/esm/six-input.entry.js.map +1 -1
- package/dist/esm/six-radio.entry.js +56 -51
- package/dist/esm/six-radio.entry.js.map +1 -1
- package/dist/esm/six-range.entry.js +114 -75
- package/dist/esm/six-range.entry.js.map +1 -1
- package/dist/esm/six-select.entry.js +299 -240
- package/dist/esm/six-select.entry.js.map +1 -1
- package/dist/esm/six-textarea.entry.js +97 -74
- package/dist/esm/six-textarea.entry.js.map +1 -1
- package/dist/esm/slot-6f3984c7.js.map +1 -1
- package/dist/types/components/six-checkbox/six-checkbox.d.ts +21 -17
- package/dist/types/components/six-input/six-input.d.ts +27 -36
- package/dist/types/components/six-radio/six-radio.d.ts +10 -11
- package/dist/types/components/six-range/six-range.d.ts +24 -20
- package/dist/types/components/six-select/six-select.d.ts +35 -40
- package/dist/types/components/six-select/util.d.ts +7 -0
- package/dist/types/components/six-textarea/six-textarea.d.ts +22 -31
- package/dist/types/components.d.ts +20 -28
- package/dist/types/utils/testing.d.ts +1 -1
- package/dist/ui-library/p-163f2bb0.entry.js +2 -0
- package/dist/ui-library/p-163f2bb0.entry.js.map +1 -0
- package/dist/ui-library/{p-14f20bbb.entry.js → p-394a2a12.entry.js} +2 -2
- package/dist/ui-library/p-394a2a12.entry.js.map +1 -0
- package/dist/ui-library/{p-7e0cc4ae.entry.js → p-3c635d0a.entry.js} +2 -2
- package/dist/ui-library/p-3c635d0a.entry.js.map +1 -0
- package/dist/ui-library/p-5a25d6fb.entry.js +2 -0
- package/dist/ui-library/p-5a25d6fb.entry.js.map +1 -0
- package/dist/ui-library/{p-90dc6af4.entry.js → p-97cc839c.entry.js} +2 -2
- package/dist/ui-library/p-97cc839c.entry.js.map +1 -0
- package/dist/ui-library/p-b4dfb7cf.js.map +1 -1
- package/dist/ui-library/p-f604e067.entry.js +2 -0
- package/dist/ui-library/p-f604e067.entry.js.map +1 -0
- package/dist/ui-library/ui-library.esm.js +1 -1
- package/package.json +13 -14
- package/dist/ui-library/p-0d79b0c6.entry.js +0 -2
- package/dist/ui-library/p-0d79b0c6.entry.js.map +0 -1
- package/dist/ui-library/p-14f20bbb.entry.js.map +0 -1
- package/dist/ui-library/p-7e0cc4ae.entry.js.map +0 -1
- package/dist/ui-library/p-835c3ff7.entry.js +0 -2
- package/dist/ui-library/p-835c3ff7.entry.js.map +0 -1
- package/dist/ui-library/p-90dc6af4.entry.js.map +0 -1
- package/dist/ui-library/p-edc96efc.entry.js +0 -2
- package/dist/ui-library/p-edc96efc.entry.js.map +0 -1
|
@@ -19,9 +19,43 @@ export class SixRadio {
|
|
|
19
19
|
this.labelId = `radio-label-${id}`;
|
|
20
20
|
/** default state whether the radio button should be checked or not when resetting */
|
|
21
21
|
this.defaultState = false;
|
|
22
|
+
this.handleClick = () => {
|
|
23
|
+
if (this.nativeInput != null) {
|
|
24
|
+
this.checked = this.nativeInput.checked;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
this.handleBlur = () => {
|
|
28
|
+
this.hasFocus = false;
|
|
29
|
+
this.sixBlur.emit();
|
|
30
|
+
};
|
|
31
|
+
this.handleFocus = () => {
|
|
32
|
+
this.hasFocus = true;
|
|
33
|
+
this.sixFocus.emit();
|
|
34
|
+
};
|
|
35
|
+
this.handleKeyDown = (event) => {
|
|
36
|
+
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
|
37
|
+
const radios = this.getAllRadios().filter((radio) => !radio.disabled);
|
|
38
|
+
const incr = ['ArrowUp', 'ArrowLeft'].includes(event.key) ? -1 : 1;
|
|
39
|
+
let index = radios.indexOf(this.host) + incr;
|
|
40
|
+
if (index < 0)
|
|
41
|
+
index = radios.length - 1;
|
|
42
|
+
if (index > radios.length - 1)
|
|
43
|
+
index = 0;
|
|
44
|
+
this.getAllRadios().map((radio) => (radio.checked = false));
|
|
45
|
+
radios[index].setFocus();
|
|
46
|
+
radios[index].checked = true;
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.handleMouseDown = (event) => {
|
|
51
|
+
var _a;
|
|
52
|
+
// Prevent clicks on the label from briefly blurring the input
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.focus();
|
|
55
|
+
};
|
|
22
56
|
this.hasFocus = false;
|
|
23
|
-
this.name =
|
|
24
|
-
this.value =
|
|
57
|
+
this.name = '';
|
|
58
|
+
this.value = 'on';
|
|
25
59
|
this.disabled = false;
|
|
26
60
|
this.checked = false;
|
|
27
61
|
this.invalid = false;
|
|
@@ -30,95 +64,66 @@ export class SixRadio {
|
|
|
30
64
|
if (this.checked) {
|
|
31
65
|
this.getSiblingRadios().map((radio) => (radio.checked = false));
|
|
32
66
|
}
|
|
33
|
-
if (this.
|
|
34
|
-
this.
|
|
67
|
+
if (this.nativeInput != null) {
|
|
68
|
+
this.nativeInput.checked = this.checked;
|
|
35
69
|
this.sixChange.emit();
|
|
36
70
|
}
|
|
37
71
|
}
|
|
38
|
-
connectedCallback() {
|
|
39
|
-
this.handleClick = this.handleClick.bind(this);
|
|
40
|
-
this.handleBlur = this.handleBlur.bind(this);
|
|
41
|
-
this.handleFocus = this.handleFocus.bind(this);
|
|
42
|
-
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
43
|
-
this.handleMouseDown = this.handleMouseDown.bind(this);
|
|
44
|
-
}
|
|
45
72
|
componentWillLoad() {
|
|
46
73
|
this.defaultState = this.checked;
|
|
47
74
|
}
|
|
48
75
|
/** Sets focus on the radio. */
|
|
49
76
|
async setFocus(options) {
|
|
50
|
-
|
|
77
|
+
var _a;
|
|
78
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.focus(options);
|
|
51
79
|
}
|
|
52
80
|
/** Removes focus from the radio. */
|
|
53
81
|
async removeFocus() {
|
|
54
|
-
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.blur();
|
|
55
84
|
}
|
|
56
85
|
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
57
86
|
async reportValidity() {
|
|
58
|
-
|
|
87
|
+
var _a;
|
|
88
|
+
return (_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.reportValidity();
|
|
59
89
|
}
|
|
60
90
|
/** Checks for validity. */
|
|
61
91
|
async checkValidity() {
|
|
62
|
-
|
|
92
|
+
if (this.nativeInput == null) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return this.nativeInput.validity.valid;
|
|
63
96
|
}
|
|
64
97
|
/** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */
|
|
65
98
|
async setCustomValidity(message) {
|
|
66
|
-
this.
|
|
67
|
-
|
|
99
|
+
if (this.nativeInput != null) {
|
|
100
|
+
this.nativeInput.setCustomValidity(message);
|
|
101
|
+
this.invalid = !this.nativeInput.checkValidity();
|
|
102
|
+
}
|
|
68
103
|
}
|
|
69
104
|
/** Resets the formcontrol */
|
|
70
105
|
async reset() {
|
|
106
|
+
var _a;
|
|
71
107
|
this.checked = this.defaultState;
|
|
72
|
-
this.
|
|
108
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.setCustomValidity('');
|
|
73
109
|
this.invalid = false;
|
|
74
110
|
}
|
|
75
111
|
getAllRadios() {
|
|
76
112
|
const form = this.host.closest('six-form, form') || document.body;
|
|
77
|
-
if (
|
|
113
|
+
if (this.name === '')
|
|
78
114
|
return [];
|
|
79
115
|
return [...form.querySelectorAll('six-radio')].filter((radio) => radio.name === this.name);
|
|
80
116
|
}
|
|
81
117
|
getSiblingRadios() {
|
|
82
118
|
return this.getAllRadios().filter((radio) => radio !== this.host);
|
|
83
119
|
}
|
|
84
|
-
handleClick() {
|
|
85
|
-
this.checked = this.input.checked;
|
|
86
|
-
}
|
|
87
|
-
handleBlur() {
|
|
88
|
-
this.hasFocus = false;
|
|
89
|
-
this.sixBlur.emit();
|
|
90
|
-
}
|
|
91
|
-
handleFocus() {
|
|
92
|
-
this.hasFocus = true;
|
|
93
|
-
this.sixFocus.emit();
|
|
94
|
-
}
|
|
95
|
-
handleKeyDown(event) {
|
|
96
|
-
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
|
97
|
-
const radios = this.getAllRadios().filter((radio) => !radio.disabled);
|
|
98
|
-
const incr = ['ArrowUp', 'ArrowLeft'].includes(event.key) ? -1 : 1;
|
|
99
|
-
let index = radios.indexOf(this.host) + incr;
|
|
100
|
-
if (index < 0)
|
|
101
|
-
index = radios.length - 1;
|
|
102
|
-
if (index > radios.length - 1)
|
|
103
|
-
index = 0;
|
|
104
|
-
this.getAllRadios().map((radio) => (radio.checked = false));
|
|
105
|
-
radios[index].setFocus();
|
|
106
|
-
radios[index].checked = true;
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
handleMouseDown(event) {
|
|
111
|
-
// Prevent clicks on the label from briefly blurring the input
|
|
112
|
-
event.preventDefault();
|
|
113
|
-
this.input.focus();
|
|
114
|
-
}
|
|
115
120
|
render() {
|
|
116
121
|
return (h("label", { part: "base", class: {
|
|
117
122
|
radio: true,
|
|
118
123
|
'radio--checked': this.checked,
|
|
119
124
|
'radio--disabled': this.disabled,
|
|
120
125
|
'radio--focused': this.hasFocus,
|
|
121
|
-
}, htmlFor: this.inputId, onKeyDown: this.handleKeyDown, onMouseDown: this.handleMouseDown }, h("span", { part: "control", class: "radio__control" }, h("span", { part: "checked-icon", class: "radio__icon" }, h("svg", { viewBox: "0 0 16 16" }, h("g", { stroke: "none", "stroke-width": "1", fill: "none", "fill-rule": "evenodd" }, h("g", { fill: "currentColor" }, h("circle", { cx: "8", cy: "8", r: "5" }))))), h("input", { ref: (el) => (this.
|
|
126
|
+
}, htmlFor: this.inputId, onKeyDown: this.handleKeyDown, onMouseDown: this.handleMouseDown }, h("span", { part: "control", class: "radio__control" }, h("span", { part: "checked-icon", class: "radio__icon" }, h("svg", { viewBox: "0 0 16 16" }, h("g", { stroke: "none", "stroke-width": "1", fill: "none", "fill-rule": "evenodd" }, h("g", { fill: "currentColor" }, h("circle", { cx: "8", cy: "8", r: "5" }))))), h("input", { ref: (el) => (this.nativeInput = el), id: this.inputId, type: "radio", name: this.name, value: this.value, checked: this.checked, disabled: this.disabled, role: "radio", "aria-checked": this.checked ? 'true' : 'false', "aria-labelledby": this.labelId, onClick: this.handleClick, onBlur: this.handleBlur, onFocus: this.handleFocus })), h("span", { part: "label", id: this.labelId, class: "radio__label" }, h("slot", null))));
|
|
122
127
|
}
|
|
123
128
|
static get is() { return "six-radio"; }
|
|
124
129
|
static get encapsulation() { return "shadow"; }
|
|
@@ -149,7 +154,8 @@ export class SixRadio {
|
|
|
149
154
|
"text": "The radio's name attribute."
|
|
150
155
|
},
|
|
151
156
|
"attribute": "name",
|
|
152
|
-
"reflect": false
|
|
157
|
+
"reflect": false,
|
|
158
|
+
"defaultValue": "''"
|
|
153
159
|
},
|
|
154
160
|
"value": {
|
|
155
161
|
"type": "string",
|
|
@@ -166,7 +172,8 @@ export class SixRadio {
|
|
|
166
172
|
"text": "The radio's value attribute."
|
|
167
173
|
},
|
|
168
174
|
"attribute": "value",
|
|
169
|
-
"reflect": false
|
|
175
|
+
"reflect": false,
|
|
176
|
+
"defaultValue": "'on'"
|
|
170
177
|
},
|
|
171
178
|
"disabled": {
|
|
172
179
|
"type": "boolean",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"six-radio.js","sourceRoot":"","sources":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AG,EAAE,CAAC,EAC9B,EAAE,EAAE,IAAI,CAAC,OAAO,EAChB,IAAI,EAAC,OAAO,EACZ,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,IAAI,EAAC,OAAO,kBACE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,qBAC5B,IAAI,CAAC,OAAO,EAC7B,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,MAAM,EAAE,IAAI,CAAC,UAAU,EACvB,OAAO,EAAE,IAAI,CAAC,WAAW,GACzB,CACG;MAEP,YAAM,IAAI,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAC,cAAc;QACvD,eAAQ,CACH,CACD,CACT,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Event, EventEmitter, Method, Prop, State, Watch, h } from '@stencil/core';\nimport { EmptyPayload } from '../../utils/types';\n\nlet id = 0;\n\n/**\n * @since 1.0\n * @status stable\n *\n * Forked from https://github.com/shoelace-style/shoelace version v2.0.0-beta27.\n *\n * @slot - The radio's label.\n *\n * @part base - The component's base wrapper.\n * @part control - The radio control.\n * @part checked-icon - The container the wraps the checked icon.\n * @part label - The radio label.\n */\n\n@Component({\n tag: 'six-radio',\n styleUrl: 'six-radio.scss',\n shadow: true,\n})\nexport class SixRadio {\n inputId = `radio-${++id}`;\n labelId = `radio-label-${id}`;\n input: HTMLInputElement;\n\n @Element() host: HTMLSixRadioElement;\n\n @State() hasFocus = false;\n\n /** The radio's name attribute. */\n @Prop() name: string;\n\n /** The radio's value attribute. */\n @Prop() value: string;\n\n /** Set to true to disable the radio. */\n @Prop() disabled = false;\n\n /** Set to true to draw the radio in a checked state. */\n @Prop({ mutable: true, reflect: true }) checked = false;\n\n /**\n * This will be true when the control is in an invalid state. Validity in range inputs is determined by the message\n * provided by the `setCustomValidity` method.\n */\n @Prop({ mutable: true, reflect: true }) invalid = false;\n\n @Watch('checked')\n handleCheckedChange() {\n if (this.checked) {\n this.getSiblingRadios().map((radio) => (radio.checked = false));\n }\n if (this.input) {\n this.input.checked = this.checked;\n this.sixChange.emit();\n }\n }\n\n /** Emitted when the control loses focus. */\n @Event({ eventName: 'six-radio-blur' }) sixBlur: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control's checked state changes. */\n @Event({ eventName: 'six-radio-change' }) sixChange: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control gains focus. */\n @Event({ eventName: 'six-radio-focus' }) sixFocus: EventEmitter<EmptyPayload>;\n\n /** default state whether the radio button should be checked or not when resetting */\n private defaultState = false;\n\n connectedCallback() {\n this.handleClick = this.handleClick.bind(this);\n this.handleBlur = this.handleBlur.bind(this);\n this.handleFocus = this.handleFocus.bind(this);\n this.handleKeyDown = this.handleKeyDown.bind(this);\n this.handleMouseDown = this.handleMouseDown.bind(this);\n }\n\n componentWillLoad() {\n this.defaultState = this.checked;\n }\n\n /** Sets focus on the radio. */\n @Method()\n async setFocus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /** Removes focus from the radio. */\n @Method()\n async removeFocus() {\n this.input.blur();\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n @Method()\n async reportValidity() {\n return this.input.reportValidity();\n }\n\n /** Checks for validity. */\n @Method()\n async checkValidity() {\n return this.input.validity.valid;\n }\n\n /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */\n @Method()\n async setCustomValidity(message: string) {\n this.input.setCustomValidity(message);\n this.invalid = !this.input.checkValidity();\n }\n\n /** Resets the formcontrol */\n @Method()\n async reset() {\n this.checked = this.defaultState;\n this.input.setCustomValidity('');\n this.invalid = false;\n }\n\n getAllRadios() {\n const form = this.host.closest('six-form, form') || document.body;\n\n if (!this.name) return [];\n\n return [...form.querySelectorAll('six-radio')].filter(\n (radio: HTMLSixRadioElement) => radio.name === this.name\n ) as HTMLSixRadioElement[];\n }\n\n getSiblingRadios() {\n return this.getAllRadios().filter((radio) => radio !== this.host) as HTMLSixRadioElement[];\n }\n\n handleClick() {\n this.checked = this.input.checked;\n }\n\n handleBlur() {\n this.hasFocus = false;\n this.sixBlur.emit();\n }\n\n handleFocus() {\n this.hasFocus = true;\n this.sixFocus.emit();\n }\n\n handleKeyDown(event: KeyboardEvent) {\n if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {\n const radios = this.getAllRadios().filter((radio) => !radio.disabled);\n const incr = ['ArrowUp', 'ArrowLeft'].includes(event.key) ? -1 : 1;\n let index = radios.indexOf(this.host) + incr;\n if (index < 0) index = radios.length - 1;\n if (index > radios.length - 1) index = 0;\n\n this.getAllRadios().map((radio) => (radio.checked = false));\n radios[index].setFocus();\n radios[index].checked = true;\n\n event.preventDefault();\n }\n }\n\n handleMouseDown(event: MouseEvent) {\n // Prevent clicks on the label from briefly blurring the input\n event.preventDefault();\n this.input.focus();\n }\n\n render() {\n return (\n <label\n part=\"base\"\n class={{\n radio: true,\n 'radio--checked': this.checked,\n 'radio--disabled': this.disabled,\n 'radio--focused': this.hasFocus,\n }}\n htmlFor={this.inputId}\n onKeyDown={this.handleKeyDown}\n onMouseDown={this.handleMouseDown}\n >\n <span part=\"control\" class=\"radio__control\">\n <span part=\"checked-icon\" class=\"radio__icon\">\n <svg viewBox=\"0 0 16 16\">\n <g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <g fill=\"currentColor\">\n <circle cx=\"8\" cy=\"8\" r=\"5\"></circle>\n </g>\n </g>\n </svg>\n </span>\n\n <input\n ref={(el) => (this.input = el)}\n id={this.inputId}\n type=\"radio\"\n name={this.name}\n value={this.value}\n checked={this.checked}\n disabled={this.disabled}\n role=\"radio\"\n aria-checked={this.checked ? 'true' : 'false'}\n aria-labelledby={this.labelId}\n onClick={this.handleClick}\n onBlur={this.handleBlur}\n onFocus={this.handleFocus}\n />\n </span>\n\n <span part=\"label\" id={this.labelId} class=\"radio__label\">\n <slot />\n </span>\n </label>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"six-radio.js","sourceRoot":"","sources":["../../../src/components/six-radio/six-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGvG,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX;;;;;;;;;;;;GAYG;AAOH,MAAM,OAAO,QAAQ;;IACX,YAAO,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC;IAC1B,YAAO,GAAG,eAAe,EAAE,EAAE,CAAC;IA6CtC,qFAAqF;IAC7E,iBAAY,GAAG,KAAK,CAAC;IAgErB,gBAAW,GAAG,GAAG,EAAE;MACzB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,EAAE;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;OACzC;IACH,CAAC,CAAC;IAEM,eAAU,GAAG,GAAG,EAAE;MACxB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;MACtB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC,CAAC;IAEM,gBAAW,GAAG,GAAG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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Event, EventEmitter, h, Method, Prop, State, Watch } from '@stencil/core';\nimport { EmptyPayload } from '../../utils/types';\n\nlet id = 0;\n\n/**\n * @since 1.0\n * @status stable\n *\n * Forked from https://github.com/shoelace-style/shoelace version v2.0.0-beta27.\n *\n * @slot - The radio's label.\n *\n * @part base - The component's base wrapper.\n * @part control - The radio control.\n * @part checked-icon - The container the wraps the checked icon.\n * @part label - The radio label.\n */\n\n@Component({\n tag: 'six-radio',\n styleUrl: 'six-radio.scss',\n shadow: true,\n})\nexport class SixRadio {\n private inputId = `radio-${++id}`;\n private labelId = `radio-label-${id}`;\n private nativeInput?: HTMLInputElement;\n\n @Element() host!: HTMLSixRadioElement;\n\n @State() hasFocus = false;\n\n /** The radio's name attribute. */\n @Prop() name = '';\n\n /** The radio's value attribute. */\n @Prop() value = 'on';\n\n /** Set to true to disable the radio. */\n @Prop() disabled = false;\n\n /** Set to true to draw the radio in a checked state. */\n @Prop({ mutable: true, reflect: true }) checked = false;\n\n /**\n * This will be true when the control is in an invalid state. Validity in range inputs is determined by the message\n * provided by the `setCustomValidity` method.\n */\n @Prop({ mutable: true, reflect: true }) invalid = false;\n\n @Watch('checked')\n handleCheckedChange() {\n if (this.checked) {\n this.getSiblingRadios().map((radio) => (radio.checked = false));\n }\n if (this.nativeInput != null) {\n this.nativeInput.checked = this.checked;\n this.sixChange.emit();\n }\n }\n\n /** Emitted when the control loses focus. */\n @Event({ eventName: 'six-radio-blur' }) sixBlur!: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control's checked state changes. */\n @Event({ eventName: 'six-radio-change' }) sixChange!: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control gains focus. */\n @Event({ eventName: 'six-radio-focus' }) sixFocus!: EventEmitter<EmptyPayload>;\n\n /** default state whether the radio button should be checked or not when resetting */\n private defaultState = false;\n\n componentWillLoad() {\n this.defaultState = this.checked;\n }\n\n /** Sets focus on the radio. */\n @Method()\n async setFocus(options?: FocusOptions) {\n this.nativeInput?.focus(options);\n }\n\n /** Removes focus from the radio. */\n @Method()\n async removeFocus() {\n this.nativeInput?.blur();\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n @Method()\n async reportValidity() {\n return this.nativeInput?.reportValidity();\n }\n\n /** Checks for validity. */\n @Method()\n async checkValidity() {\n if (this.nativeInput == null) {\n return true;\n }\n return this.nativeInput.validity.valid;\n }\n\n /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */\n @Method()\n async setCustomValidity(message: string) {\n if (this.nativeInput != null) {\n this.nativeInput.setCustomValidity(message);\n this.invalid = !this.nativeInput.checkValidity();\n }\n }\n\n /** Resets the formcontrol */\n @Method()\n async reset() {\n this.checked = this.defaultState;\n this.nativeInput?.setCustomValidity('');\n this.invalid = false;\n }\n\n private getAllRadios() {\n const form = this.host.closest('six-form, form') || document.body;\n\n if (this.name === '') return [];\n\n return [...form.querySelectorAll('six-radio')].filter(\n (radio: HTMLSixRadioElement) => radio.name === this.name\n ) as HTMLSixRadioElement[];\n }\n\n private getSiblingRadios() {\n return this.getAllRadios().filter((radio) => radio !== this.host) as HTMLSixRadioElement[];\n }\n\n private handleClick = () => {\n if (this.nativeInput != null) {\n this.checked = this.nativeInput.checked;\n }\n };\n\n private handleBlur = () => {\n this.hasFocus = false;\n this.sixBlur.emit();\n };\n\n private handleFocus = () => {\n this.hasFocus = true;\n this.sixFocus.emit();\n };\n\n private handleKeyDown = (event: KeyboardEvent) => {\n if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {\n const radios = this.getAllRadios().filter((radio) => !radio.disabled);\n const incr = ['ArrowUp', 'ArrowLeft'].includes(event.key) ? -1 : 1;\n let index = radios.indexOf(this.host) + incr;\n if (index < 0) index = radios.length - 1;\n if (index > radios.length - 1) index = 0;\n\n this.getAllRadios().map((radio) => (radio.checked = false));\n radios[index].setFocus();\n radios[index].checked = true;\n\n event.preventDefault();\n }\n };\n\n private handleMouseDown = (event: MouseEvent) => {\n // Prevent clicks on the label from briefly blurring the input\n event.preventDefault();\n this.nativeInput?.focus();\n };\n\n render() {\n return (\n <label\n part=\"base\"\n class={{\n radio: true,\n 'radio--checked': this.checked,\n 'radio--disabled': this.disabled,\n 'radio--focused': this.hasFocus,\n }}\n htmlFor={this.inputId}\n onKeyDown={this.handleKeyDown}\n onMouseDown={this.handleMouseDown}\n >\n <span part=\"control\" class=\"radio__control\">\n <span part=\"checked-icon\" class=\"radio__icon\">\n <svg viewBox=\"0 0 16 16\">\n <g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <g fill=\"currentColor\">\n <circle cx=\"8\" cy=\"8\" r=\"5\"></circle>\n </g>\n </g>\n </svg>\n </span>\n\n <input\n ref={(el) => (this.nativeInput = el)}\n id={this.inputId}\n type=\"radio\"\n name={this.name}\n value={this.value}\n checked={this.checked}\n disabled={this.disabled}\n role=\"radio\"\n aria-checked={this.checked ? 'true' : 'false'}\n aria-labelledby={this.labelId}\n onClick={this.handleClick}\n onBlur={this.handleBlur}\n onFocus={this.handleFocus}\n />\n </span>\n\n <span part=\"label\" id={this.labelId} class=\"radio__label\">\n <slot />\n </span>\n </label>\n );\n }\n}\n"]}
|
|
@@ -22,20 +22,54 @@ export class SixRange {
|
|
|
22
22
|
this.inputId = `input-${++id}`;
|
|
23
23
|
this.labelId = `input-label-${id}`;
|
|
24
24
|
this.helpTextId = `input-help-text-${id}`;
|
|
25
|
-
this.errorTextId = `input-error-text-${id}`;
|
|
26
25
|
this.customErrorText = '';
|
|
27
26
|
this.customValidation = false;
|
|
27
|
+
this.errorTextId = `input-error-text-${id}`;
|
|
28
28
|
this.eventListeners = new EventListeners();
|
|
29
29
|
/** default value the slider will be reverted to when reset is executed */
|
|
30
30
|
this.defaultValue = 0;
|
|
31
|
+
this.handleInput = () => {
|
|
32
|
+
if (this.nativeInput != null) {
|
|
33
|
+
this.update(parseFloat(this.nativeInput.value));
|
|
34
|
+
}
|
|
35
|
+
requestAnimationFrame(() => {
|
|
36
|
+
this.sixChange.emit();
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
this.handleBlur = () => {
|
|
40
|
+
var _a;
|
|
41
|
+
this.hasFocus = false;
|
|
42
|
+
this.hasTooltip = false;
|
|
43
|
+
this.sixBlur.emit();
|
|
44
|
+
if (this.nativeInput != null) {
|
|
45
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.unobserve(this.nativeInput);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
this.handleFocus = () => {
|
|
49
|
+
var _a;
|
|
50
|
+
this.hasFocus = true;
|
|
51
|
+
this.hasTooltip = true;
|
|
52
|
+
this.sixFocus.emit();
|
|
53
|
+
if (this.nativeInput != null) {
|
|
54
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.nativeInput);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.handleSlotChange = () => {
|
|
58
|
+
this.hasHelpTextSlot = hasSlot(this.host, 'help-text');
|
|
59
|
+
this.hasErrorTextSlot = hasSlot(this.host, 'error-text');
|
|
60
|
+
this.hasLabelSlot = hasSlot(this.host, 'label');
|
|
61
|
+
};
|
|
62
|
+
this.handleTouchStart = () => {
|
|
63
|
+
this.setFocus();
|
|
64
|
+
};
|
|
31
65
|
this.hasFocus = false;
|
|
32
66
|
this.hasHelpTextSlot = false;
|
|
33
67
|
this.hasLabelSlot = false;
|
|
34
68
|
this.hasErrorTextSlot = false;
|
|
35
69
|
this.hasTooltip = false;
|
|
36
70
|
this.name = '';
|
|
37
|
-
this.value =
|
|
38
|
-
this.required =
|
|
71
|
+
this.value = 0;
|
|
72
|
+
this.required = false;
|
|
39
73
|
this.label = '';
|
|
40
74
|
this.helpText = '';
|
|
41
75
|
this.errorText = '';
|
|
@@ -52,119 +86,125 @@ export class SixRange {
|
|
|
52
86
|
this.handleSlotChange();
|
|
53
87
|
}
|
|
54
88
|
handleValueChange() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.
|
|
89
|
+
this.update();
|
|
90
|
+
if (this.nativeInput != null) {
|
|
91
|
+
this.invalid = !this.nativeInput.checkValidity();
|
|
58
92
|
}
|
|
59
|
-
// In rare cases, the watcher may be called before render so we need to make sure the input exists
|
|
60
|
-
this.invalid = this.input ? !this.input.checkValidity() : false;
|
|
61
93
|
}
|
|
62
94
|
connectedCallback() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.handleFocus = this.handleFocus.bind(this);
|
|
66
|
-
this.handleSlotChange = this.handleSlotChange.bind(this);
|
|
67
|
-
this.handleTouchStart = this.handleTouchStart.bind(this);
|
|
68
|
-
this.host.shadowRoot.addEventListener('slotchange', this.handleSlotChange);
|
|
95
|
+
var _a;
|
|
96
|
+
(_a = this.host.shadowRoot) === null || _a === void 0 ? void 0 : _a.addEventListener('slotchange', this.handleSlotChange);
|
|
69
97
|
}
|
|
70
98
|
componentWillLoad() {
|
|
71
|
-
|
|
72
|
-
this.value = this.min;
|
|
73
|
-
if (this.value < this.min)
|
|
74
|
-
this.value = this.min;
|
|
75
|
-
if (this.value > this.max)
|
|
76
|
-
this.value = this.max;
|
|
99
|
+
this.update();
|
|
77
100
|
this.defaultValue = this.value;
|
|
78
101
|
this.handleSlotChange();
|
|
79
102
|
}
|
|
80
103
|
componentDidLoad() {
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
const nativeInput = this.nativeInput;
|
|
105
|
+
if (nativeInput == null) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.update();
|
|
109
|
+
this.resizeObserver = new ResizeObserver(() => this.update());
|
|
110
|
+
this.eventListeners.add(nativeInput, 'invalid', (event) => {
|
|
111
|
+
if (this.customValidation || (!this.hasErrorTextSlot && this.errorText === '' && this.customErrorText === '')) {
|
|
112
|
+
this.customErrorText = nativeInput.validationMessage;
|
|
87
113
|
}
|
|
88
114
|
event.preventDefault();
|
|
89
115
|
});
|
|
90
116
|
}
|
|
91
117
|
disconnectedCallback() {
|
|
92
|
-
|
|
118
|
+
var _a;
|
|
119
|
+
(_a = this.host.shadowRoot) === null || _a === void 0 ? void 0 : _a.removeEventListener('slotchange', this.handleSlotChange);
|
|
93
120
|
this.eventListeners.removeAll();
|
|
94
121
|
}
|
|
95
122
|
/** Sets focus on the input. */
|
|
96
123
|
async setFocus(options) {
|
|
97
|
-
|
|
124
|
+
var _a;
|
|
125
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.focus(options);
|
|
98
126
|
}
|
|
99
127
|
/** Removes focus from the input. */
|
|
100
128
|
async removeFocus() {
|
|
101
|
-
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.blur();
|
|
102
131
|
}
|
|
103
132
|
/** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */
|
|
104
133
|
async setCustomValidity(message) {
|
|
105
134
|
this.customErrorText = '';
|
|
106
135
|
this.customValidation = message !== '';
|
|
107
|
-
this.
|
|
108
|
-
|
|
136
|
+
if (this.nativeInput != null) {
|
|
137
|
+
this.nativeInput.setCustomValidity(message);
|
|
138
|
+
this.invalid = !this.nativeInput.checkValidity();
|
|
139
|
+
}
|
|
109
140
|
}
|
|
110
141
|
/** Resets the formcontrol */
|
|
111
142
|
async reset() {
|
|
143
|
+
var _a;
|
|
112
144
|
this.value = this.defaultValue;
|
|
113
145
|
this.customErrorText = '';
|
|
114
146
|
this.customValidation = false;
|
|
115
|
-
this.
|
|
147
|
+
(_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.setCustomValidity('');
|
|
116
148
|
this.invalid = false;
|
|
117
149
|
}
|
|
118
|
-
handleInput() {
|
|
119
|
-
this.value = Number(this.input.value);
|
|
120
|
-
this.sixChange.emit();
|
|
121
|
-
requestAnimationFrame(() => this.syncTooltip());
|
|
122
|
-
requestAnimationFrame(() => this.calculateColorRunnableTrack());
|
|
123
|
-
}
|
|
124
|
-
handleBlur() {
|
|
125
|
-
this.hasFocus = false;
|
|
126
|
-
this.hasTooltip = false;
|
|
127
|
-
this.sixBlur.emit();
|
|
128
|
-
this.resizeObserver.unobserve(this.input);
|
|
129
|
-
}
|
|
130
|
-
handleFocus() {
|
|
131
|
-
this.hasFocus = true;
|
|
132
|
-
this.hasTooltip = true;
|
|
133
|
-
this.sixFocus.emit();
|
|
134
|
-
this.resizeObserver.observe(this.input);
|
|
135
|
-
}
|
|
136
|
-
handleSlotChange() {
|
|
137
|
-
this.hasHelpTextSlot = hasSlot(this.host, 'help-text');
|
|
138
|
-
this.hasErrorTextSlot = hasSlot(this.host, 'error-text');
|
|
139
|
-
this.hasLabelSlot = hasSlot(this.host, 'label');
|
|
140
|
-
}
|
|
141
|
-
handleTouchStart() {
|
|
142
|
-
this.setFocus();
|
|
143
|
-
}
|
|
144
150
|
displayError() {
|
|
145
151
|
return this.invalid && (!this.errorOnBlur || !this.hasFocus);
|
|
146
152
|
}
|
|
147
|
-
syncTooltip() {
|
|
148
|
-
if (this.tooltip !== 'none') {
|
|
149
|
-
const percent = Math.max(0, (
|
|
150
|
-
const inputWidth = this.
|
|
153
|
+
syncTooltip(min, max, value) {
|
|
154
|
+
if (this.tooltip !== 'none' && this.nativeInput != null && this.output != null) {
|
|
155
|
+
const percent = Math.max(0, (value - min) / (max - min));
|
|
156
|
+
const inputWidth = this.nativeInput.offsetWidth;
|
|
151
157
|
const tooltipWidth = this.output.offsetWidth;
|
|
152
|
-
const thumbSize = getComputedStyle(this.
|
|
158
|
+
const thumbSize = getComputedStyle(this.nativeInput).getPropertyValue('--thumb-size');
|
|
153
159
|
const x = `calc(${inputWidth * percent}px - calc(calc(${percent} * ${thumbSize}) - calc(${thumbSize} / 2)))`;
|
|
154
160
|
this.output.style.transform = `translateX(${x})`;
|
|
155
161
|
this.output.style.marginLeft = `-${tooltipWidth / 2}px`;
|
|
156
162
|
}
|
|
157
163
|
}
|
|
164
|
+
isFirefox() {
|
|
165
|
+
return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
166
|
+
}
|
|
167
|
+
update(updateValue) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
if (updateValue != null) {
|
|
170
|
+
this.value = updateValue;
|
|
171
|
+
}
|
|
172
|
+
const min = (_a = Number(this.min)) !== null && _a !== void 0 ? _a : 0;
|
|
173
|
+
const max = (_b = Number(this.max)) !== null && _b !== void 0 ? _b : 0;
|
|
174
|
+
let value;
|
|
175
|
+
const parsedValue = parseFloat(this.value);
|
|
176
|
+
if (isNaN(parsedValue)) {
|
|
177
|
+
value = this.getDefaultValue(min, max);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
value = parsedValue;
|
|
181
|
+
}
|
|
182
|
+
if (this.nativeInput != null) {
|
|
183
|
+
// The value may have constraints, so we set the native control's
|
|
184
|
+
// value and sync it back to ensure it adheres to min, max, and step
|
|
185
|
+
// properly.
|
|
186
|
+
this.nativeInput.value = value.toString();
|
|
187
|
+
this.value = parseFloat(this.nativeInput.value);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
this.value = value;
|
|
191
|
+
}
|
|
192
|
+
this.calculateColorRunnableTrack(min, max, this.value);
|
|
193
|
+
this.syncTooltip(min, max, this.value);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#value
|
|
197
|
+
*/
|
|
198
|
+
getDefaultValue(min, max) {
|
|
199
|
+
return max < min ? min : min + (max - min) / 2;
|
|
200
|
+
}
|
|
158
201
|
/**
|
|
159
202
|
* For Firefox this functionality is not needed because it is supported by standard CSS.
|
|
160
203
|
*/
|
|
161
|
-
calculateColorRunnableTrack() {
|
|
162
|
-
if (!this.isFirefox()) {
|
|
163
|
-
const value = parseInt(this.input.value, 10);
|
|
164
|
-
const min = parseInt(this.input.min, 10);
|
|
165
|
-
const max = parseInt(this.input.max, 10);
|
|
204
|
+
calculateColorRunnableTrack(min, max, value) {
|
|
205
|
+
if (!this.isFirefox() && this.nativeInput != null) {
|
|
166
206
|
const percent = Math.ceil(((value - min) / (max - min)) * 100);
|
|
167
|
-
this.
|
|
207
|
+
this.nativeInput.style.background =
|
|
168
208
|
'-webkit-linear-gradient(left, var(--track-color) 0%, var(--track-color) ' +
|
|
169
209
|
percent +
|
|
170
210
|
'%, var(--six-color-web-rock-300) ' +
|
|
@@ -172,11 +212,8 @@ export class SixRange {
|
|
|
172
212
|
'%)';
|
|
173
213
|
}
|
|
174
214
|
}
|
|
175
|
-
isFirefox() {
|
|
176
|
-
return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
177
|
-
}
|
|
178
215
|
render() {
|
|
179
|
-
return (h(FormControl, { inputId: this.inputId, label: this.label, labelId: this.labelId, hasLabelSlot: this.hasLabelSlot, helpTextId: this.helpTextId, helpText: this.helpText, hasHelpTextSlot: this.hasHelpTextSlot, size: "medium", errorTextId: this.errorTextId, errorText: this.customErrorText ? this.customErrorText : this.errorText, hasErrorTextSlot: this.hasErrorTextSlot, disabled: this.disabled, required: this.required, displayError: this.displayError() }, h("div", { part: "base", class: {
|
|
216
|
+
return (h(FormControl, { inputId: this.inputId, label: this.label, labelId: this.labelId, hasLabelSlot: this.hasLabelSlot, helpTextId: this.helpTextId, helpText: this.helpText, hasHelpTextSlot: this.hasHelpTextSlot, size: "medium", errorTextId: this.errorTextId, errorText: this.customErrorText != null ? this.customErrorText : this.errorText, hasErrorTextSlot: this.hasErrorTextSlot, disabled: this.disabled, required: this.required, displayError: this.displayError() }, h("div", { part: "base", class: {
|
|
180
217
|
range: true,
|
|
181
218
|
// States
|
|
182
219
|
'range--disabled': this.disabled,
|
|
@@ -184,7 +221,7 @@ export class SixRange {
|
|
|
184
221
|
'range--tooltip-visible': this.hasTooltip,
|
|
185
222
|
'range--tooltip-top': this.tooltip === 'top',
|
|
186
223
|
'range--tooltip-bottom': this.tooltip === 'bottom',
|
|
187
|
-
}, onTouchStart: this.handleTouchStart }, h("input", { part: "input", ref: (el) => (this.
|
|
224
|
+
}, onTouchStart: this.handleTouchStart }, h("input", { part: "input", ref: (el) => (this.nativeInput = el), type: "range", class: "range__control", name: this.name, disabled: this.disabled, min: this.min, max: this.max, step: this.step, value: this.value, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur }), this.tooltip !== 'none' && (h("output", { part: "tooltip", ref: (el) => (this.output = el), class: "range__tooltip" }, this.tooltipFormatter(this.value))))));
|
|
188
225
|
}
|
|
189
226
|
static get is() { return "six-range"; }
|
|
190
227
|
static get encapsulation() { return "shadow"; }
|
|
@@ -233,7 +270,8 @@ export class SixRange {
|
|
|
233
270
|
"text": "The input's value attribute."
|
|
234
271
|
},
|
|
235
272
|
"attribute": "value",
|
|
236
|
-
"reflect": false
|
|
273
|
+
"reflect": false,
|
|
274
|
+
"defaultValue": "0"
|
|
237
275
|
},
|
|
238
276
|
"required": {
|
|
239
277
|
"type": "boolean",
|
|
@@ -250,7 +288,8 @@ export class SixRange {
|
|
|
250
288
|
"text": "Set to true to make the input a required field."
|
|
251
289
|
},
|
|
252
290
|
"attribute": "required",
|
|
253
|
-
"reflect": true
|
|
291
|
+
"reflect": true,
|
|
292
|
+
"defaultValue": "false"
|
|
254
293
|
},
|
|
255
294
|
"label": {
|
|
256
295
|
"type": "string",
|
|
@@ -613,6 +652,12 @@ export class SixRange {
|
|
|
613
652
|
}, {
|
|
614
653
|
"propName": "value",
|
|
615
654
|
"methodName": "handleValueChange"
|
|
655
|
+
}, {
|
|
656
|
+
"propName": "min",
|
|
657
|
+
"methodName": "handleValueChange"
|
|
658
|
+
}, {
|
|
659
|
+
"propName": "max",
|
|
660
|
+
"methodName": "handleValueChange"
|
|
616
661
|
}];
|
|
617
662
|
}
|
|
618
663
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"six-range.js","sourceRoot":"","sources":["../../../src/components/six-range/six-range.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,WAAW,MAAM,uDAAuD,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX;;;;;;;;;;;;;GAaG;AAMH,MAAM,OAAO,QAAQ;;IACnB,YAAO,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC;IAC1B,YAAO,GAAG,eAAe,EAAE,EAAE,CAAC;IAC9B,eAAU,GAAG,mBAAmB,EAAE,EAAE,CAAC;IACrC,gBAAW,GAAG,oBAAoB,EAAE,EAAE,CAAC;IAKvC,oBAAe,GAAG,EAAE,CAAC;IACrB,qBAAgB,GAAG,KAAK,CAAC;IAEhB,mBAAc,GAAG,IAAI,cAAc,EAAE,CAAC;IAgE/C,0EAA0E;IAClE,iBAAY,GAAG,CAAC,CAAC;oBA7DL,KAAK;2BACE,KAAK;wBACR,KAAK;4BACD,KAAK;sBACX,KAAK;gBAGZ,EAAE;;;iBASD,EAAE;oBAGC,EAAE;qBAGD,EAAE;oBAGH,KAAK;mBAM0B,KAAK;eAGzC,CAAC;eAGD,GAAG;gBAGF,CAAC;mBAG6B,KAAK;4BAGvB,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE;uBAGxC,KAAK;;EAiB3B,iBAAiB;IACf,IAAI,CAAC,gBAAgB,EAAE,CAAC;EAC1B,CAAC;EAGD,iBAAiB;IAC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,CAC3B,CACV,CACG,CACM,CACf,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Event, EventEmitter, Method, Prop, State, Watch, h } from '@stencil/core';\nimport FormControl from '../../functional-components/form-control/form-control';\nimport { hasSlot } from '../../utils/slot';\nimport { EmptyPayload } from '../../utils/types';\nimport { EventListeners } from '../../utils/event-listeners';\n\nlet id = 0;\n\n/**\n * @since 1.0\n * @status stable\n *\n * Forked from https://github.com/shoelace-style/shoelace version v2.0.0-beta27.\n *\n * @slot label - The input's label. Alternatively, you can use the label prop.\n * @slot help-text - Help text that describes how to use the input. Alternatively, you can use the help-text prop.\n * @slot error-text - Error text that is shown for validation errors. Alternatively, you can use the error-text prop.\n *\n * @part base - The component's base wrapper.\n * @part input - The native range input.\n * @part tooltip - The range tooltip.\n */\n@Component({\n tag: 'six-range',\n styleUrl: 'six-range.scss',\n shadow: true,\n})\nexport class SixRange {\n inputId = `input-${++id}`;\n labelId = `input-label-${id}`;\n helpTextId = `input-help-text-${id}`;\n errorTextId = `input-error-text-${id}`;\n resizeObserver: ResizeObserver;\n\n output: HTMLElement;\n input: HTMLInputElement;\n customErrorText = '';\n customValidation = false;\n\n readonly eventListeners = new EventListeners();\n\n @Element() host: HTMLSixRangeElement;\n\n @State() hasFocus = false;\n @State() hasHelpTextSlot = false;\n @State() hasLabelSlot = false;\n @State() hasErrorTextSlot = false;\n @State() hasTooltip = false;\n\n /** The input's name attribute. */\n @Prop() name = '';\n\n /** The input's value attribute. */\n @Prop({ mutable: true }) value: number;\n\n /** Set to true to make the input a required field. */\n @Prop({ reflect: true }) required: boolean;\n\n /** The range's label. Alternatively, you can use the label slot. */\n @Prop() label = '';\n\n /** The range's help text. Alternatively, you can use the help-text slot. */\n @Prop() helpText = '';\n\n /** The input's error text. Alternatively, you can use the error-text slot. */\n @Prop() errorText = '';\n\n /** Set to true to disable the input. */\n @Prop() disabled = false;\n\n /**\n * This will be true when the control is in an invalid state. Validity in range inputs is determined by the message\n * provided by the `setCustomValidity` method.\n */\n @Prop({ mutable: true, reflect: true }) invalid = false;\n\n /** The input's min attribute. */\n @Prop() min = 0;\n\n /** The input's max attribute. */\n @Prop() max = 100;\n\n /** The input's step attribute. */\n @Prop() step = 1;\n\n /** The preferred placedment of the tooltip. */\n @Prop() tooltip: 'top' | 'bottom' | 'none' = 'top';\n\n /** A function used to format the tooltip's value. */\n @Prop() tooltipFormatter = (value: number) => value.toString();\n\n /** Set to display the error text on blur and not when typing */\n @Prop() errorOnBlur = false;\n\n /** Emitted when the control's value changes. */\n @Event({ eventName: 'six-range-change' }) sixChange: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control loses focus. */\n @Event({ eventName: 'six-range-blur' }) sixBlur: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control gains focus. */\n @Event({ eventName: 'six-range-focus' }) sixFocus: EventEmitter<EmptyPayload>;\n\n /** default value the slider will be reverted to when reset is executed */\n private defaultValue = 0;\n\n @Watch('label')\n @Watch('errorText')\n @Watch('helpText')\n handleLabelChange() {\n this.handleSlotChange();\n }\n\n @Watch('value')\n handleValueChange() {\n if (this.input) {\n this.input.value = this.value as any;\n this.calculateColorRunnableTrack();\n }\n // In rare cases, the watcher may be called before render so we need to make sure the input exists\n this.invalid = this.input ? !this.input.checkValidity() : false;\n }\n\n connectedCallback() {\n this.handleInput = this.handleInput.bind(this);\n this.handleBlur = this.handleBlur.bind(this);\n this.handleFocus = this.handleFocus.bind(this);\n this.handleSlotChange = this.handleSlotChange.bind(this);\n this.handleTouchStart = this.handleTouchStart.bind(this);\n\n this.host.shadowRoot.addEventListener('slotchange', this.handleSlotChange);\n }\n\n componentWillLoad() {\n if (this.value === undefined || this.value === null) this.value = this.min;\n if (this.value < this.min) this.value = this.min;\n if (this.value > this.max) this.value = this.max;\n this.defaultValue = this.value;\n\n this.handleSlotChange();\n }\n\n componentDidLoad() {\n this.syncTooltip();\n this.calculateColorRunnableTrack();\n this.resizeObserver = new ResizeObserver(() => this.syncTooltip());\n this.eventListeners.add(this.input, 'invalid', (event) => {\n if (this.customValidation || (!this.hasErrorTextSlot && !this.errorText && !this.customErrorText)) {\n this.customErrorText = this.input.validationMessage;\n }\n event.preventDefault();\n });\n }\n\n disconnectedCallback() {\n this.host.shadowRoot.removeEventListener('slotchange', this.handleSlotChange);\n this.eventListeners.removeAll();\n }\n\n /** Sets focus on the input. */\n @Method()\n async setFocus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /** Removes focus from the input. */\n @Method()\n async removeFocus() {\n this.input.blur();\n }\n\n /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */\n @Method()\n async setCustomValidity(message: string) {\n this.customErrorText = '';\n this.customValidation = message !== '';\n this.input.setCustomValidity(message);\n this.invalid = !this.input.checkValidity();\n }\n\n /** Resets the formcontrol */\n @Method()\n async reset() {\n this.value = this.defaultValue;\n this.customErrorText = '';\n this.customValidation = false;\n this.input.setCustomValidity('');\n this.invalid = false;\n }\n\n handleInput() {\n this.value = Number(this.input.value);\n this.sixChange.emit();\n\n requestAnimationFrame(() => this.syncTooltip());\n requestAnimationFrame(() => this.calculateColorRunnableTrack());\n }\n\n handleBlur() {\n this.hasFocus = false;\n this.hasTooltip = false;\n this.sixBlur.emit();\n this.resizeObserver.unobserve(this.input);\n }\n\n handleFocus() {\n this.hasFocus = true;\n this.hasTooltip = true;\n this.sixFocus.emit();\n this.resizeObserver.observe(this.input);\n }\n\n handleSlotChange() {\n this.hasHelpTextSlot = hasSlot(this.host, 'help-text');\n this.hasErrorTextSlot = hasSlot(this.host, 'error-text');\n this.hasLabelSlot = hasSlot(this.host, 'label');\n }\n\n handleTouchStart() {\n this.setFocus();\n }\n\n displayError() {\n return this.invalid && (!this.errorOnBlur || !this.hasFocus);\n }\n\n syncTooltip() {\n if (this.tooltip !== 'none') {\n const percent = Math.max(0, (this.value - this.min) / (this.max - this.min));\n const inputWidth = this.input.offsetWidth;\n const tooltipWidth = this.output.offsetWidth;\n const thumbSize = getComputedStyle(this.input).getPropertyValue('--thumb-size');\n const x = `calc(${inputWidth * percent}px - calc(calc(${percent} * ${thumbSize}) - calc(${thumbSize} / 2)))`;\n this.output.style.transform = `translateX(${x})`;\n this.output.style.marginLeft = `-${tooltipWidth / 2}px`;\n }\n }\n\n /**\n * For Firefox this functionality is not needed because it is supported by standard CSS.\n */\n calculateColorRunnableTrack() {\n if (!this.isFirefox()) {\n const value = parseInt(this.input.value, 10);\n const min = parseInt(this.input.min, 10);\n const max = parseInt(this.input.max, 10);\n const percent = Math.ceil(((value - min) / (max - min)) * 100);\n this.input.style.background =\n '-webkit-linear-gradient(left, var(--track-color) 0%, var(--track-color) ' +\n percent +\n '%, var(--six-color-web-rock-300) ' +\n percent +\n '%)';\n }\n }\n\n isFirefox() {\n return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;\n }\n\n render() {\n return (\n <FormControl\n inputId={this.inputId}\n label={this.label}\n labelId={this.labelId}\n hasLabelSlot={this.hasLabelSlot}\n helpTextId={this.helpTextId}\n helpText={this.helpText}\n hasHelpTextSlot={this.hasHelpTextSlot}\n size=\"medium\"\n errorTextId={this.errorTextId}\n errorText={this.customErrorText ? this.customErrorText : this.errorText}\n hasErrorTextSlot={this.hasErrorTextSlot}\n disabled={this.disabled}\n required={this.required}\n displayError={this.displayError()}\n >\n <div\n part=\"base\"\n class={{\n range: true,\n\n // States\n 'range--disabled': this.disabled,\n 'range--focused': this.hasFocus,\n 'range--tooltip-visible': this.hasTooltip,\n 'range--tooltip-top': this.tooltip === 'top',\n 'range--tooltip-bottom': this.tooltip === 'bottom',\n }}\n onTouchStart={this.handleTouchStart}\n >\n <input\n part=\"input\"\n ref={(el) => (this.input = el)}\n type=\"range\"\n class=\"range__control\"\n name={this.name}\n disabled={this.disabled}\n min={this.min}\n max={this.max}\n step={this.step}\n value={this.value}\n onInput={this.handleInput}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n />\n {this.tooltip !== 'none' && (\n <output part=\"tooltip\" ref={(el) => (this.output = el)} class=\"range__tooltip\">\n {this.tooltipFormatter(this.value)}\n </output>\n )}\n </div>\n </FormControl>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"six-range.js","sourceRoot":"","sources":["../../../src/components/six-range/six-range.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,WAAW,MAAM,uDAAuD,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX;;;;;;;;;;;;;GAaG;AAMH,MAAM,OAAO,QAAQ;;IACX,YAAO,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC;IAC1B,YAAO,GAAG,eAAe,EAAE,EAAE,CAAC;IAC9B,eAAU,GAAG,mBAAmB,EAAE,EAAE,CAAC;IACrC,oBAAe,GAAG,EAAE,CAAC;IACrB,qBAAgB,GAAG,KAAK,CAAC;IACzB,gB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Event, EventEmitter, h, Method, Prop, State, Watch } from '@stencil/core';\nimport FormControl from '../../functional-components/form-control/form-control';\nimport { hasSlot } from '../../utils/slot';\nimport { EmptyPayload } from '../../utils/types';\nimport { EventListeners } from '../../utils/event-listeners';\n\nlet id = 0;\n\n/**\n * @since 1.0\n * @status stable\n *\n * Forked from https://github.com/shoelace-style/shoelace version v2.0.0-beta27.\n *\n * @slot label - The input's label. Alternatively, you can use the label prop.\n * @slot help-text - Help text that describes how to use the input. Alternatively, you can use the help-text prop.\n * @slot error-text - Error text that is shown for validation errors. Alternatively, you can use the error-text prop.\n *\n * @part base - The component's base wrapper.\n * @part input - The native range input.\n * @part tooltip - The range tooltip.\n */\n@Component({\n tag: 'six-range',\n styleUrl: 'six-range.scss',\n shadow: true,\n})\nexport class SixRange {\n private inputId = `input-${++id}`;\n private labelId = `input-label-${id}`;\n private helpTextId = `input-help-text-${id}`;\n private customErrorText = '';\n private customValidation = false;\n private errorTextId = `input-error-text-${id}`;\n private eventListeners = new EventListeners();\n private resizeObserver?: ResizeObserver;\n\n private output?: HTMLElement;\n private nativeInput?: HTMLInputElement;\n\n @Element() host!: HTMLSixRangeElement;\n\n @State() hasFocus = false;\n @State() hasHelpTextSlot = false;\n @State() hasLabelSlot = false;\n @State() hasErrorTextSlot = false;\n @State() hasTooltip = false;\n\n /** The input's name attribute. */\n @Prop() name = '';\n\n /** The input's value attribute. */\n @Prop({ mutable: true }) value = 0;\n\n /** Set to true to make the input a required field. */\n @Prop({ reflect: true }) required = false;\n\n /** The range's label. Alternatively, you can use the label slot. */\n @Prop() label = '';\n\n /** The range's help text. Alternatively, you can use the help-text slot. */\n @Prop() helpText = '';\n\n /** The input's error text. Alternatively, you can use the error-text slot. */\n @Prop() errorText = '';\n\n /** Set to true to disable the input. */\n @Prop() disabled = false;\n\n /**\n * This will be true when the control is in an invalid state. Validity in range inputs is determined by the message\n * provided by the `setCustomValidity` method.\n */\n @Prop({ mutable: true, reflect: true }) invalid = false;\n\n /** The input's min attribute. */\n @Prop() min = 0;\n\n /** The input's max attribute. */\n @Prop() max = 100;\n\n /** The input's step attribute. */\n @Prop() step = 1;\n\n /** The preferred placedment of the tooltip. */\n @Prop() tooltip: 'top' | 'bottom' | 'none' = 'top';\n\n /** A function used to format the tooltip's value. */\n @Prop() tooltipFormatter = (value: number) => value.toString();\n\n /** Set to display the error text on blur and not when typing */\n @Prop() errorOnBlur = false;\n\n /** Emitted when the control's value changes. */\n @Event({ eventName: 'six-range-change' }) sixChange!: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control loses focus. */\n @Event({ eventName: 'six-range-blur' }) sixBlur!: EventEmitter<EmptyPayload>;\n\n /** Emitted when the control gains focus. */\n @Event({ eventName: 'six-range-focus' }) sixFocus!: EventEmitter<EmptyPayload>;\n\n /** default value the slider will be reverted to when reset is executed */\n private defaultValue = 0;\n\n @Watch('label')\n @Watch('errorText')\n @Watch('helpText')\n handleLabelChange() {\n this.handleSlotChange();\n }\n\n @Watch('value')\n @Watch('min')\n @Watch('max')\n handleValueChange() {\n this.update();\n if (this.nativeInput != null) {\n this.invalid = !this.nativeInput.checkValidity();\n }\n }\n\n connectedCallback() {\n this.host.shadowRoot?.addEventListener('slotchange', this.handleSlotChange);\n }\n\n componentWillLoad() {\n this.update();\n this.defaultValue = this.value;\n this.handleSlotChange();\n }\n\n componentDidLoad() {\n const nativeInput = this.nativeInput;\n if (nativeInput == null) {\n return;\n }\n this.update();\n this.resizeObserver = new ResizeObserver(() => this.update());\n this.eventListeners.add(nativeInput, 'invalid', (event) => {\n if (this.customValidation || (!this.hasErrorTextSlot && this.errorText === '' && this.customErrorText === '')) {\n this.customErrorText = nativeInput.validationMessage;\n }\n event.preventDefault();\n });\n }\n\n disconnectedCallback() {\n this.host.shadowRoot?.removeEventListener('slotchange', this.handleSlotChange);\n this.eventListeners.removeAll();\n }\n\n /** Sets focus on the input. */\n @Method()\n async setFocus(options?: FocusOptions) {\n this.nativeInput?.focus(options);\n }\n\n /** Removes focus from the input. */\n @Method()\n async removeFocus() {\n this.nativeInput?.blur();\n }\n\n /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */\n @Method()\n async setCustomValidity(message: string) {\n this.customErrorText = '';\n this.customValidation = message !== '';\n if (this.nativeInput != null) {\n this.nativeInput.setCustomValidity(message);\n this.invalid = !this.nativeInput.checkValidity();\n }\n }\n\n /** Resets the formcontrol */\n @Method()\n async reset() {\n this.value = this.defaultValue;\n this.customErrorText = '';\n this.customValidation = false;\n this.nativeInput?.setCustomValidity('');\n this.invalid = false;\n }\n\n private handleInput = () => {\n if (this.nativeInput != null) {\n this.update(parseFloat(this.nativeInput.value));\n }\n requestAnimationFrame(() => {\n this.sixChange.emit();\n });\n };\n\n private handleBlur = () => {\n this.hasFocus = false;\n this.hasTooltip = false;\n this.sixBlur.emit();\n if (this.nativeInput != null) {\n this.resizeObserver?.unobserve(this.nativeInput);\n }\n };\n\n private handleFocus = () => {\n this.hasFocus = true;\n this.hasTooltip = true;\n this.sixFocus.emit();\n if (this.nativeInput != null) {\n this.resizeObserver?.observe(this.nativeInput);\n }\n };\n\n private handleSlotChange = () => {\n this.hasHelpTextSlot = hasSlot(this.host, 'help-text');\n this.hasErrorTextSlot = hasSlot(this.host, 'error-text');\n this.hasLabelSlot = hasSlot(this.host, 'label');\n };\n\n private handleTouchStart = () => {\n this.setFocus();\n };\n\n private displayError() {\n return this.invalid && (!this.errorOnBlur || !this.hasFocus);\n }\n\n private syncTooltip(min: number, max: number, value: number) {\n if (this.tooltip !== 'none' && this.nativeInput != null && this.output != null) {\n const percent = Math.max(0, (value - min) / (max - min));\n const inputWidth = this.nativeInput.offsetWidth;\n const tooltipWidth = this.output.offsetWidth;\n const thumbSize = getComputedStyle(this.nativeInput).getPropertyValue('--thumb-size');\n const x = `calc(${inputWidth * percent}px - calc(calc(${percent} * ${thumbSize}) - calc(${thumbSize} / 2)))`;\n this.output.style.transform = `translateX(${x})`;\n this.output.style.marginLeft = `-${tooltipWidth / 2}px`;\n }\n }\n\n private isFirefox() {\n return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;\n }\n\n private update(updateValue?: number) {\n if (updateValue != null) {\n this.value = updateValue;\n }\n\n const min = Number(this.min) ?? 0;\n const max = Number(this.max) ?? 0;\n let value;\n const parsedValue = parseFloat(this.value as never);\n if (isNaN(parsedValue)) {\n value = this.getDefaultValue(min, max);\n } else {\n value = parsedValue;\n }\n\n if (this.nativeInput != null) {\n // The value may have constraints, so we set the native control's\n // value and sync it back to ensure it adheres to min, max, and step\n // properly.\n this.nativeInput.value = value.toString();\n this.value = parseFloat(this.nativeInput.value);\n } else {\n this.value = value;\n }\n this.calculateColorRunnableTrack(min, max, this.value);\n this.syncTooltip(min, max, this.value);\n }\n\n /**\n * from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#value\n */\n private getDefaultValue(min: number, max: number): number {\n return max < min ? min : min + (max - min) / 2;\n }\n\n /**\n * For Firefox this functionality is not needed because it is supported by standard CSS.\n */\n private calculateColorRunnableTrack(min: number, max: number, value: number) {\n if (!this.isFirefox() && this.nativeInput != null) {\n const percent = Math.ceil(((value - min) / (max - min)) * 100);\n this.nativeInput.style.background =\n '-webkit-linear-gradient(left, var(--track-color) 0%, var(--track-color) ' +\n percent +\n '%, var(--six-color-web-rock-300) ' +\n percent +\n '%)';\n }\n }\n\n render() {\n return (\n <FormControl\n inputId={this.inputId}\n label={this.label}\n labelId={this.labelId}\n hasLabelSlot={this.hasLabelSlot}\n helpTextId={this.helpTextId}\n helpText={this.helpText}\n hasHelpTextSlot={this.hasHelpTextSlot}\n size=\"medium\"\n errorTextId={this.errorTextId}\n errorText={this.customErrorText != null ? this.customErrorText : this.errorText}\n hasErrorTextSlot={this.hasErrorTextSlot}\n disabled={this.disabled}\n required={this.required}\n displayError={this.displayError()}\n >\n <div\n part=\"base\"\n class={{\n range: true,\n\n // States\n 'range--disabled': this.disabled,\n 'range--focused': this.hasFocus,\n 'range--tooltip-visible': this.hasTooltip,\n 'range--tooltip-top': this.tooltip === 'top',\n 'range--tooltip-bottom': this.tooltip === 'bottom',\n }}\n onTouchStart={this.handleTouchStart}\n >\n <input\n part=\"input\"\n ref={(el) => (this.nativeInput = el)}\n type=\"range\"\n class=\"range__control\"\n name={this.name}\n disabled={this.disabled}\n min={this.min}\n max={this.max}\n step={this.step}\n value={this.value}\n onInput={this.handleInput}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n />\n {this.tooltip !== 'none' && (\n <output part=\"tooltip\" ref={(el) => (this.output = el)} class=\"range__tooltip\">\n {this.tooltipFormatter(this.value)}\n </output>\n )}\n </div>\n </FormControl>\n );\n }\n}\n"]}
|