@eturnity/eturnity_reusable_components 8.16.9-EPDM-6306.1 → 8.16.9-EPDM-15095.0

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": "@eturnity/eturnity_reusable_components",
3
- "version": "8.16.9-EPDM-6306.1",
3
+ "version": "8.16.9-EPDM-15095.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -123,7 +123,11 @@
123
123
  return this.type === 'error_minor'
124
124
  },
125
125
  iconName() {
126
- return this.type === 'warning' ? 'warning_triangle' : 'info'
126
+ return this.type === 'warning'
127
+ ? 'warning_triangle'
128
+ : this.isErrorMinor
129
+ ? 'erase'
130
+ : 'info'
127
131
  },
128
132
  presetStyles() {
129
133
  // the types that doesn't have explicit border anyway have it transparent
@@ -142,8 +146,8 @@
142
146
  stylesCollection.iconColor = theme.semanticColors.teal[800]
143
147
  } else if (this.isErrorMinor) {
144
148
  stylesCollection.borderStyle = 'dashed'
145
- stylesCollection.borderColor = theme.colors.pureRed
146
- stylesCollection.iconColor = theme.colors.pureRed
149
+ stylesCollection.borderColor = theme.colors.grey4
150
+ stylesCollection.iconColor = theme.colors.red
147
151
  } else {
148
152
  stylesCollection.borderStyle = 'dashed'
149
153
  stylesCollection.borderColor = theme.colors.grey4
@@ -61,7 +61,7 @@
61
61
  :show-linear-unit-name="showLinearUnitName"
62
62
  :slot-size="slotSize"
63
63
  :text-align="textAlign"
64
- :value="formattedValue"
64
+ :value="formatWithCurrency(value)"
65
65
  @blur="onInputBlur($event)"
66
66
  @focus="focusInput()"
67
67
  @input="onInput($event)"
@@ -75,7 +75,7 @@
75
75
 
76
76
  <UnitContainer
77
77
  v-if="unitName && showLinearUnitName && !hasSlot"
78
- :has-length="hasLength"
78
+ :has-length="!!textInput.length"
79
79
  :is-error="isError"
80
80
  >{{ unitName }}</UnitContainer
81
81
  >
@@ -92,7 +92,7 @@
92
92
  :disabled="isSelectDisabled"
93
93
  :select-width="`${selectWidth}px`"
94
94
  :show-border="false"
95
- @input-change="handleSelectChange"
95
+ @input-change="$emit('select-change', $event)"
96
96
  >
97
97
  <template #selector>
98
98
  <SelectText>{{ getSelectValue }}</SelectText>
@@ -457,18 +457,8 @@
457
457
  background-color: ${({ theme }) => theme.colors.grey4};
458
458
  `
459
459
 
460
- const EVENT_TYPES = {
461
- INPUT_FOCUS: 'input-focus',
462
- INPUT_CHANGE: 'input-change',
463
- INPUT_BLUR: 'input-blur',
464
- PRESS_ENTER: 'on-enter-click',
465
- INPUT_DRAG: 'on-input-drag',
466
- SELECT_CHANGE: 'select-change',
467
- }
468
-
469
460
  export default {
470
461
  name: 'InputNumber',
471
- emits: [...Object.values(EVENT_TYPES)],
472
462
  components: {
473
463
  Container,
474
464
  InputContainer,
@@ -711,10 +701,9 @@
711
701
  },
712
702
  data() {
713
703
  return {
704
+ textInput: '',
714
705
  isFocused: false,
715
706
  warningIcon: warningIcon,
716
- inputValue: null,
717
- enteredValue: null,
718
707
  }
719
708
  },
720
709
  computed: {
@@ -737,14 +726,6 @@
737
726
 
738
727
  return item ? item.label : '-'
739
728
  },
740
- formattedValue() {
741
- return this.isFocused
742
- ? this.enteredValue
743
- : this.formatWithCurrency(this.value)
744
- },
745
- hasLength() {
746
- return this.formattedValue !== null && this.formattedValue.length > 0
747
- },
748
729
  },
749
730
  watch: {
750
731
  focus(value) {
@@ -755,19 +736,30 @@
755
736
  clearInput: function (value) {
756
737
  if (value) {
757
738
  // If the value is typed, then we should clear the textInput on Continue
758
- this.inputValue = ''
759
- this.enteredValue = ''
739
+ this.textInput = ''
760
740
  }
761
741
  },
762
- value: {
763
- immediate: true,
764
- handler(val) {
765
- if (this.value !== this.inputValue && !Number.isNaN(this.value)) {
766
- this.inputValue = this.value
767
- this.enteredValue = Number(this.value.toFixed(this.numberPrecision))
768
- }
769
- },
770
- },
742
+ },
743
+ created() {
744
+ if (this.value) {
745
+ this.textInput = numberToString({
746
+ value: this.value,
747
+ numberPrecision: this.numberPrecision,
748
+ minDecimals: this.minDecimals,
749
+ })
750
+ } else if (this.defaultNumber !== null) {
751
+ this.textInput = numberToString({
752
+ value: this.defaultNumber,
753
+ numberPrecision: this.numberPrecision,
754
+ minDecimals: this.minDecimals,
755
+ })
756
+ } else if (this.minNumber !== null) {
757
+ this.textInput = numberToString({
758
+ value: this.minNumber,
759
+ numberPrecision: this.numberPrecision,
760
+ minDecimals: this.minDecimals,
761
+ })
762
+ }
771
763
  },
772
764
  mounted() {
773
765
  if (this.focus) {
@@ -806,28 +798,29 @@
806
798
  }
807
799
  },
808
800
  onEnterPress() {
809
- this.$emit(EVENT_TYPES.PRESS_ENTER)
801
+ this.$emit('on-enter-click')
810
802
  this.$refs.inputField1.$el.blur()
811
803
  },
812
- onChangeHandler(value) {
813
- if (isNaN(value) || value === '') {
814
- value = this.defaultNumber
804
+ onChangeHandler(event) {
805
+ if (isNaN(event) || event === '') {
806
+ event = this.defaultNumber
815
807
  ? this.defaultNumber
816
808
  : this.minNumber || this.minNumber === 0
817
809
  ? this.minNumber
818
- : value
810
+ : event
819
811
  }
820
812
  if (!this.allowNegative) {
821
- value = Math.abs(value)
813
+ event = Math.abs(event)
822
814
  }
823
- value = parseFloat(value)
815
+ event = parseFloat(event)
824
816
  // Need to return an integer rather than a string
825
- return parseFloat(value)
817
+ this.$emit('input-change', event)
826
818
  },
827
- onEvaluateCode(value) {
819
+ onEvaluateCode(event) {
828
820
  // function to perform math on the code
829
821
  // filter the string in case of any malicious content
830
- let filtered = value.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
822
+ const val = event.target.value
823
+ let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
831
824
  filtered = filtered.split(/([-+*/()])/)
832
825
  let formatted = filtered.map((item) => {
833
826
  if (
@@ -885,32 +878,48 @@
885
878
  return array
886
879
  },
887
880
  onInput(event) {
888
- console.log('onInput', event.target.value)
889
- this.enteredValue = event.target.value
890
- if (!this.isFocused || this.enteredValue === this.inputValue) {
881
+ if (!this.isFocused) {
891
882
  return
892
883
  }
884
+ if (event.target.value === '') {
885
+ this.$emit('on-input', '')
886
+ }
893
887
  let evaluatedVal
894
888
  try {
895
- evaluatedVal = this.onEvaluateCode(String(this.enteredValue))
889
+ evaluatedVal = this.onEvaluateCode(event)
896
890
  } finally {
897
- this.inputValue = this.onChangeHandler(evaluatedVal)
898
-
899
- if (this.isFocused && typeof this.enteredValue !== 'number') {
900
- this.$emit(EVENT_TYPES.INPUT_CHANGE, this.inputValue)
891
+ if (evaluatedVal && this.value != evaluatedVal) {
892
+ this.$emit('on-input', evaluatedVal)
901
893
  }
902
894
  }
903
895
  this.textInput = evaluatedVal
904
896
  },
905
897
  onInputBlur(e) {
906
898
  this.isFocused = false
907
- if (!Number.isNaN(this.inputValue)) {
908
- this.enteredValue = this.inputValue
899
+ let value = e.target.value
900
+ let evaluatedInput = this.onEvaluateCode(e)
901
+ this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
902
+ if ((evaluatedInput && value.length) || this.minNumber !== null) {
903
+ this.textInput = numberToString({
904
+ value:
905
+ evaluatedInput && value.length
906
+ ? evaluatedInput
907
+ : this.defaultNumber
908
+ ? this.defaultNumber
909
+ : this.minNumber,
910
+ numberPrecision: this.numberPrecision,
911
+ minDecimals: this.minDecimals,
912
+ })
909
913
  }
910
- this.$emit(
911
- EVENT_TYPES.INPUT_BLUR,
912
- Number(this.onEvaluateCode(String(this.inputValue)))
913
- )
914
+ let adjustedMinValue =
915
+ evaluatedInput && evaluatedInput.length
916
+ ? evaluatedInput
917
+ : this.defaultNumber
918
+ ? this.defaultNumber
919
+ : this.minNumber || this.minNumber === 0
920
+ ? this.minNumber
921
+ : ''
922
+ this.$emit('input-blur', adjustedMinValue)
914
923
  },
915
924
  focusInput() {
916
925
  if (this.disabled) {
@@ -920,7 +929,7 @@
920
929
  this.$nextTick(() => {
921
930
  this.$refs.inputField1.$el.select()
922
931
  })
923
- this.$emit(EVENT_TYPES.INPUT_FOCUS, this.inputValue)
932
+ this.$emit('input-focus')
924
933
  },
925
934
  blurInput() {
926
935
  if (this.disabled) {
@@ -940,7 +949,7 @@
940
949
  : this.minNumber || this.minNumber === 0
941
950
  ? this.minNumber
942
951
  : ''
943
- if (adjustedMinValue || adjustedMinValue === 0) {
952
+ if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
944
953
  let input = this.numberToStringEnabled
945
954
  ? numberToString({
946
955
  value: adjustedMinValue,
@@ -953,8 +962,6 @@
953
962
  return input + ' ' + unit
954
963
  } else if (!adjustedMinValue && adjustedMinValue !== 0) {
955
964
  return ''
956
- } else if (this.isFocused) {
957
- return value
958
965
  } else {
959
966
  return this.numberToStringEnabled
960
967
  ? numberToString({
@@ -975,7 +982,14 @@
975
982
  e.preventDefault()
976
983
  let value = parseFloat(this.value || 0)
977
984
  value += parseFloat(this.interactionStep) * parseInt(e.movementX)
978
- this.$emit(EVENT_TYPES.INPUT_DRAG, this.onChangeHandler(value))
985
+ this.$emit('on-input-drag', value)
986
+
987
+ this.textInput = numberToString({
988
+ value: value && value.length ? value : this.minNumber,
989
+ numberPrecision: this.numberPrecision,
990
+ minDecimals: this.minDecimals,
991
+ })
992
+ //this.value=value
979
993
  },
980
994
  stopInteract(e) {
981
995
  e.preventDefault()
@@ -983,9 +997,6 @@
983
997
  window.removeEventListener('mouseup', this.stopInteract, false)
984
998
  this.blurInput()
985
999
  },
986
- handleSelectChange(value) {
987
- this.$emit(EVENT_TYPES.SELECT_CHANGE, value)
988
- },
989
1000
  },
990
1001
  }
991
1002
  </script>
@@ -94,7 +94,7 @@ export const stringToNumber = ({
94
94
 
95
95
  export const numberToString = ({ value, numberPrecision, minDecimals }) => {
96
96
  const minimumRounding = minDecimals ? minDecimals : 0
97
- value = !Number.isNaN(parseFloat(value)) ? parseFloat(value) : 0
97
+ value = parseFloat(value)
98
98
  return value.toLocaleString(langForLocaleString(), {
99
99
  minimumFractionDigits: minimumRounding, // removing this for now. Why do we need this to be a minimum amount?
100
100
  maximumFractionDigits: