parent
6f76624212
commit
e5d1f83ea8
4 changed files with 481 additions and 102 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,60 @@ |
|||||||
|
<template> |
||||||
|
<div class="field__select select" v-bind:class="{ selected: isSelected, active: isOpened }"> |
||||||
|
<div class="select__head" @click="toggleOpened"> |
||||||
|
{{ selectedTitle }} |
||||||
|
</div> |
||||||
|
<div class="select__drop"> |
||||||
|
<div class="select__option" v-for="option in options"> |
||||||
|
<div class="select__title" @click="selectOption(option, $event)">{{ option.title }}</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
export default { |
||||||
|
name: "lil-select", |
||||||
|
props: ["options", "value", "valueKey", "placeholder"], |
||||||
|
data() { |
||||||
|
return { |
||||||
|
key: this.valueKey ? this.valueKey : 'value', |
||||||
|
isOpened: false, |
||||||
|
} |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
clickListener() { |
||||||
|
this.isOpened = false; |
||||||
|
}, |
||||||
|
toggleOpened(event) { |
||||||
|
event.stopPropagation(); |
||||||
|
this.isOpened = !this.isOpened |
||||||
|
}, |
||||||
|
selectOption(option, event) { |
||||||
|
event.stopPropagation(); |
||||||
|
this.isOpened = !this.isOpened; |
||||||
|
this.$emit('update:value', option); |
||||||
|
} |
||||||
|
}, |
||||||
|
mounted() { |
||||||
|
document.addEventListener("click", this.clickListener); |
||||||
|
}, |
||||||
|
destroyed() { |
||||||
|
document.removeEventListener("click", this.clickListener); |
||||||
|
}, |
||||||
|
computed: { |
||||||
|
isSelected() { |
||||||
|
return this.value && this.value[this.key] ? true : false; |
||||||
|
}, |
||||||
|
selectedTitle() { |
||||||
|
if (this.isSelected) { |
||||||
|
return this.value[this.key]; |
||||||
|
} |
||||||
|
return this.placeholder ? this.placeholder : ''; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<style scoped> |
||||||
|
|
||||||
|
</style> |
||||||
Loading…
Reference in new issue