@eturnity/eturnity_reusable_components 7.30.3-EPDM-10647.0 → 7.30.3-EPDM-10576.2

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 (82) hide show
  1. package/.eslintrc.js +184 -0
  2. package/.prettierrc +8 -6
  3. package/package.json +9 -21
  4. package/src/App.vue +79 -78
  5. package/src/assets/theme.js +3 -3
  6. package/src/components/addNewButton/AddNewButton.stories.js +2 -2
  7. package/src/components/addNewButton/index.vue +48 -51
  8. package/src/components/banner/actionBanner/index.vue +54 -55
  9. package/src/components/banner/banner/banner.stories.js +5 -5
  10. package/src/components/banner/banner/index.vue +159 -159
  11. package/src/components/banner/infoBanner/index.vue +41 -53
  12. package/src/components/buttons/buttonIcon/index.vue +125 -122
  13. package/src/components/buttons/closeButton/CloseButton.stories.js +3 -3
  14. package/src/components/buttons/closeButton/index.vue +49 -49
  15. package/src/components/buttons/mainButton/index.vue +108 -108
  16. package/src/components/card/index.vue +70 -70
  17. package/src/components/collapsableInfoText/index.vue +96 -94
  18. package/src/components/deleteIcon/DeleteIcon.stories.js +4 -4
  19. package/src/components/deleteIcon/index.vue +54 -54
  20. package/src/components/draggableInputHandle/index.vue +37 -37
  21. package/src/components/dropdown/Dropdown.stories.js +9 -10
  22. package/src/components/dropdown/index.vue +106 -106
  23. package/src/components/errorMessage/index.vue +52 -52
  24. package/src/components/filter/filterSettings.vue +486 -452
  25. package/src/components/filter/index.vue +135 -135
  26. package/src/components/filter/parentDropdown.vue +73 -73
  27. package/src/components/icon/Icons.stories.js +7 -7
  28. package/src/components/icon/iconCollection.vue +53 -53
  29. package/src/components/icon/index.vue +122 -122
  30. package/src/components/iconWrapper/index.vue +156 -156
  31. package/src/components/infoCard/index.vue +30 -32
  32. package/src/components/infoText/index.vue +142 -137
  33. package/src/components/inputs/checkbox/Checkbox.stories.js +8 -8
  34. package/src/components/inputs/checkbox/index.vue +190 -180
  35. package/src/components/inputs/inputNumber/InputNumber.stories.js +41 -41
  36. package/src/components/inputs/inputNumber/index.vue +696 -701
  37. package/src/components/inputs/inputNumberQuestion/index.vue +185 -182
  38. package/src/components/inputs/inputText/InputText.stories.js +22 -22
  39. package/src/components/inputs/inputText/index.vue +337 -336
  40. package/src/components/inputs/radioButton/RadioButton.stories.js +16 -16
  41. package/src/components/inputs/radioButton/index.vue +222 -219
  42. package/src/components/inputs/searchInput/SearchInput.stories.js +8 -8
  43. package/src/components/inputs/searchInput/index.vue +127 -126
  44. package/src/components/inputs/select/index.vue +792 -792
  45. package/src/components/inputs/select/option/index.vue +124 -124
  46. package/src/components/inputs/select/select.stories.js +31 -32
  47. package/src/components/inputs/slider/index.vue +99 -99
  48. package/src/components/inputs/switchField/index.vue +220 -222
  49. package/src/components/inputs/textAreaInput/TextAreaInput.stories.js +57 -57
  50. package/src/components/inputs/textAreaInput/index.vue +171 -173
  51. package/src/components/inputs/toggle/Toggle.stories.js +14 -14
  52. package/src/components/inputs/toggle/index.vue +214 -217
  53. package/src/components/label/index.vue +82 -82
  54. package/src/components/markerItem/index.vue +68 -66
  55. package/src/components/modals/actionModal/index.vue +54 -54
  56. package/src/components/modals/infoModal/index.vue +39 -36
  57. package/src/components/modals/modal/index.vue +134 -134
  58. package/src/components/modals/modal/modal.stories.js +5 -5
  59. package/src/components/navigationTabs/index.vue +96 -94
  60. package/src/components/pageSubtitle/index.vue +55 -49
  61. package/src/components/pageTitle/index.vue +56 -56
  62. package/src/components/pagination/index.vue +92 -89
  63. package/src/components/progressBar/index.vue +107 -107
  64. package/src/components/projectMarker/index.vue +246 -244
  65. package/src/components/rangeSlider/Slider.vue +491 -465
  66. package/src/components/rangeSlider/index.vue +410 -410
  67. package/src/components/rangeSlider/utils/dom.js +5 -5
  68. package/src/components/selectedOptions/index.vue +119 -119
  69. package/src/components/sideMenu/index.vue +199 -199
  70. package/src/components/spinner/index.vue +57 -57
  71. package/src/components/tableDropdown/index.vue +520 -520
  72. package/src/components/tables/mainTable/index.vue +417 -400
  73. package/src/components/tables/viewTable/index.vue +171 -171
  74. package/src/components/threeDots/index.vue +340 -334
  75. package/src/components/videoThumbnail/index.vue +86 -86
  76. package/src/components/videoThumbnail/videoThumbnail.stories.js +14 -16
  77. package/src/helpers/numberConverter.js +2 -2
  78. package/src/helpers/translateLang.js +9 -9
  79. package/src/mixins/inputValidations.js +5 -5
  80. package/public/favicon.ico +0 -0
  81. package/public/index.html +0 -17
  82. package/src/utils/index.js +0 -12
