@eturnity/eturnity_reusable_components 1.2.34-3d-master.3 → 1.2.34-3d-master.7

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.2.34-3d-master.3",
3
+ "version": "1.2.34-3d-master.7",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
package/src/App.vue CHANGED
@@ -3,7 +3,7 @@
3
3
  <page-container>
4
4
  <br />
5
5
 
6
- <modal v-if="false" backdrop="dark" :isLoading="false" :isOpen="true">
6
+ <modal v-if="true" backdrop="dark" :isLoading="false" :isOpen="true">
7
7
 
8
8
  <div :style="{padding:'50px'}">
9
9
 
@@ -53,18 +53,16 @@
53
53
  alignItems="vertical"
54
54
  colorMode="dark"
55
55
  @input-change="value=$event"
56
+ @search-change="searchValue=$event"
56
57
  >
57
58
  <template #selector="{selectedValue}">
58
59
  value selected: {{selectedValue}}
59
60
  </template>
60
61
  <template #dropdown>
61
- <Option value="1">value one</Option>
62
- <Option value="2">value two</Option>
63
- <Option value="3">value three</Option>
64
- <Option value="4">value four</Option>
62
+ <Option v-for="opt in filteredOptionList" :key="opt.id" :value="opt.val">{{ opt.lookFor }}</Option>
65
63
  </template>
66
64
  </Select>
67
-
65
+ {{filteredOptionList }}
68
66
  </div>
69
67
  </modal>
70
68
  <iconCollection/>
@@ -110,7 +108,19 @@ export default {
110
108
  return {
111
109
  value:42,
112
110
  value2:42,
113
- companyName:"toto"
111
+ companyName:"toto",
112
+ optionList:[
113
+ {id:'a',val:'A',lookFor:'babababa'},
114
+ {id:'b',val:'B',lookFor:'abab'},
115
+ {id:'c',val:'C',lookFor:'ccc'},
116
+ {id:'d',val:'D',lookFor:'ddd'}
117
+ ],
118
+ searchValue:""
119
+ }
120
+ },
121
+ computed:{
122
+ filteredOptionList(){
123
+ return this.optionList.filter(opt=>opt.lookFor.includes(this.searchValue))
114
124
  }
115
125
  },
