mediacube-ui 0.1.24 → 0.1.25

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": "mediacube-ui",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "Design system for Mediacube services",
5
5
  "author": "Mediacube",
6
6
  "private": false,
@@ -346,6 +346,13 @@ export default {
346
346
  type: Boolean,
347
347
  default: false,
348
348
  },
349
+ /**
350
+ * Свойство на ограничение количества символов после точки для числовых типов (num || amount_format)
351
+ */
352
+ maxDecimals: {
353
+ type: Number,
354
+ default: null,
355
+ },
349
356
  },
350
357
 
351
358
  data() {
@@ -509,13 +516,21 @@ export default {
509
516
  },
510
517
 
511
518
  methods: {
519
+ setDecimalsLimit(val) {
520
+ if (val && this.maxDecimals) {
521
+ const [integerPart, decimalPart] = val.split('.')
522
+ if(decimalPart?.length > this.maxDecimals) {
523
+ return `${integerPart}.${decimalPart.slice(0, this.maxDecimals)}`
524
+ }
525
+ }
526
+ return val
527
+ },
512
528
  prepareHandleInput(e) {
513
529
  let value = e.target.value
514
-
515
530
  switch (this.type) {
516
531
  case 'num':
517
- const [num] = /-?\d*[\.]?\d*/.exec(String(e.target.value)) || []
518
- value = num
532
+ value = this.this.setDecimalsLimit(num)
533
+ const [num] = /-?\d*[\.]?\d*/.exec(String(value)) || []
519
534
  e.target.value = num
520
535
  break
521
536
  case 'int':
@@ -524,9 +539,10 @@ export default {
524
539
  e.target.value = int
525
540
  break
526
541
  case 'amount_format':
542
+ value = this.setDecimalsLimit(value)
527
543
  const cursor_position = this.getCaretPos(e.target)?.start
528
544
 
529
- const prepared_value = this.formattedToNumber(e.target.value)
545
+ const prepared_value = this.formattedToNumber(value)
530
546
  value = prepared_value ? parseFloat(prepared_value) : null
531
547
  e.target.value = this.isRtl ? value : this.getAmountFormat(prepared_value)
532
548