-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathtabs.vue
More file actions
71 lines (64 loc) · 1.77 KB
/
tabs.vue
File metadata and controls
71 lines (64 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
<div v-if="animated" ref="elRef" :class="classNames('tabs-animated-wrap', classes)">
<div :class="tabsClasses">
<slot />
</div>
</div>
<swiper-container v-else-if="swipeable" ref="elRef" :class="classNames(tabsClasses, classes)"
:init="swiperParams ? 'false' : 'true'">
<slot />
</swiper-container>
<div v-else ref="elRef" :class="classNames(tabsClasses, classes)">
<slot />
</div>
</template>
<script>
import { computed, ref, onMounted, provide } from 'vue';
import { classNames } from '../shared/utils.js';
import { colorClasses, colorProps } from '../shared/mixins.js';
import { f7ready, f7 } from '../shared/f7.js';
export default {
name: 'f7-tabs',
props: {
animated: Boolean,
swipeable: Boolean,
routable: Boolean,
swiperParams: {
type: Object,
default: undefined,
},
...colorProps,
},
setup(props) {
const elRef = ref(null);
onMounted(() => {
if (props.swipeable) {
f7ready(() => {
// It only initializes in pageInit callback
// We may need to manually call init() to update the instance
f7.swiper.init(elRef.value)
});
}
if (!props.swipeable || !props.swiperParams) return;
if (!elRef.value) return;
Object.assign(elRef.value, props.swiperParams);
elRef.value.initialize();
});
const classes = computed(() => classNames(colorClasses(props)));
const tabsClasses = computed(() =>
classNames({
tabs: true,
'tabs-routable': props.routable,
}),
);
const TabsSwipeableContext = computed(() => props.swipeable);
provide('TabsSwipeableContext', TabsSwipeableContext);
return {
elRef,
classes,
tabsClasses,
classNames,
};
},
};
</script>