@eturnity/eturnity_reusable_components 1.0.29 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "1.0.29",
3
+ "version": "1.0.33",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
package/src/App.vue CHANGED
@@ -83,6 +83,20 @@ export default {
83
83
  {
84
84
  name: "Option 3",
85
85
  value: "option_3",
86
+ children: [
87
+ {
88
+ name: "Option 3 Child",
89
+ value: "option_3_child",
90
+ },
91
+ {
92
+ name: "Option 4 Child",
93
+ value: "option_4_child",
94
+ },
95
+ {
96
+ name: "Option 5 Child",
97
+ value: "option_5_child",
98
+ },
99
+ ],
86
100
  },
87
101
  {
88
102
  name: "Option 4",
@@ -133,6 +133,8 @@ const TableContainer = styled.table`
133
133
  }
134
134
 
135
135
  tr {
136
+ position: relative;
137
+
136
138
  &.disabled {
137
139
  cursor: not-allowed;
138
140
  }
@@ -5,26 +5,49 @@
5
5
  <dot-item />
6
6
  <dot-item />
7
7
  </button-container>
8
- <options-container v-if="isOpen">
9
- <option-item
10
- v-for="(item, index) in options"
11
- :key="item.value"
12
- tabindex="0"
13
- @click="onSelect(item.value)"
14
- @keyup.enter="onSelect(item.value)"
15
- @mouseover="onItemHover(index)"
8
+ <dropdown-container v-if="isOpen">
9
+ <children-container
10
+ class="child"
11
+ :isOpen="hoverItem !== null"
12
+ v-if="hoverItem !== null"
16
13
  >
17
- {{ item.name }}
18
- <children-container
19
- class="child"
20
- v-if="item.children && item.children.length && hoverItem === index"
14
+ <option-child
15
+ v-for="child in childOpen"
16
+ :key="child.value"
17
+ @click.stop="
18
+ onSelect({
19
+ item: child,
20
+ hasChildren: hasChildren(child),
21
+ })
22
+ "
23
+ @keyup.enter.stop="
24
+ onSelect({
25
+ item: child,
26
+ hasChildren: hasChildren(child),
27
+ })
28
+ "
21
29
  >
22
- <option-child v-for="child in item.children" :key="child.value">
23
- {{ child.name }}
24
- </option-child>
25
- </children-container>
26
- </option-item>
27
- </options-container>
30
+ {{ child.name }}
31
+ </option-child>
32
+ </children-container>
33
+ <options-container>
34
+ <option-item
35
+ v-for="(item, index) in options"
36
+ :key="item.value"
37
+ tabindex="0"
38
+ @click="onSelect({ item: item, hasChildren: hasChildren(item) })"
39
+ @keyup.enter="
40
+ onSelect({ item: item, hasChildren: hasChildren(item) })
41
+ "
42
+ @mouseover="onItemHover({ index, item })"
43
+ >
44
+ <arrow-left :hasChildren="hasChildren(item)" />
45
+ <span>
46
+ {{ item.name }}
47
+ </span>
48
+ </option-item>
49
+ </options-container>
50
+ </dropdown-container>
28
51
  </page-container>
29
52
  </template>
30
53
 
@@ -37,28 +60,55 @@
37
60
  // />
38
61
  // options to pass:
39
62
  // listOptions: [
40
- // {
41
- // name: "Option 1",
42
- // value: "option_1",
43
- // },
44
- // {
45
- // name: "Option 2",
46
- // value: "option_2",
47
- // },
48
- // {
49
- // name: "Option 3",
50
- // value: "option_3",
51
- // },
52
- // {
53
- // name: "Option 4",
54
- // value: "option_4",
55
- // }
56
- // ],
63
+ // {
64
+ // name: "Option 1",
65
+ // value: "option_1",
66
+ // children: [
67
+ // {
68
+ // name: "Option 1 Child",
69
+ // value: "option_1_child",
70
+ // },
71
+ // {
72
+ // name: "Option 2 Child",
73
+ // value: "option_2_child",
74
+ // },
75
+ // {
76
+ // name: "Option 3 Child",
77
+ // value: "option_3_child",
78
+ // },
79
+ // ],
80
+ // },
81
+ // {
82
+ // name: "Option 2",
83
+ // value: "option_2",
84
+ // },
85
+ // {
86
+ // name: "Option 3",
87
+ // value: "option_3",
88
+ // children: [
89
+ // {
90
+ // name: "Option 3 Child",
91
+ // value: "option_3_child",
92
+ // },
93
+ // {
94
+ // name: "Option 4 Child",
95
+ // value: "option_4_child",
96
+ // },
97
+ // {
98
+ // name: "Option 5 Child",
99
+ // value: "option_5_child",
100
+ // },
101
+ // ],
102
+ // },
103
+ // {
104
+ // name: "Option 4",
105
+ // value: "option_4",
106
+ // },
107
+ // ],
57
108
 
58
109
  import styled from "vue-styled-components"
59
110
 
60
111
  const PageContainer = styled.div`
61
- position: relative;
62
112
  display: grid;
63
113
  align-items: center;
64
114
  `
@@ -89,10 +139,15 @@ const DotItem = styled.div`
89
139
  border-radius: 50%;
90
140
  `
91
141
 
92
- const OptionsContainer = styled.div`
142
+ const DropdownContainer = styled.div`
93
143
  z-index: 99;
94
- position: fixed;
95
- right: 60px;
144
+ position: absolute;
145
+ right: 20px;
146
+ display: grid;
147
+ grid-template-columns: auto auto;
148
+ `
149
+
150
+ const OptionsContainer = styled.div`
96
151
  border: 1px solid ${(props) => props.theme.colors.grey3};
97
152
  display: grid;
98
153
  grid-template-columns: 1fr;
@@ -100,9 +155,9 @@ const OptionsContainer = styled.div`
100
155
  width: max-content;
101
156
  border-radius: 4px;
102
157
  background-color: #fff;
103
- margin-top: 8px;
104
158
  max-height: 220px;
105
159
  overflow: auto;
160
+ height: max-content;
106
161
  `
107
162
 
108
163
  const OptionItem = styled.div`
@@ -136,19 +191,30 @@ const OptionChild = styled.div`
136
191
  }
137
192
  `
138
193
 
139
- const ChildrenContainer = styled.div`
140
- position: fixed;
141
- right: 262px;
142
- border: 1px solid ${(props) => props.theme.colors.grey3};
143
- border-right: none;
194
+ const arrowAttrs = { hasChildren: Boolean }
195
+ const ArrowLeft = styled("span", arrowAttrs)`
196
+ border: solid #9f9f9f;
197
+ border-width: 0 1.5px 1.5px 0;
198
+ display: inline-block;
199
+ padding: 3px;
200
+ margin-bottom: 1px;
201
+ transform: rotate(135deg);
202
+ margin-right: 3px;
203
+ visibility: ${(props) => (props.hasChildren ? "visible" : "hidden")};
204
+ `
205
+
206
+ const childAttrs = { isOpen: Boolean }
207
+ const ChildrenContainer = styled("div", childAttrs)`
208
+ border: ${(props) =>
209
+ props.isOpen ? "1px solid" + props.theme.colors.grey3 : "none"};
144
210
  display: grid;
145
211
  grid-template-columns: 1fr;
146
212
  min-width: 200px;
147
213
  width: max-content;
148
214
  border-radius: 4px;
149
215
  background-color: #fff;
150
- margin-top: 8px;
151
- max-height: 220px;
216
+ margin-right: -1px;
217
+ height: max-content;
152
218
  overflow: auto;
153
219
  `
154
220
 
@@ -162,6 +228,8 @@ export default {
162
228
  OptionItem,
163
229
  ChildrenContainer,
164
230
  OptionChild,
231
+ ArrowLeft,
232
+ DropdownContainer,
165
233
  },
166
234
  props: {
167
235
  options: {
@@ -172,6 +240,7 @@ export default {
172
240
  return {
173
241
  isOpen: false,
174
242
  hoverItem: null,
243
+ childOpen: null,
175
244
  }
176
245
  },
177
246
  methods: {
@@ -184,12 +253,19 @@ export default {
184
253
  document.removeEventListener("click", this.clickOutside)
185
254
  }
186
255
  },
187
- onItemHover(index) {
188
- debugger // eslint-disable-line
189
- this.hoverItem = index
256
+ hasChildren(item) {
257
+ return !!item.children && !!item.children.length
190
258
  },
191
- onSelect(value) {
192
- this.$emit("on-select", value)
259
+ onItemHover({ index, item }) {
260
+ this.hoverItem = item.children && item.children.length ? index : null
261
+ this.childOpen =
262
+ item.children && item.children.length ? item.children : null
263
+ },
264
+ onSelect({ item, hasChildren }) {
265
+ if (hasChildren) {
266
+ return
267
+ }
268
+ this.$emit("on-select", item)
193
269
  this.isOpen = false
194
270
  },
195
271
  clickOutside(event) {