import { AnchorTitle, colors, HeaderSizes, Styles } from '@0x/react-shared'; import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptFunction, TypescriptMethod } from '@0x/types'; import * as _ from 'lodash'; import * as React from 'react'; import { DocsInfo } from '../docs_info'; import { constants } from '../utils/constants'; import { Comment } from './comment'; import { Signature } from './signature'; import { SourceLink } from './source_link'; export interface SignatureBlockProps { method: SolidityMethod | TypescriptFunction | TypescriptMethod; sectionName: string; libraryVersion: string; typeDefinitionByName: TypeDefinitionByName; docsInfo: DocsInfo; sourceUrl: string; } export interface SignatureBlockState { shouldShowAnchor: boolean; } const styles: Styles = { chip: { fontSize: 13, color: colors.white, height: 11, borderRadius: 14, lineHeight: 0.9, }, }; export class SignatureBlock extends React.Component { constructor(props: SignatureBlockProps) { super(props); this.state = { shouldShowAnchor: false, }; } public render(): React.ReactNode { const method = this.props.method; const isFallback = (method as SolidityMethod).isFallback; const hasExclusivelyNamedParams = !_.isUndefined(_.find(method.parameters, p => !_.isEmpty(p.name))); return (
{!(method as TypescriptMethod).isConstructor && (
{(method as TypescriptMethod).isStatic && this._renderChip('Static')} {(method as SolidityMethod).isConstant && this._renderChip('Constant')} {(method as SolidityMethod).isPayable && this._renderChip('Payable')} {isFallback && this._renderChip('Fallback', colors.lightGreenA700)}
)} {(method as TypescriptMethod).source && ( )} {method.comment && } {method.parameters && !_.isEmpty(method.parameters) && hasExclusivelyNamedParams && (

ARGUMENTS

{this._renderParameterDescriptions(method.parameters, method.name)}
)} {method.returnComment && (

RETURNS

)}
); } private _renderChip(text: string, backgroundColor: string = colors.lightBlueA700): React.ReactNode { return (
{text}
); } private _renderParameterDescriptions(parameters: Parameter[], name: string): React.ReactNode { const descriptions = _.map(parameters, (parameter: Parameter, i: number) => { const isOptional = parameter.isOptional; return (
{parameter.name}
{isOptional && 'optional'}
{parameter.comment && }
); }); return descriptions; } private _setAnchorVisibility(shouldShowAnchor: boolean): void { this.setState({ shouldShowAnchor, }); } }