Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bridge-ui): clean tabs component #13526

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/bridge-ui/src/components/Tabs/Tabs.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<script lang="ts" context="module">
import { getContext } from 'svelte';
import type { Writable } from 'svelte/store';

export const key = Symbol();
</script>

<script lang="ts">
import { writable } from 'svelte/store';
import { setContext } from 'svelte';
import { writable, type Writable } from 'svelte/store';
import { setContext, getContext } from 'svelte';

// Props
export let activeTab = '';

// State only available to the component and its descendants
setContext(key, writable(activeTab));
const currentActiveTab = getContext<Writable<string>>(key);
$: $currentActiveTab = activeTab;

// We need to keep the store in sync with the prop in case the user
// navigates back in the browser, which will change the prop but not
// the Tabs' state
const storeActiveTab = getContext<Writable<string>>(key);
$: $storeActiveTab = activeTab;
</script>

<div class={$$restProps.class} style={$$restProps.style}>
Expand Down