MCPcopy Create free account
hub / github.com/adobe/react-spectrum / CodeBlock

Function CodeBlock

packages/dev/s2-docs/src/CodeBlock.tsx:85–182  ·  view source on GitHub ↗
({
  render,
  children,
  dir,
  files,
  expanded,
  hidden,
  hideCode,
  ...props
}: CodeBlockProps)

Source from the content-addressed store, hash-verified

83}
84
85export function CodeBlock({
86 render,
87 children,
88 dir,
89 files,
90 expanded,
91 hidden,
92 hideCode,
93 ...props
94}: CodeBlockProps) {
95 if (hidden) {
96 return null;
97 }
98
99 let displayCode = children.replace(STARTER_ALIAS_RE, './');
100
101 if (!render) {
102 return (
103 <pre className={standaloneCode}>
104 <Code {...props} styles={style({display: 'block', width: 'fit', minWidth: 'full'})}>
105 {displayCode}
106 </Code>
107 </pre>
108 );
109 }
110
111 // Client components (client references) are rendered by ExampleOutput, which passes them props from
112 // controls. Server components can't be passed to the client, so they're rendered here.
113 if (typeof render === 'function') {
114 render = createElement(render);
115 }
116
117 let resolveFrom = path.resolve(
118 baseDir,
119 'packages/dev/s2-docs/pages',
120 dir || (props.type === 's2' ? 's2' : 'react-aria'),
121 'index.tsx'
122 );
123 let downloadFiles = hideCode
124 ? {files: {}, deps: {}}
125 : getExampleFiles(resolveFrom, children, props.type);
126
127 let code = (
128 <TruncatedCode maxLines={expanded ? Infinity : 6} {...props}>
129 {displayCode}
130 </TruncatedCode>
131 );
132
133 if (props.docs) {
134 return (
135 <VisualExample
136 {...props}
137 component={render}
138 files={files}
139 downloadFiles={downloadFiles}
140 code={code}
141 hideCode={hideCode}
142 />

Callers

nothing calls this directly

Calls 1

getExampleFilesFunction · 0.70

Tested by

no test coverage detected