@@ -1,53 +1,55 @@
1
1
  <template>
2
- <page-container
3
- @click="toggleButton()"
2
+ <PageContainer
4
3
  ref="pageContainer"
5
4
  :activated="isOpen"
5
+ @click="toggleButton()"
6
6
  >
7
- <button-container ref="dropdownItem">
8
- <dot-item />
9
- <dot-item />
10
- <dot-item />
11
- </button-container>
12
- <dropdown-container
13
- @click.stop
14
- :containerWidth="childOpen ? 440 : 240"
7
+ <ButtonContainer ref="dropdownItem">
8
+ <DotItem />
9
+ <DotItem />
10
+ <DotItem />
11
+ </ButtonContainer>
12
+ <DropdownContainer
15
13
  ref="dropdownContainer"
14
+ :container-width="childOpen ? 440 : 240"
15
+ @click.stop
16
16
  >
17
17
  <template v-if="isOpen">
18
- <loading-container v-if="isLoading">
19
- <spinner />
20
- </loading-container>
21
- <children-container
22
- class="child"
23
- :isOpen="hoverItem !== null"
18
+ <LoadingContainer v-if="isLoading">
19
+ <Spinner />
20
+ </LoadingContainer>
21
+ <ChildrenContainer
24
22
  v-if="hoverItem !== null && !isLoading"
23
+ class="child"
24
+ :is-open="hoverItem !== null"
25
25
  >
26
- <option-child
26
+ <OptionChild
27
27
  v-for="child in childOpen"
28
28
  :key="child.value"
29
29
  @click.stop="
30
30
  onSelect({
31
31
  item: child,
32
- hasChildren: hasChildren(child)
32
+ hasChildren: hasChildren(child),
33
33
  })
34
34
  "
35
35
  @keyup.enter.stop="
36
36
  onSelect({
37
37
  item: child,
38
- hasChildren: hasChildren(child)
38
+ hasChildren: hasChildren(child),
39
39
  })
40
40
  "
41
41
  >
42
42
  {{ child.name }}
