Files
Pasquale Vitiello 9302c06311 refactor: align biome settings with calcom (#718)
* update biome config + resolve issues

* improve the ui:sync command to run organizeImports on packages

* reformat

* build registry

* exclude base-ui stuff

* fix useExportsLast

* further improvements

* silence errors

* exclude examples app

* update biome + reformat

* format all the other files

* include examples app

* improve copyable-field

* remove unwanted comment

* remove a few unneeded biome comments

* avoid nested ternary

* refactored some shared components

* upgrade base ui to 1.2.0

* fix
2026-03-11 23:09:19 +00:00

59 lines
1.3 KiB
TypeScript

import fs from "node:fs/promises";
import path from "node:path";
import { CodeBlock } from "@coss/ui/shared/code-block";
import type * as React from "react";
import { CodeCollapsibleWrapper } from "@/components/code-collapsible-wrapper";
import { getRegistryItem } from "@/lib/registry";
import { cn } from "@/lib/utils";
export async function ComponentSource({
name,
src,
title,
language,
collapsible = true,
className,
}: React.ComponentProps<"div"> & {
name?: string;
src?: string;
title?: string;
language?: string;
collapsible?: boolean;
}) {
if (!name && !src) {
return null;
}
let code: string | undefined;
if (name) {
const item = await getRegistryItem(name);
code = item?.files?.[0]?.content;
}
if (src) {
const file = await fs.readFile(path.join(process.cwd(), src), "utf-8");
code = file;
}
if (!code) {
return null;
}
const lang = language ?? title?.split(".").pop() ?? "tsx";
if (!collapsible) {
return (
<div className={cn("relative", className)}>
<CodeBlock code={code} language={lang} title={title} />
</div>
);
}
return (
<CodeCollapsibleWrapper className={className}>
<CodeBlock code={code} language={lang} title={title} />
</CodeCollapsibleWrapper>
);
}