import classNames from "classnames" ; import * as React from "react" ; import { DISPLAYNAME_PREFIX } from "@blueprintjs/core" ; import * as Classes from "../../common/classes" ; import { ITruncatedFormatProps , TruncatedFormat , TruncatedPopoverMode } from "./truncatedFormat" ; export type JSONFormatProps = IJSONFormatProps ; export interface IJSONFormatProps extends ITruncatedFormatProps { children ? : any ; default omitQuotesOnStrings ? : boolean ; /**
     * Optionally specify the stringify method. Default is `JSON.stringify`
     * with 2-space indentation.
     */ stringify ? : ( obj : any ) => string ; } export class JSONFormat extends React . Component < IJSONFormatProps > { public static displayName = `${ DISPLAYNAME_PREFIX }.JSONFormat` ; public static defaultProps : IJSONFormatProps = { omitQuotesOnStrings : true , stringify : ( obj ) => JSON . stringify ( obj , null , 2 ) , } ; public render ( ) { const { children , omitQuotesOnStrings , stringify } = this . props ; let { showPopover } = this . props ; const isNully = children == null ; if ( isNully ) { showPopover = TruncatedPopoverMode . NEVER ; } const className = classNames ( this . props . className , { [ Classes . TABLE_NULL ] : isNully , } ) ; let displayValue = "" ; if ( omitQuotesOnStrings && typeof children === "string" ) { displayValue = children ; } else { displayValue = stringify ( children ) ; } return ( < TruncatedFormat { ... this . props } className = { className } showPopover = { showPopover } > { displayValue } < /TruncatedFormat>); } }