@eturnity/eturnity_reusable_components 7.51.16-EPDM-12459.0 → 7.51.16-qa-16-01-14.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "7.51.16-EPDM-12459.0",
3
+ "version": "7.51.16-qa-16-01-14.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -57,7 +57,7 @@
57
57
  :show-linear-unit-name="showLinearUnitName"
58
58
  :slot-size="slotSize"
59
59
  :text-align="textAlign"
60
- :value="formatWithCurrency(value)"
60
+ :value="formattedValue"
61
61
  @blur="onInputBlur($event)"
62
62
  @focus="focusInput()"
63
63
  @input="onInput($event)"
@@ -71,7 +71,7 @@
71
71
 
72
72
  <UnitContainer
73
73
  v-if="unitName && showLinearUnitName && !hasSlot"
74
- :has-length="!!textInput.length"
74
+ :has-length="hasLength"
75
75
  :is-error="isError"
76
76
  >{{ unitName }}</UnitContainer
77
77
  >
@@ -88,7 +88,7 @@
88
88
  :disabled="isSelectDisabled"
89
89
  :select-width="`${selectWidth}px`"
90
90
  :show-border="false"
91
- @input-change="$emit('select-change', $event)"
91
+ @input-change="handleSelectChange"
92
92
  >
93
93
  <template #selector>
94
94
  <SelectText>{{ getSelectValue }}</SelectText>
@@ -446,8 +446,18 @@
446
446
  background-color: ${({ theme }) => theme.colors.grey4};
