Skip to content

Commit

Permalink
fix(Tabs): removed neeless context
Browse files Browse the repository at this point in the history
fix(Tabs): variant styles are now reactive
  • Loading branch information
Craig Howell committed Feb 5, 2023
1 parent af36615 commit 1157efd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
21 changes: 3 additions & 18 deletions src/lib/components/tabs/Tab.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<script lang="ts" context="module">
export const TABS_TAB_CONTEXT_ID = 'tabs-tab-context-id';
</script>

<script lang="ts">
import { TABS_CONTEXT_ID } from './Tabs.svelte';
import { useContext } from '$lib/utils/useContext';
import { getContext, setContext } from 'svelte';
import type { Writable } from 'svelte/store';
import HoverBackground from '../HoverBackground.svelte';
Expand All @@ -18,19 +12,10 @@
export let href: string;
export let key: string;
useContext({
context_id: TABS_CONTEXT_ID,
parent: 'Tabs',
component: 'Tabs.Tab'
});
setContext(TABS_TAB_CONTEXT_ID, {
tab: true,
key
});
setContext('tab-key', key);
const { variant, currentTab }: { variant: string; currentTab: Writable<string> } =
getContext(TABS_CONTEXT_ID);
const variant: string = getContext('tabs-variant');
const currentTab: Writable<string> = getContext('tabs-currentTab');
let defaultClass = '';
$: if (key === $currentTab) {
Expand Down
15 changes: 4 additions & 11 deletions src/lib/components/tabs/Tabs.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<script lang="ts" context="module">
export const TABS_CONTEXT_ID = 'tabs-context-id';
</script>

<script lang="ts">
import { setContext } from 'svelte';
import { writable, type Writable } from 'svelte/store';
Expand All @@ -19,14 +15,11 @@
let selected: Writable<string> = writable(currentTab);
$: $selected = currentTab;
setContext(TABS_CONTEXT_ID, {
tabs: true,
variant,
currentTab: selected
});
setContext('tabs-variant', variant);
setContext('tabs-currentTab', selected);
let defaultContainerClass = '';
if (variant === 'bar') {
$: if (variant === 'bar') {
defaultContainerClass =
'border-light-border dark:border-dark-border overflow-hidden rounded-md shadow-md border dark:shadow-black';
} else {
Expand All @@ -35,7 +28,7 @@
$: finalContainerClass = twMerge(defaultContainerClass, containerClass);
let defaultClass = '';
if (variant === 'bar') {
$: if (variant === 'bar') {
defaultClass =
'-mb-px flex justify-evenly isolate divide-x divide-light-border dark:divide-dark-border';
} else if (variant === 'full-width') {
Expand Down

0 comments on commit 1157efd

Please sign in to comment.