A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 355c1363e98f98283f5631608652ef9a18b9d273 (3583 bytes)[doc][blame][raw]
1
import VStation from './station.js';2
import VButton from '../element/button.js';4
export default {5
props: ['title', 'items'],6
data() {7
return {8
index: 0,9
length: null,10
size: null,11
count: null12
};13
},14
components: {15
VStation,16
VButton17
},18
methods: {19
calc() {20
const items = this.$refs.list.querySelectorAll('li');21
this.length = items.length;22
if(this.length > 0) {23
this.size = items[1].offsetLeft;24
this.count = Math.ceil(this.$refs.list.clientWidth / this.size);25
}26
},27
prev() {28
this.calc();29
if(this.index === 0) {30
return;31
}32
if(this.index - this.count < 0) {33
this.index = 0;34
return;35
}36
this.index -= this.count;37
},38
next() {39
this.calc();40
if(this.index === this.length - this.count - 1) {41
return;42
}43
if(this.index + this.count > this.length - this.count) {44
this.index = this.length - this.count;45
return;46
}47
this.index += this.count;48
},49
onResize() {50
this.calc();51
this.index = 0;52
}53
},54
created() {55
window.addEventListener('resize', this.onResize);56
},57
destroyed() {58
window.removeEventListener('resize', this.onResize);59
},60
computed: {61
transform() {62
return {63
'transform': `translate(${this.index * -this.size}px, 0)`,64
'transition': `transform ease-in-out 300ms`65
};66
},67
hasPrev() {68
if(this.length === null) {69
return false;70
}71
return this.index > 0;72
},73
hasNext() {74
if(this.length === null) {75
return true;76
}77
return this.index < this.length - this.count - 1;78
}79
},80
template: `81
<div>82
<div class="flex items-center pt-4 sm:pt-0 pb-5">83
<h3 class="flex-1 text-white text-[24px] font-bold">{{title}}</h3>84
<v-button85
icon="chevron-left"86
class="hidden sm:block w-[44px] min-w-[44px] h-[44px]"87
@click="prev()"88
:disabled="!hasPrev"89
></v-button>90
<v-button91
icon="chevron-right"92
class="hidden sm:block w-[44px] min-w-[44px] h-[44px]"93
@click="next()"94
:disabled="!hasNext"95
></v-button>96
</div>97
<div class="relative sm:overflow-x-hidden">98
<ul99
ref="list"100
class="flex overflow-x-auto sm:overflow-x-visible max-w-full snap-x snap-mandatory gap-4 lg:gap-6 scroll-hidden transition-transform"101
:style="transform"102
>103
<li104
:key="item.id"105
v-for="item in items"106
class="snap-start min-w-[calc(33.333%-(1rem/3*2))] sm:min-w-[calc(25%-(1rem/4*3))] md:min-w-[calc(20%-(1rem/5*4))] lg:min-w-[calc(16.666%-(1.5rem/6*5))]"107
>108
<v-station :station="item" type="grid"></v-station>109
</li>110
</ul>111
</div>112
</div>113
`114
}