@weni/unnnic-system 1.24.21 → 1.24.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weni/unnnic-system",
3
- "version": "1.24.21",
3
+ "version": "1.24.22",
4
4
  "main": "./dist/unnnic.common.js",
5
5
  "files": [
6
6
  "dist/*",
@@ -123,10 +123,8 @@ export default {
123
123
  window.removeEventListener('resize', this.handleResize);
124
124
  },
125
125
  mounted() {
126
- const fallbackLabelWidth = 32 + this.sliderVal.toString().length * 4.5;
127
- this.sliderWidth = this.$refs.input.clientWidth;
128
- this.labelWidth = this.$refs.tooltip.$refs.label.clientWidth || fallbackLabelWidth;
129
- this.tooltipOffset = this.getNewTooltipPosition();
126
+ this.checkInputWidth();
127
+ this.checkTooltipLabelWidth();
130
128
  },
131
129
  watch: {
132
130
  sliderVal: {
@@ -146,8 +144,13 @@ export default {
146
144
  },
147
145
  methods: {
148
146
  configureTooltip() {
149
- this.sliderWidth = this.$refs.input.clientWidth;
150
- this.labelWidth = this.$refs.tooltip.$refs.label.clientWidth;
147
+ if (this.$refs.input) {
148
+ this.sliderWidth = this.$refs.input.clientWidth;
149
+ }
150
+ const tooltipLabel = this.$refs.tooltip?.$refs.label;
151
+ if (tooltipLabel) {
152
+ this.labelWidth = tooltipLabel.clientWidth || 32;
153
+ }
151
154
  this.tooltipOffset = this.getNewTooltipPosition();
152
155
  },
153
156
  handleResize() {
@@ -162,9 +165,40 @@ export default {
162
165
 
163
166
  this.handleValueChange();
164
167
  },
168
+ checkInputWidth() {
169
+ const intervalId = setInterval(() => {
170
+ const inputElement = this.$refs.input;
171
+ if (inputElement) {
172
+ const { offsetWidth } = inputElement;
173
+ if (offsetWidth > 0) {
174
+ this.sliderWidth = offsetWidth;
175
+ this.configureTooltip();
176
+ clearInterval(intervalId);
177
+ }
178
+ }
179
+ }, 100);
180
+ },
181
+ checkTooltipLabelWidth() {
182
+ const intervalId = setInterval(() => {
183
+ const tooltipLabel = this.$refs.tooltip?.$refs.label;
184
+ if (!tooltipLabel) {
185
+ return;
186
+ }
187
+
188
+ const { clientWidth } = tooltipLabel;
189
+ if (clientWidth > 0) {
190
+ this.labelWidth = clientWidth;
191
+ this.configureTooltip();
192
+ clearInterval(intervalId);
193
+ }
194
+ }, 100);
195
+ },
165
196
  getNewTooltipPosition() {
166
- const haldThumbWidth = 12 / 2;
167
- const halfLabelWidth = (this.labelWidth === 0 ? 32 : this.labelWidth) / 2;
197
+ if (this.sliderWidth === 0 || this.labelWidth === 0) {
198
+ return 0;
199
+ }
200
+ const halfThumbWidth = 12 / 2;
201
+ const halfLabelWidth = this.labelWidth / 2 || 16;
168
202
  const centerPosition = this.sliderWidth / 2;
169
203
 
170
204
  let percentOfRange = (this.sliderVal - this.minValue) / (this.maxValue - this.minValue);
@@ -175,7 +209,7 @@ export default {
175
209
  const valuePXPosition = percentOfRange * this.sliderWidth;
176
210
  const distFromCenter = valuePXPosition - centerPosition;
177
211
  const percentDistFromCenter = distFromCenter / centerPosition;
178
- const offset = percentDistFromCenter * haldThumbWidth;
212
+ const offset = percentDistFromCenter * halfThumbWidth;
179
213
 
180
214
  const finalLabelPosition = valuePXPosition - halfLabelWidth - offset;
181
215
  return finalLabelPosition;