447
447
  `
448
448
 
449
+ const EVENT_TYPES = {
450
+ INPUT_FOCUS: 'input-focus',
451
+ INPUT_CHANGE: 'input-change',
452
+ INPUT_BLUR: 'input-blur',
453
+ PRESS_ENTER: 'on-enter-click',
454
+ INPUT_DRAG: 'on-input-drag',
455
+ SELECT_CHANGE: 'select-change',
456
+ }
457
+
449
458
  export default {
450
459
  name: 'InputNumber',
460
+ emits: [...Object.values(EVENT_TYPES)],
451
461
  components: {
452
462
  Container,
453
463
  InputContainer,
@@ -678,9 +688,10 @@
678
688
  },
679
689
  data() {
680
690
  return {
681
- textInput: '',
682
691
  isFocused: false,
683
692
  warningIcon: warningIcon,
693
+ inputValue: null,
694
+ enteredValue: null,
684
695
  }
685
696
  },
686
697
  computed: {
@@ -703,6 +714,14 @@
703
714
 
704
715
  return item ? item.label : '-'
705
716
  },
717
+ formattedValue() {
718
+ return this.isFocused
719
+ ? this.enteredValue
720
+ : this.formatWithCurrency(this.value)
721
+ },
722
+ hasLength() {
723
+ return this.formattedValue !== null && this.formattedValue.length > 0
724
+ },
706
725
  },
707
726
  watch: {
708
727
  focus(value) {
@@ -713,30 +732,19 @@
713
732
  clearInput: function (value) {
714
733
  if (value) {
715
734
  // If the value is typed, then we should clear the textInput on Continue
716
- this.textInput = ''
735
+ this.inputValue = ''
736
+ this.enteredValue = ''
717
737
  }
718
738
  },
719
- },
720
- created() {
721
- if (this.value) {
722
- this.textInput = numberToString({
723
- value: this.value,
724
- numberPrecision: this.numberPrecision,
725
- minDecimals: this.minDecimals,
726
- })
727
- } else if (this.defaultNumber !== null) {
728
- this.textInput = numberToString({
729
- value: this.defaultNumber,
730
- numberPrecision: this.numberPrecision,
731
- minDecimals: this.minDecimals,
732
- })
733
- } else if (this.minNumber !== null) {
734
- this.textInput = numberToString({
735
- value: this.minNumber,
736
- numberPrecision: this.numberPrecision,
737
- minDecimals: this.minDecimals,
738
- })
739
- }
739
+ value: {
740
+ immediate: true,
741
+ handler(val) {
742
+ if (this.value !== this.inputValue && !Number.isNaN(this.value)) {
743
+ this.inputValue = this.value
744
+ this.enteredValue = this.value
745
+ }
746
+ },
747
+ },
740
748
  },
741
749
  mounted() {
742
750
  if (this.focus) {
@@ -775,29 +783,28 @@
775
783
  }
776
784
  },
777
785
  onEnterPress() {
778
- this.$emit('on-enter-click')
786
+ this.$emit(EVENT_TYPES.PRESS_ENTER)
779
787
  this.$refs.inputField1.$el.blur()
780
788
  },
781
- onChangeHandler(event) {
782
- if (isNaN(event) || event === '') {
783
- event = this.defaultNumber
789
+ onChangeHandler(value) {
790
+ if (isNaN(value) || value === '') {
791
+ value = this.defaultNumber
784
792
  ? this.defaultNumber
785
793
  : this.minNumber || this.minNumber === 0
786
794
  ? this.minNumber
787
- : event
795
+ : value
788
796
  }
789
797
  if (!this.allowNegative) {
790
- event = Math.abs(event)
798
+ value = Math.abs(value)
791
799
  }
792
- event = parseFloat(event)
800
+ value = parseFloat(value)
793
801
  // Need to return an integer rather than a string
794
- this.$emit('input-change', event)
802
+ return parseFloat(value)
795
803
  },
796
- onEvaluateCode(event) {
804
+ onEvaluateCode(value) {
797
805
  // function to perform math on the code
798
806
  // filter the string in case of any malicious content
799
- const val = event.target.value
800
- let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
807
+ let filtered = value.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
801
808
  filtered = filtered.split(/([-+*/()])/)
802
809
  let formatted = filtered.map((item) => {
803
810
  if (
@@ -855,48 +862,29 @@
855
862
  return array
856
863
  },
857
864
  onInput(event) {
858
- if (!this.isFocused) {
865
+ this.enteredValue = event.target.value
866
+ if (!this.isFocused || this.enteredValue === this.inputValue) {
859
867
  return
860
868
  }
861
- if (event.target.value === '') {
862
- this.$emit('on-input', '')
863
- }
864
869
  let evaluatedVal
865
870
  try {
866
- evaluatedVal = this.onEvaluateCode(event)
871
+ evaluatedVal = this.onEvaluateCode(String(this.enteredValue))
867
872
  } finally {
868
- if (evaluatedVal && this.value != evaluatedVal) {
869
- this.$emit('on-input', evaluatedVal)
873
+ this.inputValue = this.onChangeHandler(evaluatedVal)
874
+
875
+ if (this.isFocused && typeof this.enteredValue !== 'number') {
876
+ this.$emit(EVENT_TYPES.INPUT_CHANGE, this.inputValue)
870
877
  }
871
878
  }
872
879
  this.textInput = evaluatedVal
873
880
  },
874
881
  onInputBlur(e) {
875
882
  this.isFocused = false
876
- let value = e.target.value
877
- let evaluatedInput = this.onEvaluateCode(e)
878
- this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
879
- if ((evaluatedInput && value.length) || this.minNumber !== null) {
880
- this.textInput = numberToString({
881
- value:
882
- evaluatedInput && value.length
883
- ? evaluatedInput
884
- : this.defaultNumber
885
- ? this.defaultNumber
886
- : this.minNumber,
887
- numberPrecision: this.numberPrecision,
888
- minDecimals: this.minDecimals,
889
- })
890
- }
891
- let adjustedMinValue =
892
- evaluatedInput && evaluatedInput.length
893
- ? evaluatedInput
894
- : this.defaultNumber
895
- ? this.defaultNumber
896
- : this.minNumber || this.minNumber === 0
897
- ? this.minNumber
898
- : ''
899
- this.$emit('input-blur', adjustedMinValue)
883
+ this.enteredValue = this.inputValue
884
+ this.$emit(
885
+ EVENT_TYPES.INPUT_BLUR,
886
+ this.onEvaluateCode(String(this.inputValue))
887
+ )
900
888
  },
901
889
  focusInput() {
902
890
  if (this.disabled) {
@@ -906,7 +894,7 @@
906
894
  this.$nextTick(() => {
907
895
  this.$refs.inputField1.$el.select()
908
896
  })
909
- this.$emit('input-focus')
897
+ this.$emit(EVENT_TYPES.INPUT_FOCUS, this.inputValue)
910
898
  },
911
899
  blurInput() {
912
900
  if (this.disabled) {
@@ -939,7 +927,11 @@
939
927
  return input + ' ' + unit
940
928
  } else if (!adjustedMinValue && adjustedMinValue !== 0) {
941
929
  return ''
930
+ } else if (this.isFocused) {
931
+ console.log('1')
932
+ return value
942
933
  } else {
934
+ console.log('hehe', this.numberToStringEnabled)
943
935
  return this.numberToStringEnabled
944
936
  ? numberToString({
945
937
  value: adjustedMinValue,
@@ -959,14 +951,7 @@
959
951
  e.preventDefault()
960
952
  let value = parseFloat(this.value || 0)
961
953
  value += parseFloat(this.interactionStep) * parseInt(e.movementX)
962
- this.$emit('on-input-drag', value)
963
-
964
- this.textInput = numberToString({
965
- value: value && value.length ? value : this.minNumber,
966
- numberPrecision: this.numberPrecision,
967
- minDecimals: this.minDecimals,
968
- })
969
- //this.value=value
954
+ this.$emit(EVENT_TYPES.INPUT_DRAG, this.onChangeHandler(value))
970
955
  },
971
956
  stopInteract(e) {
972
957
  e.preventDefault()
@@ -974,6 +959,9 @@
974
959
  window.removeEventListener('mouseup', this.stopInteract, false)
975
960
  this.blurInput()
976
961
  },
962
+ handleSelectChange(value) {
963
+ this.$emit(EVENT_TYPES.SELECT_CHANGE, value)
964
+ },
977
965
  },
978
966
  }
979
967
  </script>
@@ -35,37 +35,37 @@
35
35
  visibility: ${(props) => (props.visible ? 'inherit' : 'hidden')};
36
36
  `
