Database Schema Node
A node that can be used to visualize a database schema.
UI Component: database-schema-node
index.tsx
import React, { type ReactNode } from "react";
import {
BaseNode,
BaseNodeContent,
BaseNodeHeader,
} from "@/registry/components/base-node";
import { TableBody, TableRow, TableCell } from "@/components/ui/table";
/* DATABASE SCHEMA NODE HEADER ------------------------------------------------ */
/**
* A container for the database schema node header.
*/
export type DatabaseSchemaNodeHeaderProps = {
children?: ReactNode;
};
export const DatabaseSchemaNodeHeader = ({
children,
}: DatabaseSchemaNodeHeaderProps) => {
return (
<BaseNodeHeader className="bg-secondary text-muted-foreground rounded-tl-md rounded-tr-md p-2 text-center text-sm">
<h2>{children}</h2>
</BaseNodeHeader>
);
};
/* DATABASE SCHEMA NODE BODY -------------------------------------------------- */
/**
* A container for the database schema node body that wraps the table.
*/
export type DatabaseSchemaNodeBodyProps = {
children?: ReactNode;
};
export const DatabaseSchemaNodeBody = ({
children,
}: DatabaseSchemaNodeBodyProps) => {
return (
<BaseNodeContent className="p-0">
<table className="border-spacing-10 overflow-visible">
<TableBody>{children}</TableBody>
</table>
</BaseNodeContent>
);
};
/* DATABASE SCHEMA TABLE ROW -------------------------------------------------- */
/**
* A wrapper for individual table rows in the database schema node.
*/
export type DatabaseSchemaTableRowProps = {
children: ReactNode;
className?: string;
};
export const DatabaseSchemaTableRow = ({
children,
className,
}: DatabaseSchemaTableRowProps) => {
return (
<TableRow className={`relative text-xs ${className || ""}`}>
{children}
</TableRow>
);
};
/* DATABASE SCHEMA TABLE CELL ------------------------------------------------- */
/**
* A simplified table cell for the database schema node.
* Renders static content without additional dynamic props.
*/
export type DatabaseSchemaTableCellProps = {
className?: string;
children?: ReactNode;
};
export const DatabaseSchemaTableCell = ({
className,
children,
}: DatabaseSchemaTableCellProps) => {
return <TableCell className={className}>{children}</TableCell>;
};
/* DATABASE SCHEMA NODE ------------------------------------------------------- */
/**
* The main DatabaseSchemaNode component that wraps the header and body.
* It maps over the provided schema data to render rows and cells.
*/
export type DatabaseSchemaNodeProps = {
className?: string;
children?: ReactNode;
};
export const DatabaseSchemaNode = ({
className,
children,
}: DatabaseSchemaNodeProps) => {
return <BaseNode className={className}>{children}</BaseNode>;
};component-example.tsx
import { memo } from "react";
import { Position } from "@xyflow/react";
import { LabeledHandle } from "@/registry/components/labeled-handle";
import {
DatabaseSchemaNode,
DatabaseSchemaNodeHeader,
DatabaseSchemaNodeBody,
DatabaseSchemaTableRow,
DatabaseSchemaTableCell,
} from "@/registry/components/database-schema-node";
export type DatabaseSchemaNodeData = {
data: {
label: string;
schema: { title: string; type: string }[];
};
};
const DatabaseSchemaDemo = memo(({ data }: DatabaseSchemaNodeData) => {
return (
<DatabaseSchemaNode className="p-0">
<DatabaseSchemaNodeHeader>{data.label}</DatabaseSchemaNodeHeader>
<DatabaseSchemaNodeBody>
{data.schema.map((entry) => (
<DatabaseSchemaTableRow key={entry.title}>
<DatabaseSchemaTableCell className="pl-0 pr-6 font-light">
<LabeledHandle
id={entry.title}
title={entry.title}
type="target"
position={Position.Left}
/>
</DatabaseSchemaTableCell>
<DatabaseSchemaTableCell className="pr-0 font-thin">
<LabeledHandle
id={entry.title}
title={entry.type}
type="source"
position={Position.Right}
className="p-0"
handleClassName="p-0"
labelClassName="p-0 w-full pr-3 text-right"
/>
</DatabaseSchemaTableCell>
</DatabaseSchemaTableRow>
))}
</DatabaseSchemaNodeBody>
</DatabaseSchemaNode>
);
});
DatabaseSchemaDemo.displayName = "DatabaseSchemaDemo";
export default DatabaseSchemaDemo;