({
render,
children,
dir,
files,
expanded,
hidden,
...props
}: CodeBlockProps)
| 71 | } |
| 72 | |
| 73 | export function CodeBlock({ |
| 74 | render, |
| 75 | children, |
| 76 | dir, |
| 77 | files, |
| 78 | expanded, |
| 79 | hidden, |
| 80 | ...props |
| 81 | }: CodeBlockProps) { |
| 82 | if (hidden) { |
| 83 | return null; |
| 84 | } |
| 85 | |
| 86 | let displayCode = children.replace(/(vanilla-starter|tailwind-starter)\//g, './'); |
| 87 | |
| 88 | if (!render) { |
| 89 | return ( |
| 90 | <pre className={standaloneCode}> |
| 91 | <Code {...props} styles={style({display: 'block', width: 'fit', minWidth: 'full'})}> |
| 92 | {displayCode} |
| 93 | </Code> |
| 94 | </pre> |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | let resolveFrom = path.resolve( |
| 99 | 'pages', |
| 100 | dir || (props.type === 's2' ? 's2' : 'react-aria'), |
| 101 | 'index.tsx' |
| 102 | ); |
| 103 | let downloadFiles = getExampleFiles(resolveFrom, children, props.type); |
| 104 | |
| 105 | let code = ( |
| 106 | <TruncatedCode maxLines={expanded ? Infinity : 6} {...props}> |
| 107 | {displayCode} |
| 108 | </TruncatedCode> |
| 109 | ); |
| 110 | |
| 111 | if (props.docs) { |
| 112 | return ( |
| 113 | <VisualExample |
| 114 | {...props} |
| 115 | component={render} |
| 116 | files={files} |
| 117 | downloadFiles={downloadFiles} |
| 118 | code={code} |
| 119 | /> |
| 120 | ); |
| 121 | } |
| 122 | |
| 123 | let content = ( |
| 124 | <FileProvider value={downloadFiles}> |
| 125 | <CodePlatter type={props.type} showCoachMark={props.showCoachMark}> |
| 126 | {code} |
| 127 | </CodePlatter> |
| 128 | </FileProvider> |
| 129 | ); |
| 130 |
nothing calls this directly
no test coverage detected