@eturnity/eturnity_reusable_components 1.2.25-EPDM-5202.2 → 1.2.26

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 (218) 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 +5 -5
  6. package/package.json +63 -63
  7. package/public/index.html +17 -17
  8. package/src/App.vue +321 -321
  9. package/src/assets/icons/arrow_down.svg +3 -3
  10. package/src/assets/icons/arrow_up_red.svg +3 -3
  11. package/src/assets/icons/black_spinner.svg +35 -35
  12. package/src/assets/icons/delete_icon.svg +11 -11
  13. package/src/assets/icons/delete_icon_gray.svg +11 -11
  14. package/src/assets/icons/drag_icon.svg +8 -8
  15. package/src/assets/icons/external_icon.svg +6 -6
  16. package/src/assets/icons/language_icon.svg +6 -6
  17. package/src/assets/icons/pdf_icon.svg +6 -6
  18. package/src/assets/icons/plus_button.svg +4 -4
  19. package/src/assets/icons/search_icon_black.svg +3 -3
  20. package/src/assets/icons/subposition_icon.svg +3 -3
  21. package/src/assets/icons/subposition_marker.svg +3 -3
  22. package/src/assets/icons/warning_icon.svg +3 -3
  23. package/src/assets/svgIcons/2d_active.svg +7 -7
  24. package/src/assets/svgIcons/2d_inactive.svg +8 -8
  25. package/src/assets/svgIcons/3d_active.svg +7 -7
  26. package/src/assets/svgIcons/3d_inactive.svg +8 -8
  27. package/src/assets/svgIcons/accept.svg +5 -5
  28. package/src/assets/svgIcons/activate_panels_active.svg +22 -22
  29. package/src/assets/svgIcons/activate_panels_inactive.svg +20 -20
  30. package/src/assets/svgIcons/add_icon-1.svg +3 -3
  31. package/src/assets/svgIcons/add_icon.svg +4 -4
  32. package/src/assets/svgIcons/address_book.svg +3 -3
  33. package/src/assets/svgIcons/after_sale_as_a_service.svg +6 -6
  34. package/src/assets/svgIcons/all_good.svg +3 -3
  35. package/src/assets/svgIcons/angle_active.svg +5 -5
  36. package/src/assets/svgIcons/angle_inactive.svg +4 -4
  37. package/src/assets/svgIcons/area_active.svg +11 -11
  38. package/src/assets/svgIcons/area_inactive.svg +26 -26
  39. package/src/assets/svgIcons/arrow_down.svg +3 -3
  40. package/src/assets/svgIcons/arrow_left.svg +4 -4
  41. package/src/assets/svgIcons/arrow_right.svg +4 -4
  42. package/src/assets/svgIcons/arrow_up.svg +3 -3
  43. package/src/assets/svgIcons/attachment.svg +3 -3
  44. package/src/assets/svgIcons/battery.svg +3 -3
  45. package/src/assets/svgIcons/bell.svg +3 -3
  46. package/src/assets/svgIcons/bold.svg +3 -3
  47. package/src/assets/svgIcons/bom.svg +3 -3
  48. package/src/assets/svgIcons/bom_generation.svg +10 -10
  49. package/src/assets/svgIcons/bookmaker.svg +3 -3
  50. package/src/assets/svgIcons/bubble.svg +3 -3
  51. package/src/assets/svgIcons/bullet_list.svg +8 -8
  52. package/src/assets/svgIcons/calendar.svg +7 -7
  53. package/src/assets/svgIcons/calendar_icon.svg +7 -7
  54. package/src/assets/svgIcons/call.svg +3 -3
  55. package/src/assets/svgIcons/camera.svg +3 -3
  56. package/src/assets/svgIcons/car.svg +3 -3
  57. package/src/assets/svgIcons/cart.svg +3 -3
  58. package/src/assets/svgIcons/checkbox.svg +3 -3
  59. package/src/assets/svgIcons/clear_formatting.svg +7 -7
  60. package/src/assets/svgIcons/clickable_info.svg +4 -4
  61. package/src/assets/svgIcons/clip.svg +3 -3
  62. package/src/assets/svgIcons/clock.svg +4 -4
  63. package/src/assets/svgIcons/close_for_modals,_tool_tips.svg +4 -4
  64. package/src/assets/svgIcons/collapse.svg +4 -4
  65. package/src/assets/svgIcons/component_library.svg +7 -7
  66. package/src/assets/svgIcons/context_menu-1.svg +6 -6
  67. package/src/assets/svgIcons/context_menu-2.svg +5 -5
  68. package/src/assets/svgIcons/context_menu.svg +5 -5
  69. package/src/assets/svgIcons/context_menu_tabs.svg +5 -5
  70. package/src/assets/svgIcons/cross.svg +4 -4
  71. package/src/assets/svgIcons/current_variant.svg +4 -4
  72. package/src/assets/svgIcons/deadline.svg +4 -4
  73. package/src/assets/svgIcons/delete.svg +4 -4
  74. package/src/assets/svgIcons/delete_area_active.svg +16 -16
  75. package/src/assets/svgIcons/delete_area_inactive.svg +15 -15
  76. package/src/assets/svgIcons/direction_active-1.svg +12 -12
  77. package/src/assets/svgIcons/direction_active.svg +5 -5
  78. package/src/assets/svgIcons/direction_inactive.svg +4 -4
  79. package/src/assets/svgIcons/distances_active.svg +9 -9
  80. package/src/assets/svgIcons/distances_inactive.svg +8 -8
  81. package/src/assets/svgIcons/document.svg +3 -3
  82. package/src/assets/svgIcons/downarrow.svg +3 -3
  83. package/src/assets/svgIcons/download.svg +4 -4
  84. package/src/assets/svgIcons/duplicate-1.svg +8 -8
  85. package/src/assets/svgIcons/duplicate-2.svg +5 -5
  86. package/src/assets/svgIcons/duplicate.svg +4 -4
  87. package/src/assets/svgIcons/e-mobility_configurator.svg +6 -6
  88. package/src/assets/svgIcons/edit_button.svg +3 -3
  89. package/src/assets/svgIcons/email.svg +3 -3
  90. package/src/assets/svgIcons/ems-1.svg +3 -3
  91. package/src/assets/svgIcons/ems.svg +3 -3
  92. package/src/assets/svgIcons/end_of_the_list.svg +5 -5
  93. package/src/assets/svgIcons/erase.svg +4 -4
  94. package/src/assets/svgIcons/fav_icon.svg +4 -4
  95. package/src/assets/svgIcons/financing_for_pv-1.svg +5 -5
  96. package/src/assets/svgIcons/financing_for_pv-2.svg +3 -3
  97. package/src/assets/svgIcons/financing_for_pv.svg +6 -6
  98. package/src/assets/svgIcons/finish-1.svg +4 -4
  99. package/src/assets/svgIcons/finish.svg +3 -3
  100. package/src/assets/svgIcons/folder.svg +3 -3
  101. package/src/assets/svgIcons/heat_calc.svg +7 -7
  102. package/src/assets/svgIcons/house.svg +3 -3
  103. package/src/assets/svgIcons/info.svg +3 -3
  104. package/src/assets/svgIcons/initial_situation.svg +3 -3
  105. package/src/assets/svgIcons/intro-tour-1.svg +3 -3
  106. package/src/assets/svgIcons/intro-tour.svg +3 -3
  107. package/src/assets/svgIcons/inverter-1.svg +5 -5
  108. package/src/assets/svgIcons/inverter.svg +3 -3
  109. package/src/assets/svgIcons/italic.svg +3 -3
  110. package/src/assets/svgIcons/key.svg +3 -3
  111. package/src/assets/svgIcons/lead_marketplace.svg +6 -6
  112. package/src/assets/svgIcons/lead_provider.svg +4 -4
  113. package/src/assets/svgIcons/length_in_2d_active.svg +12 -12
  114. package/src/assets/svgIcons/length_in_2d_inctive.svg +13 -13
  115. package/src/assets/svgIcons/light_bulb.svg +3 -3
  116. package/src/assets/svgIcons/line_graph.svg +3 -3
  117. package/src/assets/svgIcons/local_subsidies.svg +18 -18
  118. package/src/assets/svgIcons/location.svg +3 -3
  119. package/src/assets/svgIcons/lock.svg +3 -3
  120. package/src/assets/svgIcons/loop.svg +3 -3
  121. package/src/assets/svgIcons/lunch.svg +4 -4
  122. package/src/assets/svgIcons/map_icon.svg +3 -3
  123. package/src/assets/svgIcons/meeting.svg +6 -6
  124. package/src/assets/svgIcons/move_copy.svg +4 -4
  125. package/src/assets/svgIcons/new_area_inactive.svg +11 -11
  126. package/src/assets/svgIcons/next.svg +4 -4
  127. package/src/assets/svgIcons/not_equal_to.svg +3 -3
  128. package/src/assets/svgIcons/numbered_list.svg +6 -6
  129. package/src/assets/svgIcons/obstacle_tool.svg +13 -13
  130. package/src/assets/svgIcons/pan_tool.svg +12 -12
  131. package/src/assets/svgIcons/panels_tool.svg +8 -8
  132. package/src/assets/svgIcons/pen_tool.svg +4 -4
  133. package/src/assets/svgIcons/picker_tool.svg +4 -4
  134. package/src/assets/svgIcons/picture.svg +3 -3
  135. package/src/assets/svgIcons/pin.svg +5 -5
  136. package/src/assets/svgIcons/presentation.svg +3 -3
  137. package/src/assets/svgIcons/previous.svg +4 -4
  138. package/src/assets/svgIcons/profile-1.svg +4 -4
  139. package/src/assets/svgIcons/profile.svg +4 -4
  140. package/src/assets/svgIcons/profitability.svg +3 -3
  141. package/src/assets/svgIcons/project_analysis.svg +4 -4
  142. package/src/assets/svgIcons/project_settings.svg +4 -4
  143. package/src/assets/svgIcons/pv.svg +3 -3
  144. package/src/assets/svgIcons/quotations.svg +6 -6
  145. package/src/assets/svgIcons/rotate_view.svg +5 -5
  146. package/src/assets/svgIcons/run_simulation.svg +3 -3
  147. package/src/assets/svgIcons/scaling_tool.svg +8 -8
  148. package/src/assets/svgIcons/search.svg +3 -3
  149. package/src/assets/svgIcons/security.svg +3 -3
  150. package/src/assets/svgIcons/settings.svg +3 -3
  151. package/src/assets/svgIcons/show_in_a_new_tab.svg +12 -12
  152. package/src/assets/svgIcons/smartphone.svg +4 -4
  153. package/src/assets/svgIcons/solar_calc.svg +13 -13
  154. package/src/assets/svgIcons/sorting.svg +4 -4
  155. package/src/assets/svgIcons/start_of_the_list.svg +5 -5
  156. package/src/assets/svgIcons/strikethrough.svg +4 -4
  157. package/src/assets/svgIcons/subsidies-1.svg +5 -5
  158. package/src/assets/svgIcons/subsidies-2.svg +3 -3
  159. package/src/assets/svgIcons/subsidies.svg +3 -3
  160. package/src/assets/svgIcons/subtract_icon.svg +3 -3
  161. package/src/assets/svgIcons/suitcase.svg +3 -3
  162. package/src/assets/svgIcons/template_icon_not_clickable.svg +6 -6
  163. package/src/assets/svgIcons/transfer.svg +4 -4
  164. package/src/assets/svgIcons/truck.svg +3 -3
  165. package/src/assets/svgIcons/underlined.svg +3 -3
  166. package/src/assets/svgIcons/uparrow.svg +3 -3
  167. package/src/assets/svgIcons/upload_avatar-1.svg +12 -12
  168. package/src/assets/svgIcons/upload_avatar.svg +5 -5
  169. package/src/assets/svgIcons/upload_image.svg +8 -8
  170. package/src/assets/svgIcons/virtual_storage.svg +4 -4
  171. package/src/assets/svgIcons/warning.svg +4 -4
  172. package/src/assets/svgIcons/way.svg +5 -5
  173. package/src/assets/svgIcons/wifi.svg +3 -3
  174. package/src/assets/svgIcons/winter.svg +3 -3
  175. package/src/assets/theme.js +34 -34
  176. package/src/components/addNewButton/AddNewButton.stories.js +24 -24
  177. package/src/components/addNewButton/index.vue +58 -58
  178. package/src/components/buttons/closeButton/CloseButton.stories.js +29 -29
  179. package/src/components/buttons/closeButton/index.vue +61 -61
  180. package/src/components/buttons/externalButton/index.vue +101 -101
  181. package/src/components/buttons/mainButton/index.vue +82 -82
  182. package/src/components/deleteIcon/DeleteIcon.stories.js +29 -29
  183. package/src/components/deleteIcon/index.vue +55 -55
  184. package/src/components/icon/Icons.stories.js +41 -41
  185. package/src/components/icon/iconCollection.vue +68 -68
  186. package/src/components/icon/index.vue +83 -83
  187. package/src/components/infoText/index.vue +151 -151
  188. package/src/components/inputs/checkbox/Checkbox.stories.js +57 -57
  189. package/src/components/inputs/checkbox/index.vue +182 -182
  190. package/src/components/inputs/inputNumber/InputNumber.stories.js +150 -150
  191. package/src/components/inputs/inputNumber/index.vue +390 -390
  192. package/src/components/inputs/inputNumberQuestion/index.vue +215 -215
  193. package/src/components/inputs/inputText/InputText.stories.js +75 -75
  194. package/src/components/inputs/inputText/index.vue +253 -253
  195. package/src/components/inputs/radioButton/RadioButton.stories.js +58 -58
  196. package/src/components/inputs/radioButton/index.vue +246 -246
  197. package/src/components/inputs/searchInput/SearchInput.stories.js +40 -40
  198. package/src/components/inputs/searchInput/index.vue +97 -97
  199. package/src/components/inputs/slider/index.vue +126 -126
  200. package/src/components/inputs/textAreaInput/TextAreaInput.stories.js +135 -135
  201. package/src/components/inputs/textAreaInput/index.vue +189 -189
  202. package/src/components/inputs/toggle/Toggle.stories.js +77 -77
  203. package/src/components/inputs/toggle/index.vue +288 -288
  204. package/src/components/modals/modal/index.vue +153 -153
  205. package/src/components/modals/modal/modal.stories.js +31 -31
  206. package/src/components/pageSubtitle/index.vue +68 -68
  207. package/src/components/pageTitle/index.vue +45 -45
  208. package/src/components/progressBar/index.vue +125 -125
  209. package/src/components/projectMarker/index.vue +285 -285
  210. package/src/components/spinner/index.vue +71 -71
  211. package/src/components/tableDropdown/index.vue +644 -644
  212. package/src/components/tables/mainTable/exampleNested.vue +328 -328
  213. package/src/components/tables/mainTable/index.vue +379 -379
  214. package/src/components/tables/viewTable/index.vue +195 -195
  215. package/src/components/threeDots/index.vue +333 -333
  216. package/src/helpers/numberConverter.js +98 -98
  217. package/src/helpers/translateLang.js +80 -80
  218. package/src/main.js +13 -13
