so://phie

verbal

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

blob: 4d376ab1ab2b097d869a4de1107b313e2e9a35c3 (3799 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 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-button

85 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-button

91 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 <ul

99 ref="list"

100 v-if="items?.length > 0"

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

102 :style="transform"

103 >

104 <li

105 :key="item.id"

106 v-for="item in items"

107 v-if="item"

108 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))] max-w-[calc(33.333%-(1rem/3*2))] sm:max-w-[calc(25%-(1rem/4*3))] md:max-w-[calc(20%-(1rem/5*4))] lg:max-w-[calc(16.666%-(1.5rem/6*5))]"

109 >

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

111 </li>

112 </ul>

113 </div>

114 </div>

115 `

116}