import React, { ForwardedRef } from 'react'; import { RowData } from '@tanstack/react-table'; import { cx } from '@leafygreen-ui/emotion'; import { useMergeRefs } from '@leafygreen-ui/hooks'; import { useDarkMode } from '@leafygreen-ui/leafygreen-provider'; import InternalRowBase from '../Row/InternalRowBase'; import { useTableContext } from '../TableContext'; import { baseStyles, expandedContentThemeStyles, } from './ExpandedContent.styles'; import { ExpandedContentComponentType, ExpandedContentProps, } from './ExpandedContent.types'; const ExpandedContentWithRef = ( { row, virtualRow, ...rest }: ExpandedContentProps, ref: ForwardedRef, ) => { const { virtualTable, lgIds } = useTableContext(); const content = row.original.renderExpandedContent && row.original.renderExpandedContent(row); const { theme } = useDarkMode(); return (
{content}
); }; // React.forwardRef can only work with plain function types, i.e. types with a single call signature and no other members. // This assertion has an interface that restores the original function signature to work with generics. export const ExpandedContent = React.forwardRef( ExpandedContentWithRef, ) as ExpandedContentComponentType; ExpandedContent.displayName = 'ExpandedContent'; export default ExpandedContent;