-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathtabs.svelte
More file actions
67 lines (59 loc) · 1.56 KB
/
tabs.svelte
File metadata and controls
67 lines (59 loc) · 1.56 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
<script>
import { onMount, setContext } from 'svelte';
import { app, f7ready } from '../shared/f7.js';
import { colorClasses } from '../shared/mixins.js';
import { classNames } from '../shared/utils.js';
let {
class: className,
animated = false,
swipeable = false,
routable = false,
swiperParams = undefined,
children,
...restProps
} = $props();
let wrapEl = $state(null);
const classes = $derived(classNames(className, colorClasses(restProps)));
const tabsClasses = $derived(
classNames({
tabs: true,
'tabs-routable': routable,
}),
);
setContext('TabsSwipeableContext', () => ({
value: true,
}));
onMount(() => {
if (swipeable) {
f7ready(() => {
// It only initializes in pageInit callback
// We may need to manually call init() to update the instance
app.f7.swiper.init(wrapEl);
});
}
if (!swipeable || !swiperParams) return;
if (!wrapEl) return;
Object.assign(wrapEl, swiperParams);
wrapEl.initialize();
});
</script>
{#if animated}
<div class={classNames('tabs-animated-wrap', classes)} bind:this={wrapEl} {...restProps}>
<div class={tabsClasses}>
{@render children?.()}
</div>
</div>
{:else if swipeable}
<swiper-container
bind:this={wrapEl}
class={classNames(tabsClasses, classes)}
{...restProps}
init={swiperParams ? 'false' : 'true'}
>
{@render children?.()}
</swiper-container>
{:else}
<div class={classNames(tabsClasses, classes)} {...restProps}>
{@render children?.()}
</div>
{/if}