import { ITag } from "@documentalist/client" ; import * as React from "react" ; import { AnchorButton , Intent } from "@blueprintjs/core" ; import { IExampleProps } from "../components/example" ; export interface IExample { sourceUrl : string ; render : ( props : IExampleProps ) => JSX . Element | undefined ; } export interface IExampleMap { [ componentName ] : IExample ; } export class ReactExampleTagRenderer { constructor ( private examples ) { } /**
     * Given the name of an example component, like `"AlertExample"`, attempts to resolve
     * it to an actual example component exported by one of the packages. Also returns
     * the URL of the source code on GitHub.
     */ public render : React . FC < ITag > = ( { value : exampleName } ) => { if ( exampleName == null ) { return null ; } const example = this . examples [ exampleName ] ; if ( example == null ) { throw new Error ( `Unknown @example component: ${ exampleName }` ) ; } return ( < > { example . render ( { id : exampleName } ) } < AnchorButton className = "docs-example-view-source" fill = { true } href = { example . sourceUrl } icon = "code" intent = { Intent . PRIMARY } minimal = { true } target = "_blank" text = "View source on GitHub" / > < />); } ; }