/* ! * (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. */ import classNames from "classnames"; import { useCallback, useEffect, useRef, useState } from "react"; import { Button, type ButtonVariant, Classes, Pre, Tooltip } from "@blueprintjs/core"; import { useTheme } from "../common"; import { DOCS_CODE_BLOCK } from "../common/classes"; import { analyzeCode, getHtml, getIndex, getpackageJson, getParameters, getStyles, getTsconfig, } from "../common/sandbox"; export interface CodeExampleProps { children?: React.ReactNode; className?: string; id: string; previewCode: string; sourceCode: string; } export const CodeExample: React.FC = props => { const { children, className, id, previewCode, sourceCode, ...rest } = props; const classes = classNames("docs-code-example-frame", className); const [isMinimized, setIsMinimized] = useState(true); const toggleMinimized = useCallback(() => { setIsMinimized((prev: boolean) => !prev); }, []); return (
{children}
                    {previewCode.trimEnd()}
                
                    {sourceCode.trimEnd()}
                
); }; function CodeSandboxButton({ id, sourceCode }: { id: string; sourceCode: string }) { const { isDarkTheme } = useTheme(); const { dependencies, stylesheets } = analyzeCode(sourceCode); const packageJson = getpackageJson(dependencies); const indexJs = getIndex(stylesheets, isDarkTheme); const parameters = getParameters({ files: { "package.json": { content: packageJson, isBinary: false, }, "public/index.html": { content: getHtml({ title: `${id} - Blueprint` }), isBinary: false, }, "src/Demo.tsx": { content: sourceCode, isBinary: false, }, "src/index.tsx": { content: indexJs, isBinary: false, }, "src/styles.scss": { content: getStyles(), isBinary: false, }, "tsconfig.json": { content: getTsconfig(), isBinary: false, }, }, }); return (