@eturnity/eturnity_reusable_components 1.1.97 → 1.2.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/.prettierrc +7 -0
- package/package.json +1 -1
- package/src/components/buttons/closeButton/index.vue +8 -8
- package/src/components/inputs/inputNumber/index.vue +21 -12
- package/src/components/modals/modal/index.vue +19 -19
- package/src/components/modals/modal/modal.stories.js +30 -0
- package/src/components/tableDropdown/index.vue +1 -0
- package/src/helpers/numberConverter.js +47 -38
package/.prettierrc
ADDED
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// <close-button
|
|
14
14
|
// color="#fff"
|
|
15
15
|
// />
|
|
16
|
-
import styled from
|
|
16
|
+
import styled from 'vue-styled-components'
|
|
17
17
|
|
|
18
18
|
const Container = styled.div`
|
|
19
19
|
position: relative;
|
|
@@ -27,8 +27,8 @@ const Wrapper = styled.div`
|
|
|
27
27
|
`
|
|
28
28
|
|
|
29
29
|
const lineAttrs = { color: String }
|
|
30
|
-
const Line = styled(
|
|
31
|
-
width:
|
|
30
|
+
const Line = styled('div', lineAttrs)`
|
|
31
|
+
width: 20px;
|
|
32
32
|
height: 2px;
|
|
33
33
|
background-color: ${(props) =>
|
|
34
34
|
props.color ? props.color : props.theme.colors.red};
|
|
@@ -45,17 +45,17 @@ const RightLine = styled(Line)`
|
|
|
45
45
|
`
|
|
46
46
|
|
|
47
47
|
export default {
|
|
48
|
-
name:
|
|
48
|
+
name: 'close-button',
|
|
49
49
|
components: {
|
|
50
50
|
Container,
|
|
51
51
|
Wrapper,
|
|
52
52
|
LeftLine,
|
|
53
|
-
RightLine
|
|
53
|
+
RightLine
|
|
54
54
|
},
|
|
55
55
|
props: {
|
|
56
56
|
color: {
|
|
57
|
-
required: false
|
|
58
|
-
}
|
|
59
|
-
}
|
|
57
|
+
required: false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
</script>
|
|
@@ -265,8 +265,8 @@ export default {
|
|
|
265
265
|
},
|
|
266
266
|
numberToStringEnabled: {
|
|
267
267
|
required: false,
|
|
268
|
-
default: true
|
|
269
|
-
}
|
|
268
|
+
default: true,
|
|
269
|
+
},
|
|
270
270
|
},
|
|
271
271
|
methods: {
|
|
272
272
|
onChangeHandler(event) {
|
|
@@ -294,12 +294,16 @@ export default {
|
|
|
294
294
|
} else {
|
|
295
295
|
let num = stringToNumber({
|
|
296
296
|
value: item,
|
|
297
|
-
numberPrecision:
|
|
297
|
+
numberPrecision: false,
|
|
298
298
|
})
|
|
299
299
|
return num
|
|
300
300
|
}
|
|
301
301
|
})
|
|
302
302
|
let evaluated = eval(formatted.join(""))
|
|
303
|
+
evaluated = stringToNumber({
|
|
304
|
+
value: evaluated,
|
|
305
|
+
numberPrecision: this.numberPrecision,
|
|
306
|
+
})
|
|
303
307
|
return evaluated
|
|
304
308
|
},
|
|
305
309
|
onInputBlur(e) {
|
|
@@ -309,7 +313,8 @@ export default {
|
|
|
309
313
|
this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
|
|
310
314
|
if ((evaluatedInput && value.length) || this.minNumber !== null) {
|
|
311
315
|
this.textInput = numberToString({
|
|
312
|
-
value:
|
|
316
|
+
value:
|
|
317
|
+
evaluatedInput && value.length ? evaluatedInput : this.minNumber,
|
|
313
318
|
numberPrecision: this.numberPrecision,
|
|
314
319
|
})
|
|
315
320
|
}
|
|
@@ -338,19 +343,23 @@ export default {
|
|
|
338
343
|
? this.minNumber
|
|
339
344
|
: ""
|
|
340
345
|
if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
|
|
341
|
-
let input =
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
346
|
+
let input = this.numberToStringEnabled
|
|
347
|
+
? numberToString({
|
|
348
|
+
value: adjustedMinValue,
|
|
349
|
+
numberPrecision: this.numberPrecision,
|
|
350
|
+
})
|
|
351
|
+
: adjustedMinValue
|
|
345
352
|
let unit = this.showLinearUnitName ? "" : this.unitName
|
|
346
353
|
return input + " " + unit
|
|
347
354
|
} else if (!adjustedMinValue && adjustedMinValue !== 0) {
|
|
348
355
|
return ""
|
|
349
356
|
} else {
|
|
350
|
-
return
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
357
|
+
return this.numberToStringEnabled
|
|
358
|
+
? numberToString({
|
|
359
|
+
value: adjustedMinValue,
|
|
360
|
+
numberPrecision: this.numberPrecision,
|
|
361
|
+
})
|
|
362
|
+
: adjustedMinValue
|
|
354
363
|
}
|
|
355
364
|
},
|
|
356
365
|
},
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
// <div>Data....</div>
|
|
25
25
|
// </modal>
|
|
26
26
|
|
|
27
|
-
import styled from
|
|
28
|
-
import CloseButton from
|
|
29
|
-
import Spinner from
|
|
27
|
+
import styled from 'vue-styled-components'
|
|
28
|
+
import CloseButton from '../../buttons/closeButton'
|
|
29
|
+
import Spinner from '../../spinner'
|
|
30
30
|
|
|
31
31
|
const pageAttrs = { isOpen: Boolean }
|
|
32
|
-
const PageWrapper = styled(
|
|
32
|
+
const PageWrapper = styled('div', pageAttrs)`
|
|
33
33
|
position: fixed;
|
|
34
34
|
display: grid;
|
|
35
35
|
top: 0;
|
|
@@ -73,8 +73,8 @@ const ModalContainer = styled.div`
|
|
|
73
73
|
|
|
74
74
|
.close {
|
|
75
75
|
position: absolute;
|
|
76
|
-
right:
|
|
77
|
-
top:
|
|
76
|
+
right: 20px;
|
|
77
|
+
top: 20px;
|
|
78
78
|
|
|
79
79
|
@media (max-width: 425px) {
|
|
80
80
|
right: 14px;
|
|
@@ -93,46 +93,46 @@ const ModalContainer = styled.div`
|
|
|
93
93
|
`
|
|
94
94
|
|
|
95
95
|
export default {
|
|
96
|
-
name:
|
|
96
|
+
name: 'modal',
|
|
97
97
|
components: {
|
|
98
98
|
PageWrapper,
|
|
99
99
|
ModalContainer,
|
|
100
100
|
CloseButton,
|
|
101
|
-
Spinner
|
|
101
|
+
Spinner
|
|
102
102
|
},
|
|
103
103
|
props: {
|
|
104
104
|
isOpen: {
|
|
105
105
|
required: true,
|
|
106
|
-
default: false
|
|
106
|
+
default: false
|
|
107
107
|
},
|
|
108
108
|
preventOutsideClose: {
|
|
109
109
|
required: false,
|
|
110
|
-
default: false
|
|
110
|
+
default: false
|
|
111
111
|
},
|
|
112
112
|
isLoading: {
|
|
113
113
|
required: false,
|
|
114
|
-
default: false
|
|
114
|
+
default: false
|
|
115
115
|
},
|
|
116
116
|
hideClose: {
|
|
117
117
|
required: false,
|
|
118
|
-
default: false
|
|
119
|
-
}
|
|
118
|
+
default: false
|
|
119
|
+
}
|
|
120
120
|
},
|
|
121
121
|
methods: {
|
|
122
122
|
onCloseModal() {
|
|
123
|
-
this.$emit(
|
|
123
|
+
this.$emit('on-close')
|
|
124
124
|
},
|
|
125
125
|
onOutsideClose() {
|
|
126
126
|
// If true, then only allow closing to come from clicking the X or wherever the onCloseModal is called
|
|
127
127
|
if (!this.preventOutsideClose) {
|
|
128
|
-
this.$emit(
|
|
128
|
+
this.$emit('on-close')
|
|
129
129
|
}
|
|
130
|
-
}
|
|
130
|
+
}
|
|
131
131
|
},
|
|
132
132
|
watch: {
|
|
133
133
|
isOpen: function (newVal) {
|
|
134
|
-
document.body.style.overflow = newVal ?
|
|
135
|
-
}
|
|
136
|
-
}
|
|
134
|
+
document.body.style.overflow = newVal ? 'hidden' : ''
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
137
|
}
|
|
138
138
|
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Modal from "./index.vue";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: "Modal",
|
|
5
|
+
component: Modal,
|
|
6
|
+
// argTypes: {},
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const Template = (args, { argTypes }) => ({
|
|
10
|
+
// Components used in your story `template` are defined in the `components` object
|
|
11
|
+
components: { Modal },
|
|
12
|
+
// The story's `args` need to be mapped into the template through the `setup()` method
|
|
13
|
+
props: Object.keys(argTypes),
|
|
14
|
+
template: '<modal v-bind="$props" />',
|
|
15
|
+
|
|
16
|
+
// import Modal from "@eturnity/eturnity_reusable_components/src/components/modals/modal"
|
|
17
|
+
// This is a more flexible modal box, where the parent can decide how the body of the modal looks
|
|
18
|
+
// To use:
|
|
19
|
+
// <modal :isOpen="isOpen" @on-close="$emit('on-close-summary')" :preventOutsideClose="true" :isLoading="true" :hideClose="true">
|
|
20
|
+
// <div>Data....</div>
|
|
21
|
+
// </modal>
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const Default = Template.bind({
|
|
25
|
+
isOpen: true,
|
|
26
|
+
preventOutsideClose: true,
|
|
27
|
+
isLoading: false,
|
|
28
|
+
hideClose: false,
|
|
29
|
+
});
|
|
30
|
+
Default.args = {};
|
|
@@ -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 = ({
|
|
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(
|
|
8
|
+
const selectedLang = localStorage.getItem('lang')
|
|
5
9
|
// The first replace will replace not allowed characters with a blank
|
|
6
10
|
if (
|
|
7
|
-
selectedLang ===
|
|
8
|
-
selectedLang ===
|
|
9
|
-
selectedLang ===
|
|
10
|
-
selectedLang ===
|
|
11
|
-
selectedLang ===
|
|
12
|
-
selectedLang ===
|
|
13
|
-
selectedLang ===
|
|
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 ===
|
|
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,
|
|
34
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '')
|
|
31
35
|
} else {
|
|
32
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
36
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '')
|
|
33
37
|
}
|
|
34
38
|
} else if (
|
|
35
|
-
selectedLang ===
|
|
36
|
-
selectedLang ===
|
|
37
|
-
selectedLang ===
|
|
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,
|
|
45
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/['\s]/g, '')
|
|
42
46
|
} else {
|
|
43
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
47
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/['\s]/g, '')
|
|
44
48
|
}
|
|
45
49
|
} else if (
|
|
46
|
-
selectedLang ===
|
|
47
|
-
selectedLang ===
|
|
48
|
-
selectedLang ===
|
|
49
|
-
selectedLang ===
|
|
50
|
-
selectedLang ===
|
|
51
|
-
selectedLang ===
|
|
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,
|
|
59
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '.')
|
|
56
60
|
} else {
|
|
57
|
-
newVal = newVal.replace(/[^\d.,']/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,
|
|
66
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '')
|
|
63
67
|
} else {
|
|
64
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
68
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '')
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
|
-
newVal = parseFloat(newVal)
|
|
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(
|
|
73
|
-
? localStorage.getItem(
|
|
74
|
-
|
|
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
|
}
|