-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fd7496
commit 0bf39ec
Showing
5 changed files
with
81 additions
and
21 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
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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
<script> | ||
import { getContext } from "svelte"; | ||
import CodePanelBody from "./CodePanelBody.svelte"; | ||
import CodePanelHeader from "./CodePanelHeader.svelte"; | ||
/** @type {string|null}*/ | ||
export let label = null; | ||
/** @type {string|null}*/ | ||
export let tag = null; | ||
export let name = "default"; | ||
/** @type {import("svelte/store").Writable<string[]>}*/ | ||
const tabs = getContext("code-group-tabs"); | ||
/** @type {import("svelte/store").Writable<number>}*/ | ||
const activeTab = getContext("code-group-active-tab"); | ||
tabs.update((oldTabs) => [...oldTabs, name]); | ||
$: active = $tabs.findIndex((tab) => tab === name) === $activeTab; | ||
</script> | ||
|
||
<div class="group dark:bg-white/2.5"> | ||
{#if label || tag} | ||
<CodePanelHeader {tag} {label} /> | ||
{/if} | ||
<CodePanelBody><slot /></CodePanelBody> | ||
</div> | ||
{#if active} | ||
<div class="group dark:bg-white/2.5"> | ||
{#if label || tag} | ||
<CodePanelHeader {tag} {label} /> | ||
{/if} | ||
<CodePanelBody><slot /></CodePanelBody> | ||
</div> | ||
{/if} |
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
<script> | ||
import { setContext } from "svelte"; | ||
import CodeGroupHeader from "./Code/CodeGroupHeader.svelte"; | ||
import CodeTab from "./Code/CodePanel.svelte"; | ||
import { writable } from "svelte/store"; | ||
/** @type {import("svelte/store").Writable<string[]>}*/ | ||
let tabs = writable([]); | ||
let activeTab = writable(0); | ||
setContext("code-group-id", crypto.randomUUID()); | ||
setContext("code-group-tabs", tabs); | ||
setContext("code-group-active-tab", activeTab); | ||
</script> | ||
|
||
<div | ||
class="shadow-xl my-6 overflow-hidden rounded-md bg-zinc-900 dark:ring-1 dark:ring-white/10 not-prose" | ||
class="shadow-md my-6 overflow-hidden rounded-md bg-zinc-900 dark:ring-1 dark:ring-white/10 not-prose" | ||
> | ||
<slot Header={CodeGroupHeader} Tab={CodeTab} /> | ||
</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
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