@eturnity/eturnity_reusable_components 1.0.36 → 1.0.40
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 +17 -10
- package/src/components/deleteIcon/index.vue +4 -4
- package/src/components/inputs/inputNumber/index.vue +122 -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 +9 -1
- package/src/helpers/numberConverter.js +5 -5
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -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,
|
|
@@ -28,16 +28,16 @@ const Icon = styled("span", iconAttrs)`
|
|
|
28
28
|
cursor: pointer;
|
|
29
29
|
background-image: ${(props) =>
|
|
30
30
|
props.color === "red"
|
|
31
|
-
? `url(${require("../../assets/
|
|
31
|
+
? `url(${require("../../assets/icons/delete_icon.svg")})`
|
|
32
32
|
: props.color === "gray"
|
|
33
|
-
? `url(${require("../../assets/
|
|
34
|
-
: `url(${require("../../assets/
|
|
33
|
+
? `url(${require("../../assets/icons/delete_icon_gray.svg")})`
|
|
34
|
+
: `url(${require("../../assets/icons/delete_icon.svg")})`};
|
|
35
35
|
|
|
36
36
|
&:hover {
|
|
37
37
|
box-shadow: 0px 4px 9px 1px rgb(0 0 0 / 20%);
|
|
38
38
|
border-radius: 4px;
|
|
39
39
|
background-image: ${() =>
|
|
40
|
-
`url(${require("../../assets/
|
|
40
|
+
`url(${require("../../assets/icons/delete_icon.svg")})`};
|
|
41
41
|
}
|
|
42
42
|
`
|
|
43
43
|
|
|
@@ -2,21 +2,24 @@
|
|
|
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
|
+
:noBorder="noBorder"
|
|
16
|
+
:textAlign="textAlign"
|
|
14
17
|
/>
|
|
15
18
|
<unit-container
|
|
16
|
-
v-if="
|
|
19
|
+
v-if="unitName && showLinearUnitName"
|
|
17
20
|
:hasLength="!!textInput.length"
|
|
18
21
|
:isError="isError"
|
|
19
|
-
>{{
|
|
22
|
+
>{{ unitName }}</unit-container
|
|
20
23
|
>
|
|
21
24
|
</input-wrapper>
|
|
22
25
|
<error-message v-if="isError">{{ errorMessage }}</error-message>
|
|
@@ -24,26 +27,24 @@
|
|
|
24
27
|
</template>
|
|
25
28
|
|
|
26
29
|
<script>
|
|
27
|
-
// import
|
|
30
|
+
// import InputNumberQuestion from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumberQuestion"
|
|
28
31
|
//This component should be used for questions with input fields only
|
|
29
32
|
//How to use:
|
|
30
33
|
// <input-number
|
|
31
34
|
// placeholder="Enter distance"
|
|
32
35
|
// :isError="false" //default is false
|
|
33
36
|
// inputWidth="150px" //by default, this is 100%
|
|
34
|
-
// :
|
|
37
|
+
// :numberPrecision="3"
|
|
38
|
+
// unitName="pc"
|
|
35
39
|
// :value="inputValue" //required -- String
|
|
36
40
|
// @input-change="onInputChange($event)" //required
|
|
37
41
|
// @on-enter-click="onInputSubmit()"
|
|
38
42
|
// :errorMessage="Enter a number between 1 and 10"
|
|
43
|
+
// :disabled="false"
|
|
44
|
+
// :noBorder="true"
|
|
45
|
+
// textAlign="left" // "left, right, center"
|
|
46
|
+
// :showLinearUnitName="true"
|
|
39
47
|
// />
|
|
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
48
|
import styled from "vue-styled-components"
|
|
48
49
|
import {
|
|
49
50
|
stringToNumber,
|
|
@@ -60,22 +61,32 @@ const inputProps = {
|
|
|
60
61
|
hasUnit: Boolean,
|
|
61
62
|
inputWidth: String,
|
|
62
63
|
hasLength: Boolean,
|
|
64
|
+
disabled: Boolean,
|
|
65
|
+
noBorder: Boolean,
|
|
66
|
+
textAlign: String,
|
|
63
67
|
}
|
|
64
68
|
const InputContainer = styled("input", inputProps)`
|
|
65
|
-
border:
|
|
66
|
-
|
|
67
|
-
props.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
border: ${(props) =>
|
|
70
|
+
props.isError
|
|
71
|
+
? "1px solid " + props.theme.colors.red
|
|
72
|
+
: props.noBorder
|
|
73
|
+
? "none"
|
|
74
|
+
: props.hasLength
|
|
75
|
+
? "1px solid " + props.theme.colors.black
|
|
76
|
+
: "1px solid " + props.theme.colors.mediumGray};
|
|
72
77
|
padding: ${(props) =>
|
|
73
78
|
props.hasUnit ? "11px 40px 11px 10px" : "11px 5px 11px 10px"};
|
|
74
79
|
border-radius: 4px;
|
|
80
|
+
text-align: ${(props) => props.textAlign};
|
|
81
|
+
cursor: ${(props) => (props.disabled ? "not-allowed" : "auto")};
|
|
75
82
|
font-size: 16px;
|
|
76
83
|
color: ${(props) =>
|
|
77
|
-
props.isError ? props.theme.colors.red : props.theme.colors.
|
|
78
|
-
width: ${(props) => (props.inputWidth ? props.inputWidth : "
|
|
84
|
+
props.isError ? props.theme.colors.red : props.theme.colors.black};
|
|
85
|
+
width: ${(props) => (props.inputWidth ? props.inputWidth : "100%")};
|
|
86
|
+
background-color: ${(props) =>
|
|
87
|
+
props.disabled
|
|
88
|
+
? props.theme.colors.grey5 + " !important"
|
|
89
|
+
: "#fff !important"};
|
|
79
90
|
|
|
80
91
|
&::placeholder {
|
|
81
92
|
color: ${(props) =>
|
|
@@ -97,7 +108,7 @@ const UnitContainer = styled("span", inputProps)`
|
|
|
97
108
|
props.isError
|
|
98
109
|
? props.theme.colors.red
|
|
99
110
|
: props.hasLength
|
|
100
|
-
? props.theme.colors.
|
|
111
|
+
? props.theme.colors.black
|
|
101
112
|
: props.theme.colors.mediumGray};
|
|
102
113
|
position: absolute;
|
|
103
114
|
right: 10px;
|
|
@@ -107,7 +118,7 @@ const UnitContainer = styled("span", inputProps)`
|
|
|
107
118
|
props.isError
|
|
108
119
|
? props.theme.colors.red
|
|
109
120
|
: props.hasLength
|
|
110
|
-
? props.theme.colors.
|
|
121
|
+
? props.theme.colors.black
|
|
111
122
|
: props.theme.colors.mediumGray};
|
|
112
123
|
`
|
|
113
124
|
|
|
@@ -129,9 +140,7 @@ export default {
|
|
|
129
140
|
data() {
|
|
130
141
|
return {
|
|
131
142
|
textInput: "",
|
|
132
|
-
|
|
133
|
-
minValue: 0,
|
|
134
|
-
maxValue: 100,
|
|
143
|
+
isFocused: false,
|
|
135
144
|
}
|
|
136
145
|
},
|
|
137
146
|
props: {
|
|
@@ -143,9 +152,6 @@ export default {
|
|
|
143
152
|
required: false,
|
|
144
153
|
default: false,
|
|
145
154
|
},
|
|
146
|
-
question: {
|
|
147
|
-
required: true,
|
|
148
|
-
},
|
|
149
155
|
inputWidth: {
|
|
150
156
|
required: false,
|
|
151
157
|
default: null,
|
|
@@ -162,35 +168,97 @@ export default {
|
|
|
162
168
|
required: false,
|
|
163
169
|
default: "Please insert a correct number",
|
|
164
170
|
},
|
|
171
|
+
numberPrecision: {
|
|
172
|
+
required: false,
|
|
173
|
+
default: 0,
|
|
174
|
+
},
|
|
175
|
+
unitName: {
|
|
176
|
+
required: false,
|
|
177
|
+
default: "",
|
|
178
|
+
},
|
|
179
|
+
showLinearUnitName: {
|
|
180
|
+
required: false,
|
|
181
|
+
default: false,
|
|
182
|
+
},
|
|
183
|
+
disabled: {
|
|
184
|
+
required: false,
|
|
185
|
+
default: false,
|
|
186
|
+
},
|
|
187
|
+
noBorder: {
|
|
188
|
+
required: false,
|
|
189
|
+
default: false,
|
|
190
|
+
},
|
|
191
|
+
textAlign: {
|
|
192
|
+
required: false,
|
|
193
|
+
default: "left",
|
|
194
|
+
},
|
|
165
195
|
},
|
|
166
196
|
methods: {
|
|
167
|
-
onChangeHandler(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
value: $event,
|
|
171
|
-
numberPrecision: this.numberPrecision,
|
|
172
|
-
})
|
|
173
|
-
if (isNaN(formattedValue)) {
|
|
174
|
-
this.textInput = ""
|
|
175
|
-
formattedValue = ""
|
|
197
|
+
onChangeHandler(event) {
|
|
198
|
+
if (isNaN(event)) {
|
|
199
|
+
event = ""
|
|
176
200
|
}
|
|
177
|
-
this.$emit("input-change",
|
|
201
|
+
this.$emit("input-change", event)
|
|
178
202
|
},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
203
|
+
onEvaluateCode(val) {
|
|
204
|
+
// function to perform math on the code
|
|
205
|
+
// filter the string in case of any malicious content
|
|
206
|
+
let filtered = val.replace(/[^-()\d/*+.,]/g, "")
|
|
207
|
+
filtered = filtered.split(/([-+*/()])/)
|
|
208
|
+
let formatted = filtered.map((item) => {
|
|
209
|
+
if (
|
|
210
|
+
item === "+" ||
|
|
211
|
+
item === "-" ||
|
|
212
|
+
item === "*" ||
|
|
213
|
+
item === "/" ||
|
|
214
|
+
item === "(" ||
|
|
215
|
+
item === ")" ||
|
|
216
|
+
item === ""
|
|
217
|
+
) {
|
|
218
|
+
return item
|
|
219
|
+
} else {
|
|
220
|
+
let num = stringToNumber({
|
|
221
|
+
value: item,
|
|
222
|
+
numberPrecision: this.numberPrecision,
|
|
223
|
+
})
|
|
224
|
+
return num
|
|
225
|
+
}
|
|
187
226
|
})
|
|
227
|
+
let evaluated = eval(formatted.join(""))
|
|
228
|
+
return evaluated
|
|
229
|
+
},
|
|
230
|
+
onInputBlur(e) {
|
|
231
|
+
this.isFocused = false
|
|
232
|
+
let value = e.target.value
|
|
233
|
+
let evaluatedInput = this.onEvaluateCode(value)
|
|
234
|
+
this.onChangeHandler(evaluatedInput)
|
|
235
|
+
if (value.length) {
|
|
236
|
+
this.textInput = numberToString({
|
|
237
|
+
value: evaluatedInput,
|
|
238
|
+
numberPrecision: this.numberPrecision,
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
focusInput() {
|
|
243
|
+
this.isFocused = true
|
|
244
|
+
},
|
|
245
|
+
formatWithCurrency(value) {
|
|
246
|
+
if (value && !this.isFocused) {
|
|
247
|
+
let input = numberToString({
|
|
248
|
+
value: value,
|
|
249
|
+
numberPrecision: this.numberPrecision,
|
|
250
|
+
})
|
|
251
|
+
let unit = this.showLinearUnitName ? "" : this.unitName
|
|
252
|
+
return input + " " + unit
|
|
253
|
+
} else {
|
|
254
|
+
return numberToString({
|
|
255
|
+
value: value,
|
|
256
|
+
numberPrecision: this.numberPrecision,
|
|
257
|
+
})
|
|
258
|
+
}
|
|
188
259
|
},
|
|
189
260
|
},
|
|
190
261
|
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
262
|
if (this.value) {
|
|
195
263
|
this.textInput = numberToString({
|
|
196
264
|
value: this.value,
|
|
@@ -205,11 +273,6 @@ export default {
|
|
|
205
273
|
this.textInput = ""
|
|
206
274
|
}
|
|
207
275
|
},
|
|
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
276
|
},
|
|
214
277
|
}
|
|
215
278
|
</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,
|
|
@@ -62,6 +62,15 @@ const TableContainer = styled.table`
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
tbody {
|
|
66
|
+
tr {
|
|
67
|
+
&:hover {
|
|
68
|
+
background-color: ${(props) => props.theme.colors.grey5};
|
|
69
|
+
cursor: pointer;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
th {
|
|
66
75
|
padding: 12px 20px;
|
|
67
76
|
background-color: ${(props) => props.theme.colors.blue1};
|
|
@@ -242,7 +251,6 @@ const TableContainer = styled.table`
|
|
|
242
251
|
}
|
|
243
252
|
|
|
244
253
|
input {
|
|
245
|
-
border: none;
|
|
246
254
|
font-size: 13px;
|
|
247
255
|
padding: 5px 10px;
|
|
248
256
|
}
|
|
@@ -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)
|