@eturnity/eturnity_reusable_components 6.50.1-EPDM-9012.0 → 6.50.1-EPDM-9466.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/.prettierrc +6 -6
  2. package/.storybook/main.js +8 -8
  3. package/.storybook/preview.js +46 -46
  4. package/README.md +29 -29
  5. package/babel.config.js +4 -4
  6. package/package.json +66 -66
  7. package/postcss.config.js +6 -6
  8. package/public/index.html +17 -17
  9. package/src/App.vue +248 -248
  10. package/src/assets/icons/arrow_down.svg +3 -3
  11. package/src/assets/icons/arrow_up_red.svg +3 -3
  12. package/src/assets/icons/black_spinner.svg +35 -35
  13. package/src/assets/icons/delete_icon.svg +11 -11
  14. package/src/assets/icons/delete_icon_gray.svg +11 -11
  15. package/src/assets/icons/drag_icon.svg +8 -8
  16. package/src/assets/icons/external_icon.svg +6 -6
  17. package/src/assets/icons/language_icon.svg +6 -6
  18. package/src/assets/icons/pdf_icon.svg +6 -6
  19. package/src/assets/icons/plus_button.svg +4 -4
  20. package/src/assets/icons/search_icon_black.svg +3 -3
  21. package/src/assets/icons/subposition_icon.svg +3 -3
  22. package/src/assets/icons/subposition_marker.svg +3 -3
  23. package/src/assets/icons/warning_icon.svg +3 -3
  24. package/src/assets/svgIcons/2d_active.svg +7 -7
  25. package/src/assets/svgIcons/2d_inactive.svg +8 -8
  26. package/src/assets/svgIcons/3d_active.svg +7 -7
  27. package/src/assets/svgIcons/3d_inactive.svg +8 -8
  28. package/src/assets/svgIcons/_readme.md +7 -7
  29. package/src/assets/svgIcons/accept.svg +5 -5
  30. package/src/assets/svgIcons/activate_panels_active.svg +22 -22
  31. package/src/assets/svgIcons/activate_panels_inactive.svg +20 -20
  32. package/src/assets/svgIcons/add_icon-1.svg +3 -3
  33. package/src/assets/svgIcons/add_icon.svg +4 -4
  34. package/src/assets/svgIcons/address_book.svg +3 -3
  35. package/src/assets/svgIcons/after_sale_as_a_service.svg +6 -6
  36. package/src/assets/svgIcons/all_good.svg +3 -3
  37. package/src/assets/svgIcons/angle_active.svg +5 -5
  38. package/src/assets/svgIcons/angle_inactive.svg +4 -4
  39. package/src/assets/svgIcons/area_active.svg +11 -11
  40. package/src/assets/svgIcons/area_inactive.svg +26 -26
  41. package/src/assets/svgIcons/areas_tool.svg +14 -14
  42. package/src/assets/svgIcons/arrow_down.svg +3 -3
  43. package/src/assets/svgIcons/arrow_left.svg +4 -4
  44. package/src/assets/svgIcons/arrow_right.svg +4 -4
  45. package/src/assets/svgIcons/arrow_up.svg +3 -3
  46. package/src/assets/svgIcons/attachment.svg +3 -3
  47. package/src/assets/svgIcons/base_layer.svg +3 -3
  48. package/src/assets/svgIcons/battery.svg +3 -3
  49. package/src/assets/svgIcons/bell.svg +3 -3
  50. package/src/assets/svgIcons/bold.svg +3 -3
  51. package/src/assets/svgIcons/bom.svg +3 -3
  52. package/src/assets/svgIcons/bom_generation.svg +10 -10
  53. package/src/assets/svgIcons/bookmaker.svg +3 -3
  54. package/src/assets/svgIcons/bubble.svg +3 -3
  55. package/src/assets/svgIcons/bug.svg +5 -5
  56. package/src/assets/svgIcons/bullet_list.svg +8 -8
  57. package/src/assets/svgIcons/calendar.svg +7 -7
  58. package/src/assets/svgIcons/calendar_icon.svg +7 -7
  59. package/src/assets/svgIcons/call.svg +3 -3
  60. package/src/assets/svgIcons/camera.svg +3 -3
  61. package/src/assets/svgIcons/car.svg +3 -3
  62. package/src/assets/svgIcons/cart.svg +3 -3
  63. package/src/assets/svgIcons/checkbox.svg +3 -3
  64. package/src/assets/svgIcons/clear_formatting.svg +7 -7
  65. package/src/assets/svgIcons/clickable_info.svg +4 -4
  66. package/src/assets/svgIcons/clip.svg +3 -3
  67. package/src/assets/svgIcons/clock.svg +17 -17
  68. package/src/assets/svgIcons/close_for_modals,_tool_tips.svg +4 -4
  69. package/src/assets/svgIcons/co_branding.svg +5 -5
  70. package/src/assets/svgIcons/collapse.svg +4 -4
  71. package/src/assets/svgIcons/collections.svg +3 -3
  72. package/src/assets/svgIcons/component_library.svg +7 -7
  73. package/src/assets/svgIcons/context_menu-1.svg +6 -6
  74. package/src/assets/svgIcons/context_menu-2.svg +5 -5
  75. package/src/assets/svgIcons/context_menu.svg +5 -5
  76. package/src/assets/svgIcons/context_menu_tabs.svg +5 -5
  77. package/src/assets/svgIcons/cross.svg +4 -4
  78. package/src/assets/svgIcons/current_variant.svg +4 -4
  79. package/src/assets/svgIcons/dashboard.svg +3 -3
  80. package/src/assets/svgIcons/deadline.svg +4 -4
  81. package/src/assets/svgIcons/deal_flow.svg +5 -5
  82. package/src/assets/svgIcons/delete.svg +4 -4
  83. package/src/assets/svgIcons/delete_area_active.svg +16 -16
  84. package/src/assets/svgIcons/delete_area_inactive.svg +15 -15
  85. package/src/assets/svgIcons/direction_active-1.svg +12 -12
  86. package/src/assets/svgIcons/direction_active.svg +5 -5
  87. package/src/assets/svgIcons/direction_arrow.svg +4 -4
  88. package/src/assets/svgIcons/direction_inactive.svg +4 -4
  89. package/src/assets/svgIcons/dislike.svg +3 -3
  90. package/src/assets/svgIcons/distance_tool.svg +8 -8
  91. package/src/assets/svgIcons/distances_active.svg +9 -9
  92. package/src/assets/svgIcons/distances_inactive.svg +8 -8
  93. package/src/assets/svgIcons/distort_tool.svg +10 -10
  94. package/src/assets/svgIcons/distort_tool2.svg +16 -16
  95. package/src/assets/svgIcons/document.svg +3 -3
  96. package/src/assets/svgIcons/documents.svg +4 -4
  97. package/src/assets/svgIcons/downarrow.svg +3 -3
  98. package/src/assets/svgIcons/download.svg +4 -4
  99. package/src/assets/svgIcons/draggable_corner.svg +5 -5
  100. package/src/assets/svgIcons/draw_tool.svg +3 -3
  101. package/src/assets/svgIcons/duplicate-1.svg +8 -8
  102. package/src/assets/svgIcons/duplicate-2.svg +5 -5
  103. package/src/assets/svgIcons/duplicate.svg +4 -4
  104. package/src/assets/svgIcons/e-mobility_configurator.svg +6 -6
  105. package/src/assets/svgIcons/e_signature.svg +5 -5
  106. package/src/assets/svgIcons/edit_button.svg +3 -3
  107. package/src/assets/svgIcons/email.svg +3 -3
  108. package/src/assets/svgIcons/ems-1.svg +3 -3
  109. package/src/assets/svgIcons/ems.svg +3 -3
  110. package/src/assets/svgIcons/end_of_the_list.svg +5 -5
  111. package/src/assets/svgIcons/erase.svg +4 -4
  112. package/src/assets/svgIcons/external_icon.svg +5 -5
  113. package/src/assets/svgIcons/fav_icon.svg +4 -4
  114. package/src/assets/svgIcons/finance.svg +3 -3
  115. package/src/assets/svgIcons/financing_for_pv-1.svg +5 -5
  116. package/src/assets/svgIcons/financing_for_pv-2.svg +3 -3
  117. package/src/assets/svgIcons/financing_for_pv.svg +6 -6
  118. package/src/assets/svgIcons/finish-1.svg +4 -4
  119. package/src/assets/svgIcons/finish.svg +3 -3
  120. package/src/assets/svgIcons/flatten.svg +11 -11
  121. package/src/assets/svgIcons/folder.svg +3 -3
  122. package/src/assets/svgIcons/free_technology.svg +5 -5
  123. package/src/assets/svgIcons/heat_calc.svg +7 -7
  124. package/src/assets/svgIcons/house.svg +3 -3
  125. package/src/assets/svgIcons/info.svg +3 -3
  126. package/src/assets/svgIcons/initial_situation.svg +3 -3
  127. package/src/assets/svgIcons/integrations.svg +3 -3
  128. package/src/assets/svgIcons/intro-tour-1.svg +3 -3
  129. package/src/assets/svgIcons/intro-tour.svg +3 -3
  130. package/src/assets/svgIcons/inverter-1.svg +5 -5
  131. package/src/assets/svgIcons/inverter.svg +3 -3
  132. package/src/assets/svgIcons/italic.svg +3 -3
  133. package/src/assets/svgIcons/key.svg +3 -3
  134. package/src/assets/svgIcons/layers_close.svg +4 -4
  135. package/src/assets/svgIcons/layers_open.svg +4 -4
  136. package/src/assets/svgIcons/lead_marketplace.svg +6 -6
  137. package/src/assets/svgIcons/lead_provider.svg +4 -4
  138. package/src/assets/svgIcons/length_in_2d_active.svg +12 -12
  139. package/src/assets/svgIcons/length_in_2d_inctive.svg +13 -13
  140. package/src/assets/svgIcons/light_bulb.svg +3 -3
  141. package/src/assets/svgIcons/like.svg +3 -3
  142. package/src/assets/svgIcons/line_graph.svg +3 -3
  143. package/src/assets/svgIcons/local_subsidies.svg +18 -18
  144. package/src/assets/svgIcons/location.svg +3 -3
  145. package/src/assets/svgIcons/lock.svg +3 -3
  146. package/src/assets/svgIcons/loop.svg +3 -3
  147. package/src/assets/svgIcons/lunch.svg +4 -4
  148. package/src/assets/svgIcons/magic_tool.svg +6 -6
  149. package/src/assets/svgIcons/map_icon.svg +5 -5
  150. package/src/assets/svgIcons/map_settings.svg +3 -3
  151. package/src/assets/svgIcons/margin_tool.svg +4 -4
  152. package/src/assets/svgIcons/meeting.svg +6 -6
  153. package/src/assets/svgIcons/move_copy.svg +4 -4
  154. package/src/assets/svgIcons/new_area_inactive.svg +11 -11
  155. package/src/assets/svgIcons/next.svg +4 -4
  156. package/src/assets/svgIcons/not_equal_to.svg +3 -3
  157. package/src/assets/svgIcons/numbered_list.svg +6 -6
  158. package/src/assets/svgIcons/obstacle_tool.svg +9 -9
  159. package/src/assets/svgIcons/obstacle_tool_origin.svg +3 -3
  160. package/src/assets/svgIcons/offset_tool.svg +8 -8
  161. package/src/assets/svgIcons/outline_tool.svg +11 -11
  162. package/src/assets/svgIcons/pan_tool.svg +12 -12
  163. package/src/assets/svgIcons/panels_tool.svg +8 -8
  164. package/src/assets/svgIcons/pen_tool.svg +4 -4
  165. package/src/assets/svgIcons/picker_tool.svg +4 -4
  166. package/src/assets/svgIcons/picture.svg +3 -3
  167. package/src/assets/svgIcons/pin.svg +5 -5
  168. package/src/assets/svgIcons/presentation.svg +3 -3
  169. package/src/assets/svgIcons/previous.svg +4 -4
  170. package/src/assets/svgIcons/profile-1.svg +4 -4
  171. package/src/assets/svgIcons/profile.svg +4 -4
  172. package/src/assets/svgIcons/profitability.svg +3 -3
  173. package/src/assets/svgIcons/project_analysis.svg +4 -4
  174. package/src/assets/svgIcons/project_settings.svg +4 -4
  175. package/src/assets/svgIcons/pv.svg +3 -3
  176. package/src/assets/svgIcons/quotations.svg +6 -6
  177. package/src/assets/svgIcons/redo.svg +6 -6
  178. package/src/assets/svgIcons/resizer.svg +5 -5
  179. package/src/assets/svgIcons/roof_layer.svg +3 -3
  180. package/src/assets/svgIcons/rotate_tool.svg +3 -3
  181. package/src/assets/svgIcons/rotate_view.svg +5 -5
  182. package/src/assets/svgIcons/ruler_tool.svg +3 -3
  183. package/src/assets/svgIcons/run_simulation.svg +3 -3
  184. package/src/assets/svgIcons/scaling_tool.svg +8 -8
  185. package/src/assets/svgIcons/search.svg +3 -3
  186. package/src/assets/svgIcons/security.svg +3 -3
  187. package/src/assets/svgIcons/settings.svg +3 -3
  188. package/src/assets/svgIcons/show_in_a_new_tab.svg +12 -12
  189. package/src/assets/svgIcons/smartphone.svg +4 -4
  190. package/src/assets/svgIcons/solar_calc.svg +13 -13
  191. package/src/assets/svgIcons/sorting.svg +4 -4
  192. package/src/assets/svgIcons/start_of_the_list.svg +5 -5
  193. package/src/assets/svgIcons/strikethrough.svg +4 -4
  194. package/src/assets/svgIcons/subscriptions.svg +3 -3
  195. package/src/assets/svgIcons/subsidies-1.svg +5 -5
  196. package/src/assets/svgIcons/subsidies-2.svg +3 -3
  197. package/src/assets/svgIcons/subsidies.svg +3 -3
  198. package/src/assets/svgIcons/subtract_icon.svg +3 -3
  199. package/src/assets/svgIcons/suitcase.svg +3 -3
  200. package/src/assets/svgIcons/template_icon_not_clickable.svg +6 -6
  201. package/src/assets/svgIcons/transfer.svg +4 -4
  202. package/src/assets/svgIcons/trim_tool.svg +4 -4
  203. package/src/assets/svgIcons/truck.svg +3 -3
  204. package/src/assets/svgIcons/underlined.svg +3 -3
  205. package/src/assets/svgIcons/undo.svg +6 -6
  206. package/src/assets/svgIcons/uparrow.svg +3 -3
  207. package/src/assets/svgIcons/update.svg +3 -3
  208. package/src/assets/svgIcons/upload_avatar-1.svg +12 -12
  209. package/src/assets/svgIcons/upload_avatar.svg +5 -5
  210. package/src/assets/svgIcons/upload_image.svg +8 -8
  211. package/src/assets/svgIcons/upload_image_tool.svg +7 -7
  212. package/src/assets/svgIcons/variants.svg +6 -6
  213. package/src/assets/svgIcons/vertical_tool.svg +3 -3
  214. package/src/assets/svgIcons/virtual_storage.svg +4 -4
  215. package/src/assets/svgIcons/warning.svg +4 -4
  216. package/src/assets/svgIcons/way.svg +5 -5
  217. package/src/assets/svgIcons/wifi.svg +3 -3
  218. package/src/assets/svgIcons/winter.svg +3 -3
  219. package/src/assets/svgIcons/workflow_template.svg +11 -11
  220. package/src/assets/theme.js +38 -38
  221. package/src/components/addNewButton/AddNewButton.stories.js +24 -24
  222. package/src/components/addNewButton/index.vue +58 -58
  223. package/src/components/buttons/buttonIcon/index.vue +142 -142
  224. package/src/components/buttons/closeButton/CloseButton.stories.js +29 -29
  225. package/src/components/buttons/closeButton/index.vue +61 -61
  226. package/src/components/buttons/mainButton/index.vue +107 -107
  227. package/src/components/deleteIcon/DeleteIcon.stories.js +29 -29
  228. package/src/components/deleteIcon/index.vue +61 -61
  229. package/src/components/dropdown/Dropdown.stories.js +54 -54
  230. package/src/components/dropdown/index.vue +118 -118
  231. package/src/components/errorMessage/index.vue +61 -61
  232. package/src/components/filter/filterSettings.vue +650 -650
  233. package/src/components/filter/index.vue +132 -132
  234. package/src/components/filter/parentDropdown.vue +91 -91
  235. package/src/components/icon/Icons.stories.js +41 -41
  236. package/src/components/icon/iconCollection.vue +68 -68
  237. package/src/components/icon/index.vue +116 -116
  238. package/src/components/iconWrapper/index.vue +152 -152
  239. package/src/components/infoText/index.vue +170 -159
  240. package/src/components/inputs/checkbox/Checkbox.stories.js +57 -57
  241. package/src/components/inputs/checkbox/index.vue +187 -187
  242. package/src/components/inputs/inputNumber/InputNumber.stories.js +150 -148
  243. package/src/components/inputs/inputNumber/index.vue +710 -702
  244. package/src/components/inputs/inputNumberQuestion/index.vue +215 -215
  245. package/src/components/inputs/inputText/InputText.stories.js +75 -74
  246. package/src/components/inputs/inputText/index.vue +355 -349
  247. package/src/components/inputs/radioButton/RadioButton.stories.js +58 -58
  248. package/src/components/inputs/radioButton/index.vue +267 -267
  249. package/src/components/inputs/searchInput/SearchInput.stories.js +40 -40
  250. package/src/components/inputs/searchInput/index.vue +133 -133
  251. package/src/components/inputs/select/index.vue +582 -573
  252. package/src/components/inputs/select/option/index.vue +107 -107
  253. package/src/components/inputs/select/select.stories.js +59 -59
  254. package/src/components/inputs/slider/index.vue +126 -126
  255. package/src/components/inputs/switchField/index.vue +260 -251
  256. package/src/components/inputs/textAreaInput/TextAreaInput.stories.js +135 -127
  257. package/src/components/inputs/textAreaInput/index.vue +206 -200
  258. package/src/components/inputs/toggle/Toggle.stories.js +77 -77
  259. package/src/components/inputs/toggle/index.vue +298 -288
  260. package/src/components/modals/modal/index.vue +159 -159
  261. package/src/components/modals/modal/modal.stories.js +31 -31
  262. package/src/components/pageSubtitle/index.vue +68 -61
  263. package/src/components/pageTitle/index.vue +45 -69
  264. package/src/components/pagination/index.vue +129 -129
  265. package/src/components/progressBar/index.vue +125 -125
  266. package/src/components/projectMarker/index.vue +299 -299
  267. package/src/components/sideMenu/index.vue +266 -266
  268. package/src/components/spinner/index.vue +71 -71
  269. package/src/components/tableDropdown/index.vue +637 -637
  270. package/src/components/tables/mainTable/exampleNested.vue +328 -328
  271. package/src/components/tables/mainTable/index.vue +446 -446
  272. package/src/components/tables/viewTable/index.vue +195 -195
  273. package/src/components/threeDots/index.vue +384 -384
  274. package/src/components/videoThumbnail/index.vue +107 -107
  275. package/src/components/videoThumbnail/videoThumbnail.stories.js +35 -35
  276. package/src/helpers/numberConverter.js +102 -102
  277. package/src/helpers/translateLang.js +119 -119
  278. package/src/main.js +13 -13
@@ -1,702 +1,710 @@
1
- <template>
2
- <container :inputWidth="inputWidth" :alignItems="alignItems">
3
- <label-slot-wrapper
4
- v-if="hasLabelSlot"
5
- :isInteractive="isInteractive"
6
- :alignItems="alignItems"
7
- :noBorder="noBorder"
8
- :isError="isError"
9
- :borderColor="borderColor"
10
- @mousedown="initInteraction"
11
- >
12
- <slot name="label"></slot>
13
- </label-slot-wrapper>
14
-
15
- <label-wrapper v-if="labelText">
16
- <label-text :labelFontColor="labelFontColor" :data-id="labelDataId">
17
- {{ labelText }}
18
- </label-text>
19
-
20
- <info-text
21
- v-if="labelInfoText"
22
- :text="labelInfoText"
23
- />
24
- </label-wrapper>
25
- <input-wrapper>
26
- <input-container
27
- v-bind="$attrs"
28
- ref="inputField1"
29
- :hasUnit="unitName && !!unitName.length"
30
- :placeholder="displayedPlaceholder"
31
- :isError="isError"
32
- :inputHeight="inputHeight"
33
- :minWidth="minWidth"
34
- :isInteractive="isInteractive"
35
- :value="formatWithCurrency(value)"
36
- @blur="onInputBlur($event)"
37
- @focus="focusInput()"
38
- @keyup.enter="$emit('on-enter-click')"
39
- @input="onInput($event)"
40
- :disabled="disabled"
41
- :isDisabled="disabled"
42
- :alignItems="alignItems"
43
- :noBorder="noBorder"
44
- :borderColor="borderColor"
45
- :textAlign="textAlign"
46
- :fontSize="fontSize"
47
- :fontColor="fontColor"
48
- :backgroundColor="backgroundColor"
49
- v-on="$listeners"
50
- :hasSlot="hasSlot"
51
- :hasLabelSlot="hasLabelSlot"
52
- :slotSize="slotSize"
53
- :showLinearUnitName="showLinearUnitName"
54
- :data-id="inputDataId"
55
- />
56
- <slot-container v-if="hasSlot" :slotSize="slotSize" :isError="isError">
57
- <slot></slot>
58
- </slot-container>
59
-
60
- <unit-container
61
- v-if="unitName && showLinearUnitName && !hasSlot"
62
- :hasLength="!!textInput.length"
63
- :isError="isError"
64
- >{{ unitName }}</unit-container
65
- >
66
- <icon-wrapper v-if="isError && !showLinearUnitName" size="16px">
67
- <icon name="warning" size="16px" cursor="default" />
68
- </icon-wrapper>
69
- </input-wrapper>
70
- <error-message v-if="isError">{{ errorMessage }}</error-message>
71
- </container>
72
- </template>
73
-
74
- <script>
75
- // import InputNumber from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumber"
76
- //This component should be used for questions with input fields only
77
- //How to use:
78
- // <input-number
79
- // placeholder="Enter distance"
80
- // :isError="false" //default is false
81
- // inputWidth="150px" //by default, this is 100%
82
- // minWidth="100px"
83
- // :numberPrecision="3"
84
- // minDecimals="2"
85
- // unitName="pc"
86
- // :value="inputValue" //required -- String
87
- // @input-change="onInputChange($event)" //required
88
- // @on-enter-click="onInputSubmit()"
89
- // :errorMessage="Enter a number between 1 and 10"
90
- // :disabled="false"
91
- // :noBorder="true"
92
- // textAlign="left" // "left, right, center"
93
- // :showLinearUnitName="true"
94
- // fontSize="13px"
95
- // labelText="Number of Modules"
96
- // labelInfoText="Here is some information for you..."
97
- // :minNumber="0"
98
- // fontColor="blue"
99
- // />
100
- import styled from 'vue-styled-components'
101
- import {
102
- stringToNumber,
103
- numberToString
104
- } from '../../../helpers/numberConverter'
105
- import InfoText from '../../infoText'
106
- import ErrorMessage from '../../errorMessage'
107
- import warningIcon from '../../../assets/icons/error_icon.png'
108
- import Icon from '../../icon'
109
-
110
- const inputProps = {
111
- isError: Boolean,
112
- hasUnit: Boolean,
113
- inputWidth: String,
114
- minWidth: String,
115
- isDisabled: Boolean,
116
- noBorder: Boolean,
117
- textAlign: String,
118
- fontSize: String,
119
- fontColor: String,
120
- backgroundColor: String,
121
- hasSlot: Boolean,
122
- hasLabelSlot: Boolean,
123
- slotSize: String,
124
- inputHeight: String,
125
- isInteractive: Boolean,
126
- alignItems: String,
127
- labelFontColor: String,
128
- borderColor: String,
129
- showLinearUnitName: Boolean
130
- }
131
-
132
- const Container = styled('div', inputProps)`
133
- width: ${(props) => (props.inputWidth ? props.inputWidth : '100%')};
134
- position: relative;
135
- display: grid;
136
- grid-template-columns: ${(props) =>
137
- props.alignItems === 'vertical' ? '1fr' : 'auto 1fr'};
138
- `
139
-
140
- const InputContainer = styled('input', inputProps)`
141
- border: ${(props) =>
142
- props.isError
143
- ? '1px solid ' + props.theme.colors.red
144
- : props.noBorder
145
- ? 'none'
146
- : props.borderColor
147
- ? props.theme.colors[props.borderColor]
148
- ? '1px solid ' + props.theme.colors[props.borderColor]
149
- : '1px solid ' + props.borderColor
150
- : '1px solid ' + props.theme.colors.grey4};
151
- height: ${(props) => props.inputHeight};
152
- max-height: ${(props) => props.inputHeight};
153
- padding: 0 10px;
154
- padding-right: ${({ slotSize, isError, showLinearUnitName }) =>
155
- slotSize
156
- ? isError && !showLinearUnitName
157
- ? 'calc(' + slotSize + ' + 24px)'
158
- : 'calc(' + slotSize + ' + 10px)'
159
- : isError && !showLinearUnitName
160
- ? '24px'
161
- : '5px'};
162
- border-radius: ${(props) =>
163
- props.isInteractive && props.alignItems != 'vertical'
164
- ? '0 4px 4px 0'
165
- : '4px'};
166
- text-align: ${(props) => props.textAlign};
167
- cursor: ${(props) => (props.isDisabled ? 'not-allowed' : 'auto')};
168
- font-size: ${(props) => (props.fontSize ? props.fontSize : '13px')};
169
- color: ${(props) =>
170
- props.isError
171
- ? props.theme.colors.grey6
172
- : props.isDisabled
173
- ? props.theme.colors.grey2
174
- : props.fontColor
175
- ? props.fontColor + ' !important'
176
- : props.theme.colors.black};
177
- background-color: ${(props) =>
178
- props.backgroundColor
179
- ? props.backgroundColor + ' !important'
180
- : props.theme.colors.white};
181
- width: ${(props) =>
182
- props.inputWidth && !props.hasLabelSlot ? props.inputWidth : '100%'};
183
- min-width: ${(props) => (props.minWidth ? props.minWidth : 'unset')};
184
- background-color: ${(props) =>
185
- props.isDisabled ? props.theme.colors.grey5 : '#fff'};
186
- box-sizing: border-box;
187
-
188
- &::placeholder {
189
- color: ${(props) => props.theme.colors.grey2};
190
- }
191
-
192
- &:focus {
193
- outline: none;
194
- }
195
- `
196
-
197
- const InputWrapper = styled.span`
198
- position: relative;
199
- `
200
-
201
- const UnitContainer = styled('span', inputProps)`
202
- border-left: 1px solid
203
- ${(props) =>
204
- props.isError
205
- ? props.theme.colors.red
206
- : props.hasLength
207
- ? props.theme.colors.black
208
- : props.theme.colors.mediumGray};
209
- position: absolute;
210
- right: 10px;
211
- top: 10px;
212
- padding-left: 10px;
213
- text-align: right;
214
- color: ${(props) =>
215
- props.isError
216
- ? props.theme.colors.red
217
- : props.hasLength
218
- ? props.theme.colors.black
219
- : props.theme.colors.mediumGray};
220
- `
221
-
222
- const SlotContainer = styled('span', inputProps)`
223
- text-align: right;
224
- border-left: 1px solid
225
- ${(props) =>
226
- props.isError
227
- ? props.theme.colors.red
228
- : props.hasLength
229
- ? props.theme.colors.black
230
- : props.theme.colors.mediumGray};
231
- position: absolute;
232
- width: ${(props) =>
233
- props.slotSize ? 'calc(' + props.slotSize + ' - 10px)' : 'fit-content'};
234
- right: 10px;
235
- top: 10px;
236
- padding-left: 10px;
237
- color: ${(props) =>
238
- props.isError
239
- ? props.theme.colors.red
240
- : props.hasLength
241
- ? props.theme.colors.black
242
- : props.theme.colors.mediumGray};
243
- `
244
-
245
- const LabelWrapper = styled('div', inputProps)`
246
- display: flex;
247
- align-items: center;
248
- gap: 10px;
249
- margin-bottom: 8px;
250
- cursor: ${(props) => (props.isInteractive ? 'ew-resize' : 'auto')};
251
- `
252
- const LabelSlotWrapper = styled('div', inputProps)`
253
- display: flex;
254
- gap: 10px;
255
- align-items: center;
256
- cursor: ${(props) => (props.isInteractive ? 'ew-resize' : 'auto')};
257
- border: ${(props) =>
258
- props.alignItems == 'vertical'
259
- ? 'none'
260
- : props.isError
261
- ? '1px solid ' + props.theme.colors.red
262
- : props.noBorder
263
- ? 'none'
264
- : props.borderColor
265
- ? props.theme.colors[props.borderColor]
266
- ? '1px solid ' + props.theme.colors[props.borderColor]
267
- : '1px solid ' + props.borderColor
268
- : '1px solid ' + props.theme.colors.grey4};
269
- border-radius: 4px 0 0 4px;
270
- border-right: none;
271
- `
272
-
273
- const LabelText = styled('div', inputProps)`
274
- font-size: 13px;
275
- color: ${(props) =>
276
- props.theme.colors[props.labelFontColor]
277
- ? props.theme.colors[props.labelFontColor]
278
- : props.labelFontColor};
279
- font-weight: 700;
280
- `
281
-
282
- const IconAttrs = { size: String }
283
- const IconWrapper = styled('div', IconAttrs)`
284
- position: absolute;
285
- top: 0;
286
- bottom: 0;
287
- margin: auto;
288
- right: 5px;
289
- height: ${(props) => (props.size ? props.size : 'auto')};
290
- `
291
-
292
- export default {
293
- name: 'input-number',
294
- components: {
295
- Container,
296
- InputContainer,
297
- InputWrapper,
298
- UnitContainer,
299
- ErrorMessage,
300
- LabelWrapper,
301
- LabelSlotWrapper,
302
- LabelText,
303
- InfoText,
304
- Icon,
305
- SlotContainer,
306
- IconWrapper
307
- },
308
- inheritAttrs: false,
309
- data() {
310
- return {
311
- textInput: '',
312
- isFocused: false,
313
- warningIcon: warningIcon,
314
- isBlurred: false
315
- }
316
- },
317
- props: {
318
- placeholder: {
319
- required: false,
320
- default: ''
321
- },
322
- isError: {
323
- required: false,
324
- default: false
325
- },
326
- inputWidth: {
327
- required: false,
328
- default: null
329
- },
330
- minWidth: {
331
- required: false,
332
- default: null
333
- },
334
- inputHeight: {
335
- required: false,
336
- default: '40px'
337
- },
338
- value: {
339
- required: true,
340
- default: null
341
- },
342
- clearInput: {
343
- required: false,
344
- default: false
345
- },
346
- alignItems: {
347
- required: false,
348
- default: 'vertical'
349
- },
350
- errorMessage: {
351
- required: false,
352
- default: 'Please insert a correct number'
353
- },
354
- numberPrecision: {
355
- required: false,
356
- default: 0
357
- },
358
- minDecimals: {
359
- required: false,
360
- default: 0
361
- },
362
- unitName: {
363
- required: false,
364
- default: ''
365
- },
366
- showLinearUnitName: {
367
- required: false,
368
- default: false
369
- },
370
- disabled: {
371
- required: false,
372
- default: false
373
- },
374
- noBorder: {
375
- required: false,
376
- default: false
377
- },
378
- borderColor: {
379
- required: false
380
- },
381
- textAlign: {
382
- required: false,
383
- default: 'left'
384
- },
385
- fontSize: {
386
- required: false,
387
- default: '13px'
388
- },
389
- isInteractive: {
390
- required: false,
391
- default: false
392
- },
393
- interactionStep: {
394
- required: false,
395
- default: 1
396
- },
397
- labelText: {
398
- required: false,
399
- default: null
400
- },
401
- labelInfoText: {
402
- required: false,
403
- default: null
404
- },
405
- defaultNumber: {
406
- required: false,
407
- default: null
408
- },
409
- minNumber: {
410
- required: false,
411
- default: null
412
- },
413
- fontColor: {
414
- required: false,
415
- default: null
416
- },
417
- backgroundColor: {
418
- required: false,
419
- default: null
420
- },
421
- numberToStringEnabled: {
422
- required: false,
423
- default: true
424
- },
425
- allowNegative: {
426
- required: false,
427
- default: true
428
- },
429
- slotSize: {
430
- required: false
431
- },
432
- labelFontColor: {
433
- required: false,
434
- default: 'eturnityGrey'
435
- },
436
- focus: {
437
- required: false,
438
- default: false
439
- },
440
- labelDataId: {
441
- required: false,
442
- default: ''
443
- },
444
- inputDataId: {
445
- required: false,
446
- default: ''
447
- }
448
- },
449
- computed: {
450
- displayedPlaceholder() {
451
- if (this.placeholder) return this.placeholder
452
- if (this.defaultNumber)
453
- return `${this.defaultNumber} ${this.unitName ? this.unitName : ''}`
454
- return `${this.minNumber || 0} ${this.unitName ? this.unitName : ''}`
455
- },
456
- hasSlot() {
457
- return !!this.$slots.default
458
- },
459
- hasLabelSlot() {
460
- return !!this.$slots.label
461
- }
462
- },
463
- methods: {
464
- onChangeHandler(event) {
465
- if (isNaN(event) || event === '') {
466
- event = this.defaultNumber
467
- ? this.defaultNumber
468
- : this.minNumber || this.minNumber === 0
469
- ? this.minNumber
470
- : event
471
- }
472
- if (!this.allowNegative) {
473
- event = Math.abs(event)
474
- }
475
- event = parseFloat(event)
476
- // Need to return an integer rather than a string
477
- this.$emit('input-change', event)
478
- },
479
- onEvaluateCode(val) {
480
- // function to perform math on the code
481
- // filter the string in case of any malicious content
482
- let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
483
- filtered = filtered.split(/([-+*/()])/)
484
- let formatted = filtered.map((item) => {
485
- if (
486
- item === '+' ||
487
- item === '-' ||
488
- item === '*' ||
489
- item === '/' ||
490
- item === '(' ||
491
- item === ')' ||
492
- item === ''
493
- ) {
494
- return item
495
- } else {
496
- let num = stringToNumber({
497
- value: item,
498
- numberPrecision: false,
499
- minDecimals: this.minDecimals
500
- })
501
- return num
502
- }
503
- })
504
- let evaluated
505
- formatted = this.removeStringItemsAfterLastNumber(formatted)
506
- evaluated = eval(formatted.join(' '))
507
- if (typeof evaluated === 'string') {
508
- evaluated = stringToNumber({
509
- value: evaluated,
510
- numberPrecision: this.numberPrecision,
511
- minDecimals: this.minDecimals
512
- })
513
- } else if (typeof evaluated === 'number') {
514
- evaluated = evaluated.toFixed(this.numberPrecision)
515
- }
516
- return evaluated
517
- },
518
- removeStringItemsAfterLastNumber(array) {
519
- // fixed in EPDM-6487, in order to prevent 'Unexpected end of input'
520
- let lastNumberIndex = -1
521
- // Find the index of the last number in the array
522
- for (let i = array.length - 1; i >= 0; i--) {
523
- if (typeof array[i] === 'number') {
524
- lastNumberIndex = i
525
- break
526
- }
527
- }
528
- // if there are no numbers, return an empty array
529
- if (lastNumberIndex === -1) {
530
- return []
531
- }
532
- // Remove non-numeric items after the last number
533
- if (lastNumberIndex !== -1) {
534
- const newArray = array.slice(0, lastNumberIndex + 1)
535
- return newArray
536
- }
537
- return array
538
- },
539
- onInput(value) {
540
- if (this.isBlurred) {
541
- this.isBlurred = false
542
- return
543
- }
544
- if (value === '') {
545
- this.$emit('on-input', '')
546
- }
547
- let evaluatedVal
548
- try {
549
- evaluatedVal = this.onEvaluateCode(value)
550
- } finally {
551
- if (evaluatedVal) {
552
- this.$emit('on-input', evaluatedVal)
553
- }
554
- }
555
- },
556
- onInputBlur(e) {
557
- this.isFocused = false
558
- // setting isBlurred so we don't trigger onInput as well
559
- this.isBlurred = true
560
- let value = e.target.value
561
- let evaluatedInput = this.onEvaluateCode(value)
562
- this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
563
- if ((evaluatedInput && value.length) || this.minNumber !== null) {
564
- this.textInput = numberToString({
565
- value:
566
- evaluatedInput && value.length
567
- ? evaluatedInput
568
- : this.defaultNumber
569
- ? this.defaultNumber
570
- : this.minNumber,
571
- numberPrecision: this.numberPrecision,
572
- minDecimals: this.minDecimals
573
- })
574
- }
575
- let adjustedMinValue =
576
- evaluatedInput && evaluatedInput.length
577
- ? evaluatedInput
578
- : this.defaultNumber
579
- ? this.defaultNumber
580
- : this.minNumber || this.minNumber === 0
581
- ? this.minNumber
582
- : ''
583
- this.$emit('input-blur', adjustedMinValue)
584
- },
585
- focusInput() {
586
- if (this.disabled) {
587
- return
588
- }
589
- this.isFocused = true
590
- this.$nextTick(() => {
591
- this.$refs.inputField1.$el.select()
592
- })
593
- this.$emit('input-focus')
594
- },
595
- blurInput() {
596
- if (this.disabled) {
597
- return
598
- }
599
- this.isFocused = false
600
- this.$nextTick(() => {
601
- this.$refs.inputField1.$el.blur()
602
- })
603
- },
604
- formatWithCurrency(value) {
605
- let adjustedMinValue =
606
- value || value === 0
607
- ? value
608
- : this.defaultNumber
609
- ? this.defaultNumber
610
- : this.minNumber || this.minNumber === 0
611
- ? this.minNumber
612
- : ''
613
- if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
614
- let input = this.numberToStringEnabled
615
- ? numberToString({
616
- value: adjustedMinValue,
617
- numberPrecision: this.numberPrecision,
618
- minDecimals: this.minDecimals
619
- })
620
- : adjustedMinValue
621
- let unit = this.showLinearUnitName ? '' : this.unitName
622
- //return input + ' ' + unit
623
- return input + ' ' + unit
624
- } else if (!adjustedMinValue && adjustedMinValue !== 0) {
625
- return ''
626
- } else {
627
- return this.numberToStringEnabled
628
- ? numberToString({
629
- value: adjustedMinValue,
630
- numberPrecision: this.numberPrecision,
631
- minDecimals: this.minDecimals
632
- })
633
- : adjustedMinValue
634
- }
635
- },
636
- initInteraction(e) {
637
- window.addEventListener('mousemove', this.interact, false)
638
- window.addEventListener('mouseup', this.stopInteract, false)
639
- e.preventDefault()
640
- this.focusInput()
641
- },
642
- interact(e) {
643
- e.preventDefault()
644
- let value = parseFloat(this.value || 0)
645
- value += parseFloat(this.interactionStep) * parseInt(e.movementX)
646
- this.$emit('on-input', value)
647
-
648
- this.textInput = numberToString({
649
- value: value && value.length ? value : this.minNumber,
650
- numberPrecision: this.numberPrecision,
651
- minDecimals: this.minDecimals
652
- })
653
- //this.value=value
654
- },
655
- stopInteract(e) {
656
- e.preventDefault()
657
- window.removeEventListener('mousemove', this.interact, false)
658
- window.removeEventListener('mouseup', this.stopInteract, false)
659
- this.blurInput()
660
- }
661
- },
662
- created() {
663
- if (this.value) {
664
- this.textInput = numberToString({
665
- value: this.value,
666
- numberPrecision: this.numberPrecision,
667
- minDecimals: this.minDecimals
668
- })
669
- } else if (this.defaultNumber !== null) {
670
- this.textInput = numberToString({
671
- value: this.defaultNumber,
672
- numberPrecision: this.numberPrecision,
673
- minDecimals: this.minDecimals
674
- })
675
- } else if (this.minNumber !== null) {
676
- this.textInput = numberToString({
677
- value: this.minNumber,
678
- numberPrecision: this.numberPrecision,
679
- minDecimals: this.minDecimals
680
- })
681
- }
682
- },
683
- mounted() {
684
- if (this.focus) {
685
- this.focusInput()
686
- }
687
- },
688
- watch: {
689
- focus(value) {
690
- if (value) {
691
- this.focusInput()
692
- }
693
- },
694
- clearInput: function (value) {
695
- if (value) {
696
- // If the value is typed, then we should clear the textInput on Continue
697
- this.textInput = ''
698
- }
699
- }
700
- }
701
- }
702
- </script>
1
+ <template>
2
+ <container :inputWidth="inputWidth" :alignItems="alignItems">
3
+ <label-slot-wrapper
4
+ v-if="hasLabelSlot"
5
+ :isInteractive="isInteractive"
6
+ :alignItems="alignItems"
7
+ :noBorder="noBorder"
8
+ :isError="isError"
9
+ :borderColor="borderColor"
10
+ @mousedown="initInteraction"
11
+ >
12
+ <slot name="label"></slot>
13
+ </label-slot-wrapper>
14
+
15
+ <label-wrapper v-if="labelText">
16
+ <label-text :labelFontColor="labelFontColor" :data-id="labelDataId">
17
+ {{ labelText }}
18
+ </label-text>
19
+
20
+ <info-text
21
+ v-if="labelInfoText"
22
+ :text="labelInfoText"
23
+ borderColor="#ccc"
24
+ size="14px"
25
+ :alignArrow="labelInfoAlign"
26
+ />
27
+ </label-wrapper>
28
+ <input-wrapper>
29
+ <input-container
30
+ v-bind="$attrs"
31
+ ref="inputField1"
32
+ :hasUnit="unitName && !!unitName.length"
33
+ :placeholder="displayedPlaceholder"
34
+ :isError="isError"
35
+ :inputHeight="inputHeight"
36
+ :minWidth="minWidth"
37
+ :isInteractive="isInteractive"
38
+ :value="formatWithCurrency(value)"
39
+ @blur="onInputBlur($event)"
40
+ @focus="focusInput()"
41
+ @keyup.enter="$emit('on-enter-click')"
42
+ @input="onInput($event)"
43
+ :disabled="disabled"
44
+ :isDisabled="disabled"
45
+ :alignItems="alignItems"
46
+ :noBorder="noBorder"
47
+ :borderColor="borderColor"
48
+ :textAlign="textAlign"
49
+ :fontSize="fontSize"
50
+ :fontColor="fontColor"
51
+ :backgroundColor="backgroundColor"
52
+ v-on="$listeners"
53
+ :hasSlot="hasSlot"
54
+ :hasLabelSlot="hasLabelSlot"
55
+ :slotSize="slotSize"
56
+ :showLinearUnitName="showLinearUnitName"
57
+ :data-id="inputDataId"
58
+ />
59
+ <slot-container v-if="hasSlot" :slotSize="slotSize" :isError="isError">
60
+ <slot></slot>
61
+ </slot-container>
62
+
63
+ <unit-container
64
+ v-if="unitName && showLinearUnitName && !hasSlot"
65
+ :hasLength="!!textInput.length"
66
+ :isError="isError"
67
+ >{{ unitName }}</unit-container
68
+ >
69
+ <icon-wrapper v-if="isError && !showLinearUnitName" size="16px">
70
+ <icon name="warning" size="16px" cursor="default" />
71
+ </icon-wrapper>
72
+ </input-wrapper>
73
+ <error-message v-if="isError">{{ errorMessage }}</error-message>
74
+ </container>
75
+ </template>
76
+
77
+ <script>
78
+ // import InputNumber from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumber"
79
+ //This component should be used for questions with input fields only
80
+ //How to use:
81
+ // <input-number
82
+ // placeholder="Enter distance"
83
+ // :isError="false" //default is false
84
+ // inputWidth="150px" //by default, this is 100%
85
+ // minWidth="100px"
86
+ // :numberPrecision="3"
87
+ // minDecimals="2"
88
+ // unitName="pc"
89
+ // :value="inputValue" //required -- String
90
+ // @input-change="onInputChange($event)" //required
91
+ // @on-enter-click="onInputSubmit()"
92
+ // :errorMessage="Enter a number between 1 and 10"
93
+ // :disabled="false"
94
+ // :noBorder="true"
95
+ // textAlign="left" // "left, right, center"
96
+ // :showLinearUnitName="true"
97
+ // fontSize="13px"
98
+ // labelText="Number of Modules"
99
+ // labelInfoText="Here is some information for you..."
100
+ // labelInfoAlign="left"
101
+ // :minNumber="0"
102
+ // fontColor="blue"
103
+ // />
104
+ import styled from 'vue-styled-components'
105
+ import {
106
+ stringToNumber,
107
+ numberToString
108
+ } from '../../../helpers/numberConverter'
109
+ import InfoText from '../../infoText'
110
+ import ErrorMessage from '../../errorMessage'
111
+ import warningIcon from '../../../assets/icons/error_icon.png'
112
+ import Icon from '../../icon'
113
+
114
+ const inputProps = {
115
+ isError: Boolean,
116
+ hasUnit: Boolean,
117
+ inputWidth: String,
118
+ minWidth: String,
119
+ isDisabled: Boolean,
120
+ noBorder: Boolean,
121
+ textAlign: String,
122
+ fontSize: String,
123
+ fontColor: String,
124
+ backgroundColor: String,
125
+ hasSlot: Boolean,
126
+ hasLabelSlot: Boolean,
127
+ slotSize: String,
128
+ inputHeight: String,
129
+ isInteractive: Boolean,
130
+ alignItems: String,
131
+ labelFontColor: String,
132
+ borderColor: String,
133
+ showLinearUnitName: Boolean
134
+ }
135
+
136
+ const Container = styled('div', inputProps)`
137
+ width: ${(props) => (props.inputWidth ? props.inputWidth : '100%')};
138
+ position: relative;
139
+ display: grid;
140
+ grid-template-columns: ${(props) =>
141
+ props.alignItems === 'vertical' ? '1fr' : 'auto 1fr'};
142
+ `
143
+
144
+ const InputContainer = styled('input', inputProps)`
145
+ border: ${(props) =>
146
+ props.isError
147
+ ? '1px solid ' + props.theme.colors.red
148
+ : props.noBorder
149
+ ? 'none'
150
+ : props.borderColor
151
+ ? props.theme.colors[props.borderColor]
152
+ ? '1px solid ' + props.theme.colors[props.borderColor]
153
+ : '1px solid ' + props.borderColor
154
+ : '1px solid ' + props.theme.colors.grey4};
155
+ height: ${(props) => props.inputHeight};
156
+ max-height: ${(props) => props.inputHeight};
157
+ padding: 0 10px;
158
+ padding-right: ${({ slotSize, isError, showLinearUnitName }) =>
159
+ slotSize
160
+ ? isError && !showLinearUnitName
161
+ ? 'calc(' + slotSize + ' + 24px)'
162
+ : 'calc(' + slotSize + ' + 10px)'
163
+ : isError && !showLinearUnitName
164
+ ? '24px'
165
+ : '5px'};
166
+ border-radius: ${(props) =>
167
+ props.isInteractive && props.alignItems != 'vertical'
168
+ ? '0 4px 4px 0'
169
+ : '4px'};
170
+ text-align: ${(props) => props.textAlign};
171
+ cursor: ${(props) => (props.isDisabled ? 'not-allowed' : 'auto')};
172
+ font-size: ${(props) => (props.fontSize ? props.fontSize : '13px')};
173
+ color: ${(props) =>
174
+ props.isError
175
+ ? props.theme.colors.grey6
176
+ : props.isDisabled
177
+ ? props.theme.colors.grey2
178
+ : props.fontColor
179
+ ? props.fontColor + ' !important'
180
+ : props.theme.colors.black};
181
+ background-color: ${(props) =>
182
+ props.backgroundColor
183
+ ? props.backgroundColor + ' !important'
184
+ : props.theme.colors.white};
185
+ width: ${(props) =>
186
+ props.inputWidth && !props.hasLabelSlot ? props.inputWidth : '100%'};
187
+ min-width: ${(props) => (props.minWidth ? props.minWidth : 'unset')};
188
+ background-color: ${(props) =>
189
+ props.isDisabled ? props.theme.colors.grey5 : '#fff'};
190
+ box-sizing: border-box;
191
+
192
+ &::placeholder {
193
+ color: ${(props) => props.theme.colors.grey2};
194
+ }
195
+
196
+ &:focus {
197
+ outline: none;
198
+ }
199
+ `
200
+
201
+ const InputWrapper = styled.span`
202
+ position: relative;
203
+ `
204
+
205
+ const UnitContainer = styled('span', inputProps)`
206
+ border-left: 1px solid
207
+ ${(props) =>
208
+ props.isError
209
+ ? props.theme.colors.red
210
+ : props.hasLength
211
+ ? props.theme.colors.black
212
+ : props.theme.colors.mediumGray};
213
+ position: absolute;
214
+ right: 10px;
215
+ top: 10px;
216
+ padding-left: 10px;
217
+ text-align: right;
218
+ color: ${(props) =>
219
+ props.isError
220
+ ? props.theme.colors.red
221
+ : props.hasLength
222
+ ? props.theme.colors.black
223
+ : props.theme.colors.mediumGray};
224
+ `
225
+
226
+ const SlotContainer = styled('span', inputProps)`
227
+ text-align: right;
228
+ border-left: 1px solid
229
+ ${(props) =>
230
+ props.isError
231
+ ? props.theme.colors.red
232
+ : props.hasLength
233
+ ? props.theme.colors.black
234
+ : props.theme.colors.mediumGray};
235
+ position: absolute;
236
+ width: ${(props) =>
237
+ props.slotSize ? 'calc(' + props.slotSize + ' - 10px)' : 'fit-content'};
238
+ right: 10px;
239
+ top: 10px;
240
+ padding-left: 10px;
241
+ color: ${(props) =>
242
+ props.isError
243
+ ? props.theme.colors.red
244
+ : props.hasLength
245
+ ? props.theme.colors.black
246
+ : props.theme.colors.mediumGray};
247
+ `
248
+
249
+ const LabelWrapper = styled('div', inputProps)`
250
+ display: flex;
251
+ align-items: center;
252
+ gap: 10px;
253
+ margin-bottom: 8px;
254
+ cursor: ${(props) => (props.isInteractive ? 'ew-resize' : 'auto')};
255
+ `
256
+ const LabelSlotWrapper = styled('div', inputProps)`
257
+ display: flex;
258
+ gap: 10px;
259
+ align-items: center;
260
+ cursor: ${(props) => (props.isInteractive ? 'ew-resize' : 'auto')};
261
+ border: ${(props) =>
262
+ props.alignItems == 'vertical'
263
+ ? 'none'
264
+ : props.isError
265
+ ? '1px solid ' + props.theme.colors.red
266
+ : props.noBorder
267
+ ? 'none'
268
+ : props.borderColor
269
+ ? props.theme.colors[props.borderColor]
270
+ ? '1px solid ' + props.theme.colors[props.borderColor]
271
+ : '1px solid ' + props.borderColor
272
+ : '1px solid ' + props.theme.colors.grey4};
273
+ border-radius: 4px 0 0 4px;
274
+ border-right: none;
275
+ `
276
+
277
+ const LabelText = styled('div', inputProps)`
278
+ font-size: 13px;
279
+ color: ${(props) =>
280
+ props.theme.colors[props.labelFontColor]
281
+ ? props.theme.colors[props.labelFontColor]
282
+ : props.labelFontColor};
283
+ font-weight: 700;
284
+ `
285
+
286
+ const IconAttrs = { size: String }
287
+ const IconWrapper = styled('div', IconAttrs)`
288
+ position: absolute;
289
+ top: 0;
290
+ bottom: 0;
291
+ margin: auto;
292
+ right: 5px;
293
+ height: ${(props) => (props.size ? props.size : 'auto')};
294
+ `
295
+
296
+ export default {
297
+ name: 'input-number',
298
+ components: {
299
+ Container,
300
+ InputContainer,
301
+ InputWrapper,
302
+ UnitContainer,
303
+ ErrorMessage,
304
+ LabelWrapper,
305
+ LabelSlotWrapper,
306
+ LabelText,
307
+ InfoText,
308
+ Icon,
309
+ SlotContainer,
310
+ IconWrapper
311
+ },
312
+ inheritAttrs: false,
313
+ data() {
314
+ return {
315
+ textInput: '',
316
+ isFocused: false,
317
+ warningIcon: warningIcon,
318
+ isBlurred: false
319
+ }
320
+ },
321
+ props: {
322
+ placeholder: {
323
+ required: false,
324
+ default: ''
325
+ },
326
+ isError: {
327
+ required: false,
328
+ default: false
329
+ },
330
+ inputWidth: {
331
+ required: false,
332
+ default: null
333
+ },
334
+ minWidth: {
335
+ required: false,
336
+ default: null
337
+ },
338
+ inputHeight: {
339
+ required: false,
340
+ default: '40px'
341
+ },
342
+ value: {
343
+ required: true,
344
+ default: null
345
+ },
346
+ clearInput: {
347
+ required: false,
348
+ default: false
349
+ },
350
+ alignItems: {
351
+ required: false,
352
+ default: 'vertical'
353
+ },
354
+ errorMessage: {
355
+ required: false,
356
+ default: 'Please insert a correct number'
357
+ },
358
+ numberPrecision: {
359
+ required: false,
360
+ default: 0
361
+ },
362
+ minDecimals: {
363
+ required: false,
364
+ default: 0
365
+ },
366
+ unitName: {
367
+ required: false,
368
+ default: ''
369
+ },
370
+ showLinearUnitName: {
371
+ required: false,
372
+ default: false
373
+ },
374
+ disabled: {
375
+ required: false,
376
+ default: false
377
+ },
378
+ noBorder: {
379
+ required: false,
380
+ default: false
381
+ },
382
+ borderColor: {
383
+ required: false
384
+ },
385
+ textAlign: {
386
+ required: false,
387
+ default: 'left'
388
+ },
389
+ fontSize: {
390
+ required: false,
391
+ default: '13px'
392
+ },
393
+ isInteractive: {
394
+ required: false,
395
+ default: false
396
+ },
397
+ interactionStep: {
398
+ required: false,
399
+ default: 1
400
+ },
401
+ labelText: {
402
+ required: false,
403
+ default: null
404
+ },
405
+ labelInfoText: {
406
+ required: false,
407
+ default: null
408
+ },
409
+ labelInfoAlign: {
410
+ required: false,
411
+ default: 'left'
412
+ },
413
+ defaultNumber: {
414
+ required: false,
415
+ default: null
416
+ },
417
+ minNumber: {
418
+ required: false,
419
+ default: null
420
+ },
421
+ fontColor: {
422
+ required: false,
423
+ default: null
424
+ },
425
+ backgroundColor: {
426
+ required: false,
427
+ default: null
428
+ },
429
+ numberToStringEnabled: {
430
+ required: false,
431
+ default: true
432
+ },
433
+ allowNegative: {
434
+ required: false,
435
+ default: true
436
+ },
437
+ slotSize: {
438
+ required: false
439
+ },
440
+ labelFontColor: {
441
+ required: false,
442
+ default: 'eturnityGrey'
443
+ },
444
+ focus: {
445
+ required: false,
446
+ default: false
447
+ },
448
+ labelDataId: {
449
+ required: false,
450
+ default: ''
451
+ },
452
+ inputDataId: {
453
+ required: false,
454
+ default: ''
455
+ }
456
+ },
457
+ computed: {
458
+ displayedPlaceholder() {
459
+ if (this.placeholder) return this.placeholder
460
+ if (this.defaultNumber)
461
+ return `${this.defaultNumber} ${this.unitName ? this.unitName : ''}`
462
+ return `${this.minNumber || 0} ${this.unitName ? this.unitName : ''}`
463
+ },
464
+ hasSlot() {
465
+ return !!this.$slots.default
466
+ },
467
+ hasLabelSlot() {
468
+ return !!this.$slots.label
469
+ }
470
+ },
471
+ methods: {
472
+ onChangeHandler(event) {
473
+ if (isNaN(event) || event === '') {
474
+ event = this.defaultNumber
475
+ ? this.defaultNumber
476
+ : this.minNumber || this.minNumber === 0
477
+ ? this.minNumber
478
+ : event
479
+ }
480
+ if (!this.allowNegative) {
481
+ event = Math.abs(event)
482
+ }
483
+ event = parseFloat(event)
484
+ // Need to return an integer rather than a string
485
+ this.$emit('input-change', event)
486
+ },
487
+ onEvaluateCode(val) {
488
+ // function to perform math on the code
489
+ // filter the string in case of any malicious content
490
+ let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
491
+ filtered = filtered.split(/([-+*/()])/)
492
+ let formatted = filtered.map((item) => {
493
+ if (
494
+ item === '+' ||
495
+ item === '-' ||
496
+ item === '*' ||
497
+ item === '/' ||
498
+ item === '(' ||
499
+ item === ')' ||
500
+ item === ''
501
+ ) {
502
+ return item
503
+ } else {
504
+ let num = stringToNumber({
505
+ value: item,
506
+ numberPrecision: false,
507
+ minDecimals: this.minDecimals
508
+ })
509
+ return num
510
+ }
511
+ })
512
+ let evaluated
513
+ formatted = this.removeStringItemsAfterLastNumber(formatted)
514
+ evaluated = eval(formatted.join(' '))
515
+ if (typeof evaluated === 'string') {
516
+ evaluated = stringToNumber({
517
+ value: evaluated,
518
+ numberPrecision: this.numberPrecision,
519
+ minDecimals: this.minDecimals
520
+ })
521
+ } else if (typeof evaluated === 'number') {
522
+ evaluated = evaluated.toFixed(this.numberPrecision)
523
+ }
524
+ return evaluated
525
+ },
526
+ removeStringItemsAfterLastNumber(array) {
527
+ // fixed in EPDM-6487, in order to prevent 'Unexpected end of input'
528
+ let lastNumberIndex = -1
529
+ // Find the index of the last number in the array
530
+ for (let i = array.length - 1; i >= 0; i--) {
531
+ if (typeof array[i] === 'number') {
532
+ lastNumberIndex = i
533
+ break
534
+ }
535
+ }
536
+ // if there are no numbers, return an empty array
537
+ if (lastNumberIndex === -1) {
538
+ return []
539
+ }
540
+ // Remove non-numeric items after the last number
541
+ if (lastNumberIndex !== -1) {
542
+ const newArray = array.slice(0, lastNumberIndex + 1)
543
+ return newArray
544
+ }
545
+ return array
546
+ },
547
+ onInput(value) {
548
+ if (this.isBlurred) {
549
+ this.isBlurred = false
550
+ return
551
+ }
552
+ if (value === '') {
553
+ this.$emit('on-input', '')
554
+ }
555
+ let evaluatedVal
556
+ try {
557
+ evaluatedVal = this.onEvaluateCode(value)
558
+ } finally {
559
+ if (evaluatedVal) {
560
+ this.$emit('on-input', evaluatedVal)
561
+ }
562
+ }
563
+ },
564
+ onInputBlur(e) {
565
+ this.isFocused = false
566
+ // setting isBlurred so we don't trigger onInput as well
567
+ this.isBlurred = true
568
+ let value = e.target.value
569
+ let evaluatedInput = this.onEvaluateCode(value)
570
+ this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
571
+ if ((evaluatedInput && value.length) || this.minNumber !== null) {
572
+ this.textInput = numberToString({
573
+ value:
574
+ evaluatedInput && value.length
575
+ ? evaluatedInput
576
+ : this.defaultNumber
577
+ ? this.defaultNumber
578
+ : this.minNumber,
579
+ numberPrecision: this.numberPrecision,
580
+ minDecimals: this.minDecimals
581
+ })
582
+ }
583
+ let adjustedMinValue =
584
+ evaluatedInput && evaluatedInput.length
585
+ ? evaluatedInput
586
+ : this.defaultNumber
587
+ ? this.defaultNumber
588
+ : this.minNumber || this.minNumber === 0
589
+ ? this.minNumber
590
+ : ''
591
+ this.$emit('input-blur', adjustedMinValue)
592
+ },
593
+ focusInput() {
594
+ if (this.disabled) {
595
+ return
596
+ }
597
+ this.isFocused = true
598
+ this.$nextTick(() => {
599
+ this.$refs.inputField1.$el.select()
600
+ })
601
+ this.$emit('input-focus')
602
+ },
603
+ blurInput() {
604
+ if (this.disabled) {
605
+ return
606
+ }
607
+ this.isFocused = false
608
+ this.$nextTick(() => {
609
+ this.$refs.inputField1.$el.blur()
610
+ })
611
+ },
612
+ formatWithCurrency(value) {
613
+ let adjustedMinValue =
614
+ value || value === 0
615
+ ? value
616
+ : this.defaultNumber
617
+ ? this.defaultNumber
618
+ : this.minNumber || this.minNumber === 0
619
+ ? this.minNumber
620
+ : ''
621
+ if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
622
+ let input = this.numberToStringEnabled
623
+ ? numberToString({
624
+ value: adjustedMinValue,
625
+ numberPrecision: this.numberPrecision,
626
+ minDecimals: this.minDecimals
627
+ })
628
+ : adjustedMinValue
629
+ let unit = this.showLinearUnitName ? '' : this.unitName
630
+ //return input + ' ' + unit
631
+ return input + ' ' + unit
632
+ } else if (!adjustedMinValue && adjustedMinValue !== 0) {
633
+ return ''
634
+ } else {
635
+ return this.numberToStringEnabled
636
+ ? numberToString({
637
+ value: adjustedMinValue,
638
+ numberPrecision: this.numberPrecision,
639
+ minDecimals: this.minDecimals
640
+ })
641
+ : adjustedMinValue
642
+ }
643
+ },
644
+ initInteraction(e) {
645
+ window.addEventListener('mousemove', this.interact, false)
646
+ window.addEventListener('mouseup', this.stopInteract, false)
647
+ e.preventDefault()
648
+ this.focusInput()
649
+ },
650
+ interact(e) {
651
+ e.preventDefault()
652
+ let value = parseFloat(this.value || 0)
653
+ value += parseFloat(this.interactionStep) * parseInt(e.movementX)
654
+ this.$emit('on-input', value)
655
+
656
+ this.textInput = numberToString({
657
+ value: value && value.length ? value : this.minNumber,
658
+ numberPrecision: this.numberPrecision,
659
+ minDecimals: this.minDecimals
660
+ })
661
+ //this.value=value
662
+ },
663
+ stopInteract(e) {
664
+ e.preventDefault()
665
+ window.removeEventListener('mousemove', this.interact, false)
666
+ window.removeEventListener('mouseup', this.stopInteract, false)
667
+ this.blurInput()
668
+ }
669
+ },
670
+ created() {
671
+ if (this.value) {
672
+ this.textInput = numberToString({
673
+ value: this.value,
674
+ numberPrecision: this.numberPrecision,
675
+ minDecimals: this.minDecimals
676
+ })
677
+ } else if (this.defaultNumber !== null) {
678
+ this.textInput = numberToString({
679
+ value: this.defaultNumber,
680
+ numberPrecision: this.numberPrecision,
681
+ minDecimals: this.minDecimals
682
+ })
683
+ } else if (this.minNumber !== null) {
684
+ this.textInput = numberToString({
685
+ value: this.minNumber,
686
+ numberPrecision: this.numberPrecision,
687
+ minDecimals: this.minDecimals
688
+ })
689
+ }
690
+ },
691
+ mounted() {
692
+ if (this.focus) {
693
+ this.focusInput()
694
+ }
695
+ },
696
+ watch: {
697
+ focus(value) {
698
+ if (value) {
699
+ this.focusInput()
700
+ }
701
+ },
702
+ clearInput: function (value) {
703
+ if (value) {
704
+ // If the value is typed, then we should clear the textInput on Continue
705
+ this.textInput = ''
706
+ }
707
+ }
708
+ }
709
+ }
710
+ </script>