@tagplus/components 4.0.1 → 4.0.3

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
@@ -8,7 +8,7 @@
8
8
  "email": "bruno@tagplus.com.br"
9
9
  }
10
10
  ],
11
- "version": "4.0.1",
11
+ "version": "4.0.3",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -1,4 +1,3 @@
1
-
2
1
  <script>
3
2
  import { Steps } from 'element-ui'
4
3
 
@@ -16,8 +16,7 @@ export default {
16
16
  default: false
17
17
  },
18
18
 
19
- valorCusto: {
20
- type: Boolean,
19
+ customPrecision: {
21
20
  default: false
22
21
  }
23
22
  },
@@ -33,21 +32,21 @@ export default {
33
32
  immediate: true,
34
33
  handler (newValue, oldValue) {
35
34
  if (newValue === '' && this.allowEmpty) { this.formattedValue = ''; return }
36
- this.formattedValue = formatMoney(newValue, true, this.locale, this.valorCusto)
35
+ this.formattedValue = formatMoney(newValue, true, this.locale, this.customPrecision)
37
36
  }
38
37
  }
39
38
  },
40
39
 
41
40
  methods: {
42
41
  input (evt) {
43
- this.formattedValue = formatMoney(evt, true, this.locale, this.valorCusto)
44
- const moneyFormatado = formatMoney(evt, false, this.locale, this.valorCusto)
42
+ this.formattedValue = formatMoney(evt, true, this.locale, this.customPrecision)
43
+ const moneyFormatado = formatMoney(evt, false, this.locale, this.customPrecision)
45
44
 
46
45
  this.$emit('input', moneyFormatado)
47
46
  },
48
47
 
49
48
  handleChange (evt) {
50
- this.$emit('change', formatMoney(evt, false, this.locale, this.valorCusto))
49
+ this.$emit('change', formatMoney(evt, false, this.locale, this.customPrecision))
51
50
  }
52
51
  }
53
52
 
@@ -34,11 +34,17 @@ function unformat (input, precision = defaults.precision) {
34
34
  * @param {Float} input Valor
35
35
  * @param {Boolean} toString Se o retorno será float ou string
36
36
  * @param {Object} locale Configuração de localidade para saber número de casas decimais (precision) e caracter de decimal (decimal)
37
+ * @param {Number} customPrecision Caso o usuário queira sobrescrever o número de casas decimais (precision) da configuração de localidade.
37
38
  * @returns
38
39
  */
39
- function formatMoney (input, toString = false, locale = defaults, valorCusto = false) {
40
+ function formatMoney (input, toString = false, locale = defaults, customPrecision = false) {
40
41
  let inputString = (`${input}`)
41
42
 
43
+ // Caso componente receba props de precisão customizada (ex.: tp-money com precisão diferente da locale padrão).
44
+ if (customPrecision) {
45
+ locale.number.precision = customPrecision
46
+ }
47
+
42
48
  // Impede de digitar . ou , porque o formatador já adiciona
43
49
  if ((inputString.slice(-1).match(/[.,]/))) {
44
50
  inputString = inputString.substring(0, inputString.length - 1)
@@ -50,7 +56,7 @@ function formatMoney (input, toString = false, locale = defaults, valorCusto = f
50
56
  input = completeZeros(inputString, locale)
51
57
  }
52
58
 
53
- const precision = valorCusto ? 3 : locale.number.precision
59
+ const precision = customPrecision || locale.number.precision
54
60
  const numbers = onlyNumbers(input, precision)
55
61
  const currency = numbersToCurrency(numbers, precision)
56
62