so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: 39ef1a811131b367ebb5b86e57d5b3096644dd39 (3527 bytes)[doc][blame][raw]

1import VStation from './station.js';

2import VButton from '../element/button.js';

3

4export default {

5 props: ['title', 'items'],

6 data() {

7 return {

8 index: 0,

9 length: null,

10 size: null,

11 count: null

12 };

13 },

14 components: {

15 VStation,

16 VButton

17 },

18 methods: {

19 calc() {

20 const items = this.$refs.list.querySelectorAll('li');

21 this.length = items.length;

22 this.size = items[1].offsetLeft;

23 this.count = Math.ceil(this.$refs.list.clientWidth / this.size);

24 },

25 prev() {

26 this.calc();

27 if(this.index === 0) {

28 return;

29 }

30 if(this.index - this.count < 0) {

31 this.index = 0;

32 return;

33 }

34 this.index -= this.count;

35 },

36 next() {

37 this.calc();

38 if(this.index === this.length - this.count - 1) {

39 return;

40 }

41 if(this.index + this.count > this.length - this.count) {

42 this.index = this.length - this.count;

43 return;

44 }

45 this.index += this.count;

46 },

47 onResize() {

48 this.calc();

49 this.index = 0;

50 }

51 },

52 created() {

53 window.addEventListener('resize', this.onResize);

54 },

55 destroyed() {

56 window.removeEventListener('resize', this.onResize);

57 },

58 computed: {

59 transform() {

60 return {

61 'transform': `translate(${this.index * -this.size}px, 0)`,

62 'transition': `transform ease-in-out 300ms`

63 };

64 },

65 hasPrev() {

66 if(this.length === null) {

67 return false;

68 }

69 return this.index > 0;

70 },

71 hasNext() {

72 if(this.length === null) {

73 return true;

74 }

75 return this.index < this.length - this.count - 1;

76 }

77 },

78 template: `

79 <div>

80 <div class="flex items-center pt-4 sm:pt-0 pb-5">

81 <h3 class="flex-1 text-white text-[24px] font-bold">{{title}}</h3>

82 <v-button

83 icon="chevron-left"

84 class="hidden sm:block w-[44px] min-w-[44px] h-[44px]"

85 @click="prev()"

86 :disabled="!hasPrev"

87 ></v-button>

88 <v-button

89 icon="chevron-right"

90 class="hidden sm:block w-[44px] min-w-[44px] h-[44px]"

91 @click="next()"

92 :disabled="!hasNext"

93 ></v-button>

94 </div>

95 <div class="relative sm:overflow-x-hidden">

96 <ul

97 ref="list"

98 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"

99 :style="transform"

100 >

101 <li

102 :key="item.id"

103 v-for="item in items"

104 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))]"

105 >

106 <v-station :station="item" type="grid"></v-station>

107 </li>

108 </ul>

109 </div>

110 </div>

111 `

112}