116
126
  methods: {
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" shape-rendering="geometricPrecision" text-rendering="geometricPrecision"><path d="M3.32 2.668c-.472.22-.937.707-1.09 1.142-.17.478-.163 40.686.006 41.27.08.277.228.512.485.768.852.852 2.09.819 2.901-.079.584-.646.542 1.105.519-21.492L6.12 3.96l-.233-.42c-.527-.951-1.609-1.319-2.567-.872m5.5 9.512.02 9.38H36.2l.02-9.38.021-9.38H8.799l.021 9.38m23.74.02v5.48h-20V6.72h20v5.48M13.016 29.362c-2.807 1.987-5.093 3.643-5.08 3.678.026.073 10.119 8.16 10.182 8.16.022 0 .049-1.125.061-2.5l.021-2.5 14.02-.02 14.02-.02v-5.52H18.162l-.021-2.446-.021-2.445-5.104 3.613" fill-rule="evenodd"/></svg>
@@ -1,7 +1,6 @@
1
1
  <template>
2
2
  <Container
3
3
  :selectWidth="selectWidth"
4
- v-click-outside="closeDropdown"
5
4
  @mouseenter="mouseEnterHandler"
6
5
  @mouseleave="mouseLeaveHandler"
7
6
  >
@@ -23,25 +22,44 @@
23
22
  </label-wrapper>
24
23
  <div>
25
24
  <selectButton
26
- @click="toggleDropdown"
25
+ ref="select"
26
+ @click="toggleDropdown"
27
27
  :isActive="isActive"
28
+ :selectHeight="selectHeight"
28
29
  :bgColor="buttonBgColor || colorMode=='dark'?'transparentBlack1':'white'"
29
30
  :fontColor="buttonFontColor || colorMode=='dark'?'white':'black'"
30
-
31
+ @keydown.native="onKeyDown"
31
32
  >
32
- <slot name="selector" :selectedValue="selectedValue"></slot>
33
- <Caret :isUp="isDropdownOpen">
33
+ <inputText
34
+ v-if="isSearchBarVisible"
35
+ ref="searchInput"
36
+ tabindex="0"
37
+ :noBorder="true"
38
+ :inputHeight="selectHeight"
39
+ backgroundColor="transparent"
40
+ :fontColor="buttonFontColor || colorMode=='dark'?'white':'black'"
41
+ :value="textSearch"
42
+ @keydown.stop="onKeyDown"
43
+ @input-change="searchChange" />
44
+ <div v-else>
45
+ <slot name="selector" :selectedValue="selectedValue"></slot>
46
+ </div>
47
+ <Caret :isUp="isDropdownOpen" @click.stop="isSearchBarVisible ? closeDropdown() : toggleDropdown() " >
34
48
  <icon name="arrow_up" size="12px" :color="caretColor || colorMode=='dark'?'white':'transparentBlack1'"/>
35
49
  </Caret>
36
50
  </selectButton>
37
51
  <DropdownWrapper>
38
52
  <selectDropdown
39
- v-if="isDropdownOpen"
53
+ ref="dropdown"
54
+ v-show="isDropdownOpen"
55
+ :hoveredIndex="hoveredIndex"
40
56
  :isActive="isActive"
41
57
  :optionWidth="optionWidth"
42
58
  :bgColor="dropdownBgColor || colorMode=='dark'?'black':'white'"
43
59
  :fontColor="dropdownFontColor || colorMode=='dark'?'white':'black'"
44
- @option-selected="optionSelected">
60
+ :selectedValue="selectedValue"
61
+ @option-selected="optionSelected"
62
+ @option-hovered="optionHovered">
45
63
  <slot name="dropdown"></slot>
46
64
  </selectDropdown>
47
65
  </DropdownWrapper>
@@ -73,7 +91,8 @@
73
91
  import styled from 'vue-styled-components'
74
92
  import InfoText from '../../infoText'
75
93
  import icon from '../../icon'
76
-
94
+ import inputText from '../inputText'
95
+
77
96
  const caretAttrs={isUp:Boolean}
78
97
  const Caret=styled('div', caretAttrs)`
79
98
  position:absolute;
@@ -105,23 +124,25 @@ const LabelWrapper = styled.div`
105
124
  align-items: center;
106
125
  justify-content: start;
107
126
  `
108
- const selectButtonAttrs={bgColor:String,fontColor:String,isActive:Boolean}
127
+ const selectButtonAttrs={bgColor:String,fontColor:String,isActive:Boolean,selectHeight:String}
109
128
  const selectButton = styled('div',selectButtonAttrs)`
110
129
  position:relative;
111
130
  box-sizing: border-box;
112
131
  border:1px solid red;
113
132
  border-radius:4px;
114
- padding:10px 15px;
133
+ padding:0px 10px;
115
134
  text-align:left;
116
135
  border-radius:4px;
117
136
  min-height:36px;
118
- display: flex;
137
+ display: grid;
138
+ grid-template-columns:auto 40px;
119
139
  align-items: center;
140
+ max-height:${props=>props.selectHeight};
120
141
  border:1px solid ${(props)=>props.theme.colors.grey4}
121
142
  background-color:${(props) => props.theme.colors[props.bgColor]?props.theme.colors[props.bgColor]:props.bgColor};
122
143
  color:${(props) => props.theme.colors[props.fontColor]?props.theme.colors[props.fontColor]:props.fontColor};
123
144
  `
124
- const selectDropdownAttrs={bgColor:String,fontColor:String,selectWidth: String, optionWidth: String}
145
+ const selectDropdownAttrs={bgColor:String,fontColor:String,selectWidth: String, optionWidth: String,hoveredIndex:Number,selectedValue:Number | String}
125
146
  const selectDropdown = styled('div',selectDropdownAttrs)`
126
147
  box-sizing: border-box;
127
148
  z-index:${props=>props.isActive?'2':'1'};
@@ -140,6 +161,12 @@ const selectDropdown = styled('div',selectDropdownAttrs)`
140
161
  color:${(props) => props.theme.colors[props.fontColor]?props.theme.colors[props.fontColor]:props.fontColor};
141
162
  max-height:300px;
142
163
  overflow-y:auto;
164
+ & [data-value="${props=>props.selectedValue}"]{
165
+ backdrop-filter: brightness(1.4);
166
+ }
167
+ &>div:nth-child(${props=>props.hoveredIndex}){
168
+ backdrop-filter: brightness(1.2);
169
+ }
143
170
  `
144
171
  const DropdownWrapper=styled('div')`
145
172
  position:relative;
@@ -178,6 +205,10 @@ const InputWrapper = styled('div', inputAttrs)`
178
205
  required: false,
179
206
  default: null
180
207
  },
208
+ selectHeight: {
209
+ required: false,
210
+ default: null
211
+ },
181
212
  optionWidth: {
182
213
  required: false,
183
214
  default: null
@@ -211,6 +242,14 @@ const InputWrapper = styled('div', inputAttrs)`
211
242
  colorMode:{
212
243
  required:false,
213
244
  default:'light'
245
+ },
246
+ isSearchable:{
247
+ required:false,
248
+ default:true
249
+ },
250
+ isAutoSearch:{
251
+ required:false,
252
+ default:true
214
253
  }
215
254
  },
216
255
 
@@ -224,7 +263,8 @@ const InputWrapper = styled('div', inputAttrs)`
224
263
  InputWrapper,
225
264
  DropdownWrapper,
226
265
  icon,
227
- Caret
266
+ Caret,
267
+ inputText
228
268
  },
229
269
 
