import type {Language} from "prism-react-renderer";
import {clsx} from "@heroui/shared-utils";
import * as Components from "@heroui/react";
import NextImage from "next/image";
import {usePostHog} from "posthog-js/react";
import {ThemeSwitch} from "./theme-switch";
import {InfoCircle} from "./icons/info-circle";
import {FigmaButton} from "./figma-button";
import {Sandpack} from "@/components/sandpack";
import {CarbonAd} from "@/components/ads/carbon-ad";
import * as DocsComponents from "@/components/docs/components";
import * as BlogComponents from "@/components/blog/components";
import {Codeblock} from "@/components/docs/components";
import {DeprecationMessage} from "@/components/docs/deprecation-message";
import {VirtualAnchor, virtualAnchorEncode} from "@/components/virtual-anchor";
import {
Table as StaticTable,
TableHeader,
TableBody,
TableRow,
TableCell,
TableColumnHeader,
TableRoot,
} from "@/components/static-table";
const Table: React.FC<{children?: React.ReactNode}> = ({children}) => {
return (
);
};
const Thead: React.FC<{children?: React.ReactNode}> = ({children}) => {
return (
tr]:h-12",
"[&>tr>th]:py-0",
"[&>tr>th]:align-middle",
"[&>tr>th]:bg-default-400/20",
"dark:[&>tr>th]:bg-default-600/10",
"[&>tr>th]:text-default-600 [&>tr>th]:text-xs",
"[&>tr>th]:text-left [&>tr>th]:pl-2",
"[&>tr>th:first-child]:rounded-l-lg",
"[&>tr>th:last-child]:rounded-r-lg",
)}
>
{children}
);
};
const Trow: React.FC<{children?: React.ReactNode}> = ({children}) => {
return {children} ;
};
const Tcol: React.FC<{children?: React.ReactNode}> = ({children}) => {
return (
{children}
);
};
export interface LinkedHeadingProps {
as: keyof JSX.IntrinsicElements;
id?: string;
linked?: boolean;
children?: React.ReactNode;
className?: string;
}
const linkedLevels: Record = {
h1: 0,
h2: 1,
h3: 2,
h4: 3,
};
const LinkedHeading: React.FC = ({
as,
linked = true,
id: idProp,
className,
...props
}) => {
const Component = as;
const level = linkedLevels[as] || 1;
let id = idProp || virtualAnchorEncode(props.children as string);
return (
{linked ? {props.children} : <>{props.children}>}
);
};
const List: React.FC<{children?: React.ReactNode}> = ({children}) => {
return (
);
};
const InlineCode = ({children, className}: {children?: React.ReactNode; className?: string}) => {
return (
{children}
);
};
const Code = ({
className,
children,
meta,
}: {
children?: React.ReactNode;
className?: string;
meta?: string;
}) => {
const isMultiLine = (children as string)?.split?.("\n")?.length > 2;
const language = (className?.replace(/language-/, "") ?? "jsx") as Language;
const codeString = String(children).trim();
const posthog = usePostHog();
if (!className) {
return {children} ;
}
return (
{
posthog.capture("MDXComponents - Copy", {
category: "docs",
action: "copyCode",
});
}}
>
);
};
const Link = ({href, children}: {href?: string; children?: React.ReactNode}) => {
const isExternal = href?.startsWith("http") || href?.startsWith("https");
const posthog = usePostHog();
const handleClick = () => {
posthog.capture("MDXComponents - Click", {
category: "docs",
action: "click",
data: href || "",
});
};
const externalProps = isExternal ? {target: "_blank", rel: "noopener noreferrer"} : {};
return (
{children}
);
};
const InlineCodeChip = ({
children,
className,
}: {
children?: React.ReactNode;
className?: string;
}) => {
return (
{children}
);
};
interface APITableProps {
data: {
attribute: string;
type: string;
description: string;
deprecated?: boolean;
default?: string;
}[];
}
export const APITable: React.FC = ({data}) => {
return (
Prop
Type
Default
{data.map((item, index) => (
{item.attribute}
{item.description && (
<>
{/* Desktop tooltip */}
{/* Mobile popover */}
{item.description}
>
)}
{item.type}
{item.default && item.default !== "-" ? (
{item.default !== "true" && item.default !== "false"
? `"${item.default}"`
: item.default}
) : (
)}
))}
);
};
export const MDXComponents = {
/**
* Next.js components
*/
NextImage,
/**
* HeroUI components
*/
...Components,
/**
* Docs components
*/
...DocsComponents,
Sandpack,
ThemeSwitch,
FigmaButton,
/**
* Blog components
*/
...BlogComponents,
/**
* Markdown components
*/
// ...Icons,
h1: (props: React.HTMLAttributes) => (
),
h2: (props: React.HTMLAttributes) => ,
h3: (props: React.HTMLAttributes) => ,
h4: (props: React.HTMLAttributes) => ,
strong: (props: React.HTMLAttributes) => ,
table: Table,
thead: Thead,
tr: Trow,
td: Tcol,
CarbonAd,
DeprecationMessage,
code: Code,
ul: List,
a: (props: React.HTMLAttributes) => ,
blockquote: (props: Omit, "color">) => (
),
kbd: (props: React.HTMLAttributes) => (
),
Steps: ({...props}) => (
),
APITable,
// Block,
} as unknown as Record;