@eturnity/eturnity_reusable_components 1.0.39 → 1.0.43

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "1.0.39",
3
+ "version": "1.0.43",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
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 class="text">Body 1</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,17 +36,6 @@
23
36
  </tr>
24
37
  </tbody>
25
38
  </main-table>
26
- <toggle
27
- @on-toggle-change="onInputChange($event)"
28
- :isChecked="inputValue"
29
- size="medium"
30
- :disabled="true"
31
- />
32
- <toggle
33
- @on-toggle-change="onInputChange($event)"
34
- :isChecked="inputValue"
35
- size="small"
36
- />
37
39
  </page-container>
38
40
  </ThemeProvider>
39
41
  </template>
@@ -44,7 +46,7 @@ import theme from "./assets/theme"
44
46
  import styled from "vue-styled-components"
45
47
  import MainTable from "@/components/tables/mainTable"
46
48
  import ThreeDots from "@/components/threeDots"
47
- import Toggle from "@/components/inputs/toggle"
49
+ import InputNumber from "@/components/inputs/inputNumber"
48
50
 
49
51
  const PageContainer = styled.div`
50
52
  padding: 40px;
@@ -57,11 +59,11 @@ export default {
57
59
  PageContainer,
58
60
  MainTable,
59
61
  ThreeDots,
60
- Toggle,
62
+ InputNumber,
61
63
  },
62
64
  data() {
63
65
  return {
64
- inputValue: false,
66
+ inputValue: "",
65
67
  checkedOption: "button_1",
66
68
  question: {
67
69
  number_format_precision: 4,
@@ -2,21 +2,25 @@
2
2
  <container>
3
3
  <input-wrapper>
4
4
  <input-container
5
- :hasUnit="!!question.unit_short_name"
5
+ :hasUnit="unitName && !!unitName.length"
6
6
  :placeholder="placeholder"
7
7
  :isError="isError"
8
8
  :inputWidth="inputWidth"
9
- :value="textInput"
10
- :hasLength="!!textInput.length"
11
- @input="onChangeHandler"
12
- @blur="onInputBlur()"
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="question.unit_short_name"
20
+ v-if="unitName && showLinearUnitName"
17
21
  :hasLength="!!textInput.length"
18
22
  :isError="isError"
19
- >{{ question.unit_short_name }}</unit-container
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 InputNumber from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumber"
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
- // :question="question"
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: 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};
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.primary};
78
- width: ${(props) => (props.inputWidth ? props.inputWidth : "auto")};
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.primary
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.primary
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
- numberPrecision: 0, // we set this on created. By default is 0
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($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 = ""
199
+ onChangeHandler(event) {
200
+ if (isNaN(event)) {
201
+ event = ""
176
202
  }
177
- this.$emit("input-change", formattedValue)
203
+ this.$emit("input-change", event)
178
204
  },
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,
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>
@@ -1,14 +1,19 @@
1
1
  <template>
2
- <table-scroll>
3
- <table-wrapper :fullWidth="fullWidth">
4
- <spinner-wrapper v-if="isLoading">
5
- <spinner />
6
- </spinner-wrapper>
7
- <table-container v-else>
8
- <slot />
9
- </table-container>
10
- </table-wrapper>
11
- </table-scroll>
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 {
@@ -204,7 +217,7 @@ const TableContainer = styled.table`
204
217
 
205
218
  .drag-container {
206
219
  display: table-cell;
207
- width: auto;
220
+ width: 20px;
208
221
  vertical-align: middle;
209
222
  }
210
223
 
@@ -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)