43
- </option-child>
44
- </children-container>
45
- <options-container v-if="!isLoading" :textWrap="textWrap">
46
- <option-item
43
+ </OptionChild>
44
+ </ChildrenContainer>
45
+ <OptionsContainer v-if="!isLoading" :text-wrap="textWrap">
46
+ <OptionItem
47
47
  v-for="(item, index) in options"
48
48
  :key="item.value"
49
49
  :data-id="item.dataId"
50
+ :is-disabled="item.disabled"
50
51
  tabindex="0"
52
+ :title="item.title"
51
53
  @click.stop="
52
54
  onSelect({ item: item, hasChildren: hasChildren(item) })
53
55
  "
@@ -55,353 +57,357 @@
55
57
  onSelect({ item: item, hasChildren: hasChildren(item) })
56
58
  "
57
59
  @mouseover="onItemHover({ index, item })"
58
- :isDisabled="item.disabled"
59
- :title="item.title"
60
60
  >
61
- <arrow-left
62
- :hasChildren="hasChildren(item)"
61
+ <ArrowLeft
63
62
  v-if="hasChildren(item)"
63
+ :has-children="hasChildren(item)"
64
64
  />
65
65
  <span>
66
66
  {{ item.name }}
67
67
  </span>
68
- </option-item>
69
- </options-container>
68
+ </OptionItem>
69
+ </OptionsContainer>
70
70
  </template>
71
- </dropdown-container>
72
- </page-container>
71
+ </DropdownContainer>
72
+ </PageContainer>
73
73
  </template>
74
74
 
75
75
  <script>
76
- // import ThreeDots from "@eturnity/eturnity_reusable_components/src/components/threeDots"
77
- // To use:
78
- // <three-dots
79
- // :isLoading="true"
80
- // :options="listOptions"
81
- // @on-click="onClick($event)"
82
- // @on-select="onSelect($event)"
83
- // />
84
- // options to pass:
85
- // listOptions: [
86
- // {
87
- // name: "Option 1",
88
- // value: "option_1",
89
- // children: [
90
- // {
91
- // name: "Option 1 Child",
92
- // value: "option_1_child",
93
- // },
94
- // {
95
- // name: "Option 2 Child",
96
- // value: "option_2_child",
97
- // },
98
- // {
99
- // name: "Option 3 Child",
100
- // value: "option_3_child",
101
- // },
102
- // ],
103
- // },
104
- // {
105
- // name: "Option 2",
106
- // value: "option_2",
107
- // },
108
- // {
109
- // name: "Option 3",
110
- // value: "option_3",
111
- // children: [
112
- // {
113
- // name: "Option 3 Child",
114
- // value: "option_3_child",
115
- // },
116
- // {
117
- // name: "Option 4 Child",
118
- // value: "option_4_child",
119
- // },
120
- // {
121
- // name: "Option 5 Child",
122
- // value: "option_5_child",
123
- // },
124
- // ],
125
- // },
126
- // {
127
- // name: "Option 4",
128
- // value: "option_4",
129
- // },
130
- // ],
131
-
132
- import styled from 'vue3-styled-components'
133
- import Spinner from '../spinner'
76
+ // import ThreeDots from "@eturnity/eturnity_reusable_components/src/components/threeDots"
77
+ // To use:
78
+ // <three-dots
79
+ // :isLoading="true"
80
+ // :options="listOptions"
81
+ // @on-click="onClick($event)"
82
+ // @on-select="onSelect($event)"
83
+ // />
84
+ // options to pass:
85
+ // listOptions: [
86
+ // {
87
+ // name: "Option 1",
88
+ // value: "option_1",
89
+ // children: [
90
+ // {
91
+ // name: "Option 1 Child",
92
+ // value: "option_1_child",
93
+ // },
94
+ // {
95
+ // name: "Option 2 Child",
96
+ // value: "option_2_child",
97
+ // },
98
+ // {
99
+ // name: "Option 3 Child",
100
+ // value: "option_3_child",
101
+ // },
102
+ // ],
103
+ // },
104
+ // {
105
+ // name: "Option 2",
106
+ // value: "option_2",
107
+ // },
108
+ // {
109
+ // name: "Option 3",
110
+ // value: "option_3",
111
+ // children: [
112
+ // {
113
+ // name: "Option 3 Child",
114
+ // value: "option_3_child",
115
+ // },
116
+ // {
117
+ // name: "Option 4 Child",
118
+ // value: "option_4_child",
119
+ // },
120
+ // {
121
+ // name: "Option 5 Child",
122
+ // value: "option_5_child",
123
+ // },
124
+ // ],
125
+ // },
126
+ // {
127
+ // name: "Option 4",
128
+ // value: "option_4",
129
+ // },
130
+ // ],
134
131
 
