@eturnity/eturnity_reusable_components 1.1.98 → 1.2.0-beta.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/.prettierrc +7 -0
- package/package.json +1 -1
- package/src/App.vue +64 -61
- 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 +43 -22
- package/src/components/modals/modal/modal.stories.js +31 -0
- package/src/components/spinner/index.vue +13 -10
- package/src/helpers/numberConverter.js +47 -38
package/.prettierrc
ADDED
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<ThemeProvider :theme="getTheme()" :style="{ height: '100%' }">
|
|
3
3
|
<page-container>
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
<br />
|
|
5
|
+
<modal backdrop="dark" :isLoading="false" :isOpen="true">
|
|
6
|
+
<main-table titleText="My Table">
|
|
7
|
+
<thead>
|
|
8
|
+
<tr>
|
|
9
|
+
<th>Column 1</th>
|
|
10
|
+
<th>Column 2</th>
|
|
11
|
+
<th>Column 3</th>
|
|
12
|
+
<div />
|
|
13
|
+
</tr>
|
|
14
|
+
</thead>
|
|
15
|
+
<tbody>
|
|
16
|
+
<tr>
|
|
17
|
+
<!-- <table-dropdown
|
|
16
18
|
:colSpan="3"
|
|
17
19
|
:tableItems="getDropdownValues()"
|
|
18
20
|
@toggle-dropdown-open="toggleDropdownOpen()"
|
|
@@ -21,14 +23,14 @@
|
|
|
21
23
|
:optionItems="itemOptions"
|
|
22
24
|
:optionsDisplay="['display_name', 'company_item_number', 'model']"
|
|
23
25
|
/> -->
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
<td>Test</td>
|
|
27
|
+
<div class="icons-container">
|
|
28
|
+
<three-dots :options="listOptions" :isLoading="false" />
|
|
29
|
+
</div>
|
|
30
|
+
</tr>
|
|
31
|
+
</tbody>
|
|
32
|
+
</main-table>
|
|
33
|
+
</modal>
|
|
32
34
|
<br />
|
|
33
35
|
<toggle
|
|
34
36
|
@on-toggle-change="onInputChange($event)"
|
|
@@ -61,17 +63,18 @@
|
|
|
61
63
|
</template>
|
|
62
64
|
|
|
63
65
|
<script>
|
|
64
|
-
import { ThemeProvider } from
|
|
65
|
-
import theme from
|
|
66
|
-
import styled from
|
|
67
|
-
import MainTable from
|
|
68
|
-
import ThreeDots from
|
|
69
|
-
import Toggle from
|
|
70
|
-
import InputNumber from
|
|
71
|
-
import Checkbox from
|
|
72
|
-
import PageSubtitle from
|
|
73
|
-
import Spinner from
|
|
74
|
-
import ExternalButton from
|
|
66
|
+
import { ThemeProvider } from 'vue-styled-components'
|
|
67
|
+
import theme from './assets/theme'
|
|
68
|
+
import styled from 'vue-styled-components'
|
|
69
|
+
import MainTable from '@/components/tables/mainTable'
|
|
70
|
+
import ThreeDots from '@/components/threeDots'
|
|
71
|
+
import Toggle from '@/components/inputs/toggle'
|
|
72
|
+
import InputNumber from '@/components/inputs/inputNumber'
|
|
73
|
+
import Checkbox from '@/components/inputs/checkbox'
|
|
74
|
+
import PageSubtitle from '@/components/pageSubtitle'
|
|
75
|
+
import Spinner from '@/components/spinner'
|
|
76
|
+
import ExternalButton from '@/components/buttons/externalButton'
|
|
77
|
+
import Modal from '@/components/modals/modal'
|
|
75
78
|
// import TableDropdown from "@/components/tableDropdown"
|
|
76
79
|
|
|
77
80
|
const PageContainer = styled.div`
|
|
@@ -79,7 +82,7 @@ const PageContainer = styled.div`
|
|
|
79
82
|
`
|
|
80
83
|
|
|
81
84
|
export default {
|
|
82
|
-
name:
|
|
85
|
+
name: 'App',
|
|
83
86
|
components: {
|
|
84
87
|
ThemeProvider,
|
|
85
88
|
PageContainer,
|
|
@@ -91,62 +94,62 @@ export default {
|
|
|
91
94
|
Spinner,
|
|
92
95
|
Checkbox,
|
|
93
96
|
ExternalButton,
|
|
94
|
-
|
|
97
|
+
Modal,
|
|
95
98
|
},
|
|
96
99
|
data() {
|
|
97
100
|
return {
|
|
98
101
|
inputValue: null,
|
|
99
|
-
checkedOption:
|
|
102
|
+
checkedOption: 'button_1',
|
|
100
103
|
question: {
|
|
101
104
|
number_format_precision: 4,
|
|
102
105
|
number_min_allowed: 0,
|
|
103
106
|
number_max_allowed: 10,
|
|
104
|
-
unit_short_name:
|
|
107
|
+
unit_short_name: 'cm',
|
|
105
108
|
},
|
|
106
109
|
dropdownOpen: false,
|
|
107
110
|
isChecked: false,
|
|
108
111
|
listOptions: [
|
|
109
112
|
{
|
|
110
|
-
name:
|
|
111
|
-
value:
|
|
113
|
+
name: 'Option 1',
|
|
114
|
+
value: 'option_1',
|
|
112
115
|
disabled: true,
|
|
113
116
|
},
|
|
114
117
|
{
|
|
115
|
-
name:
|
|
116
|
-
value:
|
|
118
|
+
name: 'Option 2',
|
|
119
|
+
value: 'option_2',
|
|
117
120
|
},
|
|
118
121
|
{
|
|
119
|
-
name:
|
|
120
|
-
value:
|
|
122
|
+
name: 'Option 3',
|
|
123
|
+
value: 'option_3',
|
|
121
124
|
},
|
|
122
125
|
{
|
|
123
|
-
name:
|
|
124
|
-
value:
|
|
126
|
+
name: 'Option 4',
|
|
127
|
+
value: 'option_4',
|
|
125
128
|
},
|
|
126
129
|
],
|
|
127
130
|
itemOptions: [
|
|
128
131
|
{
|
|
129
|
-
display_name:
|
|
130
|
-
company_item_number:
|
|
131
|
-
model:
|
|
132
|
+
display_name: 'Test 1',
|
|
133
|
+
company_item_number: '123',
|
|
134
|
+
model: 'BTB-2145 Long Text Long Text Long Text Long Text Long Text',
|
|
132
135
|
id: 1,
|
|
133
136
|
},
|
|
134
137
|
{
|
|
135
|
-
display_name:
|
|
136
|
-
company_item_number:
|
|
137
|
-
model:
|
|
138
|
+
display_name: 'Test 2',
|
|
139
|
+
company_item_number: '1234',
|
|
140
|
+
model: 'BTB-123',
|
|
138
141
|
id: 2,
|
|
139
142
|
},
|
|
140
143
|
{
|
|
141
|
-
display_name:
|
|
142
|
-
company_item_number:
|
|
143
|
-
model:
|
|
144
|
+
display_name: 'Test 3',
|
|
145
|
+
company_item_number: '12345',
|
|
146
|
+
model: 'BTB-543',
|
|
144
147
|
id: 3,
|
|
145
148
|
},
|
|
146
149
|
{
|
|
147
|
-
display_name:
|
|
148
|
-
company_item_number:
|
|
149
|
-
model:
|
|
150
|
+
display_name: 'Test 4',
|
|
151
|
+
company_item_number: '123456',
|
|
152
|
+
model: 'BTB-4930',
|
|
150
153
|
id: 4,
|
|
151
154
|
},
|
|
152
155
|
],
|
|
@@ -163,7 +166,7 @@ export default {
|
|
|
163
166
|
return this.dropdownOpen
|
|
164
167
|
},
|
|
165
168
|
onClickButton() {
|
|
166
|
-
console.log(
|
|
169
|
+
console.log('Test')
|
|
167
170
|
},
|
|
168
171
|
toggleDropdownOpen() {
|
|
169
172
|
this.dropdownOpen = !this.dropdownOpen
|
|
@@ -174,19 +177,19 @@ export default {
|
|
|
174
177
|
{
|
|
175
178
|
value: this.getComponentInfo({
|
|
176
179
|
row: this.itemOptions[0],
|
|
177
|
-
value:
|
|
180
|
+
value: 'display_name',
|
|
178
181
|
}),
|
|
179
182
|
},
|
|
180
183
|
{
|
|
181
184
|
value: this.getComponentInfo({
|
|
182
185
|
row: this.itemOptions[0],
|
|
183
|
-
value:
|
|
186
|
+
value: 'company_item_number',
|
|
184
187
|
}),
|
|
185
188
|
},
|
|
186
189
|
{
|
|
187
190
|
value: this.getComponentInfo({
|
|
188
191
|
row: this.itemOptions[0],
|
|
189
|
-
value:
|
|
192
|
+
value: 'model',
|
|
190
193
|
}),
|
|
191
194
|
},
|
|
192
195
|
]
|
|
@@ -199,7 +202,7 @@ export default {
|
|
|
199
202
|
} else if (row[value]) {
|
|
200
203
|
item = row[value]
|
|
201
204
|
} else {
|
|
202
|
-
item =
|
|
205
|
+
item = '-'
|
|
203
206
|
}
|
|
204
207
|
return item
|
|
205
208
|
},
|
|
@@ -213,4 +216,4 @@ body {
|
|
|
213
216
|
height: 100%;
|
|
214
217
|
margin: 0;
|
|
215
218
|
}
|
|
216
|
-
</style>
|
|
219
|
+
</style>
|
|
@@ -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
|
},
|
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
:isOpen="isOpen"
|
|
4
4
|
:class="{ visible: isOpen, hidden: !isOpen }"
|
|
5
5
|
@click.native="onOutsideClose()"
|
|
6
|
+
:backdrop="backdrop"
|
|
7
|
+
:fullwidthSpinner="fullwidthSpinner"
|
|
6
8
|
>
|
|
7
9
|
<modal-container @click.stop>
|
|
8
|
-
<spinner v-if="isLoading" size="50px" :fullWidth="
|
|
10
|
+
<spinner v-if="isLoading" size="50px" :fullWidth="fullwidthSpinner" />
|
|
11
|
+
<content-container :visible="!isLoading">
|
|
12
|
+
<slot />
|
|
13
|
+
</content-container>
|
|
9
14
|
<close-button
|
|
10
15
|
v-if="!hideClose"
|
|
11
16
|
@click.native="onCloseModal()"
|
|
12
17
|
class="close"
|
|
13
18
|
/>
|
|
14
|
-
<slot />
|
|
15
19
|
</modal-container>
|
|
16
20
|
</page-wrapper>
|
|
17
21
|
</template>
|
|
@@ -24,19 +28,27 @@
|
|
|
24
28
|
// <div>Data....</div>
|
|
25
29
|
// </modal>
|
|
26
30
|
|
|
27
|
-
import styled from
|
|
28
|
-
import CloseButton from
|
|
29
|
-
import Spinner from
|
|
31
|
+
import styled from 'vue-styled-components'
|
|
32
|
+
import CloseButton from '../../buttons/closeButton'
|
|
33
|
+
import Spinner from '../../spinner'
|
|
30
34
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
35
|
+
const contentAttrs = { visible: Boolean }
|
|
36
|
+
const ContentContainer = styled('div', contentAttrs)`
|
|
37
|
+
visibility: ${(props) => (props.visible ? 'inherit' : 'hidden')};
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
const pageAttrs = { isOpen: Boolean, backdrop: String }
|
|
41
|
+
const PageWrapper = styled('div', pageAttrs)`
|
|
33
42
|
position: fixed;
|
|
34
43
|
display: grid;
|
|
35
44
|
top: 0;
|
|
36
45
|
left: 0;
|
|
37
46
|
width: 100%;
|
|
38
47
|
height: 100%;
|
|
39
|
-
background-color:
|
|
48
|
+
background-color: ${(props) =>
|
|
49
|
+
props.backdrop == 'dark'
|
|
50
|
+
? 'rgba(0, 0, 0, 0.4)'
|
|
51
|
+
: 'rgba(255, 255, 255, 0.9)'};
|
|
40
52
|
z-index: 99999;
|
|
41
53
|
overflow: auto;
|
|
42
54
|
|
|
@@ -73,8 +85,8 @@ const ModalContainer = styled.div`
|
|
|
73
85
|
|
|
74
86
|
.close {
|
|
75
87
|
position: absolute;
|
|
76
|
-
right:
|
|
77
|
-
top:
|
|
88
|
+
right: 20px;
|
|
89
|
+
top: 20px;
|
|
78
90
|
|
|
79
91
|
@media (max-width: 425px) {
|
|
80
92
|
right: 14px;
|
|
@@ -93,46 +105,55 @@ const ModalContainer = styled.div`
|
|
|
93
105
|
`
|
|
94
106
|
|
|
95
107
|
export default {
|
|
96
|
-
name:
|
|
108
|
+
name: 'modal',
|
|
97
109
|
components: {
|
|
98
110
|
PageWrapper,
|
|
99
111
|
ModalContainer,
|
|
100
112
|
CloseButton,
|
|
101
113
|
Spinner,
|
|
114
|
+
ContentContainer
|
|
102
115
|
},
|
|
103
116
|
props: {
|
|
104
117
|
isOpen: {
|
|
105
118
|
required: true,
|
|
106
|
-
default: false
|
|
119
|
+
default: false
|
|
107
120
|
},
|
|
108
121
|
preventOutsideClose: {
|
|
109
122
|
required: false,
|
|
110
|
-
default: false
|
|
123
|
+
default: false
|
|
111
124
|
},
|
|
112
125
|
isLoading: {
|
|
113
126
|
required: false,
|
|
114
|
-
default: false
|
|
127
|
+
default: false
|
|
115
128
|
},
|
|
116
129
|
hideClose: {
|
|
117
130
|
required: false,
|
|
118
|
-
default: false
|
|
131
|
+
default: false
|
|
132
|
+
},
|
|
133
|
+
backdrop: {
|
|
134
|
+
required: false,
|
|
135
|
+
default: 'white'
|
|
119
136
|
},
|
|
137
|
+
fullwidthSpinner: {
|
|
138
|
+
required: false,
|
|
139
|
+
default: true
|
|
140
|
+
}
|
|
120
141
|
},
|
|
121
142
|
methods: {
|
|
122
143
|
onCloseModal() {
|
|
123
|
-
this.$emit(
|
|
144
|
+
this.$emit('on-close')
|
|
124
145
|
},
|
|
125
146
|
onOutsideClose() {
|
|
126
147
|
// If true, then only allow closing to come from clicking the X or wherever the onCloseModal is called
|
|
127
148
|
if (!this.preventOutsideClose) {
|
|
128
|
-
this.$emit(
|
|
149
|
+
this.$emit('on-close')
|
|
129
150
|
}
|
|
130
|
-
}
|
|
151
|
+
}
|
|
131
152
|
},
|
|
132
153
|
watch: {
|
|
133
154
|
isOpen: function (newVal) {
|
|
134
|
-
document.body.style.overflow = newVal ?
|
|
135
|
-
}
|
|
136
|
-
}
|
|
155
|
+
document.body.style.overflow = newVal ? 'hidden' : ''
|
|
156
|
+
}
|
|
157
|
+
}
|
|
137
158
|
}
|
|
138
|
-
</script>
|
|
159
|
+
</script>
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
backdrop: 'dark',
|
|
30
|
+
})
|
|
31
|
+
Default.args = {};
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<script>
|
|
19
19
|
// import Spinner from "@eturnity/eturnity_reusable_components/src/components/spinner"
|
|
20
20
|
// <spinner size="30px" />
|
|
21
|
-
import styled from
|
|
21
|
+
import styled from 'vue-styled-components'
|
|
22
22
|
|
|
23
23
|
const SpinnerContainer = styled.div`
|
|
24
24
|
position: fixed;
|
|
@@ -37,29 +37,32 @@ const Container = styled.div`
|
|
|
37
37
|
display: grid;
|
|
38
38
|
align-items: center;
|
|
39
39
|
justify-items: center;
|
|
40
|
+
position: absolute;
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: 100%;
|
|
40
43
|
`
|
|
41
44
|
|
|
42
45
|
const spinnerAttrs = { size: String }
|
|
43
|
-
const SpinnerWrapper = styled(
|
|
44
|
-
width: ${(props) => (props.size ? props.size :
|
|
46
|
+
const SpinnerWrapper = styled('img', spinnerAttrs)`
|
|
47
|
+
width: ${(props) => (props.size ? props.size : '60px')};
|
|
45
48
|
`
|
|
46
49
|
|
|
47
50
|
export default {
|
|
48
|
-
name:
|
|
51
|
+
name: 'spinner',
|
|
49
52
|
components: {
|
|
50
53
|
Container,
|
|
51
54
|
SpinnerWrapper,
|
|
52
|
-
SpinnerContainer
|
|
55
|
+
SpinnerContainer
|
|
53
56
|
},
|
|
54
57
|
props: {
|
|
55
58
|
fullWidth: {
|
|
56
59
|
required: false,
|
|
57
|
-
default: false
|
|
60
|
+
default: false
|
|
58
61
|
},
|
|
59
62
|
size: {
|
|
60
63
|
required: false,
|
|
61
|
-
default: null
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
+
default: null
|
|
65
|
+
}
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
|
-
</script>
|
|
68
|
+
</script>
|
|
@@ -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
|
}
|