@eturnity/eturnity_reusable_components 7.51.16-EPDM-6306.0 → 7.51.16-EPDM-12459.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-6306.0",
3
+ "version": "7.51.16-EPDM-12459.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="formattedValue"
60
+ :value="formatWithCurrency(value)"
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="hasLength"
74
+ :has-length="!!textInput.length"
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="handleSelectChange"
91
+ @input-change="$emit('select-change', $event)"
92
92
  >
93
93
  <template #selector>
94
94
  <SelectText>{{ getSelectValue }}</SelectText>
@@ -446,18 +446,8 @@
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
-
458
449
  export default {
459
450
  name: 'InputNumber',
460
- emits: [...Object.values(EVENT_TYPES)],
461
451
  components: {
462
452
  Container,
463
453
  InputContainer,
@@ -688,10 +678,9 @@
688
678
  },
689
679
  data() {
690
680
  return {
681
+ textInput: '',
691
682
  isFocused: false,
692
683
  warningIcon: warningIcon,
693
- inputValue: null,
694
- enteredValue: null,
695
684
  }
696
685
  },
697
686
  computed: {
@@ -714,14 +703,6 @@
714
703
 
715
704
  return item ? item.label : '-'
716
705
  },
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
- },
725
706
  },
726
707
  watch: {
727
708
  focus(value) {
@@ -732,19 +713,30 @@
732
713
  clearInput: function (value) {
733
714
  if (value) {
734
715
  // If the value is typed, then we should clear the textInput on Continue
735
- this.inputValue = ''
736
- this.enteredValue = ''
716
+ this.textInput = ''
737
717
  }
738
718
  },
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
- },
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
+ }
748
740
  },
749
741
  mounted() {
750
742
  if (this.focus) {
@@ -783,28 +775,29 @@
783
775
  }
784
776
  },
785
777
  onEnterPress() {
786
- this.$emit(EVENT_TYPES.PRESS_ENTER)
778
+ this.$emit('on-enter-click')
787
779
  this.$refs.inputField1.$el.blur()
788
780
  },