230
270
  data() {
@@ -232,9 +272,11 @@ const InputWrapper = styled('div', inputAttrs)`
232
272
  selectedValue: null,
233
273
  isDropdownOpen:false,
234
274
  isActive:false,
275
+ textSearch:"",
276
+ hoveredIndex:0,
235
277
  }
236
278
  },
237
- created(){
279
+ mounted(){
238
280
  this.selectedValue=this.value
239
281
  },
240
282
  methods:{
@@ -244,13 +286,25 @@ const InputWrapper = styled('div', inputAttrs)`
244
286
  blur(){
245
287
  this.isActive=false
246
288
  },
247
- toggleDropdown(){
248
- this.focus()
289
+ toggleDropdown(e){
290
+ if(this.isSearchBarVisible){return}
249
291
  this.isDropdownOpen=!this.isDropdownOpen
292
+ if (this.isDropdownOpen) {
293
+ setTimeout(()=>document.addEventListener('click', this.clickOutside),10)
294
+ } else {
295
+ document.removeEventListener('click', this.clickOutside)
296
+ }
297
+
298
+ },
299
+ openDropdown(){
300
+ this.focus()
301
+ this.isDropdownOpen=true
302
+ setTimeout(()=>document.addEventListener('click', this.clickOutside),10)
250
303
  },
251
304
  closeDropdown(){
252
305
  this.blur()
253
306
  this.isDropdownOpen=false
307
+ document.removeEventListener('click', this.clickOutside)
254
308
  },
255
309
  optionSelected(e){
256
310
  this.selectedValue=e
@@ -258,21 +312,74 @@ const InputWrapper = styled('div', inputAttrs)`
258
312
  this.blur()
259
313
  this.$emit('input-change',e)
260
314
  },
315
+ optionHovered(e){
316
+ const optionElement=this.$el.querySelector(`[data-value="${e}"]`)
317
+ if(this.$refs.dropdown){
318
+ this.hoveredIndex=this.$refs.dropdown.$children.map(component=>component.$el).indexOf(optionElement)+1
319
+ }
320
+ },
261
321
  mouseEnterHandler(){
262
- this.focus()
263
322
  if(this.hoverDropdown){
323
+ this.focus()
264
324
  this.isDropdownOpen=true
265
325
  }
266
326
  },
267
327
  mouseLeaveHandler(){
268
- this.blur()
328
+ if(this.hoverDropdown){
329
+ this.blur()
330
+ }
331
+ },
332
+ searchChange(value){
333
+ this.textSearch=value
334
+ this.$emit('search-change',value)
335
+ this.$refs.dropdown.$children.map(component=>component.$el).forEach((el=>{
336
+ if(!el.textContent.toLowerCase().includes(value.toLowerCase())){el.style.display='none'}else{el.style.display='inherit'}
337
+ }))
338
+ },
339
+ clickOutside(event) {
340
+ if (this.$el==event.target || this.$el.contains(event.target)) {
341
+ return
342
+ }
343
+ this.closeDropdown()
269
344
  },
345
+ onKeyDown(e){
346
+ if(e.key=='ArrowDown'){
347
+ this.onArrowPress(1)
348
+ } else if(e.key=='ArrowUp'){
349
+ this.onArrowPress(-1)
350
+ } else if(e.key=='Enter'){
351
+ const optionHoveredComponent=this.$refs.dropdown.$children[(this.hoveredIndex-1+this.optionLength)%this.optionLength]
352
+ this.optionSelected(optionHoveredComponent.$el.dataset.value)
353
+ }
354
+
355
+ },
356
+ onArrowPress(dir){
357
+ this.hoveredIndex=((this.hoveredIndex+dir+this.optionLength-1)%this.optionLength)+1
358
+ const optionHoveredComponent=this.$refs.dropdown.$children[(this.hoveredIndex-1+this.optionLength)%this.optionLength]
359
+ const topPos = optionHoveredComponent.$el.offsetTop;
360
+ this.$refs.dropdown.$el.scrollTop = topPos;
361
+ }
270
362
  },
271
363
  computed: {
364
+ optionLength(){
365
+ if(this.isDropdownOpen){
366
+ return this.$refs.dropdown.$children.length
367
+ }else{
368
+ return 0
369
+ }
370
+ },
371
+ isSearchBarVisible(){
372
+ return this.isSearchable && this.optionLength>=5 && this.isDropdownOpen
373
+ }
272
374
  },
273
375
  watch:{
274
376
  value(val){
275
377
  this.selectedValue=val
378
+ },
379
+ isDropdownOpen(val){
380
+ if(val && this.isSearchable){
381
+ this.$nextTick(()=>{if(this.$refs.searchInput){this.$refs.searchInput.$el.querySelector('input').focus()}})
382
+ }
276
383
  }
277
384
  }
278
385
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <optionContainer :hoveredBgColor="hoveredBgColor || colorMode=='dark'?'#000000':'grey5'" @click="clickHandler">
2
+ <optionContainer :data-value="value" :hoveredBgColor="hoveredBgColor || colorMode=='dark'?'#000000':'grey5'" @click="clickHandler" @mouseover="hoverHandler">
3
3
  <slot></slot>
4
4
  </optionContainer>
5
5
  </template>
@@ -48,6 +48,9 @@
48
48
  methods:{
49
49
  clickHandler(){
50
50
  this.$parent.$emit('option-selected',this.value)
51
+ },
52
+ hoverHandler(){
53
+ this.$parent.$emit('option-hovered',this.value)
51
54
  }
52
55
  },
53
56
  computed: {