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

Function CodeBlock

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

Source from the content-addressed store, hash-verified

82}
83
84export function CodeBlock({
85 render,
86 children,
87 dir,
88 files,
89 expanded,
90 hidden,
91 hideCode,
92 ...props
93}: CodeBlockProps) {
94 if (hidden) {
95 return null;
96 }
97
98 let displayCode = children.replace(STARTER_ALIAS_RE, './');
99
100 if (!render) {
101 return (
102 <pre className={standaloneCode}>
103 <Code {...props} styles={style({display: 'block', width: 'fit', minWidth: 'full'})}>
104 {displayCode}
105 </Code>
106 </pre>
107 );
108 }
109
110 let resolveFrom = path.resolve(
111 baseDir,
112 'packages/dev/s2-docs/pages',
113 dir || (props.type === 's2' ? 's2' : 'react-aria'),
114 'index.tsx'
115 );
116 let downloadFiles = hideCode
117 ? {files: {}, deps: {}}
118 : getExampleFiles(resolveFrom, children, props.type);
119
120 let code = (
121 <TruncatedCode maxLines={expanded ? Infinity : 6} {...props}>
122 {displayCode}
123 </TruncatedCode>
124 );
125
126 if (props.docs) {
127 return (
128 <VisualExample
129 {...props}
130 component={render}
131 files={files}
132 downloadFiles={downloadFiles}
133 code={code}
134 hideCode={hideCode}
135 />
136 );
137 }
138
139 // If the example imports a component from the hooks starter, offer a per-component
140 // "Install with shadcn" command pointing at its hooks registry item.
141 let hooksComponent = files

Callers

nothing calls this directly

Calls 1

getExampleFilesFunction · 0.70

Tested by

no test coverage detected