Skip to content

Commit df4b3db

Browse files
TommertomTommertom
Tommertom
authored and
Tommertom
committed
Removed typescript from demo
1 parent dfd6b1e commit df4b3db

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

demo-app/src/lib/IonTabsLegacy.svelte

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<script lang="ts">
2+
/*
3+
DONT USE THIS ANYMORE - NO LONGER MAINTAINED
4+
https://github.com/Tommertom/ionic-svelte-tabs-howto
5+
*/
6+
import { onMount } from 'svelte';
7+
8+
import * as ionIcons from 'ionicons/icons';
9+
10+
let ionTabBarElement;
11+
12+
export let tabs;
13+
export let selected: string | undefined = undefined;
14+
export let ionTabsDidChange = (event) => {};
15+
export let ionNavWillLoad = (event) => {};
16+
export let ionTabsWillChange = (event) => {};
17+
export let slot = 'bottom';
18+
19+
// selected-tab does not seem to work - so we brute force it into the right method
20+
// https://github.com/ionic-team/ionic-framework/issues/20060
21+
let tries = 0;
22+
let controller;
23+
const selectTab = async () => {
24+
if (controller && controller.select) {
25+
controller.select(selected).then(async (x) => {
26+
const y = await controller.getSelected();
27+
});
28+
}
29+
30+
// somehow the tabs-present method does not run well on the first time, even though it gives positive response
31+
if (tries < 5) {
32+
setTimeout(() => {
33+
tries++;
34+
selectTab();
35+
}, 5);
36+
}
37+
};
38+
39+
onMount(() => {
40+
controller = ionTabBarElement;
41+
if (selected) {
42+
selectTab();
43+
}
44+
});
45+
46+
console.warn(
47+
'IonTabsLegacy used - will be deprecated in the future - https://github.com/Tommertom/ionic-svelte-tabs-howto'
48+
);
49+
</script>
50+
51+
<ion-tabs
52+
on:ionTabsDidChange={ionTabsDidChange}
53+
on:ionNavWillLoad={ionNavWillLoad}
54+
on:ionTabsWillChange={ionTabsWillChange}
55+
bind:this={ionTabBarElement}
56+
>
57+
{#each tabs as tab}
58+
<ion-tab tab={tab.tab}>
59+
<svelte:component this={tab.component} />
60+
</ion-tab>
61+
{/each}
62+
63+
{#if slot === 'bottom' || slot === ''}
64+
<ion-tab-bar slot="bottom" selected-tab={selected}>
65+
{#each tabs as tab}
66+
<ion-tab-button tab={tab.tab}>
67+
<ion-label>{tab.label}</ion-label>
68+
<ion-icon icon={ionIcons[tab.icon]} />
69+
</ion-tab-button>
70+
{/each}
71+
</ion-tab-bar>
72+
{/if}
73+
74+
{#if slot === 'top'}
75+
<ion-tab-bar slot="top" selected-tab={selected}>
76+
{#each tabs as tab}
77+
<ion-tab-button tab={tab.tab}>
78+
<ion-label>{tab.label}</ion-label>
79+
<ion-icon icon={ionIcons[tab.icon]} />
80+
</ion-tab-button>
81+
{/each}
82+
</ion-tab-bar>
83+
{/if}
84+
</ion-tabs>

demo-app/src/routes/components/tabs/[tab]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts">
22
// SvelteKit users - please refer to https://github.com/Tommertom/ionic-svelte-tabs-howto
33
// this has a newer and better way to implement tabs, using layout-system of SvelteKit router
4-
import { IonTabsLegacy } from 'ionic-svelte';
54
5+
import IonTabsLegacy from '$lib/IonTabsLegacy.svelte';
66
import Controllers from '../../Controllers/+page.svelte';
77
import Music from '$lib/components/Music.svelte';
88
import TabsExplain from '$lib/components/TabsExplain.svelte';

src/IonTabsLegacy.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<script lang="ts">
2+
/*
3+
DONT USE THIS ANYMORE - NO LONGER MAINTAINED
4+
See https://github.com/Tommertom/ionic-svelte-tabs-howto
5+
*/
26
import { onMount } from "svelte";
37
48
import * as ionIcons from "ionicons/icons";

0 commit comments

Comments
 (0)