@eturnity/eturnity_reusable_components 1.1.96 → 1.1.99

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/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "useTabs": false,
5
+ "trailingComma": "none",
6
+ "printWidth": 80
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "1.1.96",
3
+ "version": "1.1.99",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
@@ -21,7 +21,6 @@
21
21
  :inputWidth="inputWidth"
22
22
  :minWidth="minWidth"
23
23
  :value="formatWithCurrency(value)"
24
- :hasLength="!!value && !!value.length"
25
24
  @blur="onInputBlur($event)"
26
25
  @focus="focusInput()"
27
26
  @keyup.enter="$emit('on-enter-click')"
@@ -86,7 +85,6 @@ const inputProps = {
86
85
  hasUnit: Boolean,
87
86
  inputWidth: String,
88
87
  minWidth: String,
89
- hasLength: Boolean,
90
88
  isDisabled: Boolean,
91
89
  noBorder: Boolean,
92
90
  textAlign: String,
@@ -99,8 +97,6 @@ const InputContainer = styled("input", inputProps)`
99
97
  ? "1px solid " + props.theme.colors.red
100
98
  : props.noBorder
101
99
  ? "none"
102
- : props.hasLength
103
- ? "1px solid " + props.theme.colors.black
104
100
  : "1px solid " + props.theme.colors.mediumGray};
105
101
  padding: ${(props) =>
106
102
  props.hasUnit ? "11px 40px 11px 10px" : "11px 5px 11px 10px"};
@@ -269,13 +265,13 @@ export default {
269
265
  },
270
266
  numberToStringEnabled: {
271
267
  required: false,
272
- default: true
273
- }
268
+ default: true,
269
+ },
274
270
  },
275
271
  methods: {
276
272
  onChangeHandler(event) {
277
273
  if (isNaN(event)) {
278
- event = ""
274
+ event = this.minNumber || this.minNumber === 0 ? this.minNumber : event
279
275
  }
280
276
  this.$emit("input-change", event)
281
277
  },
@@ -298,22 +294,27 @@ export default {
298
294
  } else {
299
295
  let num = stringToNumber({
300
296
  value: item,
301
- numberPrecision: this.numberPrecision,
297
+ numberPrecision: false,
302
298
  })
303
299
  return num
304
300
  }
305
301
  })
306
302
  let evaluated = eval(formatted.join(""))
303
+ evaluated = stringToNumber({
304
+ value: evaluated,
305
+ numberPrecision: this.numberPrecision,
306
+ })
307
307
  return evaluated
308
308
  },
309
309
  onInputBlur(e) {
310
310
  this.isFocused = false
311
311
  let value = e.target.value
312
312
  let evaluatedInput = this.onEvaluateCode(value)
313
- this.onChangeHandler(evaluatedInput)
314
- if ((value && value.length) || this.minNumber !== null) {
313
+ this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
314
+ if ((evaluatedInput && value.length) || this.minNumber !== null) {
315
315
  this.textInput = numberToString({
316
- value: value && value.length ? evaluatedInput : this.minNumber,
316
+ value:
317
+ evaluatedInput && value.length ? evaluatedInput : this.minNumber,
317
318
  numberPrecision: this.numberPrecision,
318
319
  })
319
320
  }
@@ -342,19 +343,23 @@ export default {
342
343
  ? this.minNumber
343
344
  : ""
344
345
  if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
345
- let input = this.numberToStringEnabled ? numberToString({
346
- value: adjustedMinValue,
347
- numberPrecision: this.numberPrecision,
348
- }) : adjustedMinValue
346
+ let input = this.numberToStringEnabled
347
+ ? numberToString({
348
+ value: adjustedMinValue,
349
+ numberPrecision: this.numberPrecision,
350
+ })
351
+ : adjustedMinValue
349
352
  let unit = this.showLinearUnitName ? "" : this.unitName
350
353
  return input + " " + unit
351
354
  } else if (!adjustedMinValue && adjustedMinValue !== 0) {
352
355
  return ""
353
356
  } else {
354
- return this.numberToStringEnabled ? numberToString({
355
- value: adjustedMinValue,
356
- numberPrecision: this.numberPrecision,
357
- }) : adjustedMinValue
357
+ return this.numberToStringEnabled
358
+ ? numberToString({
359
+ value: adjustedMinValue,
360
+ numberPrecision: this.numberPrecision,
361
+ })
362
+ : adjustedMinValue
358
363
  }
359
364
  },
360
365
  },
@@ -218,6 +218,7 @@ const ComponentItem = styled("td", ItemAttrs)`
218
218
  &.table-dropdown-item {
219
219
  background-clip: content-box;
220
220
  padding: 8px 0 7px 0 !important;
221
+ vertical-align: middle;
221
222
 
222
223
  @media not all and (min-resolution: 0.001dpcm) {
223
224
  @supports (-webkit-appearance: none) {
@@ -1,79 +1,88 @@
1
- export const stringToNumber = ({ value, numberPrecision, allowNegative }) => {
1
+ export const stringToNumber = ({
2
+ value,
3
+ numberPrecision = false,
4
+ allowNegative
5
+ }) => {
2
6
  // This is for saving. It converts our input string to a readable number
3
7
  let newVal = value.toString()
4
- const selectedLang = localStorage.getItem("lang")
8
+ const selectedLang = localStorage.getItem('lang')
5
9
  // The first replace will replace not allowed characters with a blank
6
10
  if (
7
- selectedLang === "de-DE" ||
8
- selectedLang === "no-no" ||
9
- selectedLang === "da-dk" ||
10
- selectedLang === "de-lu" ||
11
- selectedLang === "de-be" ||
12
- selectedLang === "es-es" ||
13
- selectedLang === "de"
11
+ selectedLang === 'de-DE' ||
12
+ selectedLang === 'no-no' ||
13
+ selectedLang === 'da-dk' ||
14
+ selectedLang === 'de-lu' ||
15
+ selectedLang === 'de-be' ||
16
+ selectedLang === 'es-es' ||
17
+ selectedLang === 'de'
14
18
  ) {
15
19
  // replace dots with blank, and commas with a dot: 1.234,56 --> 1234.56
16
20
  if (allowNegative) {
17
21
  newVal = newVal
18
- .replace(/[^\d-.,']/g, "")
19
- .replace(/[.\s]/g, "")
20
- .replace(/[,\s]/, ".")
22
+ .replace(/[^\d-.,']/g, '')
23
+ .replace(/[.\s]/g, '')
24
+ .replace(/[,\s]/, '.')
21
25
  } else {
22
26
  newVal = newVal
23
- .replace(/[^\d.,']/g, "")
24
- .replace(/[.\s]/g, "")
25
- .replace(/[,\s]/, ".")
27
+ .replace(/[^\d.,']/g, '')
28
+ .replace(/[.\s]/g, '')
29
+ .replace(/[,\s]/, '.')
26
30
  }
27
- } else if (selectedLang === "en-us") {
31
+ } else if (selectedLang === 'en-us') {
28
32
  // replace commas with blank: 1,234.56 --> 1234.56
29
33
  if (allowNegative) {
30
- newVal = newVal.replace(/[^\d-.,']/g, "").replace(/[,\s]/g, "")
34
+ newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '')
31
35
  } else {
32
- newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
36
+ newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '')
33
37
  }
34
38
  } else if (
35
- selectedLang === "de-ch" ||
36
- selectedLang === "fr-ch" ||
37
- selectedLang === "it-ch"
39
+ selectedLang === 'de-ch' ||
40
+ selectedLang === 'fr-ch' ||
41
+ selectedLang === 'it-ch'
38
42
  ) {
39
43
  // replace ' with blank: 1'234.56 --> 1234.56
40
44
  if (allowNegative) {
41
- newVal = newVal.replace(/[^\d-.,']/g, "").replace(/['\s]/g, "")
45
+ newVal = newVal.replace(/[^\d-.,']/g, '').replace(/['\s]/g, '')
42
46
  } else {
43
- newVal = newVal.replace(/[^\d.,']/g, "").replace(/['\s]/g, "")
47
+ newVal = newVal.replace(/[^\d.,']/g, '').replace(/['\s]/g, '')
44
48
  }
45
49
  } else if (
46
- selectedLang === "fr-fr" ||
47
- selectedLang === "fr-be" ||
48
- selectedLang === "fr-lu" ||
49
- selectedLang === "sv-se" ||
50
- selectedLang === "pt-pt" ||
51
- selectedLang === "fr"
50
+ selectedLang === 'fr-fr' ||
51
+ selectedLang === 'fr-be' ||
52
+ selectedLang === 'fr-lu' ||
53
+ selectedLang === 'sv-se' ||
54
+ selectedLang === 'pt-pt' ||
55
+ selectedLang === 'fr'
52
56
  ) {
53
57
  // replace space with blank, and commas with dot: 1 234,56 --> 1234.56
54
58
  if (allowNegative) {
55
- newVal = newVal.replace(/[^\d-.,']/g, "").replace(/[,\s]/g, ".")
59
+ newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '.')
56
60
  } else {
57
- newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, ".")
61
+ newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '.')
58
62
  }
59
63
  } else {
60
64
  // en-US as default: 1,234.56 --> 1234.56
61
65
  if (allowNegative) {
62
- newVal = newVal.replace(/[^\d-.,']/g, "").replace(/[,\s]/g, "")
66
+ newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '')
63
67
  } else {
64
- newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
68
+ newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '')
65
69
  }
66
70
  }
67
- newVal = parseFloat(newVal).toFixed(numberPrecision)
71
+ newVal = parseFloat(newVal)
72
+ if (numberPrecision !== false) {
73
+ newVal = newVal.toFixed(numberPrecision)
74
+ }
68
75
  return parseFloat(newVal)
69
76
  }
70
77
 
71
78
  export const numberToString = ({ value, numberPrecision }) => {
72
- let selectedLang = localStorage.getItem("lang")
73
- ? localStorage.getItem("lang") === 'fr-lu' ? 'fr-fr' : localStorage.getItem("lang")
74
- : "en-US"
79
+ let selectedLang = localStorage.getItem('lang')
80
+ ? localStorage.getItem('lang') === 'fr-lu'
81
+ ? 'fr-fr'
82
+ : localStorage.getItem('lang')
83
+ : 'en-US'
75
84
  return value.toLocaleString(selectedLang, {
76
85
  minimumFractionDigits: numberPrecision,
77
- maximumFractionDigits: numberPrecision,
86
+ maximumFractionDigits: numberPrecision
78
87
  })
79
88
  }