37
37
 
38
- const pageAttrs = { isOpen: Boolean, backdrop: String, position: String }
38
+ const pageAttrs = { backdrop: String, position: String }
39
39
  const PageWrapper = styled('div', pageAttrs)`
40
- position: ${(props) => props.position}
41
- display: grid;
42
- top: 0;
43
- left: 0;
44
- width: 100%;
45
- height: 100%;
46
- background-color: ${(props) =>
47
- props.backdrop == 'dark'
48
- ? 'rgba(0, 0, 0, 0.4)'
49
- : 'rgba(255, 255, 255, 0.9)'};
50
- z-index: 99999;
51
- overflow: auto;
40
+ position: ${(props) => props.position}
41
+ display: grid;
42
+ top: 0;
43
+ left: 0;
44
+ width: 100%;
45
+ height: 100%;
46
+ background-color: ${(props) =>
47
+ props.backdrop == 'dark'
48
+ ? 'rgba(0, 0, 0, 0.4)'
49
+ : 'rgba(255, 255, 255, 0.9)'};
50
+ z-index: 99999;
51
+ overflow: auto;
52
52
 
53
- &.visible {
54
- visibility: visible;
55
- opacity: 1;
56
- transition: visibility 0s linear 0s, opacity 300ms;
57
- }
53
+ &.visible {
54
+ visibility: visible;
55
+ opacity: 1;
56
+ transition: visibility 0s linear 0s, opacity 300ms;
57
+ }
58
58
 
59
- &.hidden {
60
- visibility: hidden;
61
- opacity: 0;
62
- transition: visibility 0s linear 300ms, opacity 300ms;
63
- }
59
+ &.hidden {
60
+ visibility: hidden;
61
+ opacity: 0;
62
+ transition: visibility 0s linear 300ms, opacity 300ms;
63
+ }
64
64
 
65
- @media (max-width: 425px) {
66
- background: white;
67
- }
68
- `
65
+ @media (max-width: 425px) {
66
+ background: white;
67
+ }
68
+ `
69
69
 
70
70
  const modalContainerAttrs = { overflow: String }
71
71
  const ModalContainer = styled('div', modalContainerAttrs)`
@@ -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 = parseFloat(value)
97
+ value = !Number.isNaN(parseFloat(value)) ? parseFloat(value) : 0
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: