MCPcopy Create free account
hub / github.com/cosscom/coss / ComponentSource

Function ComponentSource

apps/ui/components/component-source.tsx:9–58  ·  view source on GitHub ↗
({
  name,
  src,
  title,
  language,
  collapsible = true,
  className,
}: React.ComponentProps<"div"> & {
  name?: string;
  src?: string;
  title?: string;
  language?: string;
  collapsible?: boolean;
})

Source from the content-addressed store, hash-verified

7import { cn } from "@/lib/utils";
8
9export async function ComponentSource({
10 name,
11 src,
12 title,
13 language,
14 collapsible = true,
15 className,
16}: React.ComponentProps<"div"> & {
17 name?: string;
18 src?: string;
19 title?: string;
20 language?: string;
21 collapsible?: boolean;
22}) {
23 if (!name && !src) {
24 return null;
25 }
26
27 let code: string | undefined;
28
29 if (name) {
30 const item = await getRegistryItem(name);
31 code = item?.files?.[0]?.content;
32 }
33
34 if (src) {
35 const file = await fs.readFile(path.join(process.cwd(), src), "utf-8");
36 code = file;
37 }
38
39 if (!code) {
40 return null;
41 }
42
43 const lang = language ?? title?.split(".").pop() ?? "tsx";
44
45 if (!collapsible) {
46 return (
47 <div className={cn("relative", className)}>
48 <CodeBlock code={code} language={lang} title={title} />
49 </div>
50 );
51 }
52
53 return (
54 <CodeCollapsibleWrapper className={className}>
55 <CodeBlock code={code} language={lang} title={title} />
56 </CodeCollapsibleWrapper>
57 );
58}

Callers

nothing calls this directly

Calls 2

getRegistryItemFunction · 0.90
cnFunction · 0.90

Tested by

no test coverage detected