@thinkpixellab-public/px-vue 3.0.87 → 3.0.89

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.
@@ -7,7 +7,7 @@
7
7
  * classic - rotating semi-circle
8
8
  * dots - three dots that fade in and out in turn
9
9
 
10
- Size is derived from the current font size and color is derived from currentColor. These
10
+ Size is derived from the current font size and color is derived from var(--px-spinner-color). These
11
11
  properties (as well as a transform) can be set on the component itself without side effects.
12
12
 
13
13
  Future enhancements could include additional properties for controlling things like timing,
@@ -27,7 +27,10 @@ import PxBaseVisible from './PxBaseVisible.vue';
27
27
  export default {
28
28
  name: 'px-spinner',
29
29
  mixins: [PxBaseVariants, PxBaseVisible],
30
- props: { variant: { type: String, default: 'classic' } },
30
+ props: {
31
+ variant: { type: String, default: 'classic' },
32
+ duration: { type: Number, default: 2 },
33
+ },
31
34
  };
32
35
  </script>
33
36
 
@@ -39,6 +42,11 @@ export default {
39
42
  position: relative;
40
43
  pointer-events: none;
41
44
 
45
+ --px-spinner-dur: 2s;
46
+ --px-spinner-linewidth: 0.15em;
47
+ --px-spinner-color: currentColor;
48
+ --px-spinner-color-secondary: transparent;
49
+
42
50
  &__spinner {
43
51
  display: block;
44
52
  position: relative;
@@ -48,14 +56,15 @@ export default {
48
56
 
49
57
  &--classic & {
50
58
  &__spinner {
59
+ position: relative;
51
60
  width: 1.33em;
52
61
  height: 1.33em;
53
- border: 0.15em solid currentColor;
54
- border-bottom-color: transparent;
62
+ border: var(--px-spinner-linewidth) solid var(--px-spinner-color);
63
+ border-bottom-color: var(--px-spinner-color-secondary);
55
64
  border-radius: 50%;
56
65
  display: inline-block;
57
66
  box-sizing: border-box;
58
- animation: px-spinner-classic 1s linear infinite;
67
+ animation: px-spinner-classic var(--px-spinner-dur) linear infinite;
59
68
  }
60
69
  }
61
70
 
@@ -91,15 +100,15 @@ export default {
91
100
  height: 2.5em;
92
101
  border-radius: 50%;
93
102
  animation-fill-mode: both;
94
- animation: px-spinner-dots $dur infinite $ease-in-out-quart;
103
+ animation: px-spinner-dots var(--px-spinner-dur) infinite $ease-in-out-quart;
95
104
  }
96
105
  &__spinner {
97
106
  left: 5em;
98
- color: currentColor;
107
+ color: var(--px-spinner-color);
99
108
  position: relative;
100
109
  text-indent: -9999em;
101
110
  transform: translateZ(0);
102
- animation-delay: ($dur * -0.088888888);
111
+ animation-delay: calc((var(--px-spinner-dur) * -0.088888888));
103
112
  }
104
113
  &__spinner:before,
105
114
  &__spinner:after {
@@ -109,7 +118,7 @@ export default {
109
118
  }
110
119
  &__spinner:before {
111
120
  left: -5em;
112
- animation-delay: ($dur * -0.088888888 * 2);
121
+ animation-delay: calc((var(--px-spinner-dur) * -0.088888888 * 2));
113
122
  }
114
123
  &__spinner:after {
115
124
  left: 5em;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.87",
3
+ "version": "3.0.89",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",
package/utils/utils.js CHANGED
@@ -27,6 +27,16 @@ export default {
27
27
  return Array.isArray(value) ? value : [value];
28
28
  },
29
29
 
30
+ /**
31
+ * Returns a new array containing the specified number of items generated by the provided
32
+ * function.
33
+ * @param {*} count The number of items to be generated.
34
+ * @param {*} fn The function to be called to generate each item.
35
+ */
36
+ arrayFill: function (count, fn) {
37
+ return Array.from({ count }, (_, i) => fn(i));
38
+ },
39
+
30
40
  /**
31
41
  * Safely gets an item from an array, otherwise returns a fallback value.
32
42
  * @param {*} arr The array.
@@ -344,6 +354,53 @@ export default {
344
354
  });
345
355
  },
346
356
 
357
+ /**
358
+ * Converts a floating-point number to a string value based on a map where the keys are string
359
+ * values and the corresponding values define ranges in the format 'start, end'. Open-ended
360
+ * ranges can be specified by using `null` for the start or end value. This approach avoids
361
+ * ambiguity with negative numbers by using commas to separate the range values. If the input
362
+ * value does not fall within any of the defined ranges, a fallback value is returned.
363
+ *
364
+ * @param {number} value - The floating-point number to be converted.
365
+ * @param {Object} valueMap - An object where keys are string values and values define ranges in
366
+ * the format 'start, end'. Use `null` to specify an open-ended start or end of a range.
367
+ * @param {string} fallbackValue - The value to return if the input does not match any defined
368
+ * range.
369
+ * @returns {string} - The string value corresponding to the range within which the input value
370
+ * falls, or the fallback value.
371
+ *
372
+ * @example
373
+ * const valueMap = {
374
+ * 'low': 'null, 0.5',
375
+ * 'medium': '0.5, 1',
376
+ * 'high': '1, null'
377
+ * };
378
+ * const fallback = 'unknown';
379
+ *
380
+ * console.log(floatToEnum(0.25, valueMap, fallback)); // Expected "low"
381
+ * console.log(floatToEnum(0.75, valueMap, fallback)); // Expected "medium"
382
+ * console.log(floatToEnum(1.5, valueMap, fallback)); // Expected "high"
383
+ * console.log(floatToEnum(-1, valueMap, fallback)); // Expected "unknown"
384
+ **/
385
+
386
+ floatToEnum(value, valueMap, fallbackValue) {
387
+ const rangeRegex = /^\s*(null|[+-]?\d*(?:\.\d+)?)\s*,\s*(null|[+-]?\d*(?:\.\d+)?)\s*$/;
388
+
389
+ for (const [stringValue, range] of Object.entries(valueMap)) {
390
+ const match = range.match(rangeRegex);
391
+ if (!match) continue; // Skip invalid ranges
392
+
393
+ const start = match[1] !== 'null' ? parseFloat(match[1]) : -Infinity;
394
+ const end = match[2] !== 'null' ? parseFloat(match[2]) : Infinity;
395
+
396
+ if ((start === -Infinity || value >= start) && (end === Infinity || value < end)) {
397
+ return stringValue;
398
+ }
399
+ }
400
+
401
+ return fallbackValue;
402
+ },
403
+
347
404
  /**
348
405
  * Generate a 6 letter random sequence of letters and numbers, based on this:
349
406
  * https://stackoverflow.com/questions/6248666/how-to-generate-short-uid-like-ax4j9z-in-js