@eturnity/eturnity_reusable_components 8.19.9 → 8.22.1
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
@@ -61,7 +61,7 @@
|
|
61
61
|
:show-linear-unit-name="showLinearUnitName"
|
62
62
|
:slot-size="slotSize"
|
63
63
|
:text-align="textAlign"
|
64
|
-
:value="
|
64
|
+
:value="formattedValue"
|
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="
|
78
|
+
:has-length="hasLength"
|
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="
|
95
|
+
@input-change="handleSelectChange"
|
96
96
|
>
|
97
97
|
<template #selector>
|
98
98
|
<SelectText>{{ getSelectValue }}</SelectText>
|
@@ -457,8 +457,18 @@
|
|
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
|
+
|
460
469
|
export default {
|
461
470
|
name: 'InputNumber',
|
471
|
+
emits: [...Object.values(EVENT_TYPES)],
|
462
472
|
components: {
|
463
473
|
Container,
|
464
474
|
InputContainer,
|
@@ -702,9 +712,10 @@
|
|
702
712
|
},
|
703
713
|
data() {
|
704
714
|
return {
|
705
|
-
textInput: '',
|
706
715
|
isFocused: false,
|
707
716
|
warningIcon: warningIcon,
|
717
|
+
inputValue: null,
|
718
|
+
enteredValue: null,
|
708
719
|
}
|
709
720
|
},
|
710
721
|
computed: {
|
@@ -727,6 +738,14 @@
|
|
727
738
|
|
728
739
|
return item ? item.label : '-'
|
729
740
|
},
|
741
|
+
formattedValue() {
|
742
|
+
return this.isFocused
|
743
|
+
? this.enteredValue
|
744
|
+
: this.formatWithCurrency(this.value)
|
745
|
+
},
|
746
|
+
hasLength() {
|
747
|
+
return this.formattedValue !== null && this.formattedValue.length > 0
|
748
|
+
},
|
730
749
|
},
|
731
750
|
watch: {
|
732
751
|
focus(value) {
|
@@ -737,30 +756,22 @@
|
|
737
756
|
clearInput: function (value) {
|
738
757
|
if (value) {
|
739
758
|
// If the value is typed, then we should clear the textInput on Continue
|
740
|
-
this.
|
759
|
+
this.inputValue = ''
|
760
|
+
this.enteredValue = ''
|
741
761
|
}
|
742
762
|
},
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
minDecimals: this.minDecimals,
|
756
|
-
})
|
757
|
-
} else if (this.minNumber !== null) {
|
758
|
-
this.textInput = numberToString({
|
759
|
-
value: this.minNumber,
|
760
|
-
numberPrecision: this.numberPrecision,
|
761
|
-
minDecimals: this.minDecimals,
|
762
|
-
})
|
763
|
-
}
|
763
|
+
value: {
|
764
|
+
immediate: true,
|
765
|
+
handler(val) {
|
766
|
+
if (this.value !== this.inputValue && !Number.isNaN(this.value)) {
|
767
|
+
this.inputValue = this.value
|
768
|
+
this.enteredValue =
|
769
|
+
typeof this.value === 'number' && !isNaN(this.value)
|
770
|
+
? Number(this.value.toFixed(this.numberPrecision))
|
771
|
+
: this.value
|
772
|
+
}
|
773
|
+
},
|
774
|
+
},
|
764
775
|
},
|
765
776
|
mounted() {
|
766
777
|
if (this.focus) {
|
@@ -799,32 +810,31 @@
|
|
799
810
|
}
|
800
811
|
},
|
801
812
|
onEnterPress() {
|
802
|
-
this.$emit(
|
813
|
+
this.$emit(EVENT_TYPES.PRESS_ENTER)
|
803
814
|
this.$refs.inputField1.$el.blur()
|
804
815
|
},
|
805
|
-
onChangeHandler(
|
806
|
-
if (isNaN(
|
807
|
-
|
816
|
+
onChangeHandler(value) {
|
817
|
+
if (isNaN(value) || value === '') {
|
818
|
+
value = this.defaultNumber
|
808
819
|
? this.defaultNumber
|
809
820
|
: this.minNumber || this.minNumber === 0
|
810
821
|
? this.minNumber
|
811
|
-
:
|
822
|
+
: value
|
812
823
|
}
|
813
824
|
if (!this.allowNegative) {
|
814
|
-
|
825
|
+
value = Math.abs(value)
|
815
826
|
}
|
816
|
-
if (this.minNumber && this.minNumber >
|
817
|
-
|
827
|
+
if (this.minNumber && this.minNumber > value) {
|
828
|
+
value = this.minNumber
|
818
829
|
}
|
819
|
-
event = parseFloat(event)
|
820
830
|
// Need to return an integer rather than a string
|
821
|
-
|
831
|
+
value = parseFloat(value)
|
832
|
+
return value
|
822
833
|
},
|
823
|
-
onEvaluateCode(
|
834
|
+
onEvaluateCode(value) {
|
824
835
|
// function to perform math on the code
|
825
836
|
// filter the string in case of any malicious content
|
826
|
-
|
827
|
-
let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
|
837
|
+
let filtered = value.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
|
828
838
|
filtered = filtered.split(/([-+*/()])/)
|
829
839
|
let formatted = filtered.map((item) => {
|
830
840
|
if (
|
@@ -882,58 +892,42 @@
|
|
882
892
|
return array
|
883
893
|
},
|
884
894
|
onInput(event) {
|
885
|
-
|
895
|
+
this.enteredValue = event.target.value
|
896
|
+
if (!this.isFocused || this.enteredValue === this.inputValue) {
|
886
897
|
return
|
887
898
|
}
|
888
|
-
if (event.target.value === '') {
|
889
|
-
this.$emit('on-input', '')
|
890
|
-
}
|
891
899
|
let evaluatedVal
|
892
900
|
try {
|
893
|
-
evaluatedVal = this.onEvaluateCode(
|
901
|
+
evaluatedVal = this.onEvaluateCode(String(this.enteredValue))
|
894
902
|
} finally {
|
895
|
-
|
896
|
-
|
903
|
+
this.inputValue = this.onChangeHandler(evaluatedVal)
|
904
|
+
|
905
|
+
if (this.isFocused && typeof this.enteredValue !== 'number') {
|
906
|
+
this.$emit(EVENT_TYPES.INPUT_CHANGE, this.inputValue)
|
897
907
|
}
|
898
908
|
}
|
899
909
|
this.textInput = evaluatedVal
|
900
910
|
},
|
901
911
|
onInputBlur(e) {
|
902
912
|
this.isFocused = false
|
903
|
-
|
904
|
-
|
905
|
-
this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
|
906
|
-
if ((evaluatedInput && value.length) || this.minNumber !== null) {
|
907
|
-
this.textInput = numberToString({
|
908
|
-
value:
|
909
|
-
evaluatedInput && value.length
|
910
|
-
? evaluatedInput
|
911
|
-
: this.defaultNumber
|
912
|
-
? this.defaultNumber
|
913
|
-
: this.minNumber,
|
914
|
-
numberPrecision: this.numberPrecision,
|
915
|
-
minDecimals: this.minDecimals,
|
916
|
-
})
|
913
|
+
if (!Number.isNaN(this.inputValue)) {
|
914
|
+
this.enteredValue = this.inputValue
|
917
915
|
}
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
? this.defaultNumber
|
923
|
-
: this.minNumber || this.minNumber === 0
|
924
|
-
? this.minNumber
|
925
|
-
: ''
|
926
|
-
this.$emit('input-blur', adjustedMinValue)
|
916
|
+
this.$emit(
|
917
|
+
EVENT_TYPES.INPUT_BLUR,
|
918
|
+
Number(this.onEvaluateCode(String(this.inputValue)))
|
919
|
+
)
|
927
920
|
},
|
928
921
|
focusInput() {
|
929
922
|
if (this.disabled) {
|
930
923
|
return
|
931
924
|
}
|
932
925
|
this.isFocused = true
|
926
|
+
this.textInput = this.formatWithCurrency(this.value)
|
933
927
|
this.$nextTick(() => {
|
934
928
|
this.$refs.inputField1.$el.select()
|
935
929
|
})
|
936
|
-
this.$emit(
|
930
|
+
this.$emit(EVENT_TYPES.INPUT_FOCUS, this.inputValue)
|
937
931
|
},
|
938
932
|
blurInput() {
|
939
933
|
if (this.disabled) {
|
@@ -953,7 +947,7 @@
|
|
953
947
|
: this.minNumber || this.minNumber === 0
|
954
948
|
? this.minNumber
|
955
949
|
: ''
|
956
|
-
if (
|
950
|
+
if (adjustedMinValue || adjustedMinValue === 0) {
|
957
951
|
let input = this.numberToStringEnabled
|
958
952
|
? numberToString({
|
959
953
|
value: adjustedMinValue,
|
@@ -966,6 +960,8 @@
|
|
966
960
|
return input + ' ' + unit
|
967
961
|
} else if (!adjustedMinValue && adjustedMinValue !== 0) {
|
968
962
|
return ''
|
963
|
+
} else if (this.isFocused) {
|
964
|
+
return value
|
969
965
|
} else {
|
970
966
|
return this.numberToStringEnabled
|
971
967
|
? numberToString({
|
@@ -986,14 +982,7 @@
|
|
986
982
|
e.preventDefault()
|
987
983
|
let value = parseFloat(this.value || 0)
|
988
984
|
value += parseFloat(this.interactionStep) * parseInt(e.movementX)
|
989
|
-
this.$emit(
|
990
|
-
|
991
|
-
this.textInput = numberToString({
|
992
|
-
value: value && value.length ? value : this.minNumber,
|
993
|
-
numberPrecision: this.numberPrecision,
|
994
|
-
minDecimals: this.minDecimals,
|
995
|
-
})
|
996
|
-
//this.value=value
|
985
|
+
this.$emit(EVENT_TYPES.INPUT_DRAG, this.onChangeHandler(value))
|
997
986
|
},
|
998
987
|
stopInteract(e) {
|
999
988
|
e.preventDefault()
|
@@ -1001,6 +990,9 @@
|
|
1001
990
|
window.removeEventListener('mouseup', this.stopInteract, false)
|
1002
991
|
this.blurInput()
|
1003
992
|
},
|
993
|
+
handleSelectChange(value) {
|
994
|
+
this.$emit(EVENT_TYPES.SELECT_CHANGE, value)
|
995
|
+
},
|
1004
996
|
},
|
1005
997
|
}
|
1006
998
|
</script>
|
@@ -1,8 +1,6 @@
|
|
1
1
|
<template>
|
2
2
|
<SpinnerContainer
|
3
3
|
v-if="fullWidth"
|
4
|
-
data-id="spinner_full_container"
|
5
|
-
data-qa-id="spinner_full_container"
|
6
4
|
data-test-id="spinner_full_container"
|
7
5
|
:size="size"
|
8
6
|
>
|
@@ -14,8 +12,6 @@
|
|
14
12
|
</SpinnerContainer>
|
15
13
|
<Container
|
16
14
|
v-else
|
17
|
-
data-id="spinner_container"
|
18
|
-
data-qa-id="spinner_container"
|
19
15
|
data-test-id="spinner_container"
|
20
16
|
:limited-to-modal="limitedToModal"
|
21
17
|
>
|
@@ -1,10 +1,5 @@
|
|
1
1
|
<template>
|
2
|
-
<SpinnerContainer
|
3
|
-
v-if="fullWidth"
|
4
|
-
data-id="spinner_full_container"
|
5
|
-
data-qa-id="spinner_full_container"
|
6
|
-
data-test-id="spinner_full_container"
|
7
|
-
>
|
2
|
+
<SpinnerContainer v-if="fullWidth" data-test-id="spinner_full_container">
|
8
3
|
<Container>
|
9
4
|
<SpinnerWrapper data-test-id="spinner_full_wrapper" :size="size">
|
10
5
|
<img
|
@@ -18,8 +13,6 @@
|
|
18
13
|
</SpinnerContainer>
|
19
14
|
<Container
|
20
15
|
v-else
|
21
|
-
data-id="spinner_container"
|
22
|
-
data-qa-id="spinner_container"
|
23
16
|
data-test-id="spinner_container"
|
24
17
|
:limited-to-modal="limitedToModal"
|
25
18
|
>
|
@@ -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:
|