1 "use client"
2
3 import React from "react"
4 import { CodeBlock, CodeBlockProps } from "../CodeBlock"
5 import clsx from "clsx"
6
7 export type VerticalCodeTab = {
8 title: string
9 code: CodeBlockProps
10 } & Record<string, unknown>
11
12 export type VerticalCodeTabsProps = {
13 tabs: VerticalCodeTab[]
14 className?: string
15 selectedTabIndex: number
16 setSelectedTabIndex: (value: number) => void
17 }
18
19 export const VerticalCodeTabs = ({
20 tabs,
21 className,
22 selectedTabIndex,
23 setSelectedTabIndex,
24 }: VerticalCodeTabsProps) => {
25 return (
26 <div
27 className={clsx(
28 "rounded-[20px] bg-medusa-bg-subtle p-docs_0.5",
29 "shadow-elevation-modal dark:shadow-elevation-modal-dark",
30 className
31 )}
32 data-testid="vertical-code-tabs-container"
33 >
34 <div
35 className={clsx(
36 "rounded-docs_lg bg-medusa-contrast-bg-base h-full",
37 "shadow-elevation-code-block dark:shadow-elevation-code-block-dark",
38 "flex flex-col"
39 )}
40 >
41 <div
42 className={clsx(
43 "px-docs_1 py-docs_0.75",
44 "flex gap-[6px] items-center"
45 )}
46 >
47 {new Array(3).fill(0).map((_, index) => (
48 <span
49 className={clsx(
50 "inline-block rounded-full w-[10px] h-[10px]",
51 "bg-medusa-contrast-border-bot border border-medusa-contrast-border-bot"
52 )}
53 key={index}
54 data-testid="vertical-code-tabs-dot"
55 />
56 ))}
57 </div>
58 <div
59 className={clsx(
60 "flex flex-1 gap-[6px] items-start px-[5px] pb-[5px]"
61 )}
62 >
63 <ul className="2xl:w-[180px] flex flex-col gap-[6px] shrink-0">
64 {tabs.map((tab, index) => (
65 <li
66 className={clsx(
67 "px-docs_0.75 py-[11px]",
68 "rounded-docs_DEFAULT border border-medusa-contrast-border-bot",
69 "text-code-body font-monospace cursor-pointer",
70 selectedTabIndex === index &&
71 "text-medusa-contrast-fg-primary bg-medusa-contrast-border-bot",
72 selectedTabIndex !== index &&
73 "text-medusa-contrast-fg-secondary bg-medusa-contrast-bg-subtle hover:bg-medusa-contrast-border-bot"
74 )}
75 onClick={() => setSelectedTabIndex(index)}
76 key={index}
77 >
78 {tab.title}
79 </li>
80 ))}
81 </ul>
82 <div className="flex-1 h-[388px] max-w-full overflow-hidden rounded-docs_DEFAULT [&_pre]:min-h-full">
83 <CodeBlock
84 {...tabs[selectedTabIndex].code}
85 noCopy={true}
86 noReport={true}
87 noAskAi={true}
88 forceNoTitle={true}
89 wrapperClassName="h-full !rounded-docs_DEFAULT"
90 className={clsx(
91 "overflow-auto h-full max-h-full !mb-0 !rounded-docs_DEFAULT",
92 "!border !border-medusa-contrast-border-bot"
93 )}
94 innerClassName="h-full"
95 animateTokenHighlights
96 overrideColors={{
97 bg: "bg-medusa-contrast-bg-subtle",
98 innerBg: "bg-medusa-contrast-bg-subtle",
99 lineNumbersBg: "bg-medusa-contrast-bg-subtle",
100 boxShadow: "shadow-none",
101 }}
102 />
103 </div>
104 </div>
105 </div>
106 </div>
107 )
108 }