import * as React from 'react'; import { find, isOverridden } from './utils'; interface DebugPanelDataProps { data: any; overrides?: any; comments?: any; indent?: number; highlightKey?: string; commentKeyPredicate?: (val: any) => boolean; } export const DebugPanelData: React.FC = props => { const { data, indent = 2, highlightKey, overrides, comments, commentKeyPredicate } = props; const isValidComment = typeof comments === 'string' && commentKeyPredicate && commentKeyPredicate(comments); if (typeof data === 'undefined') { return isValidComment ? undefined : undefined; } if (data === null || typeof data !== 'object') { return isValidComment ? {JSON.stringify(data)} : {JSON.stringify(data)}; } return ( <> {'{'} {Object.keys(data).map((key, idx) => { const value = data[key]; const comment = comments && comments[key]; const highlight = find(data, key, highlightKey); const overridden = isOverridden(data, key, overrides); return (
{' '.repeat(indent)} {key} {': '} {','}
); })} {`${indent > 2 ? ' '.repeat(indent - 2) : ''}}`} ); };