import { AnchorTitle, colors, HeaderSizes, Styles } from '@0xproject/react-shared'; import * as _ from 'lodash'; import * as React from 'react'; import { DocsInfo } from '../docs_info'; import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from '../types'; import { constants } from '../utils/constants'; import { typeDocUtils } from '../utils/typedoc_utils'; import { Comment } from './comment'; import { MethodSignature } from './method_signature'; import { SourceLink } from './source_link'; export interface MethodBlockProps { method: SolidityMethod | TypescriptMethod; sectionName: string; libraryVersion: string; typeDefinitionByName: TypeDefinitionByName; docsInfo: DocsInfo; sourceUrl: string; } export interface MethodBlockState { shouldShowAnchor: boolean; } const styles: Styles = { chip: { fontSize: 13, backgroundColor: colors.lightBlueA700, color: colors.white, height: 11, borderRadius: 14, lineHeight: 0.9, }, }; export class MethodBlock extends React.Component { constructor(props: MethodBlockProps) { super(props); this.state = { shouldShowAnchor: false, }; } public render() { const method = this.props.method; if (typeDocUtils.isPrivateOrProtectedProperty(method.name)) { return null; } return (
{!method.isConstructor && (
{(method as TypescriptMethod).isStatic && this._renderChip('Static')} {(method as SolidityMethod).isConstant && this._renderChip('Constant')} {(method as SolidityMethod).isPayable && this._renderChip('Payable')}
)} {(method as TypescriptMethod).source && ( )} {method.comment && } {method.parameters && !_.isEmpty(method.parameters) && (

ARGUMENTS

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

RETURNS

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