135
- const PageContainerAttrs = {
136
- activated: Boolean
137
- }
138
- const PageContainer = styled('div', PageContainerAttrs)`
139
- display: grid;
140
- align-items: center;
141
- justify-items: center;
142
- width: 30px;
143
- height: 30px;
144
- border-radius: 4px;
145
- background-color: ${(props) =>
146
- props.activated ? props.theme.colors.grey5 : ''};
132
+ import styled from 'vue3-styled-components'
133
+ import Spinner from '../spinner'
147
134
 
148
- &:hover {
149
- background-color: ${(props) => props.theme.colors.grey5};
135
+ const PageContainerAttrs = {
136
+ activated: Boolean,
150
137
  }
151
- `
138
+ const PageContainer = styled('div', PageContainerAttrs)`
139
+ display: grid;
140
+ align-items: center;
141
+ justify-items: center;
142
+ width: 30px;
143
+ height: 30px;
144
+ border-radius: 4px;
145
+ background-color: ${(props) =>
146
+ props.activated ? props.theme.colors.grey5 : ''};
152
147
 
153
- const ButtonContainer = styled.div`
154
- display: flex;
155
- flex-direction: column;
156
- align-items: center;
157
- justify-content: center;
158
- padding: 5px;
159
- cursor: pointer;
148
+ &:hover {
149
+ background-color: ${(props) => props.theme.colors.grey5};
150
+ }
151
+ `
160
152
 
161
- div {
162
- // This is the dot color
163
- background-color: #263238;
164
- }
165
- `
153
+ const ButtonContainer = styled.div`
154
+ display: flex;
155
+ flex-direction: column;
156
+ align-items: center;
157
+ justify-content: center;
158
+ padding: 5px;
159
+ cursor: pointer;
166
160
 
167
- const DotItem = styled.div`
168
- width: 4px;
169
- height: 4px;
170
- margin: 1px;
171
- border-radius: 50%;
172
- `
161
+ div {
162
+ // This is the dot color
163
+ background-color: #263238;
164
+ }
165
+ `
173
166
 
174
- const dropdownAttrs = {
175
- containerWidth: Number
176
- }
177
- const DropdownContainer = styled('div', dropdownAttrs)`
178
- z-index: 99;
179
- position: absolute;
180
- display: grid;
181
- grid-template-columns: auto auto;
182
- `
167
+ const DotItem = styled.div`
168
+ width: 4px;
169
+ height: 4px;
170
+ margin: 1px;
171
+ border-radius: 50%;
172
+ `
183
173
 
184
- const LoadingContainer = styled.div`
185
- border: 1px solid ${(props) => props.theme.colors.grey3};
186
- display: grid;
187
- grid-template-columns: 1fr;
188
- min-width: 100px;
189
- height: 100px;
190
- align-items: center;
191
- justify-items: center;
192
- background: #fff;
193
- `
174
+ const dropdownAttrs = {
175
+ containerWidth: Number,
176
+ }
177
+ const DropdownContainer = styled('div', dropdownAttrs)`
178
+ z-index: 99;
179
+ position: absolute;
180
+ display: grid;
181
+ grid-template-columns: auto auto;
182
+ `
194
183
 