@@ -1,644 +1,644 @@
1
- <template>
2
- <dropdown-row
3
- :colspan="colSpan"
4
- :isOpen="isOpen"
5
- @click="toggleOpen"
6
- :disabled="disabled"
7
- >
8
- <component-container :colSpan="colSpan - 1" class="table-dropdown">
9
- <component-item
10
- v-for="(item, index) in tableItems"
11
- :key="index"
12
- ref="dropdownItem"
13
- :isNested="isNested"
14
- :class="{
15
- 'table-dropdown-item': item.type !== 'input',
16
- }"
17
- >
18
- <nested-container :isNested="isNested">
19
- <nested-icon
20
- v-if="
21
- isNested &&
22
- (item.type === 'input' ||
23
- item.type === 'no-template' ||
24
- item.type === 'template')
25
- "
26
- />
27
- <template-button
28
- @click.stop="onTemplateClick(item.row)"
29
- v-if="
30
- item.type &&
31
- item.type === 'template' &&
32
- (item.value === '' || item.value === '-')
33
- "
34
- :key="idx"
35
- >{{ $gettext("Use template...") }}</template-button
36
- >
37
- <template-link
38
- v-else-if="
39
- item.type && item.type === 'template' && item.value !== ''
40
- "
41
- @click.stop="onSelectedTemplateClick(item.row)"
42
- >
43
- <img
44
- :src="require('../../assets/icons/file_icon.png')"
45
- alt="icon"
46
- width="12"
47
- height="16"
48
- />
49
- <div>{{ item.value }}</div>
50
- </template-link>
51
- <no-template v-if="item.type && item.type === 'no-template'">
52
- {{ $gettext("No main component template") }}
53
- </no-template>
54
- <input-container
55
- v-if="item.type === 'input'"
56
- @click.native.stop="onInputClick()"
57
- >
58
- <text-container
59
- v-if="customInputDisabled"
60
- class="input-placeholder"
61
- >
62
- <span> {{ item.value }}</span>
63
- </text-container>
64
- <input-text
65
- v-else
66
- class="inputField"
67
- :value="item.value"
68
- :noBorder="true"
69
- :minWidth="item.value.length + 'ch'"
70
- :disabled="customInputDisabled"
71
- @input-change="onCustomInputChange($event)"
72
- />
73
- </input-container>
74
- <text-container
75
- v-else-if="
76
- item.type !== 'input' &&
77
- item.type !== 'no-template' &&
78
- item.type !== 'template'
79
- "
80
- >
81
- <span> {{ item.value }}</span>
82
- </text-container>
83
- </nested-container>
84
- </component-item>
85
- <arrow-container class="arrow-container">
86
- <arrow-wrapper :showArchived="showArchived">
87
- <et-popover
88
- v-if="showArchived"
89
- button-class="error"
90
- :text="
91
- $gettext(`Component has been archived and shouldn't be used`)
92
- "
93
- triggerType="hover"
94
- ></et-popover>
95
- <arrow-down
96
- @click.native.stop="toggleOpen"
97
- v-if="!isOpen"
98
- class="arrow-dropdown"
99
- :src="require('../../assets/icons/collapse_arrow_icon.svg')"
100
- />
101
- <arrow-up
102
- @click.native.stop="toggleOpen"
103
- v-else
104
- :src="require('../../assets/icons/collapse_arrow_icon.svg')"
105
- />
106
- </arrow-wrapper>
107
- <options-container
108
- v-if="isOpen"
109
- :top="getItemLocation('top')"
110
- :left="getItemLocation('left')"
111
- ref="optionsContainer"
112
- >
113
- <options-wrapper @click.prevent.stop>
114
- <search-container @click.prevent.stop>
115
- <search-input
116
- :value="inputText"
117
- :placeholder="$gettext('Keyword') + '...'"
118
- @click.prevent.stop
119
- @on-change="onSearch($event)"
120
- ref="searchInput"
121
- />
122
- </search-container>
123
- <spinner v-if="optionsLoading" />
124
- <empty-text v-else-if="!optionsLoading && !optionItems.length">
125
- {{ emptyText ? emptyText : $gettext("No components found.") }}
126
- </empty-text>
127
- <options-item
128
- v-else
129
- :colSpan="colSpan - 1"
130
- :width="dynamicGridWidth"
131
- v-for="(item, index) in optionItems"
132
- :key="index"
133
- @click="onItemClick(item)"
134
- :tabindex="0"
135
- @keyup.enter.native="onItemClick(item)"
136
- >
137
- <template v-for="(option, idx) in optionsDisplay">
138
- <span v-if="option !== 'template'" :key="idx">
139
- {{ !!item[option] ? item[option] : "-" }}
140
- </span>
141
- <template-button
142
- @click.stop="onTemplateClick(item)"
143
- v-else-if="option === 'template' && item.has_template"
144
- :key="idx"
145
- >{{ $gettext("Use template...") }}</template-button
146
- >
147
- <no-template
148
- v-else-if="option === 'template' && !item.has_template"
149
- :key="idx"
150
- >
151
- {{ $gettext("No main component template") }}
152
- </no-template>
153
- </template>
154
- </options-item>
155
- </options-wrapper>
156
- <custom-container
157
- v-if="inputText.length && allowFreeInputs"
158
- @click="onCustomNameClick()"
159
- >
160
- <custom-name>{{ getCustomName }}</custom-name>
161
- <custom-subtext
162
- >({{ $gettext("custom_component") }})</custom-subtext
163
- >
164
- </custom-container>
165
- </options-container>
166
- </arrow-container>
167
- </component-container>
168
- </dropdown-row>
169
- </template>
170
-
171
- <script>
172
- // import TableDropdown from "@eturnity/eturnity_reusable_components/src/components/tableDropdown"
173
- // To use:
174
- // <table-dropdown
175
- // :colSpan="2"
176
- // :tableItems="getDropdownValues(row)"
177
- // :showArchived="
178
- // row.selectedValue
179
- // ? row.selectedValue.status_active === false
180
- // : row.status_active === false
181
- // "
182
- // @toggle-dropdown-open="toggleDropdownOpen(row.id, $event)"
183
- // @dropdown-search="onDropdownSearch($event)"
184
- // @item-selected="onItemSelected({ item: $event, index })"
185
- // :isOpen="isDropdownOpen(row)"
186
- // :optionItems="groupComponents" // list of options
187
- // :optionsLoading="dropdownOptionsLoading"
188
- // :optionsDisplay="['display_name', 'company_item_number']" // Array. what should be displayed
189
- // :disabled="true"
190
- // />
191
- import styled from "vue-styled-components"
192
- import Spinner from "@eturnity/eturnity_reusable_components/src/components/spinner"
193
- import SearchInput from "@eturnity/eturnity_reusable_components/src/components/inputs/searchInput"
194
- import InputText from "@eturnity/eturnity_reusable_components/src/components/inputs/inputText"
195
-
196
- const rowAttrs = { disabled: Boolean, isOpen: Boolean }
197
- const DropdownRow = styled("div", rowAttrs)`
198
- cursor: ${(props) => (props.disabled ? "not-allowed" : "pointer")};
199
- display: contents;
200
-
201
- input {
202
- cursor: ${(props) => (!props.isOpen ? "pointer !important" : "inherit")};
203
- }
204
-
205
- .input-placeholder {
206
- height: 25px;
207
- padding-left: 12px;
208
- }
209
- `
210
-
211
- const ItemAttrs = { isNested: Boolean }
212
- const ComponentItem = styled("td", ItemAttrs)`
213
- padding-left: ${(props) => (props.isNested ? "14px !important" : "0")};
214
- overflow: hidden;
215
- text-overflow: ellipsis;
216
- padding-right: 0 !important;
217
-
218
- &.table-dropdown-item {
219
- background-clip: content-box;
220
- padding: 8px 0 7px 0 !important;
221
- vertical-align: middle;
222
-
223
- @media not all and (min-resolution: 0.001dpcm) {
224
- @supports (-webkit-appearance: none) {
225
- /* Safari Only CSS here */
226
- padding: 8px 0 10px 0 !important;
227
- }
228
- }
229
-
230
- span {
231
- padding-left: 15px;
232
- }
233
- }
234
- `
235
-
236
- const containerAttrs = { colSpan: Number, width: String }
237
- const ComponentContainer = styled("div", containerAttrs)`
238
- display: contents;
239
- align-items: center;
240
- background-color: ${(props) => props.theme.colors.white};
241
- border-radius: 4px;
242
- padding: 5px 4px;
243
- `
244
-
245
- const ArrowDown = styled.img`
246
- width: 8px;
247
- transform: rotate(0deg);
248
- transition: transform 150ms ease;
249
- `
250
-
251
- const ArrowUp = styled.img`
252
- width: 8px;
253
- transform: rotate(180deg);
254
- transition: transform 150ms ease;
255
- `
256
-
257
- const ArrowContainer = styled.td`
258
- border-bottom: 1px solid ${(props) => props.theme.colors.grey4};
259
- background-clip: content-box;
260
- padding: 8px 0 7px 0 !important;
261
- border-radius: 0 4px 4px 0;
262
-
263
- @media not all and (min-resolution: 0.001dpcm) {
264
- @supports (-webkit-appearance: none) {
265
- /* Safari Only CSS here */
266
- padding: 8px 0 10px 0 !important;
267
- }
268
- }
269
-
270
- .arrow-dropdown {
271
- vertical-align: middle;
272
- margin-left: 11px;
273
- }
274
- `
275
-
276
- const arrowAttrs = { showArchived: Boolean }
277
- const ArrowWrapper = styled("div", arrowAttrs)`
278
- display: grid;
279
- grid-template-columns: ${(props) =>
280
- props.showArchived ? "auto auto" : "auto"};
281
- align-items: center;
282
- justify-items: center;
283
- height: 100%;
284
- `
285
-
286
- const optionsAttrs = { top: Number, left: Number }
287
- const OptionsContainer = styled("div", optionsAttrs)`
288
- position: absolute;
289
- display: grid;
290
- grid-template-rows: 1fr auto;
291
- top: ${(props) => props.top + "px"};
292
- left: ${(props) => props.left + "px"};
293
- width: auto;
294
- max-height: 360px;
295
- min-height: 200px;
296
- overflow: auto;
297
- border: 1px solid ${(props) => props.theme.colors.grey3};
298
- z-index: 9999;
299
- background: ${(props) => props.theme.colors.white};
300
- border-radius: 4px;
301
- `
302
-
303
- const EmptyText = styled.div`
304
- align-self: center;
305
- justify-self: center;
306
- height: 100px;
307
- display: grid;
308
- align-content: center;
309
- `
310
-
311
- const OptionsWrapper = styled.div`
312
- display: grid;
313
- position: relative;
314
- padding: 12px;
315
- grid-gap: 4px;
316
- font-size: 13px;
317
- grid-template-rows: max-content;
318
- height: max-content;
319
- min-width: 400px; // kind of an arbitrary number until we know all use cases
320
- `
321
-
322
- const OptionsItem = styled("div", containerAttrs)`
323
- display: grid;
324
- /* grid-template-columns: 1fr repeat(
325
- ${(props) => props.colSpan},
326
- minmax(50px, auto)
327
- ); */
328
- grid-template-columns: ${(props) => props.width};
329
- grid-gap: 30px;
330
- padding: 10px;
331
- height: max-content;
332
- justify-items: flex-start;
333
-
334
- span {
335
- overflow: hidden;
336
- text-overflow: ellipsis;
337
- }
338
-
339
- &:hover {
340
- background-color: ${(props) => props.theme.colors.grey5};
341
- }
342
- `
343
-
344
- const SearchContainer = styled.div`
345
- position: sticky;
346
- top: 0;
347
- padding-top: 6px;
348
- background: ${(props) => props.theme.colors.white};
349
- height: 40px;
350
- `
351
-
352
- const TemplateButton = styled.div`
353
- cursor: pointer;
354
- background-color: #263238;
355
- color: ${(props) => props.theme.colors.white};
356
- padding: 4px 10px;
357
- display: inline-block;
358
- border-radius: 4px;
359
- text-align: center;
360
- `
361
-
362
- const NoTemplate = styled.div`
363
- color: ${(props) => props.theme.colors.gray1};
364
- font-style: italic;
365
- overflow: hidden;
366
- text-overflow: ellipsis;
367
- `
368
-
369
- const TemplateLink = styled.div`
370
- color: ${(props) => props.theme.colors.purple};
371
- cursor: pointer;
372
- display: grid;
373
- grid-template-columns: auto 1fr;
374
- grid-gap: 12px;
375
- `
376
-
377
- const InputContainer = styled.div`
378
- .inputField input {
379
- border-radius: 4px 0 0 4px;
380
- }
381
- `
382
-
383
- const CustomContainer = styled.div`
384
- display: grid;
385
- grid-template-columns: auto 1fr;
386
- padding: 10px 22px;
387
- border-top: 1px solid ${(props) => props.theme.colors.grey3};
388
- height: 37px;
389
-
390
- &:hover {
391
- background-color: ${(props) => props.theme.colors.grey5};
392
- }
393
- `
394
-
395
- const CustomName = styled.div`
396
- justify-self: flex-start;
397
- `
398
-
399
- const CustomSubtext = styled.div`
400
- justify-self: flex-end;
401
- color: ${(props) => props.theme.colors.grey3};
402
- `
403
-
404
- const TextContainer = styled.div`
405
- height: 100%;
406
- display: grid;
407
- align-items: center;
408
- `
409
-
410
- const NestedIcon = styled.div`
411
- background-image: ${() =>
412
- `url(${require("../../assets/icons/subposition_marker.svg")})`};
413
- height: 10px;
414
- width: 6px;
415
- `
416
-
417
- const NestedAttrs = { isNested: Boolean }
418
- const NestedContainer = styled("div", NestedAttrs)`
419
- display: grid;
420
- grid-gap: 5px;
421
- grid-template-columns: ${(props) => (props.isNested ? "auto 1fr" : "1fr")};
422
- align-items: center;
423
- `
424
-
425
- export default {
426
- name: "table-dropdown",
427
- components: {
428
- DropdownRow,
429
- ComponentItem,
430
- ComponentContainer,
431
- ArrowDown,
432
- ArrowUp,
433
- OptionsContainer,
434
- Spinner,
435
- EmptyText,
436
- SearchInput,
437
- ArrowWrapper,
438
- OptionsWrapper,
439
- OptionsItem,
440
- SearchContainer,
441
- TemplateButton,
442
- NoTemplate,
443
- TemplateLink,
444
- InputText,
445
- InputContainer,
446
- CustomContainer,
447
- CustomName,
448
- CustomSubtext,
449
- ArrowContainer,
450
- TextContainer,
451
- NestedIcon,
452
- NestedContainer,
453
- },
454
- props: {
455
- colSpan: {
456
- required: false,
457
- default: 1,
458
- },
459
- customInputDisabled: {
460
- // whether the input field should be disabled
461
- required: false,
462
- default: true,
463
- },
464
- allowFreeInputs: {
465
- // whether we allow the user to select a custom input
466
- required: false,
467
- default: false,
468
- },
469
- tableItems: {
470
- required: true,
471
- },
472
- showArchived: {
473
- required: false,
474
- default: false,
475
- },
476
- isOpen: {
477
- required: true,
478
- default: false,
479
- },
480
- optionsLoading: {
481
- required: false,
482
- default: false,
483
- },
484
- emptyText: {
485
- required: false,
486
- default: null,
487
- },
488
- optionItems: {
489
- required: true,
490
- },
491
- optionsDisplay: {
492
- required: true,
493
- default: [], // should be like ['display_name', 'company_item_number', 'description']
494
- },
495
- disabled: {
496
- required: false,
497
- default: false,
498
- },
499
- isNested: {
500
- required: false,
501
- default: false,
502
- },
503
- },
504
- data() {
505
- return {
506
- inputText: "",
507
- wasClicked: false, // prevents custom-name from being triggered on the <input-text />
508
- dynamicWidth: [], // for numbers
509
- dynamicGridWidth: [], // for grid values
510
- }
511
- },
512
- methods: {
513
- toggleOpen() {
514
- if (this.disabled) {
515
- return
516
- }
517
- this.wasClicked = false
518
- if (!this.isOpen) {
519
- document.addEventListener("click", this.clickOutside)
520
- this.$emit("dropdown-search", "")
521
- this.$nextTick(() => {
522
- this.scrollToItem()
523
- })
524
- this.$emit("toggle-dropdown-open", { close: false })
525
- this.$nextTick(() => {
526
- this.$refs.searchInput.$el.children[0].children[0].focus()
527
- })
528
- } else {
529
- document.removeEventListener("click", this.clickOutside)
530
- this.$emit("toggle-dropdown-open", { close: true })
531
- this.inputText = ""
532
- }
533
- },
534
- onInputClick() {
535
- if (!this.isOpen) {
536
- this.toggleOpen()
537
- }
538
- },
539
- scrollToItem() {
540
- if (this.$refs.optionsContainer) {
541
- this.$refs.optionsContainer.$el.scrollIntoView({
542
- behavior: "smooth",
543
- block: "center",
544
- })
545
- }
546
- },
547
- onTemplateClick(item) {
548
- this.$emit("on-template-click", item)
549
- },
550
- onSelectedTemplateClick(item) {
551
- this.$emit("on-selected-template-click", item)
552
- },
553
- onItemClick(item) {
554
- this.wasClicked = true
555
- this.$emit("item-selected", item)
556
- },
557
- onSearch(value) {
558
- this.inputText = value
559
- this.$emit("dropdown-search", value)
560
- },
561
- getItemLocation(value) {
562
- let ref = this.$refs.dropdownItem[0]
563
- let location = ref.$el.getBoundingClientRect()[value]
564
- if (value === "top") {
565
- location = location + window.scrollY + 40
566
- }
567
- return location
568
- },
569
- clickOutside(event) {
570
- if (event.target === this.$el || this.$el.contains(event.target)) {
571
- return
572
- }
573
- this.inputText = ""
574
- // 'close: true' is needed in case a box is open and another box is clicked on
575
- // so this one will close properly
576
- document.removeEventListener("click", this.clickOutside)
577
- this.$emit("toggle-dropdown-open", { close: true })
578
- },
579
- onCustomNameClick() {
580
- this.wasClicked = true
581
- this.$emit("on-custom-input-name", this.inputText)
582
- this.$emit("toggle-dropdown-open", { close: true })
583
- this.inputText = ""
584
- },
585
- onCustomInputChange(event) {
586
- if (this.wasClicked) {
587
- return
588
- }
589
- this.$emit("custom-input-change", event)
590
- },
591
- setDropdownWidth(options) {
592
- this.dynamicWidth = []
593
- options.map((item) => {
594
- this.optionsDisplay.map((header, index) => {
595
- let value =
596
- header === "template"
597
- ? this.$gettext("No main component template")
598
- : item[header]
599
-
600
- value = !!value ? value : ""
601
-
602
- if (
603
- this.optionsDisplay.length &&
604
- (this.dynamicWidth.length < this.optionsDisplay.length ||
605
- value.length > this.dynamicWidth[index])
606
- ) {
607
- if (Array.isArray(this.dynamicGridWidth)) {
608
- this.dynamicGridWidth[index] = value.length + "ch"
609
- }
610
- this.dynamicWidth[index] = value.length
611
- }
612
- })
613
- })
614
- if (this.dynamicGridWidth.length === this.optionsDisplay.length) {
615
- this.dynamicGridWidth = this.dynamicGridWidth.join(" ")
616
- }
617
- },
618
- },
619
- computed: {
620
- getCustomName() {
621
- return this.inputText
622
- },
623
- },
624
- watch: {
625
- isOpen(newVal) {
626
- if (newVal) {
627
- document.addEventListener("click", this.clickOutside)
628
- this.$emit("dropdown-search", "")
629
- this.$nextTick(() => {
630
- this.$refs.searchInput.$el.children[0].children[0].focus()
631
- })
632
- this.$nextTick(() => {
633
- this.scrollToItem()
634
- })
635
- }
636
- },
637
- optionItems(val) {
638
- if (val && val.length) {
639
- this.setDropdownWidth(val)
640
- }
641
- },
642
- },
643
- }
644
- </script>
1
+ <template>
2
+ <dropdown-row
3
+ :colspan="colSpan"
4
+ :isOpen="isOpen"
5
+ @click="toggleOpen"
6
+ :disabled="disabled"
7
+ >
8
+ <component-container :colSpan="colSpan - 1" class="table-dropdown">
9
+ <component-item
10
+ v-for="(item, index) in tableItems"
11
+ :key="index"
12
+ ref="dropdownItem"
13
+ :isNested="isNested"
14
+ :class="{
15
+ 'table-dropdown-item': item.type !== 'input',
16
+ }"
17
+ >
18
+ <nested-container :isNested="isNested">
19
+ <nested-icon
20
+ v-if="
21
+ isNested &&
22
+ (item.type === 'input' ||
23
+ item.type === 'no-template' ||
24
+ item.type === 'template')
25
+ "
26
+ />
27
+ <template-button
28
+ @click.stop="onTemplateClick(item.row)"
29
+ v-if="
30
+ item.type &&
31
+ item.type === 'template' &&
32
+ (item.value === '' || item.value === '-')
33
+ "
34
+ :key="idx"
35
+ >{{ $gettext("Use template...") }}</template-button
36
+ >
37
+ <template-link
38
+ v-else-if="
39
+ item.type && item.type === 'template' && item.value !== ''
40
+ "
41
+ @click.stop="onSelectedTemplateClick(item.row)"
42
+ >
43
+ <img
44
+ :src="require('../../assets/icons/file_icon.png')"
45
+ alt="icon"
46
+ width="12"
47
+ height="16"
48
+ />
49
+ <div>{{ item.value }}</div>
50
+ </template-link>
51
+ <no-template v-if="item.type && item.type === 'no-template'">
52
+ {{ $gettext("No main component template") }}
53
+ </no-template>
54
+ <input-container
55
+ v-if="item.type === 'input'"
56
+ @click.native.stop="onInputClick()"
57
+ >
58
+ <text-container
59
+ v-if="customInputDisabled"
60
+ class="input-placeholder"
61
+ >
62
+ <span> {{ item.value }}</span>
63
+ </text-container>
64
+ <input-text
65
+ v-else
66
+ class="inputField"
67
+ :value="item.value"
68
+ :noBorder="true"
69
+ :minWidth="item.value.length + 'ch'"
70
+ :disabled="customInputDisabled"
71
+ @input-change="onCustomInputChange($event)"
72
+ />
73
+ </input-container>
74
+ <text-container
75
+ v-else-if="
76
+ item.type !== 'input' &&
77
+ item.type !== 'no-template' &&
78
+ item.type !== 'template'
79
+ "
80
+ >
81
+ <span> {{ item.value }}</span>
82
+ </text-container>
83
+ </nested-container>
84
+ </component-item>
85
+ <arrow-container class="arrow-container">
86
+ <arrow-wrapper :showArchived="showArchived">
87
+ <et-popover
88
+ v-if="showArchived"
89
+ button-class="error"
90
+ :text="
91
+ $gettext(`Component has been archived and shouldn't be used`)
92
+ "
93
+ triggerType="hover"
94
+ ></et-popover>
95
+ <arrow-down
96
+ @click.native.stop="toggleOpen"
97
+ v-if="!isOpen"
98
+ class="arrow-dropdown"
99
+ :src="require('../../assets/icons/collapse_arrow_icon.svg')"
100
+ />
101
+ <arrow-up
102
+ @click.native.stop="toggleOpen"
103
+ v-else
104
+ :src="require('../../assets/icons/collapse_arrow_icon.svg')"
105
+ />
106
+ </arrow-wrapper>
107
+ <options-container
108
+ v-if="isOpen"
109
+ :top="getItemLocation('top')"
110
+ :left="getItemLocation('left')"
111
+ ref="optionsContainer"
112
+ >
113
+ <options-wrapper @click.prevent.stop>
114
+ <search-container @click.prevent.stop>
115
+ <search-input
116
+ :value="inputText"
117
+ :placeholder="$gettext('Keyword') + '...'"
118
+ @click.prevent.stop
119
+ @on-change="onSearch($event)"
120
+ ref="searchInput"
121
+ />
122
+ </search-container>
123
+ <spinner v-if="optionsLoading" />
124
+ <empty-text v-else-if="!optionsLoading && !optionItems.length">
125
+ {{ emptyText ? emptyText : $gettext("No components found.") }}
126
+ </empty-text>
127
+ <options-item
128
+ v-else
129
+ :colSpan="colSpan - 1"
130
+ :width="dynamicGridWidth"
131
+ v-for="(item, index) in optionItems"
132
+ :key="index"
133
+ @click="onItemClick(item)"
134
+ :tabindex="0"
135
+ @keyup.enter.native="onItemClick(item)"
136
+ >
137
+ <template v-for="(option, idx) in optionsDisplay">
138
+ <span v-if="option !== 'template'" :key="idx">
139
+ {{ !!item[option] ? item[option] : "-" }}
140
+ </span>
141
+ <template-button
142
+ @click.stop="onTemplateClick(item)"
143
+ v-else-if="option === 'template' && item.has_template"
144
+ :key="idx"
145
+ >{{ $gettext("Use template...") }}</template-button
146
+ >
147
+ <no-template
148
+ v-else-if="option === 'template' && !item.has_template"
149
+ :key="idx"
150
+ >
151
+ {{ $gettext("No main component template") }}
152
+ </no-template>
153
+ </template>
154
+ </options-item>
155
+ </options-wrapper>
156
+ <custom-container
157
+ v-if="inputText.length && allowFreeInputs"
158
+ @click="onCustomNameClick()"
159
+ >
160
+ <custom-name>{{ getCustomName }}</custom-name>
161
+ <custom-subtext
162
+ >({{ $gettext("custom_component") }})</custom-subtext
163
+ >
164
+ </custom-container>
165
+ </options-container>
166
+ </arrow-container>
167
+ </component-container>
168
+ </dropdown-row>
169
+ </template>
170
+
171
+ <script>
172
+ // import TableDropdown from "@eturnity/eturnity_reusable_components/src/components/tableDropdown"
173
+ // To use:
174
+ // <table-dropdown
175
+ // :colSpan="2"
176
+ // :tableItems="getDropdownValues(row)"
177
+ // :showArchived="
178
+ // row.selectedValue
179
+ // ? row.selectedValue.status_active === false
180
+ // : row.status_active === false
181
+ // "
182
+ // @toggle-dropdown-open="toggleDropdownOpen(row.id, $event)"
183
+ // @dropdown-search="onDropdownSearch($event)"
184
+ // @item-selected="onItemSelected({ item: $event, index })"
185
+ // :isOpen="isDropdownOpen(row)"
186
+ // :optionItems="groupComponents" // list of options
187
+ // :optionsLoading="dropdownOptionsLoading"
188
+ // :optionsDisplay="['display_name', 'company_item_number']" // Array. what should be displayed
189
+ // :disabled="true"
190
+ // />
191
+ import styled from "vue-styled-components"
192
+ import Spinner from "@eturnity/eturnity_reusable_components/src/components/spinner"
193
+ import SearchInput from "@eturnity/eturnity_reusable_components/src/components/inputs/searchInput"
194
+ import InputText from "@eturnity/eturnity_reusable_components/src/components/inputs/inputText"
195
+
196
+ const rowAttrs = { disabled: Boolean, isOpen: Boolean }
197
+ const DropdownRow = styled("div", rowAttrs)`
198
+ cursor: ${(props) => (props.disabled ? "not-allowed" : "pointer")};
199
+ display: contents;
200
+
201
+ input {
202
+ cursor: ${(props) => (!props.isOpen ? "pointer !important" : "inherit")};
203
+ }
204
+
205
+ .input-placeholder {
206
+ height: 25px;
207
+ padding-left: 12px;
208
+ }
209
+ `
210
+
211
+ const ItemAttrs = { isNested: Boolean }
212
+ const ComponentItem = styled("td", ItemAttrs)`
213
+ padding-left: ${(props) => (props.isNested ? "14px !important" : "0")};
214
+ overflow: hidden;
215
+ text-overflow: ellipsis;
216
+ padding-right: 0 !important;
217
+
218
+ &.table-dropdown-item {
219
+ background-clip: content-box;
220
+ padding: 8px 0 7px 0 !important;
221
+ vertical-align: middle;
222
+
223
+ @media not all and (min-resolution: 0.001dpcm) {
224
+ @supports (-webkit-appearance: none) {
225
+ /* Safari Only CSS here */
226
+ padding: 8px 0 10px 0 !important;
227
+ }
228
+ }
229
+
230
+ span {
231
+ padding-left: 15px;
232
+ }
233
+ }
234
+ `
235
+
236
+ const containerAttrs = { colSpan: Number, width: String }
237
+ const ComponentContainer = styled("div", containerAttrs)`
238
+ display: contents;
239
+ align-items: center;
240
+ background-color: ${(props) => props.theme.colors.white};
241
+ border-radius: 4px;
242
+ padding: 5px 4px;
243
+ `
244
+
245
+ const ArrowDown = styled.img`
246
+ width: 8px;
247
+ transform: rotate(0deg);
248
+ transition: transform 150ms ease;
249
+ `
250
+
251
+ const ArrowUp = styled.img`
252
+ width: 8px;
253
+ transform: rotate(180deg);
254
+ transition: transform 150ms ease;
255
+ `
256
+
257
+ const ArrowContainer = styled.td`
258
+ border-bottom: 1px solid ${(props) => props.theme.colors.grey4};
259
+ background-clip: content-box;
260
+ padding: 8px 0 7px 0 !important;
261
+ border-radius: 0 4px 4px 0;
262
+
263
+ @media not all and (min-resolution: 0.001dpcm) {
264
+ @supports (-webkit-appearance: none) {
265
+ /* Safari Only CSS here */
266
+ padding: 8px 0 10px 0 !important;
267
+ }
268
+ }
269
+
270
+ .arrow-dropdown {
271
+ vertical-align: middle;
272
+ margin-left: 11px;
273
+ }
274
+ `
275
+
276
+ const arrowAttrs = { showArchived: Boolean }
277
+ const ArrowWrapper = styled("div", arrowAttrs)`
278
+ display: grid;
279
+ grid-template-columns: ${(props) =>
280
+ props.showArchived ? "auto auto" : "auto"};
281
+ align-items: center;
282
+ justify-items: center;
283
+ height: 100%;
284
+ `
285
+
286
+ const optionsAttrs = { top: Number, left: Number }
287
+ const OptionsContainer = styled("div", optionsAttrs)`
288
+ position: absolute;
289
+ display: grid;
290
+ grid-template-rows: 1fr auto;
291
+ top: ${(props) => props.top + "px"};
292
+ left: ${(props) => props.left + "px"};
293
+ width: auto;
294
+ max-height: 360px;
295
+ min-height: 200px;
296
+ overflow: auto;
297
+ border: 1px solid ${(props) => props.theme.colors.grey3};
298
+ z-index: 9999;
299
+ background: ${(props) => props.theme.colors.white};
300
+ border-radius: 4px;
301
+ `
302
+
303
+ const EmptyText = styled.div`
304
+ align-self: center;
305
+ justify-self: center;
306
+ height: 100px;
307
+ display: grid;
308
+ align-content: center;
309
+ `
310
+
311
+ const OptionsWrapper = styled.div`
312
+ display: grid;
313
+ position: relative;
314
+ padding: 12px;
315
+ grid-gap: 4px;
316
+ font-size: 13px;
317
+ grid-template-rows: max-content;
318
+ height: max-content;
319
+ min-width: 400px; // kind of an arbitrary number until we know all use cases
320
+ `
321
+
322
+ const OptionsItem = styled("div", containerAttrs)`
323
+ display: grid;
324
+ /* grid-template-columns: 1fr repeat(
325
+ ${(props) => props.colSpan},
326
+ minmax(50px, auto)
327
+ ); */
328
+ grid-template-columns: ${(props) => props.width};
329
+ grid-gap: 30px;
330
+ padding: 10px;
331
+ height: max-content;
332
+ justify-items: flex-start;
333
+
334
+ span {
335
+ overflow: hidden;
336
+ text-overflow: ellipsis;
337
+ }
338
+
339
+ &:hover {
340
+ background-color: ${(props) => props.theme.colors.grey5};
341
+ }
342
+ `
343
+
344
+ const SearchContainer = styled.div`
345
+ position: sticky;
346
+ top: 0;
347
+ padding-top: 6px;
348
+ background: ${(props) => props.theme.colors.white};
349
+ height: 40px;
350
+ `
351
+
352
+ const TemplateButton = styled.div`
353
+ cursor: pointer;
354
+ background-color: #263238;
355
+ color: ${(props) => props.theme.colors.white};
356
+ padding: 4px 10px;
357
+ display: inline-block;
358
+ border-radius: 4px;
359
+ text-align: center;
360
+ `
361
+
362
+ const NoTemplate = styled.div`
363
+ color: ${(props) => props.theme.colors.gray1};
364
+ font-style: italic;
365
+ overflow: hidden;
366
+ text-overflow: ellipsis;
367
+ `
368
+
369
+ const TemplateLink = styled.div`
370
+ color: ${(props) => props.theme.colors.purple};
371
+ cursor: pointer;
372
+ display: grid;
373
+ grid-template-columns: auto 1fr;
374
+ grid-gap: 12px;
375
+ `
376
+
377
+ const InputContainer = styled.div`
378
+ .inputField input {
379
+ border-radius: 4px 0 0 4px;
380
+ }
381
+ `
382
+
383
+ const CustomContainer = styled.div`
384
+ display: grid;
385
+ grid-template-columns: auto 1fr;
386
+ padding: 10px 22px;
387
+ border-top: 1px solid ${(props) => props.theme.colors.grey3};
388
+ height: 37px;
389
+
390
+ &:hover {
391
+ background-color: ${(props) => props.theme.colors.grey5};
392
+ }
393
+ `
394
+
395
+ const CustomName = styled.div`
396
+ justify-self: flex-start;
397
+ `
398
+
399
+ const CustomSubtext = styled.div`
400
+ justify-self: flex-end;
401
+ color: ${(props) => props.theme.colors.grey3};
402
+ `
403
+
404
+ const TextContainer = styled.div`
405
+ height: 100%;
406
+ display: grid;
407
+ align-items: center;
408
+ `
409
+
410
+ const NestedIcon = styled.div`
411
+ background-image: ${() =>
412
+ `url(${require("../../assets/icons/subposition_marker.svg")})`};
413
+ height: 10px;
414
+ width: 6px;
415
+ `
416
+
417
+ const NestedAttrs = { isNested: Boolean }
418
+ const NestedContainer = styled("div", NestedAttrs)`
419
+ display: grid;
420
+ grid-gap: 5px;
421
+ grid-template-columns: ${(props) => (props.isNested ? "auto 1fr" : "1fr")};
422
+ align-items: center;
423
+ `
424
+
425
+ export default {
426
+ name: "table-dropdown",
427
+ components: {
428
+ DropdownRow,
429
+ ComponentItem,
430
+ ComponentContainer,
431
+ ArrowDown,
432
+ ArrowUp,
433
+ OptionsContainer,
434
+ Spinner,
435
+ EmptyText,
436
+ SearchInput,
437
+ ArrowWrapper,
438
+ OptionsWrapper,
439
+ OptionsItem,
440
+ SearchContainer,
441
+ TemplateButton,
442
+ NoTemplate,
443
+ TemplateLink,
444
+ InputText,
445
+ InputContainer,
446
+ CustomContainer,
447
+ CustomName,
448
+ CustomSubtext,
449
+ ArrowContainer,
450
+ TextContainer,
451
+ NestedIcon,
452
+ NestedContainer,
453
+ },
454
+ props: {
455
+ colSpan: {
456
+ required: false,
457
+ default: 1,
458
+ },
459
+ customInputDisabled: {
460
+ // whether the input field should be disabled
461
+ required: false,
462
+ default: true,
463
+ },
464
+ allowFreeInputs: {
465
+ // whether we allow the user to select a custom input
466
+ required: false,
467
+ default: false,
468
+ },
469
+ tableItems: {
470
+ required: true,
471
+ },
472
+ showArchived: {
473
+ required: false,
474
+ default: false,
475
+ },
476
+ isOpen: {
477
+ required: true,
478
+ default: false,
479
+ },
480
+ optionsLoading: {
481
+ required: false,
482
+ default: false,
483
+ },
484
+ emptyText: {
485
+ required: false,
486
+ default: null,
487
+ },
488
+ optionItems: {
489
+ required: true,
490
+ },
491
+ optionsDisplay: {
492
+ required: true,
493
+ default: [], // should be like ['display_name', 'company_item_number', 'description']
494
+ },
495
+ disabled: {
496
+ required: false,
497
+ default: false,
498
+ },
499
+ isNested: {
500
+ required: false,
501
+ default: false,
502
+ },
503
+ },
504
+ data() {
505
+ return {
506
+ inputText: "",
507
+ wasClicked: false, // prevents custom-name from being triggered on the <input-text />
508
+ dynamicWidth: [], // for numbers
509
+ dynamicGridWidth: [], // for grid values
510
+ }
511
+ },
512
+ methods: {
513
+ toggleOpen() {
514
+ if (this.disabled) {
515
+ return
516
+ }
517
+ this.wasClicked = false
518
+ if (!this.isOpen) {
519
+ document.addEventListener("click", this.clickOutside)
520
+ this.$emit("dropdown-search", "")
521
+ this.$nextTick(() => {
522
+ this.scrollToItem()
523
+ })
524
+ this.$emit("toggle-dropdown-open", { close: false })
525
+ this.$nextTick(() => {
526
+ this.$refs.searchInput.$el.children[0].children[0].focus()
527
+ })
528
+ } else {
529
+ document.removeEventListener("click", this.clickOutside)
530
+ this.$emit("toggle-dropdown-open", { close: true })
531
+ this.inputText = ""
532
+ }
533
+ },
534
+ onInputClick() {
535
+ if (!this.isOpen) {
536
+ this.toggleOpen()
537
+ }
538
+ },
539
+ scrollToItem() {
540
+ if (this.$refs.optionsContainer) {
541
+ this.$refs.optionsContainer.$el.scrollIntoView({
542
+ behavior: "smooth",
543
+ block: "center",
544
+ })
545
+ }
546
+ },
547
+ onTemplateClick(item) {
548
+ this.$emit("on-template-click", item)
549
+ },
550
+ onSelectedTemplateClick(item) {
551
+ this.$emit("on-selected-template-click", item)
552
+ },
553
+ onItemClick(item) {
554
+ this.wasClicked = true
555
+ this.$emit("item-selected", item)
556
+ },
557
+ onSearch(value) {
558
+ this.inputText = value
559
+ this.$emit("dropdown-search", value)
560
+ },
561
+ getItemLocation(value) {
562
+ let ref = this.$refs.dropdownItem[0]
563
+ let location = ref.$el.getBoundingClientRect()[value]
564
+ if (value === "top") {
565
+ location = location + window.scrollY + 40
566
+ }
567
+ return location
568
+ },
569
+ clickOutside(event) {
570
+ if (event.target === this.$el || this.$el.contains(event.target)) {
571
+ return
572
+ }
573
+ this.inputText = ""
574
+ // 'close: true' is needed in case a box is open and another box is clicked on
575
+ // so this one will close properly
576
+ document.removeEventListener("click", this.clickOutside)
577
+ this.$emit("toggle-dropdown-open", { close: true })
578
+ },
579
+ onCustomNameClick() {
580
+ this.wasClicked = true
581
+ this.$emit("on-custom-input-name", this.inputText)
582
+ this.$emit("toggle-dropdown-open", { close: true })
583
+ this.inputText = ""
584
+ },
585
+ onCustomInputChange(event) {
586
+ if (this.wasClicked) {
587
+ return
588
+ }
589
+ this.$emit("custom-input-change", event)
590
+ },
591
+ setDropdownWidth(options) {
592
+ this.dynamicWidth = []
593
+ options.map((item) => {
594
+ this.optionsDisplay.map((header, index) => {
595
+ let value =
596
+ header === "template"
597
+ ? this.$gettext("No main component template")
598
+ : item[header]
599
+
600
+ value = !!value ? value : ""
601
+
602
+ if (
603
+ this.optionsDisplay.length &&
604
+ (this.dynamicWidth.length < this.optionsDisplay.length ||
605
+ value.length > this.dynamicWidth[index])
606
+ ) {
607
+ if (Array.isArray(this.dynamicGridWidth)) {
608
+ this.dynamicGridWidth[index] = value.length + "ch"
609
+ }
610
+ this.dynamicWidth[index] = value.length
611
+ }
612
+ })
613
+ })
614
+ if (this.dynamicGridWidth.length === this.optionsDisplay.length) {
615
+ this.dynamicGridWidth = this.dynamicGridWidth.join(" ")
616
+ }
617
+ },
618
+ },
619
+ computed: {
620
+ getCustomName() {
621
+ return this.inputText
622
+ },
623
+ },
624
+ watch: {
625
+ isOpen(newVal) {
626
+ if (newVal) {
627
+ document.addEventListener("click", this.clickOutside)
628
+ this.$emit("dropdown-search", "")
629
+ this.$nextTick(() => {
630
+ this.$refs.searchInput.$el.children[0].children[0].focus()
631
+ })
632
+ this.$nextTick(() => {
633
+ this.scrollToItem()
634
+ })
635
+ }
636
+ },
637
+ optionItems(val) {
638
+ if (val && val.length) {
639
+ this.setDropdownWidth(val)
640
+ }
641
+ },
642
+ },
643
+ }
644
+ </script>