789
- onChangeHandler(value) {
790
- if (isNaN(value) || value === '') {
791
- value = this.defaultNumber
781
+ onChangeHandler(event) {
782
+ if (isNaN(event) || event === '') {
783
+ event = this.defaultNumber
792
784
  ? this.defaultNumber
793
785
  : this.minNumber || this.minNumber === 0
794
786
  ? this.minNumber
795
- : value
787
+ : event
796
788
  }
797
789
  if (!this.allowNegative) {
798
- value = Math.abs(value)
790
+ event = Math.abs(event)
799
791
  }
800
- value = parseFloat(value)
792
+ event = parseFloat(event)
801
793
  // Need to return an integer rather than a string
802
- return parseFloat(value)
794
+ this.$emit('input-change', event)
803
795
  },
804
- onEvaluateCode(value) {
796
+ onEvaluateCode(event) {
805
797
  // function to perform math on the code
806
798
  // filter the string in case of any malicious content
807
- let filtered = value.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
799
+ const val = event.target.value
800
+ let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
808
801
  filtered = filtered.split(/([-+*/()])/)
809
802
  let formatted = filtered.map((item) => {
810
803
  if (
@@ -862,29 +855,48 @@
862
855
  return array
863
856
  },
864
857
  onInput(event) {
865
- this.enteredValue = event.target.value
866
- if (!this.isFocused || this.enteredValue === this.inputValue) {
858
+ if (!this.isFocused) {
867
859
  return
868
860
  }
861
+ if (event.target.value === '') {
862
+ this.$emit('on-input', '')
863
+ }
869
864
  let evaluatedVal
870
865
  try {
871
- evaluatedVal = this.onEvaluateCode(String(this.enteredValue))
866
+ evaluatedVal = this.onEvaluateCode(event)
872
867
  } finally {
873
- this.inputValue = this.onChangeHandler(evaluatedVal)
874
-
875
- if (this.isFocused && typeof this.enteredValue !== 'number') {
876
- this.$emit(EVENT_TYPES.INPUT_CHANGE, this.inputValue)
868
+ if (evaluatedVal && this.value != evaluatedVal) {
869
+ this.$emit('on-input', evaluatedVal)
877
870
  }
878
871
  }
879
872
  this.textInput = evaluatedVal
880
873
  },
881
874
  onInputBlur(e) {
882
875
  this.isFocused = false
883
- this.enteredValue = this.inputValue
884
- this.$emit(
885
- EVENT_TYPES.INPUT_BLUR,
886
- this.onEvaluateCode(String(this.inputValue))
887
- )
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)
888
900
  },
889
901
  focusInput() {
890
902
  if (this.disabled) {
@@ -894,7 +906,7 @@
894
906
  this.$nextTick(() => {
895
907
  this.$refs.inputField1.$el.select()
896
908
  })
897
- this.$emit(EVENT_TYPES.INPUT_FOCUS, this.inputValue)
909
+ this.$emit('input-focus')
898
910
  },
899
911
  blurInput() {
900
912
  if (this.disabled) {
@@ -927,11 +939,7 @@
927
939
  return input + ' ' + unit
928
940
  } else if (!adjustedMinValue && adjustedMinValue !== 0) {
929
941
  return ''
930
- } else if (this.isFocused) {
931
- console.log('1')
932
- return value
933
942
  } else {
934
- console.log('hehe', this.numberToStringEnabled)
935
943
  return this.numberToStringEnabled
936
944
  ? numberToString({
937
945
  value: adjustedMinValue,
@@ -951,7 +959,14 @@
951
959
  e.preventDefault()
952
960
  let value = parseFloat(this.value || 0)
953
961
  value += parseFloat(this.interactionStep) * parseInt(e.movementX)
954
- this.$emit(EVENT_TYPES.INPUT_DRAG, this.onChangeHandler(value))
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
955
970
  },
956
971
  stopInteract(e) {
957
972
  e.preventDefault()
@@ -959,9 +974,6 @@
959
974
  window.removeEventListener('mouseup', this.stopInteract, false)
960
975
  this.blurInput()
961
976
  },
962
- handleSelectChange(value) {
963
- this.$emit(EVENT_TYPES.SELECT_CHANGE, value)
964
- },
965
977
  },
966
978
  }
967
979
  </script>
@@ -139,10 +139,13 @@
139
139
  <SelectDropdown
140
140
  v-show="isSelectDropdownShown"
141
141
  ref="dropdown"
142
+ :style="{
143
+ transform: `translate(${dropdownPosition?.left}px, ${
144
+ noRelative ? 'auto' : `${dropdownPosition?.top}px`
145
+ })`,
146
+ }"
142
147
  :bg-color="
143
- dropdownBgColor ||
144
- colorMode == 'dark' ||
145
- colorMode == 'transparent'
148
+ colorMode == 'dark' || colorMode == 'transparent'
146
149
  ? 'black'
147
150
  : 'white'
148
151
  "
@@ -395,9 +398,8 @@
395
398
  box-sizing: border-box;
396
399
  z-index: ${(props) => (props.isActive ? '2' : '99999')};
397
400
  position: absolute;
398
- top: ${(props) =>
399
- props.noRelative ? 'auto' : props.dropdownPosition?.top + 'px'};
400
- left: ${(props) => props.dropdownPosition?.left}px;
401
+ top: 0px;
402
+ left: 0px;
401
403
  border: ${BORDER_WIDTH} solid ${(props) => props.theme.colors.grey4};
402
404
  border-radius: 4px;
403
405
  display: flex;
@@ -658,6 +660,10 @@
658
660
  },
659
661
  dropdownWidth: null,
660
662
  hoveredValue: null,
663
+ isDisplayedAtBottom: true,
664
+ selectTopPosition: 0,
665
+ selectAndDropdownDistance: 0,
666
+ animationFrameId: null,
661
667
  }
662
668
  },
663
669
  computed: {
@@ -728,8 +734,13 @@
728
734
  }, 10)
729
735
  await this.$nextTick()
730
736
  this.handleSetDropdownOffet()
737
+ this.calculateSelectTopPosition()
731
738
  } else {
732
739
  this.dropdownPosition.left = null
740
+ if (this.animationFrameId) {
741
+ cancelAnimationFrame(this.animationFrameId)
742
+ this.animationFrameId = null
743
+ }
733
744
  setTimeout(() => {
734
745
  this.isClickOutsideActive = false
735
746
  }, 10)
@@ -742,11 +753,27 @@
742
753
  })
743
754
  }
744
755
  },
