Created Folder For SearchInput And Changed Paths

This commit is contained in:
Moriz Wahl 2019-11-16 20:59:51 +01:00
parent 79596ab375
commit 6b68e18be6

View File

@ -36,48 +36,29 @@
@input.native="handleInput" @input.native="handleInput"
@click.capture.native="isOpen = true" @click.capture.native="isOpen = true"
> >
<template slot="option" slot-scope="{ option }"> <template slot="option" slot-scope="{ option }">
<ds-flex v-if="option.heading" class="search-option-heading"> <ds-flex>
<ds-flex-item> <ds-flex-item class="search-option-label">
<ds-heading soft size="h5">{{ option.heading }}</ds-heading> <ds-text>{{ option.label | truncate(70) }}</ds-text>
</ds-flex-item> </ds-flex-item>
</ds-flex> <ds-flex-item class="search-option-meta" width="280px">
<ds-flex v-else-if="option.searchType === 'Users'"> <ds-flex>
<ds-flex-item class="search-option"> <ds-flex-item>
<ds-avatar class="avatar" name="option.name" image="option.avatar" /> <ds-text size="small" color="softer" class="search-meta">
<div> <span style="text-align: right;">
<ds-text class="userinfo"> <b>{{ option.commentsCount }}</b>
<b class="username">{{ option.label | truncate(70) }}</b> <base-icon name="comments" />
</ds-text> </span>
</div> <span style="width: 36px; display: inline-block; text-align: right;">
<ds-text align="left" size="small" color="soft"> <b>{{ option.shoutedCount }}</b>
@{{ option.slug | truncate(70) }} <base-icon name="bullhorn" />
</ds-text> </span>
</ds-flex-item> </ds-text>
</ds-flex> </ds-flex-item>
<ds-flex v-else>
<ds-flex-item class="search-option-label">
<ds-text>{{ option.label | truncate(70) }}</ds-text>
</ds-flex-item>
<ds-flex-item class="search-option-meta" width="280px">
<ds-flex>
<ds-flex-item>
<ds-text size="small" color="softer" class="search-meta">
<span style="text-align: right;">
<b>{{ option.commentsCount }}</b>
<base-icon name="comments" />
</span>
<span style="width: 36px; display: inline-block; text-align: right;">
<b>{{ option.shoutedCount }}</b>
<base-icon name="bullhorn" />
</span>
</ds-text>
</ds-flex-item>
<ds-flex-item> <ds-flex-item>
<ds-text size="small" color="softer" align="right"> <ds-text size="small" color="softer" align="right">
{{ option.author.name | truncate(32) }} - {{ option.author.name | truncate(32) }} -
{{ option.createdAt }} {{ option.createdAt | dateTime('dd.MM.yyyy') }}
<!-- removed | dateTime('dd.MM.yyyy') -->
</ds-text> </ds-text>
</ds-flex-item> </ds-flex-item>
</ds-flex> </ds-flex>
@ -91,236 +72,197 @@
</template> </template>
<script> <script>
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
export default { export default {
name: 'SearchInput', name: 'SearchInput',
props: { props: {
id: { id: {
type: String, type: String,
default: 'nav-search', default: 'nav-search',
}, },
value: { value: {
type: String, type: String,
default: '', default: '',
}, },
results: { results: {
type: Array, type: Array,
default: () => [], default: () => [],
}, },
delay: { delay: {
type: Number, type: Number,
default: 300, default: 300,
}, },
pending: { pending: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
}, },
data() { data() {
return { return {
searchProcess: null, searchProcess: null,
isOpen: false, isOpen: false,
lastSearchTerm: '', lastSearchTerm: '',
unprocessedSearchInput: '', unprocessedSearchInput: '',
searchValue: '', searchValue: '',
} }
}, },
computed: { computed: {
// #: Unused at the moment? // #: Unused at the moment?
isActive() { isActive() {
return !isEmpty(this.lastSearchTerm) return !isEmpty(this.lastSearchTerm)
}, },
emptyText() { emptyText() {
return this.isActive && !this.pending ? this.$t('search.failed') : this.$t('search.hint') return this.isActive && !this.pending ? this.$t('search.failed') : this.$t('search.hint')
}, },
}, },
methods: { methods: {
async query(value) { async query(value) {
if (isEmpty(value) || value.length < 3) { if (isEmpty(value) || value.length < 3) {
this.clear() this.clear()
return return
} }
this.$emit('search', value) this.$emit('search', value)
}, },
handleInput(e) { handleInput(e) {
clearTimeout(this.searchProcess) clearTimeout(this.searchProcess)
const value = e.target ? e.target.value.trim() : '' const value = e.target ? e.target.value.trim() : ''
this.isOpen = true this.isOpen = true
this.unprocessedSearchInput = value this.unprocessedSearchInput = value
this.searchProcess = setTimeout(() => { this.searchProcess = setTimeout(() => {
this.lastSearchTerm = value this.lastSearchTerm = value
this.query(value) this.query(value)
}, this.delay) }, this.delay)
}, },
onSelect(item) { onSelect(item) {
this.isOpen = false this.isOpen = false
console.log('onSelect', item) this.$emit('select', item)
this.$emit('select', item) this.$nextTick(() => {
this.$nextTick(() => { this.searchValue = this.lastSearchTerm
this.searchValue = this.lastSearchTerm })
}) },
}, onFocus(e) {
onFocus(e) { clearTimeout(this.searchProcess)
clearTimeout(this.searchProcess) this.isOpen = true
this.isOpen = true },
}, onBlur(e) {
onBlur(e) { this.searchValue = this.lastSearchTerm
this.searchValue = this.lastSearchTerm // this.$nextTick(() => {
// this.$nextTick(() => { // this.searchValue = this.lastSearchTerm
// this.searchValue = this.lastSearchTerm // })
// }) this.isOpen = false
this.isOpen = false clearTimeout(this.searchProcess)
clearTimeout(this.searchProcess) },
}, onDelete(e) {
onDelete(e) { clearTimeout(this.searchProcess)
clearTimeout(this.searchProcess) const value = e.target ? e.target.value.trim() : ''
const value = e.target ? e.target.value.trim() : '' if (isEmpty(value)) {
if (isEmpty(value)) { this.clear()
this.clear() } else {
} else { this.handleInput(e)
this.handleInput(e) }
} },
}, /**
/** * TODO: on enter we should go to a dedicated seach page!?
* TODO: on enter we should go to a dedicated search page!? */
*/ onEnter(e) {
onEnter(e) { // this.isOpen = false
// this.isOpen = false clearTimeout(this.searchProcess)
clearTimeout(this.searchProcess) if (!this.pending) {
if (!this.pending) { // this.lastSearchTerm = this.unprocessedSearchInput
// this.lastSearchTerm = this.unprocessedSearchInput this.query(this.unprocessedSearchInput)
this.query(this.unprocessedSearchInput) }
} },
}, clear() {
clear() { this.$emit('clear')
this.$emit('clear') clearTimeout(this.searchProcess)
clearTimeout(this.searchProcess) this.isOpen = false
this.isOpen = false this.unprocessedSearchInput = ''
this.unprocessedSearchInput = '' this.lastSearchTerm = ''
this.lastSearchTerm = '' this.searchValue = ''
this.searchValue = '' },
}, },
}, }
}
</script> </script>
<style lang="scss"> <style lang="scss">
.search { .search {
display: flex; display: flex;
align-self: center; align-self: center;
width: 100%; width: 100%;
position: relative; position: relative;
$padding-left: $space-x-small; $padding-left: $space-x-small;
.search-option-label { .search-option-label {
align-self: center; align-self: center;
padding-left: $padding-left; padding-left: $padding-left;
} }
.search-option-meta { .search-option-meta {
align-self: center; align-self: center;
.ds-flex { .ds-flex {
flex-direction: column; flex-direction: column;
} }
} }
&, &,
.ds-select-dropdown { .ds-select-dropdown {
transition: box-shadow 100ms; transition: box-shadow 100ms;
max-height: 70vh; max-height: 70vh;
} }
&.is-open { &.is-open {
.ds-select-dropdown { .ds-select-dropdown {
box-shadow: $box-shadow-x-large; box-shadow: $box-shadow-x-large;
} }
} }
.ds-select-dropdown-message { .ds-select-dropdown-message {
opacity: 0.5; opacity: 0.5;
padding-left: $padding-left; padding-left: $padding-left;
} }
.search-clear-btn { .search-clear-btn {
right: 0; right: 0;
z-index: 10; z-index: 10;
position: absolute; position: absolute;
height: 100%; height: 100%;
width: 36px; width: 36px;
cursor: pointer; cursor: pointer;
} }
.search-meta { .search-meta {
float: right; float: right;
padding-top: 2px; padding-top: 2px;
white-space: nowrap; white-space: nowrap;
word-wrap: none; word-wrap: none;
.base-icon { .base-icon {
vertical-align: sub; vertical-align: sub;
} }
} }
.ds-select { .ds-select {
z-index: $z-index-dropdown + 1; z-index: $z-index-dropdown + 1;
} }
.ds-select-option-hover { .ds-select-option-hover {
.ds-text-size-small, .ds-text-size-small,
.ds-text-size-small-x { .ds-text-size-small-x {
color: $text-color-soft; color: $text-color-soft;
} }
} }
.field { .field {
width: 100%; width: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.control { .control {
width: 100%; width: 100%;
} }
.search-option-heading { }
font-weight: bold;
cursor: default;
background-color:white;
padding: 0;
}
.avatar {
display: inline-block;
float: left;
margin-right: 4px;
height: 100%;
vertical-align: middle;
}
.userinfo {
display: flex;
align-items: center;
> .ds-text {
display: flex;
align-items: center;
margin-left: $space-xx-small;
}
}
.user {
white-space: nowrap;
position: relative;
display: flex;
align-items: center;
&:hover,
&.active {
z-index: 999;
}
}
.username {
color: #17b53f;
}
}
</style> </style>