2019-04-08 20:06:22 +00:00
|
|
|
<template>
|
2020-06-11 18:55:39 +00:00
|
|
|
<form @submit.prevent="formSubmit" :class="formClasses" class="flex w-full text-lg text-teal-100">
|
2019-04-10 20:05:52 +00:00
|
|
|
<div class="relative w-full">
|
2020-04-01 10:55:55 +00:00
|
|
|
<button
|
|
|
|
|
ref="submit"
|
|
|
|
|
:class="[btnClasses]"
|
|
|
|
|
class="absolute z-30 h-full hover:text-teal-200"
|
|
|
|
|
type="submit"
|
|
|
|
|
>
|
2020-06-11 18:55:39 +00:00
|
|
|
<svg class="absolute w-4 h-4 vertical-center horizontal-center">
|
2020-04-01 10:55:55 +00:00
|
|
|
<use xlink:href="#search" />
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
2019-04-16 13:34:38 +00:00
|
|
|
<input
|
2020-02-10 19:53:32 +00:00
|
|
|
ref="input"
|
2019-08-23 14:48:16 +00:00
|
|
|
v-model="summoner"
|
2020-02-10 19:53:32 +00:00
|
|
|
@focus="selected = true"
|
2019-11-16 16:50:14 +00:00
|
|
|
:class="[inputClasses]"
|
2020-06-12 14:33:23 +00:00
|
|
|
class="w-full font-bold rounded-none outline-none summoner-input"
|
2020-06-11 18:55:39 +00:00
|
|
|
spellcheck="false"
|
|
|
|
|
type="text"
|
2019-09-03 17:56:41 +00:00
|
|
|
/>
|
2020-02-13 18:49:38 +00:00
|
|
|
<transition name="scale-fade">
|
2020-02-10 19:53:32 +00:00
|
|
|
<SearchFormDropdown v-if="selected" @click-dropdown="clickDropdown = true" />
|
|
|
|
|
</transition>
|
|
|
|
|
|
2020-04-08 12:02:21 +00:00
|
|
|
<div ref="region-dropdown">
|
2019-04-10 20:05:52 +00:00
|
|
|
<div
|
2020-04-08 12:02:21 +00:00
|
|
|
:class="{'mr-12': size === 'xl'}"
|
2020-06-11 18:55:39 +00:00
|
|
|
class="absolute right-0 z-30 flex items-center h-full vertical-center"
|
2019-04-08 20:06:22 +00:00
|
|
|
>
|
2019-04-16 13:34:38 +00:00
|
|
|
<div
|
2020-04-08 12:02:21 +00:00
|
|
|
@click="dropdown = !dropdown"
|
|
|
|
|
:class="[selectRegionClasses]"
|
2020-06-11 18:55:39 +00:00
|
|
|
class="flex items-center transition-all border-2 border-transparent rounded cursor-pointer transition-fast ease-in-quad ease-out-quad hover:text-white"
|
2019-05-16 13:10:00 +00:00
|
|
|
>
|
2020-06-11 18:55:39 +00:00
|
|
|
<span class="font-bold uppercase select-none selected">{{ selectedRegion }}</span>
|
|
|
|
|
<svg class="w-4 h-4 ml-1 -mr-1">
|
2020-04-08 12:02:21 +00:00
|
|
|
<use xlink:href="#caret-down" />
|
2019-10-21 14:02:45 +00:00
|
|
|
</svg>
|
2019-05-16 13:10:00 +00:00
|
|
|
</div>
|
2019-04-08 20:06:22 +00:00
|
|
|
</div>
|
2020-04-08 12:02:21 +00:00
|
|
|
<transition name="scale-fade">
|
|
|
|
|
<div
|
|
|
|
|
v-show="dropdown"
|
|
|
|
|
:class="[dropdownClasses]"
|
|
|
|
|
class="absolute right-0 z-30 text-white shadow cursor-pointer"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
v-for="(region, index) in regions"
|
|
|
|
|
:key="region"
|
|
|
|
|
@click="updateSettings({name: 'region', value: region.toLowerCase()})"
|
|
|
|
|
:class="classRegions(index)"
|
2020-06-11 18:55:39 +00:00
|
|
|
class="relative py-1 pl-5 pr-2 text-xs text-right select-none bg-blue-1000 hover:bg-blue-800"
|
2020-04-08 12:02:21 +00:00
|
|
|
>
|
|
|
|
|
<svg
|
|
|
|
|
v-if="region.toLowerCase() === selectedRegion"
|
2020-06-11 18:55:39 +00:00
|
|
|
class="absolute w-3 h-3 fill-current vertical-center offsetIcon"
|
2020-04-08 12:02:21 +00:00
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
viewBox="0 0 512 512"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
{{ region }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</transition>
|
|
|
|
|
</div>
|
2019-11-16 16:50:14 +00:00
|
|
|
</div>
|
2019-04-08 20:06:22 +00:00
|
|
|
</form>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-02-06 18:45:22 +00:00
|
|
|
import { mapActions, mapState } from 'vuex'
|
2020-02-13 19:16:13 +00:00
|
|
|
import SearchFormDropdown from '@/components/Form/SearchFormDropdown.vue'
|
2020-02-06 18:45:22 +00:00
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
export default {
|
2020-02-10 19:53:32 +00:00
|
|
|
components: {
|
|
|
|
|
SearchFormDropdown,
|
|
|
|
|
},
|
|
|
|
|
|
2019-09-14 21:19:10 +00:00
|
|
|
props: {
|
|
|
|
|
size: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'xl'
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
data() {
|
|
|
|
|
return {
|
2019-04-18 12:33:49 +00:00
|
|
|
summoner: '',
|
2019-04-08 20:06:22 +00:00
|
|
|
dropdown: false,
|
2019-04-16 13:34:38 +00:00
|
|
|
regions: [
|
2019-04-18 12:33:49 +00:00
|
|
|
'BR',
|
|
|
|
|
'EUNE',
|
|
|
|
|
'EUW',
|
|
|
|
|
'JP',
|
|
|
|
|
'KR',
|
|
|
|
|
'LAN',
|
|
|
|
|
'LAS',
|
|
|
|
|
'NA',
|
|
|
|
|
'OCE',
|
|
|
|
|
'TR',
|
|
|
|
|
'RU'
|
2019-04-16 13:34:38 +00:00
|
|
|
],
|
2020-02-10 19:53:32 +00:00
|
|
|
clickDropdown: false,
|
|
|
|
|
selected: false,
|
2019-08-23 14:48:16 +00:00
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
|
2019-09-14 21:19:10 +00:00
|
|
|
computed: {
|
|
|
|
|
btnClasses() {
|
|
|
|
|
return {
|
2020-04-01 10:55:55 +00:00
|
|
|
'left-0 w-8': this.size === 'small',
|
|
|
|
|
'right-0 w-12': this.size === 'xl'
|
2019-09-14 21:19:10 +00:00
|
|
|
}
|
|
|
|
|
},
|
2019-11-16 16:50:14 +00:00
|
|
|
formClasses() {
|
2019-09-14 21:19:10 +00:00
|
|
|
return {
|
2020-02-10 19:53:32 +00:00
|
|
|
'max-w-lg': this.size === 'small',
|
2019-09-14 21:19:10 +00:00
|
|
|
}
|
|
|
|
|
},
|
2019-11-16 16:50:14 +00:00
|
|
|
inputClasses() {
|
2019-09-14 21:19:10 +00:00
|
|
|
return {
|
2020-04-01 10:55:55 +00:00
|
|
|
'py-2 pl-12 pr-20 bg-transparent text-base border-b-2 border-blue-300 focus:border-white': this.size === 'small',
|
|
|
|
|
'py-4 pl-6 pr-32 focus:bg-blue-1000 rounded-lg': this.size === 'xl',
|
|
|
|
|
'input-color': !this.dropdown && this.size === 'xl',
|
|
|
|
|
'bg-blue-1000': this.dropdown && this.size === 'xl',
|
2019-09-14 21:19:10 +00:00
|
|
|
}
|
|
|
|
|
},
|
2019-11-16 16:50:14 +00:00
|
|
|
dropdownClasses() {
|
2019-09-14 21:19:10 +00:00
|
|
|
return {
|
2020-04-01 10:55:55 +00:00
|
|
|
'-mt-1 rounded': this.size === 'small',
|
|
|
|
|
'offsetDropDownXl rounded-b': this.size === 'xl'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
selectRegionClasses() {
|
|
|
|
|
return {
|
|
|
|
|
'px-2 text-base rounded-md': this.size === 'small',
|
|
|
|
|
'px-2 py-1': this.size === 'xl',
|
|
|
|
|
'bg-blue-1000': this.dropdown && this.size === 'small',
|
|
|
|
|
'border-teal-200': this.dropdown && this.size === 'xl',
|
2019-09-14 21:19:10 +00:00
|
|
|
}
|
2020-02-06 18:45:22 +00:00
|
|
|
},
|
|
|
|
|
...mapState({
|
|
|
|
|
selectedRegion: state => state.settings.region
|
|
|
|
|
}),
|
2019-09-14 21:19:10 +00:00
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
|
2020-04-01 10:55:55 +00:00
|
|
|
created() {
|
|
|
|
|
if (!this.summoner.length) {
|
|
|
|
|
this.summoner = this.$route.params.name
|
|
|
|
|
}
|
2020-02-10 19:53:32 +00:00
|
|
|
window.addEventListener('mousedown', this.globalClick)
|
|
|
|
|
window.addEventListener('blur', this.windowBlur)
|
2020-04-08 12:02:21 +00:00
|
|
|
document.addEventListener('click', this.clickOutsideRegionDropdown)
|
|
|
|
|
document.addEventListener('keydown', this.handleEscape)
|
2020-02-10 19:53:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
window.removeEventListener('mousedown', this.globalClick)
|
|
|
|
|
window.removeEventListener('blur', this.windowBlur)
|
2020-04-08 12:02:21 +00:00
|
|
|
document.removeEventListener('click', this.clickOutsideRegionDropdown)
|
|
|
|
|
document.removeEventListener('keydown', this.handleEscape)
|
2020-02-10 19:53:32 +00:00
|
|
|
},
|
|
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
methods: {
|
|
|
|
|
classRegions(index) {
|
|
|
|
|
return {
|
2020-04-01 10:55:55 +00:00
|
|
|
'rounded-t': index === 0,
|
2019-04-18 12:33:49 +00:00
|
|
|
'rounded-b': index === this.regions.length - 1
|
2019-08-23 14:48:16 +00:00
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
},
|
2020-04-08 12:02:21 +00:00
|
|
|
clickOutsideRegionDropdown(e) {
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
if (e.target === this.$refs['region-dropdown'] || this.$refs['region-dropdown'].contains(e.target)) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.dropdown = false
|
|
|
|
|
},
|
2019-04-08 20:06:22 +00:00
|
|
|
formSubmit() {
|
2019-09-03 17:56:41 +00:00
|
|
|
const search = this.summoner.split(' ').join('')
|
|
|
|
|
if (search.length) {
|
2020-02-06 18:45:22 +00:00
|
|
|
this.$emit('formSubmit', search, this.selectedRegion)
|
2019-08-22 22:50:00 +00:00
|
|
|
}
|
2020-02-06 18:45:22 +00:00
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
globalClick(e) {
|
|
|
|
|
if (e.target === this.$refs.input || e.target === this.$refs.submit) return
|
|
|
|
|
if (!this.clickDropdown) {
|
|
|
|
|
this.selected = false
|
|
|
|
|
}
|
|
|
|
|
this.clickDropdown = false
|
|
|
|
|
},
|
2020-04-08 12:02:21 +00:00
|
|
|
handleEscape(e) {
|
|
|
|
|
if (e.key === 'Esc' || e.key === 'Escape') {
|
|
|
|
|
this.dropdown = false
|
|
|
|
|
this.selected = false
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
windowBlur() {
|
|
|
|
|
this.selected = false
|
|
|
|
|
},
|
2020-02-06 18:45:22 +00:00
|
|
|
...mapActions('settings', ['updateSettings']),
|
2019-04-08 20:06:22 +00:00
|
|
|
}
|
2019-08-23 14:48:16 +00:00
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2019-11-16 16:50:14 +00:00
|
|
|
.offsetDropDownXl {
|
|
|
|
|
top: 58px;
|
|
|
|
|
right: 50px;
|
2019-04-16 13:34:38 +00:00
|
|
|
}
|
2019-05-16 13:10:00 +00:00
|
|
|
|
|
|
|
|
.offsetIcon {
|
|
|
|
|
left: 4px;
|
|
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
</style>
|