File size: 980 Bytes
1e92f2d |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import { Tabs } from "@chakra-ui/react"
import { Children } from "react"
interface CodeGroupProps {
children: React.ReactElement
}
export const CodeGroup: React.FC<CodeGroupProps> = (props) => {
const { children } = props
const titles: React.ReactNode[] = []
const contents: React.ReactNode[] = []
let firstTitle = ""
Children.forEach(children, (child: React.ReactElement, index: number) => {
const title = child.props["data-title"]
if (index === 0) firstTitle = title
titles.push(
<Tabs.Trigger key={title} value={title}>
{title}
</Tabs.Trigger>,
)
contents.push(
<Tabs.Content
key={title}
value={title}
mt="-2"
css={{
"& pre": { mb: "0" },
}}
>
{child.props.children}
</Tabs.Content>,
)
})
return (
<Tabs.Root my="6" size="sm" defaultValue={firstTitle}>
<Tabs.List>{titles}</Tabs.List>
{contents}
</Tabs.Root>
)
}
|