import { isTag , isTsProperty , ITsClass , ITsInterface , ITsMethod , ITsProperty , ITsSignature , } from "@documentalist/client" ; import classNames from "classnames" ; import * as React from "react" ; import { Classes , Intent , Props , Tag } from "@blueprintjs/core" ; import { DocumentationContextTypes , IDocumentationContext } from "../../common/context" ; import { ModifierTable } from "../modifierTable" ; import { ApiHeader } from "./apiHeader" ; import { DeprecatedTag } from "./deprecatedTag" ; export type Renderer < T > = ( props : T ) => React . ReactNode ; export interface IInterfaceTableProps extends Props { data : ITsClass | ITsInterface ; title : string ; } export class InterfaceTable extends React . PureComponent < IInterfaceTableProps > { public static contextTypes = DocumentationContextTypes ; public static displayName = "Docs2.InterfaceTable" ; public context : IDocumentationContext ; public render ( ) { const { data , title } = this . props ; const { renderBlock } = this . context ; const propRows = [ ... data . properties , ... data . methods ] . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) . map ( this . renderPropRow ) ; return ( < div className = { classNames ( "docs-modifiers" , this . props . className ) } > < ApiHeader { ... data } / > { renderBlock ( data . documentation ) } < ModifierTable emptyMessage = "This interface is empty." title = { title } > { propRows } { this . renderIndexSignature ( data . indexSignature ) } < /ModifierTable> < /div>); } private renderPropRow = ( entry ) => { const { renderBlock , renderType } = this . context ; const { flags : { isDeprecated , isExternal , isOptional } , name , } = entry ; const { documentation } = isTsProperty ( entry ) ? entry : entry . signatures [ 0 ] ; if ( documentation != null && documentation . contents != null && documentation . contents . some ( val => isTag ( val ) && val . tag === "internal" ) ) { return null ; } const classes = classNames ( "docs-prop-name" , { "docs-prop-is-deprecated" : isDeprecated === true || typeof isDeprecated === "string" , "docs-prop-is-internal" : ! isExternal , "docs-prop-is-required" : ! isOptional , } ) ; const typeInfo = isTsProperty ( entry ) ? ( < > < strong > { renderType ( entry . type ) } < /strong> < em className = { classNames ( "docs-prop-default" , Classes . TEXT_MUTED ) } > { entry . defaultValue } < /em> < />) : (<> < strong > { renderType ( entry . signatures [ 0 ] . type ) } < /strong> < />); return ( < tr key = { name } > < td className = { classes } > < code > { name } < /code> < /td> < td className = "docs-prop-details" > < code className = "docs-prop-type" > { typeInfo } < /code> < div className = "docs-prop-description" > { renderBlock ( documentation ) } < /div> < div className = "docs-prop-tags" > { this . renderTags ( entry ) } < /div> < /td> < /tr>); } ; private renderIndexSignature ( entry ? ) { if ( entry == null ) { return null ; } const { renderBlock , renderType } = this . context ; const [ signature , returnType ] = entry . type . slice ( 2 , - 2 ) . split ( "]: " ) ; return ( < tr key = { entry . name } > < td className = "docs-prop-name" > < code > { renderType ( signature ) } ] < /code> < /td> < td className = "docs-prop-details" > < code className = "docs-prop-type" > { renderType ( returnType ) } < /code> < div className = "docs-prop-description" > { renderBlock ( entry . documentation ) } < /div> < /td> < /tr>); } private renderTags ( entry ) { const { renderType } = this . context ; const { flags : { isDeprecated , isOptional } , inheritedFrom , } = entry ; return ( < > { ! isOptional && < Tag children = "Required" intent = { Intent . SUCCESS } minimal = { true } / > } < DeprecatedTag isDeprecated = { isDeprecated } /> { inheritedFrom && ( < Tag minimal = { true } > Inherited from < code > { renderType ( inheritedFrom ) } < /code> < /Tag>)} < />); } }