import { readExampleFile } from "@/lib/composition" import { highlightCode } from "@/lib/highlight-code" import { Box, BoxProps, HStack, Tabs } from "@chakra-ui/react" import dynamic from "next/dynamic" import { CopyButton } from "./copy-button" import { ErrorBoundary } from "./error-boundary" import { StackblitzButton } from "./stackblitz-button" interface Props { name: string scope?: "examples" | "ui" } function formatComponentName(name: string) { return name .replace("charts/", "") .split(/[-\/]/) .map((part) => part.charAt(0).toUpperCase() + part.slice(1)) .join("") } export const ExamplePreview = (props: Props) => { const { name, scope = "examples" } = props const componentName = formatComponentName(name) const Component = dynamic(() => import(`../../compositions/src/${scope}/${name}`).then( (mod) => mod[componentName], ), ) return } interface CodeProps extends Props { showCopy?: boolean ext?: string } export const ExampleCode = async (props: CodeProps) => { const { name, showCopy = true, ext = "tsx", scope = "examples" } = props const content = await readExampleFile(name, scope, ext) const html = await highlightCode(content) return ( <>
{showCopy && ( )} ) } interface CodeWrapperProps extends BoxProps {} export const ExampleCodeWrapper = (props: CodeWrapperProps) => { const { children, maxHeight, bg, px = "8", py = "6", ...rest } = props return ( {children} ) } export const Example = (props: Props) => { const { name } = props if (!name) return null return ( ) } export const ExampleTabs = (props: Props) => { const { name, scope = "examples" } = props if (!name) return null return ( Preview Code {scope === "examples" && ( )} ) }