756
+ isSelectDropdownShown(isShown) {
757
+ if (!isShown) return
758
+
759
+ // Need to wait for 1ms to make sure the dropdown menu is shown in the DOM
760
+ // before getting the distance between the select and the dropdown menu
761
+ setTimeout(() => {
762
+ this.getDistanceBetweenSelectAndDropdownMenu()
763
+ }, 100)
764
+ },
765
+ selectTopPosition() {
766
+ this.dropdownPosition.top =
767
+ this.selectTopPosition +
768
+ this.$refs.select.$el.clientHeight +
769
+ this.selectAndDropdownDistance
770
+ },
745
771
  },
746
772
  mounted() {
747
773
  this.observeDropdownHeight()
748
774
  this.observeSelectWidth()
749
775
  window.addEventListener('resize', this.handleSetDropdownOffet)
776
+ document.body.addEventListener('scroll', this.calculateSelectTopPosition)
750
777
  },
751
778
  beforeMount() {
752
779
  this.selectedValue = this.value
@@ -755,6 +782,10 @@
755
782
  window.removeEventListener('resize', this.handleSetDropdownOffet)
756
783
  if (this.dropdownResizeObserver) this.dropdownResizeObserver.disconnect()
757
784
  if (this.selectResizeObserver) this.selectResizeObserver.disconnect()
785
+ document.body.removeEventListener(
786
+ 'scroll',
787
+ this.calculateSelectTopPosition
788
+ )
758
789
  },
759
790
  unmounted() {
760
791
  document.removeEventListener('click', this.clickOutside)
@@ -860,11 +891,11 @@
860
891
  return
861
892
  }
862
893
  await this.$nextTick()
863
- const isDisplayedAtBottom = await this.generateDropdownPosition()
894
+ this.isDisplayedAtBottom = await this.generateDropdownPosition()
864
895
  // If the dropdown menu is going to be displayed at the bottom,
865
896
  // we need reverify its position after a dom update (nextTick)
866
897
  await this.$nextTick()
867
- if (isDisplayedAtBottom) this.generateDropdownPosition()
898
+ if (this.isDisplayedAtBottom) this.generateDropdownPosition()
868
899
  },
869
900
  async generateDropdownPosition() {
870
901
  const isDropdownNotCompletelyVisible =
@@ -957,6 +988,25 @@
957
988
  }
958
989
  }
959
990
  },
991
+ getDistanceBetweenSelectAndDropdownMenu() {
992
+ const wholeSelectTopPosition =
993
+ this.selectTopPosition + this.$refs.select.$el.clientHeight
994
+ this.selectAndDropdownDistance =
995
+ this.dropdownPosition.top - wholeSelectTopPosition
996
+ },
997
+ calculateSelectTopPosition() {
998
+ const selectRef = this.$refs.select
999
+ if (selectRef) {
1000
+ const currentTopPosition =
1001
+ selectRef.$el.getBoundingClientRect().top + window.scrollY
1002
+ if (this.selectTopPosition !== currentTopPosition) {
1003
+ this.selectTopPosition = currentTopPosition
1004
+ }
1005
+ }
1006
+ this.animationFrameId = requestAnimationFrame(
1007
+ this.calculateSelectTopPosition
1008
+ )
1009
+ },
960
1010
  },
961
1011
  }
962
1012
  </script>
@@ -35,37 +35,37 @@
35
35
  visibility: ${(props) => (props.visible ? 'inherit' : 'hidden')};
36
36
  `
37
37
 
38
- const pageAttrs = { backdrop: String, position: String }
38
+ const pageAttrs = { isOpen: Boolean, 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 = !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: