@eturnity/eturnity_reusable_components 7.8.1-EPDM-8441.1 → 7.8.1-EPDM-9696.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/.eslintrc +18 -0
  2. package/.prettierrc +6 -6
  3. package/.storybook/main.js +8 -8
  4. package/.storybook/preview.js +46 -46
  5. package/README.md +29 -29
  6. package/babel.config.js +4 -4
  7. package/package.json +66 -66
  8. package/postcss.config.js +6 -6
  9. package/public/index.html +17 -17
  10. package/src/App.vue +246 -247
  11. package/src/assets/icons/arrow_down.svg +3 -3
  12. package/src/assets/icons/arrow_up_red.svg +3 -3
  13. package/src/assets/icons/black_spinner.svg +35 -35
  14. package/src/assets/icons/delete_icon.svg +11 -11
  15. package/src/assets/icons/delete_icon_gray.svg +11 -11
  16. package/src/assets/icons/drag_icon.svg +8 -8
  17. package/src/assets/icons/external_icon.svg +6 -6
  18. package/src/assets/icons/language_icon.svg +6 -6
  19. package/src/assets/icons/pdf_icon.svg +6 -6
  20. package/src/assets/icons/plus_button.svg +4 -4
  21. package/src/assets/icons/search_icon_black.svg +3 -3
  22. package/src/assets/icons/subposition_icon.svg +3 -3
  23. package/src/assets/icons/subposition_marker.svg +3 -3
  24. package/src/assets/icons/warning_icon.svg +3 -3
  25. package/src/assets/svgIcons/2d_active.svg +7 -7
  26. package/src/assets/svgIcons/2d_inactive.svg +8 -8
  27. package/src/assets/svgIcons/3d_active.svg +7 -7
  28. package/src/assets/svgIcons/3d_inactive.svg +8 -8
  29. package/src/assets/svgIcons/_readme.md +7 -7
  30. package/src/assets/svgIcons/accept.svg +5 -5
  31. package/src/assets/svgIcons/activate_panels_active.svg +22 -22
  32. package/src/assets/svgIcons/activate_panels_inactive.svg +20 -20
  33. package/src/assets/svgIcons/add_icon-1.svg +3 -3
  34. package/src/assets/svgIcons/add_icon.svg +4 -4
  35. package/src/assets/svgIcons/address_book.svg +3 -3
  36. package/src/assets/svgIcons/after_sale_as_a_service.svg +6 -6
  37. package/src/assets/svgIcons/all_good.svg +3 -3
  38. package/src/assets/svgIcons/angle_active.svg +5 -5
  39. package/src/assets/svgIcons/angle_inactive.svg +4 -4
  40. package/src/assets/svgIcons/area_active.svg +11 -11
  41. package/src/assets/svgIcons/area_inactive.svg +26 -26
  42. package/src/assets/svgIcons/areas_tool.svg +14 -14
  43. package/src/assets/svgIcons/arrow_down.svg +3 -3
  44. package/src/assets/svgIcons/arrow_left.svg +4 -4
  45. package/src/assets/svgIcons/arrow_right.svg +4 -4
  46. package/src/assets/svgIcons/arrow_up.svg +3 -3
  47. package/src/assets/svgIcons/attachment.svg +3 -3
  48. package/src/assets/svgIcons/base_layer.svg +3 -3
  49. package/src/assets/svgIcons/battery.svg +3 -3
  50. package/src/assets/svgIcons/bell.svg +3 -3
  51. package/src/assets/svgIcons/bold.svg +3 -3
  52. package/src/assets/svgIcons/bom.svg +3 -3
  53. package/src/assets/svgIcons/bom_generation.svg +10 -10
  54. package/src/assets/svgIcons/bookmaker.svg +3 -3
  55. package/src/assets/svgIcons/bubble.svg +3 -3
  56. package/src/assets/svgIcons/bug.svg +5 -5
  57. package/src/assets/svgIcons/bullet_list.svg +8 -8
  58. package/src/assets/svgIcons/calendar.svg +7 -7
  59. package/src/assets/svgIcons/calendar_icon.svg +7 -7
  60. package/src/assets/svgIcons/call.svg +3 -3
  61. package/src/assets/svgIcons/camera.svg +3 -3
  62. package/src/assets/svgIcons/car.svg +3 -3
  63. package/src/assets/svgIcons/cart.svg +3 -3
  64. package/src/assets/svgIcons/checkbox.svg +3 -3
  65. package/src/assets/svgIcons/clear_formatting.svg +7 -7
  66. package/src/assets/svgIcons/clickable_info.svg +4 -4
  67. package/src/assets/svgIcons/clip.svg +3 -3
  68. package/src/assets/svgIcons/clock.svg +17 -17
  69. package/src/assets/svgIcons/close_for_modals,_tool_tips.svg +4 -4
  70. package/src/assets/svgIcons/co_branding.svg +5 -5
  71. package/src/assets/svgIcons/collapse.svg +4 -4
  72. package/src/assets/svgIcons/collections.svg +3 -3
  73. package/src/assets/svgIcons/component_library.svg +7 -7
  74. package/src/assets/svgIcons/context_menu-1.svg +6 -6
  75. package/src/assets/svgIcons/context_menu-2.svg +5 -5
  76. package/src/assets/svgIcons/context_menu.svg +5 -5
  77. package/src/assets/svgIcons/context_menu_tabs.svg +5 -5
  78. package/src/assets/svgIcons/cross.svg +4 -4
  79. package/src/assets/svgIcons/current_variant.svg +4 -4
  80. package/src/assets/svgIcons/dashboard.svg +3 -3
  81. package/src/assets/svgIcons/deadline.svg +4 -4
  82. package/src/assets/svgIcons/deal_flow.svg +5 -5
  83. package/src/assets/svgIcons/delete.svg +4 -4
  84. package/src/assets/svgIcons/delete_area_active.svg +16 -16
  85. package/src/assets/svgIcons/delete_area_inactive.svg +15 -15
  86. package/src/assets/svgIcons/direction_active-1.svg +12 -12
  87. package/src/assets/svgIcons/direction_active.svg +5 -5
  88. package/src/assets/svgIcons/direction_arrow.svg +4 -4
  89. package/src/assets/svgIcons/direction_inactive.svg +4 -4
  90. package/src/assets/svgIcons/dislike.svg +3 -3
  91. package/src/assets/svgIcons/distance_tool.svg +8 -8
  92. package/src/assets/svgIcons/distances_active.svg +9 -9
  93. package/src/assets/svgIcons/distances_inactive.svg +8 -8
  94. package/src/assets/svgIcons/distort_tool.svg +10 -10
  95. package/src/assets/svgIcons/distort_tool2.svg +16 -16
  96. package/src/assets/svgIcons/document.svg +3 -3
  97. package/src/assets/svgIcons/documents.svg +4 -4
  98. package/src/assets/svgIcons/downarrow.svg +3 -3
  99. package/src/assets/svgIcons/download.svg +4 -4
  100. package/src/assets/svgIcons/draggable_corner.svg +5 -5
  101. package/src/assets/svgIcons/draw_tool.svg +3 -3
  102. package/src/assets/svgIcons/duplicate-1.svg +8 -8
  103. package/src/assets/svgIcons/duplicate-2.svg +5 -5
  104. package/src/assets/svgIcons/duplicate.svg +4 -4
  105. package/src/assets/svgIcons/e-mobility_configurator.svg +6 -6
  106. package/src/assets/svgIcons/e_signature.svg +5 -5
  107. package/src/assets/svgIcons/edit_button.svg +3 -3
  108. package/src/assets/svgIcons/email.svg +3 -3
  109. package/src/assets/svgIcons/ems-1.svg +3 -3
  110. package/src/assets/svgIcons/ems.svg +3 -3
  111. package/src/assets/svgIcons/end_of_the_list.svg +5 -5
  112. package/src/assets/svgIcons/erase.svg +4 -4
  113. package/src/assets/svgIcons/external_icon.svg +5 -5
  114. package/src/assets/svgIcons/fav_icon.svg +4 -4
  115. package/src/assets/svgIcons/finance.svg +3 -3
  116. package/src/assets/svgIcons/financing_for_pv-1.svg +5 -5
  117. package/src/assets/svgIcons/financing_for_pv-2.svg +3 -3
  118. package/src/assets/svgIcons/financing_for_pv.svg +6 -6
  119. package/src/assets/svgIcons/finish-1.svg +4 -4
  120. package/src/assets/svgIcons/finish.svg +3 -3
  121. package/src/assets/svgIcons/flatten.svg +11 -11
  122. package/src/assets/svgIcons/folder.svg +3 -3
  123. package/src/assets/svgIcons/free_technology.svg +5 -5
  124. package/src/assets/svgIcons/heat_calc.svg +7 -7
  125. package/src/assets/svgIcons/house.svg +3 -3
  126. package/src/assets/svgIcons/info.svg +3 -3
  127. package/src/assets/svgIcons/initial_situation.svg +3 -3
  128. package/src/assets/svgIcons/integrations.svg +3 -3
  129. package/src/assets/svgIcons/intro-tour-1.svg +3 -3
  130. package/src/assets/svgIcons/intro-tour.svg +3 -3
  131. package/src/assets/svgIcons/inverter-1.svg +5 -5
  132. package/src/assets/svgIcons/inverter.svg +3 -3
  133. package/src/assets/svgIcons/italic.svg +3 -3
  134. package/src/assets/svgIcons/key.svg +3 -3
  135. package/src/assets/svgIcons/layers_close.svg +4 -4
  136. package/src/assets/svgIcons/layers_open.svg +4 -4
  137. package/src/assets/svgIcons/lead_marketplace.svg +6 -6
  138. package/src/assets/svgIcons/lead_provider.svg +4 -4
  139. package/src/assets/svgIcons/length_in_2d_active.svg +12 -12
  140. package/src/assets/svgIcons/length_in_2d_inctive.svg +13 -13
  141. package/src/assets/svgIcons/light_bulb.svg +3 -3
  142. package/src/assets/svgIcons/like.svg +3 -3
  143. package/src/assets/svgIcons/line_graph.svg +3 -3
  144. package/src/assets/svgIcons/local_subsidies.svg +18 -18
  145. package/src/assets/svgIcons/location.svg +3 -3
  146. package/src/assets/svgIcons/lock.svg +3 -3
  147. package/src/assets/svgIcons/logout.svg +3 -3
  148. package/src/assets/svgIcons/loop.svg +3 -3
  149. package/src/assets/svgIcons/lunch.svg +4 -4
  150. package/src/assets/svgIcons/magic_tool.svg +6 -6
  151. package/src/assets/svgIcons/map_icon.svg +5 -5
  152. package/src/assets/svgIcons/map_settings.svg +3 -3
  153. package/src/assets/svgIcons/margin_tool.svg +4 -4
  154. package/src/assets/svgIcons/meeting.svg +6 -6
  155. package/src/assets/svgIcons/move_copy.svg +4 -4
  156. package/src/assets/svgIcons/new_area_inactive.svg +11 -11
  157. package/src/assets/svgIcons/next.svg +4 -4
  158. package/src/assets/svgIcons/not_equal_to.svg +3 -3
  159. package/src/assets/svgIcons/numbered_list.svg +6 -6
  160. package/src/assets/svgIcons/obstacle_tool.svg +9 -9
  161. package/src/assets/svgIcons/obstacle_tool_origin.svg +3 -3
  162. package/src/assets/svgIcons/offset_tool.svg +8 -8
  163. package/src/assets/svgIcons/outline_tool.svg +11 -11
  164. package/src/assets/svgIcons/pan_tool.svg +12 -12
  165. package/src/assets/svgIcons/panels_tool.svg +8 -8
  166. package/src/assets/svgIcons/pen_tool.svg +4 -4
  167. package/src/assets/svgIcons/picker_tool.svg +4 -4
  168. package/src/assets/svgIcons/picture.svg +3 -3
  169. package/src/assets/svgIcons/pin.svg +5 -5
  170. package/src/assets/svgIcons/presentation.svg +3 -3
  171. package/src/assets/svgIcons/previous.svg +4 -4
  172. package/src/assets/svgIcons/profile-1.svg +4 -4
  173. package/src/assets/svgIcons/profile.svg +4 -4
  174. package/src/assets/svgIcons/profitability.svg +3 -3
  175. package/src/assets/svgIcons/project_analysis.svg +4 -4
  176. package/src/assets/svgIcons/project_settings.svg +4 -4
  177. package/src/assets/svgIcons/pv.svg +3 -3
  178. package/src/assets/svgIcons/quotations.svg +6 -6
  179. package/src/assets/svgIcons/redo.svg +6 -6
  180. package/src/assets/svgIcons/resizer.svg +5 -5
  181. package/src/assets/svgIcons/roof_layer.svg +3 -3
  182. package/src/assets/svgIcons/rotate_tool.svg +3 -3
  183. package/src/assets/svgIcons/rotate_view.svg +5 -5
  184. package/src/assets/svgIcons/ruler_tool.svg +3 -3
  185. package/src/assets/svgIcons/run_simulation.svg +3 -3
  186. package/src/assets/svgIcons/scaling_tool.svg +8 -8
  187. package/src/assets/svgIcons/search.svg +3 -3
  188. package/src/assets/svgIcons/security.svg +3 -3
  189. package/src/assets/svgIcons/settings.svg +3 -3
  190. package/src/assets/svgIcons/show_in_a_new_tab.svg +12 -12
  191. package/src/assets/svgIcons/smartphone.svg +4 -4
  192. package/src/assets/svgIcons/solar_calc.svg +13 -13
  193. package/src/assets/svgIcons/sorting.svg +4 -4
  194. package/src/assets/svgIcons/start_of_the_list.svg +5 -5
  195. package/src/assets/svgIcons/strikethrough.svg +4 -4
  196. package/src/assets/svgIcons/subscriptions.svg +3 -3
  197. package/src/assets/svgIcons/subsidies-1.svg +5 -5
  198. package/src/assets/svgIcons/subsidies-2.svg +3 -3
  199. package/src/assets/svgIcons/subsidies.svg +3 -3
  200. package/src/assets/svgIcons/subtract_icon.svg +3 -3
  201. package/src/assets/svgIcons/suitcase.svg +3 -3
  202. package/src/assets/svgIcons/template_icon_not_clickable.svg +6 -6
  203. package/src/assets/svgIcons/transfer.svg +4 -4
  204. package/src/assets/svgIcons/trim_tool.svg +4 -4
  205. package/src/assets/svgIcons/truck.svg +3 -3
  206. package/src/assets/svgIcons/underlined.svg +3 -3
  207. package/src/assets/svgIcons/undo.svg +6 -6
  208. package/src/assets/svgIcons/uparrow.svg +3 -3
  209. package/src/assets/svgIcons/update.svg +3 -3
  210. package/src/assets/svgIcons/upload_avatar-1.svg +12 -12
  211. package/src/assets/svgIcons/upload_avatar.svg +5 -5
  212. package/src/assets/svgIcons/upload_image.svg +8 -8
  213. package/src/assets/svgIcons/upload_image_tool.svg +7 -7
  214. package/src/assets/svgIcons/variants.svg +6 -6
  215. package/src/assets/svgIcons/vertical_tool.svg +3 -3
  216. package/src/assets/svgIcons/virtual_storage.svg +4 -4
  217. package/src/assets/svgIcons/warning.svg +4 -4
  218. package/src/assets/svgIcons/way.svg +5 -5
  219. package/src/assets/svgIcons/wifi.svg +3 -3
  220. package/src/assets/svgIcons/winter.svg +3 -3
  221. package/src/assets/svgIcons/workflow_template.svg +11 -11
  222. package/src/assets/theme.js +39 -39
  223. package/src/components/addNewButton/AddNewButton.stories.js +24 -24
  224. package/src/components/addNewButton/index.vue +62 -62
  225. package/src/components/buttons/buttonIcon/index.vue +142 -142
  226. package/src/components/buttons/closeButton/CloseButton.stories.js +29 -29
  227. package/src/components/buttons/closeButton/index.vue +61 -61
  228. package/src/components/buttons/mainButton/index.vue +107 -107
  229. package/src/components/deleteIcon/DeleteIcon.stories.js +29 -29
  230. package/src/components/deleteIcon/index.vue +61 -61
  231. package/src/components/draggableInputHandle/index.vue +47 -0
  232. package/src/components/dropdown/Dropdown.stories.js +54 -54
  233. package/src/components/dropdown/index.vue +118 -118
  234. package/src/components/errorMessage/index.vue +61 -61
  235. package/src/components/filter/filterSettings.vue +650 -650
  236. package/src/components/filter/index.vue +143 -143
  237. package/src/components/filter/parentDropdown.vue +91 -91
  238. package/src/components/icon/Icons.stories.js +41 -41
  239. package/src/components/icon/iconCollection.vue +68 -68
  240. package/src/components/icon/index.vue +116 -116
  241. package/src/components/iconWrapper/index.vue +156 -156
  242. package/src/components/infoCard/index.vue +35 -35
  243. package/src/components/infoText/index.vue +171 -171
  244. package/src/components/inputs/checkbox/Checkbox.stories.js +57 -57
  245. package/src/components/inputs/checkbox/index.vue +187 -187
  246. package/src/components/inputs/inputNumber/InputNumber.stories.js +150 -150
  247. package/src/components/inputs/inputNumber/index.vue +710 -710
  248. package/src/components/inputs/inputNumberQuestion/index.vue +215 -215
  249. package/src/components/inputs/inputText/InputText.stories.js +75 -75
  250. package/src/components/inputs/inputText/index.vue +355 -360
  251. package/src/components/inputs/radioButton/RadioButton.stories.js +58 -58
  252. package/src/components/inputs/radioButton/index.vue +267 -267
  253. package/src/components/inputs/searchInput/SearchInput.stories.js +40 -40
  254. package/src/components/inputs/searchInput/index.vue +133 -133
  255. package/src/components/inputs/select/index.vue +609 -622
  256. package/src/components/inputs/select/option/index.vue +111 -111
  257. package/src/components/inputs/select/select.stories.js +59 -59
  258. package/src/components/inputs/slider/index.vue +126 -126
  259. package/src/components/inputs/switchField/index.vue +265 -265
  260. package/src/components/inputs/textAreaInput/TextAreaInput.stories.js +135 -135
  261. package/src/components/inputs/textAreaInput/index.vue +206 -206
  262. package/src/components/inputs/toggle/Toggle.stories.js +77 -77
  263. package/src/components/inputs/toggle/index.vue +298 -298
  264. package/src/components/label/index.vue +104 -0
  265. package/src/components/modals/modal/index.vue +178 -178
  266. package/src/components/modals/modal/modal.stories.js +31 -31
  267. package/src/components/navigationTabs/index.vue +107 -107
  268. package/src/components/pageSubtitle/index.vue +68 -68
  269. package/src/components/pageTitle/index.vue +68 -68
  270. package/src/components/pagination/index.vue +144 -144
  271. package/src/components/progressBar/index.vue +125 -125
  272. package/src/components/projectMarker/index.vue +291 -291
  273. package/src/components/sideMenu/index.vue +270 -270
  274. package/src/components/spinner/index.vue +71 -71
  275. package/src/components/tableDropdown/index.vue +637 -637
  276. package/src/components/tables/mainTable/exampleNested.vue +328 -328
  277. package/src/components/tables/mainTable/index.vue +446 -446
  278. package/src/components/tables/viewTable/index.vue +195 -195
  279. package/src/components/threeDots/index.vue +389 -389
  280. package/src/components/videoThumbnail/index.vue +107 -107
  281. package/src/components/videoThumbnail/videoThumbnail.stories.js +35 -35
  282. package/src/helpers/numberConverter.js +102 -102
  283. package/src/helpers/translateLang.js +119 -119
  284. package/src/main.js +13 -13
@@ -1,710 +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
- 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>
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>