195
- const OptionsContainerAttrs = { textWrap: Boolean }
196
- const OptionsContainer = styled('div', OptionsContainerAttrs)`
197
- border: 1px solid ${(props) => props.theme.colors.grey3};
198
- display: grid;
199
- grid-template-columns: 1fr;
200
- ${(props) => props.textWrap ? 'width: 220px' : 'width: max-content' };
201
- border-radius: 4px;
202
- background-color: #fff;
203
- max-height: 220px;
204
- overflow: auto;
205
- height: max-content;
206
- ${(props) => props.textWrap ? 'white-space: normal' : 'white-space: nowrap'};
207
- `
184
+ const LoadingContainer = styled.div`
185
+ border: 1px solid ${(props) => props.theme.colors.grey3};
186
+ display: grid;
187
+ grid-template-columns: 1fr;
188
+ min-width: 100px;
189
+ height: 100px;
190
+ align-items: center;
191
+ justify-items: center;
192
+ background: #fff;
193
+ `
208
194
 
209
- const optionAttrs = { isDisabled: Boolean }
210
- const OptionItem = styled('div', optionAttrs)`
211
- padding: 12px;
212
- cursor: ${(props) => (props.isDisabled ? 'not-allowed' : 'pointer')};
213
- font-size: 13px;
214
- position: relative;
215
- ${(props) => (props.isDisabled ? `background-color: ${ props.theme.colors.grey5 }!important` : '')};
216
- ${(props) => (props.isDisabled ? `color: ${ props.theme.colors.grey2 }` : '')};
195
+ const OptionsContainerAttrs = { textWrap: Boolean }
196
+ const OptionsContainer = styled('div', OptionsContainerAttrs)`
197
+ border: 1px solid ${(props) => props.theme.colors.grey3};
198
+ display: grid;
199
+ grid-template-columns: 1fr;
200
+ ${(props) => (props.textWrap ? 'width: 220px' : 'width: max-content')};
201
+ border-radius: 4px;
202
+ background-color: #fff;
203
+ max-height: 220px;
204
+ overflow: auto;
205
+ height: max-content;
206
+ ${(props) =>
207
+ props.textWrap ? 'white-space: normal' : 'white-space: nowrap'};
208
+ `
217
209
 
218
- &:hover {
219
- background-color: #ebeef4;
220
- }
210
+ const optionAttrs = { isDisabled: Boolean }
211
+ const OptionItem = styled('div', optionAttrs)`
212
+ padding: 12px;
213
+ cursor: ${(props) => (props.isDisabled ? 'not-allowed' : 'pointer')};
214
+ font-size: 13px;
215
+ position: relative;
216
+ ${(props) =>
217
+ props.isDisabled
218
+ ? `background-color: ${props.theme.colors.grey5}!important`
219
+ : ''};
220
+ ${(props) =>
221
+ props.isDisabled ? `color: ${props.theme.colors.grey2}` : ''};
221
222
 
222
- &:focus-visible {
223
- outline: none;
224
- background-color: #ebeef4;
225
- }
226
- `
227
- const OptionChild = styled.div`
228
- padding: 12px;
229
- cursor: pointer;
230
- font-size: 13px;
231
- position: relative;
223
+ &:hover {
224
+ background-color: #ebeef4;
225
+ }
232
226
 
233
- &:hover {
234
- background-color: #ebeef4;
235
- }
227
+ &:focus-visible {
228
+ outline: none;
229
+ background-color: #ebeef4;
230
+ }
231
+ `
232
+ const OptionChild = styled.div`
233
+ padding: 12px;
234
+ cursor: pointer;
235
+ font-size: 13px;
236
+ position: relative;
236
237
 
