import { Fragment, PropsWithRef } from 'react'; import { ChevronDownSvg } from '../../atoms/icons'; import { useDetailsGrid } from './hooks/useDetailsGrid/useDetailsGrid'; import { IDetailsGridProps } from './interfaces'; import { AnyRecord } from '../../../types'; import { DataField } from '../DataField/DataField'; import { ctw } from '../../../utils/ctw/ctw'; /** * @description Displays a title and a collapsable 3 columns grid of DataField with an option of passing a component next to the title or to the bottom of the grid. * * * @param props - Props to pass to the root grid element. * @param props.data - The data to pass to the DataField - expects an object, coverts its keys to Start case to be used as a title. * @param props.header - An optional component to display next to the title. * @param props.footer - An optional component to display at the bottom of the grid. * @constructor */ export const DetailsGrid = ({ data, title, header, footer, children, loading, ...rest }: PropsWithRef>) => { const { dataFields, skeletons } = useDetailsGrid(data ?? {}); return ( <>
{loading?.title ? '' : title} {!!header && header}
{loading?.data ? ( <> {skeletons.map(i => ( ))} ) : ( dataFields?.map(({ title, text }, index) => ( {children({ title, text, index })} )) )} {!!footer && footer}
); };