@eturnity/eturnity_reusable_components 1.0.38 → 1.0.42
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 +1 -1
- package/src/App.vue +18 -11
- package/src/components/inputs/inputNumber/index.vue +127 -59
- package/src/components/inputs/inputNumberQuestion/index.vue +215 -0
- package/src/components/inputs/toggle/index.vue +23 -7
- package/src/components/tables/mainTable/exampleNested.vue +4 -4
- package/src/components/tables/mainTable/index.vue +32 -13
- package/src/helpers/numberConverter.js +5 -5
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<ThemeProvider :theme="getTheme()" :style="{ height: '100%' }">
|
|
3
3
|
<page-container>
|
|
4
|
-
<main-table>
|
|
4
|
+
<main-table titleText="My Table">
|
|
5
5
|
<thead>
|
|
6
6
|
<tr>
|
|
7
7
|
<th>Column 1</th>
|
|
@@ -13,7 +13,20 @@
|
|
|
13
13
|
</thead>
|
|
14
14
|
<tbody>
|
|
15
15
|
<tr>
|
|
16
|
-
<td
|
|
16
|
+
<td>
|
|
17
|
+
<input-number
|
|
18
|
+
placeholder="Enter distance"
|
|
19
|
+
:isError="false"
|
|
20
|
+
:numberPrecision="2"
|
|
21
|
+
unitName="pc"
|
|
22
|
+
:value="inputValue"
|
|
23
|
+
@input-change="onInputChange($event)"
|
|
24
|
+
errorMessage="Enter a number between 1 and 10"
|
|
25
|
+
:disabled="false"
|
|
26
|
+
:noBorder="true"
|
|
27
|
+
textAlign="left"
|
|
28
|
+
/>
|
|
29
|
+
</td>
|
|
17
30
|
<td class="text">Body 2</td>
|
|
18
31
|
<td class="text">Body 3</td>
|
|
19
32
|
<td class="text">Body 4</td>
|
|
@@ -23,12 +36,6 @@
|
|
|
23
36
|
</tr>
|
|
24
37
|
</tbody>
|
|
25
38
|
</main-table>
|
|
26
|
-
<checkbox
|
|
27
|
-
:isChecked="false"
|
|
28
|
-
@on-event-handler="onInputChange($event)"
|
|
29
|
-
size="small"
|
|
30
|
-
:isDisabled="false"
|
|
31
|
-
/>
|
|
32
39
|
</page-container>
|
|
33
40
|
</ThemeProvider>
|
|
34
41
|
</template>
|
|
@@ -39,7 +46,7 @@ import theme from "./assets/theme"
|
|
|
39
46
|
import styled from "vue-styled-components"
|
|
40
47
|
import MainTable from "@/components/tables/mainTable"
|
|
41
48
|
import ThreeDots from "@/components/threeDots"
|
|
42
|
-
import
|
|
49
|
+
import InputNumber from "@/components/inputs/inputNumber"
|
|
43
50
|
|
|
44
51
|
const PageContainer = styled.div`
|
|
45
52
|
padding: 40px;
|
|
@@ -52,11 +59,11 @@ export default {
|
|
|
52
59
|
PageContainer,
|
|
53
60
|
MainTable,
|
|
54
61
|
ThreeDots,
|
|
55
|
-
|
|
62
|
+
InputNumber,
|
|
56
63
|
},
|
|
57
64
|
data() {
|
|
58
65
|
return {
|
|
59
|
-
inputValue:
|
|
66
|
+
inputValue: "",
|
|
60
67
|
checkedOption: "button_1",
|
|
61
68
|
question: {
|
|
62
69
|
number_format_precision: 4,
|
|
@@ -2,21 +2,25 @@
|
|
|
2
2
|
<container>
|
|
3
3
|
<input-wrapper>
|
|
4
4
|
<input-container
|
|
5
|
-
:hasUnit="!!
|
|
5
|
+
:hasUnit="unitName && !!unitName.length"
|
|
6
6
|
:placeholder="placeholder"
|
|
7
7
|
:isError="isError"
|
|
8
8
|
:inputWidth="inputWidth"
|
|
9
|
-
:value="
|
|
10
|
-
:hasLength="!!
|
|
11
|
-
@
|
|
12
|
-
@
|
|
9
|
+
:value="formatWithCurrency(value)"
|
|
10
|
+
:hasLength="!!value.length"
|
|
11
|
+
@blur="onInputBlur($event)"
|
|
12
|
+
@focus="focusInput()"
|
|
13
13
|
@keyup.enter="$emit('on-enter-click')"
|
|
14
|
+
:disabled="disabled"
|
|
15
|
+
:isDisabled="disabled"
|
|
16
|
+
:noBorder="noBorder"
|
|
17
|
+
:textAlign="textAlign"
|
|
14
18
|
/>
|
|
15
19
|
<unit-container
|
|
16
|
-
v-if="
|
|
20
|
+
v-if="unitName && showLinearUnitName"
|
|
17
21
|
:hasLength="!!textInput.length"
|
|
18
22
|
:isError="isError"
|
|
19
|
-
>{{
|
|
23
|
+
>{{ unitName }}</unit-container
|
|
20
24
|
>
|
|
21
25
|
</input-wrapper>
|
|
22
26
|
<error-message v-if="isError">{{ errorMessage }}</error-message>
|
|
@@ -24,26 +28,25 @@
|
|
|
24
28
|
</template>
|
|
25
29
|
|
|
26
30
|
<script>
|
|
27
|
-
// import
|
|
31
|
+
// import InputNumberQuestion from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumberQuestion"
|
|
28
32
|
//This component should be used for questions with input fields only
|
|
29
33
|
//How to use:
|
|
30
34
|
// <input-number
|
|
31
35
|
// placeholder="Enter distance"
|
|
32
36
|
// :isError="false" //default is false
|
|
33
37
|
// inputWidth="150px" //by default, this is 100%
|
|
34
|
-
// :
|
|
38
|
+
// :numberPrecision="3"
|
|
39
|
+
// unitName="pc"
|
|
40
|
+
// :numberPrecision="4"
|
|
35
41
|
// :value="inputValue" //required -- String
|
|
36
42
|
// @input-change="onInputChange($event)" //required
|
|
37
43
|
// @on-enter-click="onInputSubmit()"
|
|
38
44
|
// :errorMessage="Enter a number between 1 and 10"
|
|
45
|
+
// :disabled="false"
|
|
46
|
+
// :noBorder="true"
|
|
47
|
+
// textAlign="left" // "left, right, center"
|
|
48
|
+
// :showLinearUnitName="true"
|
|
39
49
|
// />
|
|
40
|
-
// question data example:
|
|
41
|
-
// question: {
|
|
42
|
-
// number_format_precision: 4,
|
|
43
|
-
// number_min_allowed: 0,
|
|
44
|
-
// number_max_allowed: 10,
|
|
45
|
-
// unit_short_name: "cm",
|
|
46
|
-
// },
|
|
47
50
|
import styled from "vue-styled-components"
|
|
48
51
|
import {
|
|
49
52
|
stringToNumber,
|
|
@@ -60,22 +63,32 @@ const inputProps = {
|
|
|
60
63
|
hasUnit: Boolean,
|
|
61
64
|
inputWidth: String,
|
|
62
65
|
hasLength: Boolean,
|
|
66
|
+
isDisabled: Boolean,
|
|
67
|
+
noBorder: Boolean,
|
|
68
|
+
textAlign: String,
|
|
63
69
|
}
|
|
64
70
|
const InputContainer = styled("input", inputProps)`
|
|
65
|
-
border:
|
|
66
|
-
|
|
67
|
-
props.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
border: ${(props) =>
|
|
72
|
+
props.isError
|
|
73
|
+
? "1px solid " + props.theme.colors.red
|
|
74
|
+
: props.noBorder
|
|
75
|
+
? "none"
|
|
76
|
+
: props.hasLength
|
|
77
|
+
? "1px solid " + props.theme.colors.black
|
|
78
|
+
: "1px solid " + props.theme.colors.mediumGray};
|
|
72
79
|
padding: ${(props) =>
|
|
73
80
|
props.hasUnit ? "11px 40px 11px 10px" : "11px 5px 11px 10px"};
|
|
74
81
|
border-radius: 4px;
|
|
82
|
+
text-align: ${(props) => props.textAlign};
|
|
83
|
+
cursor: ${(props) => (props.isDisabled ? "not-allowed" : "auto")};
|
|
75
84
|
font-size: 16px;
|
|
76
85
|
color: ${(props) =>
|
|
77
|
-
props.isError ? props.theme.colors.red : props.theme.colors.
|
|
78
|
-
width: ${(props) => (props.inputWidth ? props.inputWidth : "
|
|
86
|
+
props.isError ? props.theme.colors.red : props.theme.colors.black};
|
|
87
|
+
width: ${(props) => (props.inputWidth ? props.inputWidth : "100%")};
|
|
88
|
+
background-color: ${(props) =>
|
|
89
|
+
props.isDisabled
|
|
90
|
+
? props.theme.colors.grey5 + " !important"
|
|
91
|
+
: "#fff !important"};
|
|
79
92
|
|
|
80
93
|
&::placeholder {
|
|
81
94
|
color: ${(props) =>
|
|
@@ -97,7 +110,7 @@ const UnitContainer = styled("span", inputProps)`
|
|
|
97
110
|
props.isError
|
|
98
111
|
? props.theme.colors.red
|
|
99
112
|
: props.hasLength
|
|
100
|
-
? props.theme.colors.
|
|
113
|
+
? props.theme.colors.black
|
|
101
114
|
: props.theme.colors.mediumGray};
|
|
102
115
|
position: absolute;
|
|
103
116
|
right: 10px;
|
|
@@ -107,7 +120,7 @@ const UnitContainer = styled("span", inputProps)`
|
|
|
107
120
|
props.isError
|
|
108
121
|
? props.theme.colors.red
|
|
109
122
|
: props.hasLength
|
|
110
|
-
? props.theme.colors.
|
|
123
|
+
? props.theme.colors.black
|
|
111
124
|
: props.theme.colors.mediumGray};
|
|
112
125
|
`
|
|
113
126
|
|
|
@@ -129,9 +142,7 @@ export default {
|
|
|
129
142
|
data() {
|
|
130
143
|
return {
|
|
131
144
|
textInput: "",
|
|
132
|
-
|
|
133
|
-
minValue: 0,
|
|
134
|
-
maxValue: 100,
|
|
145
|
+
isFocused: false,
|
|
135
146
|
}
|
|
136
147
|
},
|
|
137
148
|
props: {
|
|
@@ -143,9 +154,6 @@ export default {
|
|
|
143
154
|
required: false,
|
|
144
155
|
default: false,
|
|
145
156
|
},
|
|
146
|
-
question: {
|
|
147
|
-
required: true,
|
|
148
|
-
},
|
|
149
157
|
inputWidth: {
|
|
150
158
|
required: false,
|
|
151
159
|
default: null,
|
|
@@ -162,35 +170,100 @@ export default {
|
|
|
162
170
|
required: false,
|
|
163
171
|
default: "Please insert a correct number",
|
|
164
172
|
},
|
|
173
|
+
numberPrecision: {
|
|
174
|
+
required: false,
|
|
175
|
+
default: 0,
|
|
176
|
+
},
|
|
177
|
+
unitName: {
|
|
178
|
+
required: false,
|
|
179
|
+
default: "",
|
|
180
|
+
},
|
|
181
|
+
showLinearUnitName: {
|
|
182
|
+
required: false,
|
|
183
|
+
default: false,
|
|
184
|
+
},
|
|
185
|
+
disabled: {
|
|
186
|
+
required: false,
|
|
187
|
+
default: false,
|
|
188
|
+
},
|
|
189
|
+
noBorder: {
|
|
190
|
+
required: false,
|
|
191
|
+
default: false,
|
|
192
|
+
},
|
|
193
|
+
textAlign: {
|
|
194
|
+
required: false,
|
|
195
|
+
default: "left",
|
|
196
|
+
},
|
|
165
197
|
},
|
|
166
198
|
methods: {
|
|
167
|
-
onChangeHandler(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
value: $event,
|
|
171
|
-
numberPrecision: this.numberPrecision,
|
|
172
|
-
})
|
|
173
|
-
if (isNaN(formattedValue)) {
|
|
174
|
-
this.textInput = ""
|
|
175
|
-
formattedValue = ""
|
|
199
|
+
onChangeHandler(event) {
|
|
200
|
+
if (isNaN(event)) {
|
|
201
|
+
event = ""
|
|
176
202
|
}
|
|
177
|
-
this.$emit("input-change",
|
|
203
|
+
this.$emit("input-change", event)
|
|
178
204
|
},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
205
|
+
onEvaluateCode(val) {
|
|
206
|
+
// function to perform math on the code
|
|
207
|
+
// filter the string in case of any malicious content
|
|
208
|
+
let filtered = val.replace(/[^-()\d/*+.,]/g, "")
|
|
209
|
+
filtered = filtered.split(/([-+*/()])/)
|
|
210
|
+
let formatted = filtered.map((item) => {
|
|
211
|
+
if (
|
|
212
|
+
item === "+" ||
|
|
213
|
+
item === "-" ||
|
|
214
|
+
item === "*" ||
|
|
215
|
+
item === "/" ||
|
|
216
|
+
item === "(" ||
|
|
217
|
+
item === ")" ||
|
|
218
|
+
item === ""
|
|
219
|
+
) {
|
|
220
|
+
return item
|
|
221
|
+
} else {
|
|
222
|
+
let num = stringToNumber({
|
|
223
|
+
value: item,
|
|
224
|
+
numberPrecision: this.numberPrecision,
|
|
225
|
+
})
|
|
226
|
+
return num
|
|
227
|
+
}
|
|
187
228
|
})
|
|
229
|
+
let evaluated = eval(formatted.join(""))
|
|
230
|
+
return evaluated
|
|
231
|
+
},
|
|
232
|
+
onInputBlur(e) {
|
|
233
|
+
this.isFocused = false
|
|
234
|
+
let value = e.target.value
|
|
235
|
+
let evaluatedInput = this.onEvaluateCode(value)
|
|
236
|
+
this.onChangeHandler(evaluatedInput)
|
|
237
|
+
if (value.length) {
|
|
238
|
+
this.textInput = numberToString({
|
|
239
|
+
value: evaluatedInput,
|
|
240
|
+
numberPrecision: this.numberPrecision,
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
focusInput() {
|
|
245
|
+
if (this.disabled) {
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
this.isFocused = true
|
|
249
|
+
},
|
|
250
|
+
formatWithCurrency(value) {
|
|
251
|
+
if (value && !this.isFocused) {
|
|
252
|
+
let input = numberToString({
|
|
253
|
+
value: value,
|
|
254
|
+
numberPrecision: this.numberPrecision,
|
|
255
|
+
})
|
|
256
|
+
let unit = this.showLinearUnitName ? "" : this.unitName
|
|
257
|
+
return input + " " + unit
|
|
258
|
+
} else {
|
|
259
|
+
return numberToString({
|
|
260
|
+
value: value,
|
|
261
|
+
numberPrecision: this.numberPrecision,
|
|
262
|
+
})
|
|
263
|
+
}
|
|
188
264
|
},
|
|
189
265
|
},
|
|
190
266
|
created() {
|
|
191
|
-
this.numberPrecision = this.question.number_format_precision
|
|
192
|
-
this.minValue = this.question.number_min_allowed
|
|
193
|
-
this.maxValue = this.question.number_max_allowed
|
|
194
267
|
if (this.value) {
|
|
195
268
|
this.textInput = numberToString({
|
|
196
269
|
value: this.value,
|
|
@@ -205,11 +278,6 @@ export default {
|
|
|
205
278
|
this.textInput = ""
|
|
206
279
|
}
|
|
207
280
|
},
|
|
208
|
-
question: function (value) {
|
|
209
|
-
this.numberPrecision = value.number_format_precision
|
|
210
|
-
this.minValue = value.number_min_allowed
|
|
211
|
-
this.maxValue = value.number_max_allowed
|
|
212
|
-
},
|
|
213
281
|
},
|
|
214
282
|
}
|
|
215
283
|
</script>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<container>
|
|
3
|
+
<input-wrapper>
|
|
4
|
+
<input-container
|
|
5
|
+
:hasUnit="!!question.unit_short_name"
|
|
6
|
+
:placeholder="placeholder"
|
|
7
|
+
:isError="isError"
|
|
8
|
+
:inputWidth="inputWidth"
|
|
9
|
+
:value="textInput"
|
|
10
|
+
:hasLength="!!textInput.length"
|
|
11
|
+
@input="onChangeHandler"
|
|
12
|
+
@blur="onInputBlur()"
|
|
13
|
+
@keyup.enter="$emit('on-enter-click')"
|
|
14
|
+
/>
|
|
15
|
+
<unit-container
|
|
16
|
+
v-if="question.unit_short_name"
|
|
17
|
+
:hasLength="!!textInput.length"
|
|
18
|
+
:isError="isError"
|
|
19
|
+
>{{ question.unit_short_name }}</unit-container
|
|
20
|
+
>
|
|
21
|
+
</input-wrapper>
|
|
22
|
+
<error-message v-if="isError">{{ errorMessage }}</error-message>
|
|
23
|
+
</container>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
// import InputNumberQuestion from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumberQuestion"
|
|
28
|
+
//This component should be used for questions with input fields only
|
|
29
|
+
//How to use:
|
|
30
|
+
// <input-number
|
|
31
|
+
// placeholder="Enter distance"
|
|
32
|
+
// :isError="false" //default is false
|
|
33
|
+
// inputWidth="150px" //by default, this is 100%
|
|
34
|
+
// :question="question"
|
|
35
|
+
// :value="inputValue" //required -- String
|
|
36
|
+
// @input-change="onInputChange($event)" //required
|
|
37
|
+
// @on-enter-click="onInputSubmit()"
|
|
38
|
+
// :errorMessage="Enter a number between 1 and 10"
|
|
39
|
+
// />
|
|
40
|
+
// question data example:
|
|
41
|
+
// question: {
|
|
42
|
+
// number_format_precision: 4,
|
|
43
|
+
// number_min_allowed: 0,
|
|
44
|
+
// number_max_allowed: 10,
|
|
45
|
+
// unit_short_name: "cm",
|
|
46
|
+
// },
|
|
47
|
+
import styled from "vue-styled-components"
|
|
48
|
+
import {
|
|
49
|
+
stringToNumber,
|
|
50
|
+
numberToString,
|
|
51
|
+
} from "../../../helpers/numberConverter"
|
|
52
|
+
|
|
53
|
+
const Container = styled.div`
|
|
54
|
+
width: 100%;
|
|
55
|
+
position: relative;
|
|
56
|
+
`
|
|
57
|
+
|
|
58
|
+
const inputProps = {
|
|
59
|
+
isError: Boolean,
|
|
60
|
+
hasUnit: Boolean,
|
|
61
|
+
inputWidth: String,
|
|
62
|
+
hasLength: Boolean,
|
|
63
|
+
}
|
|
64
|
+
const InputContainer = styled("input", inputProps)`
|
|
65
|
+
border: 1px solid
|
|
66
|
+
${(props) =>
|
|
67
|
+
props.isError
|
|
68
|
+
? props.theme.colors.red
|
|
69
|
+
: props.hasLength
|
|
70
|
+
? props.theme.colors.primary
|
|
71
|
+
: props.theme.colors.mediumGray};
|
|
72
|
+
padding: ${(props) =>
|
|
73
|
+
props.hasUnit ? "11px 40px 11px 10px" : "11px 5px 11px 10px"};
|
|
74
|
+
border-radius: 4px;
|
|
75
|
+
font-size: 16px;
|
|
76
|
+
color: ${(props) =>
|
|
77
|
+
props.isError ? props.theme.colors.red : props.theme.colors.primary};
|
|
78
|
+
width: ${(props) => (props.inputWidth ? props.inputWidth : "auto")};
|
|
79
|
+
|
|
80
|
+
&::placeholder {
|
|
81
|
+
color: ${(props) =>
|
|
82
|
+
props.isError ? props.theme.colors.red : props.theme.colors.darkGray};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&:focus {
|
|
86
|
+
outline: none;
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
|
|
90
|
+
const InputWrapper = styled.span`
|
|
91
|
+
position: relative;
|
|
92
|
+
`
|
|
93
|
+
|
|
94
|
+
const UnitContainer = styled("span", inputProps)`
|
|
95
|
+
border-left: 1px solid
|
|
96
|
+
${(props) =>
|
|
97
|
+
props.isError
|
|
98
|
+
? props.theme.colors.red
|
|
99
|
+
: props.hasLength
|
|
100
|
+
? props.theme.colors.primary
|
|
101
|
+
: props.theme.colors.mediumGray};
|
|
102
|
+
position: absolute;
|
|
103
|
+
right: 10px;
|
|
104
|
+
top: 0;
|
|
105
|
+
padding-left: 10px;
|
|
106
|
+
color: ${(props) =>
|
|
107
|
+
props.isError
|
|
108
|
+
? props.theme.colors.red
|
|
109
|
+
: props.hasLength
|
|
110
|
+
? props.theme.colors.primary
|
|
111
|
+
: props.theme.colors.mediumGray};
|
|
112
|
+
`
|
|
113
|
+
|
|
114
|
+
const ErrorMessage = styled.div`
|
|
115
|
+
font-size: 14px;
|
|
116
|
+
color: ${(props) => props.theme.colors.red};
|
|
117
|
+
padding-top: 16px;
|
|
118
|
+
`
|
|
119
|
+
|
|
120
|
+
export default {
|
|
121
|
+
name: "input-number-question",
|
|
122
|
+
components: {
|
|
123
|
+
Container,
|
|
124
|
+
InputContainer,
|
|
125
|
+
InputWrapper,
|
|
126
|
+
UnitContainer,
|
|
127
|
+
ErrorMessage,
|
|
128
|
+
},
|
|
129
|
+
data() {
|
|
130
|
+
return {
|
|
131
|
+
textInput: "",
|
|
132
|
+
numberPrecision: 0, // we set this on created. By default is 0
|
|
133
|
+
minValue: 0,
|
|
134
|
+
maxValue: 100,
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
props: {
|
|
138
|
+
placeholder: {
|
|
139
|
+
required: false,
|
|
140
|
+
default: "",
|
|
141
|
+
},
|
|
142
|
+
isError: {
|
|
143
|
+
required: false,
|
|
144
|
+
default: false,
|
|
145
|
+
},
|
|
146
|
+
question: {
|
|
147
|
+
required: true,
|
|
148
|
+
},
|
|
149
|
+
inputWidth: {
|
|
150
|
+
required: false,
|
|
151
|
+
default: null,
|
|
152
|
+
},
|
|
153
|
+
value: {
|
|
154
|
+
required: true,
|
|
155
|
+
default: null,
|
|
156
|
+
},
|
|
157
|
+
clearInput: {
|
|
158
|
+
required: false,
|
|
159
|
+
default: false,
|
|
160
|
+
},
|
|
161
|
+
errorMessage: {
|
|
162
|
+
required: false,
|
|
163
|
+
default: "Please insert a correct number",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
methods: {
|
|
167
|
+
onChangeHandler($event) {
|
|
168
|
+
this.textInput = $event
|
|
169
|
+
let formattedValue = stringToNumber({
|
|
170
|
+
value: $event,
|
|
171
|
+
numberPrecision: this.numberPrecision,
|
|
172
|
+
})
|
|
173
|
+
if (isNaN(formattedValue)) {
|
|
174
|
+
this.textInput = ""
|
|
175
|
+
formattedValue = ""
|
|
176
|
+
}
|
|
177
|
+
this.$emit("input-change", formattedValue)
|
|
178
|
+
},
|
|
179
|
+
onInputBlur() {
|
|
180
|
+
let num = stringToNumber({
|
|
181
|
+
value: this.textInput,
|
|
182
|
+
numberPrecision: this.numberPrecision,
|
|
183
|
+
})
|
|
184
|
+
this.textInput = numberToString({
|
|
185
|
+
value: num,
|
|
186
|
+
numberPrecision: this.numberPrecision,
|
|
187
|
+
})
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
created() {
|
|
191
|
+
this.numberPrecision = this.question.number_format_precision
|
|
192
|
+
this.minValue = this.question.number_min_allowed
|
|
193
|
+
this.maxValue = this.question.number_max_allowed
|
|
194
|
+
if (this.value) {
|
|
195
|
+
this.textInput = numberToString({
|
|
196
|
+
value: this.value,
|
|
197
|
+
numberPrecision: this.numberPrecision,
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
watch: {
|
|
202
|
+
clearInput: function (value) {
|
|
203
|
+
if (value) {
|
|
204
|
+
// If the value is typed, then we should clear the textInput on Continue
|
|
205
|
+
this.textInput = ""
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
question: function (value) {
|
|
209
|
+
this.numberPrecision = value.number_format_precision
|
|
210
|
+
this.minValue = value.number_min_allowed
|
|
211
|
+
this.maxValue = value.number_max_allowed
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
</script>
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
tabindex="0"
|
|
12
12
|
@click="onToggleChange"
|
|
13
13
|
@keydown.space.prevent="onToggleChange"
|
|
14
|
+
:disabled="disabled"
|
|
14
15
|
>
|
|
15
16
|
<toggle-background :backgroundColor="backgroundColor" />
|
|
16
17
|
<toggle-dot
|
|
17
18
|
:isChecked="isChecked"
|
|
18
19
|
:toggleColor="toggleColor"
|
|
19
20
|
:size="size"
|
|
21
|
+
:disabled="disabled"
|
|
20
22
|
/>
|
|
21
23
|
</toggle-wrapper>
|
|
22
24
|
<label-text
|
|
@@ -62,7 +64,7 @@ const FlexWrapper = styled("div", flexAttrs)`
|
|
|
62
64
|
align-items: center;
|
|
63
65
|
`
|
|
64
66
|
|
|
65
|
-
const toggleAttrs = { size: String, fontColor: String }
|
|
67
|
+
const toggleAttrs = { size: String, fontColor: String, disabled: Boolean }
|
|
66
68
|
const LabelText = styled("div", toggleAttrs)`
|
|
67
69
|
color: ${(props) =>
|
|
68
70
|
props.fontColor ? props.fontColor : props.theme.colors.darkGray};
|
|
@@ -77,7 +79,7 @@ const LabelText = styled("div", toggleAttrs)`
|
|
|
77
79
|
const ToggleWrapper = styled("span", toggleAttrs)`
|
|
78
80
|
display: inline-block;
|
|
79
81
|
position: relative;
|
|
80
|
-
cursor: pointer;
|
|
82
|
+
cursor: ${(props) => (props.disabled ? "not-allowed" : "pointer")};
|
|
81
83
|
width: ${(props) =>
|
|
82
84
|
props.size === "medium"
|
|
83
85
|
? "50px"
|
|
@@ -115,7 +117,12 @@ const ToggleBackground = styled("span", backroundAttrs)`
|
|
|
115
117
|
transition: 0.4s ease;
|
|
116
118
|
`
|
|
117
119
|
|
|
118
|
-
const toggleProps = {
|
|
120
|
+
const toggleProps = {
|
|
121
|
+
isChecked: Boolean,
|
|
122
|
+
toggleColor: String,
|
|
123
|
+
size: String,
|
|
124
|
+
disabled: Boolean,
|
|
125
|
+
}
|
|
119
126
|
const ToggleDot = styled("span", toggleProps)`
|
|
120
127
|
position: absolute;
|
|
121
128
|
height: ${(props) =>
|
|
@@ -134,7 +141,9 @@ const ToggleDot = styled("span", toggleProps)`
|
|
|
134
141
|
bottom: ${(props) =>
|
|
135
142
|
props.size === "medium" ? "5px" : props.size === "small" ? "3px" : "5px"};
|
|
136
143
|
background-color: ${(props) =>
|
|
137
|
-
props.
|
|
144
|
+
props.disabled
|
|
145
|
+
? props.theme.colors.disabled
|
|
146
|
+
: props.isChecked
|
|
138
147
|
? props.toggleColor
|
|
139
148
|
? props.toggleColor
|
|
140
149
|
: props.theme.colors.primary
|
|
@@ -144,17 +153,17 @@ const ToggleDot = styled("span", toggleProps)`
|
|
|
144
153
|
transform: ${(props) =>
|
|
145
154
|
props.isChecked
|
|
146
155
|
? props.size === "medium"
|
|
147
|
-
? "translateX(
|
|
156
|
+
? "translateX(25px)"
|
|
148
157
|
: props.size === "small"
|
|
149
158
|
? "translateX(10px)"
|
|
150
|
-
: "translateX(
|
|
159
|
+
: "translateX(25px)"
|
|
151
160
|
: "translateX(0)"};
|
|
152
161
|
|
|
153
162
|
@media (max-width: ${(props) => props.theme.screen.mobile}) {
|
|
154
163
|
height: 24px;
|
|
155
164
|
width: 24px;
|
|
156
165
|
transform: ${(props) =>
|
|
157
|
-
props.isChecked ? "translateX(
|
|
166
|
+
props.isChecked ? "translateX(25px)" : "translateX(0)"};
|
|
158
167
|
bottom: 8px;
|
|
159
168
|
}
|
|
160
169
|
`
|
|
@@ -195,9 +204,16 @@ export default {
|
|
|
195
204
|
fontColor: {
|
|
196
205
|
required: false,
|
|
197
206
|
},
|
|
207
|
+
disabled: {
|
|
208
|
+
required: false,
|
|
209
|
+
default: false,
|
|
210
|
+
},
|
|
198
211
|
},
|
|
199
212
|
methods: {
|
|
200
213
|
onToggleChange() {
|
|
214
|
+
if (this.disabled) {
|
|
215
|
+
return
|
|
216
|
+
}
|
|
201
217
|
this.$emit("on-toggle-change", !this.isChecked)
|
|
202
218
|
},
|
|
203
219
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- This is just an example how to use mainTable with collective positioning -->
|
|
2
2
|
<!-- <template>
|
|
3
|
-
<
|
|
3
|
+
<main-table>
|
|
4
4
|
<thead>
|
|
5
5
|
<tr>
|
|
6
6
|
<div />
|
|
@@ -156,13 +156,13 @@
|
|
|
156
156
|
<td />
|
|
157
157
|
<div />
|
|
158
158
|
</tr>
|
|
159
|
-
</
|
|
159
|
+
</main-table>
|
|
160
160
|
</template>
|
|
161
161
|
|
|
162
162
|
<script>
|
|
163
163
|
import draggable from "vuedraggable"
|
|
164
164
|
import styled from "vue-styled-components"
|
|
165
|
-
import
|
|
165
|
+
import MainTable from "@/components/reusable-components/tables/MainTable"
|
|
166
166
|
import InputText from "@eturnity/eturnity_reusable_components/src/components/inputs/inputText"
|
|
167
167
|
import DeleteIcon from "@/components/reusable-components/DeleteIcon"
|
|
168
168
|
import ThreeDots from "@/components/reusable-components/ThreeDots"
|
|
@@ -190,7 +190,7 @@ export default {
|
|
|
190
190
|
components: {
|
|
191
191
|
DraggableContainer,
|
|
192
192
|
ParentContainer,
|
|
193
|
-
|
|
193
|
+
MainTable,
|
|
194
194
|
InputText,
|
|
195
195
|
ChildrenWrapper,
|
|
196
196
|
DeleteIcon,
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<table-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<table-
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
<page-container>
|
|
3
|
+
<table-title v-if="titleText">
|
|
4
|
+
{{ titleText }}
|
|
5
|
+
</table-title>
|
|
6
|
+
<table-scroll>
|
|
7
|
+
<table-wrapper :fullWidth="fullWidth">
|
|
8
|
+
<spinner-wrapper v-if="isLoading">
|
|
9
|
+
<spinner />
|
|
10
|
+
</spinner-wrapper>
|
|
11
|
+
<table-container v-else>
|
|
12
|
+
<slot />
|
|
13
|
+
</table-container>
|
|
14
|
+
</table-wrapper>
|
|
15
|
+
</table-scroll>
|
|
16
|
+
</page-container>
|
|
12
17
|
</template>
|
|
13
18
|
|
|
14
19
|
<script>
|
|
@@ -17,6 +22,14 @@
|
|
|
17
22
|
import styled from "vue-styled-components"
|
|
18
23
|
import Spinner from "../../spinner"
|
|
19
24
|
|
|
25
|
+
const PageContainer = styled.div``
|
|
26
|
+
|
|
27
|
+
const TableTitle = styled.div`
|
|
28
|
+
margin-bottom: 6px;
|
|
29
|
+
font-weight: bold;
|
|
30
|
+
font-size: 13px;
|
|
31
|
+
`
|
|
32
|
+
|
|
20
33
|
const TableScroll = styled.div`
|
|
21
34
|
position: relative;
|
|
22
35
|
max-width: 100%;
|
|
@@ -193,8 +206,8 @@ const TableContainer = styled.table`
|
|
|
193
206
|
}
|
|
194
207
|
|
|
195
208
|
&:hover {
|
|
196
|
-
input {
|
|
197
|
-
background-color: ${(props) => props.theme.colors.grey5};
|
|
209
|
+
input:disabled {
|
|
210
|
+
background-color: ${(props) => props.theme.colors.grey5 + "!important"};
|
|
198
211
|
}
|
|
199
212
|
|
|
200
213
|
.drag-icon {
|
|
@@ -251,9 +264,9 @@ const TableContainer = styled.table`
|
|
|
251
264
|
}
|
|
252
265
|
|
|
253
266
|
input {
|
|
254
|
-
border: none;
|
|
255
267
|
font-size: 13px;
|
|
256
268
|
padding: 5px 10px;
|
|
269
|
+
background: #fff !important;
|
|
257
270
|
}
|
|
258
271
|
|
|
259
272
|
.open-container {
|
|
@@ -271,6 +284,8 @@ export default {
|
|
|
271
284
|
SpinnerWrapper,
|
|
272
285
|
Spinner,
|
|
273
286
|
TableContainer,
|
|
287
|
+
PageContainer,
|
|
288
|
+
TableTitle,
|
|
274
289
|
},
|
|
275
290
|
props: {
|
|
276
291
|
fullWidth: {
|
|
@@ -281,6 +296,10 @@ export default {
|
|
|
281
296
|
required: false,
|
|
282
297
|
default: false,
|
|
283
298
|
},
|
|
299
|
+
titleText: {
|
|
300
|
+
required: false,
|
|
301
|
+
default: null,
|
|
302
|
+
},
|
|
284
303
|
},
|
|
285
304
|
}
|
|
286
305
|
</script>
|
|
@@ -7,24 +7,24 @@ export const stringToNumber = ({ value, numberPrecision }) => {
|
|
|
7
7
|
// replace commas with a dot, and dots with blank
|
|
8
8
|
newVal = newVal
|
|
9
9
|
.replace(/[^\d.,']/g, "")
|
|
10
|
-
.replace(/[.\s]
|
|
10
|
+
.replace(/[.\s]/g, "")
|
|
11
11
|
.replace(/[,\s]/, ".")
|
|
12
12
|
} else if (selectedLang === "en-us") {
|
|
13
13
|
// replace commas with blank
|
|
14
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]
|
|
14
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
|
|
15
15
|
} else if (
|
|
16
16
|
selectedLang === "de-ch" ||
|
|
17
17
|
selectedLang === "fr-ch" ||
|
|
18
18
|
selectedLang === "it-ch"
|
|
19
19
|
) {
|
|
20
20
|
// replace ' with blank
|
|
21
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/['\s]
|
|
21
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/['\s]/g, "")
|
|
22
22
|
} else if (selectedLang === "fr-fr") {
|
|
23
23
|
// replace space with blank, and commas with dot
|
|
24
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]
|
|
24
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, ".")
|
|
25
25
|
} else {
|
|
26
26
|
// en-US as default
|
|
27
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]
|
|
27
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
|
|
28
28
|
}
|
|
29
29
|
newVal = parseFloat(newVal).toFixed(numberPrecision)
|
|
30
30
|
return parseFloat(newVal)
|