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

Function CodeBlock

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

getExampleFilesFunction · 0.70

Tested by

no test coverage detected