diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/react-docs/src/components/signature.tsx | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/react-docs/src/components/signature.tsx')
-rw-r--r-- | packages/react-docs/src/components/signature.tsx | 164 |
1 files changed, 0 insertions, 164 deletions
diff --git a/packages/react-docs/src/components/signature.tsx b/packages/react-docs/src/components/signature.tsx deleted file mode 100644 index c229999b1..000000000 --- a/packages/react-docs/src/components/signature.tsx +++ /dev/null @@ -1,164 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; - -import { Parameter, Type as TypeDef, TypeDefinitionByName, TypeParameter } from '@0x/types'; - -import { DocsInfo } from '../docs_info'; - -import { Type } from './type'; - -export interface SignatureProps { - name: string; - returnType: TypeDef; - parameters: Parameter[]; - sectionName: string; - shouldHideMethodName?: boolean; - shouldUseArrowSyntax?: boolean; - typeDefinitionByName?: TypeDefinitionByName; - typeParameter?: TypeParameter; - callPath?: string; - docsInfo: DocsInfo; - isInPopover: boolean; - isFallback?: boolean; -} - -const defaultProps = { - shouldHideMethodName: false, - shouldUseArrowSyntax: false, - callPath: '', - isFallback: false, -}; - -export const Signature: React.SFC<SignatureProps> = (props: SignatureProps) => { - const sectionName = props.sectionName; - const parameters = renderParameters( - props.parameters, - props.docsInfo, - sectionName, - props.isInPopover, - props.name, - props.typeDefinitionByName, - ); - const paramStringArray: any[] = []; - // HACK: For now we don't put params on newlines if there are less then 2 of them. - // Ideally we would check the character length of the resulting method signature and - // if it exceeds the available space, put params on their own lines. - const hasMoreThenTwoParams = parameters.length > 2; - _.each(parameters, (param: React.ReactNode, i: number) => { - const finalParam = hasMoreThenTwoParams ? ( - <span className="pl2" key={`param-${i}`}> - {param} - </span> - ) : ( - param - ); - paramStringArray.push(finalParam); - const comma = hasMoreThenTwoParams ? ( - <span key={`param-comma-${i}`}> - , <br /> - </span> - ) : ( - ', ' - ); - paramStringArray.push(comma); - }); - if (!hasMoreThenTwoParams) { - paramStringArray.pop(); - } - const methodName = props.shouldHideMethodName ? '' : props.name; - const typeParameterIfExists = _.isUndefined(props.typeParameter) - ? undefined - : renderTypeParameter( - props.typeParameter, - props.docsInfo, - sectionName, - props.isInPopover, - props.typeDefinitionByName, - ); - return ( - <span style={{ fontSize: 15 }}> - {props.callPath} - {props.isFallback ? '' : methodName} - {typeParameterIfExists}({hasMoreThenTwoParams && <br />} - {paramStringArray}) - {props.returnType && ( - <span> - {props.shouldUseArrowSyntax ? ' => ' : ': '}{' '} - <Type - type={props.returnType} - sectionName={sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - </span> - )} - </span> - ); -}; - -Signature.defaultProps = defaultProps; - -function renderParameters( - parameters: Parameter[], - docsInfo: DocsInfo, - sectionName: string, - isInPopover: boolean, - name: string, - typeDefinitionByName?: TypeDefinitionByName, -): React.ReactNode[] { - const params = _.map(parameters, (p: Parameter, i: number) => { - const isOptional = p.isOptional; - const hasDefaultValue = !_.isUndefined(p.defaultValue); - const type = ( - <Type - type={p.type} - sectionName={sectionName} - typeDefinitionByName={typeDefinitionByName} - docsInfo={docsInfo} - isInPopover={isInPopover} - /> - ); - return ( - <span key={`param-${JSON.stringify(p.type)}-${name}-${i}`}> - {!_.isEmpty(p.name) && ( - <span> - {p.name} - {isOptional && '?'}:{' '} - </span> - )} - {type} - {hasDefaultValue && ` = ${p.defaultValue}`} - </span> - ); - }); - return params; -} - -function renderTypeParameter( - typeParameter: TypeParameter, - docsInfo: DocsInfo, - sectionName: string, - isInPopover: boolean, - typeDefinitionByName?: TypeDefinitionByName, -): React.ReactNode { - const typeParam = ( - <span> - {`<${typeParameter.name}`} - {!_.isUndefined(typeParameter.type) && ( - <span> - {' extends '} - <Type - type={typeParameter.type} - sectionName={sectionName} - typeDefinitionByName={typeDefinitionByName} - docsInfo={docsInfo} - isInPopover={isInPopover} - /> - </span> - )} - {`>`} - </span> - ); - return typeParam; -} |