237
- &:focus-visible {
238
- outline: none;
239
- background-color: #ebeef4;
240
- }
241
- `
238
+ &:hover {
239
+ background-color: #ebeef4;
240
+ }
241
+
242
+ &:focus-visible {
243
+ outline: none;
244
+ background-color: #ebeef4;
245
+ }
246
+ `
242
247
 
243
- const arrowAttrs = { hasChildren: Boolean }
244
- const ArrowLeft = styled('span', arrowAttrs)`
245
- border: solid #9f9f9f;
246
- border-width: 0 1.5px 1.5px 0;
247
- display: inline-block;
248
- padding: 3px;
249
- margin-bottom: 1px;
250
- transform: rotate(135deg);
251
- margin-right: 3px;
252
- visibility: ${(props) => (props.hasChildren ? 'visible' : 'hidden')};
253
- `
248
+ const arrowAttrs = { hasChildren: Boolean }
249
+ const ArrowLeft = styled('span', arrowAttrs)`
250
+ border: solid #9f9f9f;
251
+ border-width: 0 1.5px 1.5px 0;
252
+ display: inline-block;
253
+ padding: 3px;
254
+ margin-bottom: 1px;
255
+ transform: rotate(135deg);
256
+ margin-right: 3px;
257
+ visibility: ${(props) => (props.hasChildren ? 'visible' : 'hidden')};
258
+ `
254
259
 
255
- const childAttrs = { isOpen: Boolean }
256
- const ChildrenContainer = styled('div', childAttrs)`
257
- border: ${(props) =>
258
- props.isOpen ? '1px solid' + props.theme.colors.grey3 : 'none'};
259
- display: grid;
260
- grid-template-columns: 1fr;
261
- min-width: 200px;
262
- max-width: 200px;
263
- white-space: normal;
264
- width: max-content;
265
- border-radius: 4px;
266
- background-color: #fff;
267
- margin-right: -1px;
268
- height: max-content;
269
- max-height: 200px;
270
- overflow: auto;
271
- position: absolute;
272
- top: 0;
273
- right: 100%;
274
- `
260
+ const childAttrs = { isOpen: Boolean }
261
+ const ChildrenContainer = styled('div', childAttrs)`
262
+ border: ${(props) =>
263
+ props.isOpen ? '1px solid' + props.theme.colors.grey3 : 'none'};
264
+ display: grid;
265
+ grid-template-columns: 1fr;
266
+ min-width: 200px;
267
+ max-width: 200px;
268
+ white-space: normal;
269
+ width: max-content;
270
+ border-radius: 4px;
271
+ background-color: #fff;
272
+ margin-right: -1px;
273
+ height: max-content;
274
+ max-height: 200px;
275
+ overflow: auto;
276
+ position: absolute;
277
+ top: 0;
278
+ right: 100%;
279
+ `
275
280
 
