-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge-ui): Tabs Component (#13380)
- Loading branch information
1 parent
d6c12ab
commit a046fa3
Showing
7 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,6 +242,7 @@ | |
pausable: false, | ||
}; | ||
// TODO: Not found route | ||
const routes = { | ||
'/:tab?': wrap({ | ||
component: Home, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script lang="ts"> | ||
import { link } from 'svelte-spa-router'; | ||
import { getContext } from 'svelte'; | ||
import type { Writable } from 'svelte/store'; | ||
import { key } from './Tabs.svelte'; | ||
export let href: string = ''; | ||
export let name: string = ''; | ||
const activeTab = getContext<Writable<string>>(key); | ||
$: selected = name === $activeTab; | ||
$: tabActiveCls = selected ? 'tab-active' : ''; | ||
</script> | ||
|
||
<a | ||
role="tab" | ||
aria-selected={selected} | ||
class="tab tab-bordered {tabActiveCls}" | ||
on:click={() => ($activeTab = name)} | ||
{href} | ||
use:link> | ||
<slot /> | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div role="tablist" class="tabs {$$restProps.class || ''}"> | ||
<slot /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script lang="ts"> | ||
import { getContext } from 'svelte'; | ||
import type { Writable } from 'svelte/store'; | ||
import { key } from './Tabs.svelte'; | ||
export let tab: string = ''; | ||
const activeTab = getContext<Writable<string>>(key); | ||
$: selected = tab === $activeTab; | ||
$: classes = `${$$restProps.class || ''} ${!selected ? 'hidden' : ''}`; | ||
</script> | ||
|
||
<div role="tabpanel" aria-expanded={selected} class={classes}> | ||
<slot /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts" context="module"> | ||
export const key = Symbol(); | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { writable } from 'svelte/store'; | ||
import { setContext } from 'svelte'; | ||
export let activeTab = ''; | ||
// State only available to the component and its descendants | ||
setContext(key, writable(activeTab)); | ||
</script> | ||
|
||
<div class={$$restProps.class} style={$$restProps.style}> | ||
<slot /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { default as Tabs } from './Tabs.svelte'; | ||
export { default as TabList } from './TabList.svelte'; | ||
export { default as Tab } from './Tab.svelte'; | ||
export { default as TabPanel } from './TabPanel.svelte'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters