-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathCodeTabs.astro
More file actions
29 lines (25 loc) · 805 Bytes
/
CodeTabs.astro
File metadata and controls
29 lines (25 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---
import {parse} from "node-html-parser";
interface Props {
items: string[];
}
const { items } = Astro.props;
let slot = await Astro.slots.render('default');
const parsedHtml = parse(slot);
parsedHtml.childNodes.forEach((tabContent, index) => {
// @ts-ignore
if (index !== 0) tabContent.classList.add('hidden');
});
---
<div class="codetabs_wrapper">
<div class="codetabs_tabs">
{items.map((item, index) => <div class={index === 0 ? "codetabs_tab--active" : "codetabs_tab"} data-change-code-tab-btn data-tab-label={item}>{item}</div>)}
</div>
<div class="code codetabs_codeBlock">
<Fragment set:html={parsedHtml.toString()} />
</div>
</div>
<script>
import { setupSyncedTabs } from "@/utils-client";
document.addEventListener("astro:page-load", setupSyncedTabs);
</script>