import Card from '@material-ui/core/Card' import Table from '@material-ui/core/Table' import TableBody from '@material-ui/core/TableBody' import TableCell from '@material-ui/core/TableCell' import TableHead from '@material-ui/core/TableHead' import TableRow from '@material-ui/core/TableRow' import Typography from '@material-ui/core/Typography' import { titleCase } from 'title-case' import { noCase } from 'change-case' import React from 'react' import { CardTitle } from './CardTitle' const renderKey = (k: string, titleize: boolean) => titleize ? titleCase(noCase(k)) : k const renderEntries = (entries: Array>, titleize: boolean) => entries.map(([k, v]) => ( {renderKey(k, titleize)} {String(v)} )) const renderBody = ( entries: Array>, error: string, titleize: boolean, ) => { if (error) { return {error} } else if (entries.length === 0) { return } else { return renderEntries(entries, titleize) } } interface SpanRowProps { children: React.ReactNode } const SpanRow = ({ children }: SpanRowProps) => ( {children} ) const FetchingRow = () => ... interface ErrorRowProps { children: React.ReactNode } const ErrorRow = ({ children }: ErrorRowProps) => {children} interface ColProps { children: React.ReactNode } const Col = ({ children }: ColProps) => ( {children} ) interface HeadColProps { children: React.ReactNode } const HeadCol = ({ children }: HeadColProps) => ( {children} ) interface KeyValueListProps { entries: Array> titleize: boolean showHead: boolean title?: string error?: string } export const KeyValueList = ({ entries, error = '', showHead = false, title, titleize = false, }: KeyValueListProps) => ( {title && {title}} {showHead && ( Key Value )} {renderBody(entries, error, titleize)}
)