import * as React from "react"; import { Tooltip } from "@lemonsqueezy/wedges"; import { createLabelDocs, type LabelDocsParams } from "@/lib/docUtils"; import { cn } from "@/lib/utils"; type ContentItem = { value: string; description?: string; }; type SortProps = { sort: true; content: [ContentItem, { value: React.ReactNode }][]; }; type NoSortProps = { sort?: false; content: [ContentItem, ContentItem, ContentItem][]; }; export const PropsTable = React.forwardRef< HTMLTableElement, React.HTMLAttributes & { content: [ContentItem, ContentItem, ContentItem][]; isData?: boolean; isOptions?: boolean; isUtility?: boolean; sort?: boolean; includeCommonDocs?: LabelDocsParams; } & (SortProps | NoSortProps) >( ( { content, isData = false, isOptions = false, isUtility = false, sort = true, includeCommonDocs, ...otherProps }, ref ) => { // Include label docs? const { label = false, description = false, tooltip = false, helperText = false, required = false, disabled = false, before = false, after = false, asChild = false, } = includeCommonDocs ?? {}; const labelDocs = createLabelDocs({ label, description, tooltip, helperText, required, disabled, before, after, asChild, }); // Sort the content array const sortedContent = React.useMemo(() => { if (sort) { const returnContent = [...labelDocs]; returnContent.push( ...[...content].sort((a, b) => { const aValue = a[0].value; const bValue = b[0].value; return aValue?.toString().localeCompare(bValue.toString()); }) ); return returnContent; } else { return [...labelDocs, ...content]; } }, [content, sort]); return (
{!isData && !isUtility ? : null} {sortedContent?.map((row, index) => ( {row.map((rowItem, rowIndex) => isData && rowIndex === 2 ? null : ( ) )} ))}
{isData ? "Data attribute" : isOptions ? "Option" : isUtility ? "Class" : "Prop"} {isUtility ? "Values" : "Value"}Default
{typeof rowItem?.value === "string" && rowItem?.value?.includes("Present") ? ( // Render a span element if 'Present' is found {rowItem.value} ) : rowItem?.value ? ( // Existing code for other cases {rowItem.value} ) : ( // Fallback if there's no value / )} {rowItem.description}
); } ); PropsTable.displayName = "PropsTable"; const Description = ({ children }: { children: React.ReactNode }) => { return children ? ( ) : null; };