276
- export default {
277
- name: 'three-dots',
278
- components: {
279
- PageContainer,
280
- ButtonContainer,
281
- DotItem,
282
- OptionsContainer,
283
- OptionItem,
284
- ChildrenContainer,
285
- OptionChild,
286
- ArrowLeft,
287
- DropdownContainer,
288
- Spinner,
289
- LoadingContainer
290
- },
291
- props: {
292
- options: {
293
- required: true
281
+ export default {
282
+ name: 'ThreeDots',
283
+ components: {
284
+ PageContainer,
285
+ ButtonContainer,
286
+ DotItem,
287
+ OptionsContainer,
288
+ OptionItem,
289
+ ChildrenContainer,
290
+ OptionChild,
291
+ ArrowLeft,
292
+ DropdownContainer,
293
+ Spinner,
294
+ LoadingContainer,
294
295
  },
295
- isLoading: {
296
- required: false,
297
- default: false
296
+ props: {
297
+ options: {
298
+ required: true,
299
+ },
300
+ isLoading: {
301
+ required: false,
302
+ default: false,
303
+ },
304
+ textWrap: {
305
+ required: false,
306
+ default: true,
307
+ },
298
308
  },
299
- textWrap: {
300
- required: false,
301
- default: true
302
- }
303
- },
304
- data() {
305
- return {
306
- isOpen: false,
307
- hoverItem: null,
308
- childOpen: null,
309
- containerWidth: 16
310
- }
311
- },
312
- methods: {
313
- toggleButton() {
314
- this.isOpen = !this.isOpen
315
-
316
- if (this.isOpen) {
317
- this.setContextMenuPosition()
318
- window.addEventListener('resize', this.toggleButton)
319
- document.addEventListener('click', this.clickOutside)
320
- } else {
321
- window.removeEventListener('resize', this.toggleButton)
322
- document.removeEventListener('click', this.clickOutside)
309
+ data() {
310
+ return {
311
+ isOpen: false,
312
+ hoverItem: null,
313
+ childOpen: null,
314
+ containerWidth: 16,
323
315
  }
324
316
  },
325
- setContextMenuPosition() {
326
- const contextMenu = this.$refs.dropdownContainer.$el
327
- const button = this.$refs.pageContainer.$el
328
- const rectButton = button.getBoundingClientRect()
329
- const relativeParent = this.findRelativeParent(contextMenu)
330
- const rectRelativeParent = relativeParent.getBoundingClientRect()
317
+ methods: {
318
+ toggleButton() {
319
+ this.isOpen = !this.isOpen
331
320
 
332
- const positionArray = this.determineElementQuarter(button, rectButton)
333
- contextMenu.style.transform = ''
334
- if (positionArray.includes('left')) {
335
- contextMenu.style.left =
336
- rectButton.right - rectRelativeParent.left + 5 + 'px'
337
- } else {
338
- contextMenu.style.left =
339
- rectButton.left - rectRelativeParent.left - 5 + 'px'
340
- contextMenu.style.transform = 'translateX(-100%)'
341
- }
342
- if (positionArray.includes('top')) {
343
- contextMenu.style.top = rectButton.top - rectRelativeParent.top + 'px'
344
- } else {
345
- contextMenu.style.top =
346
- rectButton.bottom - rectRelativeParent.top + 'px'
347
- contextMenu.style.transform += ' translateY(-100%)'
348
- }
349
- },
350
- findRelativeParent(element) {
351
- while (element.parentElement) {
352
- if (
353
- window.getComputedStyle(element.parentElement).position ===
354
- 'relative' ||
355
- window.getComputedStyle(element.parentElement).position === 'absolute'
356
- ) {
357
- return element.parentElement
321
+ if (this.isOpen) {
322
+ this.setContextMenuPosition()
323
+ window.addEventListener('resize', this.toggleButton)
324
+ document.addEventListener('click', this.clickOutside)
325
+ } else {
326
+ window.removeEventListener('resize', this.toggleButton)
327
+ document.removeEventListener('click', this.clickOutside)
358
328
  }
359
- element = element.parentElement
360
- }
361
- return null
362
- },
363
- determineElementQuarter(element, rect) {
364
- const viewportWidth = window.innerWidth
365
- const viewportHeight = window.innerHeight
329
+ },
330
+ setContextMenuPosition() {
331
+ const contextMenu = this.$refs.dropdownContainer.$el
332
+ const button = this.$refs.pageContainer.$el
333
+ const rectButton = button.getBoundingClientRect()
334
+ const relativeParent = this.findRelativeParent(contextMenu)
335
+ const rectRelativeParent = relativeParent.getBoundingClientRect()
336
+
337
+ const positionArray = this.determineElementQuarter(button, rectButton)
338
+ contextMenu.style.transform = ''
339
+ if (positionArray.includes('left')) {
340
+ contextMenu.style.left =
341
+ rectButton.right - rectRelativeParent.left + 5 + 'px'
342
+ } else {
343
+ contextMenu.style.left =
344
+ rectButton.left - rectRelativeParent.left - 5 + 'px'
345
+ contextMenu.style.transform = 'translateX(-100%)'
346
+ }
347
+ if (positionArray.includes('top')) {
348
+ contextMenu.style.top = rectButton.top - rectRelativeParent.top + 'px'
349
+ } else {
350
+ contextMenu.style.top =
351
+ rectButton.bottom - rectRelativeParent.top + 'px'
352
+ contextMenu.style.transform += ' translateY(-100%)'
353
+ }
354
+ },
355
+ findRelativeParent(element) {
356
+ while (element.parentElement) {
357
+ if (
358
+ window.getComputedStyle(element.parentElement).position ===
359
+ 'relative' ||
360
+ window.getComputedStyle(element.parentElement).position ===
361
+ 'absolute'
362
+ ) {
363
+ return element.parentElement
364
+ }
365
+ element = element.parentElement
366
+ }
367
+ return null
368
+ },
369
+ determineElementQuarter(element, rect) {
370
+ const viewportWidth = window.innerWidth
371
+ const viewportHeight = window.innerHeight
366
372
 
367
- const horizontalMidpoint = viewportWidth / 2
368
- const verticalMidpoint = viewportHeight / 2
373
+ const horizontalMidpoint = viewportWidth / 2
374
+ const verticalMidpoint = viewportHeight / 2
369
375
 
370
- const isLeft = rect.left + rect.width / 2 < horizontalMidpoint
371
- const isTop = rect.top + rect.height / 2 < verticalMidpoint
376
+ const isLeft = rect.left + rect.width / 2 < horizontalMidpoint
377
+ const isTop = rect.top + rect.height / 2 < verticalMidpoint
372
378
 
373
- if (isLeft && isTop) {
374
- return ['left', 'top']
375
- } else if (isLeft && !isTop) {
376
- return ['left', 'bottom']
377
- } else if (!isLeft && isTop) {
378
- return ['right', 'top']
379
- } else {
380
- return ['right', 'bottom']
381
- }
382
- },
383
- hasChildren(item) {
384
- return !!item.children && !!item.children.length
385
- },
386
- onItemHover({ index, item }) {
387
- this.hoverItem = item.children && item.children.length ? index : null
388
- this.childOpen =
389
- item.children && item.children.length ? item.children : null
390
- },
391
- onSelect({ item, hasChildren }) {
392
- if (hasChildren || item.disabled) {
393
- this.$emit('on-click', item)
394
- return
395
- }
396
- this.$emit('on-select', item)
397
- this.isOpen = false
379
+ if (isLeft && isTop) {
380
+ return ['left', 'top']
381
+ } else if (isLeft && !isTop) {
382
+ return ['left', 'bottom']
383
+ } else if (!isLeft && isTop) {
384
+ return ['right', 'top']
385
+ } else {
386
+ return ['right', 'bottom']
387
+ }
388
+ },
389
+ hasChildren(item) {
390
+ return !!item.children && !!item.children.length
391
+ },
392
+ onItemHover({ index, item }) {
393
+ this.hoverItem = item.children && item.children.length ? index : null
394
+ this.childOpen =
395
+ item.children && item.children.length ? item.children : null
396
+ },
397
+ onSelect({ item, hasChildren }) {
398
+ if (hasChildren || item.disabled) {
399
+ this.$emit('on-click', item)
400
+ return
401
+ }
402
+ this.$emit('on-select', item)
403
+ this.isOpen = false
404
+ },
405
+ clickOutside(event) {
406
+ if (this.$el.contains(event.target) || !this.isOpen) {
407
+ return
408
+ }
409
+ this.toggleButton()
410
+ },
398
411
  },
399
- clickOutside(event) {
400
- if (this.$el.contains(event.target) || !this.isOpen) {
401
- return
402
- }
403
- this.toggleButton()
404
- }
405
412
  }
406
- }
407
413
  </script>